Thank you! This is tremendeously helpful, and now the messages that
users delete are moved, however...
The problem now is that the folders are lost, so recovering from
mass deletions loses folder hierarchy (in Dovecot 2.3 the folder structure was always preserved, which is important when helping users recover messages that they accidentally deleted, or their AI bots deleted, or the rare occurance when Outlook goes on one of its crazy mass-deletion rampages, etc.).
I haven't been able to find anything about preserving mailbox
folders in the documentation for Dovecot 2.4.1 -- is there a setting I'm missing that preserves folder structure within my ~/Maildir.deleted/ path? (Our mailbox path setting ~/Maildir/ and we prefer keeping lazy-expunge files in ~/Maildir.deleted/ for each user, respectively.)
Here is my current working configuration file (on our test servers
for now as I continue to work on this), which doesn't preserve deletions in their respective mailbox folders...
-------- BEGIN: 16-lazy-expunge.conf --------
lazy_expunge_mailbox = EXPUNGED/INBOX lazy_expunge_only_last_instance = yes
namespace inbox { mailbox EXPUNGED { autoexpunge = 32days autoexpunge_max_mails = 100000 } acl owner { rights = rwstipekxa } mailbox \Drafts { lazy_expunge_mailbox = } }
namespace lazy_expunge_ns { hidden = yes list = no prefix = EXPUNGED/ subscriptions = no separator = / #location = maildir:~/Maildir.deleted:INDEX= mail_driver = maildir mail_path = ~/Maildir.deleted mail_index_path = mail_index_private_path = mail_cache_path =
mailbox EXPUNGED { quota_ignore = yes } }
mail_plugins { lazy_expunge = yes }
-------- END: 16-lazy-expunge.conf --------
While most deleted messages show up under "Deleted Items" or "Trash"
because a lot of eMail software moves deletions there first, there are many instances where this doesn't occur, and deletion occurs directly -- some webmail clients do this, or the user deletes a folder that was moved to their Trash folder, or they held down the Alt or CTRL key when deleting messages (to bypass the Trash folder move), or a script/rule deletes directly, etc.
2026-06-17T10:13:27.138080-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Error: Mailbox Deleted Items: UID 864: lazy_expunge: Couldn't open expunge mailbox: Failed to open mailbox EXPUNGED/: Invalid mailbox name 'EXPUNGED/': Ends with hierarchy separator
You notice that it speaks about mailbox, not namespace. Try using EXPUNGED/INBOX as lazy_expunge_mailbox. You are now pointing it to a namespace.
Aki
On 17/06/2026 20:26 EEST Randolf Richardson via dovecot <dovecot@dovecot.org> wrote:
Thank you for your help, I appreciate it very much.
What I meant by "not working" is that the deleted messages were just disappearing, without being placed in the ~/Maildir.deleted/ folder (which is the expected behaviour), and with no errors being logged.
I tried replacing my 16-lazy-expunge.conf file with what you provided, and now, upon deletion, the IMAP4 client (Evolution on Linux in this case) reports an "expunge" operation error. The following errors now show up in the logs (this is on a test server that worked correctly before upgrading from 2.3 to 2.4.1):
2026-06-17T10:13:27.137678-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Debug: Mailbox Deleted Items: UID 864: Mail metadata accessed 2026-06-17T10:13:27.137908-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Debug: Mailbox EXPUNGED/: Mailbox opened 2026-06-17T10:13:27.138080-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Error: Mailbox Deleted Items: UID 864: lazy_expunge: Couldn't open expunge mailbox: Failed to open mailbox EXPUNGED/: Invalid mailbox name 'EXPUNGED/': Ends with hierarchy separator 2026-06-17T10:13:27.138259-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Debug: Mailbox Deleted Items: UID 864: Expunge requested 2026-06-17T10:13:27.138422-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Debug: Mailbox Deleted Items: UID 865: Expunge requested 2026-06-17T10:13:27.138547-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Debug: Mailbox Deleted Items: UID 866: Expunge requested 2026-06-17T10:13:27.138682-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Debug: Mailbox Deleted Items: UID 867: Expunge requested 2026-06-17T10:13:27.138807-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Debug: Mailbox Deleted Items: UID 868: Expunge requested 2026-06-17T10:13:27.138919-07:00 mail02 dovecot: imap(nobody@example.com)<1232591><CUPOK3ZUdOIKAQHB>: Error: Mailbox Deleted Items: Lazy-expunge transaction failed: Mailbox Deleted Items: UID 864: lazy_expunge: Couldn't open expunge mailbox: Failed to open mailbox EXPUNGED/: Invalid mailbox name 'EXPUNGED/': Ends with hierarchy separator
I did attempt removing the trailing slash, but the errors logged remained the same.
I also tried to add the following lines to "mailbox EXPUNGED" stanza (which is what I will be needing, although I'm unsure if this is the correct placement), which resulted in more errors that I think I should ignore at this point until the errors (above) are sorted:
mail_driver = maildir mail_path = ~/Maildir.deleted mail_index_private_path = mail_cache_path =Note: Some eMail clients delete directly instead of moving messages to the "Deleted Items" (Trash) folders, and Dovecot 2.3 preserved this structure with its lazy-expunge configuration (which is a wonderfully helpful feature), which is all stored in the specified "mail_path" file system hierarchy separate from the user's mailbox.
Thanks!
For 2.4 you would use
acl_driver = vfile acl_global_path = /etc/dovecot/dovecot.acl lazy_expunge_mailbox = EXPUNGED/ lazy_expunge_only_last_instance = yes
namespace inbox { mailbox EXPUNGED { autoexpunge = 32days autoexpunge_max_mails = 100000 } mailbox \Drafts { lazy_expunge_mailbox = } }
namespace ns { hidden = yes list = no prefix = EXPUNGED/ subscriptions = no
mailbox EXPUNGED { quota_ignore = yes } }
mail_plugins { acl = yes lazy_expunge = yes }
but you never did explain "how it does not work".
Aki
On 15/06/2026 19:17 EEST Randolf Richardson via dovecot <dovecot@dovecot.org> wrote:
One of the Dovecot repository maintainers on GitHub recommended sending an eMail to you regarding the issue I encountered:
Documentation for lazy-expunge doesn't work https://github.com/dovecot/documentation/issues/1555
I converted from Dovecot 2.3 to Dovecot 2.4.1, which was not a minor upgrade. Anyway, I can't get the lazy-expunge plugin to work in 2.4.1 now. Here's my configuration file from 2.3 -- how can I get this working in 2.4.1? Thanks.
namespace inbox { mailbox EXPUNGED { autoexpunge = 32days autoexpunge_max_mails = 100000 #auto = create } }
Namespace for lazy_expunge plugin
namespace { prefix = EXPUNGED/ hidden = yes list = no subscriptions = no separator = / location = maildir:~/Maildir.deleted:INDEX= }
mail_plugins = $mail_plugins lazy_expunge acl plugin {
Move expunged messages into the .EXPUNGED namespace
lazy_expunge = EXPUNGED/
Only move to expunged storage if this is the last copy of the
message in the user“s account lazy_expunge_only_last_instance = yes
Exclude Drafts from lazy expunging
lazy_expunge_exclude = \Drafts
Copy of each message is done with hard links whenever possible
maildir_copy_with_hardlinks = yes
Define ACL so that user cannot list the .EXPUNGED mailbox
Example entry: .EXPUNGED owner rwstipekxa
acl = vfile:/etc/dovecot/dovecot.acl
dovecot.acl contains one line: EXPUNGED owner ip
Expunged messages most likely don't want to be included in quota:
quota_rule = EXPUNGED:ignore } #lazy_expunge_mailbox = EXPUNGED
Here's an example of someone else who encountered the same problem: https://www.dovecot.org/mailman3/archives/list/dovecot@dovecot.org/thr ead/25BXSHQWGQQ3ACVZSYF3O3LC4WROTUCI/
Randolf Richardson, CNA - randolf@inter-corporate.com Inter-Corporate Computer & Network Services, Inc. Beautiful British Columbia, Canada https://www.inter-corporate.com/
dovecot mailing list -- dovecot@dovecot.org To unsubscribe send an email to dovecot-leave@dovecot.org
Randolf Richardson, CNA - randolf@inter-corporate.com Inter-Corporate Computer & Network Services, Inc. Beautiful British Columbia, Canada https://www.inter-corporate.com/
dovecot mailing list -- dovecot@dovecot.org To unsubscribe send an email to dovecot-leave@dovecot.org
Randolf Richardson, CNA - randolf@inter-corporate.com Inter-Corporate Computer & Network Services, Inc. Beautiful British Columbia, Canada https://www.inter-corporate.com/