C# – OpenPop.NET : Pop3Client : How to get only the new emails

cclientemailpop3

Is there a way to fetch only the new emails from the mail server (e.g. when you store the fetched emails locally) instead of fetching all of them?

I guess I could fetch emails in bunches of 5 and compare, for example, the hash of the last email (or its Uid from Pop3Client.GetMessageUid()) to the hash of the fetched emails, but I am not sure if this is the best and most reliable way. I think this will be a waste of bandwidth or bombarding the server with multiple requests.

Does the protocol allow specifying a point in time (using date, last email hash or whatever), after which it should return the emails?

Currently, I am using OpenPop.NET's OpenPop.Pop3.Pop3Client.

EDIT

I have found an example here:
http://hpop.sourceforge.net/exampleDownloadUnread.php
Although it doesn't suit my needs 100% (because it fetched ALL UIDs which may be too many) it is a good starting point.

Basically, what I want to do is what this IMAP sample does by comparing UIDs:

http://www.limilabs.com/blog/get-new-emails-using-imap

EDIT 2

I have found this similar question, but it also suggest the approach that retrieves ALL UIDs:

How to retrieve only new emails using POP3 protocol

Best Answer

You'll need to download all of the UIDs no matter what you do because you'll need to compare them to what you've already downloaded (in some sort of UID log) as well as having the UIDs of the new messages so that you can log them to compare against the next time you connect.

It should be noted, however, that not all POP3 servers support the UIDL command (it is an extension, after all), so if your code is meant to be used with a variety of POP3 servers, it will have to deal with that. How you deal with it is up to you, but I believe that my approach in the past has been to md5sum a collection of headers (although not all of them, because some POP3 servers might add or modify headers such as X-Status or Status or some custom header). You can probably get away with just hashing the Received headers.