| 1 | package MMS::Mail::Message; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | MMS::Mail::Message - A class representing an MMS (or picture) message sent via email. | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 VERSION | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Version 0.06 | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | This class is used by MMS::Mail::Parser to provide an itermediate data storage class after the MMS has been parsed by the C<parse> method but before it has been through the second stage of parsing (the MMS::Mail::Parser C<provider_parse> method). If this doesn't make sense then take a look at L<MMS::Mail::Parser> to get an idea where this module fits in before progressing any further. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 METHODS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | The following are the top-level methods of the MMS::Mail::Message class. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head2 Constructor | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =over | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =item C<new()> | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Return a new MMS::Mail::Message object. Valid attributes are any public accessor outlined in the Regular Methods section below. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =back | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head2 Regular Methods | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =over | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =item C<header_datetime> STRING | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Instance method - Returns the time and date the MMS was received when invoked with no supplied parameter. When supplied with a parameter it sets the object property to the supplied parameter. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item C<header_from> STRING | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Instance method - Returns the sending email address the MMS was sent from when invoked with no supplied parameter. When supplied with a parameter it sets the object property to the supplied parameter. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item C<header_to> STRING | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Instance method - Returns the recieving email address the MMS was sent to when invoked with no supplied parameter. When supplied with a parameter it sets the object property to the supplied parameter. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item C<header_subject> STRING | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Instance method - Returns the MMS subject when invoked with no supplied parameter. When supplied with a parameter it sets the object property to the supplied parameter. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item C<header_received_from> STRING | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Instance method - Returns the email server that (last) sent the mms when invoked with no supplied parameter. When supplied with a parameter it sets the object property to the supplied parameter. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item C<body_text> STRING | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Instance method - Returns the MMS bodytext when invoked with no supplied parameter. When supplied with a paramater it sets the object property to the supplied parameter. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item C<strip_characters> STRING | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Instance method - The supplied string should be a set of characters valid for use in a regular expression character class C<s/[]//g>. When set with a value the property is used by the C<header_from>, C<header_to>, C<header_datetime>, C<body_text> and C<header_subject> methods to remove these characters from their respective properties (in both the C<MMS::Mail::Message> and C<MMS::Mail::Message::Parsed> classes). | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =item C<cleanse_map> HASHREF | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Instance method - This method allows a regular expression or subroutine reference to be applied when an accessor sets a value, allowing message values to be cleansed or modified. These accessors are C<header_from>, C<header_to>, C<body_text>, C<header_datetime> and C<header_subject>. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | The method expects a hash reference with key values as one of the above public accessor method names and values as a scalar in the form of a regular expression or as a subroutine reference. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =item C<attachments> ARRAYREF | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Instance method - Returns an array reference to the array of MMS message attachments. When supplied with a parameter it sets the object property to the supplied parameter. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =item C<add_attachment> MIME::Entity | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | Instance method - Adds the supplied C<MIME::Entity> attachment to the attachment stack for the message. This method is mainly used by the C<MMS::Mail::Parser> class to add attachments while parsing. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =item C<is_valid> | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Instance method - Returns true or false depending if the C<header_datetime>, C<header_from> and C<header_to> fields are all populated or not. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =item C<set> | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Instance method - Overides the Class::Accessor superclass set method to apply cleanse_map and strip_character functionality to accessors. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =back | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Rob Lee, C<< <robl at robl.co.uk> >> | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 BUGS | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 99 | C<bug-mms-mail-message@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 100 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MMS-Mail-Message>. | ||||||||||||||||||||||||||||
| 101 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 102 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 NOTES | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Please read the Perl artistic license ('perldoc perlartistic') : | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||||||||||||||||
| 109 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES | ||||||||||||||||||||||||||||
| 110 | OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | As per usual this module is sprinkled with a little Deb magic. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Copyright 2005 Rob Lee, all rights reserved. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 121 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | L<MMS::Mail::Message>, L<MMS::Mail::Message::Parsed>, L<MMS::Mail::Provider> | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 4 | ▶ | use base "Class::Accessor"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # Class data | ||||||||||||||||||||||||||||
| 132 | 4 | my @Accessors=( "header_from", | |||||||||||||||||||||||||||
| 133 | "header_to", | ||||||||||||||||||||||||||||
| 134 | "body_text", | ||||||||||||||||||||||||||||
| 135 | "header_datetime", | ||||||||||||||||||||||||||||
| 136 | "header_subject", | ||||||||||||||||||||||||||||
| 137 | "header_received_from", | ||||||||||||||||||||||||||||
| 138 | "cleanse_map", | ||||||||||||||||||||||||||||
| 139 | "strip_characters", | ||||||||||||||||||||||||||||
| 140 | "attachments" | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | 4 | my @NoClone=( "body_text", | |||||||||||||||||||||||||||
| 143 | "header_subject" | ||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Class data retrieval | ||||||||||||||||||||||||||||
| 147 | 4 | ▶ | sub _Accessors { | ||||||||||||||||||||||||||
|
Subroutine
_Accessors: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 148 | 4 | return \@Accessors; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub _NoClone { | ||||||||||||||||||||||||||
|
Subroutine
_NoClone: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 151 | 0 | return \@NoClone; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 4 | __PACKAGE__->mk_accessors(@{__PACKAGE__->_Accessors}); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 1 | my $type = shift; | |||||||||||||||||||||||||||
| 159 | 1 | my $self = SUPER::new $type( {@_} ); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 1 | $self->SUPER::set('attachments', []); | |||||||||||||||||||||||||||
| 162 | 1 | $self->SUPER::set('cleanse_map', {}); | |||||||||||||||||||||||||||
| 163 | 1 | $self->SUPER::set('strip_characters', ''); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 1 | return $self; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # Override Class::Accessor default set method | ||||||||||||||||||||||||||||
| 170 | 15 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 15 | my $self = shift; | |||||||||||||||||||||||||||
| 173 | 15 | my $key = shift; | |||||||||||||||||||||||||||
| 174 | 15 | my $element = shift; | |||||||||||||||||||||||||||
| 175 | 15 | my $strippers = $self->strip_characters; | |||||||||||||||||||||||||||
| 176 | 15 | ▶ | if ((defined $strippers) && ($strippers ne '')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $strippers and $strippers ne ""
MC/DC50%1/2
defined $strippers and $strippers ne ""
defined $strippers
$strippers ne ""
Truth table66%2/3
A and B
A= defined $strippersB= $strippers ne ""
| |||||||||||||||||||||||||||||
| 177 | 6 | $element =~ s/[$strippers]//g; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 15 | ▶ | if (exists $self->cleanse_map->{$key}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | # CODE REFERENCE | ||||||||||||||||||||||||||||
| 181 | 3 | ▶ | if (ref $self->cleanse_map->{$key} eq "CODE") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 1 | my $ref = $self->cleanse_map->{$key}; | |||||||||||||||||||||||||||
| 183 | 1 | $element = &$ref($element); | |||||||||||||||||||||||||||
| 184 | } else { | ||||||||||||||||||||||||||||
| 185 | # REGEX | ||||||||||||||||||||||||||||
| 186 | 2 | my $strippers = $self->cleanse_map->{$key}; | |||||||||||||||||||||||||||
| 187 | 2 | eval '$element=~'.$strippers; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 15 | $self->SUPER::set($key, $element); | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # Overide accessors so strip_characters and cleanse_map not applied | ||||||||||||||||||||||||||||
| 196 | 24 | ▶ | sub cleanse_map { | ||||||||||||||||||||||||||
|
Subroutine
cleanse_map: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | 24 | my $self = shift; | |||||||||||||||||||||||||||
| 198 | 24 | ▶ | if (@_) { $self->SUPER::set('cleanse_map', shift) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 24 | return $self->SUPER::get('cleanse_map'); | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | 2 | ▶ | sub attachments { | ||||||||||||||||||||||||||
|
Subroutine
attachments: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 203 | 2 | ▶ | if (@_) { $self->SUPER::set('attachments', shift) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 2 | return $self->SUPER::get('attachments'); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | 17 | ▶ | sub strip_characters { | ||||||||||||||||||||||||||
|
Subroutine
strip_characters: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 207 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 208 | 17 | ▶ | if (@_) { $self->SUPER::set('strip_characters', shift) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 17 | return $self->SUPER::get('strip_characters'); | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub add_attachment { | ||||||||||||||||||||||||||
|
Subroutine
add_attachment: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 215 | 0 | my $attachment = shift; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | unless (defined $attachment) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | return 0; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | my $attach = $self->attachments; | |||||||||||||||||||||||||||
| 222 | 0 | push @{$attach}, $attachment; | |||||||||||||||||||||||||||
| 223 | 0 | $self->SUPER::set('attachments', $attach); | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | return 1; | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | sub is_valid { | ||||||||||||||||||||||||||
|
Subroutine
is_valid: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | ▶ | unless ($self->header_from) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 0 | return 0; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 0 | ▶ | unless ($self->header_to) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 0 | return 0; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | 0 | ▶ | unless ($self->header_datetime) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 0 | return 0; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | return 1; | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | sub _clone_data { | ||||||||||||||||||||||||||
|
Subroutine
_clone_data: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 250 | 0 | my $message = shift; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | my %seen; | |||||||||||||||||||||||||||
| 253 | 0 | @seen{@{$self->_NoClone}} = (); | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | foreach my $field (@{__PACKAGE__->_Accessors()}) { | |||||||||||||||||||||||||||
| 256 | 0 | ▶ | unless (exists $seen{$field}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 0 | $self->{$field} = $message->{$field}; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 1 | foreach my $attach (@{$self->attachments}) { | |||||||||||||||||||||||||||
| 268 | 0 | $attach->bodyhandle->purge; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 4 | 1; # End of MMS::Mail::Message | |||||||||||||||||||||||||||