NAME

Net::POP3::PerMsgHandler - subroutine for per message from POP3 server

SYNOPSIS

Quick summary of what the module does.

Perhaps a little code snippet.

use Net::POP3::PerMsgHandler;
use YAML::Syck;
use Perl6::Say;

my $cfg = LoadFile('config.yml');

eval {
    my $count = per_message(
        username => $cfg->{username},
        password => $cfg->{password},
        host     => $cfg->{host},
        handler  => sub {
            my ($msg, $ctl) = @_;

            my $email   = $msg->email_mime; # Email::MIME object.
            say "Subject: ".$email->header('Subject');

            $ctl->delete(0) # default
            $ctl->quit(0)   # default
        },
    );
};

say $@ if $@; # connection failed etc...

# Subject: Re: Spam collection
# Subject: Congratulations, You're a finalist
# Subject: Software Secret: WARNING Reading this could change your life
# ...

EXPORT FUNCTIONS

per_message

OPTIONS

username

required.

password

required.

host

required.

port

optional.

timeout

optional.

handler

code reference required.

The callback is given two arguments. The first is a Net::POP3::PerMsgHandler::Message object. The second is a Net::POP3::PerMsgHandler::Control object.

Executes the callback for each message.

debug

optional.

EXAMPLES

ex1 - delete message subject starting with SPAM

my $count = per_message(
    username => $cfg->{username},
    password => $cfg->{password},
    host     => $cfg->{host},
    handler  => sub {
        my ($msg, $ctl) = @_;

        my $email   = $msg->email_mime;
        my $is_spam = $email->header('Subject') =~ m/^SPAM/;

        $ctl->delete(1) if $is_spam;
    },
);

ex2 - find specified message and save attached files and delete.

my $count = per_message(
    username => $cfg->{username},
    password => $cfg->{password},
    host     => $cfg->{host},
    handler  => sub {
        my ($msg, $ctl) = @_;

        my $email = $msg->email_mime;
        return unless $email->body =~ m/\AUUID: 12345/sm;

        for my $part ($email->parts) {
            next unless defined $part->filename;
            $part->body > io( $part->filename );
        }

        $ctl->delete(1);
        $ctl->quit(1);
    },
);

SEE ALSO

Net::POP3::PerMsgHandler, Net::POP3, Email::MIME, Email::MIME::Attachment::Stripper, Mail::Message, Mail::Message::Attachment::Stripper

AUTHOR

bokutin, <bokutin at cpan.org>

COPYRIGHT & LICENSE

Copyright 2007 bokutin, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.