| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Image::Processor::Mail::GetImages; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 11 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 62 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 1 |  |  | 1 |  | 7 | use base 'Image::Processor::Base'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 87 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 2455 | use Mail::MboxParser; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub store_only { | 
| 10 |  |  |  |  |  |  | my ($self,$set) = @_; | 
| 11 |  |  |  |  |  |  | return $self->{'store_only'} if !$set; | 
| 12 |  |  |  |  |  |  | $self->{'store_only'} = $set; | 
| 13 |  |  |  |  |  |  | } | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub mbox_file { | 
| 16 |  |  |  |  |  |  | my ($self,$set) = @_; | 
| 17 |  |  |  |  |  |  | return $self->{'mbox_file'} if !$set; | 
| 18 |  |  |  |  |  |  | $self->{'mbox_file'} = $set; | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub attachment_output_directory { | 
| 22 |  |  |  |  |  |  | my ($self,$set) = @_; | 
| 23 |  |  |  |  |  |  | if (!-d $set && $set) { $self->error("Directory $set doesn't exist\n"); } | 
| 24 |  |  |  |  |  |  | return $self->{'attachment_output_directory'} if !$set; | 
| 25 |  |  |  |  |  |  | $self->{'attachment_output_directory'} = $set; | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub process_mails { | 
| 30 |  |  |  |  |  |  | my ($self) = @_; | 
| 31 |  |  |  |  |  |  | $self->graceful_exit( | 
| 32 |  |  |  |  |  |  | "You have not set 'attachment_output_directory'") | 
| 33 |  |  |  |  |  |  | if !$self->attachment_output_directory(); | 
| 34 |  |  |  |  |  |  | chdir( $self->mbox_file() ); | 
| 35 |  |  |  |  |  |  | foreach my $file ( <*> ) { | 
| 36 |  |  |  |  |  |  | # print "Working on $file\n"; | 
| 37 |  |  |  |  |  |  | process_file($file); | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub process_file { | 
| 42 |  |  |  |  |  |  | my ($self,$file) = @_; | 
| 43 |  |  |  |  |  |  | $self->graceful_exit( | 
| 44 |  |  |  |  |  |  | "You have not 'attachment_output_directory'") | 
| 45 |  |  |  |  |  |  | if !$self->attachment_output_directory(); | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | $file = "/$file" if $file; | 
| 48 |  |  |  |  |  |  | my $file_to_open = $self->mbox_file() . "$file"; | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | my $mb = Mail::MboxParser->new($file_to_open, decode => 'ALL'); | 
| 51 |  |  |  |  |  |  | my $store_only = $self->store_only() || '(jpg|gif)$'; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | while (my $msg = $mb->next_message) { | 
| 54 |  |  |  |  |  |  | $msg->store_all_attachments( | 
| 55 |  |  |  |  |  |  | path => $self->attachment_output_directory(), | 
| 56 |  |  |  |  |  |  | store_only => $store_only | 
| 57 |  |  |  |  |  |  | ); | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | 1; | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | __END__ |