1
ic = new ImapClient("imap.yandex.com", Email, email.Password, AuthMethods.Login, 993, true);
var mailMessage = ic.SearchMessages(SearchCondition.From("somemail@gmail.com"), false, true).ToList();

if (mailMessage.Count > 0)
{
    foreach (Lazy<AE.Net.Mail.MailMessage> Lmail in mailMessage)
    {
        AE.Net.Mail.MailMessage mail = Lmail.Value;
        //SendSmtpMail(mail.Subject, ReplyData, Email, Password, mail.From,mail.MessageID);
        if (mail != null)
        {
            if (mail.To.FirstOrDefault(x => x.Equals(email.EmailName)) != null)
            {
                if (mail.Body.IndexOf("Attachment Name:", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    Code= Between(mail.Body, "to:", "\r");
                }
                else
                {
                    _msg.Add("CODE NOT FOUND..." + Environment.NewLine);
                }
            }
        }
    }
}

I'm using AE Mail plugin from nuget. Problem is, the following line:

AE.Net.Mail.MailMessage mail = Lmail.Value; 

took almost 1 second for lazy enumeration. This is so bothering when parsing lots of mails. Any suggestions?

croxy
  • 4,082
  • 9
  • 28
  • 46
Ayan_84
  • 645
  • 1
  • 6
  • 18
  • 2
    Lazy means that the content is loaded from the server when you start enumerating. The slowness you experience is because it has to wait for the server to transmit all emails. – Twometer Nov 06 '18 at 11:12
  • 2
    Does https://stackoverflow.com/a/21358544/34092 help @Ayan_84? – mjwills Nov 06 '18 at 11:13
  • 1
    Why do you assume *Lazy* is slow instead of the IMAP4 server? Or returing 100 emails individually? You performed a *search* on the IMAP server which only returns pointers to the messages, not the messages themselves. That's represented by the `Lazy` object. The email won't be downloaded until you request it with `Lazy.Value` – Panagiotis Kanavos Nov 06 '18 at 11:13
  • @Ayan_84 I'd suggest moving to something else as well. Returning `Lazy` is an ... unusual idea. If you check the [source code](https://github.com/andyedinborough/aenetmail/blob/master/ImapClient.cs#L804) you'll see that the method executes `Search()` synchronously to retrieve the message IDs, then wraps `GetMessage` in a `Lazy`. You could avoid all this if you wrote the `SEARCH ...` command string yourself, or used `FILTER ...`. Once you got the message IDs you could call `GetMessage()` yourself, preferably with `Task.Run()`. Frankly, there are better libraries – Panagiotis Kanavos Nov 06 '18 at 11:20
  • @Ayan_84 in fact, it looks like AE Mail is abandoned, without any updates in 3 years – Panagiotis Kanavos Nov 06 '18 at 11:21
  • Ok guys, All of your comments are useful, and I will modify the search criteria to faster the process. Thanks guys. – Ayan_84 Nov 06 '18 at 11:52

0 Answers0