+2 votes

I have a problem that all messages on the server have the Seen flag being set. When I retrieve all messages I use GetHeadersByUIDAsync and I guess this causes the change of the Seen flag? Is this correct?

In case I'm right, do you have an idea how to get all messages without changing the flag?


1 Answer

0 votes
Best answer

You are correct GetHeadersByUIDAsync and Get methods cause \UNSEEN flag to be removed. IMAP server uses this flag to remember which messages were already read by user.

You can use PeekHeadersByUID method or any of the Peek method family.

You can also use MarkMessageSeenByUID and MarkMessageUnseenByUID to mark emails as seen/unseen:

using(Imap imap = new Imap())
    imap.Connect("imap.example.com");    // or ConnectSSL for SSL
    imap.USeBestLogin("user", "password");

    List<long> uids = client.Search(Flag.Unseen);

by (298k points)