]> git.madduck.net Git - etc/mailfilter.git/blob - bin/kill-from

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

use queue postfix on variables
[etc/mailfilter.git] / bin / kill-from
1 #!/bin/sh
2 set -eu
3
4 IGNORE_FILE="${0%/*}/../config/ignore"
5 ME="${0##*/}"
6
7 case "$ME" in
8   kill-from)
9     case "${1:-}" in
10       *@*) :;;
11       '') 
12         echo "E: missing email address argument." >&2
13         exit 1
14         ;;
15       *)
16         echo "E: not an email address: $1" >&2
17         exit 2
18         ;;
19     esac
20     CHECKPREFIX='From: someone <'
21     CHECKPOSTFIX='>'
22     REPREFIX='^From:.*'
23     REPOSTFIX=''
24     ARG="$1"
25     ;;
26   kill-thread)
27     case "${1:-}" in
28       *@*) :;;
29       '') 
30         echo "E: missing message ID argument." >&2
31         exit 1
32         ;;
33       *)
34         echo "E: not a message ID: $1" >&2
35         exit 2
36         ;;
37     esac
38     CHECKPREFIX='References: <something> '
39     CHECKPOSTFIX='>'
40     REPREFIX='^References:.*'
41     REPOSTFIX=''
42     ARG="${1#<}"; ARG="${ARG%>}"
43     ;;
44 esac
45
46 if echo "$CHECKPREFIX$1$CHECKPOSTFIX" | egrep -qif $IGNORE_FILE; then
47   echo "I: already ignored: $1" >&2
48   exit 0
49 fi
50
51 ARG_ESCAPED="$(echo "$ARG" | sed -re 's,([.+]),\\\1,g')"
52 cat <<_eof >> $IGNORE_FILE
53 $^# $(date +%Y.%m.%d.%H.%m.%S) added by ${0##*/}
54 $REPREFIX$ARG_ESCAPED$REPOSTFIX
55 _eof