sent mail getting backed up locally
[distro-setup] / mailclean
1 #!/bin/bash
2
3 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
4 source /a/bin/errhandle/err
5
6 source /a/bin/bash_unpublished/source-state
7 if [[ $HOSTNAME != "$MAIL_HOST" ]]; then
8 exit 0
9 fi
10
11
12 # find but ignore directories which dont exist, assuming first args are directories
13 # and a following arg starts with -
14 myfind() {
15 dirs=()
16 for d; do
17 if [[ $d == -* ]]; then
18 # past dirs, onto options
19 break
20 fi
21 shift
22 if [[ -e $d ]]; then
23 dirs+=($d)
24 fi
25 done
26 if (( ${#dirs[*]} )); then
27 find ${dirs[@]} $@
28 fi
29 }
30
31 # qemu-devel is our biggest list by far, so occasionally
32 # I want to hop into conversations about our mailing
33 # systems there, but I don't need many old messages.
34 myfind /m/md/l/qemu-devel/new -type f -mtime +14 -execdir rm -- '{}' +
35 myfind /m/md/l/listhelper-moderatre/new -type f -mtime +14 -execdir rm -- '{}' +
36 myfind /m/md/{sec,Spam,Drafts,{rtcc,sysadmin}/new} -type f -mtime +100 -execdir rm -- '{}' +
37 myfind /m/md/log -type f -mtime +300 -execdir rm -- '{}' +
38 myfind /m/md/dmarc -type f -mtime +60 -execdir rm -- '{}' +
39 myfind /m/md/fsfalerts -type f -mtime +10 -execdir rm -- '{}' +
40
41 # not strictly a mail directory, but it fits well in this script
42 myfind /p/c/.editor-backups -type f -mtime +300 -execdir rm -- '{}' +
43
44
45
46 shopt -s nullglob
47 shopt -s extglob
48
49
50 archive() {
51 days=$1
52 shift
53 for d; do
54 [[ -d $d ]] || continue
55 leafdir=${d##*/} # cur/new
56 archivebase=${d%/*}-myarchive
57 archive=$archivebase/$leafdir
58 mkdir -p ${archivebase}/{cur,tmp,new}
59 find $d -type f -mtime +$days -name '1*' -exec mv '{}' $archive \;
60 # count=$(find $d -type f -mtime +$days -name '1*' | wc -l)
61 # if (( count )); then
62 # echo $d $count
63 # fi
64 done
65 }
66
67 cd /m/md
68 archive 400 ./!(*archive|Drafts|Sent|INBOX)/*(cur|new) ./l/!(*archive)/*(cur|new)
69 archive 60 ./{sysadmin,rtcc,fsfcc,fsfmembers}/{cur,new}
70 archive 14 ./Junk/{cur,new}