### CMail::In::imaps # module for checking for messages in imap mailboxes over SSL package CMail::In::imaps; use strict; BEGIN { use CMail::In::imap; use vars qw($VERSION @ISA); $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; @ISA = qw( CMail::In::imap ); } use IO::Socket::SSL 0.91; use vars qw(%connections %cmdnum); # For keeping the connection cache, so we don't have to reconnect multiple # times if we're checking multiple mailboxes on the same IMAP server %connections = (); # internal methods # connect_login($host,$port,$user,$pass) - opens a socket to the given # host and port and returns it. If someone wants to implement SSL, I # suggest overloading just this function, if that's all that's required. sub connect_login { my $self = shift; my $host = shift; my $port = shift || '993'; my $user = shift; my $pass = shift; my $id = "$host:$port:$user"; if (defined $connections{$id}) { $connections{$id}->{usage}++; return $connections{$id}->{socket}; } my $socket = IO::Socket::SSL->new("$host\:$port"); if ( not defined $socket ) { die "imaps: couldn't open socket to $host:$port: $!\n"; } $connections{$id} = { 'socket' => $socket, 'usage' => 1, }; my $answer = $self->send_cmd($socket,"LOGIN $user $pass"); if ( $answer =~ /BAD|NO/ ) { die "imap: couldn't login to $host: $answer\n"; } return $socket; } 1;