Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Mail check?

by petdance (Parson)
on May 24, 2001 at 00:14 UTC ( [id://82711]=note: print w/replies, xml ) Need Help??


in reply to Mail check?

Here's what I wrote to check my POP3 box, mostly stolen from Lincoln's stellar Network Programming With Perl. I added some functionality to make it fetch a message if I specify -r n.
#!/usr/bin/perl -w use constant VERSION => '1.03'; use strict; use Net::POP3; use Mail::Header; use Term::ReadPassword; use Getopt::Long; use lib "."; use Config::rc; my $filename = "~/.mcheckrc"; my $rcfile = new Config::rc( $filename ) or die $Config::rc::Error, "\ +n"; my $host = $rcfile->parm( "host" ) or die "Mail host not specified in +$filename\n"; my $user = $rcfile->parm( "user" ) or die "User name not specified in +$filename\n"; my $readno = 0; GetOptions( "r=i", \$readno ); my $password = read_password( "Password: " ) || exit 0; my $pop = Net::POP3->new( $host, Timeout=>30 ) or die "Can't connect t +o $host: $!\n"; my $messages = $pop->login( $user, $password ) or die "Can't log in: " +, $pop->message, "\n"; my $last = $pop->last; $messages += 0; # In case it's "OEO" (zero but true) print "mcheck v", VERSION, ": Inbox has $messages messages (", $messag +es-$last," new)\n"; if ( ($readno > 0) && ($readno <= $messages) ) { my $lines = $pop->get($readno); print @$lines, "\n"; } else { for my $msgnum (reverse(1..$messages)) { my $header = $pop->top( $msgnum ); my $parsedhead = Mail::Header->new($header); chomp( my $subject = $parsedhead->get('Subject')); chomp( my $from = $parsedhead->get('From')); $from = clean_from($from); printf "%4d %-25s %-50s\n", $msgnum, $from, $subject; } # for } # else $pop->quit; sub clean_from { local $_ = shift; /^"([^\"]+)" <\S+>/ && return $1; /^([^<>]+) <\S+>/ && return $1; /^\S+ \(([^\)]+)\)/ && return $1; return $_; }
Oh yah, it uses a Config::rc module that I've been working on, but you can just hardcode your server and username if you want.

xoxo,
Andy

%_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
"hack";print map delete$_{$_},split//,q<   andy@petdance.com   >

Replies are listed 'Best First'.
Re: Re: Mail check?
by odie (Sexton) on May 24, 2001 at 00:18 UTC
    Nice hack, but I doubt it will help, unless I install a pop3 server on my localhost. Hardly seems worth the bother, don't you agree? ;)
    Odie
    --
    I am a manual signature virus. Copy me please!
      Nice hack, but I doubt it will help, unless I install a pop3 server on my localhost. Hardly seems worth the bother, don't you agree? ;)

      Hey, I just supply the code. The decision to use the code is an exercise best left to the reader. :-)

      xoxo,
      Andy

      %_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
      'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
      "hack";print map delete$_{$_},split//,q<   andy@petdance.com   >
      

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2024-04-18 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found