-
Using the library's IMAP functionality, I'd like to get a number of messages in the shortest time possible. Suppose I'm searching/filtering by subject, e.g. I'm using: // search for messages using a query
var query = SearchQuery
.DeliveredAfter(DateTime.UtcNow.AddDays(-1))
.And(SearchQuery.SubjectContains("Your case file"))
.And(SearchQuery.FromContains("[email protected]"));
var soughtUniqueIds = await inbox.SearchAsync(query);
// fetch summaries for matching messages
var summaries = await inbox.FetchAsync(soughtUniqueIds, MessageSummaryItems.Envelope);
// further filter summaries using regex on subject
var filteredUniqueIds =
summaries
.Where(summary => IsRegexMatch(summary.Envelope.Subject))
.Select(summary => summary.UniqueId);
// do something with filteredUniqueIds...
// process, print, delete, etc. I compared two approaches:
I benchmarked both and received similar but unpredictable results; probably server issues and latency. Which is the "faster" approach, in theory? Or perhaps there's an even faster way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The ENVELOPE data structure is typically cached by the IMAP server (because it is both static data and designed to be commonly requested by clients), so it should theoretically be more likely to be faster than requesting headers which is going to require the server to parse each message. Obviously it all comes down to the particular implementation of the IMAP server. |
Beta Was this translation helpful? Give feedback.
The ENVELOPE data structure is typically cached by the IMAP server (because it is both static data and designed to be commonly requested by clients), so it should theoretically be more likely to be faster than requesting headers which is going to require the server to parse each message.
Obviously it all comes down to the particular implementation of the IMAP server.