Add mblaze maildir archiving script

This commit is contained in:
lhark 2019-11-20 22:10:48 +00:00
parent a1d2af019f
commit f7b99e07d1

24
bin/mailarchive Executable file
View file

@ -0,0 +1,24 @@
#!/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