Merge pull request #19 from k-yomo/support-html-in-multipart-mixed
Add support for html in multipart/mixed
diff --git a/parsemail.go b/parsemail.go
index 42e0170..6a60192 100644
--- a/parsemail.go
+++ b/parsemail.go
@@ -249,6 +249,13 @@
}
textBody += strings.TrimSuffix(string(ppContent[:]), "\n")
+ } else if contentType == contentTypeTextHtml {
+ ppContent, err := ioutil.ReadAll(part)
+ if err != nil {
+ return textBody, htmlBody, attachments, embeddedFiles, err
+ }
+
+ htmlBody += strings.TrimSuffix(string(ppContent[:]), "\n")
} else if isAttachment(part) {
at, err := decodeAttachment(part)
if err != nil {
diff --git a/parsemail_test.go b/parsemail_test.go
index 3f3a825..109e734 100644
--- a/parsemail_test.go
+++ b/parsemail_test.go
@@ -296,6 +296,26 @@
textBody: `plain text part`,
},
10: {
+ contentType: `multipart/mixed; boundary="0000000000007e2bb40587e36196"`,
+ mailData: textHTMLInMultipart,
+ subject: "Re: kern/54143 (virtualbox)",
+ from: []mail.Address{
+ {
+ Name: "Rares",
+ Address: "rares@example.com",
+ },
+ },
+ to: []mail.Address{
+ {
+ Name: "",
+ Address: "bugs@example.com",
+ },
+ },
+ date: parseDate("Fri, 02 May 2019 11:25:35 +0300"),
+ textBody: ``,
+ htmlBody: "<div dir=\"ltr\"><div>html text part</div><div><br></div><div><br><br></div></div>",
+ },
+ 11: {
mailData: rfc5322exampleA12WithTimezone,
from: []mail.Address{
{
@@ -331,7 +351,7 @@
date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"),
textBody: `Hi everyone.`,
},
- 11: {
+ 12: {
contentType: "multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf",
mailData: attachment7bit,
subject: "Peter Foobar",
@@ -358,7 +378,7 @@
},
},
},
- 12: {
+ 13: {
contentType: "multipart/related; boundary=\"000000000000ab2e2205a26de587\"",
mailData: multipartRelatedExample,
subject: "Saying Hello",
@@ -743,6 +763,20 @@
--0000000000007e2bb40587e36196--
`
+var textHTMLInMultipart = `From: Rares <rares@example.com>
+Date: Thu, 2 May 2019 11:25:35 +0300
+Subject: Re: kern/54143 (virtualbox)
+To: bugs@example.com
+Content-Type: multipart/mixed; boundary="0000000000007e2bb40587e36196"
+
+--0000000000007e2bb40587e36196
+Content-Type: text/html; charset="UTF-8"
+
+<div dir="ltr"><div>html text part</div><div><br></div><div><br><br></div></div>
+
+--0000000000007e2bb40587e36196--
+`
+
var rfc5322exampleA11 = `From: John Doe <jdoe@machine.example>
Sender: Michael Jones <mjones@machine.example>
To: Mary Smith <mary@example.net>