Skip to content

Commit

Permalink
mmsstrip parameter; adapted to new version of Courriel
Browse files Browse the repository at this point in the history
  • Loading branch information
Zbigniew Lukasiak committed Sep 13, 2011
1 parent 911d4fc commit 9e8a488
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
15 changes: 10 additions & 5 deletions lib/Courriel/MMS.pm
Expand Up @@ -61,15 +61,18 @@ around subject => sub {
} }
} }
} }
$subject =~ s/\n+\z//gmxs; # remove one or more trailing newlines
return $subject; return $subject;
}; };




sub plain_content { sub plain_content {
my $self = shift; my $self = shift;
my $part = $self->plain_body_part; my $mmsstrip = shift;
return '' if !defined $part; my @parts = $self->all_parts_matching( sub { return 1 if shift->mime_type eq 'text/plain'; return } );
return $part->content # operator signatures are usually the last text/plain part in the mail.
pop @parts if $mmsstrip && scalar @parts;
return join( "\n\n", map { $_->content } @parts );
} }


sub _get_image_parts { sub _get_image_parts {
Expand All @@ -88,9 +91,11 @@ sub get_mms_images {
my $self = shift; my $self = shift;
my @result; my @result;
for my $part ( $self->_get_image_parts ){ for my $part ( $self->_get_image_parts ){
my $disp = $part->disposition ? $part->disposition->attribute_value( 'name' ) : undef;
my $type = $part->content_type ? $part->content_type->attribute_value( 'name' ) : undef;
my $name = $part->filename my $name = $part->filename
// $part->disposition->get_attribute( 'name' ) // $disp
// $part->content_type->get_attribute( 'name' ) // $type
// $self->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 ];
} }
Expand Down
2 changes: 1 addition & 1 deletion lib/Courriel/MMS/Plugin/MymtsRu.pm
Expand Up @@ -23,7 +23,7 @@ around '_get_image_parts' => sub {
my $self = shift; my $self = shift;
my @images; my @images;
for my $image ( $self->$orig( @_ ) ){ for my $image ( $self->$orig( @_ ) ){
my $content_id = $image->headers()->get( 'Content-ID' ); my( $content_id ) = $image->headers()->get_values( 'Content-ID' );
push @images, $image if !defined( $content_id ) || $content_id !~ /mts_logo/; push @images, $image if !defined( $content_id ) || $content_id !~ /mts_logo/;
} }
return @images; return @images;
Expand Down
25 changes: 23 additions & 2 deletions t/test.t
Expand Up @@ -7,6 +7,24 @@ use Courriel::MMS;
use Courriel::Builder; use Courriel::Builder;
use File::Slurp 'slurp'; use File::Slurp 'slurp';


{
my $template_path = '/home/zby/myopera/MyOperaFunctionalTests/uploads/mms/photo-ferreiro.txt';
open F, '<:utf8', $template_path;
my $message = join("", <F>);
close F;
my $address = 'photo+qjwdepoa@my.opera.com';
$message =~ s/\%MMSADDRESS\%/$address/go;


my $email = Courriel::MMS->parse( text => $message );

isa_ok( $email, 'Courriel::MMS', 'MMS' );

my @images = $email->get_mms_images;
is( scalar( @images ), 1, 'There are images' );
is( $images[0][0], "Iv\x{00E1}n Ferreiro.jpeg");
}

{ {
my $email = Courriel::MMS->parse( text => scalar( slurp( 't/data/MymtsRu.eml' ) ) ); my $email = Courriel::MMS->parse( text => scalar( slurp( 't/data/MymtsRu.eml' ) ) );


Expand All @@ -16,19 +34,22 @@ use File::Slurp 'slurp';
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' ); ok( $email->create_random_image_name( 'image/jpeg' ) =~ /\.jpg$/, 'random image extension' );
}


{
my $c_email = build_email( my $c_email = build_email(
subject('aaa'), subject('aaa'),
from('aaa@tmomail.net'), from('aaa@tmomail.net'),
to( 'example@example.com' ), to( 'example@example.com' ),
plain_body( 'test' ), plain_body( 'test' ),
attach( file => 't/data/cool.gif', filename => 'masthead.gif' ), attach( file => 't/data/cool.gif', filename => 'masthead.gif' ),
); );
$email = Courriel::MMS->parse( text => $c_email->as_string ); my $email = Courriel::MMS->parse( text => $c_email->as_string );
isa_ok( $email, 'Courriel::MMS::Plugin::TmobileUS', 'MMS from tmomail.net' ); isa_ok( $email, 'Courriel::MMS::Plugin::TmobileUS', 'MMS from tmomail.net' );
@images = $email->get_mms_images; my @images = $email->get_mms_images;
is( scalar( @images ), 0, 'Logo filtered out' ); is( scalar( @images ), 0, 'Logo filtered out' );
is( $email->plain_content, 'test', 'plain_content' ); is( $email->plain_content, 'test', 'plain_content' );
is( $email->plain_content( 1 ), '', 'plain_content with mmsstrip' );
} }


{ {
Expand Down

0 comments on commit 9e8a488

Please sign in to comment.