JFIF$        dd7 

Viewing File: /usr/sbin/exiqgrep

#!/usr/local/cpanel/3rdparty/perl/542/bin/perl

# Utility for searching and displaying queue information.
# Written by Matt Hubbard 15 August 2002
#
# Copyright (c) The Exim Maintainers 2021 - 2025
# SPDX-License-Identifier: GPL-2.0-or-later
# See the file NOTICE for conditions of use and distribution.

# Except when they appear in comments, the following placeholders in this
# source are replaced when it is turned into a runnable script:
#
# BIN_DIRECTORY
# PERL_COMMAND
# MSGID_RE

# This file has been so processed.


# Routine for extracting the UTC timestamp from message ID
# lifted from eximstat utility

# Version 1.4

use strict;
BEGIN { pop @INC if $INC[-1] eq '.' };

use Getopt::Std;
use File::Basename;

# Insert MSGID_RE
# Start msgid.frag
# Copyright (c) The Exim Maintainers 2025
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Regex patterns for exim message-id

# Simple matching

my $b62 = "[[:alnum:]]";

my $msgid_sec_re = "${b62}{6}";
my $msgid_pid_new_re = "${b62}{11}";
my $msgid_pid_old_re = "${b62}{6}";
my $msgid_frc_new_re = "${b62}{4}";
my $msgid_frc_old_re = "${b62}{2}";

my $msgid_new_re = "$msgid_sec_re-$msgid_pid_new_re-$msgid_frc_new_re";
my $msgid_old_re = "$msgid_sec_re-$msgid_pid_old_re-$msgid_frc_old_re";
my $msgid_re =     "(?:$msgid_new_re|$msgid_old_re)";


# Match with content submatches
# - requires variables seconds, pid, fractions

my $msgid_sec_cap_re = "(?<seconds>$msgid_sec_re)";
my $msgid_pid_cap_re = "(?<pid>(?:$msgid_pid_new_re|$msgid_pid_old_re))";
my $msgid_frc_cap_re = "(?<fractions>(?:$msgid_frc_new_re|$msgid_frc_old_re))";

my $msgid_cap_re = "(?:$msgid_sec_cap_re-$msgid_pid_cap_re-$msgid_frc_cap_re)";

# End msgid.frag

# Have this variable point to your exim binary.
my $exim = '/usr/sbin/exim';
my $eargs = '-bpu';
my %id;
my %opt;
my $count = 0;
my $mcount = 0;
my @tab62 =
  (0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,     # 0-9
   0,10,11,12,13,14,15,16,17,18,19,20,  # A-K
  21,22,23,24,25,26,27,28,29,30,31,32,  # L-W
  33,34,35, 0, 0, 0, 0, 0,              # X-Z
   0,36,37,38,39,40,41,42,43,44,45,46,  # a-k
  47,48,49,50,51,52,53,54,55,56,57,58,  # l-w
  59,60,61);                            # x-z

my $base;
if ($^O eq 'darwin') { # aka MacOS X
  $base = 36;
 } else {
  $base = 62;
};

if ($ARGV[0] eq '--version' || $ARGV[0] eq '-v') {
    print basename($0) . ": $0\n",
        "build: 4.99\n",
        "perl(runtime): $]\n";
        exit 0;
}

if (!getopts('hf:r:y:o:s:C:zxlibRcaG:E:',\%opt)) { &help; exit; }
if ($opt{h}) { &help; exit; }
if ($ARGV[0] || !($opt{f} || $opt{r} || $opt{s} || $opt{y} || $opt{o} || $opt{z} || $opt{x} || $opt{c}))
   { &help; exit(1); }
if ($opt{a}) { $eargs = '-bp'; }
if ($opt{C} && -e $opt{C} && -f $opt{C} && -R $opt{C}) { $eargs .= ' -C '.$opt{C}; }
if ($opt{G}) { $eargs .= ' -qG'.$opt{G}; }
if ($opt{E}) { $exim = $opt{E}; }

# Read message queue output into hash
&collect();
# Identify which messages match selection criteria
&selection();
# Print matching data according to display option.
&display();
exit;


sub help() {
	print <<'EOF'
Exim message queue display utility.

	-h		This help message.
	-C		Specify which exim.conf to use.
	-E		Specify exim binary to use.

Selection criteria:
	-f <regexp>	Match sender address sender (field is "< >" wrapped)
	-r <regexp>	Match recipient address
	-s <regexp>	Match against the size field from long output
	-y <seconds>	Message younger than
	-o <seconds>	Message older than
	-z		Frozen messages only (exclude non-frozen)
	-x		Non-frozen messages only (exclude frozen)
	-G <queuename>	Match in given queue only

[ NB: for regexps, provided string sits in /<string>/ ]

Display options:
	-c		Display match count
	-l		Long Format [Default]
	-i		Message IDs only
	-b		Brief Format
	-R		Reverse order
	-a		All recipients (including delivered)
EOF
}

