#!/bin/sh # forward-spool - forward a user's mail spool to another address, # optionally deleting the spool when done # # Rob Funk # check for help request if [ -z "$1" -o "x$1" = "x-h" ] then cat < "$1".lock) fi fi } unlock() { # Unlock spool if [ -x "$lockfile" ]; then if [ "`dirname $1`" = "$maildir" ]; then unlockcmd="lockfile -mu" else unlockcmd="rm -f $1.lock" fi (LOGNAME="`basename $1`"; export LOGNAME; $unlockcmd) else rm -f "$1.lock" fi } # Now lock it lock "$1" # count # of messages in spool msgcount=`grep '^From ' "$1" | wc -l | awk '{print $1}'` spoolsize=`ls -s "$1" | awk '{print $1}'` # die if nothing to do if [ $spoolsize -eq 0 ] then echo "No mail in $1 to forward!" unlock "$1" exit 0 fi echo "There are $msgcount messages in this spool," echo " totalling $spoolsize K" # now we just forward from $1 to $2 echo "Forwarding all mail in $1" echo " to $2 . . ." cat "$1" | formail -ts $sendmail "$2" if [ $? -ne 0 ] then echo "Error forwarding mail!" 1>2 unlock "$1" exit 1 fi echo "Done!" # now delete if requested... if [ $del -eq 1 ] then echo "Removing $1" rm -f "$1" echo "$1 has now been removed" fi # remove lock unlock "$1" exit 0