pop3 email check

Hey I am trying to get my app to check a certain mailbox and download selected mails… I’ve never this did before, so I am not sure how it works or how to do it…

I am experimenting with the following procedure

-Connect
-Login
-(on login successful) Count messages
-(on count received) Retrieve headers and add them to an array
-(on top lines retrieved) Stop processing if all headers processed or retrieve following if there are headers remaining
-If finished display the array of headers in a listbox.

Basically, how do I avoid downloading all the headers of the mails in the server every time I connect there are hundreds !?
Once a message is open, should it get deleted from server ?

I imagine I should create a local db file with the headers and sort of check if they were already downloaded every time I connect ?

But if I create a DB and store the headers in it, to check if a header is stored locally i need to download the toplines (header) first… so what would be the use of storing it locally, if I have to download it anyway…

And also… once the header stored … how do I get that particular message from the server…?

Please enlighten me.
Thanks

With POP3 it’s usually assumed that you download the mails from the server and then you delete them. POP3 is really simple and old. With IMAP you have much more options, but this needs the Chilkat plugin.

There is only an index to retrieve a message: http://documentation.xojo.com/index.php/POP3Socket.RetrieveMessage

Hey Beatrix, thanks for the reply.

I know about the index… but the index is not an immutable property of the message. The same message can have different indices, if there were deleted messages… So it’s not good to identify a message…

So Outlook works like this ? Does it delete automatically every read message ?

How about pop connections to gmail acounts ?

Perhaps the mail clients check the message id in the header.

If you don’t want to download and delete, which is standard procedure for POP3 protocol, you can do what other mail clients do and maintain your own list of retrieved messages. You could do this by message id, hash of headers, or some other method of your own creation. Then you just update and maintain the list each time you connect.

This can very easily get out of hand, and as mentioned before, IMAP is better if you plan to leave messages on the server.

Not necessarily. My new email client app doesn’t do that, I give the user the option for how long to leave the mail on the server.

Perhaps that’s true with the POP3Socket, which I don’t use (I’m using the SSLSocket class). Each mail has a UID, which is unique. You ask the host for a list of UIDs, which it can send along with the index of each. You then check your database for each UID to see which ones you’ve already downloaded, and that tells you which ones you still need to download.

The command the OP wants is UIDL, which returns a list of UIDs.

The problem is that the client I am developing this for uses a pop3 account… so IMAP is discarded…

These guys use outlook to check their emails… and I am not sure how it is configured… I just need my app to “take a peek at the server” and find certain emails and let the user choose some of them, and open them… For that… do I always need to download the whole list of headers ?

I want this to happen every hour… or manually at the press of a button… but it’s taking too long.

@Kevin Windham : Kevin, my problem here is that (I am still in the testing phase) but there are like 250 headers on the server… What I want is to avoid downloading them every time… it takes 1-2 minutes… but I don’t have a wat to check for new mails if I don’t download the whole list of mails (headers)

@Tim Streater : Tim… What’sway to get the list of UID’s currently in the server ?

Depending on the requirements, using pop like this could be a problem. If they are checking the account with another client then it’s possible to have emails removed that you might want to know about in your app.

That being said, the quickest way to determine what message is what, is to use the LIST command and the message sizes given there. Depending on the server you might get more info, but it’s been a long time since I messed with POP3, so test against your particular server.

Once you have the list with the sizes you could compare with your previous list and sizes and only download headers for ones that are the same so you can differentiate. It might also be possible to look at the ordering of the sizes and infer from the ones before and after what’s what. This also is probably not guaranteed and may depend on the server.

So it really depends on your specific circumstances.

Also, it is possible on many servers to have pop and imap allowed on the same account at the same time. That may or may not help you out.

It’s too bad that the Chilkat plugin doesn’t do POP. For IMAP my app downloads the headers in bulk, which made a huge difference in speed.

Also IMAP has a mode called IDLE where you get a sort of ping when there is a new message incoming.

@Kevin Windham : Hey Kevin… Not sure I understood well… I was checking your suggestion… but found out (don’t know if it is a coincidence or what) but many email messages in a row have the same size… which make the size unusable as a unique property to identify a message…

See https://tools.ietf.org/html/rfc1939