summaryrefslogtreecommitdiff
path: root/localrmstaleaccounts
blob: d095f0d8dc12aaf4083ce9a02e772fa503160768 (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. maybestaleuser() {
  11. warn "Skipping possibly non-stale account for user $user"
  12. }
  13. untouchedinbox() {
  14. set -e
  15. h="$1"; shift
  16. [ -d "$home/Maildir" ]
  17. find "$home/Maildir/new" -maxdepth 0 -type d -mtime +365 | grep -q .
  18. find "$home/Maildir/cur" -maxdepth 0 -type d -mtime +365 | grep -q .
  19. }
  20. untouchednewmail() {
  21. set -e
  22. h="$1"; shift
  23. [ -d "$home/Maildir" ]
  24. find "$home/Maildir/new" -type f -mtime +365 | grep -q
  25. }
  26. for user in $@; do
  27. home=$(getent passwd "$user" | cut -d: -f6)
  28. [ -n "$home" ] || exit1 "Failed resolving homedir for user $user"
  29. if [ -e "$home/.forward" ]; then
  30. maybestaleuser "$user"
  31. continue
  32. fi
  33. if untouchedinbox "$home" || untouchednewmail "$home"; then
  34. localrmaccount "$user"
  35. continue
  36. fi
  37. maybestaleuser "$user"
  38. done