- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 838
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
MailClient.NoOpAsync not triggering .CountChanged?!? #1288
Comments
I need more of the log to know |
@jstedfast which parts would you need? When connecting, to see what features the IMAP server has? Other than that there only are the recurring .NoOpAsync calls every minute, which don't show anything around that time - apparently since there was no mail coming in (nor sent) |
I need to see at least the SELECT or EXAMINE command and any other EXISTS/EXPUNGE notifications leading up to the one you pasted. Remember: IMAP is a state-driven protocol. That means that MailKit tracks that state. Consider the following theoretical exchange:
That wouldn't emit a CountChanged event because it was already known that 1 message existed. |
@jstedfast ok, here is the last action (it really was the prior .NoOpAsync) on this account before the one above:
And here is the last 'real' action on that account:
Does this help? |
Unfortunately I don't think it does. I'm pretty sure I have unit tests for exactly this scenario, so I was expecting something more ... unexpected I guess. |
@jstedfast thank for your feedback. Does you comment suggest you would consider this a bug in MailKit? |
No, it means that I have unit tests that test this exact scenario and those unit tests pass, thereby suggesting there is no bug in MailKit. I'm looking over the code right now and you should have gotten 2 CountChanged events. One when the server sent Are you sure that you are subscribed to the CountChanged events on this particular folder? |
@jstedfast to clarify ... may be I'm doing something wrong here:
Could that be the source of the problem? |
That shouldn't be an issue. |
@jstedfast odd .. I kinda was hoping I did screw it up there ;-) |
... to make sure we're on the same page. When working on the 'archive' folder my code does this:
|
Correct |
@jstedfast what could be done to trace down the issue? What next steps would you suggest? |
Do you log anything in your callback? Can that be tied to the protocol log? |
@jstedfast I deployed a version of my app with enhanced traces. I'll get back to you as I had more evidence... |
I've redesigned this in master to always emit CountChanged when the IMAP server sends an EXISTS notification. |
Thanks @jstedfast |
A while back we discussed MailKitLight. Is the code change available there as well? |
Yes, v3.0 will include a MailKitLite |
Great, thanks @jstedfast |
I forgot to ask: what's the ETA For 3.0? |
MailKit v3.0.0 has been released with this feature. |
Excellent! Thanks @jstedfast |
@jstedfast I just switched to MailKitLite 3.0 (from MailKit 2.X) and found that still the BouncyCastle assembly is needed upon building. A while back we discussed that you wanted to remove the BouncyCastle dependency from the MailKitLite 3.X version. Am I missing something? |
Sorry, looks like the nuget package accidentally referenced MimeKit instead of MimeKitLite Look for v3.0.0.1 |
@jstedfast hmmm ... I just updated to MailKitLite 3.0.0.1 (and have not installed MimeKitLite) and now am getting tons of these errors:
What am I doing wrong? |
try 3.0.0.2 |
Thanks that worked. I'll deploy a build shortly to see if this made a difference... |
@jstedfast unfortunately the issue still appears to exist. Here are the latest findings on the customer's account (Office 365, no CondStore support):
Appears, something prevents the relevant events being fired. Any idea what that could be? |
Are you 100% positive the server sent an EXISTS notification? |
Hmm ... I see this in my traces
Does this help? |
Is that for the Archived folder? or the INBOX? Did you subscribe to the events for that mailbox? Can you get me a full protocol log? Maybe with that, I'll be able to construct a unit test that will reproduce the issue. (Feel free to check out the ImapClient unit tests and you'll see how I can essentially replay IMAP sessions from the logs) |
This is the INBOX folder (not the ARCHIVE folder). Here is the trace file - I removed/replaced any sensitive information. Please search for "< account >", that's the account in question. |
Ok, so I think the issue is caused by the fact that you are getting disconnected and reconnecting. When that happens, the existing cache of ImapFolders is wiped out in the ImapEngine (used by the ImapClient) effectively making the ImapFolders that you have references to invalid. The reason your INBOX folder isn't getting events is because client.Inbox is a different object to the one you have a reference to once you reconnect. In other words, client.Inbox is getting the events, but you only added event handlers to the previous session's Inbox folder and so that old reference isn't getting any events. |
Thanks @jstedfast. This in fact might be the cause of trouble. I changed by code accordingly and left another donation. |
I was looking at some IMAP code last night and I remembered that I had attempted to implement "smarter" ImapFOlder caching such that if you reconnected/authenticated with the same username, it would not wipe out the cache. So I could be wrong with my diagnosis. Let me know if you are still running into problems. |
@jstedfast thanks will do as I got feedback from the customer. |
I have a customer who reports that my app would miss incoming mails.
Details:
I checked traces and found this:
2021-11-13 15:53:39:915 Mail.MailClient.NoOpAsync: mailAccount='#mail account#'
2021-11-13 15:53:39:915 Imap.C: D00000026 NOOP
2021-11-13 15:53:39:939 Imap.S: * 1 RECENT
2021-11-13 15:53:39:939 Imap.S: * 1 EXISTS
2021-11-13 15:53:39:939 Imap.S: D00000026 OK NOOP completed.
The 2 lines '1 RECENT' and '1 EXISTS' are different than the other .NoOpAsync polls which I do every minute. However, it appears they did not trigger .CountChanged (I only now added traces to confirm, so I have no hard evidence yet at this point).
Would you have any idea why .CountChanged might not have been triggered?
Thanks in advance
The text was updated successfully, but these errors were encountered: