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();
}