072e4046e4637279451b7ab4ffdb102c947dd3f8
[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
42
43 shopt -s nullglob
44 shopt -s extglob
45
46
47 archive() {
48 days=$1
49 shift
50 for d; do
51 [[ -d $d ]] || continue
52 leafdir=${d##*/} # cur/new
53 archivebase=${d%/*}-myarchive
54 archive=$archivebase/$leafdir
55 mkdir -p ${archivebase}/{cur,tmp,new}
56 find $d -type f -mtime +$days -name '1*' -exec mv '{}' $archive \;
57 # count=$(find $d -type f -mtime +$days -name '1*' | wc -l)
58 # if (( count )); then
59 # echo $d $count
60 # fi
61 done
62 }
63
64 cd /m/md
65 archive 400 ./!(*archive|Drafts|Sent|INBOX)/*(cur|new) ./l/!(*archive)/*(cur|new)
66 archive 60 ./{sysadmin,rtcc,fsfcc,fsfmembers}/{cur,new}
67 archive 14 ./Junk/{cur,new}