Sep 30, 2014 at 4:28 PM
Edited Sep 30, 2014 at 4:29 PM
I see several areas which could be causing some performance problems depending on how many messages this is operating on.
First, the following line of code may be inefficient:
List<int> all_ids = inbox.Search("ALL").ToList();
You don't need
that to be a list, you can use an enumerator in your foreach loop like this:
foreach (int item in inbox.Search("ALL"))
The odds of this being a major point of slowness in your code is minimal, however.
More than likely the problem is just network slowness, but MailSystem.NET's MIME parser is also pretty slow from my own testing.
I wrote my own parser (MimeKit
) which is almost 2 orders of magnitude faster (2 orders of magnitude meaning almost 100x faster... it actually comes out to something like 75x faster).
When MailSystem.NET did not want to use my parser, I wrote my own IMAP library (which is also more efficient than MailSystem.NET's IMAP implementation as well as being far more robust and standards-compliant) called
Hope that helps.