diff options
author | Jonas Smedegaard <dr@jones.dk> | 2019-04-21 17:11:38 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2019-04-21 17:11:38 +0200 |
commit | 534f0efa0c6ca510675bc4f2ad17f931119c895c (patch) | |
tree | 766d26edb637a7cafdf420cc69877b750a61ae0e | |
parent | d8554a9399b982d7765bd16c9a08ec6360a7aa7f (diff) |
Fix and simplify tests.
-rwxr-xr-x | localrmstaleaccounts | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/localrmstaleaccounts b/localrmstaleaccounts index d095f0d..c7c4fde 100755 --- a/localrmstaleaccounts +++ b/localrmstaleaccounts @@ -11,35 +11,32 @@ warn() ( echo >&2 "WARNING: $1" ) -maybestaleuser() { - warn "Skipping possibly non-stale account for user $user" -} - -untouchedinbox() { - set -e - h="$1"; shift - [ -d "$home/Maildir" ] - find "$home/Maildir/new" -maxdepth 0 -type d -mtime +365 | grep -q . - find "$home/Maildir/cur" -maxdepth 0 -type d -mtime +365 | grep -q . -} - -untouchednewmail() { - set -e - h="$1"; shift - [ -d "$home/Maildir" ] - find "$home/Maildir/new" -type f -mtime +365 | grep -q -} +info() ( + echo >&2 "INFO: $1" +) for user in $@; do home=$(getent passwd "$user" | cut -d: -f6) - [ -n "$home" ] || exit1 "Failed resolving homedir for user $user" - if [ -e "$home/.forward" ]; then - maybestaleuser "$user" - continue - fi - if untouchedinbox "$home" || untouchednewmail "$home"; then + 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" - continue + else + info "Skipping user $user" fi - maybestaleuser "$user" done |