Skip to content
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...
1 parent 2511e97 commit 8c9e122f673e01aa192483ef4489ccc809db2ecc @tadzik committed
View
2 lib/Courriel/MMS/Plugin/MymtsRu.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/O2Ie.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/RadiolinjaFI.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/SprintUS.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/Tele2LT.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/TelenorSE.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/TmobileUK.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/TmobileUS.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/VodafoneDE.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/VodafoneNL.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/VodafoneNZ.pm
@@ -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;
}
View
2 lib/Courriel/MMS/Plugin/VodafoneUK.pm
@@ -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
28 t/test.t
@@ -55,6 +55,22 @@ use File::Slurp 'slurp';
{
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'),
from( 'aaa@pm.sprint.com' ),
to( 'example@example.com' ),
html_body( '<html><body><table><tr> <td><pre >some text</pre></td> </tr></table></body></html>' ),
@@ -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.
Something went wrong with that request. Please try again.