How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!! - Presentation Transcript
Perl
Email
Project
the 2007 PEP talk!!!
How I Learned To
Stop Worrying
and
Love Email
rjbs
@cpan.org
we’re hiring: http://xrl.us/pobox
Perl Email Project
PEP
Email::
simple
efficient
accurate
less processor time
less memory
fewer classes
fewer methods
LESS OF A PAIN
IN THE ASS
Make Email
Handling Suck
Less
writing better modules
maintaining old modules
sharing
knowledge
Modules!
Frameworks
Mail-Box
Email::
Message Objects
Email::Simple
&
Email::MIME
use Email::Simple;
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => ‘rjbs@cpan.org’,
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => ‘1099’,
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => ‘1099’,
Keyword => ‘1040’,
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => ‘1099’,
Keyword => ‘1040’,
],
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => ‘1099’,
Keyword => ‘1040’,
],
body => “[ insert threatening text here ]”
use Email::Simple;
my $email = Email::Simple->new($string);
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => ‘1099’,
Keyword => ‘1040’,
],
body => “[ insert threatening text here ]”
);
use Email::Simple;
my $email = Email::Simple->new( \\$string );
use Email::Simple;
my $email = Email::Simple->new( \\$string );
$email->body_set( \\$new_body );
use Email::Simple;
my $email = Email::Simple->new( \\$string );
$email->body_set( \\$new_body );
use Email::Simple::FromHandle;
use Email::Simple;
my $email = Email::Simple->new( \\$string );
$email->body_set( \\$new_body );
use Email::Simple::FromHandle;
my $email = Email::SimpleFromHandle->new(
use Email::Simple;
my $email = Email::Simple->new( \\$string );
$email->body_set( \\$new_body );
use Email::Simple::FromHandle;
my $email = Email::SimpleFromHandle->new(
$input_handle
use Email::Simple;
my $email = Email::Simple->new( \\$string );
$email->body_set( \\$new_body );
use Email::Simple::FromHandle;
my $email = Email::SimpleFromHandle->new(
$input_handle
);
use Email::Simple;
my $email = Email::Simple->new( \\$string );
$email->body_set( \\$new_body );
use Email::Simple::FromHandle;
my $email = Email::SimpleFromHandle->new(
$input_handle
);
$email->stream_to($output_handle);
my $email = Email::MIME->new(\\$string);
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
],
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
],
attributes =>
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
],
attributes =>
{ content_type => ‘multipart/mixed’ },
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
],
attributes =>
{ content_type => ‘multipart/mixed’ },
parts => [
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
],
attributes =>
{ content_type => ‘multipart/mixed’ },
parts => [
Email::MIME->create(...),
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
],
attributes =>
{ content_type => ‘multipart/mixed’ },
parts => [
Email::MIME->create(...),
Email::MIME->create(...),
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
],
attributes =>
{ content_type => ‘multipart/mixed’ },
parts => [
Email::MIME->create(...),
Email::MIME->create(...),
],
my $email = Email::MIME->new(\\$string);
use Email::MIME::Creator;
my $email = Email::MIME->create(
header => [
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
],
attributes =>
{ content_type => ‘multipart/mixed’ },
parts => [
Email::MIME->create(...),
Email::MIME->create(...),
],
);
problems
still not efficient enough
FromHandle doesn’t do MIME
problems
still not efficient enough
FromHandle doesn’t do MIME
Email::MIME doesn’t stream
problems
still not efficient enough
FromHandle doesn’t do MIME
Email::MIME doesn’t stream
fairly small feature set*
MIME::Entity
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
‘Keyword:’ => [ 1099, 1040 ],
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
‘Keyword:’ => [ 1099, 1040 ],
Data => [ “This might be an audit.” ],
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
‘Keyword:’ => [ 1099, 1040 ],
Data => [ “This might be an audit.” ],
);
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
‘Keyword:’ => [ 1099, 1040 ],
Data => [ “This might be an audit.” ],
);
$entity->attach(
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
‘Keyword:’ => [ 1099, 1040 ],
Data => [ “This might be an audit.” ],
);
$entity->attach(
Path => ‘./reports/audit-results.pdf’,
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
‘Keyword:’ => [ 1099, 1040 ],
Data => [ “This might be an audit.” ],
);
$entity->attach(
Path => ‘./reports/audit-results.pdf’,
Type => ‘application/pdf’,
my $entity = MIME::Entity->new($input_handle);
my $entity = MIME::Entity->new(\\@lines);
my $entity = MIME::Entity->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
‘Keyword:’ => [ 1099, 1040 ],
Data => [ “This might be an audit.” ],
);
$entity->attach(
Path => ‘./reports/audit-results.pdf’,
Type => ‘application/pdf’,
);
problems
problems
really big (loads 50+ extra
modules)
problems
really big (loads 50+ extra
modules)
large, sometimes confusing
interface
problems
really big (loads 50+ extra
modules)
large, sometimes confusing
interface
history of subtle bugs
Mail::Message
(a Mail::Box Production)
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => 1099,
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => 1099,
Keyword => 1040,
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => 1099,
Keyword => 1040,
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => 1099,
Keyword => 1040,
data => “This might be an audit.\\n”,
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => 1099,
Keyword => 1040,
data => “This might be an audit.\\n”,
file => ‘./reports/audit-results.pdf’,
my $mail = Mail::Message->read($input_handle);
my $mail = Mail::Message->build(
To => ‘rjbs@cpan.org’,
From => ‘IRS <the.man@irs.gov>’,
Subject => ‘Please See Me’,
Keyword => 1099,
Keyword => 1040,
data => “This might be an audit.\\n”,
file => ‘./reports/audit-results.pdf’,
);
$mail->body->parts;
$mail->body->attach(@things);
$mail->body->part(1)->delete;
my @parts = $mail->body->parts(
$mail->body->parts;
$mail->body->attach(@things);
$mail->body->part(1)->delete;
my @parts = $mail->body->parts(
sub { $_[0]->mimeType eq ‘text/html }
$mail->body->parts;
$mail->body->attach(@things);
$mail->body->part(1)->delete;
my @parts = $mail->body->parts(
sub { $_[0]->mimeType eq ‘text/html }
);
$mail->body->parts;
$mail->body->attach(@things);
$mail->body->part(1)->delete;
my @parts = $mail->body->parts(
sub { $_[0]->mimeType eq ‘text/html }
);
$_->delete for @parts;
$mail->body->parts;
$mail->body->attach(@things);
$mail->body->part(1)->delete;
my @parts = $mail->body->parts(
sub { $_[0]->mimeType eq ‘text/html }
);
$_->delete for @parts;
$mail->body->rebuild;
problems
problems
really big (loads 40+ extra
modules)
problems
really big (loads 40+ extra
modules)
large, sometimes confusing
interface
Mail::Internet
Mail::Internet
MIME::Lite
MIME::Lite
Email::Abstract
my $abstract = Email::Abstract->new($thing);
my $abstract = Email::Abstract->new($thing);
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
$abstract->set_header(Subject => ‘Foo!’);
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
$abstract->set_header(Subject => ‘Foo!’);
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
$abstract->set_header(Subject => ‘Foo!’);
$abstract->get_body;
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
$abstract->set_header(Subject => ‘Foo!’);
$abstract->get_body;
$abstract->set_body(‘This is a short body!’);
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
$abstract->set_header(Subject => ‘Foo!’);
$abstract->get_body;
$abstract->set_body(‘This is a short body!’);
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
$abstract->set_header(Subject => ‘Foo!’);
$abstract->get_body;
$abstract->set_body(‘This is a short body!’);
$abstract->as_string;
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
$abstract->set_header(Subject => ‘Foo!’);
$abstract->get_body;
$abstract->set_body(‘This is a short body!’);
$abstract->as_string;
my $abstract = Email::Abstract->new($thing);
$abstract->get_header(‘Subject’);
$abstract->set_header(Subject => ‘Foo!’);
$abstract->get_body;
$abstract->set_body(‘This is a short body!’);
$abstract->as_string;
$abstract->cast(‘Mail::Internet’);
Email::Simple & ::MIME
MIME::Entity
Mail::Internet
Mail::Message
more coming
problems
problems
missing some key methods
problems
missing some key methods
needs more testing for
complex message types
problems
missing some key methods
needs more testing for
complex message types
can be inefficient
suggestion
suggestion
learn all of Email::Simple and
most of Email::MIME
suggestion
learn all of Email::Simple and
most of Email::MIME
for sending your own simple
emails, use these
suggestion
suggestion
learn the basics of Mail::Message
suggestion
learn the basics of Mail::Message
use it if you know you’ll need to use
more of Mail::Box in the future
suggestion
learn the basics of Mail::Message
use it if you know you’ll need to use
more of Mail::Box in the future
use it if you have complex encoding or
MIME-handling requirements
suggestion
suggestion
learn the basics of handling
MIME::Entity messages
suggestion
learn the basics of handling
MIME::Entity messages
lots of code uses them
suggestion
learn the basics of handling
MIME::Entity messages
lots of code uses them
use MIME::Entity when you need to
cope with crappy input that nothing
else can parse
suggestion
suggestion
if you write an API that is passed an
email message, consider using
Abstract
suggestion
if you write an API that is passed an
email message, consider using
Abstract
if it exists primarily for handling
email, pick a more complete library to
use, and stick to it.
Email Collections
Mail::Box
my $maildir = Mail::Box::Maildir->new
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
$message->delete;
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
$message->delete;
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
$message->delete;
my $newmsg = Mail::Message->new(...);
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
$message->delete;
my $newmsg = Mail::Message->new(...);
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
$message->delete;
my $newmsg = Mail::Message->new(...);
$maildir->addMessage($newmsg);
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
$message->delete;
my $newmsg = Mail::Message->new(...);
$maildir->addMessage($newmsg);
my $maildir = Mail::Box::Maildir->new
folder => ‘./Maildir/’,
);
my $message = $maildir->message(4);
$message->delete;
my $newmsg = Mail::Message->new(...);
$maildir->addMessage($newmsg);
$maildir->write;
folders over the net
subfolders
threading
delayed reading
&
construction
suggestion
suggestion
if you need to manage
mailboxes, just use it
suggestion
if you need to manage
mailboxes, just use it
there isn’t really any
alternative
suggestion
if you need to manage
mailboxes, just use it
there isn’t really any
alternative
unless you count...
Email::Folder
(and friends)
a bunch of modules
Email::Feature::Type
Email::FolderType
use Email::FolderType qw(folder_type);
use Email::FolderType qw(folder_type);
use Email::FolderType qw(folder_type);
my $type = folder_type(‘./Maildir’);
use Email::FolderType qw(folder_type);
my $type = folder_type(‘./Maildir’);
# => ‘Mbox’
use Email::FolderType qw(folder_type);
my $type = folder_type(‘./Maildir’);
# => ‘Mbox’
use Email::FolderType qw(folder_type);
my $type = folder_type(‘./Maildir’);
# => ‘Mbox’
my $type = folder_type(‘./Maildir/’);
use Email::FolderType qw(folder_type);
my $type = folder_type(‘./Maildir’);
# => ‘Mbox’
my $type = folder_type(‘./Maildir/’);
# => ‘Maildir’
use Email::FolderType qw(folder_type);
my $type = folder_type(‘./Maildir’);
# => ‘Mbox’
my $type = folder_type(‘./Maildir/’);
# => ‘Maildir’
use Email::FolderType qw(folder_type);
my $type = folder_type(‘./Maildir’);
# => ‘Mbox’
my $type = folder_type(‘./Maildir/’);
# => ‘Maildir’
my $type = folder_type(‘./Maildir//’);
use Email::FolderType qw(folder_type);
my $type = folder_type(‘./Maildir’);
# => ‘Mbox’
my $type = folder_type(‘./Maildir/’);
# => ‘Maildir’
my $type = folder_type(‘./Maildir//’);
# => Ezmlm
Email::Folder
Email::Folder::Reader
my $reader = Email::Folder->new(“./Maildir/”);
my $reader = Email::Folder->new(“./Maildir/”);
my $reader = Email::Folder->new(“./Maildir/”);
while (my $email = $reader->next_message) {
my $reader = Email::Folder->new(“./Maildir/”);
while (my $email = $reader->next_message) {
print “to delete!”
my $reader = Email::Folder->new(“./Maildir/”);
while (my $email = $reader->next_message) {
print “to delete!”
if $email->header(‘from’) =~ /Laura/i;
my $reader = Email::Folder->new(“./Maildir/”);
while (my $email = $reader->next_message) {
print “to delete!”
if $email->header(‘from’) =~ /Laura/i;
}
Email::Delete
my $reader = Email::Folder->new(“./Maildir/”);
while (my $email = $reader->next_message) {
$email->delete
if $email->header(‘from’) =~ /Laura/i;
}
E
D
O
C
my $reader = Email::Folder->new(“./Maildir/”);
L
A
while (my $email = $reader->next_message) {
E
R
$email->delete
T
if $email->header(‘from’) =~ /Laura/i;
O
}
N
delete_message(
delete_message(
from => “./Maildir/”,
delete_message(
from => “./Maildir/”,
matching => sub {
delete_message(
from => “./Maildir/”,
matching => sub {
shift->header(‘message-id’)
delete_message(
from => “./Maildir/”,
matching => sub {
shift->header(‘message-id’)
eq
delete_message(
from => “./Maildir/”,
matching => sub {
shift->header(‘message-id’)
eq
$email->header(‘message-id’)
delete_message(
from => “./Maildir/”,
matching => sub {
shift->header(‘message-id’)
eq
$email->header(‘message-id’)
},
delete_message(
from => “./Maildir/”,
matching => sub {
shift->header(‘message-id’)
eq
$email->header(‘message-id’)
},
);
my $reader = Email::Folder->new(“./Maildir/”);
my $reader = Email::Folder->new(“./Maildir/”);
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
from => “./Maildir”,
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
from => “./Maildir”,
matching => sub { my $email = shift;
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
from => “./Maildir”,
matching => sub { my $email = shift;
$email->header(‘references’)
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
from => “./Maildir”,
matching => sub { my $email = shift;
$email->header(‘references’)
and
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
from => “./Maildir”,
matching => sub { my $email = shift;
$email->header(‘references’)
and
! $saw_id{ $email->header(‘references’) }
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
from => “./Maildir”,
matching => sub { my $email = shift;
$email->header(‘references’)
and
! $saw_id{ $email->header(‘references’) }
},
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
from => “./Maildir”,
matching => sub { my $email = shift;
$email->header(‘references’)
and
! $saw_id{ $email->header(‘references’) }
},
);
my $reader = Email::Folder->new(“./Maildir/”);
$saw_id{ $_->header(‘message-id’) } = 1
while my $_ = $reader->next_message;
delete_message(
from => “./Maildir”,
matching => sub { my $email = shift;
$email->header(‘references’)
and
! $saw_id{ $email->header(‘references’) }
},
);
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
Bcc => ‘the.ceo@corp’,
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
Bcc => ‘the.ceo@corp’,
Subject => ‘u sux’,
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
Bcc => ‘the.ceo@corp’,
Subject => ‘u sux’,
});
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
Bcc => ‘the.ceo@corp’,
Subject => ‘u sux’,
});
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
Bcc => ‘the.ceo@corp’,
Subject => ‘u sux’,
});
print $mailer \"Body of message\";
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
Bcc => ‘the.ceo@corp’,
Subject => ‘u sux’,
});
print $mailer \"Body of message\";
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
Bcc => ‘the.ceo@corp’,
Subject => ‘u sux’,
});
print $mailer \"Body of message\";
$mailer->close;
my $mailer = Mail::Mailer->new(‘sendmail’);
$mailer->open({
To => [ ‘boss@corp’, ‘boss2@corp’ ],
Bcc => ‘the.ceo@corp’,
Subject => ‘u sux’,
});
print $mailer \"Body of message\";
$mailer->close;
# ...and it gets sent
Mail::Sender
my $sender = Mail::Sender->new({
smtp => ‘smtp.haliburton.gov’,
});
$sender->Open({
from => 'your@address.com',
to => 'other@address.com',
subject => 'HTML test',
ctype => \"text/html\",
encoding => \"7bit\"
}) or die $Mail::Sender::Error,\"\\n\";
while (<$input>) {
$sender->SendEx($_); # no encoding!
};
$sender->Close();
Mail::Sendmail
use Mail::Sendmail;
sendmail(
To => ‘guy@2nd.row.org’,
From => ‘rjbs@cpan.org’,
Subject => ‘STFU’,
Body => $entire_message_body,
) or die “sendmail: $Mail::Sendmail::error”;
Mail::Transport
(a Mail::Box Production)
my $sender = Mail::Transport::SMTP->new(
my $sender = Mail::Transport::SMTP->new(
hostname => ‘nebu.fleet.zion.gov’,
my $sender = Mail::Transport::SMTP->new(
hostname => ‘nebu.fleet.zion.gov’,
username => ‘t.anderson@yahoo.com’,
my $sender = Email::Send->new({
mailer => ‘SMTP’,
mailer_args => [
Host => ‘sir-mx-a-lot.plusplus.com’,
username => ‘rjbs’,
password => ‘g0t b4ckUPS’,
],
});
my $rv = $sender->send($email);
unless ($rv) {
die “failed to send: “ . $rv->string;
my $sender = Email::Send->new({
mailer => ‘SMTP’,
mailer_args => [
Host => ‘sir-mx-a-lot.plusplus.com’,
username => ‘rjbs’,
password => ‘g0t b4ckUPS’,
],
});
my $rv = $sender->send($email);
unless ($rv) {
die “failed to send: “ . $rv->string;
}
problems
problems
Return::Value
problems
Return::Value
no envelope sender
problems
Return::Value
no envelope sender
awkward mailer/sender distinction
problems
Return::Value
no envelope sender
awkward mailer/sender distinction
difficult to extend api
problems
Return::Value
no envelope sender
awkward mailer/sender distinction
difficult to extend api
not enough API guaranteed for
interchangeability
Email::Sender?
my $sender = Email::Sender::SMTP->new({
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
$sender->send(
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
$sender->send(
$email,
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
$sender->send(
$email,
{
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
$sender->send(
$email,
{
to => $env_rcpt, # or \\@env_rcpts
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
$sender->send(
$email,
{
to => $env_rcpt, # or \\@env_rcpts
from => $env_sender,
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
$sender->send(
$email,
{
to => $env_rcpt, # or \\@env_rcpts
from => $env_sender,
}
my $sender = Email::Sender::SMTP->new({
host => ‘sir-mx-a-lot.plusplus.com’,
user => ‘rjbs’,
pass => ‘wishiwereanoscarmeyerweiner’,
});
$sender->send(
$email,
{
to => $env_rcpt, # or \\@env_rcpts
from => $env_sender,
}
);
Email::Sender::Simple->send(
$email,
{
to => $recipient,
from => $sender,
},
);
Email::Sender::Simple->send(
$email,
{
to => $recipient,
from => $sender,
},
);
$ EMAIL_SENDER=SQLite ./your-program
Filtering Mail
Mail::Audit
my $mail = Mail::Audit->new;
my $mail = Mail::Audit->new;
my $mail = Mail::Audit->new;
$mail->ignore if $mail->from_daemon;
my $mail = Mail::Audit->new;
$mail->ignore if $mail->from_daemon;
my $mail = Mail::Audit->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
my $mail = Mail::Audit->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
my $mail = Mail::Audit->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
my $mail = Mail::Audit->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
$mail->reject if $mail->from =~ /laura/i;
my $mail = Mail::Audit->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
$mail->reject if $mail->from =~ /laura/i;
my $mail = Mail::Audit->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
$mail->reject if $mail->from =~ /laura/i;
$mail->accept;
Email::Filter
my $mail = Email::Filter->new;
my $mail = Email::Filter->new;
my $mail = Email::Filter->new;
$mail->ignore if $mail->from_daemon;
my $mail = Email::Filter->new;
$mail->ignore if $mail->from_daemon;
my $mail = Email::Filter->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
my $mail = Email::Filter->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
my $mail = Email::Filter->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
my $mail = Email::Filter->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
$mail->reject if $mail->from =~ /laura/i;
my $mail = Email::Filter->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
$mail->reject if $mail->from =~ /laura/i;
my $mail = Email::Filter->new;
$mail->ignore if $mail->from_daemon;
$mail->accept(‘apologies’)
if $mail->subject =~ /sorry/i;
$mail->reject if $mail->from =~ /laura/i;
$mail->accept;
key differences
key differences
Mail::Audit does more
key differences
Mail::Audit does more
Mail::Audit is > 4x the size
key differences
Mail::Audit does more
Mail::Audit is > 4x the size
Mail::Audit is totally insane
key differences
Mail::Audit does more
Mail::Audit is > 4x the size
Mail::Audit is totally insane
Mail::Audit is better tested
Mail::Procmail
Mail::Procmail
It’s like Mail::Audit
Mail::Procmail
It’s like Mail::Audit
but exports a bunch of subs
Mail::Procmail
It’s like Mail::Audit
but exports a bunch of subs
can be made into a E::F plugin
Mail::Procmail
It’s like Mail::Audit
but exports a bunch of subs
can be made into a E::F plugin
built-in logging
Mail::Sort
Mail::Sort
It’s like Mail::Audit
Mail::Sort
It’s like Mail::Audit
but has lots more methods
Mail::Sort
It’s like Mail::Audit
but has lots more methods
mostly for common matches
Mail::Sort
It’s like Mail::Audit
but has lots more methods
mostly for common matches
could be some E::F plugins
Email Addresses
HATE!!
Mail::Address
Email::Address
Mail::Address
Email::Address
Mail::Message
::Field::
Address
Email::Valid
address is well-formed domain actually exists
domain name is valid some per-domain rules
domain is fqdn in a tld some fudging allowed
Email::Stuff
->from('Principal Skinner <seymore@se.edu>')
->to('rjbs@cpan.org')
->text_body(“Please see me after class.”)
Email::Stuff
->from('Principal Skinner <seymore@se.edu>')
->to('rjbs@cpan.org')
->text_body(“Please see me after class.”)
->header(Keywords => “trouble”)
Email::Stuff
->from('Principal Skinner <seymore@se.edu>')
->to('rjbs@cpan.org')
->text_body(“Please see me after class.”)
->header(Keywords => “trouble”)
->header(Keywords => “deep”)
Email::Stuff
->from('Principal Skinner <seymore@se.edu>')
->to('rjbs@cpan.org')
->text_body(“Please see me after class.”)
->header(Keywords => “trouble”)
->header(Keywords => “deep”)
->attach(
Email::Stuff
->from('Principal Skinner <seymore@se.edu>')
->to('rjbs@cpan.org')
->text_body(“Please see me after class.”)
->header(Keywords => “trouble”)
->header(Keywords => “deep”)
->attach(
slurp(‘1099.pdf’),
Email::Stuff
->from('Principal Skinner <seymore@se.edu>')
->to('rjbs@cpan.org')
->text_body(“Please see me after class.”)
->header(Keywords => “trouble”)
->header(Keywords => “deep”)
->attach(
slurp(‘1099.pdf’),
filename => 'dead_bunbun_proof.gif')
Email::Stuff
->from('Principal Skinner <seymore@se.edu>')
->to('rjbs@cpan.org')
->text_body(“Please see me after class.”)
->header(Keywords => “trouble”)
->header(Keywords => “deep”)
->attach(
slurp(‘1099.pdf’),
filename => 'dead_bunbun_proof.gif')
->send;
HTML Email
(yeah, I know)
Email::MIME
::CreateHTML
use Email::MIME::CreateHTML;
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
to => ‘mom@aol.com’,
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
to => ‘mom@aol.com’,
from => ‘rjbs@cpan.org’,
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
to => ‘mom@aol.com’,
from => ‘rjbs@cpan.org’,
subject => ‘Happy Birthday!’,
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
to => ‘mom@aol.com’,
from => ‘rjbs@cpan.org’,
subject => ‘Happy Birthday!’,
],
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
to => ‘mom@aol.com’,
from => ‘rjbs@cpan.org’,
subject => ‘Happy Birthday!’,
],
body => $html,
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
to => ‘mom@aol.com’,
from => ‘rjbs@cpan.org’,
subject => ‘Happy Birthday!’,
],
body => $html,
);
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
to => ‘mom@aol.com’,
from => ‘rjbs@cpan.org’,
subject => ‘Happy Birthday!’,
],
body => $html,
text_body => $text,
);
my $markdown = slurp(STDIN);
use Email::MIME::CreateHTML;
my $email = Email::MIME->create_html(
header => [
to => ‘mom@aol.com’,
from => ‘rjbs@cpan.org’,
subject => ‘Happy Birthday!’,
],
body => markdown($markdown),
text_body => $markdown,
);
use Email::StripMIME qw(strip_mime);
my $stripped_email = Email::MIME->new(
strip_mime($email->as_string)
);
Sifting Through
MIME Parts
Email::MIME::XPath
use Email::MIME::XPath;
use Email::MIME::XPath;
use Email::MIME::XPath;
my ($part) = $email->xpath_findnodes(“//plain”);
use Email::MIME::XPath;
my ($part) = $email->xpath_findnodes(“//plain”);
use Email::MIME::XPath;
my ($part) = $email->xpath_findnodes(“//plain”);
my @images = $email->xpath_findnodes(
use Email::MIME::XPath;
my ($part) = $email->xpath_findnodes(“//plain”);
my @images = $email->xpath_findnodes(
“//png|//jpeg|//gif”
use Email::MIME::XPath;
my ($part) = $email->xpath_findnodes(“//plain”);
my @images = $email->xpath_findnodes(
“//png|//jpeg|//gif”
);
use Email::MIME::XPath;
my ($part) = $email->xpath_findnodes(“//plain”);
my @images = $email->xpath_findnodes(
“//png|//jpeg|//gif”
);
use Email::MIME::XPath;
my ($part) = $email->xpath_findnodes(“//plain”);
my @images = $email->xpath_findnodes(
“//png|//jpeg|//gif”
);
my $address = $part->xpath_address;
use Email::MIME::XPath;
my ($part) = $email->xpath_findnodes(“//plain”);
my @images = $email->xpath_findnodes(
“//png|//jpeg|//gif”
);
my $address = $part->xpath_address;
die “error in part $address!”;
Sending Signed Mail
my $gpg = Mail::GPG->new(
my $gpg = Mail::GPG->new(
default_key_id => ‘12345678’,
my $gpg = Mail::GPG->new(
default_key_id => ‘12345678’,
;
my $gpg = Mail::GPG->new(
default_key_id => ‘12345678’,
;
my $gpg = Mail::GPG->new(
default_key_id => ‘12345678’,
;
my $signed_entity = $gpg->mime_sign(
my $gpg = Mail::GPG->new(
default_key_id => ‘12345678’,
;
my $signed_entity = $gpg->mime_sign(
entity => $entity,
my $gpg = Mail::GPG->new(
default_key_id => ‘12345678’,
;
my $signed_entity = $gpg->mime_sign(
entity => $entity,
);
alias mollymillions molly@bama-online.com (Molly Millions)
alias mollymillions-home molly@bama-online.com (Molly
Millions)
alias mollymillions-work mm@solo.com (Molly Millions)
alias mollymillions-work-1 s.shears@bodymiraculous.com (Molly
Millions)
alias mollymillions molly@bama-online.com (Molly Millions)
alias mollymillions-home molly@bama-online.com (Molly
Millions)
alias mollymillions-work mm@solo.com (Molly Millions)
alias mollymillions-work-1 s.shears@bodymiraculous.com (Molly
Millions)
mailboxes =friends.molly
alias mollymillions molly@bama-online.com (Molly Millions)
alias mollymillions-home molly@bama-online.com (Molly
Millions)
alias mollymillions-work mm@solo.com (Molly Millions)
alias mollymillions-work-1 s.shears@bodymiraculous.com (Molly
Millions)
mailboxes =friends.molly
save-hook ~fmolly@bama-online.com =friends.molly
save-hook ~fmm@solo.com =friends.molly
save-hook ~fs.shears@bodymiraculous.com =friends.molly
alias mollymillions molly@bama-online.com (Molly Millions)
alias mollymillions-home molly@bama-online.com (Molly
Millions)
alias mollymillions-work mm@solo.com (Molly Millions)
alias mollymillions-work-1 s.shears@bodymiraculous.com (Molly
Millions)
mailboxes =friends.molly
save-hook ~fmolly@bama-online.com =friends.molly
save-hook ~fmm@solo.com =friends.molly
save-hook ~fs.shears@bodymiraculous.com =friends.molly
send-hook ~tmolly@bama-online.com set signature=\"~/.sig/ninja\"
send-hook ~tmm@solo.com set signature=\"~/.sig/ninja\"
send-hook ~ts.shears@bodymiraculous.com set signature=\"~/.sig/
ninja\"
Ready? 250 OK! Everybody loves email, right? Right! more
Ready? 250 OK! Everybody loves email, right? Right! What better language than Perl for handling all your email needs? None, right? Right! After all, with about nine hundred email modules on the CPAN, the only question is: which tool is right for the job?
This year, the Perl Email Project is going to tell you what's what. We'll see what modules solve what problems, how they differ, and how they (may or my not) work together.
We'll also show what problems aren't well-solved, what is in the works to make it happen, and how you can help. less
0 comments
Post a comment