From 24c1789ea22ee9df211af88cd10828d2018a70fb Mon Sep 17 00:00:00 2001 From: Mikita Shchyhelski Date: Mon, 5 Sep 2022 12:31:10 +0200 Subject: [PATCH] This fix includes simple change, where we initially check whether part is the attachments. Rather doing that in the last step, otherwise attachments with mimetype of text/html would not be extracted out of the eml file --- parsemail.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/parsemail.go b/parsemail.go index 6a60192..04079d1 100644 --- a/parsemail.go +++ b/parsemail.go @@ -227,6 +227,16 @@ func parseMultipartMixed(msg io.Reader, boundary string) (textBody, htmlBody str return textBody, htmlBody, attachments, embeddedFiles, err } + if isAttachment(part) { + at, err := decodeAttachment(part) + if err != nil { + return textBody, htmlBody, attachments, embeddedFiles, err + } + + attachments = append(attachments, at) + continue + } + contentType, params, err := mime.ParseMediaType(part.Header.Get("Content-Type")) if err != nil { return textBody, htmlBody, attachments, embeddedFiles, err @@ -256,13 +266,6 @@ func parseMultipartMixed(msg io.Reader, boundary string) (textBody, htmlBody str } htmlBody += strings.TrimSuffix(string(ppContent[:]), "\n") - } else if isAttachment(part) { - at, err := decodeAttachment(part) - if err != nil { - return textBody, htmlBody, attachments, embeddedFiles, err - } - - attachments = append(attachments, at) } else { return textBody, htmlBody, attachments, embeddedFiles, fmt.Errorf("Unknown multipart/mixed nested mime type: %s", contentType) } @@ -483,11 +486,11 @@ type Email struct { ResentMessageID string ContentType string - Content io.Reader + Content io.Reader HTMLBody string TextBody string Attachments []Attachment EmbeddedFiles []EmbeddedFile -} \ No newline at end of file +}