QueuedByAddr

The following Perl script will show all queued mail by email address. A message may be counted more than once if it has multiple envelope recipients.
 * 1) !/usr/bin/perl

use strict;

my $mqueue_directory = "/var/spool/mqueue"; my %occurrences;

use File::Find; find(\&wanted, $mqueue_directory);
 * 1) Recursively find all files and directories in $mqueue_directory

sub wanted { # Is this a qf* file? if ( /^qf\w{14}/ ) { open (QF_FILE, $_); while() { # Lines beginning with R contain an envelope recipient if ( /^R.*:<(.*)>$/ ) { my $domain = lc($1); # Add 1 to the %occurrences hash $occurrences{$domain}++; }     }   } }

sub hashValueAscendingNum { $occurrences{$a} <=> $occurrences{$b}; }
 * 1) Subroutine to sort hash by ascending value

foreach my $key (sort hashValueAscendingNum (keys(%occurrences))) { print "$occurrences{$key} $key\n"; }
 * 1) Print sorted results