#!/bin/bash # I, Ian Kelling, follow the GNU license recommendations at # https://www.gnu.org/licenses/license-recommendations.en.html. They # recommend that small programs, < 300 lines, be licensed under the # Apache License 2.0. This file contains or is part of one or more small # programs. If a small program grows beyond 300 lines, I plan to switch # its license to GPL. # Copyright 2024 Ian Kelling # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi source /a/bin/bash-bear-trap/bash-bear source /a/bin/bash_unpublished/source-state if [[ $HOSTNAME != "$MAIL_HOST" ]]; then exit 0 fi # 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/l/listhelper-moderatre/new -type f -mtime +14 -execdir rm -- '{}' + myfind /m/md/{sec,Spam,Drafts,{rtcc,sysadmin}/new} -type f -mtime +100 -execdir rm -- '{}' + myfind /m/md/log -type f -mtime +300 -execdir rm -- '{}' + myfind /m/md/dmarc -type f -mtime +60 -execdir rm -- '{}' + myfind /m/md/fsfalerts -type f -mtime +10 -execdir rm -- '{}' + # not strictly a mail directory, but it fits well in this script myfind /p/c/.editor-backups -type f -mtime +300 -execdir rm -- '{}' + shopt -s nullglob shopt -s extglob archive() { days=$1 shift for d; do [[ -d $d ]] || continue leafdir=${d##*/} # cur/new archivebase=${d%/*}-myarchive archive=$archivebase/$leafdir mkdir -p ${archivebase}/{cur,tmp,new} find $d -type f -mtime +$days -name '1*' -exec mv '{}' $archive \; # count=$(find $d -type f -mtime +$days -name '1*' | wc -l) # if (( count )); then # echo $d $count # fi done } cd /m/md archive 800 ./!(*archive|board|Drafts|Sent|INBOX)/*(cur|new) ./l/!(*archive)/*(cur|new) archive 60 ./{sysadmin,rtcc,fsfcc,fsfmembers}/{cur,new} archive 30 ./Junk/{cur,new} # This is a generally useless file which will grow to 1gb and eat up memory. # https://doc.dovecot.org/admin_manual/known_issues/large_cache/ # I could probably disable the cache for this folder, but that would # also mean I'm testing less of the full functionality. rm -f /m/md/l/testignore/dovecot.index.cache