exipick: support for named queues
[exim.git] / src / src / exipick.src
index 9826aaffdbdcab9e97a1e356cb09c05e7fd08380..86a010c86bb000f33af17e9a1b741ab0f4e08c73 100644 (file)
@@ -1,17 +1,29 @@
 #!PERL_COMMAND
-# $Cambridge: exim/src/src/exipick.src,v 1.10 2006/03/07 20:58:55 jetmore Exp $
+# Copyright (c) 1995 - 2018 University of Cambridge.
+# See the file NOTICE for conditions of use and distribution.
 
-# This variable should be set by the building process to Exim's spool directory.
-my $spool = 'SPOOL_DIRECTORY';
+
+# This variables should be set by the building process
+my $spool = 'SPOOL_DIRECTORY'; # may be overridden later
+my $exim  = 'BIN_DIRECTORY/exim';
+
+# Need to set this dynamically during build, but it's not used right now anyway.
+my $charset = 'ISO-8859-1';
+
+# use 'exipick --help' to view documentation for this program.
+# Documentation also viewable online at
+#       http://www.exim.org/eximwiki/ToolExipickManPage
 
 use strict;
+BEGIN { pop @INC if $INC[-1] eq '.' };
 use Getopt::Long;
+use File::Basename;
 
 my($p_name)   = $0 =~ m|/?([^/]+)$|;
-my $p_version = "20060307.0";
+my $p_version = "20100323.0";
 my $p_usage   = "Usage: $p_name [--help|--version] (see --help for details)";
 my $p_cp      = <<EOM;
-        Copyright (c) 2003-2006 John Jetmore <jj33\@pobox.com>
+        Copyright (c) 2003-2010 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
@@ -25,7 +37,7 @@ my $p_cp      = <<EOM;
 
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 EOM
 ext_usage(); # before we do anything else, check for --help
 
@@ -33,7 +45,11 @@ $| = 1; # unbuffer STDOUT
 
 Getopt::Long::Configure("bundling_override");
 GetOptions(
-  'spool:s'     => \$G::spool,      # exim spool dir
+  'spool=s'     => \$G::spool,      # exim spool dir
+  'C|Config=s'  => \$G::config,     # use alternative Exim configuration file
+  'input-dir=s' => \$G::input_dir,  # name of the "input" dir
+  'queue=s'     => \$G::queue,      # name of the queue
+  'finput'      => \$G::finput,     # same as "--input-dir Finput"
   'bp'          => \$G::mailq_bp,   # List the queue (noop - default)
   'bpa'         => \$G::mailq_bpa,  # ... with generated address as well
   'bpc'         => \$G::mailq_bpc,  # ... but just show a count of messages
@@ -43,33 +59,60 @@ GetOptions(
   'bpu'         => \$G::mailq_bpu,  # ... only undelivered addresses
   'and'         => \$G::and,        # 'and' the criteria (default)
   'or'          => \$G::or,         # 'or' the criteria
-  'f:s'         => \$G::qgrep_f,    # from regexp
-  'r:s'         => \$G::qgrep_r,    # recipient regexp
-  's:s'         => \$G::qgrep_s,    # match against size field
-  'y:s'         => \$G::qgrep_y,    # message younger than (secs)
-  'o:s'         => \$G::qgrep_o,    # message older than (secs)
+  'f=s'         => \$G::qgrep_f,    # from regexp
+  'r=s'         => \$G::qgrep_r,    # recipient regexp
+  's=s'         => \$G::qgrep_s,    # match against size field
+  'y=s'         => \$G::qgrep_y,    # message younger than (secs)
+  'o=s'         => \$G::qgrep_o,    # message older than (secs)
   'z'           => \$G::qgrep_z,    # frozen only
   'x'           => \$G::qgrep_x,    # non-frozen only
   'c'           => \$G::qgrep_c,    # display match count
   'l'           => \$G::qgrep_l,    # long format (default)
   'i'           => \$G::qgrep_i,    # message ids only
   'b'           => \$G::qgrep_b,    # brief format
-  'freeze:s'    => \$G::freeze,     # freeze data in this file
-  'thaw:s'      => \$G::thaw,       # thaw data from this file
+  'size'        => \$G::size_only,  # sum the size of the matching msgs
+  'not'         => \$G::negate,     # flip every test
+  'R|reverse'   => \$G::reverse,    # reverse output (-R is qgrep option)
+  'sort=s'      => \@G::sort,       # allow you to choose variables to sort by
+  'freeze=s'    => \$G::freeze,     # freeze data in this file
+  'thaw=s'      => \$G::thaw,       # thaw data from this file
   'unsorted'    => \$G::unsorted,   # unsorted, regardless of output format
+  'random'      => \$G::random,     # (poorly) randomize evaluation order
   'flatq'       => \$G::flatq,      # brief format
   'caseful'     => \$G::caseful,    # in '=' criteria, respect case
   'caseless'    => \$G::caseless,   #   ...ignore case (default)
-  'show-vars:s' => \$G::show_vars,  # display the contents of these vars
+  'charset=s'   => \$charset,       # charset for $bh and $h variables
+  'show-vars=s' => \$G::show_vars,  # display the contents of these vars
+  'just-vars'   => \$G::just_vars,  # only display vars, no other info
   'show-rules'  => \$G::show_rules, # display compiled match rules
-  'show-tests'  => \$G::show_tests  # display tests as applied to each message
+  'show-tests'  => \$G::show_tests, # display tests as applied to each message
+  'version'     => sub {
+        print basename($0) . ": $0\n",
+            "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION\n",
+            "perl(runtime): $]\n";
+            exit 0;
+  },
 ) || exit(1);
 
-# if both freeze and thaw specified, only thaw as it is less desctructive
+# if both freeze and thaw specified, only thaw as it is less destructive
 $G::freeze = undef               if ($G::freeze && $G::thaw);
 freeze_start()                   if ($G::freeze);
 thaw_start()                     if ($G::thaw);
 
+# massage sort options (make '$var,Var:' be 'var','var')
+for (my $i = scalar(@G::sort)-1; $i >= 0; $i--) {
+  $G::sort[$i] = lc($G::sort[$i]);
+  $G::sort[$i] =~ s/[\$:\s]//g;
+  if ((my @vars = split(/,/, $G::sort[$i])) > 1) {
+    $G::sort[$i] = $vars[0]; shift(@vars); # replace current slot w/ first var
+    splice(@G::sort, $i+1, 0, @vars);      # add other vars after current pos
+  }
+}
+push(@G::sort, "message_exim_id") if (@G::sort);
+die "empty value provided to --sort not allowed, exiting\n"
+    if (grep /^\s*$/, @G::sort);
+
+# massage the qgrep options into standard criteria
 push(@ARGV, "\$sender_address     =~ /$G::qgrep_f/") if ($G::qgrep_f);
 push(@ARGV, "\$recipients         =~ /$G::qgrep_r/") if ($G::qgrep_r);
 push(@ARGV, "\$shown_message_size eq $G::qgrep_s")   if ($G::qgrep_s);
@@ -77,31 +120,38 @@ push(@ARGV, "\$message_age        <  $G::qgrep_y")   if ($G::qgrep_y);
 push(@ARGV, "\$message_age        >  $G::qgrep_o")   if ($G::qgrep_o);
 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         = {};                  # short circuit when crit is only MID
 $G::caseless        = $G::caseful ? 0 : 1; # nocase by default, case if both
 @G::recipients_crit = ();                  # holds per-recip criteria
-$spool              = $G::spool if ($G::spool);
+$spool              = defined $G::spool ? $G::spool
+                     : do { chomp($_ = `$exim @{[defined $G::config ? "-C $G::config" : '']} -n -bP spool_directory`)
+                             and $_ or $spool };
+my $input_dir       = (defined $G::queue ? "$G::queue/" : '')
+                    . (defined $G::input_dir || ($G::finput ? "Finput" : "input"));
 my $count_only      = 1 if ($G::mailq_bpc  || $G::qgrep_c);
 my $unsorted        = 1 if ($G::mailq_bpr  || $G::mailq_bpra ||
                             $G::mailq_bpru || $G::unsorted);
 my $msg             = $G::thaw ? thaw_message_list()
-                               : get_all_msgs($spool,$unsorted);
+                               : get_all_msgs($spool, $input_dir, $unsorted,
+                                              $G::reverse, $G::random);
 die "Problem accessing thaw file\n" if ($G::thaw && !$msg);
 my $crit            = process_criteria(\@ARGV);
 my $e               = Exim::SpoolFile->new();
 my $tcount          = 0 if ($count_only);  # holds count of all messages
 my $mcount          = 0 if ($count_only);  # holds count of matching messages
+my $total_size      = 0 if ($G::size_only);
 $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);
 $e->output_idonly()              if ($G::qgrep_i);
 $e->output_brief()               if ($G::qgrep_b);
 $e->output_flatq()               if ($G::flatq);
+$e->output_vars_only()           if ($G::just_vars && $G::show_vars);
 $e->set_show_vars($G::show_vars) if ($G::show_vars);
