Message 163358 - Python tracker (original) (raw)
I looked at the source code of mutt to see how it rewrites mbox files. It does roughly this:
Block some signals.
Lock the mbox file (with dotlock, fcntl and flock).
Create a temporary file in /tmp.
Write messages to the temporary file, from the point where the first change is up to the end of the mbox file. This saves a lot of writing when the first change is near the end of the file.
Write changes from the temporary file to the mbox file, modifying the mbox file in-place.
Truncate the mbox file to the correct length.
Unblock signals.
If writing the changes back to the mbox file fails, the temporary file is copied from /tmp to near the mbox file.