HTML-FromMail
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
use IO::Handle;
my @optional =
(
[ Template::Magic => '1.02', reason => <<'REASON' ]
Required if you want to use the Template::Magic formatter, which is
not required to run the examples.
REASON
, [ Image::Magick => '5.0', reason => <<'REASON', warning => <<'WARN' ]
When messages contain images, these images can be shown as small
previews. This is done with Image::Magick, which is quite hard to
install (IMHO). So if you want to give it a try answer yes.
REASON
If you do not install Image::Magick, some examples will not work. But
you can always install it later.
WARN
);
my %prereq =
( Mail::Box => 2.051 # used everywhere
, HTML::FromText => 2.03 # for HTML::FromMail::Default::HTMLifiers
, OODoc::Template => 0.01 # default template system
, Test::Pod => 1.00
lib/HTML/FromMail/Default/Previewers.pm view on Meta::CPAN
use strict;
use warnings;
use Carp;
use File::Basename qw/basename dirname/;
our @previewers =
( 'text/plain' => \&previewText
, 'text/html' => \&previewHtml
, 'image' => \&previewImage # added when Image::Magick is installed
);
sub previewText($$$$$)
{ my ($page, $message, $part, $attach, $args) = @_;
my $decoded = $attach->{decoded}->string;
for($decoded)
{ s/^\s+//;
s/\s+/ /gs; # lists of blanks
lib/HTML/FromMail/Default/Previewers.pm view on Meta::CPAN
substr($decoded, $max) = '' if length $decoded > $max;
+{ %$attach
, image => '' # this is not an image
, html => { text => $decoded }
};
}
BEGIN
{ eval { require Image::Magick };
if($@) { warn "No Image::Magick installed" }
else { push @previewers, image => \&previewImage }
}
sub previewImage($$$$$)
{ my ($page, $message, $part, $attach, $args) = @_;
my $filename = $attach->{filename};
my $magick = Image::Magick->new;
my $error = $magick->Read($filename);
if(length $error)
{ __PACKAGE__->log(ERROR =>
"Cannot read image from $filename: $error");
return;
}
my %image;
my ($srcw, $srch) = @image{ qw/width height/ }
= $magick->Get( qw/width height/ );
( run in 0.338 second using v1.01-cache-2.11-cpan-beeb90c9504 )