From 454c6e3c77b3db507ee81875219089047fc2d5a3 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 13 Jan 2013 15:37:49 -0200 Subject: Initial import --- philter.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 philter.sh (limited to 'philter.sh') diff --git a/philter.sh b/philter.sh new file mode 100755 index 0000000..e974b2d --- /dev/null +++ b/philter.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# +# rhatto's maildir simple filter +# feedback: rhatto at riseup.net | gpl +# + +PREFILTER="$HOME/apps/scripts/philter.py" +BASE="$HOME/mail/" +MAILBOXES="$BASE/Sync/" +INBOXES="" +#TRASHCAN="$BASE/INBOX.Trash/cur" +TRASHCAN="$BASE/INBOX.Trash/new" +SUBJECT="yes" # wheter to filter subject +DEL="no" # delete the message +BOGOFILTER="yes" +FILTER="***SPAM***" + +# Load configuration +if [ -e "$HOME/.config/scripts/philter" ]; then + source $HOME/.config/scripts/philter +fi + +for account in $INBOXES; do + + NEWBOX="$MAILBOXES/$account/INBOX/new" + + if [ -x $PREFILTER ]; then + $PREFILTER + fi + + cont="0" + cd $NEWBOX + + for file in `ls -1`; do + if grep -m 1 -e "X-Bogosity" "$file" | grep -q "Spam"; then + mv "$file" "$TRASHCAN" + if [[ "$DEL" == "yes" ]]; then + rm "$TRASHCAN/$file" + fi + ((cont++)) + elif [[ "$BOGOFILTER" == "yes" ]]; then + # bogofilter + if cat $file | bogofilter -u -e -p | grep -q -e "^X-Bogosity: Spam, tests=bogofilter"; then + mv "$file" "$TRASHCAN" + if [[ "$DEL" == "yes" ]]; then + rm "$TRASHCAN/$file" + fi + ((cont++)) + fi + fi + done + + if [ ! -z "$SUBJECT" ]; then + for file in `ls -1`; do + if grep -m 1 "$FILTER" "$file" | grep -q "Subject"; then + mv "$file" "$TRASHCAN" + if [[ "$DEL" == "yes" ]]; then + rm "$TRASHCAN/$file" + fi + ((cont++)) + fi + done + fi + + echo "Total: $cont filtered messages for account $account." + +done -- cgit v1.2.3