diff --git a/parsemail.go b/parsemail.go index 6a60192..e752dd3 100644 --- a/parsemail.go +++ b/parsemail.go @@ -345,7 +345,7 @@ func decodeAttachment(part *multipart.Part) (at Attachment, err error) { } func decodeContent(content io.Reader, encoding string) (io.Reader, error) { - switch encoding { + switch strings.ToLower(encoding) { case "base64": decoded := base64.NewDecoder(base64.StdEncoding, content) b, err := ioutil.ReadAll(decoded) diff --git a/parsemail_test.go b/parsemail_test.go index 109e734..cb088aa 100644 --- a/parsemail_test.go +++ b/parsemail_test.go @@ -403,6 +403,34 @@ So, "Hello".`, htmlBody: "
Time for the egg.



", textBody: "Time for the egg.", }, + 14: { + mailData: data3, + contentType: `multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf`, + content: "", + subject: "Peter Paholík", + from: []mail.Address{ + { + Name: "Peter Paholík", + Address: "peter.paholik@gmail.com", + }, + }, + to: []mail.Address{ + { + Name: "", + Address: "dusan@kasan.sk", + }, + }, + messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com", + date: parseDate("Fri, 07 Apr 2017 09:17:26 +0200"), + htmlBody: "

", + attachments: []attachmentData{ + { + filename: "Peter Paholík 1 4 2017 2017-04-07.json", + contentType: "application/json", + data: "[1, 2, 3]", + }, + }, + }, } for index, td := range testData { @@ -750,6 +778,41 @@ YKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg== --------------C70C0458A558E585ACB75FB4-- ` +var data3 = `From: =?UTF-8?Q?Peter_Pahol=C3=ADk?= +Date: Fri, 7 Apr 2017 09:17:26 +0200 +Message-ID: +Subject: =?UTF-8?Q?Peter_Pahol=C3=ADk?= +To: dusan@kasan.sk +Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf + +--f403045f1dcc043a44054c8e6bbf +Content-Type: multipart/alternative; boundary=f403045f1dcc043a3f054c8e6bbd + +--f403045f1dcc043a3f054c8e6bbd +Content-Type: text/plain; charset=UTF-8 + + + +--f403045f1dcc043a3f054c8e6bbd +Content-Type: text/html; charset=UTF-8 + +

+ +--f403045f1dcc043a3f054c8e6bbd-- +--f403045f1dcc043a44054c8e6bbf +Content-Type: application/json; + name="=?UTF-8?Q?Peter_Paholi=CC=81k_1?= + =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Ejson?=" +Content-Disposition: attachment; + filename="=?UTF-8?Q?Peter_Paholi=CC=81k_1?= + =?UTF-8?Q?_4_2017_2017=2D04=2D07=2Ejson?=" +Content-Transfer-Encoding: BASE64 +X-Attachment-Id: f_j17i0f0d0 + +WzEsIDIsIDNd +--f403045f1dcc043a44054c8e6bbf-- +` + var textPlainInMultipart = `From: Rares Date: Thu, 2 May 2019 11:25:35 +0300 Subject: Re: kern/54143 (virtualbox)