TIL that the old mbox format (one of them anyway) handles deletion by... rewriting the entire mailbox without the deleted messages. I guess Idk what I expected: https://github.com/python/cpython/blob/3.14/Lib/mailbox.py#L704-L770

Oh, and this impl has a fun side effect- you can fail to regain the lock after rewrite. I guess an existing lock granted by flock dies after a rename()?

cpython/Lib/mailbox.py at 3.14 · python/cpython

The Python programming language. Contribute to python/cpython development by creating an account on GitHub.

GitHub

@cr1901 a bunch of mbox handling programs will flag deletion by some combination of overwriting part of the mail header (in place as a flag) or updating the index they built flagging it as deleted.

But yes to truly remove a message from a mbox file, you have to rewrite the whole file (or at least from the message to the end). Which can be expensive on large files. (Hence Thunderbird “compact now” delaying it.)

It’s one of the reasons MH / Maildir (both one file per message) got invented.