pkg/email: handle emails without Content-Type header

git-send-email sends emails without Content-Type,
let's assume it's text.
This commit is contained in:
Dmitry Vyukov 2018-01-24 19:37:00 +01:00
parent 9a6ff11ff9
commit 866f1102f7
2 changed files with 8 additions and 4 deletions

View File

@ -246,9 +246,14 @@ func extractArgsLine(body []byte) string {
}
func parseBody(r io.Reader, headers mail.Header) (body []byte, attachments [][]byte, err error) {
mediaType, params, err := mime.ParseMediaType(headers.Get("Content-Type"))
if err != nil {
return nil, nil, fmt.Errorf("failed to parse email header 'Content-Type': %v", err)
// git-send-email sends emails without Content-Type, let's assume it's text.
mediaType := "text/plain"
var params map[string]string
if contentType := headers.Get("Content-Type"); contentType != "" {
mediaType, params, err = mime.ParseMediaType(headers.Get("Content-Type"))
if err != nil {
return nil, nil, fmt.Errorf("failed to parse email header 'Content-Type': %v", err)
}
}
// Note: mime package handles quoted-printable internally.
if strings.ToLower(headers.Get("Content-Transfer-Encoding")) == "base64" {

View File

@ -320,7 +320,6 @@ Message-ID: <123>
Subject: test subject
From: Bob <bob@example.com>
To: syzbot <bot@example.com>, Alice <alice@example.com>
Content-Type: text/plain
#syz invalid
text body