Skip to content

Commit

Permalink
XWA removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Zbigniew Lukasiak committed Aug 31, 2011
1 parent e499abc commit 462de6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
42 changes: 34 additions & 8 deletions lib/Courriel/MMS.pm
Expand Up @@ -7,7 +7,7 @@ use Moose;


extends 'Courriel'; extends 'Courriel';


use XWA::MIME::Util; use MIME::Types;
use Class::MOP; use Class::MOP;


my @subclasses = qw( my @subclasses = qw(
Expand All @@ -16,6 +16,12 @@ Courriel::MMS::TmobileUK
Courriel::MMS::TmobileUS Courriel::MMS::TmobileUS
); );


# --- Attributes ---

has mime_types => ( is => 'ro', lazy_build => 1 );

sub _build_mime_types { MIME::Types->new() }



# --- Class methods --- # --- Class methods ---
around 'parse' => sub { around 'parse' => sub {
Expand Down Expand Up @@ -61,25 +67,45 @@ sub get_mms_images {
my $name = $part->filename my $name = $part->filename
// $part->disposition->get_attribute( 'name' ) // $part->disposition->get_attribute( 'name' )
// $part->content_type->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 ]; push @result, [ $name, $part->content ];
} }
return @result; return @result;


} }


# --- Functions ---

sub create_random_image_name { sub create_random_image_name {
my ($mime_type) = @_; my ( $self, $mime_type ) = @_;
my $mime_util = XWA::MIME::Util->new();
my $suffix = $mime_util->get_extension($mime_type, {must_be_media => "image"}); # 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 @r = ("A" .. "Z", "a" .. "z", 1 .. 9);
my $filename = join q{}, map { $r[ rand @r ] } (1 .. 8); 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(); __PACKAGE__->meta()->make_immutable();


1; 1;
Expand Down
2 changes: 2 additions & 0 deletions t/test.t
Expand Up @@ -14,6 +14,8 @@ isa_ok( $email, 'Courriel::MMS::MymtsRu', 'MMS from mms.mymts.ru' );
my @images = $email->get_mms_images; my @images = $email->get_mms_images;
is( scalar( @images ), 1, 'Logo filtered out' ); is( scalar( @images ), 1, 'Logo filtered out' );


ok( $email->create_random_image_name( 'image/jpeg' ) =~ /\.jpg$/, 'random image extension' );

$email = build_email( $email = build_email(
subject('aaa'), subject('aaa'),
from('aaa@tmomail.net'), from('aaa@tmomail.net'),
Expand Down

0 comments on commit 462de6c

Please sign in to comment.