public async Task GetMessagesAsync(Func <ImapMessage, AsyncRetrievalInfo, Task> func, ImapFilter filter = null, uint[] UIdsToExclude = null) { await FilterAndExclude(filter, UIdsToExclude); var asyncInfo = new AsyncRetrievalInfo() { CountRetrievedMessages = _lastRetrievedUids.Count, UniqueIds = _lastRetrievedUids.Select(x => x.Id).ToArray(), }; for (int i = 0; i < _lastRetrievedUids.Count; i++) { var mimeUid = await _client.GetMessageUid(_lastRetrievedUids[i]); var imapMsg = await mimeUid.ToImapMessage(); if (imapMsg != null) { imapMsg.MailFolder = _client.OpenedMailFolder; asyncInfo.Index = i; await func.Invoke(imapMsg, asyncInfo); } } }
private async Task FilterAndExclude(ImapFilter filter, uint[] UIdsToExclude) { _lastRetrievedUids = await _client.GetUIds(filter); if (UIdsToExclude != null && UIdsToExclude.Length > 0) { _lastRetrievedUids = _lastRetrievedUids.Where(x => !UIdsToExclude.Contains(x.Id)).ToList(); } if (filter?.LimitResults > 0) { _lastRetrievedUids = _lastRetrievedUids.Take(filter.LimitResults).ToList(); } }
public async Task <List <ImapMessage> > GetMessages(ImapFilter filter = null, uint[] UIdsToExclude = null) { var results = new List <ImapMessage>(); await FilterAndExclude(filter, UIdsToExclude); var mimeMsgs = await _client.GetMessageUids(_lastRetrievedUids); foreach (var mime in mimeMsgs) { var imapMsg = await mime.ToImapMessage(); imapMsg.MailFolder = _client.OpenedMailFolder; results.Add(imapMsg); } return(results); }
public async IAsyncEnumerable <ImapMessage> GetMessagesAsync(ImapFilter filter = null, uint[] UIdsToExclude = null) { await FilterAndExclude(filter, UIdsToExclude); for (int i = 0; i < _lastRetrievedUids.Count; i++) { var mimeUid = await _client.GetMessageUid(_lastRetrievedUids[i]); var imapMsg = await mimeUid.ToImapMessage(); if (imapMsg != null) { imapMsg.MailFolder = _client.OpenedMailFolder; yield return(imapMsg); } } }
public async Task GetMessagesAsync(Func <ImapMessage, Task> func, ImapFilter filter = null, uint[] UIdsToExclude = null) { await FilterAndExclude(filter, UIdsToExclude); foreach (var uId in _lastRetrievedUids) { var mimeUid = await _client.GetMessageUid(uId); var imapMsg = await mimeUid.ToImapMessage(); if (imapMsg != null) { imapMsg.MailFolder = _client.OpenedMailFolder; await func.Invoke(imapMsg); } } }