#!/bin/bash
#                       /usr/local/bin/mail_tidy
#  http://crystalfaeries.net/posix/bin/mail_tidy
# celeste:crystalfaery 2016-07-02 21:51:25+00:00
# Tidy my Mail folder
retain=6 # days retention of size 0 mailboxes to ensure that deletions propogate amongst all synchronized hosts = 1 week
for f in $(find ~/Mail -mindepth 1 -maxdepth 1 -size 0 -mtime +$retain \! -name .mail_tidy);do # we have a list of special folders to keep even if empty:
	case $(/usr/bin/basename "${f}") in
		sent)
			ln -s ~/Mail/sent ~/sent	2>/dev/null
			;;	# sent e-mails redirected from ~ to Mail
		postponed)	
			ln -s ~/Mail/postponed ~/postponed	2>/dev/null
			;;	# postponed = drafts redirected from ~ to Mail
		*)
			/usr/local/bin/delete	"${f}"	2>/dev/null
			;;
	esac
done
touch	~/Mail/.mail_tidy	# tidy time stamp


syntax highlighted by Code2HTML, v. 0.9.1