Subject: | Cannot LOGIN with empty password |
I have an IMAP server (Dovecot) where the login credentials are
username = "anonymous", password = "". Fetchmail connects correctly
with the following:
----8<----
fetchmail: IMAP< * OK Dovecot ready.
fetchmail: IMAP> A0001 CAPABILITY
fetchmail: IMAP< * CAPABILITY IMAP4rev1 SASL-IR SORT THREAD=REFERENCES
MULTIAPPEND UNSELECT LITERAL+ IDLE CHILDREN NAMESPACE LOGIN-REFERRALS
AUTH=PLAIN
fetchmail: IMAP< A0001 OK Capability completed.
fetchmail: IMAP> A0002 LOGIN "anonymous" *
fetchmail: IMAP< A0002 OK Logged in.
---->8----
So, in my Mail::IMAPClient->new() call, I set
User => 'anonymous',
Password => '',
and I get
----8<----
Using Mail::IMAPClient version 3.19 on perl 5.010000
Read: * OK Dovecot ready.
Sending: 1 STATUS INBOX (MESSAGES)
Sent 27 bytes
Read: 1 BAD Error in IMAP command received by server.
ERROR: 1 BAD Error in IMAP command received by server.
at /tmp/Mail-IMAPClient-3.19/lib/Mail/IMAPClient.pm line 1316
---->8----
It's not even doing the LOGIN. I made a small change to the bottom of
Mail::IMAPClient::Socket():
- $self->User && $self->Password ? $self->login : $self;
+ $self->User && defined($self->Password) ? $self->login : $self;
Now, I get
----8<----
Using Mail::IMAPClient version 3.19 on perl 5.010000
Read: * OK Dovecot ready.
Sending: 1 LOGIN "anonymous"
Sent 22 bytes
Read: 1 BAD Error in IMAP command received by server.
ERROR: 1 BAD Error in IMAP command received by server.
at /tmp/Mail-IMAPClient-3.19/lib/Mail/IMAPClient.pm line 1316
---->8----
So I made one more change, this time in Mail::IMAPClient::login():
----8<----
@@ -371,6 +371,9 @@
$passwd =~ s/(["\\])/\\$1/g;
$passwd = qq("$passwd");
}
+ if ( $passwd eq '' ) {
+ $passwd = '*';
+ }
$id = qq("$id") if $id !~ /^".*"$/;
---->8----
And finally, everything works:
----8<----
Using Mail::IMAPClient version 3.19 on perl 5.010000
Read: * OK Dovecot ready.
Sending: 1 LOGIN "anonymous" *
Sent 23 bytes
Read: 1 OK Logged in.
Sending: 2 STATUS INBOX (MESSAGES)
Sent 27 bytes
Read: * STATUS "INBOX" (MESSAGES 269)
2 OK Status completed.
Sending: 3 LOGOUT
Sent 10 bytes
Read: * BYE Logging out
3 OK Logout completed.
---->8----
A proper patch file, against the 3.19 source, is attached.
This issue was first observed on 3.12, as shipped with Ubuntu Jaunty,
and confirmed on the latest 3.19.
Subject: | imapclient-fix.patch |
diff -ru Mail-IMAPClient-3.19.orig/lib/Mail/IMAPClient.pm Mail-IMAPClient-3.19/lib/Mail/IMAPClient.pm
--- Mail-IMAPClient-3.19.orig/lib/Mail/IMAPClient.pm 2009-06-19 15:06:33.000000000 -0400
+++ Mail-IMAPClient-3.19/lib/Mail/IMAPClient.pm 2009-07-22 23:58:35.000000000 -0400
@@ -353,7 +353,7 @@
return $self;
}
- $self->User && $self->Password ? $self->login : $self;
+ $self->User && defined($self->Password) ? $self->login : $self;
}
sub login {
@@ -371,6 +371,9 @@
$passwd =~ s/(["\\])/\\$1/g;
$passwd = qq("$passwd");
}
+ if ( $passwd eq '' ) {
+ $passwd = '*';
+ }
$id = qq("$id") if $id !~ /^".*"$/;