0 votes
by (8.4k points)

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.0k points)
Best answer

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


// 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);