Quantcast
Channel: Rebex Q&A Forum - Recent questions and answers
Viewing all articles
Browse latest Browse all 3862

Answered: POP3 limit number of messages returned by GetMessageList?

$
0
0

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
        // ...
    }
}

Viewing all articles
Browse latest Browse all 3862

Trending Articles