Skip Menu |

This queue is for tickets about the Mail-IMAPClient CPAN distribution.

Report information
The Basics
Id: 9256
Status: resolved
Priority: 0/
Queue: Mail-IMAPClient

People
Owner: Nobody in particular
Requestors: joost [...] cassee.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Patch for SSL support
This patch will add SSL support to IMAPClient. It needs IO::Socket::SSL. You may want to make it optional in the same way as CRAM-MD5. Also changed login, because passwords were logged otherwise (because of multi-line string).
--- IMAPClient.pm 2003-07-02 19:28:54.000000000 +0200 +++ /usr/share/perl5/Mail/IMAPClient.pm 2004-12-30 13:08:10.000000000 +0100 @@ -8,6 +8,7 @@ use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); use Socket(); use IO::Socket(); +use IO::Socket::SSL(); use IO::Select(); use IO::File(); use Carp qw(carp); @@ -114,6 +115,7 @@ Authmechanism Authcallback Ranges Readmethod Showcredentials Prewritemethod + Ssl ) ) { no strict 'refs'; @@ -245,13 +247,15 @@ and $IO::Socket::INET::VERSION eq '1.25' and !$self->Port; %$self = (%$self, @_); - my $sock = IO::Socket::INET->new( + my $sock = ($self->Ssl ? IO::Socket::SSL->new : IO::Socket::INET->new); + my $dp = ($self->Ssl ? 'imaps(993)' : 'imap(143)'); + $sock->configure({ PeerAddr => $self->Server , - PeerPort => $self->Port||'imap(143)' , + PeerPort => $self->Port||$dp , Proto => 'tcp' , Timeout => $self->Timeout||0 , Debug => $self->Debug , - ) ; + }) ; unless ( defined($sock) ) { @@ -302,9 +306,10 @@ my $id = $self->User; my $has_quotes = $id =~ /^".*"$/ ? 1 : 0; - my $string = "Login " . ( $has_quotes ? $id : qq("$id") ) . " " . - "{" . length($self->Password) . - "}\r\n".$self->Password."\r\n"; + #my $string = "Login " . ( $has_quotes ? $id : qq("$id") ) . " " . + # "{" . length($self->Password) . + # "}\r\n".$self->Password."\r\n"; + my $string = "Login " . ( $has_quotes ? $id : qq("$id") ) . " " . $self->Password . "\r\n"; $self->_imap_command($string) and $self->State(Authenticated); # $self->folders and $self->separator unless $self->NoAutoList; @@ -1628,7 +1633,7 @@ return undef; } # successfully wrote to other end, keep going... - $count += $ret; + $count += $ret if defined($ret); LINES: while ( $iBuffer =~ s/^(.*?\x0d?\x0a)// ) { my $current_line = $1; @@ -2167,8 +2172,8 @@ (?:"[^"]*"|NIL)\s+ # "delimiter" or NIL (?:"([^"]*)"|(.*))\x0d\x0a$ # Name or "Folder name" /ix; - $folders[-1] = '"' . $folders[-1] . '"' - if $1 and !$self->exists($folders[-1]) ; + #$folders[-1] = '"' . $folders[-1] . '"' + # if $1 and !$self->exists($folders[-1]) ; # $self->_debug("folders: line $list[$m]: 1=$1 and 2=$2\n"); }
Subject: Patch for SSL support - Enhanced, applied in Debian
From: Gunnar Wolf
I tested the patch provided by Joost Cassee for inclusion in the Debian release of your module - It works correctly. I included it, updated the Makefile.PL to reflect a prereq on IO::Socket::SSL, and wrote a simple blurb of documentation about it. I am attaching here the updated patch.
--- libmail-imapclient-perl-2.2.9+deb.orig/Makefile.PL +++ libmail-imapclient-perl-2.2.9+deb/Makefile.PL @@ -28,6 +28,7 @@ 'Fcntl' => 0, 'IO::Select' => 0, 'IO::File' => 0, + 'IO::Socket::SSL'=>0, 'Data::Dumper' => 0, 'Carp' => 0, }, --- libmail-imapclient-perl-2.2.9+deb.orig/IMAPClient.pm +++ libmail-imapclient-perl-2.2.9+deb/IMAPClient.pm @@ -8,6 +8,7 @@ use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); use Socket(); use IO::Socket(); +use IO::Socket::SSL(); use IO::Select(); use IO::File(); use Carp qw(carp); @@ -114,6 +115,7 @@ Authmechanism Authcallback Ranges Readmethod Showcredentials Prewritemethod + Ssl ) ) { no strict 'refs'; @@ -245,13 +247,15 @@ and $IO::Socket::INET::VERSION eq '1.25' and !$self->Port; %$self = (%$self, @_); - my $sock = IO::Socket::INET->new( + my $sock = ($self->Ssl ? IO::Socket::SSL->new : IO::Socket::INET->new); + my $dp = ($self->Ssl ? 'imaps(993)' : 'imap(143)'); + $sock->configure({ PeerAddr => $self->Server , - PeerPort => $self->Port||'imap(143)' , + PeerPort => $self->Port||$dp , Proto => 'tcp' , Timeout => $self->Timeout||0 , Debug => $self->Debug , - ) ; + }) ; unless ( defined($sock) ) { @@ -302,9 +306,10 @@ my $id = $self->User; my $has_quotes = $id =~ /^".*"$/ ? 1 : 0; - my $string = "Login " . ( $has_quotes ? $id : qq("$id") ) . " " . - "{" . length($self->Password) . - "}\r\n".$self->Password."\r\n"; + #my $string = "Login " . ( $has_quotes ? $id : qq("$id") ) . " " . + # "{" . length($self->Password) . + # "}\r\n".$self->Password."\r\n"; + my $string = "Login " . ( $has_quotes ? $id : qq("$id") ) . " " . $self->Password . "\r\n"; $self->_imap_command($string) and $self->State(Authenticated); # $self->folders and $self->separator unless $self->NoAutoList; @@ -1628,7 +1633,7 @@ return undef; } # successfully wrote to other end, keep going... - $count += $ret; + $count += $ret if defined($ret); LINES: while ( $iBuffer =~ s/^(.*?\x0d?\x0a)// ) { my $current_line = $1; @@ -1906,7 +1911,7 @@ return undef; } # successfully wrote to other end, keep going... - $count += $ret; + $count += $ret if defined($ret); LINES: while ( $iBuffer =~ s/^(.*?\x0d?\x0a)// ) { my $current_line = $1; @@ -2167,8 +2172,8 @@ (?:"[^"]*"|NIL)\s+ # "delimiter" or NIL (?:"([^"]*)"|(.*))\x0d\x0a$ # Name or "Folder name" /ix; - $folders[-1] = '"' . $folders[-1] . '"' - if $1 and !$self->exists($folders[-1]) ; + #$folders[-1] = '"' . $folders[-1] . '"' + # if $1 and !$self->exists($folders[-1]) ; # $self->_debug("folders: line $list[$m]: 1=$1 and 2=$2\n"); } --- libmail-imapclient-perl-2.2.9+deb.orig/IMAPClient.pod +++ libmail-imapclient-perl-2.2.9+deb/IMAPClient.pod @@ -3414,6 +3414,25 @@ parameter/value pairs to the method, or later by calling the parameter's eponymous object method. +=head2 Ssl + +Example: + + $is_ssl_active = $imap->Ssl(); + # or: + $imap->Ssl($activate_ssl); + +Specifies whether a connection should be established using a SSL (cyphered) +channel or via a regular clear TCP connection. Of course, setting this +parameter makes sense only before the connection is established. + +Please note that this parameter was specifically added for the Debian +packaging. If you are developing software to be deployed over different +machines, we suggest you not to use it - or to specify your users to install +this patch. You can get it at Debian's bug tracking system at +L<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=111960>, or at CPAN's +L<http://rt.cpan.org/NoAuth/Bug.html?id=9256>. + =cut
New maintainer. There is no need for this patch: the SSL socket can be passed in with new(). I think that is a much cleaner way. -- MarkOv