Permalink
Browse files

Be more strict about domain detection in MMSes.

Without regex anchoring it'd be possible for the username in email to confuse
Courriel::MMS.

Also add some tests for T-Mobile UK and the behaviour described above.
  • Loading branch information...
tadzik committed Mar 16, 2012
1 parent 2511e97 commit 8c9e122f673e01aa192483ef4489ccc809db2ecc
@@ -12,7 +12,7 @@ extends 'Courriel::MMS';
sub match {
my( $class, $email ) = @_;
- return 1 if $email->from =~ /mms\.mymts\.ru/i;
+ return 1 if $email->from =~ /mms\.mymts\.ru$/i;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /mms\.o2\.ie/;
+ return 1 if $email->from =~ /mms\.o2\.ie$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /mmsc\.radiolinja\.fi/;
+ return 1 if $email->from =~ /mmsc\.radiolinja\.fi$/;
return;
}
@@ -16,7 +16,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /pm\.sprint\.com/;
+ return 1 if $email->from =~ /pm\.sprint\.com$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /mms\.tele2/;
+ return 1 if $email->from =~ /mms\.tele2\.\w+$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /mms-email\.telenor\.se/;
+ return 1 if $email->from =~ /mms-email\.telenor\.se$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /mmsreply\.t-mobile\.co\.uk/;
+ return 1 if $email->from =~ /mmsreply\.t-mobile\.co\.uk$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /tmomail.net/;
+ return 1 if $email->from =~ /tmomail\.net$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /mmsmail\.vodafone\.de/;
+ return 1 if $email->from =~ /mmsmail\.vodafone\.de$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /mms2mail\.vodafone\.nl/;
+ return 1 if $email->from =~ /mms2mail\.vodafone\.nl$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /pxt.vodafone.net.nz/;
+ return 1 if $email->from =~ /pxt\.vodafone\.net\.nz$/;
return;
}
@@ -13,7 +13,7 @@ sub match {
my $class = shift;
my $email = shift;
- return 1 if $email->from =~ /mms\.vodafone\.co\.uk/;
+ return 1 if $email->from =~ /mms\.vodafone\.co\.uk$/;
return;
}
View
@@ -52,6 +52,22 @@ use File::Slurp 'slurp';
is( $email->plain_content( 1 ), '', 'plain_content with mmsstrip' );
}
+{
+ my $c_email = build_email(
+ subject('aaa'),
+ from('aaa@mmsreply.t-mobile.co.uk'),
+ to( 'example@example.com' ),
+ plain_body( 'test' ),
+ attach( file => 't/data/cool.gif', filename => 'logo.gif' ),
+ );
+ my $email = Courriel::MMS->parse( text => $c_email->as_string );
+ isa_ok( $email, 'Courriel::MMS::Plugin::TmobileUK', 'MMS from T-Mobile UK' );
+ 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' );
+}
+
{
my $c_email = build_email(
subject('aaa'),
@@ -171,5 +187,17 @@ use File::Slurp 'slurp';
is( $email->plain_content, '', 'content cleared for Radiolinja' );
}
+# check if username will not confuse the domain detection
+{
+ my $c_email = build_email(
+ subject('MMS via e-mail'),
+ from( 'mms.tele2.lt@doesnotexi.st' ),
+ to( 'example@example.com' ),
+ plain_body( 'test' ),
+ );
+ my $email = Courriel::MMS->parse( text => $c_email->as_string );
+ ok( !$email->isa('Courriel::MMS::Plugin::Tele2LT'), 'MMS not from Tele2 Lithuania' );
+}
+
done_testing();

0 comments on commit 8c9e122

Please sign in to comment.