Skip to content

Commit 2e670d9

Browse files
committed
Add support for html in multipart/mixed
1 parent 1ce83dc commit 2e670d9

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

parsemail.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ func parseMultipartMixed(msg io.Reader, boundary string) (textBody, htmlBody str
249249
}
250250

251251
textBody += strings.TrimSuffix(string(ppContent[:]), "\n")
252+
} else if contentType == contentTypeTextHtml {
253+
ppContent, err := ioutil.ReadAll(part)
254+
if err != nil {
255+
return textBody, htmlBody, attachments, embeddedFiles, err
256+
}
257+
258+
htmlBody += strings.TrimSuffix(string(ppContent[:]), "\n")
252259
} else if isAttachment(part) {
253260
at, err := decodeAttachment(part)
254261
if err != nil {

parsemail_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,26 @@ So, "Hello".`,
296296
textBody: `plain text part`,
297297
},
298298
10: {
299+
contentType: `multipart/mixed; boundary="0000000000007e2bb40587e36196"`,
300+
mailData: textHTMLInMultipart,
301+
subject: "Re: kern/54143 (virtualbox)",
302+
from: []mail.Address{
303+
{
304+
Name: "Rares",
305+
Address: "rares@example.com",
306+
},
307+
},
308+
to: []mail.Address{
309+
{
310+
Name: "",
311+
Address: "bugs@example.com",
312+
},
313+
},
314+
date: parseDate("Fri, 02 May 2019 11:25:35 +0300"),
315+
textBody: ``,
316+
htmlBody: "<div dir=\"ltr\"><div>html text part</div><div><br></div><div><br><br></div></div>",
317+
},
318+
11: {
299319
mailData: rfc5322exampleA12WithTimezone,
300320
from: []mail.Address{
301321
{
@@ -331,7 +351,7 @@ So, "Hello".`,
331351
date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"),
332352
textBody: `Hi everyone.`,
333353
},
334-
11: {
354+
12: {
335355
contentType: "multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf",
336356
mailData: attachment7bit,
337357
subject: "Peter Foobar",
@@ -358,7 +378,7 @@ So, "Hello".`,
358378
},
359379
},
360380
},
361-
12: {
381+
13: {
362382
contentType: "multipart/related; boundary=\"000000000000ab2e2205a26de587\"",
363383
mailData: multipartRelatedExample,
364384
subject: "Saying Hello",
@@ -743,6 +763,20 @@ plain text part
743763
--0000000000007e2bb40587e36196--
744764
`
745765

766+
var textHTMLInMultipart = `From: Rares <rares@example.com>
767+
Date: Thu, 2 May 2019 11:25:35 +0300
768+
Subject: Re: kern/54143 (virtualbox)
769+
To: bugs@example.com
770+
Content-Type: multipart/mixed; boundary="0000000000007e2bb40587e36196"
771+
772+
--0000000000007e2bb40587e36196
773+
Content-Type: text/html; charset="UTF-8"
774+
775+
<div dir="ltr"><div>html text part</div><div><br></div><div><br><br></div></div>
776+
777+
--0000000000007e2bb40587e36196--
778+
`
779+
746780
var rfc5322exampleA11 = `From: John Doe <jdoe@machine.example>
747781
Sender: Michael Jones <mjones@machine.example>
748782
To: Mary Smith <mary@example.net>

0 commit comments

Comments
 (0)