Net-IMAP-Server

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
- 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 print 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

README  view on Meta::CPAN

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
DESTROY
  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

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
sub 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

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
use Coro;
use Scalar::Util qw/weaken/;
 
 
__PACKAGE__->mk_accessors(
    qw(server coro io_handle model auth
       timer commands pending
       selected_read_only
       _selected
 
       temporary_messages temporary_sequence_map
       ignore_flags
       _session_flags
 
       last_poll previous_exists in_poll
       _unsent_expunge _unsent_fetch

lib/Net/IMAP/Server/Connection.pm  view on Meta::CPAN

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
sub 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

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
=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

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
Updates 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

341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
sub 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 )