+1 vote

When I use:

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

hiewver, it marks the emails as read.
I need to obtain the IDs without marking them as read.

I'm using Mail.dll version 3.0.

by

1 Answer

0 votes
 
Best answer

IMAP SEARCH shouldn't change the seen/unseen status of an email.

Are you absolutely sure that your server does that?

Most likely it's the subsequent Imap.GetMessage call that does that.

Use Imap.PeekMessage instead of Imap.GetMessage in order to prevent that:

using(Imap client = new Imap())
{
    client.ConnectAAL("imap.example.com");
    client.UseBestLogin("user", "password/app password"); 
    // client.LoginOAUTH2(user, accessToken)

    client.SelectInbox();

    List<long> uidList = imap.Search(Flag.Unseen);

    foreach (long uid in uidList)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(client.PeekMessageByUID(uid));

        string subject = email.Subject;
    }
    client.Close();
}
by (300k points)
...