Exemplo n.º 1
0
        public async Task <List <MimeMessage> > GetMessages(IMailFolder sourceFolder, SearchQuery query, CancellationToken ct)
        {
            return(await PolicyWrapper.WrapRetryOnNotConnected(async() =>
            {
                await sourceFolder.OpenAsync(FolderAccess.ReadOnly).ConfigureAwait(false);
                var uids = (await sourceFolder.SearchAsync(query).ConfigureAwait(false))
                           .Take(10); // TODO Only for test for better performance

                var messages = new List <MimeMessage>();
                foreach (var uid in uids)
                {
                    if (ct.IsCancellationRequested)
                    {
                        break;
                    }
                    try
                    {
                        var msg = await sourceFolder.GetMessageAsync(uid).ConfigureAwait(false);
                        messages.Add(msg);
                    }
                    catch (FolderNotOpenException)
                    {
                        break;
                    }
                }
                return messages;
            },
                                                               EnsureConnected).ConfigureAwait(false));
        }
Exemplo n.º 2
0
 public async Task <IEnumerable <IMailFolder> > GetSubFolders(IMailFolder parentFolder)
 {
     return(await PolicyWrapper.WrapRetryOnNotConnected(async() =>
     {
         return await parentFolder.GetSubfoldersAsync().ConfigureAwait(false);
     },
                                                        EnsureConnected).ConfigureAwait(false));
 }
Exemplo n.º 3
0
 public async Task <IList <IMailFolder> > GetFolders()
 {
     return(await PolicyWrapper.WrapRetryOnNotConnected(async() =>
     {
         var ns = Client.PersonalNamespaces?[0] ?? Client.OtherNamespaces?[0] ?? Client.SharedNamespaces?[0];
         if (ns == null)
         {
             throw new InvalidOperationException("No folder namespace found");
         }
         return await Client.GetFoldersAsync(ns).ConfigureAwait(false);
     },
                                                        EnsureConnected).ConfigureAwait(false));
 }