From e6bd6def3efc930e56a1af4cf13bacc305a9bb56 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Wed, 18 May 2016 10:13:47 -0700 Subject: [PATCH] check on the basis of pwd, not the name of the file --- learn_from_spam | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/learn_from_spam b/learn_from_spam index aca7f21..bb721e1 100755 --- a/learn_from_spam +++ b/learn_from_spam @@ -11,8 +11,8 @@ HAM_REPORT="spamc --learntype=ham" SPAM_CHECK="spamc -c" # needs rules directories -NEEDS_SPAM_RULES=~/Maildir/spam/needs_rules/cur/ -NEEDS_HAM_RULES=~/Maildir/spam/needs_ham_rules/cur/ +NEEDS_SPAM_RULES=~/Maildir/spam/needs_rules +NEEDS_HAM_RULES=~/Maildir/spam/needs_ham_rules if [ "$(basename $0)" = "learn_from_spam" ]; then for file in "$@"; do @@ -23,14 +23,15 @@ if [ "$(basename $0)" = "learn_from_spam" ]; then 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 + 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" "${NEEDS_SPAM_RULES}$(basename "$file")"; + mv "$TMP/file" "${NEEDS_SPAM_RULES}/cur/$(basename "$file")"; trap - EXIT; rmdir "$TMP"; - elif [ "$file" = "${NEEDS_SPAM_RULES}$(basename "$file")" ]; then + elif [ "$(pwd)" = "${NEEDS_SPAM_RULES}" ]; then rm -f "$file"; fi; done; @@ -39,14 +40,14 @@ elif [ "$(basename $0)" = "learn_from_ham" ]; then $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; + 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" "${NEEDS_HAM_RULES}$(basename "$file")"; + mv "$TMP/file" "${NEEDS_HAM_RULES}/cur/$(basename "$file")"; trap - EXIT; rmdir "$TMP"; - elif [ "$file" = "${NEEDS_HAM_RULES}$(basename "$file")" ]; then + elif [ "$(pwd)" = "${NEEDS_HAM_RULES}" ]; then rm -f "$file"; fi; done; -- 2.39.2