We are using Mail.dll to connect to an 'outlook.office365.com' mail account.
The Inbox consists of a collection of Seen and Unseen emails.
We are trying to return a list of emails that have a specific email address and have not been read. We are trying to achieve this using the where clause on the imap.Search() function.
The search returns a number of results which doesn't match whats in the search criteria.
If we interrogate the returned results we observed that all of the emails have the flag 'Seen' set.
This was working previously, we have only noticed this after moving across to Office365.
using (Imap imap = new Imap())
{
imap.ConnectSSL(InboundServerName);
imap.UseBestLogin(InboundUserName, InboundPassword);
imap.SelectInbox();
List<long> uids = imap.Search().Where(
Expression.And(
Expression.HasFlag(Flag.Unseen),
Expression.Or(
Expression.To(EmailAddress),
Expression.Cc(EmailAddress))
));
foreach (var uid in uids)
{
IMail email = new MailBuilder().CreateFromEml(
imap.PeekMessageByUID(uid));
var flags = imap.GetFlagsByUID(uid);
}
imap.Close();
}