Count messages in a Imap-Mailfolder
[email protected] (Michelle Konzack)
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
************************************************************************
* Do not Cc: me, because I READ THIS LIST, if I write here *
* Keine Cc: am mich, ich LESE DIESE LISTE wenn ich hier schreibe *
************************************************************************
Hello,
since I live in a region where I have NO telephone line which mean no
Internet too I am connecting to the internet over GSM/GPRS. But there is
a big problem: I have several mail accounts and I am on MANY mailing-
lists...
Now, before downloading the messages I like to check from a small script
how many messages are in the Mailaccount and the size. OK, the number
of mesages is no problem but the total size.
Querying an account with 3500 messages daily cost 1700 kByte GSM/GPRS
traffic which is realy expensive.
Now since I am beginner in perl, I like to know, whether there is a
function to get the total size of a IMAP folder?
Note: I use the Debian package "libnet-imap-simple-perl"
if it is important for you to help.
My current script is:
----[ '~/bin/tdcheckimapsize' ]-----------------------------------------
#!/usr/bin/perl
use Net::IMAP::Simple;
use strict;
use Getopt::Long;
my $PASS="";
my $USER="[email protected]";
my $HOST="server4.pinguinhosting.de";
GetOptions('user=s' => \$USER,
'pass=s' => \$PASS,
'host=s' => \$HOST);
die "No user given\n" unless $USER;
die "No password given\n" unless $PASS;
die "No host given\n" unless $HOST;
my $imap = Net::IMAP::Simple->new($HOST) || die
$Net::IMAP::Simple::errstr."\n";
unless($imap->login($USER, $PASS)){
die "Login failed: " . $imap->errstr() . "\n";
}
my @mb=$imap->mailboxes;
my $size = 0;
my $num_tot = 0;
my $size_tot = 0;
foreach (@mb){
my $num = $imap->select($_);
for (my $i=1; $i <= $num; $i++){
$size += $imap->list($i);
}
$num_tot += $num;
$size_tot += $size;
};
printf "%i %i", $num_tot, $size_tot/1024;
$imap->quit;
------------------------------------------------------------------------
Thanks, Greetings and nice Day
Michelle Konzack
Systemadministrator
24V Electronic Engineer
Tamay Dogan Network
Debian GNU/Linux Consultant
--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
+49/177/9351947 50, rue de Soultz MSN LinuxMichi
+33/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)
signature.pgp
(application/pgp-signature, 189 B) - not displayed