From bc8a29b94b0ec20adbda1e2540b2a263c6996906 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 25 Oct 2015 12:04:45 +0000 Subject: [PATCH] Spam and ham filtering for multiple users --- src/freedombone | 70 ++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/src/freedombone b/src/freedombone index 10598c24..258cde87 100755 --- a/src/freedombone +++ b/src/freedombone @@ -6333,44 +6333,54 @@ function spam_filtering { chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.procmailrc # filtering scripts echo '#!/bin/bash' > /usr/bin/filterspam - echo 'USERNAME=$1' >> /usr/bin/filterspam - echo 'MAILDIR=/home/$USERNAME/Maildir/.learn-spam' >> /usr/bin/filterspam - echo 'if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterspam - echo ' exit' >> /usr/bin/filterspam - echo 'fi' >> /usr/bin/filterspam - echo 'for f in `ls $MAILDIR/cur`' >> /usr/bin/filterspam - echo 'do' >> /usr/bin/filterspam - echo ' spamc -L spam < "$MAILDIR/cur/$f" > /dev/null' >> /usr/bin/filterspam - echo ' rm "$MAILDIR/cur/$f"' >> /usr/bin/filterspam - echo 'done' >> /usr/bin/filterspam - echo 'for f in `ls $MAILDIR/new`' >> /usr/bin/filterspam - echo 'do' >> /usr/bin/filterspam - echo ' spamc -L spam < "$MAILDIR/new/$f" > /dev/null' >> /usr/bin/filterspam - echo ' rm "$MAILDIR/new/$f"' >> /usr/bin/filterspam + echo 'for d in /home/*/ ; do' >> /usr/bin/filterspam + echo ' USERNAME=$(echo "$d" | awk -F "/" "{print $3}")' >> /usr/bin/filterspam + echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/filterspam + echo ' MAILDIR=/home/$USERNAME/Maildir/.learn-spam' >> /usr/bin/filterspam + echo ' if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterspam + echo ' exit' >> /usr/bin/filterspam + echo ' fi' >> /usr/bin/filterspam + echo ' for f in `ls $MAILDIR/cur`' >> /usr/bin/filterspam + echo ' do' >> /usr/bin/filterspam + echo ' spamc -L spam < "$MAILDIR/cur/$f" > /dev/null' >> /usr/bin/filterspam + echo ' rm "$MAILDIR/cur/$f"' >> /usr/bin/filterspam + echo ' done' >> /usr/bin/filterspam + echo ' for f in `ls $MAILDIR/new`' >> /usr/bin/filterspam + echo ' do' >> /usr/bin/filterspam + echo ' spamc -L spam < "$MAILDIR/new/$f" > /dev/null' >> /usr/bin/filterspam + echo ' rm "$MAILDIR/new/$f"' >> /usr/bin/filterspam + echo ' done' >> /usr/bin/filterspam + echo ' fi' >> /usr/bin/filterspam echo 'done' >> /usr/bin/filterspam + echo 'exit 0' >> /usr/bin/filterspam echo '#!/bin/bash' > /usr/bin/filterham - echo 'USERNAME=$1' >> /usr/bin/filterham - echo 'MAILDIR=/home/$USERNAME/Maildir/.learn-ham' >> /usr/bin/filterham - echo 'if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterham - echo ' exit' >> /usr/bin/filterham - echo 'fi' >> /usr/bin/filterham - echo 'for f in `ls $MAILDIR/cur`' >> /usr/bin/filterham - echo 'do' >> /usr/bin/filterham - echo ' spamc -L ham < "$MAILDIR/cur/$f" > /dev/null' >> /usr/bin/filterham - echo ' rm "$MAILDIR/cur/$f"' >> /usr/bin/filterham - echo 'done' >> /usr/bin/filterham - echo 'for f in `ls $MAILDIR/new`' >> /usr/bin/filterham - echo 'do' >> /usr/bin/filterham - echo ' spamc -L ham < "$MAILDIR/new/$f" > /dev/null' >> /usr/bin/filterham - echo ' rm "$MAILDIR/new/$f"' >> /usr/bin/filterham + echo 'for d in /home/*/ ; do' >> /usr/bin/filterham + echo ' USERNAME=$(echo "$d" | awk -F "/" "{print $3}")' >> /usr/bin/filterham + echo ' if [[ $USERNAME != "git" ]]; then' >> /usr/bin/filterham + echo ' MAILDIR=/home/$USERNAME/Maildir/.learn-ham' >> /usr/bin/filterham + echo ' if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterham + echo ' exit' >> /usr/bin/filterham + echo ' fi' >> /usr/bin/filterham + echo ' for f in `ls $MAILDIR/cur`' >> /usr/bin/filterham + echo ' do' >> /usr/bin/filterham + echo ' spamc -L ham < "$MAILDIR/cur/$f" > /dev/null' >> /usr/bin/filterham + echo ' rm "$MAILDIR/cur/$f"' >> /usr/bin/filterham + echo ' done' >> /usr/bin/filterham + echo ' for f in `ls $MAILDIR/new`' >> /usr/bin/filterham + echo ' do' >> /usr/bin/filterham + echo ' spamc -L ham < "$MAILDIR/new/$f" > /dev/null' >> /usr/bin/filterham + echo ' rm "$MAILDIR/new/$f"' >> /usr/bin/filterham + echo ' done' >> /usr/bin/filterham + echo ' fi' >> /usr/bin/filterham echo 'done' >> /usr/bin/filterham + echo 'exit 0' >> /usr/bin/filterham if ! grep -q "filterspam" /etc/crontab; then - echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam $MY_USERNAME" >> /etc/crontab + echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam" >> /etc/crontab fi if ! grep -q "filterham" /etc/crontab; then - echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham $MY_USERNAME" >> /etc/crontab + echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham" >> /etc/crontab fi chmod 655 /usr/bin/filterspam /usr/bin/filterham sed -i 's/# use_bayes 1/use_bayes 1/g' /etc/mail/spamassassin/local.cf