+2 votes

I know that unlike IMAP.Get, IMAP.Peek is able to download the email and keep it as "unread" to the user.

This is a great feature and we need it, but in my case, the application needs to check the email server several times during the day and download matching emails but since they are not marked as read, they will be downloaded again until the next day when they will be (finally) filtered by the "Expression.SentSince()".

By the way, correct me if I'm wrong but the "Expression.SentSince()" does not considers the time part of the date right?

Is there a way to prevent the email to be downloaded more than once?

by (960 points)
edited by

1 Answer

0 votes
 
Best answer

Is it possible to flag email as read using IMAP.Peek

You can use Imap.MarkMessageSeenByUID and Imap.MarkMessageUnseenByUID to set or remove \Seen flag on the message stored on the IMAP server.

Correct me if I'm wrong but the "Expression.SentSince()" does not
considers the time part of the date right?

Yes, all expressions that work on dates disregard time and timezone. Have in mind that this is imposed by the IMAP specification, and the entire processing is done by the IMAP server not by an IMAP client.

Is there a way to prevent the email to be downloaded more than once?

Well, there are 2 ways:

  1. If your IMAP server supports custom flags (FolderStatus.SupportsCustomFlags returned by Imap.Select method) you can mark messages using a custom flag.
  2. Remember what UIDs have been already processed. You need to remember however that:
  • UIDs identify a message uniquely only within a folder (not on the entire server)
  • UIDs may change (if folder's UIDValidity changed)
  • UIDs are ‘supposed’ to be stable across sessions, and never change, and always increase in value. You need to check the FolderStatus.UIDValidity when you select the folder. If the FolderStatus.UIDValidity number hasn’t changed, then the UIDs are still valid across sessions.

Consider reading those 2 articles:

by (297k points)
selected by
...