]> git.madduck.net Git - etc/mutt.git/blob - .mutt/add-tickle-stamp

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:

autoload zargs
[etc/mutt.git] / .mutt / add-tickle-stamp
1 #!/bin/sh
2 set -eu
3
4 file=/dev/stdin
5 if [ -r "${1:-}" ] && [ -w "${1:-}" ]; then
6   file="$1"
7   shift
8 fi
9
10 date=
11 arg="${1:-}"
12 args="$*"
13 if [ -z "$arg" ]; then
14   read -p 'When should I tickle you about this message? ' args
15   arg="${args%% *}"
16 fi
17
18 if [ "$arg" = '-d' ] || [ $# -gt 1 ]; then
19   shift
20   date="$args"
21 else
22   case "$arg" in
23     *[0-9]w) date="now + ${arg%w} weeks 00:00";;
24     *[0-9]m) date="now + ${arg%m} months 00:00";;
25     *[0-9]d) date="now + ${arg%d} days 00:00";;
26     *[0-9]h) date="now + ${arg%h} hours";;
27     @[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
28       date="@${arg#@}";;
29     *' '*) date="$args";;
30     *[!0-9]*) 
31       echo "E: invalid argument: $arg" >&2
32       exit 1
33       ;;
34     *) date="now + $arg days 00:00";;
35   esac
36 fi
37
38 tickle=$(date +'%s (%c)' -d "$date")
39
40 TMPFILE="$(tempfile -d /tmp -p tickle)"
41 trap "rm -f $TMPFILE" 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15
42
43 formail -i "X-Tickle: $tickle" < $file \
44   | formail -R X-Postponed X-Was-Postponed > $TMPFILE
45
46 [ -w "$file" ] && mv $TMPFILE $file
47
48 rm -f $TMPFILE
49 trap - 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15