Skip to content

Commit

Permalink
Merge pull request #19 from k-yomo/support-html-in-multipart-mixed
Browse files Browse the repository at this point in the history
Add support for html in multipart/mixed
  • Loading branch information
DusanKasan committed Apr 30, 2020
2 parents 1ce83dc + 2e670d9 commit d916cfb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
7 changes: 7 additions & 0 deletions parsemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ func parseMultipartMixed(msg io.Reader, boundary string) (textBody, htmlBody str
}

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 {
Expand Down
38 changes: 36 additions & 2 deletions parsemail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@ So, "Hello".`,
textBody: `plain text part`,
},
10: {
contentType: `multipart/mixed; boundary="0000000000007e2bb40587e36196"`,
mailData: textHTMLInMultipart,
subject: "Re: kern/54143 (virtualbox)",
from: []mail.Address{
{
Name: "Rares",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
},
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{
{
Expand Down Expand Up @@ -331,7 +351,7 @@ So, "Hello".`,
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",
Expand All @@ -358,7 +378,7 @@ So, "Hello".`,
},
},
},
12: {
13: {
contentType: "multipart/related; boundary=\"000000000000ab2e2205a26de587\"",
mailData: multipartRelatedExample,
subject: "Saying Hello",
Expand Down Expand Up @@ -743,6 +763,20 @@ plain text part
--0000000000007e2bb40587e36196--
`

var textHTMLInMultipart = `From: Rares <[email protected]>
Date: Thu, 2 May 2019 11:25:35 +0300
Subject: Re: kern/54143 (virtualbox)
To: [email protected]
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 <[email protected]>
Sender: Michael Jones <[email protected]>
To: Mary Smith <[email protected]>
Expand Down

0 comments on commit d916cfb

Please sign in to comment.