[ Regarding someone's query on an automatic email-based contest entry
parser. ]
I see a two part solution for this:
Part 1: A procmmail recipe that recognizes contest email by a token
in the subject field, for instance:
:0
* ^Subject:.*Contest Entry
| /usr/contest/store_entry
Part 2: The store_entry script
This would be an awk or perl script that reads the email message and
outputs the needed data to the specified file:
[ Perl script deleted ].
Actually, "Part 2" can easily be done by procmail also. In fact, "Part
1" and "Part 2" could go something like this:
============================= cut here ===================================
###### -- this procmail rc file is untested
SAVEFILE=contest-data
# Deliver the mail normally unless it is a contest entry
:0
* ! ^Subject:.*Contest Entry
$DEFAULT
ERR # no errors just yet
# Look for the keywords and associated values
:0 B
* TEAM[ ]+\/[^ ]+.*
{ TEAM=$MATCH }
# Missing TEAM
:0 E
{ ERR="The TEAM statement is missing!" }
:0 B
* PRICE[ ]+\/[^ ]+.*
{ PRICE=$MATCH }
:0 E
{ ERR="$ERR
The PRICE statement is missing!" }
:0 B
* PASSWORD[ ]+\/[^ ]+.*
{ PASS=$MATCH }
:0 E
{ ERR="$ERR
The PASSWORD statement is missing!" }
# Get the subject
SUBJ=`formail -zxSubject: | sed -e 's/^Re: *//g'`
# Get the date
DATE=`date`
# Any errors?
:0
* ERR ?? .
{
# replace the headers with a reply header
:0 fh
| formail -rt -I"Subject: Re: $SUBJ"
# replace the body with the error messages, and quote the original
# message
:0 fb
| ( echo $ERR ; sed -e 's/^/> /' )
# Deliver it finally
:0
! -oi -t
}
# Good reply -- save results
# Place the tokens in a file, separated by " : ".
:0 c :$SAVEFILE.lock
| echo "$DATE : $TEAM : $PRICE : $PASS" >> $SAVEFILE
# Now, give the sender a nice confirmation reply
# Generate the reply header
:0 fh
| formail -rt -I"Subject: Re: $SUBJ"
# Generate the body
:0 fb
| echo "Your entry for $TEAM has been recorded. Thank you."
# Mail it and be done
:0
! -oi -t