Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

POP3 client - end

by w3b (Beadle)
on Dec 04, 2005 at 15:39 UTC ( [id://513963]=sourcecode: print w/replies, xml ) Need Help??
Category: E-Mail Programs
Author/Contact Info haptor@op.pl #perl @ ircnet.pl
Description: I wrote (for me) nice script I use it always when i want to check mail.... i hope that somebody use this script and write me about it. Maybe you see some bad moves, or something.... tha n write in reply... I have to learn perl always and everywhere. Please comment this source
#!/usr/bin/perl
use warnings;
use strict;
use Net::POP3;
use Tie::File;

tie my @file, "Tie::File", "dane";

if ($#file != 2){
print "Write pop3 server adress:\n";
chomp($file[0] = <STDIN>);
print "Write login:\n";
chomp($file[1] = <STDIN>);
print "Write password:\n";
chomp($file[2] = <STDIN>);
}

my $time = scalar localtime;

my $pop = Net::POP3->new($file[0]);
my $res = $pop->login($file[1], $file[2]);

if ($res){
print"On $time e-mail status inbox: $res post \n";
} else {
print "Couldn't connect $!\n";
exit;
}

my $msg; my $msgnum;

do{
print "Write id(number) email to read subject:\n";
chomp($msgnum = <STDIN>);
} while($msgnum > $res);

$msg = $pop->get($msgnum);

for my $line ( @$msg ) {
if( $line =~ /^Subject:(.*)/ ) {
 print "Subject is $1\n";
 last
} }

print "Read e-mail? [y/n]\n";
chomp(my $ans = <STDIN>);
if ($ans =~ /y/i){
 while( my $line = shift @$msg ) {
   last while $line =~ /^Status:/;
}

my $nline = 0;

for( @$msg )
{
    $nline += 1;
    print "$nline> $_";
} } elsif ($ans =~ /n/i){
exit;
} else {
print "Bad!";
exit;
}

$pop->quit();
Replies are listed 'Best First'.
Re: POP3 client - end
by Discipulus (Canon) on Dec 05, 2005 at 08:59 UTC
    thnks for this scripts.. but I dont understand his behaviour...

    at glance:
    1-If i say n (I dont wanna see that mail)the program seems to exit BUT if I launch the perl another time it REMEMBER my account !! not so kind.

    2-if I say y it exit in the same way
    C:\prova>pop3client.pl Write pop3 server adress: mail.nowhere.it Write login: +++++++++++ Write password: itWasBetterAshdowedPWD On Mon Dec 5 09:55:07 2005 e-mail status inbox: 111 post Write id(number) email to read subject: 1 Subject is Read e-mail? [y/n] n C:\prova>pop3client.pl On Mon Dec 5 09:55:31 2005 e-mail status inbox: 111 post Write id(number) email to read subject: 2 Subject is Chiusura ticket n.:1543. codice servizio:HOSTING Mail auto +matica. Read e-mail? [y/n] y C:\prova>

      It's a "feature" the OP built in using Tie::File.

      To disable it, change this line
          tie my @file, "Tie::File", "dane";
      to simply say
          my @file;

      Cheers, Sören

      Good idea i do that^^ thx, maybe my script will be more useful... thx
        No I wrote new version^^ thx for suggestion
        #!/usr/bin/perl use warnings; use strict; use Net::POP3; use Tie::File; use Term::ReadKey; tie my @file, "Tie::File", "dane"; if ($#file != 1){ print "Write pop3 server adress:\n"; chomp($file[0] = <STDIN>); print "Write login:\n"; chomp($file[1] = <STDIN>); } my $time = scalar localtime; my ($msg, $msgnum); print "Write password:\n"; ReadMode 4; chomp(my $key = <STDIN>); ReadMode 0; my $pop = Net::POP3->new($file[0]); my $res = $pop->login($file[1], $key); if ($res){ print"Connect!\nOn $time e-mail status inbox: $res post \n"; } else { print "Couldn't connect $!\n"; exitl } while($res){ do{ do{ print "Write id(number) email to read subject:\n"; chomp($msgnum = <STDIN>); next if $msgnum !~ /\d/; } while ($msgnum > $res); $msg = $pop->get($msgnum); for my $line ( @$msg ) { if( $line =~ /^Subject:(.*)/ ) { print "Subject is:\n $1\n"; last } } print "Read e-mail? [y/n]\n"; chomp(my $ans = <STDIN>); if ($ans =~ /y/i){ while( my $line = shift @$msg ) { last while $line =~ /^Status:/; } my $nline = 0; for( @$msg ) { print ++$nline,'>', $_; } } elsif ($ans =~ /n/i){ } else { print "Bad!\n"; } } } $pop->quit();
        I wait for next suggestion;p what do think about many account??

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://513963]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found