dovecot: cleaning old Spam and Trash messages after some days

This script is useful to delete old messages in “Junk” mail folders (Spam, Trash) automatically after some days. adapted from these notes to work on debian/postfixadmin/dovecot #!/bin/bash # # itera sulle mailbox cancellando messaggi vecchi # per default, nel cestino 30gg e Spam 15 gg # # MySQL details HOST="127.0.0.1"; USER="put_here_your_mysql_user"; PWD="put_here_your_mysql_password"; MYSQL="/usr/bin/mysql"; # dovecot details DOVEADM="/usr/bin/doveadm"; TEMPFILE=$(/bin/mktemp) # Output sql to a file that we want to run echo "use postfixadmin; select username from mailbox" > $TEMPFILE # Run the query and get the results (adjust the path to mysql) results=$($MYSQL -h $HOST -u $USER -p$PWD -N < $TEMPFILE); # Loop through each row for row in $results do echo "Purging $row Trash and Junk mailbox....

March 5, 2014 · Andrea Manzini