X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=learn_from_spam;h=8d3b2c88b9553eef05ca0a05c3c4e63d691a0f81;hb=59404941343ff9bb75baf172c153f572bd1e4f4c;hp=96f9bd97400a81e2934f21e74019815ab600a8e2;hpb=bf450cece3c634d0c6b90e35b31221acedb1e60b;p=bin.git diff --git a/learn_from_spam b/learn_from_spam index 96f9bd9..8d3b2c8 100755 --- a/learn_from_spam +++ b/learn_from_spam @@ -6,24 +6,56 @@ HAM_REPORT="spamassassin --revoke" SPAM_CHECK="spamassassin -e" # these are for spamc -SPAM_REPORT="spamc --learntype=spam" -HAM_REPORT="spamc --learntype=ham" -SPAM_CHECK="spamc -c" +SPAM_REPORT="spamc --learntype=spam -s $((100 * 1024 * 1024))" +HAM_REPORT="spamc --learntype=ham -s $((100 * 1024 * 1024))" +SPAM_CHECK="spamc -s $((100 * 1024 * 1024)) -c" + +# needs rules directories +NEEDS_SPAM_RULES="$(echo ~/Maildir/spam/needs_rules)" +NEEDS_HAM_RULES="$(echo ~/Maildir/spam/needs_ham_rules)" + +run_through_spamc () { + # destdir + DESTDIR="$1" + FILENAME="$2" + mkdir -p "$1" + TMP="$(mktemp -d)" + DESTFILE="$DESTDIR/$(basename "$FILENAME")" + DESTFILE_NO_SIZE="$DESTDIR/$(basename "$FILENAME"|sed 's/,S=.*//g')" + spamc -s $((100 * 1024 * 1024)) < "$FILENAME" > "$TMP/file" 2>/dev/null; + mv "$TMP/file" "$DESTFILE" + if [ "$DESTFILE" -ne "$DESTFILE_NO_SIZE" ]; then + mv "$DESTFILE" "$DESTFILE_NO_SIZE" + fi; + trap - EXIT; + rmdir "$TMP"; +} if [ "$(basename $0)" = "learn_from_spam" ]; then for file in "$@"; do - $SPAM_REPORT < "$file" >/dev/null; - grep -e '^From ' -e 'From: ' "$file" | spamassassin -R >/dev/null; - # check to see if it's still spam - if ! spam -c < "$file"; then - # this message is still not spam; may need custom rules - cp "$file" ~/Mail/spam/needs_rules/cur/; + if ! formail -c < "$file"|grep -q '^List-Id'; then + $SPAM_REPORT < "$file" >/dev/null 2>&1; + else + spamasssin --local --report < "$file" >/dev/null 2>&1; + fi + formail -c < "$file" | grep -e '^From ' -e 'From: ' | spamassassin --add-to-blacklist >/dev/null 2>&1; + formail -c < "$file" | grep -e '^From ' -e 'From: ' | spamassassin --remove-from-whitelist >/dev/null 2>&1; + # check to see if it's still ham + if $SPAM_CHECK < "$file" >/dev/null 2>&1; then + run_through_spamc "${NEEDS_SPAM_RULES}/cur" "$file"; + elif [ "$(pwd)" = "${NEEDS_SPAM_RULES}" ]; then + rm -f "$file"; fi; done; elif [ "$(basename $0)" = "learn_from_ham" ]; then for file in "$@"; do - $HAM_REPORT < "$file" >/dev/null; - grep -e '^From ' -e 'From: ' -e 'To: ' -e 'Cc: ' "$file"|spamassassin -W>/dev/null; + $HAM_REPORT < "$file" >/dev/null 2>&1; + formail -c < "$file" |grep -e '^From ' -e 'From: ' -e 'To: ' -e 'Cc: '|spamassassin --add-to-whitelist >/dev/null 2>&1; + if ! $SPAM_CHECK < "$file" >/dev/null 2>&1; then + run_through_spamc "${NEEDS_HAM_RULES}/cur" "$file"; + elif [ "$(pwd)" = "${NEEDS_HAM_RULES}" ]; then + rm -f "$file"; + fi; done; else "Called in a way this script cannot recognize";