#!/usr/bin/perl use strict; use warnings; use Text::BarGraph; use List::Util; our $VERSION = 0.04; # Save optional folder my @fol = grep { /^\+/ } @ARGV; @ARGV = grep { $_ !~ /^\+/ } @ARGV if scalar @fol; # Set-up filter by sender use Getopt::Long; my($from, $notfrom); GetOptions ('from=s' => \$from, 'notfrom=s' => \$notfrom); foreach( $from, $notfrom ){ # Convert filter string into regexp $_ ? do { $_ =~ y/,/|/; $_ = qr/$_/ } : ($_ = ''); } # Collect data my @msg = qx`scan -format '%04(year{date})-%02(mon{date})-%02(mday{date})\t%(addr{from})' -header @ARGV @fol`; # Header info print shift(@msg); # Parse my(%Dsummary, %Ssummary, %details); foreach my $datum (@msg){ chomp($datum); my($date, $sender) = split/\t/, $datum; $Dsummary{$date}++; $Ssummary{$sender}++; $details{$sender}{$date}++; } printf("\n\%4i \UTotal\n", List::Util::sum(values(%Ssummary)) ); print Text::BarGraph->new()->graph(\%Dsummary); # Filter sub-graphs my @senders = keys %details; if( length($from) > 0 ){ @senders = grep {$_ =~ /$from/ } @senders } elsif( length($notfrom) > 0 ){ @senders = grep {$_ !~ /$notfrom/ } @senders } # Most prolific senders first, then alphabetically my $max = List::Util::max( values(%Dsummary) ); foreach ( sort {$Ssummary{$b} <=> $Ssummary{$a} || $a cmp $b } @senders ){ printf("\n%4i \L$_\n", $Ssummary{$_}); my $g = Text::BarGraph->new(); $g->max_data($max); print $g->graph($details{$_}); } __END__ =pod =head1 NAME mhisto - Generates text-based histograms of folder contents by sender =head1 SYNOPSIS mhisto [+folder] [B] [B<-file> F] [B<--from> addrs] FOLDER SPAM Thu, 20 Feb 2014 11:44:15 -0500 2014-02-14 (17) ######################### 2014-02-15 (21) ############################### 2014-02-16 (18) ########################### 2014-02-17 (32) ################################################ 2014-02-18 (25) ##################################### 2014-02-19 (22) ################################# 2014-02-20 (29) ########################################### 2014-02-21 ( 3) #### 2014-02-22 ( 1) # 3 belg4mit@ono.com 2014-02-13 ( 2) #### 2014-02-18 ( 1) ## 2 auto-invoice@quickbooks.com 2014-02-14 ( 2) #### [truncated] =head1 DESCRIPTION The per-sender graphs are scaled the same as the folder summary graph.. Sender graphs are sorted but prolificness then alphabetically. You may specify a comma or pipe-delimited list of address (substrings) to be used in a regular expression to limit the set of per-sender graphs to be printed. The switch may also be given as a negated form B<--notfrom>. If you wish to only produce the summary graph, supply a B<-from> switch with a substring that will not match any address such as I<@@> =head1 REQUIREMENTS L, L =head1 HISTORY =head2 0.01 First implementation =head2 0.02 Documentation =head2 0.03 Add filtering =head2 0.04 More documentation =cut