+1 vote

I want to read the email from the server without marking them read. Currently, if I read it from the server it will mark them as a read there.

by

1 Answer

0 votes
 
Best answer

If you use Imap.GetMessageByUID to download email message (or Imap.GetHeadersByUID to get only email headers), most IMAP servers will automatically mark such messages as seen.

In other words IMAP server adds \SEEN flag to the messages you have downloaded.

If it's not an expected behavior you can use one of the **Imap.Peek**** methods, such as: *Imap.PeekHeadersByUID, Imap.PeekMessageByUID:

var eml = imap.PeekMessageByUID(uid);

IMail email = new MailBuilder().CreateFromEml(eml);

Here's the entire sample that downloads all unseen messages without changing read/unread status:

using(Imap imap = new Imap())
{
    imap.Connect("imap.server.com");
    imap.Login("user", "password");

    imap.SelectInbox();
    List<long> uidList = imap.Search(Flag.Unseen);
    foreach (long uid in uidList)
    {
        var eml = imap.PeekMessageByUID(uid);

        IMail email = new MailBuilder().CreateFromEml(eml);

        Console.WriteLine(email.Subject);
    }
    imap.Close();
}
by (297k points)
...