skip to content

Under RFC 1939, when does a POP3 DELE actually remove a message, and what happens if the connection drops before QUIT?

level: middleimportance: should knowfreq 34%

answer

  1. mark now, remove later
  2. three session states
  3. only QUIT from TRANSACTION
  4. abnormal end removes nothing

basics

~20 s

DELE only marks a message; the server removes marked messages when QUIT moves the session from TRANSACTION into the UPDATE state. If the connection drops or times out first, the session never enters UPDATE and nothing is removed.

solid answer

~40 s

RFC 1939 runs every POP3 session through three states: **AUTHORIZATION** (log in), **TRANSACTION** (work on the maildrop) and **UPDATE** (commit and close). In TRANSACTION, `DELE n` only marks message `n`: it disappears from `STAT` and `LIST` and further references to it fail, and `RSET` can unmark it. The server removes marked messages only when the client sends `QUIT` from TRANSACTION, which enters UPDATE. If the session ends any other way — a dropped connection, a crashed client, the server's autologout timer (at least 10 minutes) — RFC 1939 says the session does NOT enter UPDATE and MUST not remove any messages. `QUIT` from AUTHORIZATION also skips UPDATE. The design protects mail a client may not have stored; its cost is that the next session sees those messages again, so a careless client downloads duplicates.

code

plaintext · 21 lines
plaintext
S: +OK POP3 server ready
C: USER alice
S: +OK
C: PASS ...
S: +OK maildrop has 3 messages (8420 octets)
C: STAT
S: +OK 3 8420
C: RETR 1
S: +OK 2210 octets
S: <message 1>
S: .
C: DELE 1
S: +OK message 1 deleted
C: STAT
S: +OK 2 6210
C: RSET
S: +OK maildrop has 3 messages (8420 octets)
C: DELE 1
S: +OK message 1 deleted
C: QUIT
S: +OK POP3 server signing off (2 messages left)

go deeper

for a junior

Remember the order: DELE marks, QUIT commits. A connection that drops before QUIT deletes nothing.

for a middle

Name the three states and which commands belong to each, and explain RSET and why message numbers are per session. Be exact that only QUIT from TRANSACTION enters UPDATE.

for a senior

Use the rule to diagnose reports of deleted mail returning or duplicates after an outage, and explain why a client should key on UIDL rather than message numbers.

for a principal

Weigh the protocol's choice to lose nothing over avoiding duplicates, and hold any server-side deletion policy to the same rule: act only after a clean QUIT.

## The three states RFC 1939 (May 1996) defines POP3 as a short-lived session that moves through three states: 1. **AUTHORIZATION** — after the server's greeting, the client identifies itself (`USER` and `PASS`, `APOP`, or a SASL mechanism via `AUTH` from RFC 5034). On success the server opens the user's **maildrop**, takes an exclusive-access lock as necessary, numbers the messages `1..n`, and the session moves on. 2. **TRANSACTION** — the client works: `STAT` (count and total size), `LIST` (size per message), `RETR` (download), `DELE` (mark for deletion), `NOOP`, `RSET` (unmark everything), and the optional `TOP` and `UIDL`. 3. **UPDATE** — entered only when the client sends `QUIT` from TRANSACTION. The server removes the marked messages, releases the lock and closes the connection. Every reply is either `+OK` or `-ERR`; a command sent in the wrong state gets `-ERR`. ## What DELE really does `DELE n` is a mark, not an erase. After it: - the message is no longer counted by `STAT` or shown by `LIST` or `UIDL`; - any later command naming message `n` in this session returns `-ERR`; - `RSET` clears every mark made in the session and the server replies `+OK` (the RFC's example also reports the maildrop size). RFC 1939 is explicit: the server "does not actually delete the message until the POP3 session enters the UPDATE state." Message numbers belong to the session, so a later session may number the same mail differently — `DELE 3` is not a stable reference across sessions. ## How a session ends — and what each ending removes | How the session ends | Enters UPDATE? | Marked messages | |---|---|---| | `QUIT` from TRANSACTION | Yes | Removed | | `QUIT` from AUTHORIZATION | No | None existed | | Connection dropped, client crashed | No | Kept | | Server's autologout timer expires | No | Kept | Two details are worth knowing: - **Autologout.** A server MAY have an inactivity timer; RFC 1939 says it MUST be at least 10 minutes, and when it expires the session does not enter UPDATE — the server closes the connection without removing anything or replying. - **Errors during UPDATE.** If the server hits a problem while removing, "some or none" of the marked messages may be gone, and it answers `-ERR some deleted messages not removed`. It may never remove a message that was not marked. ## Why the protocol was designed this way RFC 1939 section 8 gives the reason in its discussion of download-once site policies: messages must not be deleted after an abnormal termination "because the client may not have successfully received or stored the messages." The deferral makes a session behave like a unit of work that commits only on a clean `QUIT`. The cost lands on the client. After a drop, every message the client already downloaded is still in the maildrop. A client that only tracks message numbers will fetch them again; a well-behaved client compares `UIDL` unique-ids, which RFC 1939 requires to persist across sessions "even if a session ends without entering the UPDATE state", and skips what it already holds. ## Reading it on your own server An administrator testing a mailbox can see the deferral directly: after `DELE`, `STAT` already shows one message fewer, yet the mail is still on disk until `QUIT`, and `RSET` brings it back. The example in this question does exactly that. What to take into operations: - A user who reports that "deleted mail came back" on a flaky mobile link is usually seeing a session that never reached `QUIT`. - A user who reports duplicates after an outage has a client that re-downloads instead of checking `UIDL`. - A server-side policy that deletes downloaded mail (for example, the download-once policy RFC 1939 describes) should act only after a clean `QUIT`, for the same reason the protocol does. ## Later extensions keep the rule The extensions added since 1996 do not move the commit point. RFC 2449's `EXPIRE 0` capability tells a client it may not leave mail on the server, and lets the server treat each message downloaded with `RETR` as if `DELE` had been sent — but only "when the session enters the UPDATE state". Authentication through SASL `AUTH` (RFC 5034) or a session protected from the start on port `995` changes how the client logs in, not when deletions take effect.

  • Why does RFC 1939 delete nothing when a session ends without QUIT, and what does that cost the client?
    Because the client may not have received or stored the messages it downloaded; deleting them on a drop could lose mail. The cost is that those messages are still in the maildrop next time. A client that tracks only session message numbers downloads them again; one that compares persistent `UIDL` unique-ids skips what it already holds.
  • If QUIT reaches the UPDATE state but the server fails while removing messages, what is still guaranteed?
    Only that no unmarked message is removed. RFC 1939 allows some or none of the marked messages to be removed after an error such as a resource shortage, signalled by `-ERR some deleted messages not removed`. Either way the server releases the maildrop lock and closes the connection, so the client should re-check on its next session.

A shop till: items scanned onto the bill are not sold until the customer pays. If the power fails before payment, the sale is voided and every item goes back on the shelf. DELE scans, QUIT pays, and a dropped connection is the power cut.

  • DELE removes the message from the server as soon as the server answers +OK.
  • A dropped connection commits every DELE the client issued before it.
  • The autologout timeout counts as a QUIT and enters the UPDATE state.
  • Message numbers stay the same across sessions, so DELE 3 always means the same mail.
  • RSET brings back messages that an earlier session already removed.