2

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)

Diego Queiroz
  • 3,198
  • 1
  • 24
  • 36
  • The documentation for the `retr` method does not indicate the message is deleted. There is a separate method, `dele`, to flag a message for deletion, which the server is not supposed to do until after you quit the current session. Before the, you can use the `rset` method to clear any delete flags. – chepner Nov 09 '18 at 18:53

2 Answers2

4

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.)

Community
  • 1
  • 1
chepner
  • 497,756
  • 71
  • 530
  • 681
2

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.

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • "by default", which implies that there is an option to *not* remove the emails. That's what the OP is asking about. – chepner Nov 09 '18 at 18:38
  • I was aware of this, but POP3 is definitely not an option? – Diego Queiroz Nov 09 '18 at 18:39
  • 1
    @chepner: I should probably clarify that. The specification *itself* does not allow the messages to persist since it will automatically delete them. Hence the name "Post Office Protocol". The post office doesn't keep your mail around after you retrieve it, y'know... – Makoto Nov 09 '18 at 18:39
  • The metaphor does not define what the protocol makes available. – chepner Nov 09 '18 at 18:46
  • Could you cite the portion of the POPv3 spec that says a message is automatically deleted after it is retrieved? – chepner Nov 09 '18 at 18:49
  • "The post office doesn't keep your mail around after you retrieve it". Gotcha. – Diego Queiroz Nov 09 '18 at 18:53
  • @chepner Actually, in the RFC Introduction it states: "POP3 is not intended to provide extensive manipulation operations of mail on the server; normally, mail is downloaded and then deleted. A more advanced (and complex) protocol, IMAP4, is discussed in [RFC1730]." https://www.ietf.org/rfc/rfc1939.txt – Diego Queiroz Nov 09 '18 at 18:53
  • Yes? *Normally* deletes. That's talking about the use case for a client implementing the protocol, not the protocol itself. As far as I can tell, RFC1939 only says that the RETR command *retrieves* the message; it does not delete, or even flag for deletion, the retrieved message. – chepner Nov 09 '18 at 18:56
  • 3
    I won't argue against the claim that IMAP is a better protocol, but claiming that POP3 does not support retrieving a message without deleting appears to be without merit. – chepner Nov 09 '18 at 18:58
  • I agree with you. In fact, several mail clients workaround this "limitation" and allows you to keep messages in the server. So despite of this being a good answer, I won't accept it as the solution. I'd really want to know how mail clients achieve this... – Diego Queiroz Nov 09 '18 at 19:00
  • @DiegoQueiroz I expect mail clients typically send a DELE command for every message they retrieve with RETR. Any "limitation" appears to self-imposed by the clients themselves. The server is just deleting whatever messages the client tells it to delete. – chepner Nov 09 '18 at 19:08
  • Section 10 of RFC1939 even shows an example POP3 session in which a message is explicitly deleted after retrieving it, and POP3 defines an attempt to delete a message twice as an error. – chepner Nov 09 '18 at 19:11