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.