#!/usr/bin/perl use strict; use warnings; use diagnostics; use Net::POP3; use Term::ReadKey; # Read the mail accounts from a file called addresses # which resides in the script's directory open ADDRESSES, "./addresses"; # read all the lines my @addys = ; # close address file close ADDRESSES; # do the following for every address foreach my $address (@addys) { # chomp newlines chomp $address; # split address into username and hostname (my $user, my $host) = split /\s/, $address; # let the user enter his password print "Please enter the password for $user\@$host\:"; ReadMode( "noecho" ); my $pass = ReadLine(); ReadMode( "normal" ); print "\n"; # connect to host my $pop = Net::POP3->new( $host ) or do { print "Could not initialize connection.\n"; next; }; print "Connected to $host.\n"; # send USER $pop->user( $user ) or do { print "Could not send user name.\n"; next; }; print "Sent username $user.\n"; # send pass, receive number of messages my @a = $pop->pass( $pass ) or do { print "Could not send password.\n"; next; }; # print number of msg or complain about failed login if (defined $a[0]) { $pop->quit(); print "Messages: $a[0]\n"; } else { print "Login failed.\n"; } }