3 # Copyright (C) 2009,2011 Nick Bowler
5 # Delete email older than a given date from a maildir. Assumes that the
6 # Date headers in the mails are valid and correct, and is therefore
7 # somewhat less useful for cleaning up spam.
9 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
10 # This is free software: you are free to do what the fuck you want to.
11 # There is NO WARRANTY, to the extent permitted by law.
16 while getopts 'd:' opt $@; do
28 elif [[ -n $MAIL ]]; then
33 date=`date --rfc-3339=date --date=$cutoff` || exit 1
35 if [[ -z $maildir ]]; then
36 printf '%s: you must specify a maildir.\n' $0
40 if ! [[ -d $maildir/cur && -d $maildir/new && -d $maildir/tmp ]]; then
41 printf '%s: %s is not a valid maildir.\n' $0 $maildir
45 total=`ls $maildir/cur | wc -l`.
48 for i in $maildir/cur/*; do
49 datehdr=`formail -x Date < $i`
50 maildate=`date --rfc-3339=date --date=$datehdr`
54 if [[ $maildate < $date ]]; then
55 printf '(%.0f%%) %s: deleting %s\n' $((100*count/total)) $0 $i
58 printf '(%.0f%%) %s: keeping %s\n' $((100*count/total)) $0 $i