#!/bin/bash MAILIN=/tmp/lijst_mailin.$$ HEADERS=/tmp/lijst_headers.$$ REPLY=/tmp/lijst_reply.$$ TMPLIST=/tmp/lijst_tmp.$$ # these all create temporary files # create log entry, handy for seeing if it works logger -p mail.info -t LIST '[$$] Mail from <'$SENDER'>' # save mail cat > $MAILIN # save headers grep -B200 -m 1 -e ^$ $MAILIN > $HEADERS # get subject SUBJECT=$(grep -m1 -e ^Subject $HEADERS | awk -F : {'print $2'}) # messages go to 'list+todo@mydomain.com', the next line grabs the part between + and @ TYPE=$(grep -m1 -e ^To $HEADERS | sed -e 's/^.*+\(.*\)@.*$/\1/') RCPT=$(grep -m1 -e ^To $HEADERS | sed -e 's/^To://') $TYPE $SUBJECT > $TMPLIST # if the message went to 'list+todo@mydomain.com' and the subject is 'list' this will be: 'todo list > $TMPLIST' # creates the reply echo 'To: '$SENDER > $REPLY echo 'From: '$RCPT'(Responder)' >> $REPLY echo 'Subject: Re:'$SUBJECT >> $REPLY echo '' >> $REPLY cat $TMPLIST >> $REPLY echo '.' >> $REPLY # Send email off /usr/sbin/sendmail -r $RECIPIENT $SENDER < $REPLY # Delete temp files rm -f $MAILIN &> /dev/null rm -f $HEADERS &> /dev/null rm -f $REPLY &> /dev/null rm -f $TMPLIST &> /dev/null # Create log entry logger -p mail.info -t LIST '[$$] Mail from <'$SENDER'> - response sent' exit