Syntax error in BODYSTRUCTURE. Unexpected token: '('
One of our clients got fetch error with his gmail account:
This is the stacktrace:
MailKit.Net.Imap.ImapProtocolException: Syntax error in BODYSTRUCTURE. Unexpected token: ')'
at MailKit.Net.Imap.ImapUtils.ReadNStringTokenAsync(ImapEngine engine, String format, Boolean rfc2047, Boolean doAsync, CancellationToken cancellationToken)
at MailKit.Net.Imap.ImapUtils.ParseBodyAsync(ImapEngine engine, String format, String path, Boolean doAsync, CancellationToken cancellationToken)
at MailKit.Net.Imap.ImapUtils.ParseMultipartAsync(ImapEngine engine, String format, String path, String subtype, Boolean doAsync, CancellationToken cancellationToken)
at MailKit.Net.Imap.ImapUtils.ParseBodyAsync(ImapEngine engine, String format, String path, Boolean doAsync, CancellationToken cancellationToken)
at MailKit.Net.Imap.ImapFolder.FetchSummaryItemsAsync(ImapEngine engine, ImapCommand ic, Int32 index, Boolean doAsync)
at MailKit.Net.Imap.ImapEngine.ProcessUntaggedResponseAsync(Boolean doAsync, CancellationToken cancellationToken)
at MailKit.Net.Imap.ImapCommand.StepAsync(Boolean doAsync)
at MailKit.Net.Imap.ImapEngine.IterateAsync(Boolean doAsync)
at MailKit.Net.Imap.ImapEngine.RunAsync(ImapCommand ic, Boolean doAsync)
at MailKit.Net.Imap.ImapFolder.FetchAsync(IList`1 uids, MessageSummaryItems items, HashSet`1 fields, Boolean doAsync, CancellationToken cancellationToken)
It failed on this particular fetch :
IMAP | Server : * 56697 FETCH (X-GM-THRID 1563190496481790748 X-GM-MSGID 1563491715126921418 X-GM-LABELS ("\\Sent") UID 227195 RFC822.SIZE 87705 MODSEQ (10677203) INTERNALDATE "01-Apr-2017 15:51:32 +0000" FLAGS (\Seen) ENVELOPE ("Sat, 01 Apr 2017 15:51:32 +0000" "=?UTF-8?B?RndkOiDXodeo15nXp9eqINeq157Xldeg15XXqg==?=" (("..." NIL "..." "gmail.com")) (("...." NIL "..." "gmail.com")) (("... ..." NIL "..." "gmail.com")) (("[email protected]" NIL "..." "....com")) NIL NIL "<[email protected]>" "<[email protected]>") BODYSTRUCTURE ((("TEXT" "PLAIN" ("CHARSET" "UTF-8" "DELSP" "yes" "FORMAT" "flowed") NIL NIL "BASE64" 10418 133 NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "UTF-8") NIL NIL "BASE64" 34544 442 NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "94eb2c1cd0507723d5054c1ce6cb") NIL NIL)("RELATED" NIL ("ATTACHMENT" NIL) NIL)("RELATED" NIL ("ATTACHMENT" NIL) NIL)("RELATED" NIL ("ATTACHMENT" NIL) NIL)("RELATED" NIL ("ATTACHMENT" NIL) NIL) "MIXED" ("BOUNDARY" "94eb2c1cd0507723e6054c1ce6cd") NIL NIL) BODY[HEADER.FIELDS (JOB-ID KEYWORDS LIST-ARCHIVE LIST-HELP LIST-ID LIST-ID LIST-OWNER LIST-POST LIST-SUBSCRIBE LIST-UNSUBSCRIBE LIST-UNSUBSCRIBE-POST LIST-ID LIST-UNSUBSCRIBE MESSAGEID MIME-VERSION MIME-VERSION MAILING-LIST MCIPGROUP)] {21}
MIME-Version: 1.0
)
(from https://github.com/jstedfast/MailKit/issues/371)
Thanks!!
This was basically the exact same bug as issue #205, except that it had NIL instead of (...) as the Content-Type parameter list.
If this message doesn't contain secret information, it might be worth trying to report this to Google so that they can fix their MIME parser.
My guess is something about this message is confusing their parser and causing it to treat those multipart/related parts in a weird way.
🙌 thanks :) We will check the option to report this mail to google
Cool.
FWIW, I hope to make a new release probably next weekend.
Thanksgiving is going to get in the way of this weekend and I'm working on writing a lot more unit tests as well and making a lot of improvements based on those new tests. I've also been adding some new functionality based on the IMAP4rev2 specifications that are close to being published.
Okay, MASSIVE new 2.1.0 release has been pushed. I would recommend reading the ReleaseNotes.md.