3 # Utility for searching and displaying queue information.
4 # Written by Matt Hubbard 15 August 2002
6 # Except when they appear in comments, the following placeholders in this
7 # source are replaced when it is turned into a runnable script:
15 # Routine for extracting the UTC timestamp from message ID
16 # lifted from eximstat utility
23 # Have this variable point to your exim binary.
24 my $exim = 'BIN_DIRECTORY/exim';
31 (0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, # 0-9
32 0,10,11,12,13,14,15,16,17,18,19,20, # A-K
33 21,22,23,24,25,26,27,28,29,30,31,32, # L-W
34 33,34,35, 0, 0, 0, 0, 0, # X-Z
35 0,36,37,38,39,40,41,42,43,44,45,46, # a-k
36 47,48,49,50,51,52,53,54,55,56,57,58, # l-w
40 if ($^O eq 'darwin') { # aka MacOS X
46 getopts('hf:r:y:o:s:C:zxlibRca',\%opt);
47 if ($opt{h}) { &help; exit;}
48 if ($opt{a}) { $eargs = '-bp'; }
49 if ($opt{C} && -e $opt{C} && -f $opt{C} && -R $opt{C}) { $eargs .= ' -C '.$opt{C}; }
51 # Read message queue output into hash
53 # Identify which messages match selection criteria
55 # Print matching data according to display option.
62 Exim message queue display utility.
65 -C Specify which exim.conf to use.
68 -f <regexp> Match sender address sender (field is "< >" wrapped)
69 -r <regexp> Match recipient address
70 -s <regexp> Match against the size field from long output
71 -y <seconds> Message younger than
72 -o <seconds> Message older than
73 -z Frozen messages only (exclude non-frozen)
74 -x Non-frozen messages only (exclude frozen)
76 [ NB: for regexps, provided string sits in /<string>/ ]
79 -c Display match count
80 -l Long Format [Default]
84 -a All recipients (including delivered)
89 open(QUEUE,"$exim $eargs |") or die("Error openning pipe: $!\n");
93 #Should be 1st line of record, if not error.
94 if ($line =~ /^\s*(\w+)\s+((?:\d+(?:\.\d+)?[A-Z]?)?)\s*(\w{6}-\w{6}-\w{2})\s+(<.*?>)/) {
99 $id{$msg}{birth} = &msg_utc($msg);
100 $id{$msg}{ages} = time - $id{$msg}{birth};
101 if ($line =~ /\*\*\* frozen \*\*\*$/) {
102 $id{$msg}{frozen} = 1;
104 $id{$msg}{frozen} = 0;
106 while(<QUEUE> =~ /\s+(.*?\@.*)$/) {
107 push(@{$id{$msg}{rcpt}},$1);
109 # Increment message counter.
112 print STDERR "Line mismatch: $line\n"; exit 1;
115 close(QUEUE) or die("Error closing pipe: $!\n");
119 foreach my $msg (keys(%id)) {
121 # Match sender address
122 next unless ($id{$msg}{from} =~ /$opt{f}/i);
125 # Match any recipient address
127 foreach my $rcpt (@{$id{$msg}{rcpt}}) {
128 $match++ if ($rcpt =~ /$opt{r}/i);
130 next unless ($match);
133 # Match against the size string.
134 next unless ($id{$msg}{size} =~ /$opt{s}/);
138 next unless ($id{$msg}{ages} < $opt{y});
142 next unless ($id{$msg}{ages} > $opt{o});
146 next unless ($id{$msg}{frozen});
150 next if ($id{$msg}{frozen});
152 # Here's what we do to select the record.
153 # Should only get this far if the message passed all of
156 # Increment match counter.
163 printf("%d matches out of %d messages\n",$mcount,$count);
166 foreach my $msg (sort { $opt{R} ? $id{$b}{birth} <=> $id{$a}{birth} : $id{$a}{birth} <=> $id{$b}{birth} } keys(%id) ) {
167 if (exists($id{$msg}{d})) {
173 printf("%s From: %s To: %s\n",$msg,$id{$msg}{from},join(';',@{$id{$msg}{rcpt}}))
175 # Otherwise Long format attempted duplication of original format.
176 printf("%3s %5s %s %s%s\n",$id{$msg}{age},$id{$msg}{size},$msg,$id{$msg}{from},$id{$msg}{frozen} ? " *** frozen ***" : "");
177 foreach my $rcpt (@{$id{$msg}{rcpt}}) {
178 printf(" %s\n",$rcpt);
187 foreach my $msg (keys(%id)) {
188 print "$id{$msg}{birth} $msg\tAge: $id{$msg}{age}\tSize: $id{$msg}{size}\tFrom: $id{$msg}{from}\tTo: " . join(" ",@{$id{$msg}{rcpt}}). "\n";
193 my $id = substr((pop @_), 0, 6);
195 my @c = split(//, $id);
196 while($#c >= 0) { $s = $s * $base + $tab62[ord(shift @c) - ord('0')] }