0 votes
by (8.6k points)
edited

Is there a way to limit the amount of messages from Imap.GetMessageList as Inbox has got so large that just hanging or timing out?

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (18.1k points)
edited
 
Best answer

Yes, this is possible – use the ImapMessageSet argument to pass the desired message range.

Example:


// number of newest messages to retrieve
int limit = 10; // calculate the range
int last = _client.CurrentFolder.TotalMessageCount;
int first = Math.Max(1, last - limit); // construct an ImapMessageSet
ImapMessageSet set = new ImapMessageSet();
set.AddRange(first, last); // retrieve the messages
messages = _client.GetMessageList(set, ImapListFields.Envelope
| ImapListFields.MessageStructure
| ImapListFields.Body);
...