#!/usr/bin/perl use IO::Socket; use IO::Select; $user = shift || die "Usage: $0 user password server msgnum\n"; $pass = shift || die "Usage: $0 user password server msgnum\n"; $server = shift || die "Usage: $0 user password server msgnum\n"; $msgnum = shift || die "Usage: $0 user password server msgnum\n"; sub setgreen { print "\033[00;32m"; } sub setred { print "\033[00;31m"; } sub setnormal { printf "\033[00m"; } $dstsock = IO::Socket::INET->new( PeerAddr => $server, PeerPort => 110, Proto => 'tcp'); $readables = IO::Select->new(); $readables->add($dstsock); $notdone = 1; while ($notdone) { my @ready = $readables->can_read(0); foreach $sock (@ready) { $data = <$dstsock>; if ($data) { setred; print "$data"; setnormal; if ($data =~ /^\+OK Qpopper/) { print $dstsock "user $user\r\n"; setgreen(); print "user $pass\r\n"; setnormal; } if ($data =~ /^\+OK Password/) { print $dstsock "pass $pass\r\n"; setgreen(); print "pass $pass\r\n"; setnormal; } if ($data =~ /^\+OK $user/) { print $dstsock "retr $msgnum\r\n"; setgreen(); print "retr $msgnum\r\n"; setnormal; } if ($data =~ /^\.$/) { print $dstsock "quit\r\n"; setgreen(); print "quit\r\n"; setnormal; } } else { $notdone = 0; close $dstsock; close $srcsock; } } }