Exim - Cleaning tools

Non active users cleaner
#!/bin/bash

for f in $(ls "/data/mail/domain.ru/" | grep -v "`mysql -uUSER -pPASSWORD -B exim -e "SELECT id FROM users WHERE active='Y';"`"); do eval  mv "/data/mail/domain.ru/$f" "/data/mail/_archive/"; done
Trash & Junk folders cleaner
#!/bin/bash

base_dir=/data/mail        # base dir for your mail server Maildirs
temp_dir=$base_dir/_trash  # temp folder for old mails
archive_after=7            # days to move old files to temp_folder
delete_after=30            # delete files after this days
#method="rm -f"            # best for physical servers
method="shred -n 0 -z -u " # best for virtual servers

#=================================================================================================

# move old files to temp dir
for f in $base_dir/*/*/Maildir/{".Junk",".junkmail",".Trash",".&BCMENAQwBDsENQQ9BD0ESwQ1-",".Deleted Messages",".&BB0ENQQ2BDUEOwQwBEIENQQ7BEwEPQQwBE8- &BD8EPgRHBEIEMA-"}/{cur,new}
do
 [ -d "$f" ] && find "$f" -type f -mtime +$archive_after -print0 | xargs -0 mv -t "$temp_dir" 2>/dev/null
done

# cleanup temp folder
find "$temp_dir" -type f -mtime +$delete_after -print0 | xargs -0 $method 2>/dev/null

exit 0