Kloxo – LXAdmin- Qmail – Remove Spam from Users Inbox

There was a user that had accumilated a lot of spam in their inbox over the years, but never had the mail server to send it directly to the spam box directly upon receipt. The good thing is that spamassasin was installed and was marking the spam status of an email within the headers. This makes it easy to seperate the email from the good and bad emails.

The below script will find the headers marked as spam and then move the spam emails from the users inbox to the users spam folder. This is for Kloxo/qmail based systems, but can be modified for any other mail servers if needed.

#!/bin/bash

## Really do not need to change this if you are moving spam from a user's inbox
spam='X-Spam-Status: Yes,'
## Change this to the user. Do not include "@domain.com" at the end of the username
user='mailusername'
## The domain for the user
domain='test.com'

for u in $(grep -l "$spam" /home/lxadmin/mail/domains/$domain/$user/Maildir/cur/*); do
mv /home/lxadmin/mail/domains/$domain/$user/Maildir/cur/"$u" /home/lxadmin/mail/domains/$domain/$user/Maildir/.Spam/cur/
done

Enjoy,
Jason

, , , ,

Comments are closed.