We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
Howto: dovecot expunge spam/trash
Howto: dovecot expunge spam/trash
On another (non-Vesta) mail server I run, I these daily cron tasks:
To save space by clearing out trash and junk older than 30 days. Note the -A flag does this for all users - but on a Vesta server, this doesn't work - because the config is split among different domain-specific files, dovecot doesn't 'know' all the users.
Instead I came up with this script - couldn't see anything similar on the forum, so hope this helps some folks:
You can add this to your admin cron. Just, I think, one prerequisite:
NB suggest having an alternative sudo (or root) login when mucking about with sudoers.d - any mistakes and you may not be able to sudo to undo them!
Code: Select all
0 3 * * * doveadm expunge -A mailbox Trash savedbefore 30d
5 3 * * * doveadm expunge -A mailbox Junk savedbefore 30d
Instead I came up with this script - couldn't see anything similar on the forum, so hope this helps some folks:
Code: Select all
#!/bin/bash
#run this so cron job has environment variable
export VESTA='/usr/local/vesta'
#can't force everyone to use the same folders, so catch both variants
declare -a dcfolders=( "Trash" "Spam" "Junk" "Deleted Messages" )
sudo /usr/local/vesta/bin/v-list-users plain | cut -f1 | sort | while read -r vuser ; do
sudo /usr/local/vesta/bin/v-list-mail-domains $vuser plain | cut -f1 | sort | while read -r vdomain ; do
sudo /usr/local/vesta/bin/v-list-mail-accounts $vuser $vdomain plain | cut -f1 | sort | while read -r vaccount ; do
for dcfolder in "${dcfolders[@]}"
do
if sudo doveadm mailbox list -u $vaccount@$vdomain | grep "^${dcfolder}$" > /dev/null;
then
echo "$vaccount@$vdomain $dcfolder"
sudo doveadm -v expunge -u $vaccount@$vdomain mailbox "$dcfolder" sentbefore 30d
fi
done
done
done
done
- You'll need to edit sudoers to allow admin to sudo doveadm without a password (my route)
- Or, I think you may be able to add admin to the mail group, and change the script to run doveadm without sudo
- Or remove all sudo references and add it to your sudo crontab
Code: Select all
admin ALL=NOPASSWD: /usr/local/vesta/bin/*, /usr/bin/doveadm
Re: Howto: dovecot expunge spam/trash
This is great work, thank you! Works perfectly for me 1 year later.