+1 vote

Is there a way for me to check the flag status on a particular mail object? For example I have the code below and I want to check if it's unread so that I can mark it in bold.

Sub ProcessMessage(ByVal email As IMail)
    Dim sb As New StringBuilder

    sb.Append("Subject: " + email.Subject & "<br>")
    sb.Append("From: " + JoinMailboxes(email.From) & "<br>")
    sb.Append("To: " + JoinAddresses(email.To) & "<br>")
    sb.Append("Cc: " + JoinAddresses(email.Cc) & "<br>")
    sb.Append("Bcc: " + JoinAddresses(email.Bcc) & "<br>")

    'sb.Append("Text: " + email.Text & "<hr>")
    sb.Append("HTML: " + email.Html & "<hr>")

    sb.Append("Attachments: ")
    Dim f As String = ""
    Dim x = 1


    lblResult.Text = sb.ToString
End Sub
by

1 Answer

0 votes
 
Best answer

No, it is not possible as flags are stored on the IMAP server.

IMail object represents email data only (not IMAP state of the message).

For example: IMail can be created from an email file stored on disk or downloaded from POP3 (as opposed from IMAP) server.

You need to get this information using IMAP client. You could use Imap.GetMessageInfoByUID method for instance. Then use Flags and Unseen property.

by (269k points)
I want to display a paged list of emails in the UI. Would like to bold the Unread messages. I am using the following code, but not getting the correct flag to show seen/unseen.

                    using (var imap = new Imap())
                    {
                        imap.ConnectSSL(provider.EmailServer, provider.EmailPort);   // or ConnectSSL

                        imap.SendCommand(@"ID (""GUID"" ""1"")");

                        imap.Login(provider.EmailUserName, provider.EmailPassword);

                        imap.SelectInbox();

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

                        //List<MessageInfo> infos = imap.GetMessageInfoByUID(uids);

                        List<long> uids = imap.GetAll();

                        totalMailCount = uids.Count;

                        var filter = new List<long>();

                        if (totalMailCount > pageSize)
                        {
                            filter = uids.Skip(pageNumber).Take(pageSize).ToList();
                        }
                        else
                        {
                            filter = uids;
                        }

                        List<MessageInfo> infos = imap.GetMessageInfoByUID(filter);

                        foreach (MessageInfo info in infos)
                        {
                            var item = new MailItem();

                            item.Subject = info.Envelope.Subject;
                            var from = info.Envelope.From.First();

                            item.FromEmailAddress = from.Address;
                            item.FromName = from.Name;

                            item.FromName = string.IsNullOrEmpty(item.FromName) ? item.FromEmailAddress : item.FromName;

                            item.SentDate = info.Envelope.Date.Value;
                            item.Id = (int)info.UID;
                            item.AttachmentCount = info.BodyStructure.Attachments.Count;
                            item.UIDL = info.UID.ToString();

                            list.Add(item);
                        }
                        imap.Close();
                    }


Please let me know, if I am doing this right. Or is there a better way.
Please ask a separate question.
...