procmail
[Top] [All Lists]

Re: Procmail Database Interface?

1999-07-12 12:04:56
On Mon, 12 Jul 1999 14:31:55 -0400,
"Russell D. Weiss" <rweiss(_at_)inforelay(_dot_)com> wrote:
You can probably do something like
   :0
   ! `script $key`
where script is a Perl or shell script, or a dedicated program, which
returns the correct address for $key (which Procmail would somehow
If I can get the "To" e-mail address from the incoming message, run a PERL
script with that as a parameter, have the PERL script return the forwarding
address (where the message should be forwarded to), and then have procmail
take this retrieved address and actually do the forwarding, it would be
perfect.

I'd still try to persuade you to do this differently. If you haven't
yet read the section in the FAQ about this, please have a go at it.
You should probably set up your MTA to do the forwarding for you
somehow.

How can I get procmail to call the PERL script with the correct "To" e-mail
address?  How can I get procmail to find this address and call the PERL
script with it?

Perl can extract the To: field(s) just fine (there can legitimately be
several) or you can take a cheap shot and just extract the first. If
you are unsure of how to do this in Perl, (you can't possibly manage
to write a script which does the rest of the job, but) you can get
Procmail to extract the first To: header thusly:

    :0w
    * ^To:[     ]*\/[^  ].*
    | perl-script "$MATCH"

The Perl script receives the message on standard input, and the
contents of the To: header as the first command-line parameter. We
might as well call up Sendmail directly from Perl so we are assuming
the Perl script calls up Sendmail for us, too (or returns a non-zero
error code if the address looked like bogus).

The parsing of the To: field(s) is really not all that trivial and
might better be externalized to the Perl script as well. Some ideas
for what to look for is in the Email Addressing FAQ, which has a few
useful appendices. <http://www.qz.to/~eli/faqs/addressing.html>

To reiterate the key points in the Procmail Mini-FAQ on this topic
<http://www.iki.fi/era/procmail/mini-faq.html#advanced>, the envelope
information will be lost by the time you invoke Procmail, and trying
to recover it from the To: header is unnecessarily messy at best, and
quite impossible in a number of cases. And there is really no major
gain in invoking Procmail at all; instead, try something like this in
your virtusertable:

    @otherdomain.net    prog:perl-script "%1"

(I'm a Sendmail illiterate so this is probably a syntax error, but if
you know what you're doing, this should hopefully be enough to set you
on the right track.)

If you still want to use Procmail for this, and manage to pass in the
envelope recipient e.g. as the $1 argument, you can just say

    KEY=$1

    :0
    ! `perl-script "$KEY"`

See the documentation for the -a flag for more information about this.

/* 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>