0 votes
by (8.4k 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 (17.7k 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);
...