3 # Utility for searching and displaying queue information.
4 # Written by Matt Hubbard 15 August 2002
6 # Copyright (c) The Exim Maintainers 2021 - 2022
8 # Except when they appear in comments, the following placeholders in this
9 # source are replaced when it is turned into a runnable script:
17 # Routine for extracting the UTC timestamp from message ID
18 # lifted from eximstat utility
23 BEGIN { pop @INC if $INC[-1] eq '.' };
28 # Have this variable point to your exim binary.
29 my $exim = 'BIN_DIRECTORY/exim';
36 (0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, # 0-9
37 0,10,11,12,13,14,15,16,17,18,19,20, # A-K
38 21,22,23,24,25,26,27,28,29,30,31,32, # L-W
39 33,34,35, 0, 0, 0, 0, 0, # X-Z
40 0,36,37,38,39,40,41,42,43,44,45,46, # a-k
41 47,48,49,50,51,52,53,54,55,56,57,58, # l-w
45 if ($^O eq 'darwin') { # aka MacOS X
51 if ($ARGV[0] eq '--version') {
52 print basename($0) . ": $0\n",
53 "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION\n",
54 "perl(runtime): $]\n";
58 if (!getopts('hf:r:y:o:s:C:zxlibRcaG:E:',\%opt)) { &help; exit; }
59 if ($opt{h}) { &help; exit; }
60 if ($ARGV[0] || !($opt{f} || $opt{r} || $opt{s} || $opt{y} || $opt{o} || $opt{z} || $opt{x} || $opt{c}))
62 if ($opt{a}) { $eargs = '-bp'; }
63 if ($opt{C} && -e $opt{C} && -f $opt{C} && -R $opt{C}) { $eargs .= ' -C '.$opt{C}; }
64 if ($opt{G}) { $eargs .= ' -qG'.$opt{G}; }
65 if ($opt{E}) { $exim = $opt{E}; }
67 # Read message queue output into hash
69 # Identify which messages match selection criteria
71 # Print matching data according to display option.
78 Exim message queue display utility.
81 -C Specify which exim.conf to use.
82 -E Specify exim binary to use.
85 -f <regexp> Match sender address sender (field is "< >" wrapped)
86 -r <regexp> Match recipient address
87 -s <regexp> Match against the size field from long output
88 -y <seconds> Message younger than
89 -o <seconds> Message older than
90 -z Frozen messages only (exclude non-frozen)
91 -x Non-frozen messages only (exclude frozen)
92 -G <queuename> Match in given queue only
94 [ NB: for regexps, provided string sits in /<string>/ ]
97 -c Display match count
98 -l Long Format [Default]
102 -a All recipients (including delivered)
107 open(QUEUE,"$exim $eargs |") or die("Error opening pipe: $!\n");
111 #Should be 1st line of record, if not error.
112 if ($line =~ /^\s*(\w+)\s+((?:\d+(?:\.\d+)?[A-Z]?)?)\s*(\w{6}-\w{6}-\w{2})\s+(<.*?>)/) {
115 $id{$msg}{size} = $2;
116 $id{$msg}{from} = $4;
117 $id{$msg}{birth} = &msg_utc($msg);
118 $id{$msg}{ages} = time - $id{$msg}{birth};
119 if ($line =~ /\*\*\* frozen \*\*\*$/) {
120 $id{$msg}{frozen} = 1;
122 $id{$msg}{frozen} = 0;
124 while(<QUEUE> =~ /\s+(.*?\@.*)$/) {
125 push(@{$id{$msg}{rcpt}},$1);
127 # Increment message counter.
130 print STDERR "Line mismatch: $line\n"; exit 1;
133 close(QUEUE) or die("Error closing pipe: $!\n");
137 foreach my $msg (keys(%id)) {
139 # Match sender address
140 next unless ($id{$msg}{from} =~ /$opt{f}/i);
143 # Match any recipient address
145 foreach my $rcpt (@{$id{$msg}{rcpt}}) {
146 $match++ if ($rcpt =~ /$opt{r}/i);
148 next unless ($match);
151 # Match against the size string.
152 next unless ($id{$msg}{size} =~ /$opt{s}/);
156 next unless ($id{$msg}{ages} < $opt{y});
160 next unless ($id{$msg}{ages} > $opt{o});
164 next unless ($id{$msg}{frozen});
168 next if ($id{$msg}{frozen});
170 # Here's what we do to select the record.
171 # Should only get this far if the message passed all of
174 # Increment match counter.
181 printf("%d matches out of %d messages\n",$mcount,$count);
184 foreach my $msg (sort { $opt{R} ? $id{$b}{birth} <=> $id{$a}{birth} : $id{$a}{birth} <=> $id{$b}{birth} } keys(%id) ) {
185 if (exists($id{$msg}{d})) {
191 printf("%s From: %s To: %s\n",$msg,$id{$msg}{from},join(';',@{$id{$msg}{rcpt}}))
193 # Otherwise Long format attempted duplication of original format.
194 printf("%3s %5s %s %s%s\n",$id{$msg}{age},$id{$msg}{size},$msg,$id{$msg}{from},$id{$msg}{frozen} ? " *** frozen ***" : "");
195 foreach my $rcpt (@{$id{$msg}{rcpt}}) {
196 printf(" %s\n",$rcpt);
205 foreach my $msg (keys(%id)) {
206 print "$id{$msg}{birth} $msg\tAge: $id{$msg}{age}\tSize: $id{$msg}{size}\tFrom: $id{$msg}{from}\tTo: " . join(" ",@{$id{$msg}{rcpt}}). "\n";
211 my $id = substr((pop @_), 0, 6);
213 my @c = split(//, $id);
214 while($#c >= 0) { $s = $s * $base + $tab62[ord(shift @c) - ord('0')] }