Skip to content
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
9 changes: 7 additions & 2 deletions parsemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"mime"
"mime/multipart"
"mime/quotedprintable"
"net/mail"
"strings"
"time"
Expand Down Expand Up @@ -45,9 +46,11 @@ func Parse(r io.Reader) (email Email, err error) {
case contentTypeMultipartRelated:
email.TextBody, email.HTMLBody, email.EmbeddedFiles, err = parseMultipartRelated(msg.Body, params["boundary"])
case contentTypeTextPlain:
msg.Body, _ = decodeContent(msg.Body, msg.Header.Get("Content-Transfer-Encoding"))
message, _ := ioutil.ReadAll(msg.Body)
email.TextBody = strings.TrimSuffix(string(message[:]), "\n")
case contentTypeTextHtml:
msg.Body, _ = decodeContent(msg.Body, msg.Header.Get("Content-Transfer-Encoding"))
message, _ := ioutil.ReadAll(msg.Body)
email.HTMLBody = strings.TrimSuffix(string(message[:]), "\n")
default:
Expand Down Expand Up @@ -361,6 +364,8 @@ func decodeContent(content io.Reader, encoding string) (io.Reader, error) {
}

return bytes.NewReader(dd), nil
case "quoted-printable":
return quotedprintable.NewReader(content), nil
case "":
return content, nil
default:
Expand Down Expand Up @@ -483,11 +488,11 @@ type Email struct {
ResentMessageID string

ContentType string
Content io.Reader
Content io.Reader

HTMLBody string
TextBody string

Attachments []Attachment
EmbeddedFiles []EmbeddedFile
}
}
Loading