Hi all,
I have a problem that I don't think I can solve (I don't understand what's wrong), so I decided to ask for your help.
I have the following piece of code (which uses an open connection from Mail::Cclient with parameters the connection -$imap- and the foldername -$fname-) :
sub foldertree($$) {
my ($imap,$fname) = @_;
my $count=0;
my $new=0;
my $unread=0;
my @folders=();
set_callback(
list => sub {
my @tmp = split ('}',$_[2]);
push (@folders, $tmp[1]);
},
status => sub {
$count = $_[3];
$new = $_[5];
$unread = $_[7];
}
);
$imap->list("{hostname:143/imap}$fname",'%');
my @topfolders = @folders;
my @folderlist;
foreach my $f (sort @topfolders) {
$imap->status("{hostname:143/imap}$f",
"messages","recent","unseen");
my %foldhash= (
'name' => $f,
'count' => $count,
'new' => $new,
'unread' => $unread
);
my @subfolders=&foldertree($imap,$f);
my $fc=@subfolders;
$foldhash{'fc'} = $fc;
$foldhash{'subfolders'} = @subfolders;
@folderlist = (@folderlist, \%foldhash);
}
return @folderlist;
}
Later, when I iterrate the
@folderlist, I notice that all the count, new and unread values are set to zero (0) but the numbers are not correct...
If, though, I skip the stage where I recursively call the sub in order to get the subfolders, it works like a charm (but I don't have the subfolder info which I need).
I also tried modifying the sub as follows (only appropriate part provided):
foreach my $f (sort @topfolders) {
$imap->status("{hostname:143/imap}$f",
"messages","recent","unseen");
my $new_count=$count;
my $new_new=$new;
my $new_unread=$unread;
my %foldhash= (
'name' => $f,
'count' => $new_count,
'new' => $new_new,
'unread' => $new_unread
);
my @subfolders=&foldertree($imap,$f);
my $fc=@subfolders;
$foldhash{'fc'} = $fc;
$foldhash{'subfolders'} = @subfolders;
but it didn't make any difference.
Any good ideas? I think something is wrong with the scope of the variables, but if that's the case, then why does the second example have problem as well?
Thanks in advance