Net-IMAP-Server
view release on metacpan or search on metacpan
212213214215216217218219220221222223224225226227228229230- Add missing Net::SSLeay dep
0.5 2008-04-25T12:18:17Z
- Add
'use Coro'
s
for
the places I added
'cede'
s
- Module::Install version bump
0.4 2008-04-23T15:24:22Z
- Weaken the timeout callback, so we don't leak connection objects
- Don't double-store refs to connections
- Actually clean out old
keys
in the connection hash
- Try to
from the right coro, so EV doesn't complain about recursive
entry, and then wedge the
next
time
it happens.
- Drop some more
'cede'
s in
for
commands which
do
many things
0.3 2008-03-11T12:33:14Z
- Connections weren't being fully closed on timeout
0.2 2008-03-10T16:47:52Z
- Initial release to CPAN
121122123124125126127128129130131132133134135136137138139140141DESTROY
On destruction, ensure that we
close
all client connections and
listening sockets.
connections
Returns an arrayref of Net::IMAP::Server::Connection objects which are
currently connected to the server.
connection
Returns the currently active Net::IMAP::Server::Connection object,
if
there is one. This is determined by examining the current coroutine.
concurrent_mailbox_connections [MAILBOX]
This can be called as either a class method or an instance method; it
returns the set of connections which are concurrently connected to the
given
mailbox object (which defaults to the current connection's
selected mailbox)
concurrent_user_connections [USER]
This can be called as either a class method or an instance method; it
returns the set of connections whose
"user"
in
lib/Net/IMAP/Server.pm view on Meta::CPAN
289290291292293294295296297298299300301302303304305306307308309sub
connections {
my
$self
=
shift
;
return
[
values
%{
$self
->{connection}} ];
}
=head2 connection
Returns the currently active L<Net::IMAP::Server::Connection> object,
if there is one. This is determined by examining the current
coroutine.
=cut
sub
connection {
my
$class
=
shift
;
my
$self
=
ref
$class
?
$class
:
$Net::IMAP::Server::Server
;
if
(
@_
) {
if
(
defined
$_
[0]) {
$self
->{connection}{
$Coro::current
.
""
} =
shift
;
}
else
{
lib/Net/IMAP/Server/Connection.pm view on Meta::CPAN
67891011121314151617181920212223242526
lib/Net/IMAP/Server/Connection.pm view on Meta::CPAN
45464748495051525354555657585960616263646566676869707172737475767778798081sub
new {
my
$class
=
shift
;
my
$self
=
$class
->SUPER::new(
{
@_
,
state
=>
"unauth"
,
_unsent_expunge
=> [],
_unsent_fetch
=> {},
last_poll
=>
time
,
commands
=> 0,
coro
=>
$Coro::current
,
_session_flags
=> {},
}
);
$self
->update_timer;
return
$self
;
}
=head2 server
Returns the L<Net::IMAP::Server> that this connection is on.
=head2 coro
Returns the L<Coro> process associated with this connection. For
things interacting with this connection, it will probably be the
current coroutine, except for interactions coming from event loops.
=head2 io_handle
Returns the IO handle that can be used to read from or write to the
client.
=head2 model
Gets or sets the L<Net::IMAP::Server::DefaultModel> or descendant
associated with this connection. Note that connections which have not
lib/Net/IMAP/Server/Connection.pm view on Meta::CPAN
165166167168169170171172173174175176177178179180181182183184185186187188189190191192=cut
sub greeting {
my $self = shift;
$self->untagged_response('OK IMAP4rev1 Server');
}
=head2 handle_lines
The main line handling loop. Since we are using L<Coro>, this cedes
to other coroutines whenever we block, given them a chance to run. We
additionally cede after handling every command.
=cut
sub
handle_lines {
my
$self
=
shift
;
$self
->coro->prio(-4);
eval
{
$self
->greeting;
while
(
$self
->io_handle and
$_
=
$self
->io_handle->getline() ) {
$self
->handle_command(
$_
);
$self
->commands(
$self
->commands + 1 );
if
(
$self
->is_unauth
and
$self
->server->unauth_commands
and
$self
->commands >=
$self
->server->unauth_commands )
{
lib/Net/IMAP/Server/Connection.pm view on Meta::CPAN
214215216217218219220221222223224225226227228229230231232233234Updates the inactivity timer.
=cut
sub update_timer {
my $self = shift;
$self->timer(undef);
my $weakself = $self;
weaken($weakself);
my $timeout = sub {
$weakself->coro->throw("Timeout\n");
$weakself->coro->ready;
};
if ( $self->is_unauth and $self->server->unauth_idle ) {
$self->timer( AnyEvent->timer( after => $self->server->unauth_idle, cb => $timeout ) );
} elsif ( $self->server->auth_idle ) {
$self->timer( AnyEvent->timer( after => $self->server->auth_idle, cb => $timeout ) );
}
}
=head2 timer [AnyEvent watcher]
lib/Net/IMAP/Server/Connection.pm view on Meta::CPAN
341342343344345346347348349350351352353354355356357358359360361sub
close
{
my
$self
=
shift
;
if
(
$self
->io_handle ) {
$self
->io_handle->
close
;
$self
->io_handle(
undef
);
}
$self
->timer(
undef
)
if
$self
->timer;
$self
->selected->
close
if
$self
->selected;
$self
->model->
close
if
$self
->model;
$self
->server->connection(
undef
)
if
$self
->server;
$self
->coro(
undef
);
}
=head2 parse_command LINE
Parses the line into the C<tag>, C<command>, and C<options>. Returns
undef if parsing fails for some reason.
=cut
sub
parse_command {
( run in 0.264 second using v1.01-cache-2.11-cpan-ec4f86ec37b )