Skip to content

Instantly share code, notes, and snippets.

@alexalouit
Last active August 28, 2017 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexalouit/11040751 to your computer and use it in GitHub Desktop.
Save alexalouit/11040751 to your computer and use it in GitHub Desktop.
Automatic purge of spam emails and trash that are aged 14 days over
#!/bin/bash
#
# cron ex: 1 0 * * * /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /root/scripts/mail-purge.sh >> /root/scripts/cron.log
# Search messages more than 14 days in the appropriate directories and removes
find /var/vmail/ -regex '.*/\.\(Trash\|Junk\|Deleted\ Messages\)\(/.*\)?\/\(cur\|new\)/.*' -type f -ctime +14 -delete
# Dovecot is restarted to refresh quota (to update the .quotausage file)
/etc/init.d/dovecot restart
# since version ~2.2 (need userdb iterate):
#doveadm expunge -A mailbox Trash savedbefore 14d
#doveadm expunge -A mailbox Junk savedbefore 14d
#doveadm expunge -A mailbox Deleted\ Messages savedbefore 14d
#doveadm quota recalc -A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment