Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Almost success

by BUU (Prior)
on Dec 04, 2005 at 01:53 UTC ( [id://513881]=note: print w/replies, xml ) Need Help??


in reply to Almost success

If by "But!We see many unnecessarys information....;( i want to see only message, but i don't know how to write this" you mean you don't want to see the headers preceding the content body, you simply need to skip them when output the message. Headers in smtpd are delimited by an empty line or two newlines in a row. For example:
while( my $line = shift @$msg ) { last unless length $line; } for( @$msg ) { print "Body: $_"; }
The first while loop removes the first element from the array each time it loops. If the element is empty, signifying we have reached the end of the headers, we exit the loop. The next loop can simply print the remainder.

I should note that you are unlikely to acheive good results if you have some sort of multipart message, you might want to consider using an actual parser from CPAN.

Replies are listed 'Best First'.
Re^2: Almost success
by w3b (Beadle) on Dec 04, 2005 at 07:17 UTC
    Thank you very very much^^ now my script looks nice^^ Here is source:
    #!/usr/bin/perl use warnings; use strict; use Net::POP3; my $time = scalar localtime; my $pop3 = "pop3.poczta.onet.pl"; my $login = "haptor\@op.pl"; my $pass = "******************"; my $pop = Net::POP3->new($pop3); my $res = $pop->login($login, $pass); 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();
    If somebody use this scripts i'll be very happy^^ i love Perl;p

Log In?
Username:
Password:

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

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

    No recent polls found