in reply to POP3 client - end

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>

Replies are listed 'Best First'.
Re^2: POP3 client - end
by Happy-the-monk (Canon) on Dec 05, 2005 at 09:12 UTC

    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

Re^2: POP3 client - end
by w3b (Beadle) on Dec 05, 2005 at 12:37 UTC
    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??
        dear w3b

        thks for this script, but I prefered to rewrite it a bit to add some featurs and I have not liked so much the tied file. I have wrapped the display function in 3 subs for readbility and to print the text without headers. Need a regexed monk to grind this line: $text =~s/<[^>]*>//gs;to remove html tags from the text result.
        greetings from roma Lor* #!/usr/bin/perl use warnings; use strict; use Net::POP3; #use Tie::File; use Term::ReadKey; #tie my @file, "Tie::File", "dane"; my @file; 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); my $sep_bold = '#'x80; print "Write password:\n"; ReadMode 'noecho'; chomp(my $key = <STDIN>); ReadMode 'restore'; my $pop = Net::POP3->new($file[0]); my $res = $pop->login($file[1], $key); if ($res>0){print"$sep_bold\nConnect!\nOn $time e-mail status inbox: $ +res post \n$sep_bold\n";} else {print "$sep_bold\nCouldn't connect $!\n$sep_bold\n";exit;} my $syntax = "\tafter login you have this choices:\n \ta number to print the subj of specified mail. \ta range of number to do the same for specified messages. \tall to print out all the subjects. \thnum (e.g. h99) to print the header only of the message. \trnum (e.g. r99) to print only the text of the message. \tx to quit clean \t? to print this help.\n\n"; while($res) { my $msg_id; my $msg_title; my $msg_text; print "$sep_bold\n Make your choice! (all | 99 | 1-99 | h99 | r99 | + x | ?) \n$sep_bold\n"; chomp($msg_id = <STDIN>); if ($msg_id eq 'all') # tutti i subj {foreach my $item(1..$res) {print "$item - ",&get_subject($item),"\n"; +}} elsif ($msg_id =~/^(\d+)-(\d+)$/) # range di subj {foreach my $item($1..$2){print "$item - ",&get_subject($item),"\n";}} elsif ($msg_id =~/^(\d+)$/) # un solo subj {print "$msg_id - ",&get_subject($1),"\n";} elsif ($msg_id =~/^h\s?(\d+)$/i) # header di uno solo msg {print "$msg_id - ",&get_subject($1),"\n";my $ref = &get_head($1);prin +t "\t$_" for @$ref;} elsif ($msg_id =~/^r\s?(\d+)$/i) # testo di uno solo msg {print "$msg_id :\n ";print &get_text($1)} elsif ($msg_id =~/\?/i) # help {print "$sep_bold\nSYNTAX $0:\n$syntax\n$sep_bold\n"} elsif ($msg_id =~/x|q|exit|quit/i) # esci {print "GOODBY ..\n ";$pop->quit();exit;} else {next} } ############################ subroutines ############################# +##### sub get_subject { my $msg_id = shift; my $msg = $pop->get($msg_id); for my $line ( @$msg ) {if( $line =~ /^Subject:(.*)/ ) { return $1}} } ############################ sub get_head { my $msg_id = shift; my $msg = $pop->top($msg_id); return $msg; } ############################ sub get_text { my $msg_id = shift; my $head_ref = &get_head($msg_id); my $msg = $pop->get($msg_id); for (@$head_ref){shift @$msg } # cut headers my $text = "@$msg";#$line=~s/<html>.*<\/html>/''/g; $text =~s{<([^>])+>|&([^;])+;}{}gsx; return $text; #for my $line ( @$msg ){print "\t$line"} }