Lazy Expunge (Dovecot Plugin)
Danger
This guide is still a work in progress, and errors may occur! Use this feature with caution!
Info
This feature is compatible with mailcow versions starting from 2024-11. Older versions are theoretically capable of using it as well, but due to internal changes, the implementation is more complicated, so it won't be stated here as unsupported.
Introduction¶
Dovecot has supported a feature called Lazy Expunge for quite some time, which allows server administrators to temporarily retain deleted emails from a user account even after they have been deleted.
mailcow also has a similar feature, but it is not easily accessible to users (see Recover accidentally deleted data (Mail)) and serves more as a fallback method for administrators.
With the Dovecot option, users can view and restore emails that have been marked as deleted before they are automatically purged by the Dovecot server.
Setup¶
-
Edit the
extra.conf
file in the Dovecot configuration folder (usually located atMAILCOW_ROOT/data/conf/dovecot
) with the following content:plugin { # Copy all deleted emails to the .EXPUNGED mailbox lazy_expunge = .EXPUNGED # Exclude marked-as-deleted emails from the quota quota_rule = .EXPUNGED:ignore } # Define the .EXPUNGED mailbox namespace inbox { mailbox .EXPUNGED { # Define how long emails will stay in this folder before they are deleted. Time is defined according to: https://doc.dovecot.org/2.3/settings/types/#time autoexpunge = 7days # Define how many emails can be kept in the EXPUNGED folder before it is cleared autoexpunge_max_mails = 100000 } }
-
Restart the Dovecot container:
docker compose restart dovecot-mailcow
docker-compose restart dovecot-mailcow
-
Once the trash is emptied, a new folder named
.EXPUNGED
should appear. This folder will contain emails that, according to the rules defined in step 1, will be automatically deleted from the server after a certain period.