Permalink
Browse files

mmsstrip parameter; adapted to new version of Courriel

  • Loading branch information...
1 parent 911d4fc commit 9e8a4882d1ff218f2274fc9fdc982fd1afbd369e Zbigniew Lukasiak committed Sep 13, 2011
Showing with 34 additions and 8 deletions.
  1. +10 −5 lib/Courriel/MMS.pm
  2. +1 −1 lib/Courriel/MMS/Plugin/MymtsRu.pm
  3. +23 −2 t/test.t
View
@@ -61,15 +61,18 @@ around subject => sub {
}
}
}
+ $subject =~ s/\n+\z//gmxs; # remove one or more trailing newlines
return $subject;
};
sub plain_content {
my $self = shift;
- my $part = $self->plain_body_part;
- return '' if !defined $part;
- return $part->content
+ my $mmsstrip = shift;
+ my @parts = $self->all_parts_matching( sub { return 1 if shift->mime_type eq 'text/plain'; return } );
+ # 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 {
@@ -88,9 +91,11 @@ sub get_mms_images {
my $self = shift;
my @result;
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
- // $part->disposition->get_attribute( 'name' )
- // $part->content_type->get_attribute( 'name' )
+ // $disp
+ // $type
// $self->create_random_image_name( $part->mime_type );
push @result, [ $name, $part->content ];
}
@@ -23,7 +23,7 @@ around '_get_image_parts' => sub {
my $self = shift;
my @images;
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/;
}
return @images;
View
@@ -8,6 +8,24 @@ use Courriel::Builder;
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' ) ) );
isa_ok( $email, 'Courriel::MMS::Plugin::MymtsRu', 'MMS from mms.mymts.ru' );
@@ -16,19 +34,22 @@ use File::Slurp 'slurp';
is( scalar( @images ), 1, 'Logo filtered out' );
ok( $email->create_random_image_name( 'image/jpeg' ) =~ /\.jpg$/, 'random image extension' );
+}
+{
my $c_email = build_email(
subject('aaa'),
from('aaa@tmomail.net'),
to( 'example@example.com' ),
plain_body( 'test' ),
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' );
- @images = $email->get_mms_images;
+ my @images = $email->get_mms_images;
is( scalar( @images ), 0, 'Logo filtered out' );
is( $email->plain_content, 'test', 'plain_content' );
+ is( $email->plain_content( 1 ), '', 'plain_content with mmsstrip' );
}
{

0 comments on commit 9e8a488

Please sign in to comment.