NAME
Email::Handle - A Objective Email Handler
SYNOPSIS
use Email::Handle;
my $email = Email::Handle->new('root@example.com');
print $email->is_valid ? 'yes' : 'no';
print $email->obfuscate;
print $email->anonymize;
print $email;
$email->send(From => 'foo@example.com');
This module is also convenient for using on the DB application with Template and Class::DBI / DBIx::Class.
# setup the table that has column of email with this module
my $loader = Class::DBI::Loader->new(
...
namespace => 'MyApp'
);
$loader->find_class('user')->has_a(email => 'Email::Handle');
# then output records with TT2
my $tmpl = Template->new;
$tmpl->process(
'sample.tt',
{ users => $loader->find_class('user')->retrieve_all }
);
# You can write the template with some methods of this module like this
[% WHILE (user IN users) %]
[% user.email.obfuscate IF user.email.is_valid %]
[% END %]
DESCRIPTION
This module allows you to handle an email address as a object.
METHODS
new
Returns Email::Handle object. It has three forms of construction.
my $email = Email::Handle->new('root@example.com');
or
my $email = Email::Handle->new(
user => 'root',
host => 'example.com'
);
or
my $email = Email::Handle->new;
$email->user('root');
$email->host('example.com');
Set/get an email address. A passed string will be splited and setted as user and host internally.
as_string
Returns a Email::Handle object to a plain string. Email::Handle objects are also converted to plain strings automatically by overloading. This means that objects can be used as plain strings in most Perl constructs.
my $email = Email::Handle->new('root@example.com');
print $email->as_string; # 'root@example.com'
print $email; # 'root@example.com'
user
Set/get a user name for an email address.
$email->user; # 'root'
$email->user('foo'); # changing the user from 'root' to 'foo'
host
Set/get a host name for an email address.
$email->host; # 'examplle.com'
$email->host('cpan.org'); # changing the host from 'example.com' to 'cpan.org'
is_valid
Validates whether an address is well-formed with Email::Valid/Email::Valid::Loose and returns false if the address is not valid. This method takes some options as arguments.
$email->is_valid; # validating with Email::Valid
$email->is_valid(loose => 1); # validating with Email::Valid::Loose
# Any other arguments will be passed to the validator.
$email->is_valid(-mxcheck => 1);
obfuscate
Returns obfuscated HTML email addresses which is hard to be scraped. It requires "HTML::Email::Obfuscate ".
$email->obfuscate;
This code generates obfuscated strings like this:
roo<span>t</span><!-- @ -->@hat<span>e</span>na<B>.</b>ne<B>.</b><span>j</span>p
Arguments will be passed to the constructor of the HTML::Email::Obfuscate.
$email->obfuscate(javascript => 1);
$email->obfuscate(lite => 1);
anonymize
Returns an anonymized email address like this:
$email->anonymize; # 'root@e...'
$email->anonymize('***'); # 'root@e***'
mime
Returns MIME::Lite message object for sending mail to the address. Arguments will be passed to the constructor of MIME::Lite;
$email->mime(
From => 'me@myhost.com',
Subject => 'Hello'
)->send;
If you want to use any other MIME classes like MIME::Lite::TT rather than MIME::Lite, override package variable $Email::Handle::MIME_CLASS
$Email::Handle::MIME_CLASS = 'MIME::Lite::TT';
my $msg = $email->mime(...)
send
A shortcut method for sending mail with MIME::Lite.
$email->send(From => 'me@myhost.com', Subject => 'Hello');
AUTHOR
Naoya Ito, <naoya at bloghackers.net>
BUGS
Please report any bugs or feature requests to bug-email-handle at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Email-Handle. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Email::Handle
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
RT: CPAN's request tracker
Search CPAN
COPYRIGHT & LICENSE
Copyright 2006 Naoya Ito, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 203:
L<> starts or ends with whitespace