procmail
[Top] [All Lists]

Re: Autoresponder (progress?)

1999-06-02 14:04:24
Hello again,

... can someone look at the .procmailrc below and tell me if it will do at
least the following:
1. Autorespond *only* to emails arriving "To: help(_at_)infusia(_dot_)com"
with boilerplate text coming from /autores/info.txt
2. Send a copy to another party as shown
3. Keep a copy in folder "infusia"
and maybe if that works, someone can help me with the logging issue
afterwards.
Oh yeah, lest I forget, will procmail see all of this as one recipe?
Here's the .procmailrc:
----<snip>
VERBOSE=on
SENDMAIL=/usr/sbin/sendmail
MAILDIR=/var/spool/mail
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/log
FILEDIR=$HOME/autores

:0 h c
#ONLY autorespond to email directed to help(_at_)infusia(_dot_)com
* To: help(_at_)infusia(_dot_)com
* !^FROM_DAEMON 
* !^X-Loop: cjraven(_at_)cloud9(_dot_)net
| (formail -r -A"Precedence: junk" \
-A"X-Loop: cjraven(_at_)cloud9(_dot_)net" ; \
cat $FILEDIR/info.txt) | $SENDMAIL -t
#Will procmail see all of the above, plus what follows as one recipe?
{
:0
* ^To: help(_at_)infusia(_dot_)com
{
:0 c
! nilasi(_at_)home(_dot_)com

:0
infusia
}   

From the top:

 SENDMAIL=/usr/sbin/sendmail should not be needed. Procmail learns where
 sendmail is when it is compiled. There are reasons to reset it from the
 default, but I don't believe we see one here.

 The first condition line would benefit from a couple of changes. 

 . It should be anchored to the beginning of a line (unless you also intend
   to catch Apparently-To:, Reply-To:, Resent-To:, and so on).

 . You should allow for zero or more spaces after the colon.

 . You should allow a nickname in addition to the address, as in:
      To: help desk <help(_at_)infusia(_dot_)com>

 . A minor nit -- the . of infusia.com will match any single character; to
   match only a . you need to enter \. (backslashdot).

 . You may also want to accept messages which have been CCd or BCCd to you,
   or otherwise directed to you, and that is the purpose of the macro ^TO_
   (qv in the fine manual).

 Thus, this condition might be rewritten:

      ^TO_help(_at_)infusia\(_dot_)com
 or
      ^to:.*\<help(_at_)infusia\(_dot_)com\>

 ( \< and \> match non-word characters, including end-of-line.) Note that the
 case of the condition text does not matter, except for the names of
 pre-defined macros (^TO_, ^FROM_DAEMON, ...) and variables, unless you have
 the 'D' flag on the recipe-start line.

 You should be more lenient with what you accept with the x-loop test.
 Replace the space which follows the colon with '.*\<' and you will have a
 more forgiving recipe.

 Now for the real problems. Procmail will not see this all as one recipe.
 There are, however, a few ways to cause it to. The first is through the use
 of recipe flags which bind the execution of one recipe to the success of a
 previous recipe, and the second is through grouping of recipes. Here is how
 they work:

      :0
      * condition1a
      * condition1b
      action1

      :0A
      * condition2
      action2

 causes recipe 2 to be executed only if conditions1 are met. Action2 will be
 attempted only if condition2 is also met. If, instead of :0A, you had :0a
 (lower case a), then recipe 2 would be executed only if conditions1 were met
 _and_ action1 succeeded. Similar flags exist for testing failure-to-execute
 (E and e). These can be chained -- RTFM.

      :0
      * condition1a
      * condition1b
      {
        :0
        action1

        :0
        *condition2
        action2
      }

 causes action1 to be executed whenever conditions1 are met, and action2 to
 be executed whenever conditions1 and 2 are met.

 Note that, with both the flag method and the brace-grouping method, if
 action1 is a delivering action processing will stop without examining the
 next recipe unless the 'c' flag is on the action1 recipe.

 Formail -r is less reliable than formail -rt in selecting the proper address
 for reply. The list archive has some discussion on this. You may want the
 standard set of sendmail options as well. These are in SENDMAILFLAGS.

 Assuming that infusia is a file, you should explicitly indicate that locking
 should be used when you have a recipe deliver to it. This is done with the
 trailing : on the recipe start line.

 It isn't clear exactly what you are trying to accomplish with the second to:
 recipe. You could only be within the braces if that were already known to be
 true and the other conditions have been met as well. I will assume that it is
 superfluous, and that what you want to do is to respond with the canned
 response, to forward a copy of the original, and to file away the original.
 This is what your text says, but not the code. Also, your request says that
 the boilerplate is in /autores, while your code says $HOME/autores. Iff
 $HOME is the root directory will these be the same.

 Finally, your example can benefit from indenting to make it more readable
 (although all programmers learn to trust the code but to doubt what is
 implied by comments or indents). Rewriting your recipes above, we might
 expect to see:

 VERBOSE=on
 MAILDIR=/var/spool/mail
 PMDIR=$HOME/.procmail
 LOGFILE=$PMDIR/log
 FILEDIR=$HOME/autores
 
 :0
 *   ^to:.*\<help(_at_)infusia\(_dot_)com\>
 * ! ^FROM_DAEMON 
 * ! ^x-loop:.*\<cjraven(_at_)cloud9\(_dot_)net\>
 {
   :0 h c  
   | ( formail -rt -A "Precedence: junk" \
                   -A "X-Loop: cjraven(_at_)cloud9(_dot_)net" ; \
       cat $FILEDIR/info.txt) \
     | $SENDMAIL $SENDMAILFLAGS -t

   :0 c
   ! nilasi(_at_)home(_dot_)com
 
   :0 :
   infusia
 }   

-- 
Rik Kabel          Old enough to be an adult              
rik(_at_)netcom(_dot_)com

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