I have a standard routine to get an unread email from a mail server, mark it as read and then process it. It looks similar to this:
var view = new ItemView(1);
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
var findResults = ExchangeService.FindItems(WellKnownFolderName.Inbox, sf, view);
if (findResults.Items.Any())
{
EmailMessage emailMsg = findResults.Items.First() as EmailMessage;
emailMsg.IsRead = true;
emailMsg.Update(ConflictResolutionMode.AutoResolve);
ProcessMail(emailMsg);
}
This could be invoked from various processes, so I need to ensure atomicity of "find unread / mark as read" operation. In other words between Service.FindItems()
and mail.Update()
the same email could be read twice by different processes and result in duplicated processing.
Now, I don't want to get involved in discussion about storing processed email IDs or whether I should be using multiple processes accessing the same email server.
All I want to find out is if there is a EWS API method which does the two operations in one call? Ideally that would be something like this:
var mail = ExchangeService.GetFirstUnreadEmailAndMarkItAsRead()