How to limit retrieving amount of messages from IMAP?

0 votes
asked Jan 9, 2013 by Rebex KB (8,330 points)
edited Jan 9, 2013

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
answered Jan 9, 2013 by Jan Sotola (16,930 points)
edited Jan 9, 2013
 
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);
...