Skip to content

Add support for uppercase encodings #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parsemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
63 changes: 63 additions & 0 deletions parsemail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,34 @@ So, "Hello".`,
htmlBody: "<div dir=\"ltr\"><div>Time for the egg.</div><div><br></div><div><br><br></div></div>",
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: "[email protected]",
},
},
to: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
},
messageID: "CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com",
date: parseDate("Fri, 07 Apr 2017 09:17:26 +0200"),
htmlBody: "<div dir=\"ltr\"><br></div>",
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 {
Expand Down Expand Up @@ -750,6 +778,41 @@ YKUKF+Os3baUndC0pDnwNAmLy1SUr2Gw0luxQuV/AwC6cEhVV5VRrwAAAABJRU5ErkJggg==
--------------C70C0458A558E585ACB75FB4--
`

var data3 = `From: =?UTF-8?Q?Peter_Pahol=C3=ADk?= <[email protected]>
Date: Fri, 7 Apr 2017 09:17:26 +0200
Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com>
Subject: =?UTF-8?Q?Peter_Pahol=C3=ADk?=
To: [email protected]
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

<div dir="ltr"><br></div>

--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 <[email protected]>
Date: Thu, 2 May 2019 11:25:35 +0300
Subject: Re: kern/54143 (virtualbox)
Expand Down