Auto purge mail with doveadm

[email protected]:~# /usr/bin/doveadm expunge -A mailbox ‘*’ SAVEDBEFORE 30days
Error: User listing returned failure
doveadm: Error: Failed to iterate through some users

Any idea?

For some reason doveadm is unable to read a list of users from the text files hestia uses to store accounts, so the -A flag won’t work. (This is also true of other operations). If user accounts are stored in an SQL backend it doesn’t have this problem.

So, if you use -u [email protected] instead, then it can find the account and will be able to process your account.
The solution therefore is to write a script with all the users listed in it, one per line. Or write a script to use the v-commands to list the mail users and loop over them.
You can use the doveadm search command with the same command options to check its doing the right thing.

This is a quick and dirty script to list the mail accounts. I’m not saying its bulletproof, but it might help.


for USER in $( v-list-users plain | awk '{print $1}' )
  COUNTMAIL=$(v-list-mail-domains $USER plain | awk '{print $1}' | wc -l )
  if [[ "$COUNTMAIL" -gt "0" ]]; then
    for DOMAIN in $(v-list-mail-domains $USER plain | awk '{print $1}')
      for ACCOUNT in $( v-list-mail-accounts $USER $DOMAIN plain | awk '{print $1}')
        echo "$ACCOUNT"@"$DOMAIN"

Or even a bit dirtier :slight_smile:

for dir in /home/*/mail/*/*; do
dir=$(echo "$dir" | awk -F"/" '{print $6"@"$5}')
doveadm expunge -u "$dir" mailbox '*' savedbefore 100days

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.