This project is read-only.

Get only unflagged messages


I have a Windows service using the AE.Net.Mail IMAP client with G-mail. The service runs every x minutes, retrieves inbox messages, applies some business logic, and marks them as deleted. This all works.

However, Gmail leaves them in the inbox so subsequent calls fetch them again. I can skip them by looking at the Seen or Deleted flags but I'd rather not get them at all. Unless someone goes in and cleans up the inbox frequently fetches will grow exponentially.

I've experimented with Gmails expunge options but they don't seem to have any effect.


jstedfast wrote Jul 23, 2014 at 12:00 PM

I would recommend using my MailKit library and using the following technique:

When you connect to the IMAP server, keep track of the most recent UID of the messages that you download as well as the folder's UIDVALIDITY value.

The next time you connect, check that the UIDVALIDITY values match and, if so, you can start downloading messages with a higher UID than the last one you downloaded in a previous session.

If you need help figuring out how to do this in MailKit, let me know and I'll give you a hand.