#!/bin/sh set -e exit1() ( echo >&2 "ERROR: $1" exit 1 ) warn() ( echo >&2 "WARNING: $1" ) info() ( echo >&2 "INFO: $1" ) for user in $@; do home=$(getent passwd "$user" | cut -d: -f6) if [ -z "$home" ]; then warn "Skipping user $user: failed resolving homedir" elif [ -e "$home/.forward" ]; then warn "Skipping user $user: Email gets forwarded" elif [ ! -d "$home/Maildir" ]; then warn "Skipping user $user: Missing Maildir" elif untouchedinbox "$home" || untouchednewmail "$home"; then localrmaccount "$user" elif untouchedinbox "$home" || untouchednewmail "$home"; then localrmaccount "$user" elif find "$home/Maildir/new" -maxdepth 0 -type d -mtime +365 | grep -q .; then info "Removing user $user: Maildir INBOX/new untouched for a year" localrmaccount "$user" elif find "$home/Maildir/cur" -maxdepth 0 -type d -mtime +365 | grep -q .; then info "Removing user $user: Maildir INBOX/cur untouched for a year" localrmaccount "$user" elif find "$home/Maildir/new" -type f -mtime +365 | grep -q .; then info "Removing user $user: new mail in INBOX untouched for a year" localrmaccount "$user" else info "Skipping user $user" fi done