Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Peeking into a POP3-SSL exchange

by sg (Pilgrim)
on Sep 06, 2007 at 03:27 UTC ( [id://637314]=perlquestion: print w/replies, xml ) Need Help??

sg has asked for the wisdom of the Perl Monks concerning the following question:

Making changes mutatis mutandis to Net::SMTP::SSL, I "created" Net::POP3::SSL. Then used the test code given below to connect to a pop3 server (using Net::POP3 and Net::POP3::SSL, one at a time). Both attempts succeeded, as shown by the output.

However, both outputs look alike (except for the leading tag)!

What exactly needs to be done in the user-code so that the output would explicitly show ssl'ish things happening in one case and non-ssl'ish things happening in the other case? For example, how would one print out the messages being exchanged by the local machine and the pop server and show that in one case the messages are in plain text and in the other case the messages are ssl-encrypted?

#!/use/bin/perl BEGIN {(*STDERR = *STDOUT) || die;} use diagnostics; use warnings; use strict; $| = 1; { package Net::POP3::SSL; # $Id:,v 1.1 2004/07/20 03:22:18 cwest Exp $ use strict; use vars qw[$VERSION @ISA]; $VERSION = sprintf "%d.%02d", split m/\./, (qw$Revision: 1.1 $)[1]; use IO::Socket::SSL; use Net::POP3; @ISA = ( 'IO::Socket::SSL', grep { $_ ne 'IO::Socket::INET' } @Net::POP3::ISA ); no strict 'refs'; foreach ( keys %Net::POP3:: ) { next unless defined *{$Net::POP3::{$_}}{CODE}; *{$_} = \&{"Net::POP3::$_"}; } 1; } my $pop_host = '<>'; my $pop_port = 995; my $user_id = '<user_id>'; my $password = '<password>'; my %pop_options = ( Host => $pop_host, LocalPort => $pop_port, #ResvPort => 1, # Timeout => 30, Debug => 4, ); my %pop_ssl_options = ( Host => $pop_host, Port => $pop_port, #ResvPort => 1, # Timeout => 30, Debug => 4, ); test_pop(); sub test_pop { my $mail =''; if(!($mail = Net::POP3::SSL->new(%pop_ssl_options))) #if(!($mail = Net::POP3->new(%pop_options))) { print "ERROR: Could not open $pop_host\n$!\n"; return -1; } my $number_of_messages = $mail->login($user_id, $password); if(!$number_of_messages) { (defined $number_of_messages) or print "ERROR: Login error for +$pop_host\n$!\n"; $mail->quit(); return -1; } print "Number of messages: $number_of_messages\n"; } __END__ Output: Net::POP3>>> Net::POP3(2.29) Net::POP3>>> Net::Cmd(2.29) Net::POP3>>> Exporter(5.60) Net::POP3>>> IO::Socket::INET(1.31) Net::POP3>>> IO::Socket(1.30) Net::POP3>>> IO::Handle(1.27) Net::POP3=GLOB(0x1d699cc)<<< +OK hello from popgate on 2.38.1 Net::POP3=GLOB(0x1d699cc)>>> USER <user_name> Net::POP3=GLOB(0x1d699cc)<<< +OK password required. Net::POP3=GLOB(0x1d699cc)>>> PASS .... Net::POP3=GLOB(0x1d699cc)<<< +OK maildrop ready, 452 messages (5836296 + octets) (6062525 3105357824) Number of messages: 452 Net::POP3::SSL>>> Net::POP3::SSL(1.01) Net::POP3::SSL>>> IO::Socket::SSL(1.08) Net::POP3::SSL>>> IO::Socket::INET(1.31) Net::POP3::SSL>>> IO::Socket(1.30) Net::POP3::SSL>>> IO::Handle(1.27) Net::POP3::SSL>>> Exporter(5.60) Net::POP3::SSL>>> Net::Cmd(2.29) Net::POP3::SSL=GLOB(0x1d69a0c)<<< +OK hello from popgate on pop106.plu 2.38.1 Net::POP3::SSL=GLOB(0x1d69a0c)>>> USER <user_name> Net::POP3::SSL=GLOB(0x1d69a0c)<<< +OK password required. Net::POP3::SSL=GLOB(0x1d69a0c)>>> PASS .... Net::POP3::SSL=GLOB(0x1d69a0c)<<< +OK maildrop ready, 447 messages (58 +08500 octets) (6034729 3105357824) Number of messages: 447

Replies are listed 'Best First'.
Re: Peeking into a POP3-SSL exchange
by ikegami (Patriarch) on Sep 06, 2007 at 04:36 UTC

    Read the DEBUGGING section of IO::Socket::SSL's docs.

    It's not a per-object flag, it's a global flag that can be set as follows:
    use IO::Socket::SSL qw( debug4 );
    $IO::Socket::SSL::DEBUG = 4;

      Fri Sep 21 14:38:22 2007 Net::POP3::SSL>>> Net::POP3::SSL(1.01) Net::POP3::SSL>>> IO::Socket::SSL(1.08) Net::POP3::SSL>>> IO::Socket::INET(1.29) Net::POP3::SSL>>> IO::Socket(1.29) Net::POP3::SSL>>> IO::Handle(1.25) Net::POP3::SSL>>> Exporter(5.58) Net::POP3::SSL>>> Net::Cmd(2.26) Net::POP3::SSL=GLOB(0x1eb7a50)<<< * OK Microsoft Exchange Server 2007 IMAP4 service ready err There was a problem connecting to the server. Anyone try this with Microsoft Exchange 2007. It seems to get a response from the IMAP service, but never returns a true value.
        Instead of replying to me in an old thread with this unrelated question, you should post this new problem in a new thread.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://637314]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-21 11:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found