| 1 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | package Email::Folder; | ||||||||||||||||||||
| 4 | # ABSTRACT: read all the messages from a folder as Email::Simple objects | ||||||||||||||||||||
| 5 | 3 | $Email::Folder::VERSION = '0.859'; | |||||||||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 3 | ▶ | use Email::Simple; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use Email::FolderType 0.6 qw/folder_type/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | #pod =head1 SYNOPSIS | ||||||||||||||||||||
| 11 | #pod | ||||||||||||||||||||
| 12 | #pod use Email::Folder; | ||||||||||||||||||||
| 13 | #pod | ||||||||||||||||||||
| 14 | #pod my $folder = Email::Folder->new("some_file"); | ||||||||||||||||||||
| 15 | #pod | ||||||||||||||||||||
| 16 | #pod print join "\n", map { $_->header("Subject") } $folder->messages; | ||||||||||||||||||||
| 17 | #pod | ||||||||||||||||||||
| 18 | #pod =head1 METHODS | ||||||||||||||||||||
| 19 | #pod | ||||||||||||||||||||
| 20 | #pod =head2 new($folder, %options) | ||||||||||||||||||||
| 21 | #pod | ||||||||||||||||||||
| 22 | #pod Takes the name of a folder, and a hash of options | ||||||||||||||||||||
| 23 | #pod | ||||||||||||||||||||
| 24 | #pod If a 'reader' option is passed in then that is | ||||||||||||||||||||
| 25 | #pod used as the class to read in messages with. | ||||||||||||||||||||
| 26 | #pod | ||||||||||||||||||||
| 27 | #pod =cut | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | sub new { | ||||||||||||||||||||
| 30 | 11 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||
| 31 | 11 | ▶ | my $folder = shift || carp "Must provide a folder name\n"; | ||||||||||||||||||
|
Condition33%1/3
shift() || carp("Must provide a folder name\n")
MC/DC0%0/2
shift() || carp("Must provide a folder name\n")
shift()
carp("Must provide a folder name\n")
Truth table33%1/3
A || B
A= shift()B= carp("Must provide a folder name\n")
| |||||||||||||||||||||
| 32 | 11 | my %self = @_; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 11 | my $reader; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 11 | ▶ | if ($self{reader}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 0 | $reader = $self{reader}; | |||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||
| 39 | 11 | $reader = "Email::Folder::".folder_type($folder); | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | 11 | ▶ | eval "require $reader" or die $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 11 | $self{_folder} = $reader->new($folder, @_); | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 11 | return bless \%self, $class; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | #pod =head2 messages | ||||||||||||||||||||
| 49 | #pod | ||||||||||||||||||||
| 50 | #pod Returns a list containing all of the messages in the folder. Can only | ||||||||||||||||||||
| 51 | #pod be called once as it drains the iterator. | ||||||||||||||||||||
| 52 | #pod | ||||||||||||||||||||
| 53 | #pod =cut | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | sub messages { | ||||||||||||||||||||
| 56 | 9 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
messages: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 9 | my @messages = $self->{_folder}->messages; | |||||||||||||||||||
| 59 | 9 | my @ret; | |||||||||||||||||||
| 60 | 9 | ▶ | while (my $body = shift @messages) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 52 | push @ret, $self->bless_message( $body ); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 9 | return @ret; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | #pod =head2 next_message | ||||||||||||||||||||
| 68 | #pod | ||||||||||||||||||||
| 69 | #pod acts as an iterator. reads the next message from a folder. returns | ||||||||||||||||||||
| 70 | #pod false at the end of the folder | ||||||||||||||||||||
| 71 | #pod | ||||||||||||||||||||
| 72 | #pod =cut | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | sub next_message { | ||||||||||||||||||||
| 75 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
next_message: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 2 | ▶ | my $body = $self->{_folder}->next_message or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 2 | $self->bless_message( $body ); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | #pod =head2 bless_message($message) | ||||||||||||||||||||
| 83 | #pod | ||||||||||||||||||||
| 84 | #pod Takes a raw RFC822 message and blesses it into a class. | ||||||||||||||||||||
| 85 | #pod | ||||||||||||||||||||
| 86 | #pod By default this is an Email::Simple object but can easily be overridden | ||||||||||||||||||||
| 87 | #pod in a subclass. | ||||||||||||||||||||
| 88 | #pod | ||||||||||||||||||||
| 89 | #pod For example, this simple subclass just returns the raw rfc822 messages, | ||||||||||||||||||||
| 90 | #pod and exposes the speed of the parser. | ||||||||||||||||||||
| 91 | #pod | ||||||||||||||||||||
| 92 | #pod package Email::RawFolder; | ||||||||||||||||||||
| 93 | #pod use base 'Email::Folder'; | ||||||||||||||||||||
| 94 | #pod sub bless_message { $_[1] }; | ||||||||||||||||||||
| 95 | #pod 1; | ||||||||||||||||||||
| 96 | #pod | ||||||||||||||||||||
| 97 | #pod =cut | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | sub bless_message { | ||||||||||||||||||||
| 100 | 54 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
bless_message: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 101 | 54 | ▶ | my $message = shift || die "You must pass a message\n"; | ||||||||||||||||||
|
Condition50%1/2
shift() || die("You must pass a message\n")
MC/DC0%0/1
shift() || die("You must pass a message\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 54 | return Email::Simple->new($message); | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | #pod =head2 reader | ||||||||||||||||||||
| 108 | #pod | ||||||||||||||||||||
| 109 | #pod read-only accessor to the underlying Email::Reader subclass instance | ||||||||||||||||||||
| 110 | #pod | ||||||||||||||||||||
| 111 | #pod =cut | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | sub reader { | ||||||||||||||||||||
| 114 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
reader: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 115 | 1 | return $self->{_folder}; | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 3 | 1; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | #pod =head1 SEE ALSO | ||||||||||||||||||||
| 121 | #pod | ||||||||||||||||||||
| 122 | #pod L<Email::LocalDelivery>, L<Email::FolderType>, L<Email::Simple> | ||||||||||||||||||||
| 123 | #pod | ||||||||||||||||||||
| 124 | #pod =cut | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||