From a2cf1b6022a43b6f3ed00850b50ffaf7d722ef92 Mon Sep 17 00:00:00 2001 From: Michal Horejsek Date: Wed, 6 Jan 2021 13:49:55 +0100 Subject: [PATCH] Fix parsing messages with long lines in header and long header split to multiple lines --- go.mod | 6 +- go.sum | 7 ++ pkg/message/parser_test.go | 30 +++++++++ pkg/message/testdata/long_header_line.eml | 5 ++ .../testdata/long_header_line_multiline.eml | 64 +++++++++++++++++++ unreleased.md | 3 +- 6 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 pkg/message/testdata/long_header_line.eml create mode 100644 pkg/message/testdata/long_header_line_multiline.eml diff --git a/go.mod b/go.mod index e996acdf..6656cd40 100644 --- a/go.mod +++ b/go.mod @@ -35,10 +35,10 @@ require ( github.com/emersion/go-imap-specialuse v0.0.0-20200722111535-598ff00e4075 github.com/emersion/go-imap-unselect v0.0.0-20171113212723-b985794e5f26 github.com/emersion/go-mbox v1.0.2 - github.com/emersion/go-message v0.12.1-0.20200903165315-e1abe21f389a + github.com/emersion/go-message v0.12.1-0.20201221184100-40c3f864532b github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 github.com/emersion/go-smtp v0.14.0 - github.com/emersion/go-textwrapper v0.0.0-20160606182133-d0e65e56babe + github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594 github.com/emersion/go-vcard v0.0.0-20190105225839-8856043f13c5 // indirect github.com/fatih/color v1.9.0 github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect @@ -68,7 +68,7 @@ require ( github.com/urfave/cli v1.22.4 go.etcd.io/bbolt v1.3.5 golang.org/x/net v0.0.0-20200707034311-ab3426394381 - golang.org/x/text v0.3.3 + golang.org/x/text v0.3.5-0.20201125200606-c27b9fd57aec gopkg.in/stretchr/testify.v1 v1.2.2 // indirect ) diff --git a/go.sum b/go.sum index d972975a..e08904b9 100644 --- a/go.sum +++ b/go.sum @@ -91,6 +91,8 @@ github.com/emersion/go-mbox v1.0.2/go.mod h1:Yp9IVuuOYLEuMv4yjgDHvhb5mHOcYH6x92O github.com/emersion/go-message v0.11.1/go.mod h1:C4jnca5HOTo4bGN9YdqNQM9sITuT3Y0K6bSUw9RklvY= github.com/emersion/go-message v0.12.1-0.20200903165315-e1abe21f389a h1:3C6qIGgPr1qAT0ikRD5NbyKpME/iHCDeXhpv/JJsFsE= github.com/emersion/go-message v0.12.1-0.20200903165315-e1abe21f389a/go.mod h1:kYIioST9GDHte9/BRWgi93rpqbDuFftMjKSMaXS8ABo= +github.com/emersion/go-message v0.12.1-0.20201221184100-40c3f864532b h1:xYuhW6egTaCP+zjbUcfoy/Dr3ASdVPR9W7fmkHvZHPE= +github.com/emersion/go-message v0.12.1-0.20201221184100-40c3f864532b/go.mod h1:N1JWdZQ2WRUalmdHAX308CWBq747VJ8oUorFI3VCBwU= github.com/emersion/go-sasl v0.0.0-20191210011802-430746ea8b9b/go.mod h1:G/dpzLu16WtQpBfQ/z3LYiYJn3ZhKSGWn83fyoyQe/k= github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ= github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= @@ -98,6 +100,8 @@ github.com/emersion/go-smtp v0.14.0 h1:RYW203p+EcPjL8Z/ZpT9lZ6iOc8MG1MQzEx1UKEkX github.com/emersion/go-smtp v0.14.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ= github.com/emersion/go-textwrapper v0.0.0-20160606182133-d0e65e56babe h1:40SWqY0zE3qCi6ZrtTf5OUdNm5lDnGnjRSq9GgmeTrg= github.com/emersion/go-textwrapper v0.0.0-20160606182133-d0e65e56babe/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= +github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594 h1:IbFBtwoTQyw0fIM5xv1HF+Y+3ZijDR839WMulgxCcUY= +github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= github.com/emersion/go-vcard v0.0.0-20190105225839-8856043f13c5 h1:n9qx98xiS5V4x2WIpPC2rr9mUM5ri9r/YhCEKbhCHro= github.com/emersion/go-vcard v0.0.0-20190105225839-8856043f13c5/go.mod h1:WIi9g8OKJQHXtQbx7GExlo6UAFaui9WDMYabJ+Be4WI= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= @@ -186,6 +190,7 @@ github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/z github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/martinlindhe/base36 v1.0.0 h1:eYsumTah144C0A8P1T/AVSUk5ZoLnhfYFM3OGQxB52A= github.com/martinlindhe/base36 v1.0.0/go.mod h1:+AtEs8xrBpCeYgSLoY/aJ6Wf37jtBuR0s35750M27+8= +github.com/martinlindhe/base36 v1.1.0/go.mod h1:+AtEs8xrBpCeYgSLoY/aJ6Wf37jtBuR0s35750M27+8= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= @@ -333,6 +338,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5-0.20201125200606-c27b9fd57aec h1:A1qYjneJuzBZZ2gIB8rd6zrfq6l7SoEMJ8EsSilNK/U= +golang.org/x/text v0.3.5-0.20201125200606-c27b9fd57aec/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= diff --git a/pkg/message/parser_test.go b/pkg/message/parser_test.go index 9b48a376..f2f8fd2e 100644 --- a/pkg/message/parser_test.go +++ b/pkg/message/parser_test.go @@ -31,6 +31,36 @@ import ( "golang.org/x/text/encoding/charmap" ) +func TestParseLongHeaderLine(t *testing.T) { + f := getFileReader("long_header_line.eml") + + m, _, plainBody, attReaders, err := Parse(f) + require.NoError(t, err) + + assert.Equal(t, `"Sender" `, m.Sender.String()) + assert.Equal(t, `"Receiver" `, m.ToList[0].String()) + + assert.Equal(t, "body", m.Body) + assert.Equal(t, "body", plainBody) + + assert.Len(t, attReaders, 0) +} + +func TestParseLongHeaderLineMultiline(t *testing.T) { + f := getFileReader("long_header_line_multiline.eml") + + m, _, plainBody, attReaders, err := Parse(f) + require.NoError(t, err) + + assert.Equal(t, `"Sender" `, m.Sender.String()) + assert.Equal(t, `"Receiver" `, m.ToList[0].String()) + + assert.Equal(t, "body", m.Body) + assert.Equal(t, "body", plainBody) + + assert.Len(t, attReaders, 0) +} + func TestParseTextPlain(t *testing.T) { f := getFileReader("text_plain.eml") diff --git a/pkg/message/testdata/long_header_line.eml b/pkg/message/testdata/long_header_line.eml new file mode 100644 index 00000000..1d9ff8af --- /dev/null +++ b/pkg/message/testdata/long_header_line.eml @@ -0,0 +1,5 @@ +From: Sender +References: Date: Wed, 13 Apr 2016 14:06:11 +0200 +To: Receiver + +body \ No newline at end of file diff --git a/pkg/message/testdata/long_header_line_multiline.eml b/pkg/message/testdata/long_header_line_multiline.eml new file mode 100644 index 00000000..c4509d40 --- /dev/null +++ b/pkg/message/testdata/long_header_line_multiline.eml @@ -0,0 +1,64 @@ +From: Sender +References: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +To: Receiver + +body \ No newline at end of file diff --git a/unreleased.md b/unreleased.md index dcefbadd..3a1a1d9e 100644 --- a/unreleased.md +++ b/unreleased.md @@ -14,7 +14,8 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) * GODT-773 Replace old dates with birthday of RFC822 to not crash Apple Mail. Original is available under `X-Original-Date` header. * GODT-922 Fix panic during restarting the bridge. * GODT-945 Fix panic in integration tests caused by concurrent map writes. -* GODT-732 Fix usage of fontawesome +* GODT-732 Fix usage of fontawesome. +* GODT-951 Properly parse message with long lines in header and long header split to multiple lines (upgrading to latest go-message). ### Changed * GODT-858 Bump go-rfc5322 dependency to v0.5.0 to handle some invalid RFC5322 groups and add support for semicolon delimiter in address-list.