cleaned old code, fixed path
[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 source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
10
11 # the storage area that the spam catcher tool puts the suspected spam into.
12 SPAM_SPOOL="/var/spool/sa-exim"
13 # a temporary directory where we'll move all the spam for analysis.
14 SPAM_HOLD="$HOME/spamcrud"
15 # the white list needs to be a file of good email addresses that will
16 # probably never send spam.  it should be formatted one address to a line.
17 EMAIL_WHITE_LIST="$CLOUD_BASE/magic_cabinet/lists/email_addresses.txt"
18 # we'll save a report of the spam checks in the file below.
19 REPORT_FILE="$HOME/spam_check_report_$(date_stringer).txt"
20
21 if [ ! -d "$SPAM_HOLD" ]; then
22   mkdir "$SPAM_HOLD"
23 fi
24 echo "The operation to move the spam files requires sudo privileges..."
25 sudo find "$SPAM_SPOOL" -type f -exec mv {} "$SPAM_HOLD" ';'
26 if [ $? -ne 0 ]; then
27   echo "The spam moving operation failed, which probably means we failed to get sudo access"
28   exit 3
29 fi
30 echo "Setting the directory back to user's ownership..."
31 sudo chown -R $USER "$SPAM_HOLD" 
32 sudo chgrp -R $USER "$SPAM_HOLD" 
33 echo "Checking for false-positive spams..." | tee "$REPORT_FILE"
34 bash "$FEISTY_MEOW_SCRIPTS/email/scan_spam.sh" "$SPAM_HOLD" "$EMAIL_WHITE_LIST" 2>&1 \
35   | tee -a "$REPORT_FILE"
36 echo "Done checking for false-positive spams." | tee -a "$REPORT_FILE"
37
38