NAME

Net::IMAP::Simple::NB - Non-blocking IMAP.

SYNOPSIS

use Net::IMAP::Simple::NB;
use Scalar::Util qw(weaken isweak);
Danga::Socket->AddTimer(0, sub {
    # Create the object
    my $imap = Net::IMAP::Simple::NB->new('server:143') ||
       die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";
    
    $imap->login('user','password', sub {
        my $login_ok = shift;
        if ($login_ok) {
            print "Login OK\n";
            $imap->select("INBOX", sub {
                my $nm = shift;
                print "Got $nm Messages\n";
                my $i = 1;
                my $sub;
                $sub = sub {
                    weaken($sub) unless isweak($sub);
                    my $headers = shift;
                    print grep { /^Subject:/ } @$headers;
                    $i++;
                    $imap->top($i, $sub) unless $i == $nm;
                };
                $imap->top($i, $sub);
            });
        }
        else {
            warn("Login failed!");
        }
    });
});

Danga::Socket->EventLoop;

DESCRIPTION

This module models the Net::IMAP::Simple API, but works non-blocking. It is based on the Danga::Socket framework, rather than anything generic. Sorry if that doesn't fit your world-view.

API

The Net::IMAP::Simple::NB API models the Net::IMAP::Simple API exactly, with the difference that instead of having return values, you supply a callback as the last parameter of the method call. This callback will receive in @_ the same as whatever the Net::IMAP::Simple method would have returned.

The only real difference aside from that is a slightly modified constructor:

CLASS->new(...)

my $imap = Net::IMAP::Simple->new( $server [ :port ]);
OR
my $imap = Net::IMAP::Simple->new( $server [, option_name => option_value ] );

This class method constructs a new Net::IMAP::Simple::NB object. It takes one required parameter which is the server to connect to, and additional optional parameters.

The server parameter may specify just the server, or both the server and port number. To specify an alternate port, seperate it from the server with a colon (:), example.com:5143.

On success an object is returned. On failure, nothing is returned and an error message is set to $Net::IMAP::Simple::errstr.

OPTIONS:

port             => Assign the port number (default: 143)

timeout          => Connection timeout in seconds.

use_v6           => If set to true, attempt to use IPv6
                 -> sockets rather than IPv4 sockets.
                 -> This option requires the
                 -> IO::Socket::INET6 module

bindaddr         => Assign a local address to bind


use_select_cache => Enable select() caching internally

select_cache_ttl => The number of seconds to allow a
                 -> select cache result live before running
                 -> select() again.

AUTHOR

Matt Sergeant, <matt@sergeant.org>.

SEE ALSO

Net::IMAP::Simple

LICENSE

You may use and redistribute this module under the same terms as perl itself.