Permalink
Browse files

plain_content method; new subclasses

  • Loading branch information...
Zbigniew Lukasiak
Zbigniew Lukasiak committed Sep 5, 2011
1 parent c17864b commit 064f9b1f78bf8cfb3f259c8c1c01c3774aee3ce3
View
@@ -25,13 +25,25 @@ around 'parse' => sub {
my $email = $self->$orig( @_ );
for my $class ( $email->plugins ){
- return bless( $email, $class ) if $class->match( $email );
+ return $class->rebless( $email ) if $class->match( $email );
}
return $email;
};
+sub rebless {
+ my( $class, $email ) = @_;
+ return bless $email, $class;
+}
+
# --- Instance methods ---
+sub plain_content {
+ my $self = shift;
+ my $part = $self->plain_body_part;
+ return '' if !defined $part;
+ return $part->content
+}
+
sub _get_image_parts {
my $self = shift;
return $self->all_parts_matching(
@@ -0,0 +1,60 @@
+use strict;
+use warnings;
+
+package Courriel::MMS::Plugin::O2Ie;
+use namespace::autoclean;
+use Moose;
+
+extends 'Courriel::MMS';
+
+# --- Class methods ---
+
+sub match {
+ my $class = shift;
+ my $email = shift;
+
+ return 1 if $email->from =~ /mms\.o2\.ie/;
+ return;
+}
+
+
+# --- 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;
+
+__END__
+
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from O2 Ireland.
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 CLASS METHODS
+
+=head1 INSTANCE METHODS
+
+=head2 C<get_mms_images>
+
+=head1 SEE ALSO
+
+=head2 L<<< Courriel >>>
+
+=head1 AUTHOR
+
+Zbigniew Łukasiak, E<lt>zlukasiak@opera.comE<gt>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c), 2011 Opera Software ASA.
+All rights reserved.
@@ -0,0 +1,62 @@
+use strict;
+use warnings;
+
+package Courriel::MMS::Plugin::RadiolinjaFI;
+use namespace::autoclean;
+use Moose;
+
+extends 'Courriel::MMS';
+
+# --- Class methods ---
+
+sub match {
+ my $class = shift;
+ my $email = shift;
+
+ return 1 if $email->from =~ /mmsc\.radiolinja\.fi/;
+ return;
+}
+
+
+# --- Instance methods ---
+
+around plain_content => sub {
+ my $orig = shift;
+ my $self = shift;
+ my $content = $self->$orig();
+ return '' if $content eq 'This is a HTML message, sorry';
+ return $content;
+};
+
+
+
+__PACKAGE__->meta()->make_immutable();
+
+1;
+
+__END__
+
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from Telenor SE.
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 CLASS METHODS
+
+=head1 INSTANCE METHODS
+
+=head2 C<get_mms_images>
+
+=head1 SEE ALSO
+
+=head2 L<<< Courriel >>>
+
+=head1 AUTHOR
+
+Zbigniew Łukasiak, E<lt>zlukasiak@opera.comE<gt>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c), 2011 Opera Software ASA.
+All rights reserved.
@@ -23,15 +23,12 @@ sub match {
# --- Instance methods ---
-# this should really override the ->content method on $self->text_body_part
-# but how to do that elegantly?
-#
-sub text_content {
+sub plain_content {
my $self = shift;
my $html = $self->html_body_part->content;
- my ($body) = $html->[0] =~ m#<tr>\s+<td><pre[^>]+>(.*?)</pre></td>\s+</tr>#gs;
+ my ($body) = $html =~ m#<tr>\s+<td><pre[^>]+>(.*?)</pre></td>\s+</tr>#gs;
return $body;
}
@@ -0,0 +1,60 @@
+use strict;
+use warnings;
+
+package Courriel::MMS::Plugin::Tele2LT;
+use namespace::autoclean;
+use Moose;
+
+extends 'Courriel::MMS';
+
+# --- Class methods ---
+
+sub match {
+ my $class = shift;
+ my $email = shift;
+
+ return 1 if $email->from =~ /mms\.tele2/;
+ return;
+}
+
+
+# --- 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;
+
+__END__
+
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from Tele2 Lithuania.
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 CLASS METHODS
+
+=head1 INSTANCE METHODS
+
+=head2 C<get_mms_images>
+
+=head1 SEE ALSO
+
+=head2 L<<< Courriel >>>
+
+=head1 AUTHOR
+
+Zbigniew Łukasiak, E<lt>zlukasiak@opera.comE<gt>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c), 2011 Opera Software ASA.
+All rights reserved.
@@ -0,0 +1,65 @@
+use strict;
+use warnings;
+
+package Courriel::MMS::Plugin::TelenorSE;
+use namespace::autoclean;
+use Moose;
+
+extends 'Courriel::MMS';
+
+# --- Class methods ---
+
+sub match {
+ my $class = shift;
+ my $email = shift;
+
+ return 1 if $email->from =~ /mms-email\.telenor\.se/;
+ return;
+}
+
+
+# --- Instance methods ---
+
+around plain_content => sub {
+ my $orig = shift;
+ my $self = shift;
+ my $content = $self->$orig();
+ my $html = $self->html_body_part->content;
+ if( $html =~ m#<h1.*?</div>\n<div class="text-400">\n(.*?)\n</div>#s ){
+ $content = $content . $1;
+ }
+ return $content;
+};
+
+
+
+__PACKAGE__->meta()->make_immutable();
+
+1;
+
+__END__
+
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from Telenor SE.
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 CLASS METHODS
+
+=head1 INSTANCE METHODS
+
+=head2 C<get_mms_images>
+
+=head1 SEE ALSO
+
+=head2 L<<< Courriel >>>
+
+=head1 AUTHOR
+
+Zbigniew Łukasiak, E<lt>zlukasiak@opera.comE<gt>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c), 2011 Opera Software ASA.
+All rights reserved.
@@ -0,0 +1,76 @@
+use strict;
+use warnings;
+
+package Courriel::MMS::Plugin::VodafoneDE;
+use namespace::autoclean;
+use Moose;
+
+extends 'Courriel::MMS';
+
+# --- Class methods ---
+
+sub match {
+ my $class = shift;
+ my $email = shift;
+
+ return 1 if $email->from =~ /mmsmail\.vodafone\.de/;
+ return;
+}
+
+
+# --- 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(
+ sub {
+ my $part = shift;
+ my $mime = $part->mime_type();
+ return if $mime ne 'text/plain';
+ return if $part->content =~ m#http://www.vodafone.de#;
+ return 1;
+ }
+ );
+ return $part->content if $part;
+ return;
+};
+
+
+__PACKAGE__->meta()->make_immutable();
+
+1;
+
+__END__
+
+# ABSTRACT: L<Courriel::MMS> extension for dealing with MMS messages from Vodafone DE.
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 CLASS METHODS
+
+=head1 INSTANCE METHODS
+
+=head2 C<get_mms_images>
+
+=head1 SEE ALSO
+
+=head2 L<<< Courriel >>>
+
+=head1 AUTHOR
+
+Zbigniew Łukasiak, E<lt>zlukasiak@opera.comE<gt>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c), 2011 Opera Software ASA.
+All rights reserved.
Oops, something went wrong.

0 comments on commit 064f9b1

Please sign in to comment.