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"} }

In reply to Re^4: POP3 client - end by Discipulus
in thread POP3 client - end by w3b

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.