Score:0

Dovecot How To Periodically Empty All Users Mailboxes

gb flag

I have a fresh install of a Dovecot (and Postfix) setup on Ubuntu Server 22.04

The configuration is exclusively for local mail between desks and the messages are in practice instant only

in few words , the drive storage is limited and this is not the office official mail

These mails will be just instant messages between users and the history will be kept in the respective Thunderbird clients. Please note that for that same reson dovecot-imapd is NOT installed at all


I need to set a script that will erase all the users messages older than 30 days

So far, reading the documentation, I have found that these commands should be the right ones

doveadm expunge -A mailbox Inbox savedbefore 30d
doveadm expunge -A mailbox Sent savedbefore 30d
doveadm expunge -A mailbox Trash savedbefore 30d

P.S. as Dovecot provides the -A switch for selecting ALL the users, do you kindly know if it is available a similar switch to select ALL the maiboxes types (sent received trash etc etc altogether, this to be sure to have matched all at once in one line only) , thank you

please note that dovecot-imapd is NOT installed

Well, when I run just one of them, e.g. doveadm expunge -A mailbox Inbox savedbefore 30d , I get this output

doveadm(nobody): Error: mkdir(/nonexistent/mail/.imap) failed: Permission denied (euid=65534(nobody) egid=65534(nogroup))
doveadm(nobody): Error: mkdir(/nonexistent/mail/.imap) failed: Permission denied (euid=65534(nobody) egid=65534(nogroup))
doveadm(nobody): Error: Syncing mailbox 'Trash' failed: Mailbox doesn't exist: Trash
doveadm(robert): Error: Syncing mailbox 'Trash' failed: Mailbox doesn't exist: Trash
doveadm(lxd): Error: mkdir(/var/snap/lxd/common/lxd/mail/.imap) failed: Permission denied (euid=999(lxd) egid=100(users) missing +w perm: /var/snap/lxd/common/lxd, dir owned by 0:0 mode=0711)
doveadm(lxd): Error: mkdir(/var/snap/lxd/common/lxd/mail/.imap) failed: Permission denied (euid=999(lxd) egid=100(users) missing +w perm: /var/snap/lxd/common/lxd, dir owned by 0:0 mode=0711)
doveadm(lxd): Error: Syncing mailbox 'Trash' failed: Mailbox doesn't exist: Trash

Permission to who?

doveadm is a command theoretically run by the dovecot user which theoretically is the one that manages the mailboxes

Really confused

Thank you for hinting about this

Also, any acknowledge about the command lines, would be welcome as well. Thank you

jp flag
This seems like a use case for POP3.
Score:0
fr flag
anx

Though the "shortest valid search_query is ALL", doveadm asks you to explicitly list the mailboxes when you delete things, to avoid mistakes. You may still execute the command multiple times, or combine multiple search-queries with OR, though. Don't forget to escape parentheses if working in a shell, e.g.:

doveadm [command] \( MAILBOX box1 OR MAILBOX box2 [..] \) [common-search-query]

If the list is not static, you can still loop over the output of doveadm mailbox list.


/nonexistent sounds like the -A flag iterated through system users that were not meant to use dovecot.

Review your first_valid_uid setting.

Robert avatar
gb flag
`first_valid_uid` and `last_valid_uid` fixed the issue but now I have a new one. If I use the command `doveadm expunge -u userName01 mailbox INBOX ALL` I get an error I cannot found on google `doveadm(userName01): Error: Mailbox INBOX: open(.) failed: Permission denied` (the same happen if I use `doveadm expunge -A mailbox INBOX ALL`) , whilst if I use `doveadm expunge -u userName01 mailbox INBOX ALL` it works . Can you kindly hint about this?
Robert avatar
gb flag
Better to add that I don't use MySQL/MariaDB for mails storing because I use pop3 only and as said above, for brief short messages for internal local office LAN use. That is why I want to erase every day on cron script , all the messages in any mailbox older than 30 days
anx avatar
fr flag
anx
First, use some non-destructive command (like `user *wild*card*`, then `-A mailbox list`) to verify that the user iteration after your changes only includes users which have a home & mail directory setup the way you expect. You may still be looping over (system?) users which do not ordinarily receive mail.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.