2 # $Cambridge: exim/src/src/exipick.src,v 1.14 2006/11/17 22:27:41 jetmore Exp $
4 # This variable should be set by the building process to Exim's spool directory.
5 my $spool = 'SPOOL_DIRECTORY';
6 # Need to set this dynamically during build, but it's not used right now anyway.
7 my $charset = 'ISO-8859-1';
9 # use 'exipick --help' to view documentation for this program.
10 # Documentation also viewable online at
11 # http://www.exim.org/eximwiki/ToolExipickManPage
16 my($p_name) = $0 =~ m|/?([^/]+)$|;
17 my $p_version = "20061117.2";
18 my $p_usage = "Usage: $p_name [--help|--version] (see --help for details)";
20 Copyright (c) 2003-2006 John Jetmore <jj33\@pobox.com>
22 This program is free software; you can redistribute it and/or modify
23 it under the terms of the GNU General Public License as published by
24 the Free Software Foundation; either version 2 of the License, or
25 (at your option) any later version.
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
36 ext_usage(); # before we do anything else, check for --help
38 $| = 1; # unbuffer STDOUT
40 Getopt::Long::Configure("bundling_override");
42 'spool=s' => \$G::spool, # exim spool dir
43 'bp' => \$G::mailq_bp, # List the queue (noop - default)
44 'bpa' => \$G::mailq_bpa, # ... with generated address as well
45 'bpc' => \$G::mailq_bpc, # ... but just show a count of messages
46 'bpr' => \$G::mailq_bpr, # ... do not sort
47 'bpra' => \$G::mailq_bpra, # ... with generated addresses, unsorted
48 'bpru' => \$G::mailq_bpru, # ... only undelivered addresses, unsorted
49 'bpu' => \$G::mailq_bpu, # ... only undelivered addresses
50 'and' => \$G::and, # 'and' the criteria (default)
51 'or' => \$G::or, # 'or' the criteria
52 'f=s' => \$G::qgrep_f, # from regexp
53 'r=s' => \$G::qgrep_r, # recipient regexp
54 's=s' => \$G::qgrep_s, # match against size field
55 'y=s' => \$G::qgrep_y, # message younger than (secs)
56 'o=s' => \$G::qgrep_o, # message older than (secs)
57 'z' => \$G::qgrep_z, # frozen only
58 'x' => \$G::qgrep_x, # non-frozen only
59 'c' => \$G::qgrep_c, # display match count
60 'l' => \$G::qgrep_l, # long format (default)
61 'i' => \$G::qgrep_i, # message ids only
62 'b' => \$G::qgrep_b, # brief format
63 'size' => \$G::size_only, # sum the size of the matching msgs
64 'not' => \$G::negate, # flip every test
65 'R|reverse' => \$G::reverse, # reverse output (-R is qgrep option)
66 'sort=s' => \@G::sort, # allow you to choose variables to sort by
67 'freeze=s' => \$G::freeze, # freeze data in this file
68 'thaw=s' => \$G::thaw, # thaw data from this file
69 'unsorted' => \$G::unsorted, # unsorted, regardless of output format
70 'random' => \$G::random, # (poorly) randomize evaluation order
71 'flatq' => \$G::flatq, # brief format
72 'caseful' => \$G::caseful, # in '=' criteria, respect case
73 'caseless' => \$G::caseless, # ...ignore case (default)
74 'charset=s' => \$charset, # charset for $bh and $h variables
75 'show-vars=s' => \$G::show_vars, # display the contents of these vars
76 'just-vars' => \$G::just_vars, # only display vars, no other info
77 'show-rules' => \$G::show_rules, # display compiled match rules
78 'show-tests' => \$G::show_tests # display tests as applied to each message
81 # if both freeze and thaw specified, only thaw as it is less desctructive
82 $G::freeze = undef if ($G::freeze && $G::thaw);
83 freeze_start() if ($G::freeze);
84 thaw_start() if ($G::thaw);
86 # massage sort options (make '$var,Var:' be 'var','var')
87 for (my $i = scalar(@G::sort)-1; $i >= 0; $i--) {
88 $G::sort[$i] = lc($G::sort[$i]);
89 $G::sort[$i] =~ s/[\$:\s]//g;
90 if ((my @vars = split(/,/, $G::sort[$i])) > 1) {
91 $G::sort[$i] = $vars[0]; shift(@vars); # replace current slot w/ first var
92 splice(@G::sort, $i+1, 0, @vars); # add other vars after current pos
95 push(@G::sort, "message_exim_id") if (@G::sort);
96 die "empty value provided to --sort not allowed, exiting\n"
97 if (grep /^\s*$/, @G::sort);
99 # massage the qgrep options into standard criteria
100 push(@ARGV, "\$sender_address =~ /$G::qgrep_f/") if ($G::qgrep_f);
101 push(@ARGV, "\$recipients =~ /$G::qgrep_r/") if ($G::qgrep_r);
102 push(@ARGV, "\$shown_message_size eq $G::qgrep_s") if ($G::qgrep_s);
103 push(@ARGV, "\$message_age < $G::qgrep_y") if ($G::qgrep_y);
104 push(@ARGV, "\$message_age > $G::qgrep_o") if ($G::qgrep_o);
105 push(@ARGV, "\$deliver_freeze") if ($G::qgrep_z);
106 push(@ARGV, "!\$deliver_freeze") if ($G::qgrep_x);
108 $G::mailq_bp = $G::mailq_bp; # shut up -w
109 $G::and = $G::and; # shut up -w
110 $G::msg_ids = {}; # short circuit when crit is only MID
111 $G::caseless = $G::caseful ? 0 : 1; # nocase by default, case if both
112 @G::recipients_crit = (); # holds per-recip criteria
113 $spool = $G::spool if ($G::spool);
114 my $count_only = 1 if ($G::mailq_bpc || $G::qgrep_c);
115 my $unsorted = 1 if ($G::mailq_bpr || $G::mailq_bpra ||
116 $G::mailq_bpru || $G::unsorted);
117 my $msg = $G::thaw ? thaw_message_list()
118 : get_all_msgs($spool, $unsorted,
119 $G::reverse, $G::random);
120 die "Problem accessing thaw file\n" if ($G::thaw && !$msg);
121 my $crit = process_criteria(\@ARGV);
122 my $e = Exim::SpoolFile->new();
123 my $tcount = 0 if ($count_only); # holds count of all messages
124 my $mcount = 0 if ($count_only); # holds count of matching messages
125 my $total_size = 0 if ($G::size_only);
126 $e->set_undelivered_only(1) if ($G::mailq_bpru || $G::mailq_bpu);
127 $e->set_show_generated(1) if ($G::mailq_bpra || $G::mailq_bpa);
128 $e->output_long() if ($G::qgrep_l);
129 $e->output_idonly() if ($G::qgrep_i);
130 $e->output_brief() if ($G::qgrep_b);
131 $e->output_flatq() if ($G::flatq);
132 $e->output_vars_only() if ($G::just_vars && $G::show_vars);
133 $e->set_show_vars($G::show_vars) if ($G::show_vars);
134 $e->set_spool($spool);
137 foreach my $m (@$msg) {
138 next if (scalar(keys(%$G::msg_ids)) && !$G::or
139 && !$G::msg_ids->{$m->{message}});
141 my $data = thaw_data();
142 if (!$e->restore_state($data)) {
143 warn "Couldn't thaw $data->{_message}: ".$e->error()."\n";
147 if (!$e->parse_message($m->{message}, $m->{path})) {
148 warn "Couldn't parse $m->{message}: ".$e->error()."\n";
155 foreach my $c (@G::recipients_crit) { # handle each_recip* vars
156 foreach my $addr (split(/, /, $e->get_var($c->{var}))) {
157 my %t = ( 'cmp' => $c->{cmp}, 'var' => $c->{var} );
158 $t{cmp} =~ s/"?\$var"?/'$addr'/;
159 push(@local_crit, \%t);
162 if ($G::show_tests) { print $e->get_var('message_exim_id'), "\n"; }
164 foreach my $c (@$crit, @local_crit) {
165 my $var = $e->get_var($c->{var});
166 my $ret = eval($c->{cmp});
167 if ($G::show_tests) {
168 printf " %25s = '%s'\n %25s => $ret\n",$c->{var},$var,$c->{cmp},$ret;
171 print STDERR "Error in eval '$c->{cmp}': $@\n";
175 if ($G::or) { last CRITERIA; }
176 else { next CRITERIA; }
178 if ($G::or) { next CRITERIA; }
183 # skip this message if any criteria were supplied and it didn't match
184 next MSG if ((scalar(@$crit) || scalar(@local_crit)) && !$match);
186 if ($count_only || $G::size_only) {
188 $total_size += $e->get_var('message_size');
191 # if we are defining criteria to sort on, save the message here. If
192 # we don't save here and do the sort later, we have a chicken/egg
194 push(@G::to_print, { vars => {}, output => "" });
195 foreach my $var (@G::sort) {
196 # save any values we want to sort on. I don't like doing the internal
197 # struct access here, but calling get_var a bunch can be _slow_ =(
198 $G::sort_type{$var} ||= '<=>';
199 $G::to_print[-1]{vars}{$var} = $e->{_vars}{$var};
200 $G::sort_type{$var} = 'cmp' if ($G::to_print[-1]{vars}{$var} =~ /\D/);
202 $G::to_print[-1]{output} = $e->format_message();
204 print $e->format_message();
209 freeze_data($e->get_state());
210 push(@G::frozen_msgs, $m);
215 msg_sort(\@G::to_print, \@G::sort, $G::reverse);
216 foreach my $msg (@G::to_print) {
217 print $msg->{output};
222 print "$mcount matches out of $tcount messages" .
223 ($G::size_only ? " ($total_size)" : "") . "\n";
224 } elsif ($G::mailq_bpc) {
225 print "$mcount" . ($G::size_only ? " ($total_size)" : "") . "\n";
226 } elsif ($G::size_only) {
227 print "$total_size\n";
231 freeze_message_list(\@G::frozen_msgs);
239 # sender_address_domain,shown_message_size
246 foreach my $v (@G::sort) {
247 push(@pieces, "\$a->{vars}{\"$v\"} $G::sort_type{$v} \$b->{vars}{\"$v\"}");
249 my $sort_str = join(" || ", @pieces);
251 @$msgs = sort { eval $sort_str } (@$msgs);
252 @$msgs = reverse(@$msgs) if ($reverse);
262 # FREEZE FILE FORMAT:
268 # message_list_bytes <- 10 bytes, zero-packed, plus \n
271 eval("use Storable");
272 die "Storable module not found: $@\n" if ($@);
273 open(O, ">$G::freeze") || die "Can't open freeze file $G::freeze: $!\n";
274 $G::freeze_handle = \*O;
278 close($G::freeze_handle);
282 eval("use Storable");
283 die "Storable module not found: $@\n" if ($@);
284 open(I, "<$G::thaw") || die "Can't open freeze file $G::thaw: $!\n";
285 $G::freeze_handle = \*I;
289 close($G::freeze_handle);
293 my $h = Storable::freeze($_[0]);
294 print $G::freeze_handle length($h)+1, "\n$h\n";
297 sub freeze_message_list {
298 my $h = Storable::freeze($_[0]);
299 my $l = length($h) + 1;
300 printf $G::freeze_handle "EOM\n$l\n$h\n%010d\n", $l+11+length($l)+1;
303 sub thaw_message_list {
304 my $orig_pos = tell($G::freeze_handle);
305 seek($G::freeze_handle, -11, 2);
306 chomp(my $bytes = <$G::freeze_handle>);
307 seek($G::freeze_handle, $bytes * -1, 2);
308 my $obj = thaw_data();
309 seek($G::freeze_handle, 0, $orig_pos);
315 chomp(my $bytes = <$G::freeze_handle>);
316 return(undef) if (!$bytes || $bytes eq 'EOM');
317 my $read = read(I, $obj, $bytes);
318 die "Format error in thaw file (expected $bytes bytes, got $read)\n"
319 if ($bytes != $read);
321 return(Storable::thaw($obj));
324 sub process_criteria {
330 foreach my $t ('@') { s/$t/\\$t/g; }
331 if (/^(.*?)\s+(<=|>=|==|!=|<|>)\s+(.*)$/) {
332 #print STDERR "found as integer\n";
333 my $v = $1; my $o = $2; my $n = $3;
334 if ($n =~ /^(-?[\d\.]+)M$/) { $n = $1 * 1024 * 1024; }
335 elsif ($n =~ /^(-?[\d\.]+)K$/) { $n = $1 * 1024; }
336 elsif ($n =~ /^(-?[\d\.]+)B?$/) { $n = $1; }
337 elsif ($n =~ /^(-?[\d\.]+)d$/) { $n = $1 * 60 * 60 * 24; }
338 elsif ($n =~ /^(-?[\d\.]+)h$/) { $n = $1 * 60 * 60; }
339 elsif ($n =~ /^(-?[\d\.]+)m$/) { $n = $1 * 60; }
340 elsif ($n =~ /^(-?[\d\.]+)s?$/) { $n = $1; }
342 print STDERR "Expression $_ did not parse: numeric comparison with ",
347 push(@c, { var => lc($v), cmp => "(\$var $o $n)" });
348 } elsif (/^(.*?)\s+(=~|!~)\s+(.*)$/) {
349 #print STDERR "found as string regexp\n";
350 push(@c, { var => lc($1), cmp => "(\"\$var\" $2 $3)" });
351 } elsif (/^(.*?)\s+=\s+(.*)$/) {
352 #print STDERR "found as bare string regexp\n";
353 my $case = $G::caseful ? '' : 'i';
354 push(@c, { var => lc($1), cmp => "(\"\$var\" =~ /$2/$case)" });
355 # quote special characters in perl text string
356 #foreach my $t ('@') { $c[-1]{cmp} =~ s/$t/\\$t/g; }
357 } elsif (/^(.*?)\s+(eq|ne)\s+(.*)$/) {
358 #print STDERR "found as string cmp\n";
359 my $var = lc($1); my $op = $2; my $val = $3;
360 $val =~ s|^(['"])(.*)\1$|$2|;
361 push(@c, { var => $var, cmp => "(\"\$var\" $op \"$val\")" });
362 if (($var eq 'message_id' || $var eq 'message_exim_id') && $op eq "eq") {
363 #print STDERR "short circuit @c[-1]->{cmp} $val\n";
364 $G::msg_ids->{$val} = 1;
366 #foreach my $t ('@') { $c[-1]{cmp} =~ s/$t/\\$t/g; }
367 } elsif (/^(\S+)$/) {
368 #print STDERR "found as boolean\n";
369 push(@c, { var => lc($1), cmp => "(\$var)" });
371 print STDERR "Expression $_ did not parse\n";
375 # assign the results of the cmp test here (handle "!" negation)
376 # also handle global --not negation
377 if ($c[-1]{var} =~ s|^!||) {
378 $c[-1]{cmp} .= $G::negate ? " ? 1 : 0" : " ? 0 : 1";
380 $c[-1]{cmp} .= $G::negate ? " ? 0 : 1" : " ? 1 : 0";
382 # support the each_* psuedo variables. Steal the criteria off of the
383 # queue for special processing later
384 if ($c[-1]{var} =~ /^each_(recipients(_(un)?del)?)$/) {
386 push(@G::recipients_crit,pop(@c));
387 $G::recipients_crit[-1]{var} = $var; # remove each_ from the variable
393 if ($G::show_rules) { foreach (@c) { print "$_->{var}\t$_->{cmp}\n"; } }
399 my $d = shift() . '/input';
400 my $u = shift; # don't sort
401 my $r = shift; # right before returning, reverse order
402 my $o = shift; # if true, randomize list order before returning
405 opendir(D, "$d") || die "Couldn't opendir $d: $!\n";
406 foreach my $e (grep !/^\./, readdir(D)) {
407 if ($e =~ /^[a-zA-Z0-9]$/) {
408 opendir(DD, "$d/$e") || next;
409 foreach my $f (grep !/^\./, readdir(DD)) {
410 push(@m, { message => $1, path => "$d/$e" }) if ($f =~ /^(.{16})-H$/);
413 } elsif ($e =~ /^(.{16})-H$/) {
414 push(@m, { message => $1, path => $d });
421 # loop twice to pretend we're doing a good job of mixing things up
422 for (my $i = 0; $i < 2 * $c; $i++) {
423 my $rand = int(rand($c));
424 ($m[$i % $c],$m[$rand]) = ($m[$rand],$m[$i % $c]);
427 @m = sort { $a->{message} cmp $b->{message} } @m;
429 @m = reverse(@m) if ($r);
436 package Exim::SpoolFile;
438 # versions 4.61 and higher will not need these variables anymore, but they
439 # are left for handling legacy installs
440 $Exim::SpoolFile::ACL_C_MAX_LEGACY = 10;
441 #$Exim::SpoolFile::ACL_M_MAX _LEGACY= 10;
446 bless($self, $class);
448 $self->{_spool_dir} = '';
449 $self->{_undelivered_only} = 0;
450 $self->{_show_generated} = 0;
451 $self->{_output_long} = 1;
452 $self->{_output_idonly} = 0;
453 $self->{_output_brief} = 0;
454 $self->{_output_flatq} = 0;
455 $self->{_output_vars_only} = 0;
456 $self->{_show_vars} = [];
465 $self->{_output_long} = 1;
466 $self->{_output_idonly} = 0;
467 $self->{_output_brief} = 0;
468 $self->{_output_flatq} = 0;
469 $self->{_output_vars_only} = 0;
475 $self->{_output_long} = 0;
476 $self->{_output_idonly} = 1;
477 $self->{_output_brief} = 0;
478 $self->{_output_flatq} = 0;
479 $self->{_output_vars_only} = 0;
485 $self->{_output_long} = 0;
486 $self->{_output_idonly} = 0;
487 $self->{_output_brief} = 1;
488 $self->{_output_flatq} = 0;
489 $self->{_output_vars_only} = 0;
495 $self->{_output_long} = 0;
496 $self->{_output_idonly} = 0;
497 $self->{_output_brief} = 0;
498 $self->{_output_flatq} = 1;
499 $self->{_output_vars_only} = 0;
502 sub output_vars_only {
505 $self->{_output_long} = 0;
506 $self->{_output_idonly} = 0;
507 $self->{_output_brief} = 0;
508 $self->{_output_flatq} = 0;
509 $self->{_output_vars_only} = 1;
516 foreach my $v (split(/\s*,\s*/, $s)) {
517 push(@{$self->{_show_vars}}, $v);
521 sub set_show_generated {
523 $self->{_show_generated} = shift;
526 sub set_undelivered_only {
528 $self->{_undelivered_only} = shift;
533 return $self->{_error};
538 $self->{_error} = shift;
545 $self->{_error} = '';
546 $self->{_delivered} = 0;
547 $self->{_message} = '';
550 $self->{_vars_raw} = {};
552 $self->{_numrecips} = 0;
553 $self->{_udel_tree} = {};
554 $self->{_del_tree} = {};
555 $self->{_recips} = {};
564 $self->{_message} = shift || return(0);
565 $self->{_path} = shift; # optional path to message
566 return(0) if (!$self->{_spool_dir});
567 if (!$self->{_path} && !$self->_find_path()) {
568 # assume the message was delivered from under us and ignore
569 $self->{_delivered} = 1;
572 $self->_parse_header() || return(0);
577 # take the output of get_state() and set up a message internally like
578 # parse_message (except from a saved data struct, not by parsing the
584 return(1) if ($h->{_delivered});
586 $self->{_message} = $h->{_message} || return(0);
587 return(0) if (!$self->{_spool_dir});
589 $self->{_path} = $h->{_path};
590 $self->{_vars} = $h->{_vars};
591 $self->{_numrecips} = $h->{_numrecips};
592 $self->{_udel_tree} = $h->{_udel_tree};
593 $self->{_del_tree} = $h->{_del_tree};
594 $self->{_recips} = $h->{_recips};
596 $self->{_vars}{message_age} = time() - $self->{_vars}{received_time};
600 # This returns the state data for a specific message in a format that can
601 # be later frozen back in to regain state
603 # after calling this function, this specific state is not expect to be
604 # reused. That's because we're returning direct references to specific
605 # internal structures. We're also modifying the structure ourselves
606 # by deleting certain internal message variables.
609 my $h = {}; # this is the hash ref we'll be returning.
611 $h->{_delivered} = $self->{_delivered};
612 $h->{_message} = $self->{_message};
613 $h->{_path} = $self->{_path};
614 $h->{_vars} = $self->{_vars};
615 $h->{_numrecips} = $self->{_numrecips};
616 $h->{_udel_tree} = $self->{_udel_tree};
617 $h->{_del_tree} = $self->{_del_tree};
618 $h->{_recips} = $self->{_recips};
620 # delete some internal variables that we will rebuild later if needed
621 delete($h->{_vars}{message_body});
622 delete($h->{_vars}{message_age});
627 # keep this sub as a feature if we ever break this module out, but do away
628 # with its use in exipick (pass it in from caller instead)
632 return(0) if (!$self->{_message});
633 return(0) if (!$self->{_spool_dir});
635 # test split spool first on the theory that people concerned about
636 # performance will have split spool set =).
637 foreach my $f (substr($self->{_message}, 5, 1).'/', '') {
638 if (-f "$self->{_spool_dir}/input/$f$self->{_message}-H") {
639 $self->{_path} = $self->{_spool_dir} . "/input/$f";
648 $self->{_spool_dir} = shift;
651 sub get_matching_vars {
657 foreach my $v (keys %{$self->{_vars}}) { push(@r, $v) if ($v =~ /$e/); }
664 # accepts a variable with or without leading '$' or trailing ':'
667 my $var = lc(shift); $var =~ s/^\$//; $var =~ s/:$//;
669 if ($var eq 'message_body' && !defined($self->{_vars}{message_body})) {
671 } elsif ($var =~ s|^([rb]?h)(eader)?_|${1}eader_| &&
672 exists($self->{_vars}{$var}) && !defined($self->{_vars}{$var}))
674 if ((my $type = $1) eq 'rh') {
675 $self->{_vars}{$var} = join('', @{$self->{_vars_raw}{$var}{vals}});
677 # both bh_ and h_ build their strings from rh_. Do common work here
678 my $rh = $var; $rh =~ s|^b?|r|;
679 my $comma = 1 if ($self->{_vars_raw}{$rh}{type} =~ /^[BCFRST]$/);
680 foreach (@{$self->{_vars_raw}{$rh}{vals}}) {
681 my $x = $_; # editing $_ here would change the original, which is bad
684 if ($comma) { chomp($x); $self->{_vars}{$var} .= "$x,\n"; }
685 else { $self->{_vars}{$var} .= $x; }
687 $self->{_vars}{$var} =~ s|[\s\n]*$||;
688 $self->{_vars}{$var} =~ s|,$|| if ($comma);
689 # ok, that's the preprocessing, not do specific processing for h type
691 $self->{_vars}{$var} = $self->_decode_2047($self->{_vars}{$var});
693 $self->{_vars}{$var} =
694 $self->_decode_2047($self->{_vars}{$var}, $charset);
698 elsif ($var eq 'received_count' && !defined($self->{_vars}{received_count}))
700 $self->{_vars}{received_count} =
701 scalar(@{$self->{_vars_raw}{rheader_received}{vals}});
703 elsif ($var eq 'message_headers' && !defined($self->{_vars}{message_headers}))
705 $self->{_vars}{$var} =
706 $self->_decode_2047($self->{_vars}{message_headers_raw}, $charset);
707 chomp($self->{_vars}{$var});
709 elsif ($var eq 'reply_address' && !defined($self->{_vars}{reply_address}))
711 $self->{_vars}{reply_address} = exists($self->{_vars}{"header_reply-to"})
712 ? $self->get_var("header_reply-to") : $self->get_var("header_from");
715 #chomp($self->{_vars}{$var}); # I think this was only for headers, obsolete
716 return $self->{_vars}{$var};
721 my $s = shift; # string to decode
722 my $c = shift; # target charset. If empty, just decode, don't convert
723 my $t = ''; # the translated string
724 my $e = 0; # set to true if we get an error in here anywhere
726 return($s) if ($s !~ /=\?/); # don't even bother to look if there's no sign
729 foreach my $mw (split(/(=\?[^\?]{3,}\?[BQ]\?[^\?]{1,74}\?=)/i, $s)) {
731 if ($mw =~ /=\?([^\?]{3,})\?([BQ])\?([^\?]{1,74})\?=/i) {
732 push(@p, { data => $3, encoding => uc($2), charset => uc($1),
734 if ($p[-1]{encoding} eq 'Q') {
735 my @ow = split('', $p[-1]{data});
737 for (my $i = 0; $i < @ow; $i++) {
738 if ($ow[$i] eq '_') { push(@nw, ' '); }
739 elsif ($ow[$i] eq '=') {
740 if (scalar(@ow) - ($i+1) < 2) { # ran out of characters
742 } elsif ($ow[$i+1] !~ /[\dA-F]/i || $ow[$i+2] !~ /[\dA-F]/i) {
745 #push(@nw, chr('0x'.$ow[$i+1].$ow[$i+2]));
746 push(@nw, pack("C", hex($ow[$i+1].$ow[$i+2])));
750 elsif ($ow[$i] =~ /\s/) { # whitspace is illegal
754 else { push(@nw, $ow[$i]); }
756 $p[-1]{data} = join('', @nw);
757 } elsif ($p[-1]{encoding} eq 'B') {
758 my $x = $p[-1]{data};
759 $x =~ tr#A-Za-z0-9+/##cd;
761 $x =~ tr#A-Za-z0-9+/# -_#;
763 while ($x =~ s/(.{1,60})//s) {
764 $r .= unpack("u", chr(32 + int(length($1)*3/4)) . $1);
769 push(@p, { data => $mw, is_mime => 0,
770 is_ws => ($mw =~ m|^[\s\n]+|sm) ? 1 : 0 });
774 for (my $i = 0; $i < @p; $i++) {
775 # mark entities we want to skip (whitespace between consecutive mimewords)
776 if ($p[$i]{is_mime} && $p[$i+1]{is_ws} && $p[$i+2]{is_mime}) {
780 # if word is a mimeword and we have access to Encode and charset was
781 # specified, try to convert text
782 # XXX _cannot_ get consistent conversion results in perl, can't get them
783 # to return same conversions that exim performs. Until I can figure this
784 # out, don't attempt any conversions (header_ will return same value as
786 #if ($c && $p[$i]{is_mime} && $self->_try_load('Encode')) {
787 # # XXX not sure how to catch errors here
788 # Encode::from_to($p[$i]{data}, $p[$i]{charset}, $c);
791 # replace binary zeros w/ '?' in decoded text
792 if ($p[$i]{is_mime}) { $p[$i]{data} =~ s|\x00|?|g; }
798 return(join('', map { $_->{data} } grep { !$_->{skip} } @p));
802 # This isn't a class func but I'm tired
813 my $f = $self->{_path} . '/' . $self->{_message} . '-D';
814 $self->{_vars}{message_body} = ""; # define var so we only come here once
816 open(I, "<$f") || return($self->_error("Couldn't open $f: $!"));
818 return(0) if ($self->{_message}.'-D' ne $_);
820 $self->{_vars}{message_body} = join('', <I>);
822 $self->{_vars}{message_body} =~ s/\n/ /g;
823 $self->{_vars}{message_body} =~ s/\000/ /g;
829 my $f = $self->{_path} . '/' . $self->{_message} . '-H';
831 if (!open(I, "<$f")) {
832 # assume message went away and silently ignore
833 $self->{_delivered} = 1;
837 # There are a few numeric variables that should explicitly be set to
838 # zero if they aren't found in the header. Technically an empty value
839 # works just as well, but might as well be pedantic
840 $self->{_vars}{body_zerocount} = 0;
841 $self->{_vars}{host_lookup_deferred} = 0;
842 $self->{_vars}{host_lookup_failed} = 0;
843 $self->{_vars}{tls_certificate_verified} = 0;
846 return(0) if ($self->{_message}.'-H' ne $_);
847 $self->{_vars}{message_id} = $self->{_message};
848 $self->{_vars}{message_exim_id} = $self->{_message};
852 return(0) if (!/^(.+)\s(\-?\d+)\s(\-?\d+)$/);
853 $self->{_vars}{originator_login} = $1;
854 $self->{_vars}{originator_uid} = $2;
855 $self->{_vars}{originator_gid} = $3;
859 return(0) if (!/^<(.*)>$/);
860 $self->{_vars}{sender_address} = $1;
861 $self->{_vars}{sender_address_domain} = $1;
862 $self->{_vars}{sender_address_local_part} = $1;
863 $self->{_vars}{sender_address_domain} =~ s/^.*\@//;
864 $self->{_vars}{sender_address_local_part} =~ s/^(.*)\@.*$/$1/;
868 return(0) if (!/^(\d+)\s(\d+)$/);
869 $self->{_vars}{received_time} = $1;
870 $self->{_vars}{warning_count} = $2;
871 $self->{_vars}{message_age} = time() - $self->{_vars}{received_time};
875 if (/^(-\S+)\s*(.*$)/) {
878 if ($tag eq '-acl') {
880 return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
881 if ($1 < $Exim::SpoolFile::ACL_C_MAX_LEGACY) {
884 $t = "acl_m" . ($1 - $Exim::SpoolFile::ACL_C_MAX_LEGACY);
886 read(I, $self->{_vars}{$t}, $2+1) || return(0);
887 chomp($self->{_vars}{$t});
888 } elsif ($tag eq '-aclc') {
889 #return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
890 return(0) if ($arg !~ /^(\S+)\s(\d+)$/);
892 read(I, $self->{_vars}{$t}, $2+1) || return(0);
893 chomp($self->{_vars}{$t});
894 } elsif ($tag eq '-aclm') {
895 #return(0) if ($arg !~ /^(\d+)\s(\d+)$/);
896 return(0) if ($arg !~ /^(\S+)\s(\d+)$/);
898 read(I, $self->{_vars}{$t}, $2+1) || return(0);
899 chomp($self->{_vars}{$t});
900 } elsif ($tag eq '-local') {
901 $self->{_vars}{sender_local} = 1;
902 } elsif ($tag eq '-localerror') {
903 $self->{_vars}{local_error_message} = 1;
904 } elsif ($tag eq '-local_scan') {
905 $self->{_vars}{local_scan_data} = $arg;
906 } elsif ($tag eq '-spam_score_int') {
907 $self->{_vars}{spam_score_int} = $arg;
908 $self->{_vars}{spam_score} = $arg / 10;
909 } elsif ($tag eq '-bmi_verdicts') {
910 $self->{_vars}{bmi_verdicts} = $arg;
911 } elsif ($tag eq '-host_lookup_deferred') {
912 $self->{_vars}{host_lookup_deferred} = 1;
913 } elsif ($tag eq '-host_lookup_failed') {
914 $self->{_vars}{host_lookup_failed} = 1;
915 } elsif ($tag eq '-body_linecount') {
916 $self->{_vars}{body_linecount} = $arg;
917 } elsif ($tag eq '-body_zerocount') {
918 $self->{_vars}{body_zerocount} = $arg;
919 } elsif ($tag eq '-frozen') {
920 $self->{_vars}{deliver_freeze} = 1;
921 $self->{_vars}{deliver_frozen_at} = $arg;
922 } elsif ($tag eq '-allow_unqualified_recipient') {
923 $self->{_vars}{allow_unqualified_recipient} = 1;
924 } elsif ($tag eq '-allow_unqualified_sender') {
925 $self->{_vars}{allow_unqualified_sender} = 1;
926 } elsif ($tag eq '-deliver_firsttime') {
927 $self->{_vars}{deliver_firsttime} = 1;
928 $self->{_vars}{first_delivery} = 1;
929 } elsif ($tag eq '-manual_thaw') {
930 $self->{_vars}{deliver_manual_thaw} = 1;
931 $self->{_vars}{manually_thawed} = 1;
932 } elsif ($tag eq '-auth_id') {
933 $self->{_vars}{authenticated_id} = $arg;
934 } elsif ($tag eq '-auth_sender') {
935 $self->{_vars}{authenticated_sender} = $arg;
936 } elsif ($tag eq '-sender_set_untrusted') {
937 $self->{_vars}{sender_set_untrusted} = 1;
938 } elsif ($tag eq '-tls_certificate_verified') {
939 $self->{_vars}{tls_certificate_verified} = 1;
940 } elsif ($tag eq '-tls_cipher') {
941 $self->{_vars}{tls_cipher} = $arg;
942 } elsif ($tag eq '-tls_peerdn') {
943 $self->{_vars}{tls_peerdn} = $arg;
944 } elsif ($tag eq '-host_address') {
945 $self->{_vars}{sender_host_port} = $self->_get_host_and_port(\$arg);
946 $self->{_vars}{sender_host_address} = $arg;
947 } elsif ($tag eq '-interface_address') {
948 $self->{_vars}{received_port} =
949 $self->{_vars}{interface_port} = $self->_get_host_and_port(\$arg);
950 $self->{_vars}{received_ip_address} =
951 $self->{_vars}{interface_address} = $arg;
952 } elsif ($tag eq '-active_hostname') {
953 $self->{_vars}{smtp_active_hostname} = $arg;
954 } elsif ($tag eq '-host_auth') {
955 $self->{_vars}{sender_host_authenticated} = $arg;
956 } elsif ($tag eq '-host_name') {
957 $self->{_vars}{sender_host_name} = $arg;
958 } elsif ($tag eq '-helo_name') {
959 $self->{_vars}{sender_helo_name} = $arg;
960 } elsif ($tag eq '-ident') {
961 $self->{_vars}{sender_ident} = $arg;
962 } elsif ($tag eq '-received_protocol') {
963 $self->{_vars}{received_protocol} = $arg;
964 } elsif ($tag eq '-N') {
965 $self->{_vars}{dont_deliver} = 1;
967 # unrecognized tag, save it for reference
968 $self->{$tag} = $arg;
975 # when we drop out of the while loop, we have the first line of the
976 # delivered tree in $_
980 } elsif ($_ =~ s/^[YN][YN]\s+//) {
981 $self->{_del_tree}{$_} = 1;
986 } while ($_ !~ /^\d+$/);
988 $self->{_numrecips} = $_;
989 $self->{_vars}{recipients_count} = $self->{_numrecips};
990 for (my $i = 0; $i < $self->{_numrecips}; $i++) {
994 if (/^(.*)\s\d+,(\d+),\d+$/) {
995 #print STDERR "exim3 type (untested): $_\n";
996 $self->{_recips}{$1} = { pno => $2 };
998 } elsif (/^(.*)\s(\d+)$/) {
999 #print STDERR "exim4 original type (untested): $_\n";
1000 $self->{_recips}{$1} = { pno => $2 };
1002 } elsif (/^(.*)\s(.*)\s(\d+),(\d+)#1$/) {
1003 #print STDERR "exim4 new type #1 (untested): $_\n";
1004 return($self->_error("incorrect format: $_")) if (length($2) != $3);
1005 $self->{_recips}{$1} = { pno => $4, errors_to => $2 };
1007 } elsif (/^.*#(\d+)$/) {
1008 #print STDERR "exim4 #$1 style (unimplemented): $_\n";
1009 $self->_error("exim4 #$1 style (unimplemented): $_");
1011 #print STDERR "default type: $_\n";
1012 $self->{_recips}{$_} = {};
1015 $self->{_udel_tree}{$addr} = 1 if (!$self->{_del_tree}{$addr});
1017 $self->{_vars}{recipients} = join(', ', keys(%{$self->{_recips}}));
1018 $self->{_vars}{recipients_del} = join(', ', keys(%{$self->{_del_tree}}));
1019 $self->{_vars}{recipients_undel} = join(', ', keys(%{$self->{_udel_tree}}));
1020 $self->{_vars}{recipients_undel_count} = scalar(keys(%{$self->{_udel_tree}}));
1021 $self->{_vars}{recipients_del_count} = 0;
1022 foreach my $r (keys %{$self->{_del_tree}}) {
1023 next if (!$self->{_recips}{$r});
1024 $self->{_vars}{recipients_del_count}++;
1029 return(0) if (!/^$/);
1031 # start reading headers
1032 while (read(I, $_, 3) == 3) {
1034 return(0) if (!length($t));
1035 while ($t =~ /^\d$/) {
1041 $t = getc(I); # strip the space out of the file
1042 return(0) if (read(I, $_, $hdr_bytes) != $hdr_bytes);
1043 if ($hdr_flag ne '*') {
1044 $self->{_vars}{message_linecount} += (tr/\n//);
1045 $self->{_vars}{message_size} += $hdr_bytes;
1048 # mark (rb)?header_ vars as existing and store raw value. They'll be
1049 # processed further in get_var() if needed
1050 my($v,$d) = split(/:/, $_, 2);
1051 $v = "header_" . lc($v);
1052 $self->{_vars}{$v} = $self->{_vars}{"b$v"} = $self->{_vars}{"r$v"} = undef;
1053 push(@{$self->{_vars_raw}{"r$v"}{vals}}, $d);
1054 $self->{_vars_raw}{"r$v"}{type} = $hdr_flag;
1055 $self->{_vars}{message_headers_raw} .= $_;
1059 $self->{_vars}{message_body_size} =
1060 (stat($self->{_path}.'/'.$self->{_message}.'-D'))[7] - 19;
1061 if ($self->{_vars}{message_body_size} < 0) {
1062 $self->{_vars}{message_size} = 0;
1063 $self->{_vars}{message_body_missing} = 1;
1065 $self->{_vars}{message_size} += $self->{_vars}{message_body_size} + 1;
1068 $self->{_vars}{message_linecount} += $self->{_vars}{body_linecount};
1070 my $i = $self->{_vars}{message_size};
1071 if ($i == 0) { $i = ""; }
1072 elsif ($i < 1024) { $i = sprintf("%d", $i); }
1073 elsif ($i < 10240) { $i = sprintf("%.1fK", $i / 1024); }
1074 elsif ($i < 1048576) { $i = sprintf("%dK", ($i+512)/1024); }
1075 elsif ($i < 10485760) { $i = sprintf("%.1fM", $i/1048576); }
1076 else { $i = sprintf("%dM", ($i + 524288)/1048576); }
1077 $self->{_vars}{shown_message_size} = $i;
1082 # mimic exim's host_extract_port function - receive a ref to a scalar,
1083 # strip it of port, return port
1084 sub _get_host_and_port {
1086 my $host = shift; # scalar ref, be careful
1088 if ($$host =~ /^\[([^\]]+)\](?:\:(\d+))?$/) {
1091 } elsif ($$host =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?:\.(\d+))?$/) {
1094 } elsif ($$host =~ /^([\d\:]+)(?:\.(\d+))?$/) {
1102 # honoring all formatting preferences, return a scalar variable of the
1103 # information for the single message matching what exim -bp would show.
1104 # We can print later if we want.
1105 sub format_message {
1108 return if ($self->{_delivered});
1110 # define any vars we want to print out for this message. The requests
1111 # can be regexps, and the defined vars can change for each message, so we
1112 # have to build this list for each message
1114 if (@{$self->{_show_vars}}) {
1116 foreach my $e (@{$self->{_show_vars}}) {
1117 foreach my $v ($self->get_matching_vars($e)) {
1118 next if ($t{$v}); $t{$v}++; push(@vars, $v);
1123 if ($self->{_output_idonly}) {
1124 $o .= $self->{_message};
1125 foreach my $v (@vars) { $o .= " $v='" . $self->get_var($v) . "'"; }
1128 } elsif ($self->{_output_vars_only}) {
1129 foreach my $v (@vars) { $o .= $self->get_var($v) . "\n"; }
1133 if ($self->{_output_long} || $self->{_output_flatq}) {
1134 my $i = int($self->{_vars}{message_age} / 60);
1136 $i = int(($i+30)/60);
1137 if ($i > 72) { $o .= sprintf "%2dd ", int(($i+12)/24); }
1138 else { $o .= sprintf "%2dh ", $i; }
1139 } else { $o .= sprintf "%2dm ", $i; }
1141 if ($self->{_output_flatq} && @vars) {
1142 $o .= join(';', map { "$_='".$self->get_var($_)."'" } (@vars)
1145 $o .= sprintf "%5s", $self->{_vars}{shown_message_size};
1149 $o .= "$self->{_message} ";
1150 $o .= "From: " if ($self->{_output_brief});
1151 $o .= "<$self->{_vars}{sender_address}>";
1153 if ($self->{_output_long}) {
1154 $o .= " ($self->{_vars}{originator_login})"
1155 if ($self->{_vars}{sender_set_untrusted});
1157 # XXX exim contains code here to print spool format errors
1158 $o .= " *** frozen ***" if ($self->{_vars}{deliver_freeze});
1161 foreach my $v (@vars) {
1162 $o .= sprintf " %25s = '%s'\n", $v, $self->get_var($v);
1165 foreach my $r (keys %{$self->{_recips}}) {
1166 next if ($self->{_del_tree}{$r} && $self->{_undelivered_only});
1167 $o .= sprintf " %s %s\n", $self->{_del_tree}{$r} ? "D" : " ", $r;
1169 if ($self->{_show_generated}) {
1170 foreach my $r (keys %{$self->{_del_tree}}) {
1171 next if ($self->{_recips}{$r});
1172 $o .= sprintf " +D %s\n", $r;
1175 } elsif ($self->{_output_brief}) {
1177 foreach my $r (keys %{$self->{_recips}}) {
1178 next if ($self->{_del_tree}{$r});
1181 $o .= " To: " . join(';', @r);
1182 if (scalar(@vars)) {
1183 $o .= " Vars: ".join(';',map { "$_='".$self->get_var($_)."'" } (@vars));
1185 } elsif ($self->{_output_flatq}) {
1186 $o .= " *** frozen ***" if ($self->{_vars}{deliver_freeze});
1188 foreach my $r (keys %{$self->{_recips}}) {
1189 next if ($self->{_del_tree}{$r});
1192 $o .= " " . join(' ', @r);
1201 my $fh = shift || \*STDOUT;
1202 return if ($self->{_delivered});
1204 print $fh $self->format_message();
1210 foreach my $k (sort keys %$self) {
1211 my $r = ref($self->{$k});
1212 if ($r eq 'ARRAY') {
1213 printf "%20s <<EOM\n", $k;
1214 print @{$self->{$k}}, "EOM\n";
1215 } elsif ($r eq 'HASH') {
1216 printf "%20s <<EOM\n", $k;
1217 foreach (sort keys %{$self->{$k}}) {
1218 printf "%20s %s\n", $_, $self->{$k}{$_};
1222 printf "%20s %s\n", $k, $self->{$k};
1230 if ($ARGV[0] =~ /^--help$/i) {
1232 $ENV{PATH} .= ":" unless $ENV{PATH} eq "";
1233 $ENV{PATH} = "$ENV{PATH}$Config::Config{'installscript'}";
1234 #exec("perldoc", "-F", "-U", $0) || exit 1;
1235 $< = $> = 1 if ($> == 0 || $< == 0);
1236 exec("perldoc", $0) || exit 1;
1238 %Config::Config = ();
1239 } elsif ($ARGV[0] =~ /^--version$/i) {
1240 print "$p_name version $p_version\n\n$p_cp\n";
1252 exipick - selectively display messages from an Exim queue
1256 exipick [<options>] [<criterion> [<criterion> ...]]
1260 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.
1264 Delete every frozen message from queue:
1265 exipick -zi | xargs exim -Mrm
1267 Show only messages which have not yet been virus scanned:
1268 exipick '$received_protocol ne virus-scanned'
1270 Run the queue in a semi-random order:
1271 exipick -i --random | xargs exim -M
1273 Show the count and total size of all messages which either originated from localhost or have a received protocol of 'local':
1274 exipick --or --size --bpc \
1275 '$sender_host_address eq 127.0.0.1' \
1276 '$received_protocol eq local'
1278 Display all messages received on the MSA port, ordered first by the sender's email domain and then by the size of the emails:
1279 exipick --sort sender_address_domain,message_size \
1280 '$received_port == 587'
1282 Display only messages whose every recipient is in the example.com domain, also listing the IP address of the sending host:
1283 exipick --show-vars sender_host_address \
1284 '$each_recipients = example.com'
1286 Same as above, but show values for all defined variables starting with sender_ and the number of recipients:
1287 exipick --show-vars ^sender_,recipients_count \
1288 '$each_recipients = example.com'
1296 Display messages matching all criteria (default)
1300 Display messages in brief format (exiqgrep)
1304 Display messages in standard mailq format (default)
1308 Same as -bp, show generated addresses also (exim)
1312 Show a count of matching messages (exim)
1316 Same as '-bp --unsorted' (exim)
1320 Same as '-bpr --unsorted' (exim)
1324 Same as '-bpu --unsorted' (exim)
1328 Same as -bp, but only show undelivered messages (exim)
1332 Show a count of matching messages (exiqgrep)
1336 Make operators involving '=' honor case
1340 Override the default local character set for $header_ decoding
1344 Same as '$sender_address = <regexp>' (exiqgrep)
1348 Use a single-line output format
1350 =item --freeze <cache file>
1352 Save queue information in an quickly retrievable format
1360 Display only the message IDs (exiqgrep)
1364 Same as -bp (exiqgrep)
1372 Same as '$message_age > <seconds>' (exiqgrep)
1376 Display messages matching any criteria
1380 Same as --reverse (exiqgrep)
1384 Same as '$recipients = <regexp>' (exiqgrep)
1388 Display messages in random order
1392 Display messages in reverse order
1396 Same as '$shown_message_size eq <string>' (exiqgrep)
1398 =item --spool <path>
1400 Set the path to the exim spool to use
1404 Show the internal representation of each criterion specified
1408 Show the result of each criterion on each message
1410 =item --show-vars <variable>[,<variable>...]
1412 Show the value for <variable> for each displayed message. <variable> will be a regular expression if it begins with a circumflex.
1416 Show the total bytes used by each displayed message
1418 =item --thaw <cache file>
1420 Read queue information cached from a previous --freeze run
1422 =item --sort <variable>[,<variable>...]
1424 Display matching messages sorted according to <variable>
1428 Do not apply any sorting to output
1432 Display the version of this command
1436 Same as '!$deliver_freeze' (exiqgrep)
1440 Same as '$message_age < <seconds>' (exiqgrep)
1444 Same as '$deliver_freeze' (exiqgrep)
1450 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.
1452 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.
1454 See the VARIABLES and OPERATORS sections below for more details
1462 Boolean variables are checked simply by being true or false. There is no real operator except negation. Examples of valid boolean tests:
1468 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 mulitplied by 86400, 3600, 60, 1, 1048576, 1024, or 1 respectively. Examples of valid numeric tests:
1469 '$message_age >= 3d'
1470 '$local_interface == 587'
1471 '$message_size < 30K'
1475 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:
1476 '$received_protocol eq esmtp'
1477 '$sender_address = example.com'
1478 '$each_recipients =~ /^a[a-z]{2,3}@example.com$/'
1482 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 equivilant to adding a ! to the beginning of every test.
1488 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.
1490 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.
1493 B - Boolean variables
1494 S - String variables
1495 N - Numeric variables
1496 . - Standard variable matching Exim's content definition
1497 # - Standard variable, contents differ from Exim's definition
1498 + - Non-standard variable
1502 =item S . $acl_c0-$acl_c9, $acl_m0-$acl_m9
1504 User definable variables.
1506 =item B + $allow_unqualified_recipient
1508 TRUE if unqualified recipient addresses are permitted in header lines.
1510 =item B + $allow_unqualified_sender
1512 TRUE if unqualified sender addresses are permitted in header lines.
1514 =item S . $authenticated_id
1516 Optional saved information from authenticators, or the login name of the calling process for locally submitted messages.
1518 =item S . $authenticated_sender
1520 The value of AUTH= param for smtp messages, or a generated value from the calling processes login and qualify domain for locally submitted messages.
1522 =item S . $bheader_*, $bh_*
1524 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.
1526 =item S + $bmi_verdicts
1528 The verdict string provided by a Brightmail content scan
1530 =item N . $body_linecount
1532 The number of lines in the message's body.
1534 =item N . $body_zerocount
1536 The number of binary zero bytes in the message's body.
1538 =item B + $deliver_freeze
1540 TRUE if the message is currently frozen.
1542 =item N + $deliver_frozen_at
1544 The epoch time at which message was frozen.
1546 =item B + $dont_deliver
1548 TRUE if, under normal circumstances, Exim will not try to deliver the message.
1550 =item S + $each_recipients
1552 This is a psuedo 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.
1554 =item S + $each_recipients_del
1556 Like $each_recipients, but for $recipients_del
1558 =item S + $each_recipients_undel
1560 Like $each_recipients, but for $recipients_undel
1562 =item B . $first_delivery
1564 TRUE if the message has never been deferred.
1566 =item S . $header_*, $h_*
1568 This will always match the contents of the corresponding $bheader_* variable currently (the same behaviour Exim displays when iconv is not installed).
1570 =item B . $host_lookup_deferred
1572 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.
1574 =item B . $host_lookup_failed
1576 TRUE if there was an attempt to look up the host's name from its IP address, but the attempt returned a negative result.
1578 =item B + $local_error_message
1580 TRUE if the message is a locally-generated error message.
1582 =item S . $local_scan_data
1584 The text returned by the local_scan() function when a message is received.
1586 =item B . $manually_thawed
1588 TRUE when the message has been manually thawed.
1590 =item N . $message_age
1592 The number of seconds since the message was received.
1594 =item S # $message_body
1596 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.
1598 =item B + $message_body_missing
1600 TRUE is a message's spool data file (-D file) is missing or unreadable.
1602 =item N . $message_body_size
1604 The size of the body in bytes.
1606 =item S . $message_exim_id, $message_id
1608 The unique message id that is used by Exim to identify the message. $message_id is deprecated as of Exim 4.53.
1610 =item S . $message_headers
1612 A concatenation of all the header lines except for lines added by routers or transports. RFC2047 decoding is performed
1614 =item S . $message_headers_raw
1616 A concatenation of all the header lines except for lines added by routers or transports. No decoding or translation is performed.
1618 =item N . $message_linecount
1620 The number of lines in the entire message (body and headers).
1622 =item N . $message_size
1624 The size of the message in bytes.
1626 =item N . $originator_gid
1628 The group id under which the process that called Exim was running as when the message was received.
1630 =item S + $originator_login
1632 The login of the process which called Exim.
1634 =item N . $originator_uid
1636 The user id under which the process that called Exim was running as when the message was received.
1638 =item S . $received_ip_address, $interface_address
1640 The address of the local IP interface for network-originated messages. $interface_address is deprecated as of Exim 4.64
1642 =item N . $received_port, $interface_port
1644 The local port number if network-originated messages. $interface_port is deprecated as of Exim 4.64
1646 =item N . $received_count
1648 The number of Received: header lines in the message.
1650 =item S . $received_protocol
1652 The name of the protocol by which the message was received.
1654 =item N . $received_time
1656 The epoch time at which the message was received.
1658 =item S # $recipients
1660 The list of envelope recipients for a message. Unlike Exim's version, this variable always contains every recipient of the message. The recipients are seperated by a comma and a space. See also $each_recipients.
1662 =item N . $recipients_count
1664 The number of envelope recipients for the message.
1666 =item S + $recipients_del
1668 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.
1670 =item N + $recipients_del_count
1672 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.
1674 =item S + $recipients_undel
1676 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.
1678 =item N + $recipients_undel_count
1680 The number of envelope recipients for the message which have not yet been delivered.
1682 =item S . $reply_address
1684 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.
1686 =item S . $rheader_*, $rh_*
1688 The value of the message's header(s) with the same name. See section 11.5 of Exim's spec.txt for full description.
1690 =item S . $sender_address
1692 The sender's address that was received in the message's envelope. For bounce messages, the value of this variable is the empty string.
1694 =item S . $sender_address_domain
1696 The domain part of $sender_address.
1698 =item S . $sender_address_local_part
1700 The local part of $sender_address.
1702 =item S . $sender_helo_name
1704 The HELO or EHLO value supplied for smtp or bsmtp messages.
1706 =item S . $sender_host_address
1708 The remote host's IP address.
1710 =item S . $sender_host_authenticated
1712 The name of the authenticator driver which successfully authenticated the client from which the message was received.
1714 =item S . $sender_host_name
1716 The remote host's name as obtained by looking up its IP address.
1718 =item N . $sender_host_port
1720 The port number that was used on the remote host for network-originated messages.
1722 =item S . $sender_ident
1724 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.
1726 =item B + $sender_local
1728 TRUE if the message was locally generated.
1730 =item B + $sender_set_untrusted
1732 TRUE if the envelope sender of this message was set by an untrusted local caller.
1734 =item S + $shown_message_size
1736 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.
1738 =item S . $smtp_active_hostname
1740 The value of the active host name when the message was received, as specified by the "smtp_active_hostname" option.
1742 =item S . $spam_score
1744 The spam score of the message, for example '3.4' or '30.5'. (Requires exiscan or WITH_CONTENT_SCAN)
1746 =item S . $spam_score_int
1748 The spam score of the message, multiplied by ten, as an integer value. For instance '34' or '305'. (Requires exiscan or WITH_CONTENT_SCAN)
1750 =item B . $tls_certificate_verified
1752 TRUE if a TLS certificate was verified when the message was received.
1754 =item S . $tls_cipher
1756 The cipher suite that was negotiated for encrypted SMTP connections.
1758 =item S . $tls_peerdn
1760 The value of the Distinguished Name of the certificate if Exim is configured to request one
1762 =item N + $warning_count
1764 The number of delay warnings which have been sent for this message.
1772 =item EMAIL: proj-exipick@jetmore.net
1774 =item HOME: jetmore.org/john/code/#exipick