How can I set an IMAP folder to prevent deletion of mail it contains?

This page is showing a generic answer.
To see a more detailed answer customized for you, type your e-mail address here:

We’re occasionally asked if there’s any way to set up an IMAP mail folder so that messages it contains can’t be accidentally deleted from that folder later on.

The Dovecot mail server software we use has a feature called access control lists for this. In most cases, this is something we will set up for you if you request it, but for technically advanced users who are comfortable with shell commands, this is done by creating a file named dovecot-acl in the appropriate maildir directory.

For example, for the “Sent” folder of the address address@example.com, you’d create a file at:

~/mailstore/address/.Sent/dovecot-acl

To prevent deletions from that folder, the file should contain this line:

owner lrwsipk

(The Dovecot access control lists page describes what that means, but the key thing is that “lrwsipk” does not contain the “t” or “e” necessary to allow deletion of messages.)

After doing this, attempts to remove a message from that folder will fail with a “permission denied” IMAP error.

Does this method prevent malicious deletions?

This method works very well for preventing accidental deletions, but it’s not secure against malicious deletions by someone who has your password. Because it’s possible for you to add or remove the “dovecot-acl” file using the password of the mailbox or the account master password, it would be possible for a “hacker” who knows your password to do the same thing.

If you need to audit the history of a mailbox for security reasons, you shouldn’t rely solely on this method; you should make your own separate backups of the mail, too.