Quick and dirty current inbox stats:

Inbox: ($unread)/$total messages “; print ‘Size: ‘ . sprintf(‘%.1f’, $size/1024) . ‘ MiB

‘;
?>

Here’s the code that generates the text file which I simply read with file() and then split:

#!/bin/sh
echo time,`date +%s`;
echo inbox.total,`ls /home/lhl/Maildir/cur/ | wc -l`
echo inbox.unread,`ls /home/lhl/Maildir/cur/ | grep -v 'S' | wc -l`
echo inbox.size,`du -s /home/lhl/Maildir/cur/ | cut -f1`

Alternatives for keeping detailed mail stats:

  • Use procmail log tool (mailstat, fm.pl) in cron, possibly graph to RRDTool? (see Mailgraph)
  • Use Mail::Graph or other Perl-based solution
  • Log to MySQL schema: total(timestamp, folder, unread, total, size)

Ideally, I’d want to be able to do minute-by-minute graphing of individual mailboxes to see trends. Would be interesting to generate a Filelight-like display as well as to try to map time-based changes (perhaps in 3D?).

What I’ll probably do I’ve done:

  • Pulling Inbox info (total, unread, size) from cron every minute
  • Dumping Inbox information into MySQL table every 10 minutes
  • Processing daily procmail log from cron every minute
  • Rotating procmail log stats into MySQL table at midnight

Getting totals should be as easy as running a SUM() on the mail_daily table. The mail_folders is currently only watching the inbox, but could easily be expanded. (These tables should really be called mail_incoming and mail_totals to better describe how their different, but whatever).