APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Perl 'kreport' gives details on Kerio Connect Store usage


A Kerio Connect administrator was recently surprised to find that one user had two Draft messages with large attachments that consumed over a gigabyte of storage by themselves. By itself, that's not necessarily a problem - such messages should be sent by FTP or Dropbox or stored in Kerio Workspace, Google Docs or similar places, but they aren't causing any real problem just sitting there. However, large files like that do add to total disk space used and increase the time needed to make full backups.

So how do you find silly things like that? The Kerio administration console can give you some information about users, but it doesn't actually count everything and it doesn't give any details. You can look at your Store directory using your computer operating system, but that gives you too much information. Wouldn't it be nice to have something a little better?

User usage from Kerio Admin

Kreport Perl Script

How about something that could give you this for every user in your domains?

- aplawrence.com/sales-support 6 messages 6.25 Mbytes all told, 5.91
Mbytes in .eml's: Largest directory #deleted/#msgs has 5 messages
and is 5.91 Mbytes.  Largest mail message #deleted/#msgs/0000014f.eml
is 1.49 Mbytes

- aplawrence.com/tony 7,810 messages 494.58 Mbytes all told,
360.43 Mbytes in .eml's: Largest directory INBOX/#msgs has
2,447 messages and is 161.31 Mbytes.  Largest mail message
INBOX/2012_06_30/#msgs/0000cd24.eml is 10.72 Mbytes

And if you wanted even more detail, would this help?

kreport tony
aplawrence.com tony
- - aplawrence.com/tony/Sent Items/#msgs 63 messages 0.99 Mbytes
- - aplawrence.com/tony/Deleted Items/#msgs 22 messages 4.37 Mbytes
- - aplawrence.com/tony/Apl RSS/#msgs 2 messages 0.02 Mbytes
- - aplawrence.com/tony/Apl RSS/#assoc 1 messages 0.00 Mbytes
- - aplawrence.com/tony/Apl RSS 1 messages 0.02 Mbytes
- - aplawrence.com/tony/#deleted/#msgs 1973 messages 73.29 Mbytes
- - aplawrence.com/tony/INBOX/2012_06_30/#msgs 1303 messages 79.04 Mbytes
- - aplawrence.com/tony/INBOX/#msgs 2447 messages 161.31 Mbytes
- - aplawrence.com/tony/INBOX/#assoc 8 messages 0.00 Mbytes
- - aplawrence.com/tony/Junk E-mail/#msgs 1591 messages 41.31 Mbytes
- - aplawrence.com/tony/__keriomapi__STORE/__keriomapi__
STORE_ROOT/IPM_VIEWS/#assoc 1 messages 0.00 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT/IPM_VIEWS 1 messages 0.02 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT/Freebusy Data/#msgs 1 messages 0.00 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT/IPM_COMMON_VIEWS/#assoc 3 messages 0.00 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT/IPM_COMMON_VIEWS 3 messages 0.02 Mbytes
- - aplawrence.com/tony/__keriomapi__
STORE/__keriomapi__STORE_ROOT 3 messages 0.03 Mbytes
- - aplawrence.com/tony/__keriomapi__STORE 3 messages 0.05 Mbytes
- - aplawrence.com/tony/Contacts/#msgs 389 messages 0.09 Mbytes
- - aplawrence.com/tony/Contacts/#assoc 1 messages 0.00 Mbytes
- - aplawrence.com/tony/Contacts 1 messages 1.07 Mbytes
- - aplawrence.com/tony/Tasks/#msgs 1 messages 0.00 Mbytes
- - aplawrence.com/tony/Calendar/#msgs 2 messages 0.00 Mbytes
- - aplawrence.com/tony/Calendar/#assoc 2 messages 0.00 Mbytes
- - aplawrence.com/tony/Calendar 2 messages 0.05 Mbytes
- aplawrence.com/tony 7,810 messages 494.58 Mbytes all told,
360.43 Mbytes in .eml's: Largest directory INBOX/#msgs has
2,447 messages and is 161.31 Mbytes.  Largest mail message
INBOX/2012_06_30/#msgs/0000cd24.eml is 10.72 Mbytes

You can get that with this simple Perl script. As usual, it's something I dashed off quickly earlier today and could certainly use some improvement, but I think you will find it useful. You'll need to adjust the STORE directory for your environment, but other than that I expect it will run on any platform where you have Perl.

use File::Basename;
my $totsize;
$detail=shift @ARGV;
chdir("$STORE") or die "Fix Kerio store/mail $STORE $!";
foreach(<*>) {
  print "\n$domain $detail\n";
  foreach(<$domain/*>) {
     next if ($detail and $user !~ /$detail/);
      $file{$user}=~ s/$user\///;
      $namelargesteml{$user}=~ s/$user\///;
     next if  (not $count and not $totsize);
     printf "- $user %s messages %0.2f Mbytes all
       told, %0.2f Mbytes in .eml's", commify($count),
     printf ": Largest directory %s has %s messages and
       is %0.2f Mbytes.  Largest mail message %s is %0.2f
       Mbytes\n", $file{$user},commify($count{$user}),

# cribbed from http://www.perlmonks.org/?node_id=51836
# modded just a bit for our use here
sub dodir {
my $dir = $_[0];
if ($dir !~ /\/$/) { $dir .= "/"; }
my @List=readdir(DIR); 
foreach $file (@List) {
next if ($file eq "." or $file eq "..");
my $file = $dir.$file;
if (-d $file) { 
  if ($subtotsize > $largest{$user} ){
    $largest{$user}=$subtotsize ;
  printf "- - $file $subcount messages %0.2f Mbytes\n",
     ($subtotsize/1024/1024) if ($detail and $subcount and $subtotsize);
else { 
  $size=(-s $file);
  $totsize += $size;
  $subtotsize += $size;
  if ($file =~ /.eml$/) {
    $emlsize += $size;
    if ($size > $largesteml{$user}) {

sub commify {
    my $text = reverse $_[0];
    $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
    return scalar reverse $text

That's it - have fun and let me know about any bugs or errors.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Perl 'kreport' gives details on Kerio Connect Store usage

1 comment

Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Anthony Lawrence

Wed Jul 25 20:39:34 2012: 11218   TonyLawrence


This counts Contacts and Calendar items as well as some Outlook related items; you could easily modify the script to skip those if you wish.

For example, you might add under

foreach $file (@List) {
next if $file =~ /keriomapi/;
next if $file =~ /Contacts/;
next if $file =~ /Calendar/;

Kerio Connect Mailserver

Kerio Samepage

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

I think it’s a new feature. Don’t tell anyone it was an accident. (Larry Wall)

There are only two hard problems in computer science: cache invalidation and naming things. (Phil Karlton)

This post tagged: