procmail
[Top] [All Lists]

Re: Pass to perl.

1999-12-08 10:32:32
On Sun, 5 Dec 1999 11:43:56 -0800 (PST), Paul Evad
<pevad(_at_)gold(_dot_)baremetal(_dot_)com> wrote (backwards quoting repaired):
On Sun, 5 Dec 1999, Jason C. Leach wrote:
How would I pass something from procmail to purl? Say the To or
Subject field?

This is a question which comes up relatively frequently. It is thus in
the FAQ <http://www.iki.fi/era/procmail/mini-faq.html> and you should
find some earlier replies from the on-line archives, too; those are at
<http://www.rosat.mpe-garching.mpg.de/mailing-lists/procmail/>

There are several good answers but the best one is often "change your
Perl script so you don't have to". If you're passing the message to
Perl anyhow, it might be best to defer any message parsing to the Perl
script itself; that way, the script is self-contained, and it's easier
to test it e.g. from the command line with a few good sample messages.

Here is how I did it once... 
  :0 H # reverse mailheader and extract name
  * ^Subject: get[ ]*\/[^ ]+
  { FILE="$MATCH" }
  #now get the sender's address
  :0 a
  { F=`formail -rtzxTo:` }
  # here we pass the F variable to the checkuser script to 
  # see if it's a valid user. Based on the error code returned
  # send an appropriate message. 
  :0 a
  * ! F ?? ^^^^
  {
    RESULT = `$HOME/checkuser3.pl "$F"`
  }

Gargle. This should probably be simplified to

    :0  # H is the default anyway
    * ^Subject: get[    ]*\/[^  ]+
    {
        FILE=$MATCH
        F=`formail -rtzxTo:`
        # This is virtually guaranteed to return +something+ so we
        #  don't worry about checking for a return value
        RESULT=`$HOME/checkuser3.pl "$F"`
    }

This in itself is of course a good example of a case where it +does+
make sense to extract information from within Procmail and then pass
that information to a Perl script on the command line.

If we are allowed to speculate a bit about how the rest of this script
looks, it might even be possible to further simplify it:

    :0
    * ^Subject: get[    ]*\/[^  ]+
    * ! ?? MATCH (.[/.])
    * test -f $MAILDIR/ftp-by-mail/$MATCH
    * ? formail -rzxTo: | $HOME/checkuser4.pl  # like check3 but reads stdin
    | reply somehow

On the other hand, a typical ftp-by-mail server should proably be
implemented in stages, so that it sends some sort of reply anyway, but
only a short rejection notice if the user does not pass the checkuser
test.

Hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

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