Commits

Cameron Simpson committed 2072ab8

email-add-spam-subject: record message subject as spam rule

  • Participants
  • Parent commits 69bd88b

Comments (0)

Files changed (1)

File bin-cs/email-add-spam-subject

+#!/bin/sh -u
+#
+# Add this message's Subject: line as a pattern in the spam rules.
+#       - Cameron Simpson <cs@zip.com.au> 03nov2012
+#
+
+set -ue
+
+: ${TMPDIR:=/tmp}
+: ${NOTIFY:=$EMAIL}
+
+cmd=`basename "$0"` || exit 1
+usage="Usage: $cmd < email"
+
+tmpf=$TMPDIR/$cmd$$
+trap 'rm -f "$tmpf"' 0 1 2 13 15
+
+filer=$HOME/rc/mail/filer/spam-subj
+
+cat >"$tmpf" || exit 1
+
+eval `mhdrs -sh < "$tmpf" | sed 's/^/hdr_/'`
+subj=$hdr_SUBJECT
+[ -n "$subj" ]
+re_subj=\^$(printf "%s\n" "$subj" | sed '2,$d; s/\\/&&/g')
+[ -n "$re_subj" ]
+
+( cat "$filer"
+  echo "spam SPAM-SUBJ subject:/$re_subj"
+) | rewriteif -D "$NOTIFY" "$filer" sort -u