Subject: | Does not handle spaces in mailbox names |
Using IMAP::Client-0.13 on Perl 5.8.7 running Solaris 10 x86 against a
Cyrus IMAP server.
Running the STATUS command on mailboxes with spaces produces misleading
results as the spaces are not handled correctly.
This Perl code shows the problem:
use IMAP::Client;
my $imap = new IMAP::Client();
my $server = "";
my $user = "";
my $passwd = "";
$imap->connect (PeerAddr => $server, ConnectMethod => 'SSL STARTTLS
PLAIN')
or die "Unable to connect to server: " . $imap->error() . "\n";
$imap->authenticate($user,$passwd)
or die "Unable to authenticate as $user: ".$imap->error()."\n";
my $mailbox = "INBOX.test 2.sub test 2";
my @list = $imap->list( '*', $mailbox );
my $total = 0;
foreach my $box (@list) {
my %status = $imap->status( $box->{'MAILBOX'}, ( 'MESSAGES' ));
$total += $status{'MESSAGES'};
}
print "$mailbox total messages: $total\n";
This is the IMAP protocol dump:
<<0008 Status {23+}
INBOX.test 2.sub test 2 (MESSAGES)
Show quoted text
>>* STATUS "INBOX.test 2.sub test 2" (MESSAGES 7)
0008 OK Completed
In the code above, the original version of IMAP::Client returns 0
instead of 7.
This patch against the latest release appears to work satisfactorily:
--- a/IMAP/Client.pm Tue Sep 9 14:50:55 2008
+++ b/IMAP/Client.pm Tue May 22 16:58:22 2012
@@ -1523,7 +1523,7 @@
# find STATUS line and process results
foreach my $line (@resp) {
- next unless ($line =~ s/^\*\s+STATUS\s+\S+\s+\
((.*?)\)\r\n$/$1/);
+ next unless ($line =~ s/^\*\s+STATUS\s+(\S+|".*?")\s+\
((.*?)\)\r\n$/$2/);
%results = split(/ /,$line); # thanks to the "key value
key value" string
}