Reputation: 129
What is the best way to receive messages from a POP3 Server? We have to build the POP3 Receiver client only and not the server. So we don't know the behavior of the server(eg: when the server deletes the messages etc).
I know of the following options, but I am not able to present the case with proper reason. Please help.
1.UUIDs. Are there any performance impacts of this if we save all the UUIDs?
With Flag.deleted, we delete the messages from the server. So everytime we poll the server we will get the latest message only. But some POP3 servers save the mails, so wont it be wrong if we delete the mails from server?
I save mails in the db. So, I have a count of all received messages. This is what is implemented. Take a count of received mails from the db(x). Take the latest count of mail from the pop3 folder(y). Then retrieve the mail from (y-x+1) to y. This is what we have implemented.
Get the list of headers from the folder. Get the list of headers after a particular date, and compare it with the list of UUIDs for say a last few couple of days. Get the data for the remaining UUIDs from the folder. I think this is the best. But will there be performance issues because of this?
Any help would be appreciated. Thank you!
Note: I am using javamail!
Upvotes: 0
Views: 842
Reputation: 29961
There's a lot of "diversity" in POP3 servers, so you may have to use different strategies with different servers.
It sounds like you just want to use the POP3 server as a "mail drop", extracting all the messages from the server and saving them elsewhere. This usually works pretty well if you're sure your program is the only one removing messages from the POP3 folder. Copy the message out of the folder, mark them deleted, and close the folder. The biggest complication is handling failure. You might want to keep track of the UUIDs of the messages in the folder until you're sure they've been deleted from the folder so you know which ones you've already copied. If your program or the server fails before you copy and delete all the messages, you can pick up where you left off.
If other programs are reading messages from the same POP3 folder, this all becomes more complicated.
Upvotes: 1