summaryrefslogtreecommitdiff
path: root/localrmstaleaccounts
blob: c7c4fde9d127775db359bdc1864f3c62178b6e1d (plain)
  1. #!/bin/sh
  2. set -e
  3. exit1() (
  4. echo >&2 "ERROR: $1"
  5. exit 1
  6. )
  7. warn() (
  8. echo >&2 "WARNING: $1"
  9. )
  10. info() (
  11. echo >&2 "INFO: $1"
  12. )
  13. for user in $@; do
  14. home=$(getent passwd "$user" | cut -d: -f6)
  15. if [ -z "$home" ]; then
  16. warn "Skipping user $user: failed resolving homedir"
  17. elif [ -e "$home/.forward" ]; then
  18. warn "Skipping user $user: Email gets forwarded"
  19. elif [ ! -d "$home/Maildir" ]; then
  20. warn "Skipping user $user: Missing Maildir"
  21. elif untouchedinbox "$home" || untouchednewmail "$home"; then
  22. localrmaccount "$user"
  23. elif untouchedinbox "$home" || untouchednewmail "$home"; then
  24. localrmaccount "$user"
  25. elif find "$home/Maildir/new" -maxdepth 0 -type d -mtime +365 | grep -q .; then
  26. info "Removing user $user: Maildir INBOX/new untouched for a year"
  27. localrmaccount "$user"
  28. elif find "$home/Maildir/cur" -maxdepth 0 -type d -mtime +365 | grep -q .; then
  29. info "Removing user $user: Maildir INBOX/cur untouched for a year"
  30. localrmaccount "$user"
  31. elif find "$home/Maildir/new" -type f -mtime +365 | grep -q .; then
  32. info "Removing user $user: new mail in INBOX untouched for a year"
  33. localrmaccount "$user"
  34. else
  35. info "Skipping user $user"
  36. fi
  37. done