Mail-Graph
view release on metacpan or search on metacpan
lib/Mail/Graph.pm view on Meta::CPAN
return;
}
sub _save_chart
{
my $self = shift;
my $chart = shift or die "Need a chart!";
my $name = shift or die "Need a name!";
local(*OUT);
my $ext = $self->{_options}->{graph_ext} || $chart->export_format();
open(OUT, ">$name.$ext") or
die "Cannot open $name.$ext for write: $!";
binmode OUT;
print OUT $chart->gd->$ext();
close OUT;
}
1;
__END__
###############################################################################
###############################################################################
=pod
=head1 NAME
Mail::Graph - draw graphical stats for mails/spams
=head1 SYNOPSIS
use Mail::Graph;
$graph = Mail::Graph->new( items => 'spam',
output => 'spams/',
input => '~/Mail/spam/',
);
$graph->generate();
=head1 DESCRIPTION
This module parses mailbox files in either compressed or uncompressed form
and then generates pretty statistics and graphs about them. Although at first
developed to do spam statistics, it works just fine for normal mail.
=head2 File Format
The module reads in files in mbox format. These can be compressed by gzip,
or just plain text. Since the module read in any files that are in one
directory, it can also handle mail-dir style folders, e.g. a directory where
each mail resides in an extra file.
The file format is quite simple and looks like this:
From sample_foo@example.com Tue Oct 27 18:38:52 1998
Received: from barfel by foo.example.com (8.9.1/8.6.12)
From: forged_bar@example.com
X-Envelope-To: <sample_foo@example.com>
Date: Tue, 27 Oct 1998 09:52:14 +0100 (CET)
Message-Id: <199810270852.12345567@example.com>
To: <none@example.com>
Subject: Sorry...
X-Loop-Detect: 1
X-Spamblock: caught by rule dummy@
This is a sample spam
Basically, an email header plus email body, separated by the C<From> lines.
The following fields are examined to determine:
X-Envelope-To the target address/domain
From address@domain the sender
From date the receiving date
=head1 METHODS
=head2 new()
Create a new Mail::Graph object.
The following options exist:
input Path to a directory containing (gzipped) mbox files
Alternatively, name of an (gzipped) mbox file
index Directory where to write (and read) the index files
output Directory where to write the output stats
items Try 'spams' or 'mails' (can be any string)
generate hash with names of stats to generate (1=on, 0=off):
month per each month of the year
day per each day of the month
hour per each hour of the day
dow per each day of the week
yearly per year
daily per each day (with average)
monthly per each month
toplevel per top_level domain
rule per filter rule that matched
target per target address
domain per target domain
last_x_days items for each of the last x days
set it to the number of days you want
score_histogram show histogram of SpamAssassin scores
set it to the step-width (like 5)
score_daily SA score for each of the last x days
set it to the number of days you want
score_scatter SA scatter score diagram, set it to
the limit of the score (a line will be
draw there)
average set to 0 to disable, otherwise it gives the number
of days/weeks/month to average over
average_daily if not set, uses average, 0 to disable
number of days to average over in the daily graph
height base height of the generated images
template name of the template file (ending in .tpl) that is
used to generate the html output, e.g. 'index.tpl'
no_title set to 1 to disable graph titles, default 0
filter_domains array ref with list of domains to show as "unknown"
filter_target array ref with list of targets (regualr expressions)
( run in 1.397 second using v1.01-cache-2.11-cpan-e1769b4cff6 )