/usr/share/doc/libmail-box-perl/examples/smaller.pl is in libmail-box-perl 2.118-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #!/usr/bin/perl
# Demonstration on reducing the size of a folder.
#
# This code can be used and modified without restriction.
# Mark Overmeer, <mailbox@overmeer.net>, 12 jul 2003
use warnings;
use strict;
use lib ('../lib', 'lib');
use Mail::Box::Manager;
use Mail::Message;
use List::Util 'sum';
my $for_real = 0; # set to 'true' to make changes
sub size($) { Mail::Message->shortSize($_[0]) } # nice output of value
#
# Get the command line arguments.
#
die "Usage: $0 folder\n"
unless @ARGV==1;
my $name = shift @ARGV;
my $mgr = Mail::Box::Manager->new;
my $folder = $mgr->open
( $name
, access => ($for_real ? 'rw' : 'r')
);
die "Cannot open folder $name" unless $folder;
print "** Dry run: no changes made to $name\n" unless $for_real;
my $msgs = $folder->messages;
my $size = $folder->size;
print "Folder contains $msgs messages at start, in total about ",
size($size), " bytes\n";
foreach my $msg ($folder->messages)
{ $msg->head->removeResentGroups;
}
my $newsize = $folder->size;
print "After removal of resent groups, the folder is about ",
size($newsize), " bytes\n";
my $resentsize = $size - $newsize;
foreach my $msg ($folder->messages)
{ $msg->head->removeListGroup;
}
my $newsize2 = $folder->size;
print "After removal of list groups, the folder is only ",
size($newsize2), " bytes\n";
my $listsize = $newsize - $newsize2;
foreach my $msg ($folder->messages)
{ $msg->head->removeSpamGroups;
}
my $finalsize = $folder->size;
print "After removal of spam groups, the folder is only ",
size($finalsize), " bytes\n";
my $spamsize = $newsize2 - $finalsize;
# Final statistics
sub percent($$)
{ my ($part, $size) = @_;
sprintf "%4.1f%% (%s)", ($part*100)/$size, size($part);
}
my $sizeheads = sum map {$_->head->size}
map {$_->parts}
$folder->messages;
print ' resent headers were ', percent($resentsize,$size), "\n",
' list headers were ', percent($listsize,$size), "\n",
' spam headers were ', percent($spamsize,$size), "\n",
' remaining headers are ', percent($sizeheads, $size), "\n",
' size of bodies is ', percent($finalsize-$sizeheads, $size), "\n";
# End
if($for_real) { $folder->close }
else { $folder->close(write => 'NEVER') }
exit 0;
|