#!/bin/bash set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR x="$(readlink -f -- "$BASH_SOURCE")"; scriptdir=${x%/*} # find but ignore directories which dont exist, assuming first args are directories # and a following arg starts with - myfind() { dirs=() for d; do if [[ $d == -* ]]; then # past dirs, onto options break fi shift if [[ -e $d ]]; then dirs+=($d) fi done if [[ $dirs ]]; then find ${dirs[@]} $@ fi } # qemu-devel is our biggest list by far, so occasionally # I want to hop into conversations about our mailing # systems there, but I don't need many old messages. myfind /m/md/l/qemu-devel/new -type f -mtime +14 -execdir rm -- '{}' + myfind /m/md/{sec,Spam,Drafts,{rtcc,sysadmin,l/outreachy-mentors}/new} -type f -mtime +100 -execdir rm -- '{}' + myfind /m/md/log -type f -mtime +300 -execdir rm -- '{}' + myfind /m/md/dmarc -type f -mtime +14 -execdir rm -- '{}' + myfind /m/md/fsfalerts -type f -mtime +10 -execdir rm -- '{}' + shopt -s nullglob shopt -s extglob now=$(date +%s) cd /m/md for d in ./!(*archive|Drafts)/*(cur|new) ./l/!(*archive)/*(cur|new); do madearchive=false leafdir=${d##*/} md=${d%/*}; md=${md##*/} archivebase=${d%/*/*}/${md}-myarchive archive=$archivebase/$leafdir for f in $d/1*; do date=$($scriptdir/email-date.py $f) || echo $f [[ $date ]] || continue if (( date < now - 60*60*24*400 )); then if ! $madearchive; then echo mkdir -p ${archivebase}/{cur,tmp,new} mkdir -p ${archivebase}/{cur,tmp,new} madearchive=true fi mv $f $archive echo mv $f $archive fi done done