[Bps-public-commit] Net-IMAP-Server branch, master, updated. 1.25-3-gfed18b1

Alex M Vandiver alexmv at bestpractical.com
Tue Dec 8 20:41:16 EST 2009


The branch, master has been updated
       via  fed18b138a3b935286c8d2577798beb0875fbc85 (commit)
       via  e4a5176c8e96ee64e42d35109d25e272cd16ff01 (commit)
      from  107435f582c9c13a51bbd6da36eaa0a3ffefebc4 (commit)

Summary of changes:
 lib/Net/IMAP/Server/Command/Select.pm |    3 +--
 lib/Net/IMAP/Server/Connection.pm     |   33 +++++++++++++++++++++++----------
 lib/Net/IMAP/Server/Mailbox.pm        |   12 +++++++++++-
 3 files changed, 35 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit e4a5176c8e96ee64e42d35109d25e272cd16ff01
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Dec 8 20:38:24 2009 -0500

    Add a ->select callback on Net::IMAP::Server::Mailbox, when it is selected
    
    Additionally, refactor the SELECT command such that selected_read_only
    is already set correctly when the new ->select callback is called.

diff --git a/lib/Net/IMAP/Server/Command/Select.pm b/lib/Net/IMAP/Server/Command/Select.pm
index 3e11775..575e1b8 100644
--- a/lib/Net/IMAP/Server/Command/Select.pm
+++ b/lib/Net/IMAP/Server/Command/Select.pm
@@ -27,8 +27,7 @@ sub run {
     my $mailbox = $self->connection->model->lookup( $self->parsed_options );
     $mailbox->poll;
     $self->connection->last_poll(time);
-    $self->connection->selected($mailbox);
-    $self->connection->selected_read_only(1) if $self->command eq "Examine";
+    $self->connection->selected($mailbox, $self->command eq "Examine");
 
     $self->untagged_response(
         'FLAGS (' . join( ' ', $mailbox->flags ) . ')' );
diff --git a/lib/Net/IMAP/Server/Connection.pm b/lib/Net/IMAP/Server/Connection.pm
index 14655a9..34458a6 100644
--- a/lib/Net/IMAP/Server/Connection.pm
+++ b/lib/Net/IMAP/Server/Connection.pm
@@ -116,23 +116,36 @@ sub client_id {
     return $self->{client} || {};
 }
 
-=head2 selected [MAILBOX]
+=head2 selected [MAILBOX], [READ_ONLY]
 
-Gets or sets the currently selected mailbox for this connection.  This
-may trigger the sending of untagged notifications to the client.
+Gets or sets the currently selected mailbox for this connection.
+Changing mailboxes triggers the sending of untagged notifications to
+the client, as well as calling L<Net::IMAP::Server::Mailbox/close> and
+L<Net::IMAP::Server::Mailbox/select>.
 
 =cut
 
 sub selected {
     my $self = shift;
-    if ( @_ and $self->selected ) {
-        unless ( $_[0] and $self->selected eq $_[0] ) {
-            $self->send_untagged;
-            $self->selected->close;
-        }
-        $self->selected_read_only(0);
+    my ($mailbox, $read_only) = @_;
+
+    # This is just being called as a getter
+    return $self->_selected unless @_;
+
+    # This is a setter, but isn't actually changing the mailbox.
+    return $self->_selected if $mailbox and $mailbox eq $self->_selected;
+
+    # Otherwise, flush any untagged messages, close the old, and open
+    # the new.
+    $self->send_untagged;
+    $self->_selected->close if $self->_selected;
+    $self->_selected( $mailbox );
+    if ($self->_selected) {
+        $self->selected_read_only( $read_only );
+        $self->_selected->select;
     }
-    return $self->_selected(@_);
+
+    return $self->_selected;
 }
 
 =head2 selected_read_only
diff --git a/lib/Net/IMAP/Server/Mailbox.pm b/lib/Net/IMAP/Server/Mailbox.pm
index d7ccc47..ab92a7e 100644
--- a/lib/Net/IMAP/Server/Mailbox.pm
+++ b/lib/Net/IMAP/Server/Mailbox.pm
@@ -551,6 +551,15 @@ sub read_only {
     return Net::IMAP::Server->connection->selected_read_only;
 }
 
+=head3 select
+
+Called when the mailbox is selected; by default does nothing.  Note
+that this could be called a a result of either a SELECT or an EXAMINE.
+
+=cut
+
+sub select {}
+
 =head3 selected
 
 Returns true if this mailbox is the mailbox selected by the current

commit fed18b138a3b935286c8d2577798beb0875fbc85
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Dec 8 20:39:38 2009 -0500

    ->read_only only cares about ->selected_read_only if it is currently selected
    
    The old behavior caused _all_ mailboxes to pretend that they were read
    only if the current mailbox was opened with EXAMINE.

diff --git a/lib/Net/IMAP/Server/Mailbox.pm b/lib/Net/IMAP/Server/Mailbox.pm
index ab92a7e..d51f936 100644
--- a/lib/Net/IMAP/Server/Mailbox.pm
+++ b/lib/Net/IMAP/Server/Mailbox.pm
@@ -548,7 +548,8 @@ L<Net::IMAP::Server::Connection/selected_read_only>)
 sub read_only {
     my $self = shift;
     return unless Net::IMAP::Server->connection;
-    return Net::IMAP::Server->connection->selected_read_only;
+    return $self->selected
+        and Net::IMAP::Server->connection->selected_read_only;
 }
 
 =head3 select

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list