#!/usr/bin/perl
my $all_accounts=`zmprov gaa`;
my @accounts = split(/\n/,$all_accounts);
my @sizes;
foreach $account (@accounts) {
my $mb_size=`zmmailbox -z -m $account gms`;
chomp($mb_size);
my $size;
if ($mb_size =~ /(.+)\ GB/) {
$size = $1 * 1024 * 1024;
} elsif ($mb_size =~ /(.+)\ MB/) {
$size = $1 * 1024;
} elsif ($mb_size =~ /(.+)\ KB/) {
$size = $1;
} elsif ($mb_size =~ /(.+)\ B/) {
$nsize = $1;
if ($nsize eq 0) {
$size = 0;
} else {
$size = abs(1024/$1);
};
};
$next = scalar(@sizes);
$sizes[$next][0] = $account;
$sizes[$next][1] = $size;
};
@sizes = sort { $a->[1] <=> $b->[1] } @sizes;
my $D=`date +'%m/%d/%y %H:%M'`; chomp($D);
print "==========================================================\n";
print " Zimbra Mailbox Report\n";
print " \n";
print " All sizes in KB.";
print " Generated on: $D\n";
print "==========================================================\n";
for (my $i = $#sizes-1; $i >= 0; $i--) {
printf ("%15.2f %s\n",$sizes[$i][1], $sizes[$i][0]);
};