Problem with IMAP4 flags, uniq(), $ids and substitution warnings

Raul Dias <[email protected]> Wed, 25 May 2005 16:40:36 -0300
Newsgroups gmane.comp.lang.perl.modules.mail-box
Message-ID <[email protected]>
Hi, when batch moving^B^B^B^Bcopying a thousand messages from a local
mbox to a remove imap folder, I get lots of this warnings:


Use of uninitialized value in hash element
at /usr/lib/perl5/site_perl/5.8.5/Mail/Transport/IMAP4.pm line 362.
Use of uninitialized value in substitution (s///)
at /usr/lib/perl5/site_perl/5.8.5/Mail/Transport/IMAP4.pm line 366.
Use of uninitialized value in hash element
at /usr/lib/perl5/site_perl/5.8.5/Mail/Transport/IMAP4.pm line 367.

This seems to happens only when the destination IMAP folder is empty.
If it has messages in it, this wont happen (at least until now).

I traced the problem, but not too far yet.

The messages happens in this code from the flagsToLabels() function:

foreach my $f (@_)
    {   if(my $lab = $flags2labels{$f})
        {   $labels{$lab->[0]} = $clear ? not($lab->[1]) : $lab->[1];
        }
        else
        {   (my $lab = $f) =~ s,^\\,,;
            $labels{$lab}++;
        }
    }


which in turn comes from the $imap->flags($id) from the
getFlags() function:

sub getFlags($$)
{   my ($self, $id) = @_;
    my $imap   = $self->imapClient or return ();
    my $labels = $self->flagsToLabels(SET => $imap->flags($id));


The problem is that $id is undefined, so $imap->flags return undef too.

This function is called from Mail::Box::IMAP4::Message by too functions:
label() and labels().
Both functions get the $id from $self->unique.

unique() is defined in Mail::Box::Net::Message.

There is two places where unique is set:
1 - Durint Mail::Box::Net::Message::init() whic passes the {unique}  
    argument.
2 - In Mail::Box::IMAP4::Message::writeDelayed():

sub writeDelayed($$)
{   my ($self, $foldername, $imap) = @_;

    my $id     = $self->unique;
    my $labels = $self->labels;

    if($self->head->modified || $self->body->modified || !$id)
    {
        $imap->appendMessage($self, $foldername);
        if($id)
        {   $self->delete;
            $self->unique(undef);
        }
    }


Which I understand that it means no unique value for appended messages.
The docs states that this unique string is the name of the file which
the message is stored and undef means that the message is not stored on
a file.

The solution seens to me to just add a 'return unless defined $id' in
the getFlags() function.

But I am not sure if this is really where the problem is.


Raul Dias