| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package MMS::Mail::Message; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 65699 | use warnings; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 90 |  | 
| 4 | 3 |  |  | 3 |  | 16 | use strict; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 217 |  | 
| 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 |  |  |  |  |  |  | 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 method but before it has been through the second stage of parsing (the MMS::Mail::Parser C method).  If this doesn't make sense then take a look at L 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 | 
| 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 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 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 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 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 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 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 STRING | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | Instance method - The supplied string should be a set of characters valid for use in a regular expression character class C .  When set with a value the property is used by the C, C, C, C and C methods to remove these characters from their respective properties (in both the C and C classes).  | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =item C 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, C, C, C and C. | 
| 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 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 MIME::Entity | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | Instance method - Adds the supplied C attachment to the attachment stack for the message.  This method is mainly used by the C class to add attachments while parsing. | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =item C | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | Instance method - Returns true or false depending if the C, C and C fields are all populated or not. | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =item C | 
| 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<<  >> | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head1 BUGS | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 99 |  |  |  |  |  |  | C, or through the web interface at | 
| 100 |  |  |  |  |  |  | L. | 
| 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, L, L | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =cut | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 3 |  |  | 3 |  | 14 | use base "Class::Accessor"; | 
|  | 3 |  |  |  |  | 21 |  | 
|  | 3 |  |  |  |  | 2746 |  | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | # Class data | 
| 132 |  |  |  |  |  |  | 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 |  |  |  |  |  |  | my @NoClone=(	"body_text", | 
| 143 |  |  |  |  |  |  | "header_subject" | 
| 144 |  |  |  |  |  |  | ); | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | # Class data retrieval | 
| 147 |  |  |  |  |  |  | sub _Accessors { | 
| 148 | 3 |  |  | 3 |  | 30 | return \@Accessors; | 
| 149 |  |  |  |  |  |  | } | 
| 150 |  |  |  |  |  |  | sub _NoClone { | 
| 151 | 0 |  |  | 0 |  | 0 | return \@NoClone; | 
| 152 |  |  |  |  |  |  | } | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | __PACKAGE__->mk_accessors(@{__PACKAGE__->_Accessors}); | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | sub new { | 
| 157 |  |  |  |  |  |  |  | 
| 158 | 1 |  |  | 1 | 1 | 13 | my $type = shift; | 
| 159 | 1 |  |  |  |  | 12 | my $self = SUPER::new $type( {@_} ); | 
| 160 |  |  |  |  |  |  |  | 
| 161 | 1 |  |  |  |  | 17 | $self->SUPER::set('attachments', []); | 
| 162 | 1 |  |  |  |  | 17 | $self->SUPER::set('cleanse_map', {}); | 
| 163 | 1 |  |  |  |  | 10 | $self->SUPER::set('strip_characters', ''); | 
| 164 |  |  |  |  |  |  |  | 
| 165 | 1 |  |  |  |  | 12 | return $self; | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | } | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | # Override Class::Accessor default set method | 
| 170 |  |  |  |  |  |  | sub set { | 
| 171 |  |  |  |  |  |  |  | 
| 172 | 15 |  |  | 15 | 1 | 4132 | my $self = shift; | 
| 173 | 15 |  |  |  |  | 23 | my $key = shift; | 
| 174 | 15 |  |  |  |  | 17 | my $element = shift; | 
| 175 | 15 |  |  |  |  | 33 | my $strippers = $self->strip_characters; | 
| 176 | 15 | 100 | 66 |  |  | 204 | if ((defined $strippers) && ($strippers ne '')) { | 
| 177 | 6 |  |  |  |  | 43 | $element =~ s/[$strippers]//g; | 
| 178 |  |  |  |  |  |  | } | 
| 179 | 15 | 100 |  |  |  | 30 | if (exists $self->cleanse_map->{$key}) { | 
| 180 |  |  |  |  |  |  | # CODE REFERENCE | 
| 181 | 3 | 100 |  |  |  | 24 | if (ref $self->cleanse_map->{$key} eq "CODE") { | 
| 182 | 1 |  |  |  |  | 34 | my $ref = $self->cleanse_map->{$key}; | 
| 183 | 1 |  |  |  |  | 7 | $element = &$ref($element); | 
| 184 |  |  |  |  |  |  | } else { | 
| 185 |  |  |  |  |  |  | # REGEX | 
| 186 | 2 |  |  |  |  | 18 | my $strippers = $self->cleanse_map->{$key}; | 
| 187 | 2 |  |  |  |  | 162 | eval '$element=~'.$strippers; | 
| 188 |  |  |  |  |  |  | } | 
| 189 |  |  |  |  |  |  | } | 
| 190 |  |  |  |  |  |  |  | 
| 191 | 15 |  |  |  |  | 110 | $self->SUPER::set($key, $element); | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | } | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | # Overide accessors so strip_characters and cleanse_map not applied | 
| 196 |  |  |  |  |  |  | sub cleanse_map { | 
| 197 | 24 |  |  | 24 | 1 | 721 | my $self = shift; | 
| 198 | 24 | 100 |  |  |  | 48 | if (@_) { $self->SUPER::set('cleanse_map', shift) } | 
|  | 3 |  |  |  |  | 9 |  | 
| 199 | 24 |  |  |  |  | 77 | return $self->SUPER::get('cleanse_map'); | 
| 200 |  |  |  |  |  |  | } | 
| 201 |  |  |  |  |  |  | sub attachments { | 
| 202 | 2 |  |  | 2 | 1 | 2029 | my $self = shift; | 
| 203 | 2 | 100 |  |  |  | 7 | if (@_) { $self->SUPER::set('attachments', shift) } | 
|  | 1 |  |  |  |  | 5 |  | 
| 204 | 2 |  |  |  |  | 15 | return $self->SUPER::get('attachments'); | 
| 205 |  |  |  |  |  |  | } | 
| 206 |  |  |  |  |  |  | sub strip_characters { | 
| 207 | 17 |  |  | 17 | 1 | 2357 | my $self = shift; | 
| 208 | 17 | 100 |  |  |  | 39 | if (@_) { $self->SUPER::set('strip_characters', shift) } | 
|  | 2 |  |  |  |  | 6 |  | 
| 209 | 17 |  |  |  |  | 60 | return $self->SUPER::get('strip_characters'); | 
| 210 |  |  |  |  |  |  | } | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | sub add_attachment { | 
| 213 |  |  |  |  |  |  |  | 
| 214 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 215 | 0 |  |  |  |  | 0 | my $attachment = shift; | 
| 216 |  |  |  |  |  |  |  | 
| 217 | 0 | 0 |  |  |  | 0 | unless (defined $attachment) { | 
| 218 | 0 |  |  |  |  | 0 | return 0; | 
| 219 |  |  |  |  |  |  | } | 
| 220 |  |  |  |  |  |  |  | 
| 221 | 0 |  |  |  |  | 0 | my $attach = $self->attachments; | 
| 222 | 0 |  |  |  |  | 0 | push @{$attach}, $attachment; | 
|  | 0 |  |  |  |  | 0 |  | 
| 223 | 0 |  |  |  |  | 0 | $self->SUPER::set('attachments', $attach); | 
| 224 |  |  |  |  |  |  |  | 
| 225 | 0 |  |  |  |  | 0 | return 1; | 
| 226 |  |  |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | } | 
| 228 |  |  |  |  |  |  |  | 
| 229 |  |  |  |  |  |  | sub is_valid { | 
| 230 |  |  |  |  |  |  |  | 
| 231 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 232 |  |  |  |  |  |  |  | 
| 233 | 0 | 0 |  |  |  | 0 | unless ($self->header_from) { | 
| 234 | 0 |  |  |  |  | 0 | return 0; | 
| 235 |  |  |  |  |  |  | } | 
| 236 | 0 | 0 |  |  |  | 0 | unless ($self->header_to) { | 
| 237 | 0 |  |  |  |  | 0 | return 0; | 
| 238 |  |  |  |  |  |  | } | 
| 239 | 0 | 0 |  |  |  | 0 | unless ($self->header_datetime) { | 
| 240 | 0 |  |  |  |  | 0 | return 0; | 
| 241 |  |  |  |  |  |  | } | 
| 242 |  |  |  |  |  |  |  | 
| 243 | 0 |  |  |  |  | 0 | return 1; | 
| 244 |  |  |  |  |  |  |  | 
| 245 |  |  |  |  |  |  | } | 
| 246 |  |  |  |  |  |  |  | 
| 247 |  |  |  |  |  |  | sub _clone_data { | 
| 248 |  |  |  |  |  |  |  | 
| 249 | 0 |  |  | 0 |  | 0 | my $self = shift; | 
| 250 | 0 |  |  |  |  | 0 | my $message = shift; | 
| 251 |  |  |  |  |  |  |  | 
| 252 | 0 |  |  |  |  | 0 | my %seen; | 
| 253 | 0 |  |  |  |  | 0 | @seen{@{$self->_NoClone}} = (); | 
|  | 0 |  |  |  |  | 0 |  | 
| 254 |  |  |  |  |  |  |  | 
| 255 | 0 |  |  |  |  | 0 | foreach my $field (@{__PACKAGE__->_Accessors()}) { | 
|  | 0 |  |  |  |  | 0 |  | 
| 256 | 0 | 0 |  |  |  | 0 | unless (exists $seen{$field}) { | 
| 257 | 0 |  |  |  |  | 0 | $self->{$field} = $message->{$field}; | 
| 258 |  |  |  |  |  |  | } | 
| 259 |  |  |  |  |  |  | } | 
| 260 |  |  |  |  |  |  |  | 
| 261 |  |  |  |  |  |  | } | 
| 262 |  |  |  |  |  |  |  | 
| 263 |  |  |  |  |  |  | sub DESTROY { | 
| 264 |  |  |  |  |  |  |  | 
| 265 | 1 |  |  | 1 |  | 333 | my $self = shift; | 
| 266 |  |  |  |  |  |  |  | 
| 267 | 1 |  |  |  |  | 2 | foreach my $attach (@{$self->attachments}) { | 
|  | 1 |  |  |  |  | 3 |  | 
| 268 | 0 |  |  |  |  |  | $attach->bodyhandle->purge; | 
| 269 |  |  |  |  |  |  | } | 
| 270 |  |  |  |  |  |  |  | 
| 271 |  |  |  |  |  |  | } | 
| 272 |  |  |  |  |  |  |  | 
| 273 |  |  |  |  |  |  | 1; # End of MMS::Mail::Message |