various fixes
[distro-setup] / mailclean
1 #!/bin/bash
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5 x="$(readlink -f -- "$BASH_SOURCE")"; scriptdir=${x%/*}
6
7
8
9 # find but ignore directories which dont exist, assuming first args are directories
10 # and a following arg starts with -
11 myfind() {
12 dirs=()
13 for d; do
14 if [[ $d == -* ]]; then
15 # past dirs, onto options
16 break
17 fi
18 shift
19 if [[ -e $d ]]; then
20 dirs+=($d)
21 fi
22 done
23 if [[ $dirs ]]; then
24 find ${dirs[@]} $@
25 fi
26 }
27
28 # qemu-devel is our biggest list by far, so occasionally
29 # I want to hop into conversations about our mailing
30 # systems there, but I don't need many old messages.
31 myfind /nocow/user/fsfmd/l/qemu-devel/new -type f -mtime +14 -execdir rm -- '{}' +
32 myfind /nocow/user/fsfmd/{sec,Spam,Drafts,{rtcc,sysadmin,l/outreachy-mentors}/new} -type f -mtime +100 -execdir rm -- '{}' +
33 myfind /nocow/user/fsfmd/log -type f -mtime +300 -execdir rm -- '{}' +
34 myfind /nocow/user/fsfmd/dmarc -type f -mtime +14 -execdir rm -- '{}' +
35
36
37
38 shopt -s nullglob
39 shopt -s extglob
40
41 now=$(date +%s)
42 cd /m/md
43 for d in ./!(*archive|Drafts)/*(cur|new) ./l/!(*archive)/*(cur|new); do
44 madearchive=false
45 leafdir=${d##*/}
46 md=${d%/*}; md=${md##*/}
47 archive=${d%/*/*}/${md}-myarchive/$leafdir
48 archivebase=archive=${d%/*/*}/${md}-myarchive
49 for f in $d/1*; do
50 date=$($scriptdir/email-date.py $f) || echo $f
51 [[ $date ]] || continue
52 if (( date < now - 60*60*24*400 )); then
53 if ! $madearchive; then
54 mkdir -p ${archivebase}{cur,tmp,new}
55 madearchive=true
56 fi
57 mv $f $archive
58 echo mv $f $archive
59 fi
60 done
61 done