#!/bin/sh # bin eaddress-sort -i "-vD" -- \ # eaddress-sort -- finds older mail and sorts mail by the date sent and the mailing list or the best from address revision='$Revision: 1.6 $'; version(){ cat < This is free software; see the GNU General Public License version 2 or later for copying conditions. There is NO warranty. VRS false; } help() { cat <> "$SRTR_LOGFILE" } sort_mail() { local file; ### Filter files into $SRTR_DIR/YYYY-MM/(mail_list_addr|best_from_addr) while read -r file; do [ "$file" ]&& [ -f "$file" ]|| continue; $sorter_pgm "$SRTR_DIR" <"$file"&& [ -z "$SORT_DEBUG" ]&& log_mail $(rm -f $verb "$file") done } warn() { echo $pgm:\ "$@">&2;} readonly sorter_cfg="$HOME/.${sorter_pgm}" sorter_pgm=eaddress-sorter; yyyy_mm=`date +%Y-%m`; # default values MAILDIR=$HOME/Mail SRTR_DIR=Year-Mo_From SRTR_LOGFILE=log/sorter.$yyyy_mm; SORT_FIND="-mtime +7"; UMASK=077; [ ! -f "$sorter_cfg" ]|| . "$sorter_cfg"|| exit; pgm=eaddress-sort one="DHVv" umask $UMASK; while getopts "d:f:S:$one" option;do case "$option" in H) help;; V) version $revision;; S) set $OPTARG;; D) SORT_DEBUG=y;; d) SRTR_DIR="$OPTARG";; f) SORT_FIND="$OPTARG";; v) verb=-v;; \?) false;; *) false;; esac|| exit; done shift $(($OPTIND-1)); hash $sorter_pgm|| exit; [ "$MAILDIR" ]|| error "MAILDIR variable is null"|| exit; cd "$MAILDIR"|| exit; [ "$SRTR_LOGFILE" ]|| error "SRTR_LOGFILE variable is null"|| exit; [ -d "$SRTR_DIR" ]|| mkdir -p $verb "$SRTR_DIR"|| exit if [ "$SORT_DEBUG" ]; then SRTR_LOGFILE="${SRTR_LOGFILE}.debug" fi while [ $# -gt 0 ]; do [ -d "$1/cur" ]&& find "$1/cur" $SORT_FIND | sort_mail; shift done;