From 83620124829998ba57a260c4bc1692746d4eb594 Mon Sep 17 00:00:00 2001 From: Mykola Terelia Date: Fri, 20 May 2022 00:58:59 +0300 Subject: [PATCH 1/2] inbound.Parse: fix panic when Content-Type is not multipart --- helpers/inbound/inbound.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/helpers/inbound/inbound.go b/helpers/inbound/inbound.go index 3c688fca..9d9053d7 100644 --- a/helpers/inbound/inbound.go +++ b/helpers/inbound/inbound.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "mime" "mime/multipart" + "mime/quotedprintable" "net/http" "strings" ) @@ -168,6 +169,26 @@ func (email *ParsedEmail) parseRawEmail(rawEmail string) error { return err } + // if Content-Type is not multipart just set the whole email + if raw == nil { + if len(sections) < 2 { + return nil + } + + wholeEmail := sections[1] + // decode if needed + if email.Headers["Content-Transfer-Encoding"] == "quoted-printable" { + decoded, err := ioutil.ReadAll(quotedprintable.NewReader(strings.NewReader(wholeEmail))) + if err != nil { + return fmt.Errorf("failed to decode quoted-printable: %w", err) + } + wholeEmail = string(decoded) + } + + email.Body[email.Headers["Content-Type"]] = wholeEmail + return nil + } + for { emailPart, err := raw.NextPart() if err == io.EOF { From 6d23f68fa4d66a8c6d411c574d2645e566c3de56 Mon Sep 17 00:00:00 2001 From: Mykola Terelia Date: Fri, 20 May 2022 01:11:33 +0300 Subject: [PATCH 2/2] drop err msg --- helpers/inbound/inbound.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/inbound/inbound.go b/helpers/inbound/inbound.go index 9d9053d7..6f9a07c5 100644 --- a/helpers/inbound/inbound.go +++ b/helpers/inbound/inbound.go @@ -180,7 +180,7 @@ func (email *ParsedEmail) parseRawEmail(rawEmail string) error { if email.Headers["Content-Transfer-Encoding"] == "quoted-printable" { decoded, err := ioutil.ReadAll(quotedprintable.NewReader(strings.NewReader(wholeEmail))) if err != nil { - return fmt.Errorf("failed to decode quoted-printable: %w", err) + return err } wholeEmail = string(decoded) }