Skip to content
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

Handle missing Content-Type in multipart/alternative as plain text #47

Open
wants to merge 2 commits 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
8 changes: 6 additions & 2 deletions parsemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ func parseMultipartAlternative(msg io.Reader, boundary string) (textBody, htmlBo
return textBody, htmlBody, embeddedFiles, err
}

contentType, params, err := mime.ParseMediaType(part.Header.Get("Content-Type"))
var contentTypeHeader = part.Header.Get("Content-Type")
if len(contentTypeHeader) == 0 {
contentTypeHeader = contentTypeTextPlain
}
contentType, params, err := mime.ParseMediaType(contentTypeHeader)
if err != nil {
return textBody, htmlBody, embeddedFiles, err
}
Expand Down Expand Up @@ -490,4 +494,4 @@ type Email struct {

Attachments []Attachment
EmbeddedFiles []EmbeddedFile
}
}
2 changes: 2 additions & 0 deletions parsemail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,8 @@ Content-Type: multipart/related; boundary="000000000000ab2e2205a26de587"
--000000000000ab2e2205a26de587
Content-Type: multipart/alternative; boundary="000000000000ab2e1f05a26de586"

--000000000000ab2e1f05a26de586

--000000000000ab2e1f05a26de586
Content-Type: text/plain; charset="UTF-8"

Expand Down