emailrelay/bin/emailrelay-resubmit.sh_
Graeme Walker ed23b3c747 v1.5
2007-04-10 12:00:00 +00:00

64 lines
1.6 KiB
Bash

#!/bin/sh
#
# Copyright (C) 2001-2007 Graeme Walker <graeme_walker@users.sourceforge.net>
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# ===
#
# emailrelay-resubmit.sh
#
# Looks for all failed e-mails in the E-MailRelay spool directory
# and resubmits them. However, if an e-mail has been retried five
# times already then it is not resubmitted again.
#
# usage: emailrelay-resubmit.sh [<spool-dir>]
#
store="__SPOOL_DIR__"
retry_limit="5"
# parse the command line
#
if test $# -ge 1
then
store="${1}"
fi
# check the spool directory is valid
#
if test \! -d "${store}"
then
echo `basename $0`: invalid spool directory >&2
exit 1
fi
# for each failed e-mail...
#
for file in ${store}/emailrelay.*.envelope.bad ""
do
if test -f "${file}"
then
failures="`fgrep MailRelay-Reason: < ${file} | wc -l`"
if test "${failures}" -lt "${retry_limit}"
then
good_file="`echo ${file} | sed 's/\.bad$//'`"
mv -f ${file} ${good_file}
fi
fi
done