[Bps-public-commit] r19266 - in Net-IMAP-Server/lib/Net/IMAP/Server: Command

alexmv at bestpractical.com alexmv at bestpractical.com
Thu Apr 16 23:40:27 EDT 2009


Author: alexmv
Date: Thu Apr 16 23:40:26 2009
New Revision: 19266

Modified:
   Net-IMAP-Server/lib/Net/IMAP/Server/Command/Close.pm
   Net-IMAP-Server/lib/Net/IMAP/Server/Command/Expunge.pm
   Net-IMAP-Server/lib/Net/IMAP/Server/Command/Select.pm
   Net-IMAP-Server/lib/Net/IMAP/Server/Command/Store.pm
   Net-IMAP-Server/lib/Net/IMAP/Server/Command/Uid.pm
   Net-IMAP-Server/lib/Net/IMAP/Server/Connection.pm
   Net-IMAP-Server/lib/Net/IMAP/Server/Mailbox.pm

Log:
Use Mailboxes' read-only attribute, and make it respect connection read-only-ness

Previously, mailboxes had a mostly-ignored read_only attribute, and
connections had an orthogonal selected_read_only attribute, set by
EXAMINE.  Merge these two senses of read-only-ness by having the
mailbox's read_only respect the connection's setting, and standardize
on calling connection->selected->read_only in all places.

Modified: Net-IMAP-Server/lib/Net/IMAP/Server/Command/Close.pm
==============================================================================
--- Net-IMAP-Server/lib/Net/IMAP/Server/Command/Close.pm	(original)
+++ Net-IMAP-Server/lib/Net/IMAP/Server/Command/Close.pm	Thu Apr 16 23:40:26 2009
@@ -21,7 +21,7 @@
 sub run {
     my $self = shift;
 
-    $self->connection->selected->expunge unless $self->connection->selected_read_only;
+    $self->connection->selected->expunge unless $self->connection->selected->read_only;
     $self->connection->selected(undef);
 
     $self->ok_completed();

Modified: Net-IMAP-Server/lib/Net/IMAP/Server/Command/Expunge.pm
==============================================================================
--- Net-IMAP-Server/lib/Net/IMAP/Server/Command/Expunge.pm	(original)
+++ Net-IMAP-Server/lib/Net/IMAP/Server/Command/Expunge.pm	Thu Apr 16 23:40:26 2009
@@ -12,7 +12,7 @@
     return $self->bad_command("Select a mailbox first")
         unless $self->connection->is_selected;
 
-    return $self->bad_command("Mailbox is read-only") if $self->connection->selected_read_only;
+    return $self->bad_command("Mailbox is read-only") if $self->connection->selected->read_only;
 
     my @options = $self->parsed_options;
     return $self->bad_command("Too many options") if @options;

Modified: Net-IMAP-Server/lib/Net/IMAP/Server/Command/Select.pm
==============================================================================
--- Net-IMAP-Server/lib/Net/IMAP/Server/Command/Select.pm	(original)
+++ Net-IMAP-Server/lib/Net/IMAP/Server/Command/Select.pm	Thu Apr 16 23:40:26 2009
@@ -50,7 +50,7 @@
             . join( ' ', $mailbox->permanentflags )
             . ')]' );
 
-    if ( $self->connection->selected_read_only ) {
+    if ( $self->connection->selected->read_only ) {
         $self->ok_command("[READ-ONLY] Completed");
     } else {
         $self->ok_command("[READ-WRITE] Completed");

Modified: Net-IMAP-Server/lib/Net/IMAP/Server/Command/Store.pm
==============================================================================
--- Net-IMAP-Server/lib/Net/IMAP/Server/Command/Store.pm	(original)
+++ Net-IMAP-Server/lib/Net/IMAP/Server/Command/Store.pm	Thu Apr 16 23:40:26 2009
@@ -14,7 +14,7 @@
     return $self->bad_command("Select a mailbox first")
         unless $self->connection->is_selected;
 
-    return $self->bad_command("Mailbox is read-only") if $self->connection->selected_read_only;
+    return $self->bad_command("Mailbox is read-only") if $self->connection->selected->read_only;
 
     my @options = $self->parsed_options;
     return $self->bad_command("Not enough options") if @options < 3;

Modified: Net-IMAP-Server/lib/Net/IMAP/Server/Command/Uid.pm
==============================================================================
--- Net-IMAP-Server/lib/Net/IMAP/Server/Command/Uid.pm	(original)
+++ Net-IMAP-Server/lib/Net/IMAP/Server/Command/Uid.pm	Thu Apr 16 23:40:26 2009
@@ -60,7 +60,7 @@
 sub store {
     my $self = shift;
 
-    return $self->bad_command("Mailbox is read-only") if $self->connection->selected_read_only;
+    return $self->bad_command("Mailbox is read-only") if $self->connection->selected->read_only;
 
     return $self->bad_command("Not enough options") if @_ < 3;
     return $self->bad_command("Too many options") if @_ > 3;
@@ -115,7 +115,7 @@
     return $self->bad_command("Not enough options") if @_ < 1;
     return $self->bad_command("Too many options") if @_ > 2;
 
-    return $self->bad_command("Mailbox is read-only") if $self->connection->selected_read_only;
+    return $self->bad_command("Mailbox is read-only") if $self->connection->selected->read_only;
 
     my ( $messages ) = @_;
     my @messages = $self->connection->selected->get_uids($messages);

Modified: Net-IMAP-Server/lib/Net/IMAP/Server/Connection.pm
==============================================================================
--- Net-IMAP-Server/lib/Net/IMAP/Server/Connection.pm	(original)
+++ Net-IMAP-Server/lib/Net/IMAP/Server/Connection.pm	Thu Apr 16 23:40:26 2009
@@ -123,6 +123,13 @@
     return $self->_selected(@_);
 }
 
+=head2 selected_read_only
+
+Returns true of the currently selected mailbox has been forced into
+read-only mode.  Note that the mailbox may be read-only for other
+reasons, so checking L<Net::IMAP::Server::Mailbox/read_only> is
+suggested instead.
+
 =head2 greeting
 
 Sends out a one-line untagged greeting to the client.

Modified: Net-IMAP-Server/lib/Net/IMAP/Server/Mailbox.pm
==============================================================================
--- Net-IMAP-Server/lib/Net/IMAP/Server/Mailbox.pm	(original)
+++ Net-IMAP-Server/lib/Net/IMAP/Server/Mailbox.pm	Thu Apr 16 23:40:26 2009
@@ -505,14 +505,17 @@
 
 =head3 read_only
 
-Returns true if this mailbox is read-only.  By default, always returns
-false.
+Returns true if this mailbox is read-only.  By default, the value of
+this depends on if the mailbox was selected using C<EXAMINE> or
+C<SELECT> (see L<Net::IMAP::Server::Command::Select> and
+L<Net::IMAP::Server::Connection/selected_read_only>)
 
 =cut
 
 sub read_only {
     my $self = shift;
-    return 0;
+    return unless Net::IMAP::Server->connection;
+    return Net::IMAP::Server->connection->selected_read_only;
 }
 
 =head3 selected



More information about the Bps-public-commit mailing list