sub collect() {
	open(QUEUE,"$exim $eargs |") or die("Error opening pipe: $!\n");
	while(<QUEUE>) {
		chomp();
		my $line = $_;
		#Should be 1st line of record, if not error.
		if ($line =~ /^\s*(?<age>\w+)
			      \s+(?<size>(?:\d+(?:\.\d+)?[A-Z]?)?)
			      \s*(?<msgid>$msgid_re)
			      \s+(?<from><.*?>)/x) {
			my $msg = $+{msgid};
			$id{$msg}{age} = $+{age};
			$id{$msg}{size} = $+{size};
			$id{$msg}{from} = $+{from};
			$id{$msg}{birth} = &msg_utc($msg);
			$id{$msg}{ages} = time - $id{$msg}{birth};
			$id{$msg}{frozen} = ($line =~ /\*\*\* frozen \*\*\*$/) ? 1 : 0;
			while(<QUEUE> =~ /\s+(.*?\@.*)$/) {
				push(@{$id{$msg}{rcpt}},$1);
			}
			# Increment message counter.
			$count++;
		} else {
			print STDERR "Line mismatch: $line\n"; exit 1;
		}
	}
	close(QUEUE) or die("Error closing pipe: $!\n");
}

sub selection() {
	foreach my $msg (keys(%id)) {
		if ($opt{f}) {
			# Match sender address
			next unless ($id{$msg}{from} =~ /$opt{f}/i);
		}
		if ($opt{r}) {
			# Match any recipient address
			my $match = 0;
			foreach my $rcpt (@{$id{$msg}{rcpt}}) {
				$match++ if ($rcpt =~ /$opt{r}/i);
			}
			next unless ($match);
		}
		if ($opt{s}) {
			# Match against the size string.
			next unless ($id{$msg}{size} =~ /$opt{s}/);
		}
		if ($opt{y}) {
			# Match younger than
			next unless ($id{$msg}{ages} < $opt{y});
		}
		if ($opt{o}) {
			# Match older than
			next unless ($id{$msg}{ages} > $opt{o});
		}
		if ($opt{z}) {
			# Exclude non frozen
			next unless ($id{$msg}{frozen});
		}
		if ($opt{x}) {
			# Exclude frozen
			next if ($id{$msg}{frozen});
		}
		# Here's what we do to select the record.
		# Should only get this far if the message passed all of
		# the active tests.
		$id{$msg}{d} = 1;
		# Increment match counter.
		$mcount++;
	}
}

sub display() {
	if ($opt{c}) {
		printf("%d matches out of %d messages\n",$mcount,$count);
		exit;
	}
	foreach my $msg (sort { $opt{R} ? $id{$b}{birth} <=> $id{$a}{birth} : $id{$a}{birth} <=> $id{$b}{birth} } keys(%id) ) {
		if (exists($id{$msg}{d})) {
			if ($opt{i}) {
				# Just the msg ID
				print $msg, "\n";
			} elsif ($opt{b}) {
				# Brief format
				printf("%s From: %s To: %s\n",$msg,$id{$msg}{from},join(';',@{$id{$msg}{rcpt}}))
			} else {
				# Otherwise Long format attempted duplication of original format.
				printf("%3s %5s %s %s%s\n",$id{$msg}{age},$id{$msg}{size},$msg,$id{$msg}{from},$id{$msg}{frozen} ? " *** frozen ***" : "");
				foreach my $rcpt (@{$id{$msg}{rcpt}}) {
					printf("	  %s\n",$rcpt);
				}
				print "\n";
			}
		}
	}
}

sub report() {
	foreach my $msg (keys(%id)) {
		print "$id{$msg}{birth} $msg\tAge: $id{$msg}{age}\tSize: $id{$msg}{size}\tFrom: $id{$msg}{from}\tTo: " . join(" ",@{$id{$msg}{rcpt}}). "\n";
	}
}

sub msg_utc() {
	my $id = substr((pop @_), 0, 6);
	my $s = 0;
	my @c = split(//, $id);
	while($#c >= 0) { $s = $s * $base + $tab62[ord(shift @c) - ord('0')] }
	return $s;
}

# vim:ft=perl:
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP A\ILNj!J۱+O\͔]ޒS߼Jȧc%ANolՎprULZԛerE2=XDXgVQeӓk yP7U*omQIs,K`)6\G3t?pgjrmۛجwluGtfh9uyP0D;Uڽ"OXlif$)&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