Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use Net::POP3;
- use Date::Parse;
- my $popserver = 'mail.example.com';
- my $username = 'funtimes@example.com';
- my $password = 'dogs';
- my $pop = Net::POP3->new($popserver) or die "Unable to connect to $popserver.\n";
- if (!defined $pop->login($username, $password)) {
- die "Unable to login to pop server.\n";
- }
- my $msgnums = $pop->list; # hashref of msgnum => size
- foreach my $msgnum (keys %$msgnums) {
- my $msg = $pop->get($msgnum);
- my ($timestamp,$time,$from,$body);
- # parse headers
- while (@$msg) {
- local $_ = shift(@$msg); # shave a line off and parse it
- if (/^Date: (.*)/) {
- $timestamp = $1;
- $time = str2time($timestamp);
- } elsif (/^From: (.*)/) {
- $from = $1;
- } elsif (/^\s$/) { # blank line means end of headers, exit loop
- last;
- }
- }
- # remaining lines in @$msg are the body
- $body = join('',@$msg);
- # *** We now have ($time,$from,$body) - DO STUFF ***
- # delete message from POP server
- $pop->delete($msgnum);
- }
- $pop->quit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement