Email client question

BlitzPlus Forums/BlitzPlus Programming/Email client question

JoshK(Posted 2005) [#1]
How do you tell which messages to skip, if you have already downloaded email, but left it on the server? Each email has a unique messageid, but to get that, you have to download the message's header.


BlitzSupport(Posted 2005) [#2]
You'd have to keep a list within your client, I think. I did a POP3 downloader that can download a particular message using its index number, but I'm not sure if they get renumbered when an email is deleted. The only other option I'm aware of would be to scan the headers like you say... POP3 servers are pretty dumb.

I guess you could store each read email's index and messageid in a list and check against it when trying to download email number 'x', only checking all the headers for the messageid if it doesn't match -- this may help to answer the question of whether they're renumbered when one is deleted.


JoshK(Posted 2005) [#3]
Yeah, but what if another email program deletes an email, or if you check your mail online and delete something?


BlitzSupport(Posted 2005) [#4]
Good point... I guess you're limited to scanning the headers. From what I remember reading, POP3 servers don't have an awful lot of capabilities, anyway. Here's the POP3 command summary from the relevant RFC (official documented protocol):


9. POP3 Command Summary

Minimal POP3 Commands:

USER name valid in the AUTHORIZATION state
PASS string
QUIT

STAT valid in the TRANSACTION state
LIST [msg]
RETR msg
DELE msg
NOOP
RSET
QUIT

Optional POP3 Commands:

APOP name digest valid in the AUTHORIZATION state

TOP msg n valid in the TRANSACTION state
UIDL [msg]

POP3 Replies:

+OK
-ERR

Note that with the exception of the STAT, LIST, and UIDL commands,
the reply given by the POP3 server to any command is significant
only to "+OK" and "-ERR". Any text occurring after this reply
may be ignored by the client.



Ah... the UIDL command might do it, but that's optional for POP3 servers to support, though most probably do by now. You'd presumably have to check it gets a valid response, and default to header scanning if not available. From a quick Google, it looks like you pass a message number and it returns the unique ID, or pass nothing for (all?) unique IDs.

Some guy in this thread says:


This isn't actually the case. POP3 has extended command UIDL, which returns you a list of unique identifiers (just like LIST returns the sizes of messages). After this, you only need to check the UID with stored UIDs of the messages you've already downloaded. This is quite fast even with thousands of messages.

The downside is that not all servers provide UIDL-command since it's not required by the standard. If this is the case, the only solution is to download message headers (using command like TOP) only and comparing them to headers already received. This takes somewhat longer
(but not as long as it'd take to download the whole messages) and isn't as reliable as using UIDs.




JoshK(Posted 2005) [#5]
Thanks.