statmail

General | Documentation | Download | License | Contact

General information

statmail is a procmail log analyzer, implemented as a drop-in replacement for the mailstat log analyzer that comes with the procmail MDA: it computes aggregated data from a procmail log file.

Here is what motivated me to write statmail:

  1. One day, mailstat failed on me in some unexplained way, although the log file that looked fine;
  2. mailstat has some potentially dangerous features — by default, it deletes the logfile after analyzing it;
  3. the source of mailstat challenged me to write such a script by myself.

As a bonus, statmail appears to be faster than the original. Tested on my logfile for September 2004, the programs had the following execution times:

mailstat: 1.93user 0.03system 0:01.98elapsed 98%CPU
statmail: 0.53user 0.00system 0:00.52elapsed 100%CPU
      

Documentation

Configuration of procmail

First of all, one needs to ask procmail to gather some data about the mail it delivers. Thus, your procmailrc file may start in the following way:

# $Id: procmailrc,v 1.37 2004/09/28 13:36:59 homer Exp $

MAILDIR=/var/mail/homer/Maildir/
DEFAULT=$MAILDIR
SHELL=/bin/sh
LOGFILE=$HOME/.logs/procmail-`date +%Y-%m`.log
COMSAT=off
# VERBOSE=yes

# Keep a copy of everything
:0 c:
/archive/homer/backup/mailbox
      

That is, you should set LOGFILE, but should not use the verbose logging mode (the relevant line is the one that which starts with LOGFILE=). By the way, and this has nothing to do with statmail in particular, it is probably a good idea to keep a copy of all your incoming mail before sorting it. This is to stay on the safe side: the day that the disks that hold your homedir crashes and you lose a few hours of updates, or if you mess up part of your init file, you will be happy to have an up-to-date version of your mailbox (that is, if your homedir and the mail spool are on separate disks; but this generally the case).

Invocation

The output of statmail cannot be customized, and is approximately equivalent to the output of statmail -klm — except faster, and with wide enough columns to contain the octet size of mailboxes from the early 2000s (the columns will overflow after nine decimal digits, however).

Thus, the only needed argument is the path of your logfile. Actually, it isn't required; you can just pipe the log into statmail. And, thanks to the wonderfully permissive syntax of Perl, you can pass an arbitrary number of logfiles as arguments. An example, valid in bash and if you use time-stamped logs like I do:

$ statmail <~/.logs/procmail-$(date +%Y-%m).log

Sample logfile excerpt

For reference, here is what the logfiles look like. One can guess that extracting size and folder name from such a file is not a very challenging task with a language —like Perl— that provides PCREs.

From root@edcsm.jussieu.fr  Wed Sep  1 00:04:24 2004
 Subject: Cron <haguenau@isis2> $HOME/bin/loadavgsto >> $HOME/.logs/keruload-is
  Folder: /dev/null							   2444
From linux-kernel-owner@vger.kernel.org  Wed Sep  1 00:07:21 2004
 Subject: Re: PATCH: Root reservations for strict overcommit
  Folder: bots/lkml/new/_oiB+ZaPNBB.homer				   3957
From linux-kernel-owner@vger.kernel.org  Wed Sep  1 00:07:22 2004
 Subject: Re: [patch] voluntary-preempt-2.6.9-rc1-bk4-Q5
  Folder: bots/lkml/new/_7iB+aaPNBB.homer				   4004
From linux-kernel-owner@vger.kernel.org  Wed Sep  1 00:07:25 2004
 Subject: Re: [patch] voluntary-preempt-2.6.9-rc1-bk4-Q5
  Folder: bots/lkml/new/_ejB+daPNBB.homer				   3656
  

Sample output ("screenshot")

Here is the output of statmail when asked to process my log for September 2004. Some of the entries have been obfuscated to protect the innocent passerby. From this report, it is obvious that the O'Caml list and the Mutt lists have about the same amount of traffic, but that reading the Linux kernel mailing list is quite a time-consuming task.

    Total   Average    Number Folder
--------- --------- --------- ----------------
 10201225      2427      4203 /dev/null
    36597      9149         4 bots/amz
   872416     15041        58 bots/bots
  2719762      4918       553 bots/caml
   171389      2856        60 bots/cron
    39539      4942         8 bots/dea
    17384     17384         1 bots/dnrc
   261351      8711        30 bots/du821
   987123      7050       140 bots/error
    46874      5208         9 bots/icfp-penn
   146885      7344        20 bots/imdb
   172575      3451        50 bots/inria
    85902      4295        20 bots/lip6
 55015526      6011      9152 bots/lkml
   484280      6372        76 bots/misc
  1681735      3866       435 bots/mutt
   185262      3632        51 bots/sylph
   842246      5433       155 bots/vg
    30152      5025         6 in
    31624      2635        12 local/sentbcc
   959652     10318        93 news/inria
     2805      2805         1 news/news
     9600      1920         5 per/—
    51396      3023        17 per/—
    22756      2275        10 per/—
    29138      3642         8 per/—
    45711      2176        21 per/—
     7747      2582         3 per/—
     3704      3704         1 per/—
    43467      2716        16 per/—
  3022458      5122       590 trash/spam
   495474     41289        12 trash/virus
    19344      3224         6 trash/wrway
--------- --------- --------- ----------------
 78743099      4975     15826 
      

Bugs

Please note that this script has received little testing outside of the following configurations:

In particular, configurations using the MH format have not been tested. Explicit support for the MH format may be added if there is sufficient demand. Reports of success or failure on other setups are welcome.

Distribution ("distribution")

This project is graciously hosted by SourceForge.net. You can go to the statmail project page to access all statmail-related resources, which include:

This program is implemented as a single Perl source file which you can install manually anywhere you like: for a system-wide installation on a Unix system, this may be as simple as:

$ su -c 'cp statmail /usr/local/bin/'

Detailed instructions for accessing the CVS repository are given on the project page at SourceForge.net.

License

statmail is free software and is released under the terms of the GNU GPL.

Contact

Contact address, bug reports, praise: David Haguenauer.


SourceForge.net Logo Valid XHTML 1.1! Valid CSS 2.1!

$Id: index.html,v 1.23 2007/08/28 22:34:33 dhag Exp $ - www.kurokatta.org home