Exception on IMapFolder.FetchAsync
DierkDroth opened this issue · comments
@jstedfast I found some exceptions on my server (which handles a couple of customer mail accounts):
Mail.MailClient.MessageFlagsChangedDeferred.Exception: mailAccount='email' index=41 System.ArgumentOutOfRangeException: Non-negative number required. (Parameter 'capacity')
at System.Collections.Generic.List`1..ctor(Int32)
at MailKit.Net.Imap.ImapFolder.FetchAsync(Int32, Int32, IFetchRequest, Boolean, CancellationToken)
at Unusual.Mail.MailClient.<>c__DisplayClass55_1.<<SubscribeMailFolderEvents>b__5>d.MoveNext() | (email) Mail.MailClient.MessageFlagsChangedDeferred.Exception:
mailAccount='email' index=41 System.ArgumentOutOfRangeException: Non-negative number required. (Parameter 'capacity')
at System.Collections.Generic.List`1..ctor(Int32)
at MailKit.Net.Imap.ImapFolder.FetchAsync(Int32, Int32, IFetchRequest, Boolean, CancellationToken) at Unusual.Mail.MailClient.<>c__DisplayClass55_1.<<SubscribeMailFolderEvents>b__5>d.MoveNext()
The logic above is part of the inboxFolder.MessageFlagsChanged
handling.
As you can see the index in fact is >= 0. Hence, I wonder where this exception is coming from. I have a suspicion that the mail which I'm trying to reference by that index no longer exists in the IMapFolder since the customer deleted or moved the mail.
Could you confirm/deny that suspicion?
No, the exception is because MailKit is trying to call new List<T> (-1)
(or a negative value of some kind).
Which version is this?
Nevermind, I see what is happening... your max value must be > folder.Count?
Nevermind, I see what is happening... your max value must be > folder.Count?
This is what I suspected ... and confirms my speculation. I believe this is a race condition in the actual use case. I will have to look into ... thanks @jstedfast
To double check: the index
is 0-based and not 1-based correct. So, index >= folder.Count
would be the condition to check for, no?
Correct
Hi, I'm having a problem with fetching email with same content, like subject and body but different UID and message-id, Resulting to Entry Duplication