Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error in BODYSTRUCTURE. Unexpected token: '(' #1700

Closed
HochzeitManagement opened this issue Feb 7, 2024 · 4 comments
Closed

Syntax error in BODYSTRUCTURE. Unexpected token: '(' #1700

HochzeitManagement opened this issue Feb 7, 2024 · 4 comments
Labels
compatibility Compatibility with existing software server-bug The bug appears to be in the server

Comments

@HochzeitManagement
Copy link

HochzeitManagement commented Feb 7, 2024

Hey,
I am getting a issue with BODYSTRUCTURE parsing.

See similar error:
#1393
#777
#371

[MailKit.Net](http://mailkit.net/).Imap.ImapProtocolException HResult=0x80131500 Message=Syntax error in BODYSTRUCTURE. Unexpected token: '(' Source=MailKit StackTrace: at [MailKit.Net](http://mailkit.net/).Imap.ImapUtils.ReadNStringToken(ImapEngine engine, String format, Boolean rfc2047, CancellationToken cancellationToken) at [MailKit.Net](http://mailkit.net/).Imap.ImapUtils.ParseBody(ImapEngine engine, String format, String path, CancellationToken cancellationToken) at [MailKit.Net](http://mailkit.net/).Imap.ImapUtils.ParseMultipart(ImapEngine engine, String format, String path, CancellationToken cancellationToken) at [MailKit.Net](http://mailkit.net/).Imap.ImapUtils.ParseBody(ImapEngine engine, String format, String path, CancellationToken cancellationToken) at [MailKit.Net](http://mailkit.net/).Imap.ImapFolder.ParseSummaryItems(ImapEngine engine, MessageSummary message, FetchSummaryItemsCompletedCallback completed, CancellationToken cancellationToken) at [MailKit.Net](http://mailkit.net/).Imap.ImapFolder.UntaggedFetchSummaryItemsHandler(ImapEngine engine, ImapCommand ic, Int32 index, Boolean doAsync) at [MailKit.Net](http://mailkit.net/).Imap.ImapEngine.ProcessUntaggedResponse(CancellationToken cancellationToken) at [MailKit.Net](http://mailkit.net/).Imap.ImapCommand.Step() at [MailKit.Net](http://mailkit.net/).Imap.ImapEngine.Iterate() at [MailKit.Net](http://mailkit.net/).Imap.ImapEngine.Run(ImapCommand ic) at [MailKit.Net](http://mailkit.net/).Imap.ImapFolder.Fetch(IList1 uids, IFetchRequest request, CancellationToken cancellationToken) at MailKit.IMailFolderExtensions.Fetch(IMailFolder folder, IList1 uids, MessageSummaryItems items, IEnumerable1 headers, CancellationToken cancellationToken) at Management.Services.MailboxSyncService.Synchronization.MailboxFolderSync.<SyncMails>d__1.MoveNext() in C:\Users\konta\Source\Repos\Hochzeit.Management-DEV\Source\Management.Services.MailboxSyncService\Synchronization\MailboxFolderSync.cs:line 188 This exception was originally thrown at this call stack: [External Code] Management.Services.MailboxSyncService.Synchronization.MailboxFolderSync.SyncMails(Management.Modules.Mailing.HmImapClient, System.Guid, System.Guid, MailKit.IMailFolder, System.Collections.Generic.List<Management.Services.MailboxSyncService.Models.ContactMappingModel>) in MailboxFolderSync.cs

Using .net Framework 4.6.1
Mailkit library: v4.3.0.962

imap.log

Any ideas, if this can be fixed, or maybe even message could be ignored somehow?
Thanks

@jstedfast jstedfast added server-bug The bug appears to be in the server compatibility Compatibility with existing software labels Feb 7, 2024
@jstedfast
Copy link
Owner

Based on the exception, the issue is with parsing the BODYSTRUCTURE portion of the response.

Luckily, your log has only 1 FETCH response, so it means it has to be this:

BODYSTRUCTURE (("text" "html" ("charset" "utf-8") NIL NIL "base64" 38706 497 NIL NIL NIL ()) ("image" "jpeg" ("name" "image003.jpg") "<image003.jpg@01CD0772.E9574810>" "image003.jpg" "base64" 3446 NIL ("inline" ("filename" "image003.jpg" "size" "2782" "creation-date" "Thu, 22 Mar 2012 13:56:38 GMT" "modification-date" "Thu, 22 Mar 2012 13:56:38 GMT")) NIL ()) ("image" "jpeg" ("name" "image004.jpg") "<image004.jpg@01CD0772.E9574810>" "image004.jpg" "base64" 3446 NIL ("inline" ("filename" "image004.jpg" "size" "2782" "creation-date" "Thu, 22 Mar 2012 13:56:39 GMT" "modification-date" "Thu, 22 Mar 2012 13:56:39 GMT")) NIL ()) ("image" "jpeg" ("name" "image005.jpg") "<image005.jpg@01CD0772.E9574810>" "image005.jpg" "base64" 3232 NIL ("inline" ("filename" "image005.jpg" "size" "2625" "creation-date" "Thu, 22 Mar 2012 13:56:39 GMT" "modification-date" "Thu, 22 Mar 2012 13:56:39 GMT")) NIL ()) "related" ("boundary" "_004_7D3F5AE184118942976793FC500B8F4A402D17DB3PRD0702MB097eu_" "type" "text/html") NIL ("de-DE") NIL)

From just looking at it, I suspect the issue is the () parts. the IMAP protocol is a very LISP-like syntax and so anything in ()'s is a "list" of some type. Empty lists (at least in the IMAP specification), are generally required to be represented by a NIL instead of (), and that's probably why things are blowing up.

Any ideas, if this can be fixed, or maybe even message could be ignored somehow?

My initial assumption based on what I'm seeing in the log is that yes, this server bug can be worked around.

I'll work on a fix shortly.

@HochzeitManagement
Copy link
Author

Thanks for your fast answer and help,
here are the hole imap.log, but yes, it was just 1 Fetch.

imap.log

jstedfast added a commit that referenced this issue Feb 7, 2024
@jstedfast
Copy link
Owner

To get even more specific, the issue is with

@HochzeitManagement
Copy link
Author

Thanks for your awesome work. a 💕 Dinner for Two 💕 is on the way to you :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with existing software server-bug The bug appears to be in the server
Projects
None yet
Development

No branches or pull requests

2 participants