Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Subject heuristics

  • Loading branch information...
commit 911d4fce45805d2db99cfc2a6aabb4b8e25d1133 1 parent 064f9b1
Zbigniew Lukasiak authored
View
4 TODO
@@ -0,0 +1,4 @@
+When we have too many subclasses - then checking each of them to mach
+each of the messages will be too slow. Probably we'll need a hash
+translating the email origin domain to the subclass.
+
View
28 lib/Courriel/MMS.pm
@@ -35,8 +35,36 @@ sub rebless {
return bless $email, $class;
}
+sub bad_subject {}
+
# --- Instance methods ---
+around subject => sub {
+ my $orig = shift;
+ my $self = shift;
+ my $subject = $self->$orig( @_ );
+ if( $self->bad_subject( $subject ) ){
+ $subject = '';
+ }
+ if( !length( $subject ) ) {
+ my $plain_content = $self->plain_content;
+ if( length( $plain_content ) ) {
+ ( $subject ) = $plain_content =~ /^([^\.]+\.)/g; # use the first sentence.
+ if( !$subject ) {
+ $subject = substr( $plain_content, 0, 25 ); # if still not subject, use some of the text
+ }
+ }
+ else{
+ my @images = $self->get_mms_images;
+ if( @images ) {
+ $subject = $images[0][0]; # set subject to image filename
+ }
+ }
+ }
+ return $subject;
+};
+
+
sub plain_content {
my $self = shift;
my $part = $self->plain_body_part;
View
9 lib/Courriel/MMS/Plugin/O2Ie.pm
@@ -17,17 +17,10 @@ sub match {
return;
}
+sub bad_subject { $_[1] eq 'Multimedia message' }
# --- Instance methods ---
-around subject => sub {
- my $orig = shift;
- my $self = shift;
- my $subject = $self->$orig;
- return undef if $subject eq 'Multimedia message';
- return $subject;
-};
-
__PACKAGE__->meta()->make_immutable();
1;
View
9 lib/Courriel/MMS/Plugin/Tele2LT.pm
@@ -17,17 +17,10 @@ sub match {
return;
}
+sub bad_subject { $_[1] =~ /MMS via e-mail/ }
# --- Instance methods ---
-around subject => sub {
- my $orig = shift;
- my $self = shift;
- my $subject = $self->$orig;
- return undef if $subject =~ /MMS via e-mail/;
- return $subject;
-};
-
__PACKAGE__->meta()->make_immutable();
1;
View
9 lib/Courriel/MMS/Plugin/VodafoneDE.pm
@@ -17,17 +17,10 @@ sub match {
return;
}
+sub bad_subject { $_[1] eq 'Sie haben eine MMS erhalt' }
# --- Instance methods ---
-around subject => sub {
- my $orig = shift;
- my $self = shift;
- my $subject = $self->$orig;
- return undef if $subject eq 'Sie haben eine MMS erhalt';
- return $subject;
-};
-
override plain_content => sub {
my $self = shift;
my $part = $self->first_part_matching(
View
9 lib/Courriel/MMS/Plugin/VodafoneNZ.pm
@@ -17,17 +17,10 @@ sub match {
return;
}
+sub bad_subject { $_[1] =~ /^You have a PXT from/ }
# --- Instance methods ---
-around subject => sub {
- my $orig = shift;
- my $self = shift;
- my $subject = $self->$orig;
- return undef if $subject =~ /^You have a PXT from/;
- return $subject;
-};
-
__PACKAGE__->meta()->make_immutable();
1;
View
10 t/test.t
@@ -48,11 +48,11 @@ use File::Slurp 'slurp';
subject('Multimedia message'),
from( 'aaa@mms.o2.ie' ),
to( 'example@example.com' ),
- plain_body( 'test' ),
+ plain_body( '' ),
);
my $email = Courriel::MMS->parse( text => $c_email->as_string );
isa_ok( $email, 'Courriel::MMS::Plugin::O2Ie', 'MMS from O2 Ireland' );
- is( $email->subject, undef, 'subject cleared for O2Ie' );
+ is( $email->subject, '', 'subject cleared for O2Ie' );
}
{
@@ -66,7 +66,7 @@ use File::Slurp 'slurp';
);
my $email = Courriel::MMS->parse( text => $c_email->as_string );
isa_ok( $email, 'Courriel::MMS::Plugin::VodafoneDE', 'MMS from Vodafone DE' );
- is( $email->subject, undef, 'subject cleared for VodafoneDE' );
+ is( $email->subject, 'some text', 'subject cleared for VodafoneDE' );
is( $email->plain_content, 'some text', 'plain_content ignored http://www.vodafone.de' );
}
@@ -93,7 +93,7 @@ use File::Slurp 'slurp';
);
my $email = Courriel::MMS->parse( text => $c_email->as_string );
isa_ok( $email, 'Courriel::MMS::Plugin::VodafoneNZ', 'MMS from Vodafone New Zealand' );
- is( $email->subject, undef, 'subject cleared for VodafoneNZ' );
+ is( $email->subject, 'test', 'subject cleared for VodafoneNZ' );
}
{
@@ -135,7 +135,7 @@ use File::Slurp 'slurp';
);
my $email = Courriel::MMS->parse( text => $c_email->as_string );
isa_ok( $email, 'Courriel::MMS::Plugin::Tele2LT', 'MMS from Tele2 Lithuania' );
- is( $email->subject, undef, 'subject cleared for Tele2LT' );
+ is( $email->subject, 'test', 'subject cleared for Tele2LT' );
}
{
Please sign in to comment.
Something went wrong with that request. Please try again.