procmail
[Top] [All Lists]

Re: a mini "vacation" recipe, help check?

1996-12-09 08:07:36
  > I'm going to be gone for two weeks.  Most people I deal with are
  > used to me answering my email almost immediately.  I want to do a
  > mini-vacation program, sending messages only to those who send me
  > email directly to the username "luomat" (at various accounts which
  > are all forwarded to one, which has procmail at it) or to the
  > username "next-ftp"

  > Here's what I am thinking:

Did you know that if you set MAILDIR, it is the same as doing a "chdir
$MAILDIR", which means that files within "$MAILDIR" can all be named
without a path name?  With "plain" files, sometimes you don't need to
use a variable.

Also, I see inconsistent usage below: several usages of $PROCDIR/ and
one $PROCMAIL/.   If you have no other user for MAILDIR, then if you set
MAILDIR to the value of $PROCDIR, then you can avoid having to specify
PROCDIR everywhere.

  > PROCDIR=$HOME/.procmail
  > SENDER=`formail -rtzxTo:`
  > 
  > VACATIONMSG=$PROCMAIL/I.am.gone

Do you mean "$PROCDIR" here?

  > NOTIFIED=$PROCDIR/notified
  > 
  > :0c
  > * ! ^FROM_DAEMON
  > * ^TOluomat|^TOnext-ftp

Don't forget this recipe condition, to make sure you don't respond to
yourself.

    * ! ^(From |From:)(.*[^a-zA-Z0-9_.-])?luomat

You also don't want to respond to someone else's autoresponse for
vacation or some other purpose:  So, a condition like this is needed:

    * !^Subject:(\[(ack(nowledge?ment)?|on vacation)\]|\
                auto(matic)[- ]reply|\
                away from mail|\
                out of town|\
                can ?not (reply|answer)|\
                (on |via )vacation( program)?)

I won't claim that this is complete, but it catches most of the
autoresponse subjects I've seen for a while.

And, in the very strange, but possible, situation of a previous response
somehow making its way back to you, you'll want a recipe condition like
this, which will avoid mail tagged with the "X-Loop:" header (see
below):

    * !^X-Loop: luomat(_at_)peak(_dot_)org

This should be:

    * ^TO(luomat|next-ftp)

Not just because it is prettier, but because "^TO" is a macro for a
fairly hairy regexp, and using "^TO" twice doubles the hairyness.

  > * ? test -f $VACATIONMSG
  > * ! ? grep "$SENDER" "$NOTIFIED"

You should make "grep" work silently, by using the '-s' option.
You don't need to quote the filename.

    * !? grep -s "$SENDER" $NOTIFIED

One thing you should know: using "$vars in recipe conditions usually
requires a leading '$' to tell procmail to expand them, especially when
using variables in regular expressions.  

On the other hand, when invoking shell commands, the $vars get placed
into the environment, and the shell does the variable substitution.  If
you are expecting the shell to do variable substitution on the
*contents* of your variable, then you must have procmail do the
substitution before invoking the shell.  If you are never going to do
anything fancy like that, then don't worry about it.

  > {
  >     :0
  >     |(formail -rt -I"From: Timothy Luoma <luomat(_at_)peak(_dot_)org>" ; \
  >       /bin/cat $VACATIONMSG )|$SENDMAIL -oi -t

If you want the recipe below to work, you'll need to place a 'c" on the
recipe above; otherwise, when it completes with status 0, procmail will
quit.

  >     :0hi $NOTIFIED.lock
  >     |/bin/echo "$SENDER" >> $NOTIFIED

In order for the lockfile above to actually work you'll need a ':' in
front of it.

In order to avoid mail loops, you'll also need to insert an X-Loop:
header.

To assist the recipients of your automatic responses, some of whom may
not be pleased with auto-response systems, you should set the
Precedence: header in your reply; I don't know of many MUA's which
actually do something with it, but it is considered good practise to set
that header accordingly.  For responses, I set it to "junk".

Finally, since there are just two recipes in this nested block, you can
make the second one an 'a' flag recipe, which will cause it to be
invoked only if the previous recipe was executed successfully.

So, let's rewrite the entire recipe with of all these suggestions:

    MAILDIR=$HOME/.procmail             # does a "chdir" too
    SENDER=`formail -rtzxTo:`
    VACAMSG=I.am.gone
    MY_ADDR=luomat(_at_)peak(_dot_)org
    FROMSIG="Timothy Luoma's Mail-Agent <$MY_ADDR>"

    :0 hc
    * ? test -f $VACATIONMSG
    * ^TO(luomat|next-ftp)
    * ! ^FROM_DAEMON
    * ! ^(From |From:)(.*[^a-zA-Z0-9_.-])?luomat
    * ! ^Subject: *\/.*(\[(ack(nowledge?ment)?|on vacation)\]|\
                auto(matic)[- ]reply|\
                away from mail|\
                out of town|\
                can ?not (reply|answer)|\
                (on |via )vacation( program)?)
    * !? grep -s "$SENDER" notified
    * $!^X-Loop: $MYADDR
    | ( formail -rt -I"From: $FROMSIG" \
                    -I"Subject: On vacation (re: $SUBJ
                    -I"X-Loop: $MY_ADDR" \
                    -I"Precedence: junk" ; \
      cat $VACAMSG ) | $SENDMAIL -oi -t

    :0 ahi: notified.lock
    |echo "$SENDER" >>notified

  > Whatdya think?  I know you have a much more detailed thing for  
  > this, but I'm looking for something rather simple that I can  
  > understand.

  > Suggestions, comments, and "gotchas" appreciated

Now, if you have a copy of my "ackmail.rc" recipe file, and have read
it, then you could have written an even simpler recipe:

  MAILDIR=$HOME/.procmail
  VACAMSG=I.am.gone
  MY_ADDR=luomat(_at_)peak(_dot_)org
  MY_NAMES="Timothy Luoma"
  FROMSIG="Timothy Luoma's Mail-Agent <$MY_ADDR>"

  INCLUDERC=ackmail.rc                  # perform vacation response

Isn't this much simpler?  And, on top of that, it works great.  I've
been using for several years.

Anyway, good luck and have a nice vacation.

___________________________________________________________
Alan Stebbens <aks(_at_)sgi(_dot_)com>      http://reality.sgi.com/aks

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