Search code examples
delphiimapindy

Indy IMAP - which property to use for identifying new email messages?


Using: Delphi XE2, latest Indy snapshot from SVN (10.6.0.4997)

In the case of IMAP there are 2 properties - UID and MsgID which can be used to uniquely identify a message in a mailbox.

  1. I'm writing an email client, and need to know which is the more reliable or recommended of the two to store everytime the client connects and retrieves the message list.

  2. What sequence of steps are needed to check for new emails? I'm specifically looking for the correct sequence and set of Indy IdIMAP4 commands to get new emails.


Solution

  • Unlike POP3/SMTP, IMAP defines flags on emails. The TIdMessage.Flags property has mfRecent and mfSeen flags available (amongst others). Your client can look for emails that have mfRecent set on them, then update the flags on the server to clear mfRecent and set mfSeen as needed.