aboutsummaryrefslogtreecommitdiff
path: root/philter.sh
diff options
context:
space:
mode:
Diffstat (limited to 'philter.sh')
-rwxr-xr-xphilter.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/philter.sh b/philter.sh
new file mode 100755
index 0000000..f260a96
--- /dev/null
+++ b/philter.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+#
+# 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