procmail
[Top] [All Lists]

Re: Auto-reply recipe

2000-10-21 12:10:55
The system here died on me during my first attempt to reply to Subba, so I'll
try again.

Subba asked,

| I have written the following recipe to auto reply to a headhunter.
| Since I get the mail from this headhunter, once a week, I cannot test it.
| Does this recipe look logically and syntactically correct?

| :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)
| }

You can test it by putting "headhunter.com" in the comment area of the From:
line of a test message to yourself.

| I have extracted SUBJECT and REPLYTO_ at the begining of the procmailrc
| file.  I am using mutt to send the mail, which will save a copy in the
| "sent" folder.

I have quite a few recommendations.  First, you're creating a temporary file
(return.tmp; headhunter.txt and headhunter.tmp we're going to get rid of),
letting go of the lockfile on it, and then using it again.  Although these
messages normally come only once a week, you never know when something may
change and two might arrive at almost the same time.  So we need a regional
lockfile around the entire routine

Second, formail.lock is a poor choice of name.  The name of the lockfile
should relate to the name of the folder it is locking; if you use
formail.lock everywhere formail is involved, you'll find different types of
mail waiting for the same lockfile when they don't have to.

Third, you could have saved the two rm's for a single operation.

But anyway, we won't need any lockfiles (unless you want to change the code
to save a copy of the incoming message) nor any temporary files after all:

 :0
 * ^From:.*headhunter\.com
 {

## Uncomment next two lines to save a copy of the incoming message:
# :0c:
# headhunter

# One sed will do both jobs, and you can filter the text instead of 
# using a temporary file.  Also, the space doesn't need brackets.
# If sed adds "-- Your Message --" here, we won't need to interrupt
# the two cats with an echo later, so one cat will work.
# If your version of sed generates two blank lines after "-- Your Message --";
# remove the last pair of backslashes.
# Also, sed should indent only non-empty lines, and the `g' flag on sed
# substitutions is extraneous when the search string is anchored,

   :0f # Discard [trailing] whitespaces, insert a leading blank
   | expand | sed -e 's/ *$//' -e 's/^./ &/' -e "1i\\
-- Your Message --\\
\\
"

   :0 # note disconnected trailing hyphen in cat's arguments
   | cat headhunter.txt - | mutt -s "$SUBJECT" $REPLYTO_
 }


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>