X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=learn_from_spam;h=071f7f1f49576eef9fff9cb1c00ca1dbe5aafc84;hb=7072dd6217d2a600f729188624f228b5700bd836;hp=5644096225e033bbcc5340dd4a723a7511c03510;hpb=0bd97f3ae6c713583a10fc8613c5d613f1f48d7a;p=bin.git diff --git a/learn_from_spam b/learn_from_spam index 5644096..071f7f1 100755 --- a/learn_from_spam +++ b/learn_from_spam @@ -8,7 +8,11 @@ SPAM_CHECK="spamassassin -e" # these are for spamc SPAM_REPORT="spamc --learntype=spam" HAM_REPORT="spamc --learntype=ham" -SPAM_CHECK="spamc -c" +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)" if [ "$(basename $0)" = "learn_from_spam" ]; then for file in "$@"; do @@ -17,29 +21,34 @@ if [ "$(basename $0)" = "learn_from_spam" ]; then 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 spam - if ! $SPAM_CHECK < "$file" >/dev/null 2>&1; then + # check to see if it's still ham + if $SPAM_CHECK < "$file" >/dev/null 2>&1; then + mkdir -p "${NEEDS_SPAM_RULES}/cur"; TMP="$(mktemp -d)" trap "rm -f '$TMP'/file; rmdir '$TMP'" EXIT # this message is still not spam; may need custom rules spamc < "$file" > "$TMP/file" 2>/dev/null; - mv "$TMP/file" ~/Maildir/spam/needs_rules/cur/"$(basename "$file")"; + mv "$TMP/file" "${NEEDS_SPAM_RULES}/cur/$(basename "$file")"; trap - EXIT; rmdir "$TMP"; + 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 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 - mkdir -p ~/Maildir/spam/needs_ham_rules/cur; + if ! $SPAM_CHECK < "$file" >/dev/null 2>&1; then + mkdir -p "${NEEDS_HAM_RULES}/cur"; TMP="$(mktemp -d)" trap "rm -f '$TMP'/file; rmdir '$TMP'" EXIT spamc < "$file" > "$TMP/file" 2>/dev/null; - mv "$TMP/file" ~/Maildir/spam/needs_ham_rules/cur/"$(basename "$file")"; + mv "$TMP/file" "${NEEDS_HAM_RULES}/cur/$(basename "$file")"; trap - EXIT; rmdir "$TMP"; + elif [ "$(pwd)" = "${NEEDS_HAM_RULES}" ]; then + rm -f "$file"; fi; done; else