Archived Forum Post

Index of archived forum posts

Question:

NumMessages Not Working?

Feb 16 '15 at 08:51

Hi Guys,

I've got a weird one here. I connect to a user's mailbox, iterate through each folder and ask for the number of items in each folder using NumMessages...but it's proving to be 'temperamental'. For several folders it returns 0 when there are definitely emails in the folder. No errors are getting generated when I connect to the mailbox (or folder) and, as far as I can tell, nothing is blowing up or causing any exceptions (I check after connecting to each folder). I'm running v9.5.0.47 of the IMAP controls and this is against a Gmail mailbox.

Not sure whether it's connected or not but some folders where I have found emails (i.e. NumMessages returned the correct number), when I delete those emails (by using the SetMailFlag method to set the Deleted flag for each email and then calling ExpungeAndClose method) they don't get deleted. Again, no errors are being generated or exceptions thrown and the methods are returning 'success'.

This is all code that has been working fine in the past and has been tested against Gmail, Office365 and Exchange without any problems.

Any ideas?


Answer

Set the Imap.KeepSessionLog property = true, then examine the contents of the Imap.SessionLog property after the method calls and property accesses of interest have been called..

In other words -- look to see what transpired.. :)


Answer

Very strange as I added that to my code (really useful BTW - I didn't know the controls could do that) and it revealed that everything was OK when it came to the NumMessages and deleting emails and both now seem to be working.

The only difference that I can find is that the user who was having problems took the afternoon off. Nothing too strange in that except that he uses Google's sync tools to connect Outlook to his GMail account. Could that be causing problems?


Answer

I've dug into this and the problem does look to be Google's sync tools - emails are showing in Outlook which aren't on the Gmail server (e.g. going via Gmail rather than Outlook). This explains why Chilkat is returning different email counts to what the user in question is seeing.

No idea what the long-term solution is but, hopefully, this'll save anyone else banging their head against it.


Answer

See this: http://www.cknotes.com/understanding-gmails-behavior/