]> git.madduck.net Git - etc/mailfilter.git/blob - bin/list-postponed-messages

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:

rewrite processing of postponed messages
[etc/mailfilter.git] / bin / list-postponed-messages
1 #!/bin/sh
2 set -eu
3
4 ME="${0##*/}"
5
6 about()
7 {
8   echo "$ME -- list postponed messages which have expired"
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         -a|--all & list all postponed messages, not only expired ones
22         -s|--stamp & include the time stamp *before* the filename
23         _eof
24 }
25
26 SHORTOPTS=Vhas
27 LONGOPTS=version,help,all,stamp
28
29 maildirs=
30 listall=0
31 timestamp=0
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     -a|--all) listall=1;;
38     -s|--stamp) timestamp=1;;
39     --) :;;
40     *)
41       if [ -d "$opt/cur" ] && [ -d "$opt/new" ] && [ -d "$opt/tmp" ]; then
42         maildirs="$maildirs $opt"
43       else
44         echo "E: unknown argument: $opt" >&2
45         exit 1
46       fi
47       ;;
48   esac
49 done
50
51 if [ -z "$maildirs" ]; then
52   echo "E: no Maildirs specified." >&2
53   exit 2
54 fi
55
56 NOW=$(date +%s)
57
58 for i in $maildirs; do
59   d="${i%/}"
60   echo "$d/new/"
61   echo "$d/cur/"
62 done \
63   | xargs -I {} find {} -type f \
64   | xargs grep '^X-Postponed:' \
65   | while read i; do
66       f="${i%:X-Postponed:*}"
67       ts="${i#*:X-Postponed: }"; ts="${ts%% *}"
68
69       if [ $listall -eq 1 ] || [ $ts -le $NOW ]; then
70         [ $timestamp -eq 1 ] && echo -n "$ts "
71         echo "$f"
72       fi
73     done