ImapClient.FetchMessage should not mark the email message as read

Hi There,

I am using Aspose.Email v21.4.0.
With the following code I am trying to get an email message from an Imap server.
Currently, if the email message is marked as read, right after FetchMessage is executed it marks it as read . Is there a way to go around it? as I don’t want to make changes on message flags, just fetching its info.

ImapClient imapClient = new ImapClient(“imap-mail.outlook.com”, “user-name”, “password”);
imapWrapper.SecurityOptions = Aspose.Email.Clients.SecurityOptions.SSLImplicit;
imapWrapper.Port = 993;
imapClient.FetchMessage(uniqueId); //let’s assume I have the right uniqueId

@Orenk9,
Thank you for posting the query. FETCH command sets the SEEN flag for messages on the IMAP server automatically. But you can reset the flag as shown below:

imapClient.RemoveMessageFlags(uniqueId, ImapMessageFlags.IsRead);

Documents: Working with Message Flags on Server
API Reference: ImapClient Class

I would like to set unread only for emails that were unread before fetching them.
Is there a way to determine whether an email message is set to be read/unread before fetching it?

@Orenk9,
Unfortunately, I found no way to check this flag. I added a ticket with ID EMAILNET-40324 in our tracking system. Our development team will investigate this possibility. I will inform you of any news.

@Orenk9,
Our development team investigated your requirements. You can use ImapClient.ListMessages method to check whether an email message with defined UniqueId is set to be read/unread. This method does not change read/unread flag of messages. Also, the ImapMessageInfo object contains other useful information.
Code example:

var messageInfoCollection = imapClient.ListMessages();
foreach (var messageInfo in messageInfoCollection)
{
    bool isRead = messageInfo.IsRead;
    string subject = messageInfo.Subject;
    string uniqueId = messageInfo.UniqueId;
}

Documents: Working with Messages from IMAP Server

@Orenk9,
You can also get information about a single message without changing the message flags using the ListMessage method:

var messageInfo = imapClient.ListMessage(uniqueId);

API Reference: ImapClient.ListMessage Method