Archived Forum Post

Index of archived forum posts

Question:

FetchBundle Performance - IMAP

Dec 17 '12 at 08:59

Essentially, I just want to make sure I'm doing the most optimal way of retrieving emails of a certain type from the mailbox. The sets can be quite large, 10000s of emails might match a specific subject, and there could be 100000s of mails in the mailbox at a given time.

Say I were to try to to fetch all emails with Subject having "undeliverable" in them.

var mailer = new Imap(); //- mail box setup //- end mail box setup mailer.SelectMailbox("Inbox"); MessageSet set = mailer.Search("SUBJECT Undeliverable", true);

bundle = mailer.FetchBundle(set); EmailBundle bundle;

This process can take a very long time - minutes doing this approach. I'm just trying figure out if there is a more optimal approach to this.


Answer

I don't think there is a more optimal way on your side (the client side).

If the Search method returns a large set of email UID's, then it might be best to write a loop that fetches them individually, to avoid memory issues or to allow for partial completion w/ the capability of resuming afterwards (such as in a case where a network failure occurs).

I've noticed that some mail servers have very poor SEARCH performance when the number of messages is very large. If the bulk of the time is spent in the SEARCH, you might look at a different overall architecture -- for example, check to see if it's possible to write a filtering rule on the server so that incoming "undeliverables" are immediately moved to a separate mailbox. You could then avoid the SEARCH altogether and just process the "undeliverables" mailbox contents.