css / 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}

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/[^-A-Za-z0-9_, 	]/\\&/g')
[ -n "$re_subj" ]

( cat "$filer"
  echo "=spam SPAM-SUBJ subject:/$re_subj"
) | rewriteif "$filer" sort -u
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.