jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.

Home Page:http://www.mimekit.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syntax error in MODSEQ. Unexpected atom token: -1

HochzeitManagement opened this issue · comments

Hey guys,

One of our users calls his mailbox 1-2 times an hour. Most of the time it works without any problems. Sometimes, however, the following error occurs:

  • OS: Windows
  • .NET Framework: .NET 4.6.2
  • MailKit Version: 3.1.1 (i know, its old, we will update it soon)

Can you help us? Thanks
`
-------Inner 1------
Syntax error in MODSEQ. Unexpected atom token: -1

------Stack Trace:-----
bei MailKit.Net.Imap.ImapEngine.ParseNumber64(ImapToken token, Boolean nonZero, String format, Object[] args) in D:\src\MailKit\MailKit\Net\Imap\ImapEngine.cs:Zeile 586.
bei MailKit.Net.Imap.ImapFolder.d__179.MoveNext() in D:\src\MailKit\MailKit\Net\Imap\ImapFolderFetch.cs:Zeile 328.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei MailKit.Net.Imap.ImapFolder.d__180.MoveNext() in D:\src\MailKit\MailKit\Net\Imap\ImapFolderFetch.cs:Zeile 435.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
bei MailKit.Net.Imap.ImapEngine.d__174.MoveNext() in D:\src\MailKit\MailKit\Net\Imap\ImapEngine.cs:Zeile 2023.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
bei MailKit.Net.Imap.ImapCommand.d__83.MoveNext() in D:\src\MailKit\MailKit\Net\Imap\ImapCommand.cs:Zeile 865.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei MailKit.Net.Imap.ImapEngine.d__175.MoveNext() in D:\src\MailKit\MailKit\Net\Imap\ImapEngine.cs:Zeile 2138.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei MailKit.Net.Imap.ImapEngine.d__176.MoveNext() in D:\src\MailKit\MailKit\Net\Imap\ImapEngine.cs:Zeile 2162.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei MailKit.Net.Imap.ImapFolder.d__194.MoveNext() in D:\src\MailKit\MailKit\Net\Imap\ImapFolderFetch.cs:Zeile 1126.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei MailKit.Net.Imap.ImapFolder.Fetch(Int32 min, Int32 max, IFetchRequest request, CancellationToken cancellationToken) in D:\src\MailKit\MailKit\Net\Imap\ImapFolderFetch.cs:Zeile 1194.
bei MailKit.IMailFolderExtensions.Fetch(IMailFolder folder, Int32 min, Int32 max, MessageSummaryItems items, CancellationToken cancellationToken) in D:\src\MailKit\MailKit\IMailFolderFetchExtensions.cs:Zeile 1540.
bei Management.Services.MailboxSyncService.Synchronization.MailboxFolderSync.d__1.MoveNext() in C:\Projects\Hochzeit.Management-DEV\Source\Management.Services.MailboxSyncService\Synchronization\MailboxFolderSync.cs:Zeile 83.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
bei Management.Services.MailboxSyncService.Synchronization.MailboxSync.<>c__DisplayClass4_0.<b__2>d.MoveNext() in C:\Projects\Hochzeit.Management-DEV\Source\Management.Services.MailboxSyncService\Synchronization\MailboxSync.cs:Zeile 169.
`

Hard to know for sure based on just a stacktrace (I'd need a protocol log), but it looks like the IMAP server tried to send -1 as a MODSEQ value which is defined by the IMAP specifications as a non-zero unsigned 64-bit integer (i.e. it can't be a negative value or 0).

I've taken a look at the code, and assuming that my theory is correct, 4.3.0 will also throw this exception in this scenario.

If you could get a protocol log for this scenario, I will take a look and see if I can implement an appropriate work-around to avoid throwing an exception.

Can you confirm that subsequent connections for this customer seem to work? I am wondering if this happens if the IMAP server hasn't yet assigned a MODSEQ value or something (i.e. there is some sort of inconsistent state in the IMAP server and this causes it to write -1 for the MODSEQ value instead of a real value).

If this is the case, I think the appropriate work-around might be to treat -1 as if a value wasn't sent at all (in other words, treat it as if a MODSEQ value was not present at all).

The other possibility that I can think of is that the IMAP server is using a 32-bit int instead of a 64-bit unsigned int and the IMAP server code is suffering from an integer overflow bug, making it such that we might have to treat -1 as a valid value (which might get complicated).

Would be good to know what the IMAP greeting is as well, so I can add it to my list of server-dependent work-arounds.

FWIW, the ProtocolLogger defaults to redacting authentication secrets starting with MailKit v3.1.0, so you won't need to do anything special to hide those if you get a log.

All I really need from the log is the first line after the "Connected to ..." message and the line matching * # FETCH (... MODSEQ -1 ...) (if there is one - I mostly just need this to be confirmed).

I'm pretty confident (~99%?) that there will be a response line with MODSEQ -1, but I am not 100% certain.

@jstedfast so sorry, I haven't had time yet as I need to check this locally. hope to get to it quickly. thanks.

imap-mailkit.log
here the imap log. is it helpful for you? what can we do? thanks

@HochzeitManagement yes, this log is perfect! Thank you.

S: * 39 FETCH (MODSEQ (0) FLAGS (\Recent \Seen) UID 290)
S: * 40 FETCH (MODSEQ (-1) FLAGS (\Recent \Seen) UID 336)

Sure enough, the IMAP server is sending us a value of -1. It's also sending us a value of 0 which I think is illegal, but MailKit already handles that.

I'll work on writing up a work-around now that we have verified that it really was sending -1.