Hi
We want to read all unread emails from a mailbox folder in an exchange server, and mark them as read. Now we uses the following code snippet to filter the unread emails, where client is an exchange client (WebDAV or EWS) object.
var msgCollection = client.ListMessages(folderUri);
if (msgCollection == null || !msgCollection.Any()) return;
var unreadMsgCollection = (from msg in msgCollection
where (!msg.IsRead)
select msg).ToList();
This piece of code has a problem: in case that folder has 1000 emails, where 50 are unread, the msgCollection contains all the 1000 msgInfo, which seems to be a waste of memory. ImapClient can filter unread emails using a query like “(‘Seen’ = ‘False’)”, but I did not find similar methods in exchangeClient.
I thought of using
while (some condition)
{
var msgCollection = client.ListMessages(folderUri, 50);
// filter unread emails in msgCollection
…
}
I am afraid that the msgCollection will always be the same 50 emails since it downloads lastest 50 emails. Then I have no way to read the rest 950 emails unless I move the messages to other folder.
Please let me know whether I am correct. Thanks.
Xu