Skip Menu |

This queue is for tickets about the MIME-Lite-HTML CPAN distribution.

Report information
The Basics
Id: 67695
Status: resolved
Priority: 0/
Queue: MIME-Lite-HTML

People
Owner: Nobody in particular
Requestors: thomas.briggs [...] booking.com
Cc: thomas.briggs@booking.com (no email address)
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.8
Fixed in: (no value)



CC: thomas.briggs [...] booking.com
Subject: Feature proposal: ExternImages param to constructor
I'd like to add a feature to MIME::Lite::HTML. I've written the patch myself -- I'm just opening this issue so people can see and talk about the proposal. Currently, the module can either send images as attachments, or as external <img> links, but it can't mix the two methods. I'd like to make that possible. My idea is to have an argument that's a list of regular expressions. For each image, MIME::Lite::HTML will check if the path matches one of the regular expressions, and if so, it will be an external <img> link. If not, it will use whatever the IncludeType is. For example, the constructor might look like: my $parser = MIME::Lite::HTML->( IncludeType => 'location', ExternImages => [ '.*_logo.*' ] ); In this example, "cat_and_dog.jpg" would be sent with the Content-Location header, but "company_logo.jpg" would be sent as an <img> link. I'm attaching the diff that implements this.
Subject: HTML.pm.diff
1c1 < package MIME::Lite::HTML; --- > package Bookings::MIME::Lite::HTML; 8c8,12 < # Revision 1.23 2008/10/14 11:27:42 alian --- > # Revision 1.24 2011/04/15 11:27:42 tbriggs > # > > # Revision 1.24 2011/04/15 11:27:42 tbriggs > # Add feature: "ExternImages" parameter to constructor 62c66 < $VERSION = ('$Revision: 1.23 $ ' =~ /(\d+\.\d+)/)[0]; --- > $VERSION = ('$Revision: 1.24 $ ' =~ /(\d+\.\d+)/)[0]; 65a70 > 142a148,152 > > # Get regexps for images that should be external > if (defined $param{'ExternImages'}) { > $self->{_externimages} = $param{'ExternImages'}; > } 283a294 > 321c332,333 < if (($self->{_include} ne 'extern')&&(!$images_read{$urlAbs})) --- > if (($self->{_include} ne 'extern')&&(!$images_read{$urlAbs}) > and not $self->_matches_extern_images( $urlAbs ) ) 339c351,352 < if (($self->{_include} ne 'extern')&&(!$images_read{$urlAbs})) --- > if (($self->{_include} ne 'extern')&&(!$images_read{$urlAbs}) > and not $self->_matches_extern_images( $urlAbs ) ) 360c373,374 < if (($self->{_include} ne 'extern')&&(!$images_read{$urlAbs})) --- > if (($self->{_include} ne 'extern')&&(!$images_read{$urlAbs}) > and not $self->_matches_extern_images($urlAbs)) 369a384 > ( not $self->_matches_extern_images( $urlAbs ) ) && 371a387 > 408a425,445 > > #------------------------------------------------------------------------------ > # _matches_extern_images > # > # For a given image, does it match any of the regexps in $self->{_externimages} ? > #------------------------------------------------------------------------------ > sub _matches_extern_images { > > my ( $self, $image ) = @_; > > my $regexps = $self->{_externimages} || [ ]; > > foreach my $regexp ( @$regexps ) { > if ( $image =~ /$regexp/ ) { > return 1; > } > } > return 0; > } > > 579a617 > 944a983,996 > =item ExternImages > > This is a listref of regular expressions. If an image matches any of the > regular expressions, it will be rendered as an <img> link, without being > attached to the mail, regardless of the IncludeType setting above. > For example: > > ExternImages => [ '.*cat\.jpg.*', 'external/.*' ] > > ...would mean that "images/cat.jpg" and "external/foo.jpg" would be > sent as external <img> links, but "images/dog.jpg" would be sent using > whatever the default IncludeType (above) is. > >
Fixed in 1.24