From 161569708a0cf8ba078767934e384f0fd0c3bf6a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 24 Jul 2019 22:27:35 +0300 Subject: [PATCH] imap: fix FETCH BODY[N] --- imap/message.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/imap/message.go b/imap/message.go index 7a769b6..c0d4428 100644 --- a/imap/message.go +++ b/imap/message.go @@ -348,10 +348,19 @@ func (mbox *mailbox) fetchBodySection(msg *protonmail.Message, section *imap.Bod return nil, err } - if section.Specifier == imap.TextSpecifier { + switch section.Specifier { + case imap.TextSpecifier: + // The header hasn't been requested. Discard it. b.Reset() + case imap.EntireSpecifier: + if len(section.Path) > 0 { + // When selecting a specific part by index, IMAP servers + // return only the text, not the associated MIME header. + b.Reset() + } } + // Write the body, if requested switch section.Specifier { case imap.EntireSpecifier, imap.TextSpecifier: r, err := getBody()