Email::Folder::IMAP - Email::Folder Access to IMAP Folders


Email-Folder-IMAP documentation Contained in the Email-Folder-IMAP distribution.

Index


Code Index:

NAME

Top

Email::Folder::IMAP - Email::Folder Access to IMAP Folders

SYNOPSIS

Top

  use Email::Folder;
  use Email::FolderType::Net;

  my $folder = Email::Folder->new('imap://example.com'); # read INBOX

  print $_->header('Subject') for $folder->messages;

DESCRIPTION

Top

This software adds IMAP functionality to Email::Folder. Its interface is identical to the other Email::Folder::Reader subclasses.

Parameters

username and password parameters may be sent to new(). If used, they override any user info passed in the connection URI.

Folder Specification

Folders are specified using a simplified form of the IMAP URL Scheme detailed in RFC 2192. Not all of that specification applies. Here are a few examples.

Selecting the INBOX.

  imap://foo.com

Selecting the INBOX using URI based authentication. Remember that the username and password parameters passed to new() will override anything set in the URI.

  imap://user:pass@foo.com

Selecting the p5p list.

  imap://foo.com/perl/perl5-porters

SEE ALSO

Top

Email::Folder, Email::Folder::Reader, Email::FolderType::Net, URI::imap, Net::IMAP::Simple.

PERL EMAIL PROJECT

Top

This module is maintained by the Perl Email Project.

http://emailproject.perl.org/wiki/Email::Folder::IMAP

AUTHOR

Top

Casey West, <casey@geeknest.com>.

COPYRIGHT

Top


Email-Folder-IMAP documentation Contained in the Email-Folder-IMAP distribution.

package Email::Folder::IMAP;
use strict;

use vars qw[$VERSION];
$VERSION = '1.102';

use base qw[Email::Folder::Reader];
use Net::IMAP::Simple;
use URI;

sub _imap_class {
  'Net::IMAP::Simple';
}

sub _uri {
  my $self = shift;
  return $self->{_uri} ||= URI->new($self->{_file});
}

sub _server {
  my $self = shift;
  return $self->{_server} if $self->{_server};

  my $uri = $self->_uri;

  my $host   = $uri->host_port;
  my $server = $self->_imap_class->new($host);

  my ($user, $pass) = @{$self}{qw[username password]};
  ($user, $pass) = split ':', $uri->userinfo, 2 unless $user;

  $server->login($user, $pass) if $user;

  my $box = substr $uri->path, 1;
  $server->select($box) if $box;

  $self->{_next} = 1;
  return $self->{_server} = $server;
}

sub next_message {
  my $self    = shift;
  my $message = $self->_server->get($self->{_next});
  if ($message) {
    ++$self->{_next};
    return join '', @{$message};
  }
  $self->{_next} = 1;
  return;
}

1;

__END__