procmail
[Top] [All Lists]

Re: Perl scripts not recognized as such?

2008-12-05 06:01:25
Bill Oakley schreef:

------------------------------- begin  -------------------------------

#!/usr/local/perl/bin/perl

my $rwFrom = '(Jeremiah Builds|builds|Polly Prerel|prerel)';

while (<STDIN>) {
  if (/^From: (.*)/) {
    exit 0 if $1 =~ /$rwFrom/;
  } elsif (/^Subject: (.*)/) {
    exit 0 if $1 =~ /\[Qt-interest\]/;
  }
}

exit 1;

-------------------------------- end  --------------------------------


At least put a SHELL=/bin/sh in the top of your .procmailrc.


Rewrite of your Perl script:
------------------------------- begin  -------------------------------

#!/usr/bin/perl
  use strict;
  use warnings;

  my $re_From = qr/Jeremiah Builds|builds|Polly Prerel|prerel/;

  my $hdr;
  {   local $/ = "";  # paragraph mode
      ($hdr = <STDIN>) =~ s/\n+(?=\s)//g;  # unfolded header
  }

  for ( $hdr ) {
      exit 0 if /^From:.*${re_From}/m;
      exit 0 if /^Subject:.*\[Qt-interest\]/m;
  }
  exit 1;

-------------------------------- end  --------------------------------

(untested)

Nicer would be to create a hash like

  my %re = (
    "From:"    => qr/Jeremiah Builds|builds|Polly Prerel|prerel/,
    "Subject:" => qr/\[Qt-interest\]/,
  );

and work from there.

-- 
Groet, Ruud

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail