0 votes
by (230 points)

We are using GetMessageList() to fetch the message IDs from POP3 servers. We then iterate through results calling GetMailMessage(sequenceNumber).

Problem is that the initial call to GetMessageList may consume a lot of memory - initial tests suggest the amount of memory is proportional to the number of messages in the POP3 account (although we have not memory profiled this yet).

This is a dotnet core application running in a container (similar case to https://forum.rebex.net/9846/imap-client-memory-usage-for-large-folders actually).

Is there a way to limit the number of messages returned by GetMessageList (or perhaps it could be added?).

I think we could get the mailbox size and/or number of messages and use this to decide whether to call GetMessageList - but this probably would result in a poor user experience (e.g. 'Cannot load messages because your mailbox is too big').

It might be nicer to have GetMessageList(int maxMessageCount) or similar.

We may not even need to support POP3 in our product as IMAP seems more useful in general, so this is just a preliminary question to make sure we're not missing something!

Thanks in advance,

Nick

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (73.5k points)
selected by
 
Best answer

The POP3 protocol is really old protocol. It has only couple of basic commands, see RFC 1939. It cannot do paging.

However, I thing that you do not to call GetMessageList at all. If you want to download all messages do it like this:

int count = pop3.GetMessageCount();
for (int i = 1; i <= count; i++)
{
    var mail = pop3.GetMailMessage(i);
    // do something with the message
    // ...
}

In POP3 it is ensured that the sequence numbers do not change during session (sequence numbers are numbered from 1 to GetMessageCount()).

If you want to retrieve only couple of messages, you can modify the for cycle easily:

const int PAGE_SIZE = 100;

public void GetMails(Pop3 client, int page)
{
    int count = client.GetMessageCount();

    int from = 1 + page * PAGE_SIZE;
    int to = Math.Min(from + PAGE_SIZE - 1, count);

    for (int i = from; i <= to; i++)
    {
        var mail = client.GetMailMessage(i);
        // do something with the message
        // ...
    }
}
...