rc/bin/mailarchive

25 lines
615 B
Text
Raw Permalink Normal View History

2019-11-20 22:10:48 +00:00
#!/bin/sh
if [ -z "$2" ]; then
>&2 echo "Usage: $0 <source maildir> <archive maildir>"
exit 1
fi
src="$1"
arch="$2"
begin="2010"
if ! [ -d "$arch/cur" ]; then
>&2 echo "Folder $arch does not appear to be a maildir"
exit 1
fi
umask 700
for y in $(seq "$begin" "$(date '+%Y')" | sort -r); do
mkdir -p "$arch/$y/cur" "$arch/$y/new" "$arch/$y/tmp"
mails=$(mlist "$src" | mpick -t "date <= \"$y-12-31\" && date >= \"$y-01-01\" && date < \"-180d\"" 2> /dev/null)
>&2 printf 'The year is %s. %s emails to sort\n' "$y" "$(echo "$mails" | wc -l)"
echo "$mails" | mrefile "$arch/$y"
done