Fetch mails via POP3, but keep them on the server

1.5k views Asked by At

I'd like to fetch mails from a server, but I also want to control when to delete them.

Is there a way to do this?

I know this setting is very usual in mail clients, but it seems this option is not well supported by POPv3 specification and/or server implementations.

(I'm using python, but I'm ok with other languages/libraries, Python's poplib seems very simplistic)

2

There are 2 answers

0
chepner On BEST ANSWER

Most POP3 clients may delete successfully retrieved messages automatically, but that's a feature of the client itself, not the protocol. POPv3 supports four basic operations during the transaction phase of a session:

  1. Listing all available messages in the mailbox. (LIST)
  2. Retrieving a specific message (RETR)
  3. Flagging a message for deletion (DELE)
  4. Clearing all deletion flags (RSET)

After the client ends the session with the QUIT command, any messages still flagged for deletion are deleted during the update phase. Note, though, that the RETR command (based on my reading of RFC1939 does not flag a message for deletion; that needs to be done explicitly with the DELE command.

Note, however, that a particular POP3 server may have a policy of deleting retrieved messages, whether or not the client requested they be deleted. Whether such a server provides an operation to bypass that is beyond the scope of the protocol. (A discussion of this point is mentioned in section 8 of the RFC, but is not part of the protocol itself.)

12
Makoto On

POP3 by design downloads and removes mail from a server after it's successfully fetched. If you don't want that, then use the IMAP protocol instead. That protocol has support to allow you to delete mail at your leisure as opposed to when it's synced to your machine.