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

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:

fix twitter reply filter
[etc/mailfilter.git] / bin / resubmit
1 #!/bin/sh
2 set -eu
3
4 ME="${0##*/}"
5
6 about()
7 {
8   echo "$ME -- resubmit messages to the mail filter"
9   echo "Copyright © martin f. krafft <madduck@madduck.net>"
10   echo "Released under the terms of the Artistic Licence 2.0"
11 }
12
13 usage()
14 {
15   echo "Usage: $ME [options] <Maildir> [<Maildir> ...]"
16   echo
17   echo "Valid options are:"
18   cat <<-_eof | column -s\& -t
19         -V|--version & show version information.
20         -h|--help & show this output.
21         -l|--list & process the argument list (even if empty), never stdin
22         -r|--deliver-read & mark messages read on delivery
23         _eof
24 }
25
26 SHORTOPTS=Vhlr
27 LONGOPTS=version,help,list,deliver-read
28
29 list=0
30 mark_read=0
31 files=
32
33 for opt in $(getopt -n $ME -o $SHORTOPTS -l $LONGOPTS -u -- "$@"); do
34   case "$opt" in
35     -V|--version) about; exit 0;;
36     -h|--help) about; echo; usage; exit 0;;
37     -l|--list) list=1;;
38     -r|--deliver-read) mark_read=1;;
39     --) :;;
40     *)
41       if [ -f "$opt" ] && [ -r "$opt" ]; then
42         files="$files $opt"
43       else
44         echo "E: unknown argument: $opt" >&2
45         exit 1
46       fi
47       ;;
48   esac
49 done
50
51 PROCMAIL=$HOME/.etc/mailfilter/procmail/procmailrc
52
53 if [ "$mark_read" -eq 1 ]; then
54   PROCMAIL="$PROCMAIL DELIVER_READ=1"
55 fi
56
57 # execute the date -R only during the eval, not immediately
58 FILTER='/usr/bin/formail -I"X-Resubmitted: $(date -R)"'
59
60 if [ -z "${files:-}" ] && [ $list -eq 0 ]; then
61   eval $FILTER | exec $PROCMAIL
62 else
63   for f in $files; do
64     eval $FILTER < "$f" | $PROCMAIL && rm -f "$f"
65   done
66 fi
67
68 exit 0