first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / email / move_spams_and_check.sh
1 #!/bin/bash
2
3 # retrieves the system's spam pile from sa-exim's spool folder and
4 # moves it to the user's home directory.  sudo access is required
5 # for the file moving operations.
6 # after the spam is all snagged, it is scanned for any untoward presence
7 # of non-spam folks using the user's valid email list.
8
9 # the storage area that the spam catcher tool puts the suspected spam into.
10 SPAM_SPOOL="/var/spool/sa-exim"
11 # a temporary directory where we'll move all the spam for analysis.
12 SPAM_HOLD="$HOME/spamcrud"
13 # the white list needs to be a file of good email addresses that will
14 # probably never send spam.  it should be formatted one address to a line.
15 EMAIL_WHITE_LIST="$HOME/quartz/database/email_addresses.txt"
16 # we'll save a report of the spam checks in the file below.
17 REPORT_FILE="$HOME/spam_check_report.txt"
18
19 if [ ! -d "$SPAM_HOLD" ]; then
20   mkdir "$SPAM_HOLD"
21 fi
22 echo "The operation to move the spam files requires sudo privileges..."
23 sudo find "$SPAM_SPOOL" -type f -exec mv {} "$SPAM_HOLD" ';'
24 if [ $? -ne 0 ]; then
25   echo "The spam moving operation failed, which probably means we failed to get sudo access"
26   exit 3
27 fi
28 echo "Setting the directory back to user's ownership..."
29 sudo chown -R $USER "$SPAM_HOLD" 
30 sudo chgrp -R $USER "$SPAM_HOLD" 
31 echo "Running checker for false-positive spams..."
32 bash "$SHELLDIR/email/scan_spam.sh" "$SPAM_HOLD" "$EMAIL_WHITE_LIST" 2>&1 \
33   | tee "$REPORT_FILE"
34
35