Contrib - single line mail queue printer in perl

this simple hacked script produces the queue with one line per message,
to allow you to do the equivalent of
	eximq1l | grep 'hotmail.com' | awk '{print $3}'
to extract the message IDs of interesting messages for nefarious purposes.



#!/opt/perl/bin/perl

open ( MQ, "/opt/exim/bin/exim -bp|") or die "can't run the exim command\n";


$state = 0;	# simple state machine
$recips = 0;
while ( <MQ> )
{
	$line = $_;
	chop $line;
	if ($state == 0)	# line read is the sender info
	{
		print "$line ";
		$state = 1;
		$recips = 0;
	}
	else			# line read is a recip
	{
		if ($line =~ /^$/)	# if blank, about to start new mail
		{
			$state = 0;
			print "\n";
		}
		else			# append recipient to line
		{
			if ($recips > 0)	# separate recipients with :
			{
				print ':';
			}
			if ($line =~ /^\s+\S\s+(.*)/)
			{
				print "$1";
			}
			elsif ($line =~ /^\s+(.*)/)
			{
				print "$1";
			}
			++$recips;
		}
	}
}

# end