better i3 handling
[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 /m/md/l/qemu-devel/new -type f -mtime +14 -execdir rm -- '{}' +
32 myfind /m/md/{sec,Spam,Drafts,{rtcc,sysadmin,l/outreachy-mentors}/new} -type f -mtime +100 -execdir rm -- '{}' +
33 myfind /m/md/log -type f -mtime +300 -execdir rm -- '{}' +
34 myfind /m/md/dmarc -type f -mtime +14 -execdir rm -- '{}' +
35 myfind /m/md/fsfalerts -type f -mtime +10 -execdir rm -- '{}' +
36
37
38
39 shopt -s nullglob
40 shopt -s extglob
41
42 now=$(date +%s)
43 cd /m/md
44 for d in ./!(*archive|Drafts)/*(cur|new) ./l/!(*archive)/*(cur|new); do
45 madearchive=false
46 leafdir=${d##*/}
47 md=${d%/*}; md=${md##*/}
48 archivebase=${d%/*/*}/${md}-myarchive
49 archive=$archivebase/$leafdir
50 for f in $d/1*; do
51 date=$($scriptdir/email-date.py $f) || echo $f
52 [[ $date ]] || continue
53 if (( date < now - 60*60*24*400 )); then
54 if ! $madearchive; then
55 echo mkdir -p ${archivebase}/{cur,tmp,new}
56 mkdir -p ${archivebase}/{cur,tmp,new}
57 madearchive=true
58 fi
59 mv $f $archive
60 echo mv $f $archive
61 fi
62 done
63 done