procmail
[Top] [All Lists]

Re: Bit wise &

2003-09-16 09:05:37
On 16 Sep, David W. Tamkin wrote:
| Homer asked two questions, and Klaus answered both.  This was the second:
| 
| S>     Can environmental variables created inside a perl
| S> script survive back to procmail once the script is ended?
| 
| and Klaus replied,
| 
| R> No, but again you can call Perl and interpret the return value,
| 
| Klaus didn't illustrate that, but I gather he meant something like this:
| 
|   versetbyperl=`/usr/bin/perl -T -w /home/user/script.pl`
| 
| or, if your version of procmail and your OS form a combination under 
| which this usage doesn't cause a segmentation fault,
| 
|   :0 flags # can include `h' or `b' to reduce input to perl
|   * conditions if any
|   varsetbyperl=| /usr/bin/perl -T -w /home/user/script.pl
| 
| where perl puts the value you want for the variable onto stdout. 
| Certainly that's the way to go if you want to get only one variable back 
| from perl.  But if you need to get two or more variables out of one call 
| to perl, I can't improve on Klaus's suggestion:
| 
| R> or call
| R> Perl as a filter and store values in X- header fields, e.g.
| 
| R> :0 hfw
| R> | /usr/bin/perl -T -w  /home/user/script.pl
| 
| R> where script.pl adds headers with information you want to use later in
| R> the program.
| 
| 

Improvement or not, I don't know.  But here's something I do:

LINEBUF = 32768
:0
* $ ^Cc:$wsstar\/$wsneg.*
{
  CC = "$MATCH"
  CCADDR = `perl -e'$_=$ENV{CC};$j=s/.*?([^\s<,]+(_at_)[^\s>,]+)>?/$1, /g;
                     s/,\s*$//;print join(",",$j||0,$_);'`
  :0
  * CCADDR ?? ^^\/[0-9]+
  { CCCOUNT = $MATCH }
  :0
  * CCADDR ?? ^^[0-9]+,\/.*
  { CCADDR = "$MATCH" }
}

That takes a header like:

        Cc: "First Guy" <guy1(_at_)place1(_dot_)tld>, Second Guy 
<guy2(_at_)place2(_dot_)tld>,
                <guy3(_at_)place3(_dot_)tld>

And populates the variables like this:

The perl one-liner populates:

CCADDR = "3,guy1(_at_)place1(_dot_)tld, guy2(_at_)place2(_dot_)tld, 
guy3(_at_)place3(_dot_)tld"

The two following recipes turn that into:

CCCOUNT = 3
CCADDR = "guy1(_at_)place1(_dot_)tld, guy2(_at_)place2(_dot_)tld, 
guy3(_at_)place3(_dot_)tld"

It could be extended to do more than 2 variables simply enough.


-- 
Email address in From: header is valid  * but only for a couple of days *
This is my reluctant response to spammers' unrelenting address harvesting



_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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