#!/bin/bash # # $Id: send-emails-in-directory,v 1.1 2004/06/19 11:50:37 suter Exp $ # Copyright (C) 2004 Mark Suter # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## Our "die" function (think perl) function die () { echo "$@" 1>&2 ; exit 1 ; } ## Peoples' preferences vary widely EDITOR=${EDITOR:=vi} PAGER=${PAGER:=cat} ## Check for our needed binaries hash test $EDITOR $PAGER basename find rm sleep wc sendmail || die $0: required binaries not present ## We expect one arguemnt, the directory with the emails in it directory="$1" test -n "$directory" || die Usage: $(basename $0) directory test -d $directory || die $0: Thing \"$maildir\" is not a directory. ## Initialize the integers typeset -i i=0 typeset -i total=$( find $directory -type f -print | wc -l ) find $directory -type f -print | while read email ; do ## Disply the report $PAGER $email ## Get the From: address from=$(perl -ne'/From: .*<(.*)>/ and print $1' $email) test -z "$from" && continue ## Setup the loop i=i+1 action=v while [ "$action" != "d" -a "$action" != "m" ] ; do read -p "$i/$total: (d)elete, (e)dit, or (m)ail ? " -n 1 action < /dev/tty case $action in "d" ) rm $email && echo eleted. ;; "e" ) echo diting... && $EDITOR $email < /dev/tty ;; "m" ) sendmail -f "$from" -t -i < $email && rm $email && echo ailed. ;; * ) echo " - Huh?" ;; esac done done