#!/bin/sh set -eu ME="${0##*/}" about() { echo "$ME -- list postponed messages which have expired" echo "Copyright © martin f. krafft " echo "Released under the terms of the Artistic Licence 2.0" } usage() { echo "Usage: $ME [options] [ ...]" echo echo "Valid options are:" cat <<-_eof | column -s\& -t -V|--version & show version information. -h|--help & show this output. -a|--all & list all postponed messages, not only expired ones -s|--stamp & include the time stamp *before* the filename _eof } SHORTOPTS=Vhas LONGOPTS=version,help,all,stamp maildirs= listall=0 timestamp=0 for opt in $(getopt -n $ME -o $SHORTOPTS -l $LONGOPTS -u -- "$@"); do case "$opt" in -V|--version) about; exit 0;; -h|--help) about; echo; usage; exit 0;; -a|--all) listall=1;; -s|--stamp) timestamp=1;; --) :;; *) if [ -d "$opt/cur" ] && [ -d "$opt/new" ] && [ -d "$opt/tmp" ]; then maildirs="$maildirs $opt" else echo "E: unknown argument: $opt" >&2 exit 1 fi ;; esac done if [ -z "$maildirs" ]; then echo "E: no Maildirs specified." >&2 exit 2 fi NOW=$(date +%s) for i in $maildirs; do d="${i%/}" echo "$d/new/" echo "$d/cur/" done \ | xargs -I {} find {} -type f \ | xargs grep --with-filename --text --max-count=150 '^X-Postponed:' \ | while read i; do f="${i%:X-Postponed:*}" ts="${i#*:X-Postponed: }"; ts="${ts%% *}" if [ $listall -eq 1 ] || [ $ts -le $NOW ]; then [ $timestamp -eq 1 ] && echo -n "$ts " echo "$f" fi done