0

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

Robert
  • 146
  • 5

1 Answers1

0

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.

anx
  • 8,963
  • 5
  • 24
  • 48
  • `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 Jan 30 '23 at 18:10
  • 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 – Robert Jan 30 '23 at 18:25
  • 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. – anx Jan 30 '23 at 18:53