Add support for setclassresources() in the pipe transport on FreeBSD,
[exim.git] / src / src / exipick.src
index 89cd2f8fc5a44833634601f78865ca175db756c9..e3967c382a7c3b451e3cf9ead13f144a3602679a 100644 (file)
@@ -1,5 +1,5 @@
 #!PERL_COMMAND
-# $Cambridge: exim/src/src/exipick.src,v 1.6 2005/08/02 16:12:14 jetmore Exp $
+# $Cambridge: exim/src/src/exipick.src,v 1.9 2006/02/16 17:03:16 jetmore Exp $
 
 # This variable should be set by the building process to Exim's spool directory.
 my $spool = 'SPOOL_DIRECTORY';
@@ -8,10 +8,10 @@ use strict;
 use Getopt::Long;
 
 my($p_name)   = $0 =~ m|/?([^/]+)$|;
-my $p_version = "20050802.1";
+my $p_version = "20060216.1";
 my $p_usage   = "Usage: $p_name [--help|--version] (see --help for details)";
 my $p_cp      = <<EOM;
-        Copyright (c) 2003-2005 John Jetmore <jj33\@pobox.com>
+        Copyright (c) 2003-2006 John Jetmore <jj33\@pobox.com>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -71,17 +71,17 @@ push(@ARGV, "\$deliver_freeze")                      if ($G::qgrep_z);
 push(@ARGV, "!\$deliver_freeze")                     if ($G::qgrep_x);
 $G::mailq_bp        = $G::mailq_bp;        # shut up -w
 $G::and             = $G::and;             # shut up -w
-$G::msg_ids         = {};
+$G::msg_ids         = {};                  # short circuit when crit is only MID
 $G::caseless        = $G::caseful ? 0 : 1; # nocase by default, case if both
-@G::recipients_crit = ();
+@G::recipients_crit = ();                  # holds per-recip criteria
 $spool              = $G::spool if ($G::spool);
 my $count_only      = 1 if ($G::mailq_bpc || $G::qgrep_c);
 my $unsorted        = 1 if ($G::mailq_bpr || $G::mailq_bpra || $G::mailq_bpru);
 my $msg             = get_all_msgs($spool, $unsorted);
 my $crit            = process_criteria(\@ARGV);
 my $e               = Exim::SpoolFile->new();
-my $tcount          = 0 if ($count_only);
-my $mcount          = 0 if ($count_only);
+my $tcount          = 0 if ($count_only);  # holds count of all messages
+my $mcount          = 0 if ($count_only);  # holds count of matching messages
 $e->set_undelivered_only(1)      if ($G::mailq_bpru || $G::mailq_bpu);
 $e->set_show_generated(1)        if ($G::mailq_bpra || $G::mailq_bpa);
 $e->output_long()                if ($G::qgrep_l);
@@ -97,7 +97,7 @@ foreach my $m (@$msg) {
                                       && !$G::msg_ids->{$m->{message}});
   if (!$e->parse_message($m->{message})) {
     warn "Couldn't parse $m->{message}: ".$e->error()."\n";
-    next(MSG);
+    next MSG;
   }
   $tcount++;
   my $match = 0;
@@ -119,17 +119,19 @@ foreach my $m (@$msg) {
     }
     if ($@) {
       print STDERR "Error in eval '$c->{cmp}': $@\n";
-      next(MSG);
+      next MSG;
     } elsif ($ret) {
       $match = 1;
-      if ($G::or) { last(CRITERIA); }
-      else        { next(CRITERIA); }
+      if ($G::or) { last CRITERIA; }
+      else        { next CRITERIA; }
     } else { # no match
-      if ($G::or) { next(CRITERIA); }
-      else        { next(MSG);      }
+      if ($G::or) { next CRITERIA; }
+      else        { next MSG;      }
     }
   }
-  next(MSG) if (scalar(@$crit, @local_crit) > 0 && !$match);
+
+  # skip this message if any criteria were supplied and it didn't match
+  next MSG if ((scalar(@$crit) || scalar(@local_crit)) && !$match);
 
   if ($count_only) {
     $mcount++;
@@ -139,7 +141,7 @@ foreach my $m (@$msg) {
 }
 
 if ($G::mailq_bpc) {
-  print "$tcount\n";
+  print "$mcount\n";
 } elsif ($G::qgrep_c) {
   print "$mcount matches out of $tcount messages\n";
 }
@@ -235,8 +237,10 @@ BEGIN {
 
 package Exim::SpoolFile;
 
-$Exim::SpoolFile::ACL_C_MAX = 10;
-#$Exim::SpoolFile::ACL_M_MAX = 10;
+# versions 4.61 and higher will not need these variables anymore, but they
+# are left for handling legacy installs
+$Exim::SpoolFile::ACL_C_MAX_LEGACY = 10;
+#$Exim::SpoolFile::ACL_M_MAX _LEGACY= 10;
 
 sub new {
   my $class = shift;
@@ -378,7 +382,7 @@ sub set_spool {
 # accepts a variable with or without leading '$' or trailing ':'
 sub get_var {
   my $self = shift;
-  my $var  = shift;
+  my $var  = lc(shift);
 
   $var =~ s/^\$//;
   $var =~ s/:$//;
@@ -445,13 +449,23 @@ sub _parse_header {
       if ($tag eq '-acl') {
         my $t;
         return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
-        if ($1 < $Exim::SpoolFile::ACL_C_MAX) {
+        if ($1 < $Exim::SpoolFile::ACL_C_MAX_LEGACY) {
           $t = "acl_c$1";
         } else {
-          $t = "acl_m" . ($1 - $Exim::SpoolFile::ACL_C_MAX);
+          $t = "acl_m" . ($1 - $Exim::SpoolFile::ACL_C_MAX_LEGACY);
         }
         read(I, $self->{_vars}{$t}, $2+1) || return(0);
         chomp($self->{_vars}{$t});
+      } elsif ($tag eq '-aclc') {
+        return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
+        my $t = "acl_c$1";
+        read(I, $self->{_vars}{$t}, $2+1) || return(0);
+        chomp($self->{_vars}{$t});
+      } elsif ($tag eq '-aclm') {
+        return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
+        my $t = "acl_m$1";
+        read(I, $self->{_vars}{$t}, $2+1) || return(0);
+        chomp($self->{_vars}{$t});
       } elsif ($tag eq '-local') {
         $self->{_vars}{sender_local} = 1;
       } elsif ($tag eq '-localerror') {
@@ -596,7 +610,12 @@ sub _parse_header {
     my $bytes = $_;
     return(0) if (read(I, $_, $bytes) != $bytes);
     chomp(); # may regret this later
-    $self->{_vars}{message_linecount} += scalar(split(/\n/)) if ($t ne '*');
+    if ($t ne '*') {
+      # use of this temp variable is a little lame but it prevents a
+      # -w warning (Use of implicit split to @_ is deprecated)
+      my @t = split(/\n/);
+      $self->{_vars}{message_linecount} += scalar(@t);
+    }
     # build the $header_ variable, following exim's rules (sort of)
     if (/^([^ :]+):(.*)$/s) {
       my $v = "header_" . lc($1);
@@ -725,7 +744,7 @@ sub print_message {
       push(@r, $r);
     }
     print $fh " To: ", join(';', @r);
-    if ($self->{_show_vars}) {
+    if ($self->{_show_vars} && scalar(@{$self->{_show_vars}})) {
       print $fh " Vars: ", join(';',
                                 map { "$_='".$self->get_var($_)."'" }
                                     (@{$self->{_show_vars}})