public Task BeginDownloadInboxAsync(CancellationToken token)
        {
            return(Task.Factory.StartNew(() =>
            {
                using (var pop3 = new Pop3())
                {
                    ConnectAndLogin(pop3);
                    var allUids = pop3.GetAll();
                    var chunkUids = Common.SplitList(allUids, 5);
                    var builder = new MailBuilder();

                    foreach (var uids in chunkUids)
                    {
                        var items = new List <EmailItem>();
                        foreach (var uid in uids)
                        {
                            var bytes = pop3.GetHeadersByUID(uid);
                            IMail email = builder.CreateFromEml(bytes);
                            items.Add(ParseIMail(uid, email));
                        }
                        ItemsDownloaded?.Invoke(this, items);
                    }
                }
            }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default));
        }
Exemplo n.º 2
0
 public Task BeginDownloadInboxAsync(CancellationToken token)
 {
     return(Task.Factory.StartNew(() =>
     {
         using (var imap = new Imap())
         {
             ConnectAndLogin(imap);
             imap.SelectInbox();
             var allUids = imap.GetAll();
             var chunkUids = Common.SplitList(allUids, 5);
             foreach (var uids in chunkUids)
             {
                 List <MessageInfo> infos = imap.GetMessageInfoByUID(uids);
                 var items = infos.Select(x => ParseMessageInfoToEmail(x)).ToList();
                 ItemsDownloaded?.Invoke(this, items);
             }
         }
     }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default));
 }