1
0
mirror of https://github.com/imapsync/imapsync.git synced 2024-11-17 00:02:29 +01:00
imapsync/W/learn/memory_consumption
Nick Bebout c08a56e486 1.504
2012-09-02 19:08:57 -05:00

58 lines
1.2 KiB
Perl
Executable File

#!/usr/bin/perl
use warnings;
use strict;
use English;
use Mail::IMAPClient;
$ARGV[3] or die "usage: $0 host user password folder\n";
my $host = $ARGV[0];
my $user = $ARGV[1];
my $password = $ARGV[2];
my $folder = $ARGV[3];
my $imap = Mail::IMAPClient->new();
$imap->Debug(0);
$imap->Server($host);
$imap->connect() or die;
$imap->User($user);
$imap->Password($password);
$imap->login() or die;
$imap->Uid(1);
$imap->Peek(1);
$imap->Clear(1);
#print map {"$_\n"} $imap->folders();
$imap->select($folder) or die;
my @msgs = $imap->messages or die "Could not messages: $@\n";
print "@msgs\n";
print memory_consumption();
foreach my $msg (@msgs) {
my $size = $imap->size($msg);
print "message size of $msg = $size bytes\n";
my $string = $imap->message_string($msg);
print memory_consumption();
$imap->append('INBOX.Trash', $string);
print memory_consumption();
}
$imap->close();
print memory_consumption();
sub memory_consumption {
my @PID = (@_) ? @_ : ($PROCESS_ID);
my $val;
my ($package, $filename, $line, $subroutine) = caller(0);
$val = "$package $filename line $line: ";
my @ps = qx{ ps o vsz @PID };
my $vsz = $ps[1];
chomp($vsz);
$val .= $vsz * 1024 . " bytes\n";
#$val .= '-' x 80 . "\n";
return($val);
}