Re: folder->messages(begin, end) implementation on maildir

Mark Overmeer <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.mail-box
Organization MARKOV Solutions
Message-ID <[email protected]>
* Mike J. Vincelette ([email protected]) [040202 23:26]:
> I'm getting some strange behavior using the "folder->messages(begin, 
> end) construction. I can work around it, but I think it may be a bug.

You're right.  I see a strange behavior of a slice like
@{$r}[1..2] in scalar subroutine context.  Besides, there is an off-by-one
error in the protection which avoids addressing out-of-bounds.

Mail::Box sub message() should be modified a little:

    if(@_==2)   # range
    {   my ($begin, $end) = @_;
        $begin += $nr   if $begin < 0;
        $begin  = 0     if $begin < 0;
        $end   += $nr   if $end < 0;
 -      $end    = $nr   if $end > $nr;
 +      $end    = $nr-1 if $end >= $nr;
                                                                                
 -      return $begin > $end ? () : @{$self->{MB_messages}}[$begin..$end];
 +      return () if $begin > $end;
 +                                                                              
 +      my @range = @{$self->{MB_messages}}[$begin..$end];
 +      return @range;
    }

Thanks for the report!
-- 
               MarkOv

------------------------------------------------------------------------
drs Mark A.C.J. Overmeer                                MARKOV Solutions
       [email protected]                          [email protected]
http://Mark.Overmeer.net                   http://solutions.overmeer.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.