procmail
[Top] [All Lists]

Re: procmail and perl trouble...

1998-08-27 17:01:34
Paul Evad - Kudosnet Communications <paul(_at_)kudosnet(_dot_)com> writes:
I'm trying to grab the email address from an incomming message, pass it to
a perl script for validation, then do something based on that validation.
...
procmail: Executing 
"/home/getfile/checkuser3.pl,nfedder(_at_)GraphicSolutions(_dot_)com"

#this line apparently looks fine to me.... it appears to be passing the
#correct email address to the script. But the following 'warn' statements
#from the perl script suggest this isn't quite what's going on...

was passed From nfedder(_at_)pop(_dot_)mindspring(_dot_)com  Thu Aug 27 
06:05:16 1998 at
/home/getfile/checkuser3.pl line 16, <STDIN> chunk 1.
...

----------.procmailrc [relevant portion]

SHELL=/bin/sh
LOGFILE=procmail.log
COMSAT=no
VERBOSE=on

# first we determine if we are dealing with a 'get' command
:0
* ^Subject: get[ ]*[0-9a-z]
* !^X-Loop: getfile*
* !^Subject:.*Re:
* !^FROM_DEAMON
* !^Subject: get .*[/.]\.
{
 # looks like we got one, so  process accordingly
 :0 H # reverse mailheader and extract name
 * ^Subject: get[ ]*\/[^ ]+
 { FILE="$MATCH" }

 #now get the sender's address
 :0 a
 { F=`formail -rtzxTo:` }

That would be more efficient if written as:

        :0 ah
        F=|formail -rtzxTo:

That way only the header gets fed into formail.  Also, you can then
check the return code of formail.


 # 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/getfile/checkuser3.pl "$F"`
 }
...

Okay, you're passing the address ($F) on the command line.  It should
therefore be availible to the script as $ARGV[0].


---------- perl script.

#!/usr/bin/perl -w

use Mysql;
$database="xxxxx";
$user="xxxxx";
$password="xxxxx";

#expect <STDIN> to be an email address... nothing but an email address

#ignore anything else but the first line...
$_=<STDIN>;

Umm, why are you looking at STDIN???  I think you meant to say:

        $_ = $ARGV[0];


#remove any newlines
chomp;
#from this we get a line FROM email_address

warn "was passed $_";
...

Well, STDIN had the entire message on it, and the "$_ = <STDIN>" read
in the first line, so it contains the "From " pseudo-header.


Philip Guenther

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