Subba Rao wrote:
Hi,
I have written the following receipe to auto reply to a headhunter.
Since I get the mail from this headhunter, once a week, I cannot test it.
Can't test it? How about using an old message and a procmail testbed?
From Jari's procmail tips (old version):
# 5.1 What is dry run testing [toc]
#
# It means that you call your procmail test script directly with
# sample test mail
#
# % procmail $HOME/pm/pm-test.rc < $HOME/tmp/test-mail.txt
#
# The script pm-test.rc has the procmail recipe you're testing ...
Does this receipe look logically and syntactically correct?
If two qualifying messages might come right on top of each other, then
I think you need to change the recipe to something like this. Besides
the two lines marked "###added###", please note that I changed the
flags.
:0
* ^From:.*headhunter\.com
{
LOCKFILE=formail.lock ###added###
:0cw
# Discard whitespaces, insert a leading blank
| expand | sed -e 's/[ ]*$//g' | sed -e 's/^/ /' > return.tmp
:0hwi
| (cat headhunter.txt > headhunter.tmp;\
echo "-- Your Message --" >> headhunter.tmp;\
cat return.tmp >> headhunter.tmp;\
rm -f return.tmp;\
mutt -s ${SUBJECT} ${REPLYTO_} < headhunter.tmp;\
rm -f headhunter.tmp)
LOCKFILE ###added###
}
Do you see why the lockfile change? Let two messages arrive on top of
each other. In the original, one message will enter the "| expand..."
block, holding formail.lock. The second message will wait. As soon
as the first one is complete, the second message may enter that
recipe, over-writing the contents of return.tmp.
The new version, above, holds the lockfile from the "| expand..." 's
start until the "| (cat ..." block's end.
I changed the flags from :0c: to ":0cw" because, first, the local
lockfile is deleted, and second, we want the first recipe to wait 'til
the expand/sed/sed to finish (thus the 'w').
On the second line, I added flags 'i' to ignore write errors on early
closed pipe. This is because your delivering recipe doesn't use stdin
at all; hence the input pipe may be closed early and you'd encounter a
write error on that pipe. I added 'w' so that the lockfile would be
held until we were done. Finally I added 'h' to save some CPU cycles,
as procmail then won't waste time trying to write the message body to
the pipe as well (when you're ignoring it anyway).
:0
* ^From:.*headhunter\.com
{
:0c:formail.lock
# Discard whitespaces, insert a leading blank
| expand | sed -e 's/[ ]*$//g' | sed -e 's/^/ /' > return.tmp
:0:formail.lock
| (cat headhunter.txt > headhunter.tmp;\
echo "-- Your Message --" >> headhunter.tmp;\
cat return.tmp >> headhunter.tmp;\
rm -f return.tmp;\
mutt -s ${SUBJECT} ${REPLYTO_} < headhunter.tmp;\
rm -f headhunter.tmp)
}
Finally, it occurs to me that maybe it would be better to just make
the whole thing into a single recipe and eliminate all temp files,
like this:
:0
* ^From:.*headhunter\.com
| (cat headhunter.txt; echo "-- Your Message --"; \
expand | sed -e 's/[ ]*$//g' | sed -e 's/^/ /' ) \
| mutt -s ${SUBJECT} ${REPLYTO_}
This is completely untested but "basically, it should work."
hth
--
Neither I nor my employer will accept any liability for any problems
or consequential loss caused by relying on this information. Sorry.
Collin Park Not a statement of my employer.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail