Skip to content
Browse files

XWA removed

  • Loading branch information...
1 parent e499abc commit 462de6c8187181b35afa2ca2de0521b0bb4833c3 Zbigniew Lukasiak committed
Showing with 36 additions and 8 deletions.
  1. +34 −8 lib/Courriel/MMS.pm
  2. +2 −0 t/test.t
View
42 lib/Courriel/MMS.pm
@@ -7,7 +7,7 @@ use Moose;
extends 'Courriel';
-use XWA::MIME::Util;
+use MIME::Types;
use Class::MOP;
my @subclasses = qw(
@@ -16,6 +16,12 @@ Courriel::MMS::TmobileUK
Courriel::MMS::TmobileUS
);
+# --- Attributes ---
+
+has mime_types => ( is => 'ro', lazy_build => 1 );
+
+sub _build_mime_types { MIME::Types->new() }
+
# --- Class methods ---
around 'parse' => sub {
@@ -61,25 +67,45 @@ sub get_mms_images {
my $name = $part->filename
// $part->disposition->get_attribute( 'name' )
// $part->content_type->get_attribute( 'name' )
- // create_random_image_name( $part->mime_type );
+ // $self->create_random_image_name( $part->mime_type );
push @result, [ $name, $part->content ];
}
return @result;
}
-# --- Functions ---
-
sub create_random_image_name {
- my ($mime_type) = @_;
- my $mime_util = XWA::MIME::Util->new();
- my $suffix = $mime_util->get_extension($mime_type, {must_be_media => "image"});
+ my ( $self, $mime_type ) = @_;
+
+ # Workaround for MSIE6 sending image/pjpeg for JPEG images, wtf!
+ # http://www.webmasterworld.com/forum88/5931.htm
+ # The MIME::Types modules does not list it:
+ # http://search.cpan.org/src/MARKOV/MIME-Types-1.20/lib/MIME/Types.pm
+ # -- nicolasm 2007-09-06
+ if ($mime_type eq 'image/pjpeg') {
+ $mime_type = 'image/jpeg';
+ }
+ my $this_type = $self->mime_types->type( $mime_type );
+ return if not $this_type;
+ return if $this_type->mediaType ne 'image';
+
+ # Choose the first three character extension.
+ my $extension;
+ EXTENSION:
+ for my $cur_extension ( $this_type->extensions ) {
+ $extension = $cur_extension;
+ last EXTENSION if length $cur_extension == 3;
+ }
+
+
my @r = ("A" .. "Z", "a" .. "z", 1 .. 9);
my $filename = join q{}, map { $r[ rand @r ] } (1 .. 8);
- return join q{.} => ($filename, $suffix);
+ return join q{.} => ( $filename, $extension );
}
+# --- Functions ---
+
__PACKAGE__->meta()->make_immutable();
1;
View
2 t/test.t
@@ -14,6 +14,8 @@ isa_ok( $email, 'Courriel::MMS::MymtsRu', 'MMS from mms.mymts.ru' );
my @images = $email->get_mms_images;
is( scalar( @images ), 1, 'Logo filtered out' );
+ok( $email->create_random_image_name( 'image/jpeg' ) =~ /\.jpg$/, 'random image extension' );
+
$email = build_email(
subject('aaa'),
from('aaa@tmomail.net'),

0 comments on commit 462de6c

Please sign in to comment.
Something went wrong with that request. Please try again.