| 1 | package MMS::Mail::Provider::UK3; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base 'MMS::Mail::Provider'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MMS::Mail::Message::Parsed; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use HTML::TableExtract; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | MMS::Mail::Provider::UK3 - This provides a class for parsing an MMS::Mail::Message object that has been sent via the UK 3 network. | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 VERSION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | Version 0.02 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | This class provides a parse method for parsing an MMS::Mail::Message object into an MMS::Mail::Message::Parsed object for MMS messages sent from the UK 3 network. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 METHODS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | The following are the top-level methods of the MMS::Mail::Parser::UK3 class. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head2 Constructor | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =over | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =item C<new()> | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Return a new MMS::Mail::Provider::UK3 object. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =back | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 Regular Methods | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =over | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =item C<parse> MMS::Mail::Message | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | The C<parse> method is called as an instance method. It parses the MMS::Mail::Message object and returns an MMS::Mail::Message::Parsed object. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =back | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | Rob Lee, C<< <robl at robl.co.uk> >> | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 BUGS | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 58 | C<bug-mms-mail-provider-uk3 at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 59 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MMS-Mail-Provider-UK3>. | ||||||||||||||||||||||||||||
| 60 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 61 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | perldoc MMS::Mail::Provider::UK3 | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | You can also look for information at: | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =over 4 | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | L<http://annocpan.org/dist/MMS-Mail-Provider-UK3> | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | L<http://cpanratings.perl.org/d/MMS-Mail-Provider-UK3> | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MMS-Mail-Provider-UK3> | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | L<http://search.cpan.org/dist/MMS-Mail-Provider-UK3> | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =back | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | Copyright 2006 Rob Lee, all rights reserved. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 98 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 0 | my $message = shift; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | unless (defined $message) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | return undef; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | my $parsed = new MMS::Mail::Message::Parsed(message=>$message); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | my $htmltext=undef; | |||||||||||||||||||||||||||
| 114 | 0 | foreach my $element (@{$parsed->attachments}) { | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($element->mime_type eq 'text/html') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 116 | 0 | $htmltext = $element->bodyhandle->as_string; | |||||||||||||||||||||||||||
| 117 | } elsif ($element->mime_type =~ /jpeg$/) { | ||||||||||||||||||||||||||||
| 118 | 0 | my $header = $element->head; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($header->recommended_filename() !~ /^images\//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $parsed->add_image($element); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } elsif ($element->mime_type =~ /^video/) { | ||||||||||||||||||||||||||||
| 123 | 0 | $parsed->add_video($element); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | unless (defined $htmltext) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | return undef; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my $te1 = new HTML::TableExtract( depth => 2, count => 2 ); | |||||||||||||||||||||||||||
| 132 | 0 | $te1->parse($htmltext); | |||||||||||||||||||||||||||
| 133 | 0 | foreach my $ts1 ($te1->table_states) { | |||||||||||||||||||||||||||
| 134 | 0 | foreach my $row1 ($ts1->rows) { | |||||||||||||||||||||||||||
| 135 | 0 | foreach my $ele (@$row1) { | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ((defined $ele) && ($ele ne '')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ele and $ele ne ""
MC/DC0%0/2
defined $ele and $ele ne ""
defined $ele
$ele ne ""
Truth table0%0/3
A and B
A= defined $eleB= $ele ne ""
| |||||||||||||||||||||||||||||
| 137 | 0 | $parsed->header_subject($ele); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | my $te2 = new HTML::TableExtract( depth => 3, count => 2 ); | |||||||||||||||||||||||||||
| 144 | 0 | $te2->parse($htmltext); | |||||||||||||||||||||||||||
| 145 | 0 | my $text; | |||||||||||||||||||||||||||
| 146 | 0 | foreach my $ts2 ($te2->table_states) { | |||||||||||||||||||||||||||
| 147 | 0 | foreach my $row2 ($ts2->rows) { | |||||||||||||||||||||||||||
| 148 | 0 | $text = join('\n', @$row2); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ((defined $text) && $text ne "") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $text and $text ne ""
MC/DC0%0/2
defined $text and $text ne ""
defined $text
$text ne ""
Truth table0%0/3
A and B
A= defined $textB= $text ne ""
| |||||||||||||||||||||||||||||
| 151 | 0 | $parsed->body_text($text); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # Set mobile number property to a VALID number | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ($parsed->header_from =~ /<(.+)\/(.+)>/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | $parsed->phone_number('00'.$1); | |||||||||||||||||||||||||||
| 158 | 0 | return $parsed; | |||||||||||||||||||||||||||
| 159 | } else { | ||||||||||||||||||||||||||||
| 160 | 0 | return undef; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 2 | 1; # End of MMS::Mail::Provider::UK3 | |||||||||||||||||||||||||||