make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / half-baked / mails
blobb539c13027b4750d4ba4eb8e9410bff16d19e402
1 #!/bin/bash
3 . /usr/lib/tool/bash-utils || exit -1
5 opt_maildir=~/Mail/new/
6 opt_newer=''
7 opt_older=''
8 opt_newer_rel=''
9 opt_older_rel=''
11 opt_parser_set_opt()
13 local optname=$1
14 optname=opt_${optname//-/_}
15 if [ "${!optname+x}" != x ]
16 then
17 warnx "option is not known: $1"
18 return 1
20 shift
21 local optval=$1
22 eval "$optname=\$optval"
25 while [ $# -gt 0 ]
27 if [ "$1" = -- ]
28 then
29 shift
30 break
31 elif [[ $1 =~ ^--([a-zA-Z0-9_-]+)=(.*)$ ]]
32 then
33 opt_parser_set_opt "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" || exit -1
34 elif [[ $1 =~ ^--([a-zA-Z0-9_-]+)$ ]]
35 then
36 shift
37 opt_parser_set_opt "${BASH_REMATCH[1]}" "$1" || exit -1
38 elif [[ $1 =~ ^-([a-zA-Z0-9_-]+)$ ]]
39 then
40 flags=${BASH_REMATCH[1]}
41 for (( i=0; i<${#flags}; i++ ))
43 opt_parser_set_opt "${flags:$i:1}" 1 || exit -1
44 done
45 unset flags
46 unset i
48 shift
49 done
51 find "$opt_maildir" -maxdepth 1 -type f \
52 ${opt_newer:+-newermt "$opt_newer"} ${opt_older:+! -newermt "$opt_older"} \
53 ${opt_newer_rel:+-newermt "now - $opt_newer_rel"} ${opt_older_rel:+! -newermt "now - $opt_older_rel"} |\
54 foreach stat -c "%y %n" | sort |\
55 foreach -t -p $'\n''${FIELD[1]}'$'\n''${FIELD[0]}'$'\n' \
56 pipecmd cat {1} -- pipecmd mail-extract-raw-headers -n From Delivered-To To Cc Subject -- mime-header-decode