first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / email / scan_spam.sh
1 #!/bin/bash
2
3 if [ $# -lt 2 ]; then
4   echo "This program needs two parameters.  The first is the directory where spam"
5   echo "emails are stored.  The second parameter is a text file containing non-spammy"
6   echo "email addresses (that is, a whitelist of good email addresses--people who are"
7   echo "allowed to send you email).  The script will scan that directory for any email"
8   echo "addresses in the whitelist file and report files that might potentially not be"
9   echo "spam (i.e., false positives)."
10   exit 2323
11 fi
12
13 if [ ! -d "$1" ]; then
14   echo "This program needs a spam email *directory* as its first parameter."
15   exit 2324
16 fi
17
18 if [ ! -f "$2" ]; then
19   echo "This program needs a whitelist *file* as its second parameter."
20   exit 2325
21 fi
22
23 export SCAN_DIR="$1"  # where we will scan spam emails.
24 export ADDRESS_FILE="$2"  # where our addresses live.
25
26 # a generated script that reports when a matching pattern was found in a file.
27 export ITERATE_COMMAND="$(mktemp "$TMP/zz_saitercmd.XXXXXX")"
28 # was in there "$2" but not defined?
29 echo '\
30   matched=; \
31   if [ ! -z "$(head -50 "$1" | grep "From:" | grep -f "$ADDRESS_FILE" -i )" ]; then \
32     matched="$1"; \
33   fi; \
34   if [ ! -z "$matched" ]; then \
35     echo "found non-spam email address in : $matched"; \
36   fi \
37 ' >$ITERATE_COMMAND
38
39 find $SCAN_DIR -type f -exec bash $ITERATE_COMMAND "{}" ';' 
40
41 rm -f $ITERATE_COMMAND 
42