-$e->set_spool($spool);
-
+$e->set_spool($spool, $input_dir);
 
 MSG:
 foreach my $m (@$msg) {
@@ -153,10 +203,26 @@ foreach my $m (@$msg) {
   # 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) {
+  if ($count_only || $G::size_only) {
     $mcount++;
+    $total_size += $e->get_var('message_size');
   } else {
-    $e->print_message(\*STDOUT);
+    if (@G::sort) {
+      # if we are defining criteria to sort on, save the message here.  If
+      # we don't save here and do the sort later, we have a chicken/egg
+      # problem
+      push(@G::to_print, { vars => {}, output => "" });
+      foreach my $var (@G::sort) {
+        # save any values we want to sort on.  I don't like doing the internal
+        # struct access here, but calling get_var a bunch can be _slow_ =(
+        $G::sort_type{$var} ||= '<=>';
+        $G::to_print[-1]{vars}{$var} = $e->{_vars}{$var};
+        $G::sort_type{$var} = 'cmp' if ($G::to_print[-1]{vars}{$var} =~ /\D/);
+      }
+      $G::to_print[-1]{output} = $e->format_message();
+    } else {
+      print $e->format_message();
+    }
   }
 
   if ($G::freeze) {
@@ -165,10 +231,20 @@ foreach my $m (@$msg) {
   }
 }
 
-if ($G::mailq_bpc) {
-  print "$mcount\n";
-} elsif ($G::qgrep_c) {
-  print "$mcount matches out of $tcount messages\n";
+if (@G::to_print) {
+  msg_sort(\@G::to_print, \@G::sort, $G::reverse);
+  foreach my $msg (@G::to_print) {
+    print $msg->{output};
+  }
+}
+
+if ($G::qgrep_c) {
+  print "$mcount matches out of $tcount messages" .
+        ($G::size_only ? " ($total_size)" : "") . "\n";
+} elsif ($G::mailq_bpc) {
+  print "$mcount" .  ($G::size_only ? " ($total_size)" : "") . "\n";
+} elsif ($G::size_only) {
+  print "$total_size\n";
 }
 
 if ($G::freeze) {
@@ -180,6 +256,29 @@ if ($G::freeze) {
 
 exit;
 
+# sender_address_domain,shown_message_size
+sub msg_sort {
+  my $msgs    = shift;
+  my $vars    = shift;
+  my $reverse = shift;
+
+  my @pieces = ();
+  foreach my $v (@G::sort) {
+    push(@pieces, "\$a->{vars}{\"$v\"} $G::sort_type{$v} \$b->{vars}{\"$v\"}");
+  }
+  my $sort_str = join(" || ", @pieces);
+
+  @$msgs = sort { eval $sort_str } (@$msgs);
+  @$msgs = reverse(@$msgs) if ($reverse);
+}
+
+sub try_load {
+  my $mod = shift;
+
+  eval("use $mod");
+  return $@ ? 0 : 1;
+}
+
 # FREEZE FILE FORMAT:
 # message_data_bytes
 # message_data
@@ -248,24 +347,23 @@ sub process_criteria {
   my $e = 0;
 
   foreach (@$a) {
-    foreach my $t ('@') { s/$t/\\$t/g; } # '$'
+    foreach my $t ('@') { s/$t/\\$t/g; }
     if (/^(.*?)\s+(<=|>=|==|!=|<|>)\s+(.*)$/) {
       #print STDERR "found as integer\n";
       my $v = $1; my $o = $2; my $n = $3;
-      if    ($n =~ /^([\d\.]+)M$/)  { $n = $1 * 1024 * 1024; }
-      elsif ($n =~ /^([\d\.]+)K$/)  { $n = $1 * 1024; }
-      elsif ($n =~ /^([\d\.]+)B?$/) { $n = $1; }
-      elsif ($n =~ /^([\d\.]+)d$/)  { $n = $1 * 60 * 60 * 24; }
-      elsif ($n =~ /^([\d\.]+)h$/)  { $n = $1 * 60 * 60; }
-      elsif ($n =~ /^([\d\.]+)m$/)  { $n = $1 * 60; }
-      elsif ($n =~ /^([\d\.]+)s?$/) { $n = $1; }
+      if    ($n =~ /^(-?[\d\.]+)M$/)  { $n = $1 * 1024 * 1024; }
+      elsif ($n =~ /^(-?[\d\.]+)K$/)  { $n = $1 * 1024; }
+      elsif ($n =~ /^(-?[\d\.]+)B?$/) { $n = $1; }
+      elsif ($n =~ /^(-?[\d\.]+)d$/)  { $n = $1 * 60 * 60 * 24; }
+      elsif ($n =~ /^(-?[\d\.]+)h$/)  { $n = $1 * 60 * 60; }
+      elsif ($n =~ /^(-?[\d\.]+)m$/)  { $n = $1 * 60; }
+      elsif ($n =~ /^(-?[\d\.]+)s?$/) { $n = $1; }
       else {
         print STDERR "Expression $_ did not parse: numeric comparison with ",
                      "non-number\n";
         $e = 1;
         next;
       }
-      #push(@c, { var => lc($v), cmp => "(\$var $o $n) ? 1 : 0" });
       push(@c, { var => lc($v), cmp => "(\$var $o $n)" });
     } elsif (/^(.*?)\s+(=~|!~)\s+(.*)$/) {
       #print STDERR "found as string regexp\n";
@@ -274,6 +372,8 @@ sub process_criteria {
       #print STDERR "found as bare string regexp\n";
       my $case = $G::caseful ? '' : 'i';
       push(@c, { var => lc($1), cmp => "(\"\$var\" =~ /$2/$case)" });
+      # quote special characters in perl text string
+      #foreach my $t ('@') { $c[-1]{cmp} =~ s/$t/\\$t/g; }
     } elsif (/^(.*?)\s+(eq|ne)\s+(.*)$/) {
       #print STDERR "found as string cmp\n";
       my $var = lc($1); my $op = $2; my $val = $3;
@@ -283,20 +383,23 @@ sub process_criteria {
         #print STDERR "short circuit @c[-1]->{cmp} $val\n";
         $G::msg_ids->{$val} = 1;
       }
+      #foreach my $t ('@') { $c[-1]{cmp} =~ s/$t/\\$t/g; }
     } elsif (/^(\S+)$/) {
       #print STDERR "found as boolean\n";
       push(@c, { var => lc($1), cmp => "(\$var)" });
     } else {
       print STDERR "Expression $_ did not parse\n";
       $e = 1;
+      next;
     }
     # assign the results of the cmp test here (handle "!" negation)
+    # also handle global --not negation
     if ($c[-1]{var} =~ s|^!||) {
-      $c[-1]{cmp} .= " ? 0 : 1";
+      $c[-1]{cmp} .= $G::negate ? " ? 1 : 0" : " ? 0 : 1";
     } else {
-      $c[-1]{cmp} .= " ? 1 : 0";
+      $c[-1]{cmp} .= $G::negate ? " ? 0 : 1" : " ? 1 : 0";
     }
-    # support the each_* psuedo variables.  Steal the criteria off of the
+    # support the each_* pseudo variables.  Steal the criteria off of the
     # queue for special processing later
     if ($c[-1]{var} =~ /^each_(recipients(_(un)?del)?)$/) {
       my $var = $1;
@@ -313,10 +416,15 @@ sub process_criteria {
 }
 
 sub get_all_msgs {
-  my $d = shift() . '/input';
-  my $u = shift;
+  my $d = shift();
+  my $i = shift();
+  my $u = shift; # don't sort
+  my $r = shift; # right before returning, reverse order
+  my $o = shift; # if true, randomize list order before returning
   my @m = ();
 
+  if ($i =~ m|^/|) { $d = $i; } else { $d = $d . '/' . $i; }
+
   opendir(D, "$d") || die "Couldn't opendir $d: $!\n";
   foreach my $e (grep !/^\./, readdir(D)) {
     if ($e =~ /^[a-zA-Z0-9]$/) {
@@ -331,7 +439,19 @@ sub get_all_msgs {
   }
   closedir(D);
 
-  return($u ? \@m : [ sort { $a->{message} cmp $b->{message} } @m ]);
+  if ($o) {
+    my $c = scalar(@m);
+    # loop twice to pretend we're doing a good job of mixing things up
+    for (my $i = 0; $i < 2 * $c; $i++) {
+      my $rand = int(rand($c));
+      ($m[$i % $c],$m[$rand]) = ($m[$rand],$m[$i % $c]);
+    }
+  } elsif (!$u) {
+    @m = sort { $a->{message} cmp $b->{message} } @m;
+  }
+  @m = reverse(@m) if ($r);
+
+  return(\@m);
 }
 
 BEGIN {
@@ -349,12 +469,14 @@ sub new {
   bless($self, $class);
 
   $self->{_spool_dir}        = '';
+  $self->{_input_path}       = '';
   $self->{_undelivered_only} = 0;
   $self->{_show_generated}   = 0;
   $self->{_output_long}      = 1;
   $self->{_output_idonly}    = 0;
   $self->{_output_brief}     = 0;
   $self->{_output_flatq}     = 0;
+  $self->{_output_vars_only} = 0;
   $self->{_show_vars}        = [];
 
   $self->_reset();
@@ -368,6 +490,7 @@ sub output_long {
   $self->{_output_idonly}    = 0;
   $self->{_output_brief}     = 0;
   $self->{_output_flatq}     = 0;
+  $self->{_output_vars_only} = 0;
 }
 
 sub output_idonly {
@@ -377,6 +500,7 @@ sub output_idonly {
   $self->{_output_idonly}    = 1;
   $self->{_output_brief}     = 0;
   $self->{_output_flatq}     = 0;
+  $self->{_output_vars_only} = 0;
 }
 
 sub output_brief {
@@ -386,6 +510,7 @@ sub output_brief {
   $self->{_output_idonly}    = 0;
   $self->{_output_brief}     = 1;
   $self->{_output_flatq}     = 0;
+  $self->{_output_vars_only} = 0;
 }
 
 sub output_flatq {
@@ -395,6 +520,17 @@ sub output_flatq {
   $self->{_output_idonly}    = 0;
   $self->{_output_brief}     = 0;
   $self->{_output_flatq}     = 1;
+  $self->{_output_vars_only} = 0;
+}
+
+sub output_vars_only {
+  my $self = shift;
+
+  $self->{_output_long}      = 0;
+  $self->{_output_idonly}    = 0;
+  $self->{_output_brief}     = 0;
+  $self->{_output_flatq}     = 0;
+  $self->{_output_vars_only} = 1;
 }
 
 sub set_show_vars {
@@ -435,6 +571,7 @@ sub _reset {
   $self->{_message}     = '';
   $self->{_path}        = '';
   $self->{_vars}        = {};
+  $self->{_vars_raw}    = {};
 
   $self->{_numrecips}   = 0;
   $self->{_udel_tree}   = {};
@@ -450,7 +587,7 @@ sub parse_message {
   $self->_reset();
   $self->{_message} = shift || return(0);
   $self->{_path}    = shift; # optional path to message
-  return(0) if (!$self->{_spool_dir});
+  return(0) if (!$self->{_input_path});
   if (!$self->{_path} && !$self->_find_path()) {
     # assume the message was delivered from under us and ignore
     $self->{_delivered} = 1;
@@ -471,7 +608,7 @@ sub restore_state {
   return(1) if ($h->{_delivered});
   $self->_reset();
   $self->{_message} = $h->{_message} || return(0);
-  return(0) if (!$self->{_spool_dir});
+  return(0) if (!$self->{_input_path});
 
   $self->{_path}      = $h->{_path};
   $self->{_vars}      = $h->{_vars};
@@ -517,13 +654,13 @@ sub _find_path {
   my $self = shift;
 
   return(0) if (!$self->{_message});
-  return(0) if (!$self->{_spool_dir});
+  return(0) if (!$self->{_input_path});
 
   # test split spool first on the theory that people concerned about
   # performance will have split spool set =).
   foreach my $f (substr($self->{_message}, 5, 1).'/', '') {
-    if (-f "$self->{_spool_dir}/input/$f$self->{_message}-H") {
-      $self->{_path} = $self->{_spool_dir} . "/input/$f";
+    if (-f "$self->{_input_path}/$f$self->{_message}-H") {
+      $self->{_path} = "$self->{_input_path}}/$f";
       return(1);
     }
   }
@@ -533,26 +670,176 @@ sub _find_path {
 sub set_spool {
   my $self = shift;
   $self->{_spool_dir} = shift;
+  $self->{_input_path} = shift;
+  if ($self->{_input_path} !~ m|^/|) {
+    $self->{_input_path} = $self->{_spool_dir} . '/' . $self->{_input_path};
+  }
+}
+
+sub get_matching_vars {
+  my $self = shift;
+  my $e    = shift;
+
+  if ($e =~ /^\^/) {
+    my @r = ();
+    foreach my $v (keys %{$self->{_vars}}) { push(@r, $v) if ($v =~ /$e/); }
+    return(@r);
+  } else {
+    return($e);
+  }
 }
 
 # accepts a variable with or without leading '$' or trailing ':'
 sub get_var {
   my $self = shift;
-  my $var  = lc(shift);
+  my $var  = lc(shift); $var =~ s/^\$//; $var =~ s/:$//;
+
+  if ($var eq 'message_body' && !defined($self->{_vars}{message_body})) {
+    $self->_parse_body()
+  } elsif ($var =~ s|^([rb]?h)(eader)?_|${1}eader_| &&
+           exists($self->{_vars}{$var}) && !defined($self->{_vars}{$var}))
+  {
+    if ((my $type = $1) eq 'rh') {
+      $self->{_vars}{$var} = join('', @{$self->{_vars_raw}{$var}{vals}});
+    } else {
+      # both bh_ and h_ build their strings from rh_.  Do common work here
+      my $rh = $var; $rh =~ s|^b?|r|;
+      my $comma = 1 if ($self->{_vars_raw}{$rh}{type} =~ /^[BCFRST]$/);
+      foreach (@{$self->{_vars_raw}{$rh}{vals}}) {
+        my $x = $_; # editing $_ here would change the original, which is bad
+        $x =~ s|^\s+||;
+        $x =~ s|\s+$||;
+        if ($comma) { chomp($x); $self->{_vars}{$var} .= "$x,\n"; }
+        else        { $self->{_vars}{$var} .= $x; }
+      }
+      $self->{_vars}{$var} =~ s|[\s\n]*$||;
+      $self->{_vars}{$var} =~ s|,$|| if ($comma);
+      # ok, that's the preprocessing, not do specific processing for h type
+      if ($type eq 'bh') {
+        $self->{_vars}{$var} = $self->_decode_2047($self->{_vars}{$var});
+      } else {
+        $self->{_vars}{$var} =
+            $self->_decode_2047($self->{_vars}{$var}, $charset);
+      }
+    }
+  }
+  elsif ($var eq 'received_count' && !defined($self->{_vars}{received_count}))
+  {
+    $self->{_vars}{received_count} =
+        scalar(@{$self->{_vars_raw}{rheader_received}{vals}});
+  }
+  elsif ($var eq 'message_headers' && !defined($self->{_vars}{message_headers}))
+  {
+    $self->{_vars}{$var} =
+        $self->_decode_2047($self->{_vars}{message_headers_raw}, $charset);
+    chomp($self->{_vars}{$var});
+  }
+  elsif ($var eq 'reply_address' && !defined($self->{_vars}{reply_address}))
+  {
+    $self->{_vars}{reply_address} = exists($self->{_vars}{"header_reply-to"})
+        ? $self->get_var("header_reply-to") : $self->get_var("header_from");
+  }
 
-  $var =~ s/^\$//;
-  $var =~ s/:$//;
+  #chomp($self->{_vars}{$var}); # I think this was only for headers, obsolete
+  return $self->{_vars}{$var};
+}
 
-  $self->_parse_body()
-      if ($var eq 'message_body' && !$self->{_vars}{message_body});
+sub _decode_2047 {
+  my $self = shift;
+  my $s    = shift; # string to decode
+  my $c    = shift; # target charset.  If empty, just decode, don't convert
+  my $t    = '';    # the translated string
+  my $e    = 0;     # set to true if we get an error in here anywhere
+
+  return($s) if ($s !~ /=\?/); # don't even bother to look if there's no sign
+
+  my @p = ();
+  foreach my $mw (split(/(=\?[^\?]{3,}\?[BQ]\?[^\?]{1,74}\?=)/i, $s)) {
+    next if ($mw eq '');
+    if ($mw =~ /=\?([^\?]{3,})\?([BQ])\?([^\?]{1,74})\?=/i) {
+      push(@p, { data => $3, encoding => uc($2), charset => uc($1),
+                 is_mime => 1 });
+      if ($p[-1]{encoding} eq 'Q') {
+        my @ow = split('', $p[-1]{data});
+        my @nw = ();
+        for (my $i = 0; $i < @ow; $i++) {
+          if ($ow[$i] eq '_') { push(@nw, ' '); }
+          elsif ($ow[$i] eq '=') {
+            if (scalar(@ow) - ($i+1) < 2) {  # ran out of characters
+              $e = 1; last;
+            } elsif ($ow[$i+1] !~ /[\dA-F]/i || $ow[$i+2] !~ /[\dA-F]/i) {
+              $e = 1; last;
+            } else {
+              #push(@nw, chr('0x'.$ow[$i+1].$ow[$i+2]));
+              push(@nw, pack("C", hex($ow[$i+1].$ow[$i+2])));
+              $i += 2;
+            }
+          }
+          elsif ($ow[$i] =~ /\s/) { # whitespace is illegal
+            $e = 1;
+            last;
+          }
+          else { push(@nw, $ow[$i]); }
+        }
+        $p[-1]{data} = join('', @nw);
+      } elsif ($p[-1]{encoding} eq 'B') {
+        my $x = $p[-1]{data};
+        $x    =~ tr#A-Za-z0-9+/##cd;
+        $x    =~ s|=+$||;
+        $x    =~ tr#A-Za-z0-9+/# -_#;
+        my $r = '';
+        while ($x =~ s/(.{1,60})//s) {
+          $r .= unpack("u", chr(32 + int(length($1)*3/4)) . $1);
+        }
+        $p[-1]{data} = $r;
+      }
+    } else {
+      push(@p, { data => $mw, is_mime => 0,
+                 is_ws => ($mw =~ m|^[\s\n]+|sm) ? 1 : 0 });
+    }
+  }
 
-  chomp($self->{_vars}{$var});
-  return $self->{_vars}{$var};
+  for (my $i = 0; $i < @p; $i++) {
+    # mark entities we want to skip (whitespace between consecutive mimewords)
+    if ($p[$i]{is_mime} && $p[$i+1]{is_ws} && $p[$i+2]{is_mime}) {
+      $p[$i+1]{skip} = 1;
+    }
+
+    # if word is a mimeword and we have access to Encode and charset was
+    # specified, try to convert text
+    # XXX _cannot_ get consistent conversion results in perl, can't get them
+    # to return same conversions that exim performs.  Until I can figure this
+    # out, don't attempt any conversions (header_ will return same value as
+    # bheader_).
+    #if ($c && $p[$i]{is_mime} && $self->_try_load('Encode')) {
+    #  # XXX not sure how to catch errors here
+    #  Encode::from_to($p[$i]{data}, $p[$i]{charset}, $c);
+    #}
+
+    # replace binary zeros w/ '?' in decoded text
+    if ($p[$i]{is_mime}) { $p[$i]{data} =~ s|\x00|?|g; }
+  }
+
+  if ($e) {
+    return($s);
+  } else {
+    return(join('', map { $_->{data} } grep { !$_->{skip} } @p));
+  }
+}
+
+# This isn't a class func but I'm tired
+sub _try_load {
+  my $self = shift;
+  my $mod  = shift;
+
+  eval("use $mod");
+  return $@ ? 0 : 1;
 }
 
 sub _parse_body {
   my $self = shift;
   my $f    = $self->{_path} . '/' . $self->{_message} . '-D';
+  $self->{_vars}{message_body} = ""; # define var so we only come here once
 
   open(I, "<$f") || return($self->_error("Couldn't open $f: $!"));
   chomp($_ = <I>);
@@ -562,13 +849,14 @@ sub _parse_body {
   close(I);
   $self->{_vars}{message_body} =~ s/\n/ /g;
   $self->{_vars}{message_body} =~ s/\000/ /g;
-print "returning (1)\n";
   return(1);
 }
 
 sub _parse_header {
   my $self = shift;
   my $f    = $self->{_path} . '/' . $self->{_message} . '-H';
+  $self->{_vars}{header_path} = $f;
+  $self->{_vars}{data_path}   = $self->{_path} . '/' . $self->{_message} . '-D';
 
   if (!open(I, "<$f")) {
     # assume message went away and silently ignore
@@ -576,6 +864,14 @@ sub _parse_header {
     return(1);
   }
 
+  # There are a few numeric variables that should explicitly be set to
+  # zero if they aren't found in the header.  Technically an empty value
+  # works just as well, but might as well be pedantic
+  $self->{_vars}{body_zerocount}           = 0;
+  $self->{_vars}{host_lookup_deferred}     = 0;
+  $self->{_vars}{host_lookup_failed}       = 0;
+  $self->{_vars}{tls_certificate_verified} = 0;
+
   chomp($_ = <I>);
   return(0) if ($self->{_message}.'-H' ne $_);
   $self->{_vars}{message_id}       = $self->{_message};
@@ -620,12 +916,14 @@ sub _parse_header {
         read(I, $self->{_vars}{$t}, $2+1) || return(0);
         chomp($self->{_vars}{$t});
       } elsif ($tag eq '-aclc') {
-        return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
+        #return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
+        return(0) if ($arg !~ /^(\S+)\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+)$/);
+        #return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
+        return(0) if ($arg !~ /^(\S+)\s(\d+)$/);
         my $t = "acl_m$1";
         read(I, $self->{_vars}{$t}, $2+1) || return(0);
         chomp($self->{_vars}{$t});
@@ -646,6 +944,8 @@ sub _parse_header {
         $self->{_vars}{host_lookup_failed} = 1;
       } elsif ($tag eq '-body_linecount') {
         $self->{_vars}{body_linecount} = $arg;
+      } elsif ($tag eq '-max_received_linelength') {
+        $self->{_vars}{max_received_linelength} = $arg;
       } elsif ($tag eq '-body_zerocount') {
         $self->{_vars}{body_zerocount} = $arg;
       } elsif ($tag eq '-frozen') {
@@ -673,12 +973,16 @@ sub _parse_header {
         $self->{_vars}{tls_cipher} = $arg;
       } elsif ($tag eq '-tls_peerdn') {
         $self->{_vars}{tls_peerdn} = $arg;
+      } elsif ($tag eq '-tls_sni') {
+        $self->{_vars}{tls_sni} = $arg;
       } elsif ($tag eq '-host_address') {
         $self->{_vars}{sender_host_port} = $self->_get_host_and_port(\$arg);
         $self->{_vars}{sender_host_address} = $arg;
       } elsif ($tag eq '-interface_address') {
-        $self->{_vars}{interface_port} = $self->_get_host_and_port(\$arg);
-        $self->{_vars}{interface_address} = $arg;
+        $self->{_vars}{received_port} =
+            $self->{_vars}{interface_port} = $self->_get_host_and_port(\$arg);
+        $self->{_vars}{received_ip_address} =
+            $self->{_vars}{interface_address} = $arg;
       } elsif ($tag eq '-active_hostname') {
         $self->{_vars}{smtp_active_hostname} = $arg;
       } elsif ($tag eq '-host_auth') {
@@ -734,6 +1038,12 @@ sub _parse_header {
       return($self->_error("incorrect format: $_")) if (length($2) != $3);
       $self->{_recips}{$1} = { pno => $4, errors_to => $2 };
       $addr = $1;
+    } elsif (/^(\S*)\s(\S*)\s(\d+),(\d+)\s(\S*)\s(\d+),(-?\d+)#3$/) {
+      #print STDERR "exim4 new type #3 DSN (untested): $_\n";
+      return($self->_error("incorrect format: $_"))
+        if ((length($2) != $3) || (length($5) != $6));
+      $self->{_recips}{$1} = { pno => $7, errors_to => $5 };
+      $addr = $1;
     } elsif (/^.*#(\d+)$/) {
       #print STDERR "exim4 #$1 style (unimplemented): $_\n";
       $self->_error("exim4 #$1 style (unimplemented): $_");
@@ -766,38 +1076,31 @@ sub _parse_header {
       $_ .= $t;
       $t  = getc(I);
     }
-    # ok, right here $t contains the header flag and $_ contains the number of
-    # bytes to read.  If we ever use the header flag, grab it here.
-    $self->{_vars}{message_size} += $_ if ($t ne '*');
-    $t = getc(I); # strip the space out of the file
-    my $bytes = $_;
-    return(0) if (read(I, $_, $bytes) != $bytes);
-    $self->{_vars}{message_linecount} += (tr/\n//) if ($t ne '*');
-
-    # build the $header_ variable, following exim's rules (sort of)
+    my $hdr_flag  = $t;
+    my $hdr_bytes = $_;
+    $t            = getc(I);              # strip the space out of the file
+    return(0) if (read(I, $_, $hdr_bytes) != $hdr_bytes);
+    if ($hdr_flag ne '*') {
+      $self->{_vars}{message_linecount} += (tr/\n//);
+      $self->{_vars}{message_size}      += $hdr_bytes;
+    }
+
+    # mark (rb)?header_ vars as existing and store raw value.  They'll be
+    # processed further in get_var() if needed
     my($v,$d) = split(/:/, $_, 2);
     $v = "header_" . lc($v);
-    $d =~ s/^\s+//;
-    $d =~ s/\s+$//;
-    $self->{_vars}{$v} .= "$d\n";
-    $self->{_vars}{received_count}++ if ($v eq 'header_received');
-    # push header onto $message_headers var, following exim's rules
-    $self->{_vars}{message_headers} .= $_;
+    $self->{_vars}{$v} = $self->{_vars}{"b$v"} = $self->{_vars}{"r$v"} = undef;
+    push(@{$self->{_vars_raw}{"r$v"}{vals}}, $d);
+    $self->{_vars_raw}{"r$v"}{type} = $hdr_flag;
+    $self->{_vars}{message_headers_raw} .= $_;
   }
   close(I);
-  # remove trailing newline from $message_headers
-  chomp($self->{_vars}{message_headers});
-
-  if (length($self->{_vars}{"header_reply-to"}) > 0) {
-    $self->{_vars}{reply_address} = $self->{_vars}{"header_reply-to"};
-  } else {
-    $self->{_vars}{reply_address} = $self->{_vars}{header_from};
-  }
 
   $self->{_vars}{message_body_size} =
       (stat($self->{_path}.'/'.$self->{_message}.'-D'))[7] - 19;
   if ($self->{_vars}{message_body_size} < 0) {
     $self->{_vars}{message_size} = 0;
+    $self->{_vars}{message_body_missing} = 1;
   } else {
     $self->{_vars}{message_size} += $self->{_vars}{message_body_size} + 1;
   }
@@ -836,62 +1139,77 @@ sub _get_host_and_port {
   return(0);
 }
 
-sub print_message {
+# honoring all formatting preferences, return a scalar variable of the
+# information for the single message matching what exim -bp would show.
+# We can print later if we want.
+sub format_message {
   my $self = shift;
-  my $fh   = shift || \*STDOUT;
+  my $o    = '';
   return if ($self->{_delivered});
 
-  if ($self->{_output_idonly}) {
-    print $fh $self->{_message};
-    foreach my $v (@{$self->{_show_vars}}) {
-      print $fh " $v='", $self->get_var($v), "'";
+  # define any vars we want to print out for this message.  The requests
+  # can be regexps, and the defined vars can change for each message, so we
+  # have to build this list for each message
+  my @vars = ();
+  if (@{$self->{_show_vars}}) {
+    my %t = ();
+    foreach my $e (@{$self->{_show_vars}}) {
+      foreach my $v ($self->get_matching_vars($e)) {
+        next if ($t{$v}); $t{$v}++; push(@vars, $v);
+      }
     }
-    print $fh "\n";
-    return;
+  }
+
+  if ($self->{_output_idonly}) {
+    $o .= $self->{_message};
+    foreach my $v (@vars) { $o .= " $v='" . $self->get_var($v) . "'"; }
+    $o .= "\n";
+    return $o;
+  } elsif ($self->{_output_vars_only}) {
+    foreach my $v (@vars) { $o .= $self->get_var($v) . "\n"; }
+    return $o;
   }
 
   if ($self->{_output_long} || $self->{_output_flatq}) {
     my $i = int($self->{_vars}{message_age} / 60);
     if ($i > 90) {
       $i = int(($i+30)/60);
-      if ($i > 72) { printf $fh "%2dd ", int(($i+12)/24); }
-      else { printf $fh "%2dh ", $i; }
-    } else { printf $fh "%2dm ", $i; }
-
-    if ($self->{_output_flatq} && $self->{_show_vars}) {
-        print $fh join(';',
-                       map { "$_='".$self->get_var($_)."'" }
-                           (@{$self->{_show_vars}})
-                      );
+      if ($i > 72) { $o .= sprintf "%2dd ", int(($i+12)/24); }
+      else { $o .= sprintf "%2dh ", $i; }
+    } else { $o .= sprintf "%2dm ", $i; }
+
+    if ($self->{_output_flatq} && @vars) {
+        $o .= join(';', map { "$_='".$self->get_var($_)."'" } (@vars)
+                  );
     } else {
-      printf $fh "%5s", $self->{_vars}{shown_message_size};
+      $o .= sprintf "%5s", $self->{_vars}{shown_message_size};
     }
-    print $fh " ";
+    $o .= " ";
   }
-  print $fh "$self->{_message} ";
-  print $fh "From: " if ($self->{_output_brief});
-  print $fh "<$self->{_vars}{sender_address}>";
+  $o .= "$self->{_message} ";
+  $o .= "From: " if ($self->{_output_brief});
+  $o .= "<$self->{_vars}{sender_address}>";
 
   if ($self->{_output_long}) {
-    print $fh " ($self->{_vars}{originator_login})"
+    $o .= " ($self->{_vars}{originator_login})"
         if ($self->{_vars}{sender_set_untrusted});
 
     # XXX exim contains code here to print spool format errors
-    print $fh " *** frozen ***" if ($self->{_vars}{deliver_freeze});
-    print $fh "\n";
+    $o .= " *** frozen ***" if ($self->{_vars}{deliver_freeze});
+    $o .= "\n";
 
-    foreach my $v (@{$self->{_show_vars}}) {
-      printf $fh "  %25s = '%s'\n", $v, $self->get_var($v);
+    foreach my $v (@vars) {
+      $o .= sprintf "  %25s = '%s'\n", $v, $self->get_var($v);
     }
 
     foreach my $r (keys %{$self->{_recips}}) {
       next if ($self->{_del_tree}{$r} && $self->{_undelivered_only});
-      printf $fh "        %s %s\n", $self->{_del_tree}{$r} ? "D" : " ", $r;
+      $o .= sprintf "        %s %s\n", $self->{_del_tree}{$r} ? "D" : " ", $r;
     }
     if ($self->{_show_generated}) {
       foreach my $r (keys %{$self->{_del_tree}}) {
         next if ($self->{_recips}{$r});
-        printf $fh "       +D %s\n", $r;
+        $o .= sprintf "       +D %s\n", $r;
       }
     }
   } elsif ($self->{_output_brief}) {
@@ -900,24 +1218,30 @@ sub print_message {
       next if ($self->{_del_tree}{$r});
       push(@r, $r);
     }
-    print $fh " To: ", join(';', @r);
-    if ($self->{_show_vars} && scalar(@{$self->{_show_vars}})) {
-      print $fh " Vars: ", join(';',
-                                map { "$_='".$self->get_var($_)."'" }
-                                    (@{$self->{_show_vars}})
-                               );
+    $o .= " To: " . join(';', @r);
+    if (scalar(@vars)) {
+      $o .= " Vars: ".join(';',map { "$_='".$self->get_var($_)."'" } (@vars));
     }
   } elsif ($self->{_output_flatq}) {
-    print $fh " *** frozen ***" if ($self->{_vars}{deliver_freeze});
+    $o .= " *** frozen ***" if ($self->{_vars}{deliver_freeze});
     my @r = ();
     foreach my $r (keys %{$self->{_recips}}) {
       next if ($self->{_del_tree}{$r});
       push(@r, $r);
     }
-    print $fh " ", join(' ', @r);
+    $o .= " " . join(' ', @r);
   }
 
-  print $fh "\n";
+  $o .= "\n";
+  return($o);
+}
+
+sub print_message {
+  my $self = shift;
+  my $fh   = shift || \*STDOUT;
+  return if ($self->{_delivered});
+
+  print $fh $self->format_message();
 }
 
 sub dump {
@@ -965,159 +1289,254 @@ __END__
 
 =head1 NAME
 
-exipick - display messages from Exim queue based on a variety of criteria
+exipick - selectively display messages from an Exim queue
 
-=head1 USAGE
+=head1 SYNOPSIS
 
-exipick [--help|--version] | [-spool <spool>] [-and|-or] [-bp|-bpa|-bpc|-bpr|-bpra|-bpru|-bpu] [<criterion> [<criterion> ...]]
+exipick [<options>] [<criterion> [<criterion> ...]]
 
 =head1 DESCRIPTION
 
-exipick is designed to display the contents of a Exim mail spool based on user-specified criteria.  It is designed to mimic the output of 'exim -bp' (or any of the other -bp* options) and Exim's spec.txt should be used to learn more about the exact format of the output.  The criteria are formed by creating comparisons against characteristics of the messages, for instance $message_size, $sender_helo_name, or $message_headers.
+exipick is a tool to display messages in an Exim queue.  It is very similar to exiqgrep and is, in fact, a drop in replacement for exiqgrep.  exipick allows you to select messages to be displayed using any piece of data stored in an Exim spool file.  Matching messages can be displayed in a variety of formats.
+
+=head1 QUICK START
+
+Delete every frozen message from queue:
+    exipick -zi | xargs exim -Mrm
+
+Show only messages which have not yet been virus scanned:
+    exipick '$received_protocol ne virus-scanned'
+
+Run the queue in a semi-random order:
+    exipick -i --random | xargs exim -M
+
+Show the count and total size of all messages which either originated from localhost or have a received protocol of 'local':
+    exipick --or --size --bpc \
+            '$sender_host_address eq 127.0.0.1' \
+            '$received_protocol eq local'
+
+Display all messages received on the MSA port, ordered first by the sender's email domain and then by the size of the emails:
+    exipick --sort sender_address_domain,message_size \
+            '$received_port == 587'
+
+Display only messages whose every recipient is in the example.com domain, also listing the IP address of the sending host:
+    exipick --show-vars sender_host_address \
+            '$each_recipients = example.com'
+
+Same as above, but show values for all defined variables starting with sender_ and the number of recipients:
+    exipick --show-vars ^sender_,recipients_count \
+            '$each_recipients = example.com'
 
 =head1 OPTIONS
 
 =over 4
 
-=item --spool
+=item --and
 
-The path to Exim's spool directory.  In general usage you should set the $spool variable in the script to your site's main spool directory (and if exipick was installed from the Exim distribution, this is done by default), but this option is useful for alternate installs, or installs on NFS servers, etc.
+Display messages matching all criteria (default)
 
-=item --and
+=item -b
 
-A message will be displayed only if it matches all of the specified criteria.  This is the default.
+Display messages in brief format (exiqgrep)
 
-=item --or
+=item -bp
+
+Display messages in standard mailq format (default)
+
+=item -bpa
+
+Same as -bp, show generated addresses also (exim)
 
-A message will be displayed if it matches any of the specified criteria.
+=item -bpc
+
+Show a count of matching messages (exim)
+
+=item -bpr
+
+Same as '-bp --unsorted' (exim)
+
+=item -bpra
+
+Same as '-bpa --unsorted' (exim)
+
+=item -bpru
+
+Same as '-bpu --unsorted' (exim)
+
+=item -bpu
+
+Same as -bp, but only show undelivered messages (exim)
+
+=item -C | --config <config>
+
+Use <config> to determine the proper spool directory. (See C<--spool>
+or C<--input> for alternative ways to specify the directories to operate on.)
+
+=item -c
+
+Show a count of matching messages (exiqgrep)
 
 =item --caseful
 
-By default criteria using the '=' operator are caseless.  Specifying this option make them respect case.
+Make operators involving '=' honor case
 
-=item --show-vars <variable>[,<variable>...]
+=item --charset
 
-Cause the value of each specified variable to be displayed for every message dispayed.  For instance, the command "exipick --show-vars '$sender_ident' 'sender_host_address eq 127.0.01'" will show the ident string for every message submitted via localhost.  How exactly the variable value is diplayed changes according to what output format you specify.
+Override the default local character set for $header_ decoding
 
-=item --show-rules
+=item -f <regexp>
 
-If specified the internal representation of each message criteria is shown.  This is primarily used for debugging purposes.
+Same as '$sender_address =~ /<regexp>/' (exiqgrep).  Note that this preserves the default case sensitivity of exiqgrep's interface.
 
-==item --show-tests
+=item --finput
 
-If specified, for every message (regardless of matching criteria) the criteria's actual value is shown and the compiled internal eval is shown.  This is used primarily for debugging purposes.
+Same as '--input-dir Finput'.  'Finput' is where exim copies frozen messages when compiled with SUPPORT_MOVE_FROZEN_MESSAGES.
 
 =item --flatq
 
-Change format of output so that every message is on a single line.  Useful for parsing with tools such as sed, awk, cut, etc.
+Use a single-line output format
 
-=item --unsorted
+=item --freeze <cache file>
+
+Save queue information in an quickly retrievable format
+
+=item --help
 
-This prevents sorting the messages according to their age when they are displayed.  While there were exim-clone options that enabled this functionality (-bpr, -bpra, etc) they only worked in the standard output format.  --unsorted works in all output formats, including the exiqgrep clone output and --flatq.
+Display this output
 
-=item The -bp* options all control how much information is displayed and in what manner.  They all match the functionality of the options of the same name in Exim.  Briefly:
+=item -i
 
-=item -bp   display the matching messages in 'mailq' format.
+Display only the message IDs (exiqgrep)
 
-=item -bpa    ... with generated addresses as well.
+=item --input-dir <inputname>
 
-=item -bpc    ... just show a count of messages.
+Set the name of the directory under the spool directory.  By default this is "input".  If this starts with '/', the value of --spool is ignored.  See also --finput.
 
-=item -bpr    ... do not sort.
+=item -l
 
-=item -bpra   ... with generated addresses, unsorted.
+Same as -bp (exiqgrep)
 
-=item -bpru   ... only undelivered addresses, unsorted.
+=item --not
 
-=item -bpu    ... only undelivered addresses.
+Negate all tests.
 
-Please see Exim's spec.txt for details on the format and information displayed with each option.
+=item -o <seconds>
 
-=item The following options are included for compatibility with the 'exiqgrep' utility:
+Same as '$message_age > <seconds>' (exiqgrep)
 
-=item -f <regexp>  Same as '$sender_address = <regexp>'
+=item --or
 
-=item -r <regexp>  Same as '$recipients = <regexp>'
+Display messages matching any criteria
 
-=item -s <string>  Same as '$shown_message_size eq <string>'
+=item --queue <name>
 
-=item -y <seconds> Same as '$message_age < <seconds>'
+Name of the queue (default: ''). See "named queues" in the spec.
 
-=item -o <seconds> Same as '$message_age > <seconds>'
+=item -R
 
-=item -z           Same as '$deliver_freeze'
+Same as --reverse (exiqgrep)
 
-=item -x           Same as '!$deliver_freeze'
+=item -r <regexp>
 
-=item -c           Display count of matches only
+Same as '$recipients =~ /<regexp>/' (exiqgrep).  Note that this preserves the default case sensitivity of exiqgrep's interface.
 
-=item -l           Display in long format (default)
+=item --random
 
-=item -i           Display message IDs only
+Display messages in random order
 
-=item -b           Display brief format only
+=item --reverse
 
-Please see the 'exiqgrep' documentation for more details on the behaviour and output format produced by these options
+Display messages in reverse order
 
-=item <criterion>
+=item -s <string>
 
-The criteria are used to determine whether or not a given message should be displayed.  The criteria are built using variables containing information about the individual messages (see VARIABLES section for list and descriptions of available variables).  Each criterion is evaluated for each message in the spool and if all (by default) criteria match or (if --or option is specified) any criterion matches, the message is displayed.  See VARIABLE TYPES for explanation of types of variables and the evaluations that can be performed on them and EXAMPLES section for complete examples.
+Same as '$shown_message_size eq <string>' (exiqgrep)
 
-The format of a criterion is explained in detail below, but a key point to make is that the variable being compared must always be on the left side of the comparison.
+=item --spool <path>
 
-If no criteria are provided all messages in the queue are displayed (in this case the output of exipick should be identical to the output of 'exim -bp')
+Set the path to the exim spool to use.  This value will have the argument to --input or 'input' appended, or be ignored if --input is a full path. If not specified, exipick uses the value from C<exim [-C config] -n -bP spool_directory>, and if this call fails, the  F</opt/exim/spool> from build time (F<Local/Makefile>) is used. See also --config.
 
-=item --freeze <cache file>, --thaw <cache file>
+=item --show-rules
 
-Every time exipick runs, it has to rescan the input directory, open every file, and correctly parse the contents of every file.  While this isn't very time consuming on with a small queue or a lightly loaded server, it can take a great deal of time on heavily loaded machines or large queues.  Unfortunately, one of the best times to use exipick is diagnosing large mail queues.
+Show the internal representation of each criterion specified
 
-To speed run times in these situations, you can use --freeze to save a cache of the message information.  --thaw can then be used to read from the cache rather than directly from the spool.  Over time, of course, the information in the cache will drift further and further out of date, but this is not a significant problem over short runs, but do keep in mind that any deliveries made or messages removed from the queue after the cache file is made will not be reflected in the output when using --thaw.
+=item --show-tests
 
-All message variables are saved to the cache except $message_body and $message_age.  $message_age is skipped because it is recalculated dynamically at every running of exipick.  $message_body is skipped because of the potentially large storage requirements.  If $message_body is referenced in any criteria when using --thaw, the data will be looked up from the spool file if the message is still in the spool.
+Show the result of each criterion on each message
 
-If criteria are specified when using --freeze, only matching messages will be written to the cache file.  Subsequent runs of exipick --thaw using that cache file will not need the original criteria specified.
+=item --show-vars <variable>[,<variable>...]
 
-There are tradeoffs when using this system, time and space.  The cache file will take disk space to write.  The size of the file depends on the type of mail the server handles, but it ranges between 2KB and 5KB per message.  The run of exipick which creates the cache file will take longer to run than a standard run, perhaps as much as 50% longer, but the subsequent runs readng from the cache file will take as little as 10-20% of the time it would take for a run of exipick without --freeze/--thaw.  In other words, if a system is in a state where it takes 30 seconds to run exipick, making a cache file will take around 45 second, but subsequent reads of the cache will take around 5 seconds.  The size needed for the cache file decrease and the performance gains on the --thaw runs increase if criteria which limits the number of messages written to the cache file are used on the --freeze run.
+Show the value for <variable> for each displayed message.  <variable> will be a regular expression if it begins with a circumflex.
 
-=item --help
+=item --size
 
-This screen.
+Show the total bytes used by each displayed message
+
+=item --thaw <cache file>
+
+Read queue information cached from a previous --freeze run
+
+=item --sort <variable>[,<variable>...]
+
+Display matching messages sorted according to <variable>
+
+=item --unsorted
+
+Do not apply any sorting to output
 
 =item --version
 
-Version info.
+Display the version of this command
+
+=item -x
+
+Same as '!$deliver_freeze' (exiqgrep)
+
+=item -y
+
+Same as '$message_age < <seconds>' (exiqgrep)
+
+=item -z
+
+Same as '$deliver_freeze' (exiqgrep)
 
 =back
 
-=head1 VARIABLE TYPES
+=head1 CRITERIA
 
-Although there are variable types defined, they are defined only by the type of data that gets put into them.  They are internally typeless.  Because of this it is perfectly legal to perform a numeric comparison against a string variable, although the results will probably be meaningless.
+Exipick decides which messages to display by applying a test against each message.  The rules take the general form of 'VARIABLE OPERATOR VALUE'.  For example, '$message_age > 60'.  When exipick is deciding which messages to display, it checks the $message_age variable for each message.  If a message's age is greater than 60, the message will be displayed.  If the message's age is 60 or less seconds, it will not be displayed.
 
-=over 4
+Multiple criteria can be used.  The order they are specified does not matter.  By default all criteria must evaluate to true for a message to be displayed.  If the --or option is used, a message is displayed as long as any of the criteria evaluate to true.
 
-=item NUMERIC
+See the VARIABLES and OPERATORS sections below for more details
 
-Variable of the numeric type can be of integer or float.  Valid comparisons are <, <=, >, >=, ==, and !=.
+=head1 OPERATORS
 
-The numbers specified in the criteria can have a suffix of d, h, m, s, M, K, or B, in which case the number will be mulitplied by 86400, 3600, 60, 1, 1048576, 1024, or 1 respectively.  These suffixes are case sensitive.  While these are obviously designed to aid in date and size calculations, they are not restricted to variables of their respective types.  That is, though it's odd it's legal to create a criterion of a message being around for 3 kiloseconds: '$message_age >= 3K'.
+=over 4
 
 =item BOOLEAN
 
-Variables of the boolean type are very easy to use in criteria.  The format is either the variable by itself or the variable negated with a ! sign.  For instance, '$deliver_freeze' matches if the message in question is frozen, '!$deliver_freeze' matches if message is not frozen.
+Boolean variables are checked simply by being true or false.  There is no real operator except negation.  Examples of valid boolean tests:
+  '$deliver_freeze'
+  '!$deliver_freeze'
 
-=item STRING
-
-String variables are basically defined as those that are neither numeric nor boolean and can contain any data.  The string operators are =, eq, ne, =~, and !~.  With the exception of '=', the operators all match the functionality of the like-named perl operators.
+=item NUMERIC
 
-The simplest form is a bare string regular expression, represented by the operator '='.  The value used for the comparison will be evaluated as a regular expression and can be as simple or as complex as desired.  For instance '$sender_helo_name = example' on the simple end or '$sender_helo_name = ^aol\.com$' on the more complex end.  This comparison is caseless by default, but see the --caseful option to change this.
+Valid comparisons are <, <=, >, >=, ==, and !=.  Numbers can be integers or floats.  Any number in a test suffixed with d, h, m, s, M, K, or B will be multiplied by 86400, 3600, 60, 1, 1048576, 1024, or 1 respectively.  Examples of valid numeric tests:
+  '$message_age >= 3d'
+  '$local_interface == 587'
+  '$message_size < 30K'
 
-Slightly more complex is the string comparison with the operators 'eq' and 'ne' for equal and not equal, respectively.  '$sender_helo_name eq hotmail.com' is true for messages with the exact helo string "hotmail.com", while '$sender_helo_name ne hotmail.com' is true for any message with a helo string other than "hotmail.com".
+=item STRING
 
-The most complex and the most flexible format are straight regular expressions with the operators '=~' and '!~'.  The value in the criteria is expected to be a correctly formatted perl regular expression B<including the regexp delimiters (usually //)>.  The criterion '$sender_helo_name !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/' matches for any message which does not have an IP address for its helo string.
+The string operators are =, eq, ne, =~, and !~.  With the exception of '=', the operators all match the functionality of the like-named perl operators.  eq and ne match a string exactly.  !~, =~, and = apply a perl regular expression to a string.  The '=' operator behaves just like =~ but you are not required to place // around the regular expression.  Examples of valid string tests:
+  '$received_protocol eq esmtp'
+  '$sender_address = example.com'
+  '$each_recipients =~ /^a[a-z]{2,3}@example.com$/'
 
 =item NEGATION
 
-In addition to standard logical negation available with the operators above (== vs !=, < vs >=, etc) any criteria can be whole negated by prepending an exclamation mark ("!") to the variable name.  This is required for negating boolean variables, and very convenient for negating the simple '=' operator (previously, the opposite of '$var = foo' was '$var !~ /foo/'.  This can now be written '!$var = foo').
+There are many ways to negate tests, each having a reason for existing.  Many tests can be negated using native operators.  For instance, >1 is the opposite of <=1 and eq and ne are opposites.  In addition, each individual test can be negated by adding a ! at the beginning of the test.  For instance, '!$acl_m1 =~ /^DENY$/' is the same as '$acl_m1 !~ /^DENY$/'.  Finally, every test can be specified by using the command line argument --not.  This is functionally equivalent to adding a ! to the beginning of every test.
 
 =back
 
@@ -1125,305 +1544,299 @@ In addition to standard logical negation available with the operators above (==
 
 With a few exceptions the available variables match Exim's internal expansion variables in both name and exact contents.  There are a few notable additions and format deviations which are noted below.  Although a brief explanation is offered below, Exim's spec.txt should be consulted for full details.  It is important to remember that not every variable will be defined for every message.  For example, $sender_host_port is not defined for messages not received from a remote host.
 
-In the list below, '.' denotes standard messages with contents matching Exim's variable, '#' denotes standard variables with non-standard contents, and '+' denotes a non-standard variable.
+Internally, all variables are represented as strings, meaning any operator will work on any variable.  This means that '$sender_host_name > 4' is a legal criterion, even if it does not produce meaningful results.  Variables in the list below are marked with a 'type' to help in choosing which types of operators make sense to use.
 
-=head2 Boolean variables
+  Identifiers
+    B - Boolean variables
+    S - String variables
+    N - Numeric variables
+    . - Standard variable matching Exim's content definition
+    # - Standard variable, contents differ from Exim's definition
+    + - Non-standard variable
 
 =over 4
 
-=item + $allow_unqualified_recipient
-
-TRUE if unqualified recipient addresses are permitted in header lines.
-
-=item + $allow_unqualified_sender
+=item S . $acl_c0-$acl_c9, $acl_m0-$acl_m9
 
-TRUE if unqualified sender addresses are permitted in header lines.
+User definable variables.
 
-=item + $deliver_freeze
+=item B + $allow_unqualified_recipient
 
-TRUE if the message is currently frozen.
+TRUE if unqualified recipient addresses are permitted in header lines.
 
-=item . $first_delivery
+=item B + $allow_unqualified_sender
 
-TRUE if the message has never been deferred.
+TRUE if unqualified sender addresses are permitted in header lines.
 
-=item . $manually_thawed
+=item S . $authenticated_id
 
-TRUE when the message has been manually thawed.
+Optional saved information from authenticators, or the login name of the calling process for locally submitted messages.
 
-=item + $dont_deliver
+=item S . $authenticated_sender
 
-TRUE if, under normal circumstances, Exim will not try to deliver the message.
+The value of AUTH= param for smtp messages, or a generated value from the calling processes login and qualify domain for locally submitted messages.
 
-=item . $host_lookup_deferred
+=item S . $bheader_*, $bh_*
 
-TRUE if there was an attempt to look up the host's name from its IP address, but an error occurred that during the attempt.
+Value of the header(s) with the same name with any RFC2047 words decoded if present.  See section 11.5 of Exim's spec.txt for full details.
 
-=item . $host_lookup_failed
+=item S + $bmi_verdicts
 
-TRUE if there was an attempt to look up the host's name from its IP address, but the attempt returned a negative result.
+The verdict string provided by a Brightmail content scan
 
-=item + $local_error_message
+=item N . $body_linecount
 
-TRUE if the message is a locally-generated error message.
+The number of lines in the message's body.
 
-=item + $sender_local
+=item N . $body_zerocount
 
-TRUE if the message was locally generated.
+The number of binary zero bytes in the message's body.
 
-=item + $sender_set_untrusted
+=item S + $data_path
 
-TRUE if the envelope sender of this message was set by an untrusted local caller.
+The path to the body file's location in the filesystem.
 
-=item . $tls_certificate_verified
+=item B + $deliver_freeze
 
-TRUE if a TLS certificate was verified when the message was received.
+TRUE if the message is currently frozen.
 
-=back
+=item N + $deliver_frozen_at
 
-=head2 Numeric variables
+The epoch time at which message was frozen.
 
-=over 4
+=item B + $dont_deliver
 
-=item . $body_linecount
+TRUE if, under normal circumstances, Exim will not try to deliver the message.
 
-The number of lines in the message's body.
+=item S + $each_recipients
 
-=item . $body_zerocount
+This is a pseudo variable which allows you to apply a test against each address in $recipients individually.  Whereas '$recipients =~ /@aol.com/' will match if any recipient address contains aol.com, '$each_recipients =~ /@aol.com$/' will only be true if every recipient matches that pattern.  Note that this obeys --and or --or being set.  Using it with --or is very similar to just matching against $recipients, but with the added benefit of being able to use anchors at the beginning and end of each recipient address.
 
-The number of binary zero bytes in the message's body.
+=item S + $each_recipients_del
 
-=item + $deliver_frozen_at
+Like $each_recipients, but for $recipients_del
 
-The epoch time at which message was frozen.
+=item S + $each_recipients_undel
 
-=item . $interface_port
+Like $each_recipients, but for $recipients_undel
 
-The local port number if network-originated messages.
+=item B . $first_delivery
 
-=item . $message_age
+TRUE if the message has never been deferred.
 
-The number of seconds since the message was received.
+=item S . $header_*, $h_*
 
-=item . $message_body_size
+This will always match the contents of the corresponding $bheader_* variable currently (the same behaviour Exim displays when iconv is not installed).
 
-The size of the body in bytes.
+=item S + $header_path
 
-=item . $message_linecount
+The path to the header file's location in the filesystem.
 
-The number of lines in the entire message (body and headers).
+=item B . $host_lookup_deferred
 
-=item . $message_size
+TRUE if there was an attempt to look up the host's name from its IP address, but an error occurred that during the attempt.
 
-The size of the message in bytes.
+=item B . $host_lookup_failed
 
-=item . $originator_gid
+TRUE if there was an attempt to look up the host's name from its IP address, but the attempt returned a negative result.
 
-The group id under which the process that called Exim was running as when the message was received.
+=item B + $local_error_message
 
-=item . $originator_uid
+TRUE if the message is a locally-generated error message.
 
-The user id under which the process that called Exim was running as when the message was received.
+=item S . $local_scan_data
 
-=item . $received_count
+The text returned by the local_scan() function when a message is received.
 
-The number of Received: header lines in the message.
+=item B . $manually_thawed
 
-=item . $received_time
+TRUE when the message has been manually thawed.
 
-The epoch time at which the message was received.
+=item N . $max_received_linelength
 
-=item . $recipients_count
+The number of bytes in the longest line that was received as part of the message, not counting line termination characters.
 
-The number of envelope recipients for the message.
+=item N . $message_age
 
-=item + $recipients_del_count
+The number of seconds since the message was received.
 
-The number of envelope recipients for the message which have already been delivered.  Note that this is the count of original recipients to which the message has been delivered.  It does not include generated addresses so it is possible that this number will be less than the number of addresses in the recipients_del string.
+=item S # $message_body
 
-=item + $recipients_undel_count
+The message's body.  Unlike Exim's variable of the same name, this variable contains the entire message body.  Newlines and nulls are replaced by spaces.
 
-The number of envelope recipients for the message which have not yet been delivered.
+=item B + $message_body_missing
 
-=item . $sender_host_port
+TRUE is a message's spool data file (-D file) is missing or unreadable.
 
-The port number that was used on the remote host for network-originated messages.
+=item N . $message_body_size
 
-=item + $warning_count
+The size of the body in bytes.
 
-The number of delay warnings which have been sent for this message.
+=item S . $message_exim_id, $message_id
 
-=back
+The unique message id that is used by Exim to identify the message.  $message_id is deprecated as of Exim 4.53.
 
-=head2 String variables
+=item S . $message_headers
 
-=over 4
+A concatenation of all the header lines except for lines added by routers or transports.  RFC2047 decoding is performed
 
-=item . $acl_c0-$acl_c9, $acl_m0-$acl_m9
+=item S . $message_headers_raw
 
-User definable variables.
+A concatenation of all the header lines except for lines added by routers or transports.  No decoding or translation is performed.
 
-=item . $authenticated_id
+=item N . $message_linecount
 
-Optional saved information from authenticators, or the login name of the calling process for locally submitted messages.
+The number of lines in the entire message (body and headers).
 
-=item . $authenticated_sender
+=item N . $message_size
 
-The value of AUTH= param for smtp messages, or a generated value from the calling processes login and qualify domain for locally submitted messages.
+The size of the message in bytes.
 
-=item + $bmi_verdicts
+=item N . $originator_gid
 
-I honestly don't know what the format of this variable is.  It only exists if you have Exim compiled with WITH_CONTENT_SCAN and EXPERIMENTAL_BRIGHTMAIL (and, you know, pay Symantec/Brightmail a bunch of money for the client libs and a server to use them with).
+The group id under which the process that called Exim was running as when the message was received.
 
-=item + $each_recipients
+=item S + $originator_login
 
-This is a psuedo variable which allows you to apply a criterion against each address in $recipients individually.  This allows you to create criteria against which every individual recipient is tested.  For instance, '$recipients =~ /aol.com/' will match if any of the recipient addresses contain the string "aol.com".  However, with the criterion '$each_recipients =~ /@aol.com$/', a message will only match if B<every> recipient matches that pattern.  Note that this obeys --and or --or being set.  Using it with --or is very similar to just matching against $recipients, but with the added benefit of being able to use anchors at the beginning and end of each recipient address.
+The login of the process which called Exim.
 
-=item + $each_recipients_del
+=item N . $originator_uid
 
-Like $each_recipients, but for the $recipients_del variable.
+The user id under which the process that called Exim was running as when the message was received.
 
-=item + $each_recipients_undel
+=item S . $received_ip_address, $interface_address
 
-Like $each_recipients, but for the $recipients_undel variable.
+The address of the local IP interface for network-originated messages.  $interface_address is deprecated as of Exim 4.64
 
-=item # $header_*
+=item N . $received_port, $interface_port
 
-The value of the same named message header, for example header_to or header_reply-to.  These variables are really closer to Exim's rheader_* variables, with the exception that leading and trailing space is removed.
+The local port number if network-originated messages.  $interface_port is deprecated as of Exim 4.64
 
-=item . $interface_address
+=item N . $received_count
 
-The address of the local IP interface for network-originated messages.
+The number of Received: header lines in the message.
 
-=item . $local_scan_data
+=item S . $received_protocol
 
-The text returned by the local_scan() function when a message is received.
+The name of the protocol by which the message was received.
 
-=item # $message_body
+=item N . $received_time
 
-The message's body.  Unlike Exim's variable of the same name, this variable contains the entire message body.  The logic behind this is that the message body is not read unless it is specifically referenced, so under normal circumstances it is not a penalty, but when you need the entire body you need the entire body.  Like Exim's copy, newlines and nulls are replaced by spaces.
+The epoch time at which the message was received.
 
-=item . $message_headers
+=item S # $recipients
 
-A concatenation of all the header lines except for lines added by routers or transports.
+The list of envelope recipients for a message.  Unlike Exim's version, this variable always contains every recipient of the message.  The recipients are separated by a comma and a space.  See also $each_recipients.
 
-=item . $message_exim_id, $message_id
+=item N . $recipients_count
 
-The unique message id that is used by Exim to identify the message.  $message_id is deprecated as of Exim 4.53.
+The number of envelope recipients for the message.
 
-=item + $originator_login
+=item S + $recipients_del
 
-The login of the process which called Exim.
+The list of delivered envelope recipients for a message.  This non-standard variable is in the same format as $recipients and contains the list of already-delivered recipients including any generated addresses.  See also $each_recipients_del.
 
-=item . $received_protocol
+=item N + $recipients_del_count
 
-The name of the protocol by which the message was received.
+The number of envelope recipients for the message which have already been delivered.  Note that this is the count of original recipients to which the message has been delivered.  It does not include generated addresses so it is possible that this number will be less than the number of addresses in the $recipients_del string.
 
-=item # $recipients
+=item S + $recipients_undel
 
-The list of envelope recipients for a message.  Unlike Exim's version, this variable always contains every envelope recipient of the message.  The recipients are separated by a comma and a space.
+The list of undelivered envelope recipients for a message.  This non-standard variable is in the same format as $recipients and contains the list of undelivered recipients.  See also $each_recipients_undel.
 
-=item + $recipients_del
+=item N + $recipients_undel_count
 
-The list of delivered envelope recipients for a message.  This non-standard variable is in the same format as recipients and contains the list of already-delivered recipients including any generated addresses.
+The number of envelope recipients for the message which have not yet been delivered.
 
-=item + $recipients_undel
+=item S . $reply_address
 
-The list of undelivered envelope recipients for a message.  This non-standard variable is in the same format as recipients and contains the list of undelivered recipients.
+The contents of the Reply-To: header line if one exists and it is not empty, or otherwise the contents of the From: header line.
 
-=item . $reply_address
+=item S . $rheader_*, $rh_*
 
-The contents of the Reply-To: header line if one exists and it is not empty, or otherwise the contents of the From: header line.
+The value of the message's header(s) with the same name.  See section 11.5 of Exim's spec.txt for full description.
 
-=item . $sender_address
+=item . $sender_address
 
 The sender's address that was received in the message's envelope.  For bounce messages, the value of this variable is the empty string.
 
-=item . $sender_address_domain
+=item . $sender_address_domain
 
 The domain part of $sender_address.
 
-=item . $sender_address_local_part
+=item . $sender_address_local_part
 
 The local part of $sender_address.
 
-=item . $sender_helo_name
+=item . $sender_helo_name
 
 The HELO or EHLO value supplied for smtp or bsmtp messages.
 
-=item . $sender_host_address
+=item . $sender_host_address
 
 The remote host's IP address.
 
-=item . $sender_host_authenticated
+=item . $sender_host_authenticated
 
 The name of the authenticator driver which successfully authenticated the client from which the message was received.
 
-=item . $sender_host_name
+=item . $sender_host_name
 
 The remote host's name as obtained by looking up its IP address.
 
-=item . $sender_ident
-
-The identification received in response to an RFC 1413 request for remote messages, the login name of the user that called Exim for locally generated messages.
-
-=item + $shown_message_size
-
-This non-standard variable contains the formatted size string.  That is, for a message whose $message_size is 66566 bytes, $shown_message_size is 65K.
-
-=item . $smtp_active_hostname
+=item N . $sender_host_port
 
-The value of the active host name when the message was received, as specified by the "smtp_active_hostname" option.
+The port number that was used on the remote host for network-originated messages.
 
-=item . $spam_score
+=item S . $sender_ident
 
-The spam score of the message, for example '3.4' or '30.5'.  (Requires exiscan or WITH_CONTENT_SCAN)
+The identification received in response to an RFC 1413 request for remote messages, the login name of the user that called Exim for locally generated messages.
 
-=item . $spam_score_int
+=item B + $sender_local
 
-The spam score of the message, multiplied by ten, as an integer value.  For instance '34' or '305'.  (Requires exiscan or WITH_CONTENT_SCAN)
+TRUE if the message was locally generated.
 
-=item . $tls_cipher
+=item B + $sender_set_untrusted
 
-The cipher suite that was negotiated for encrypted SMTP connections.
+TRUE if the envelope sender of this message was set by an untrusted local caller.
 
-=item . $tls_peerdn
+=item S + $shown_message_size
 
-The value of the Distinguished Name of the certificate if Exim is configured to request one.
+This non-standard variable contains the formatted size string.  That is, for a message whose $message_size is 66566 bytes, $shown_message_size is 65K.
 
-=back
+=item S . $smtp_active_hostname
 
-=head1 EXAMPLES
+The value of the active host name when the message was received, as specified by the "smtp_active_hostname" option.
 
-=over 4
+=item S . $spam_score
 
-=item exipick '$deliver_freeze'
+The spam score of the message, for example '3.4' or '30.5'.  (Requires exiscan or WITH_CONTENT_SCAN)
 
-Display only frozen messages.
+=item S . $spam_score_int
 
-=item exipick '$received_protocol eq asmtp' '$message_age < 20m'
+The spam score of the message, multiplied by ten, as an integer value.  For instance '34' or '305'.  (Requires exiscan or WITH_CONTENT_SCAN)
 
-Display only messages which were delivered over an authenticated smtp session in the last 20 minutes.
+=item B . $tls_certificate_verified
 
-=item exipick -bpc '$message_size > 200K'
+TRUE if a TLS certificate was verified when the message was received.
 
-Display a count of messages in the queue which are over 200 kilobytes in size.
+=item S . $tls_cipher
 
-=item exipick -or '$sender_helo_name =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/' '$sender_helo_name = _'
+The cipher suite that was negotiated for encrypted SMTP connections.
 
-Display message which have a HELO string which either is an IP address or contains an underscore.
+=item S . $tls_peerdn
 
-=back
+The value of the Distinguished Name of the certificate if Exim is configured to request one
 
-=head1 REQUIREMENTS
+=item S . $tls_sni
 
-None that I know of, except an Exim installation.  Your life will also be a lot easier if you set $spool at the top of the script to your install's spool directory (assuming this was not done automatically by the Exim install process).
+The value of the Server Name Indication TLS extension sent by a client, if one was sent.
 
-=head1 ACKNOWLEDGEMENTS
+=item N + $warning_count
 
-Although I conceived of the concept for this program independently, the name 'exipick' was taken from the Exim WishList and was suggested by Jeffrey Goldberg.
+The number of delay warnings which have been sent for this message.
 
-Thank you to Philip Hazel for writing Exim.  Of course this program exists because of Exim, but more specifically the message parsing code is based on Exim's and some of this documentation was copy/pasted from Exim's.
+=back
 
 =head1 CONTACT