-1

I'm having some issues with getting into sync with my Exchange account through MailKit using IMAP. I'm doing a

Inbox.Fetch(0, -1, items);

To get all mails in my inbox. This imapClient will never close, and have a timer that will do the Fetch command on every elapse. But it seems that while this client is open and running, I won't get any newly incoming emails (or get them VERY delayed). If I close my solution and start it again, it will get all the new mails right away.

Did I miss something? Does a "refresh" method exist that I missed?

grmihel
  • 784
  • 3
  • 15
  • 40

1 Answers1

1

Unfortunately, Microsoft Exchange is buggy (I remember discovering this back in the early 2000's but apparently it is still a problem).

If I recall correctly, re-opening the folder will cause Exchange to sync its new messages into the folder and then you'll be able to fetch them.

Hope that helps.

jstedfast
  • 35,744
  • 5
  • 97
  • 110
  • I already did an .Open() operation on the folder, which caused problems. Strange thing is, that I opened it as ReadOnly, and if I open it as ReadWrite, the count of mails in that folder seems to be correct?! Is this just another wierd behavior of Exchange or...?? – grmihel Apr 13 '15 at 16:01
  • Yep, just another Exchange bug. – jstedfast Apr 13 '15 at 16:11
  • A little offtopic, but can regarding the method MoveMail() in MailKit, does at always flagged the mail moved as 'DELETED' in the source folder, or does this only count if you move a mail from the inbox?? – grmihel Apr 14 '15 at 08:17
  • If the server supports the MOVE command, it uses the MOVE command which does not mark messages as \Deleted. If the server supports UIDPLUS, then it will COPY the messages, mark them as \Deleted and then UID EXPUNGE those messages making it so you could never tell that the server didn't support MOVE (effectively). If the server supports neither, then it has no choice but to leave the messages in the folder marked as \Deleted after copying them to the destination folder. – jstedfast Apr 14 '15 at 11:28
  • Okay, cool! Is there any way to check what my IMAP server support? – grmihel Apr 15 '15 at 07:55
  • 1
    Yes, check the flags set on ImapClient.Capabilities. – jstedfast Apr 15 '15 at 12:43
  • Cheers, thanks for the fast response, and great work! :) – grmihel Apr 15 '15 at 13:06
  • @jstedfast server is supporting UIDPLUS do i need to call expunge(), will the moveTo not do it for me? – coder771 Sep 29 '16 at 10:19
  • If your IMAP server supports the MOVE command, then there is no need for EXPUNGE. If the IMAP server does not support MOVE, but does support UIDPLUS, then MailKit will ImapFolder.CopyTo(), then ImapFolder.AddFlags() to mark the messages as deleted, and then it will ImapFolder.Expunge(). If that doesn't work for you, then your server does not follow standard IMAP behavior (GMail?) If you are using GMail, you need to configure your settings to behave normally. – jstedfast Sep 29 '16 at 11:11
  • You can see the code for MailKit's MoveTo() implementation here: https://github.com/jstedfast/MailKit/blob/master/MailKit/Net/Imap/ImapFolder.cs#L2974 – jstedfast Sep 29 '16 at 11:11