summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlocalrmstaleaccounts49
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