Subject: | Some extensions for Email::Folder::Maildir |
I was playing with Email::Folder::Maildir, but wanted to move around in the message queue. I added a lot to the package and here it is. I'd really like to see the same API available to all subclasses of Email::Folder::Reader, where appropriate.
BEGIN {
package Email::Folder::Maildir;
sub count {
$_[0]->{_messages} || $_[0]->_what_is_there;
scalar @{ $_[0]->{_messages} };
}
sub new { shift->SUPER::new( @_ )->init }
sub init
{
$_[0]->_what_is_there;
$_[0]->{_cursor} = -1; # next_message starts at 0;
$_[0]
}
sub messages { $_[0]->{_messages} }
sub message_total { $#{ $_[0]->messages } + 1 }
sub cursor { $_[0]->{_cursor} += $_[1] }
sub current_message { $_[0]->get_message( $_[0]->cursor ) }
sub previous_message { $_[0]->get_message( $_[0]->cursor( -1 ) ) }
sub next_message { $_[0]->get_message( $_[0]->cursor( +1 ) ) }
sub message_file
{
abs( $_[1] ) <= $_[0]->message_total ?
$_[0]->{_messages}[ $_[1] ] : ()
}
sub get_message
{
my $self = shift;
my $num = shift;
my $file = $self->message_file( $num );
open my($fh), $file or carp "Couldn't open file $file: $!";
my $message = join '', <$fh>;
}
}