| 1 | package Net::IMAP::SimpleX::NIL; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 0 | ▶ | use overload fallback=>1, '""' => sub { "" }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||
| 6 | 0 | ▶ | sub new { return bless {}, "Net::IMAP::SimpleX::NIL" } | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||
| 7 | |||||||||||||
| 8 | package Net::IMAP::SimpleX::Body; | ||||||||||||
| 9 | |||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | no warnings 'once'; ## no critic | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 1 | our $uidm; | |||||||||||
| 15 | |||||||||||||
| 16 | 1 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||
| 17 | 1 | our @fields = qw/content_description encoded_size charset content_type format part_number id name encoding/; | |||||||||||
| 18 | 1 | for my $attr (@fields) { | |||||||||||
| 19 | 1 | ▶ | no strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 0 | ▶ | *{"Net::IMAP::SimpleX::Body::$attr"} = sub { shift->{$attr}; }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||||
| 21 | } | ||||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | 0 | ▶ | sub hasparts { return 0; } *has_parts = \&hasparts; | ||||||||||
|
Subroutine
hasparts: not called CC=1 SCAR=1.2
| |||||||||||||
| 25 | 0 | ▶ | sub parts { return } | ||||||||||
|
Subroutine
parts: not called CC=1 SCAR=6.9
| |||||||||||||
| 26 | 0 | ▶ | sub type { return } | ||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
| |||||||||||||
| 27 | 0 | ▶ | sub body { return shift; } | ||||||||||
|
Subroutine
body: not called CC=1 SCAR=6.9
| |||||||||||||
| 28 | |||||||||||||
| 29 | package Net::IMAP::SimpleX::BodySummary; | ||||||||||||
| 30 | |||||||||||||
| 31 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | 1 | ▶ | no warnings 'once'; ## no critic | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | |||||||||||||
| 35 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||
| 36 | 0 | my ($class, $data) = @_; | |||||||||||
| 37 | 0 | my $self; | |||||||||||
| 38 | |||||||||||||
| 39 | 0 | Net::IMAP::SimpleX::_id_parts($data); | |||||||||||
| 40 | |||||||||||||
| 41 | 0 | ▶ | if ($data->{parts}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 0 | $self = $data; | |||||||||||
| 43 | } else { | ||||||||||||
| 44 | 0 | $self = { body => $data }; | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 0 | return bless $self, $class; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 0 | ▶ | sub hasparts { return shift->{parts} ? 1 : 0; } *has_parts = \&hasparts; | ||||||||||
|
Subroutine
hasparts: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||
| 51 | 0 | ▶ | sub parts { my $self = shift; return wantarray ? @{$self->{parts}} : $self->{parts}; } | ||||||||||
|
Subroutine
parts: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||
| 52 | 0 | ▶ | sub type { return shift->{type} || undef; } | ||||||||||
|
Subroutine
type: not called CC=2 SCAR=17.9
Condition0%0/2
+(shift())->{'type'} || undef
MC/DC0%0/1
+(shift())->{'type'} || undef
+(shift())->{'type'}
Truth table0%0/2
A
A= +(shift())->{'type'}
| |||||||||||||
| 53 | 0 | ▶ | sub body { return shift->{body}; } | ||||||||||
|
Subroutine
body: not called CC=1 SCAR=6.9
| |||||||||||||
| 54 | |||||||||||||
| 55 | |||||||||||||
| 56 | package Net::IMAP::SimpleX; | ||||||||||||
| 57 | |||||||||||||
| 58 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 59 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 60 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 61 | 1 | ▶ | use Parse::RecDescent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 62 | 1 | ▶ | use base 'Net::IMAP::Simple'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 63 | |||||||||||||
| 64 | 1 | our $VERSION = "1.1000"; | |||||||||||
| 65 | |||||||||||||
| 66 | # directly from http://tools.ietf.org/html/rfc3501#section-9 | ||||||||||||
| 67 | # try and flatten, format as best we can | ||||||||||||
| 68 | 1 | our $body_grammar = q { | |||||||||||
| 69 | body: body_type_mpart | body_type_1part | ||||||||||||
| 70 | { $return = bless $item[1], 'Net::IMAP::SimpleX::Body'; } | ||||||||||||
| 71 | body_type_mpart: '('body(s) subtype')' | ||||||||||||
| 72 | { $return = bless { | ||||||||||||
| 73 | parts => $item[2], | ||||||||||||
| 74 | type => $item{subtype} | ||||||||||||
| 75 | }, 'Net::IMAP::SimpleX::BodySummary'; | ||||||||||||
| 76 | } | ||||||||||||
| 77 | body_type_1part: body_type_basic | body_type_text | ||||||||||||
| 78 | { $return = bless $item[1], 'Net::IMAP::SimpleX::BodySummary'; } | ||||||||||||
| 79 | body_type_basic: '('media_type body_fields')' | ||||||||||||
| 80 | { $return = { | ||||||||||||
| 81 | content_type => $item{media_type}, | ||||||||||||
| 82 | %{$item{body_fields}} | ||||||||||||
| 83 | }; | ||||||||||||
| 84 | } | ||||||||||||
| 85 | body_type_text: '('media_type body_fields number')' | ||||||||||||
| 86 | { $return = { | ||||||||||||
| 87 | content_type => $item{media_type}, | ||||||||||||
| 88 | %{$item{body_fields}}, | ||||||||||||
| 89 | }} | ||||||||||||
| 90 | body_fields: body_field_param body_field_id body_field_desc body_field_enc body_field_octets | ||||||||||||
| 91 | { $return = { | ||||||||||||
| 92 | id => $item{body_field_id}, | ||||||||||||
| 93 | content_description => $item{body_field_desc}, | ||||||||||||
| 94 | encoding => $item{body_field_enc}, | ||||||||||||
| 95 | encoded_size => $item{body_field_octets}, | ||||||||||||
| 96 | $item{body_field_param} ? %{$item{body_field_param}} : () | ||||||||||||
| 97 | }; | ||||||||||||
| 98 | } | ||||||||||||
| 99 | body_field_id: nil | word | ||||||||||||
| 100 | body_field_desc: nil | word | ||||||||||||
| 101 | body_field_enc: word | ||||||||||||
| 102 | body_field_octets: number | ||||||||||||
| 103 | body_field_param: body_field_param_simple | body_field_param_ext | nil | ||||||||||||
| 104 | body_field_param_ext: '('word word word word')' | ||||||||||||
| 105 | { $return = { $item[2] => $item[3], $item[4] => $item[5] }; } | ||||||||||||
| 106 | body_field_param_simple: '('word word')' | ||||||||||||
| 107 | { $return = { $item[2] => $item[3] }; } | ||||||||||||
| 108 | body_field_param: nil | ||||||||||||
| 109 | media_type: type subtype | ||||||||||||
| 110 | { $return = "$item{type}/$item{subtype}"; } | ||||||||||||
| 111 | type: word | ||||||||||||
| 112 | subtype: word | ||||||||||||
| 113 | nil: 'NIL' | ||||||||||||
| 114 | {$return = '';} | ||||||||||||
| 115 | number: /\d+/ | ||||||||||||
| 116 | key: word | ||||||||||||
| 117 | value: word | ||||||||||||
| 118 | word: /[^\s\)\(]+/ | ||||||||||||
| 119 | { $item[1] =~ s/\"//g; $return = $item[1];} | ||||||||||||
| 120 | }; | ||||||||||||
| 121 | |||||||||||||
| 122 | 1 | our $fetch_grammar = q& | |||||||||||
| 123 | fetch: fetch_item(s) {$return={ map {(@$_)} reverse @{$item[1]} }} | ||||||||||||
| 124 | |||||||||||||
| 125 | fetch_item: cmd_start 'FETCH' '(' value_pair(s?) ')' {$return=[$item[1], {map {(@$_)} @{$item[4]}}]} | ||||||||||||
| 126 | |||||||||||||
| 127 | cmd_start: '*' /\d+/ {$return=$item[2]} | ||||||||||||
| 128 | |||||||||||||
| 129 | value_pair: tag value {$return=[$item[1], $item[2]]} | ||||||||||||
| 130 | |||||||||||||
| 131 | tag: /BODY\b(?:\.PEEK)?(?:\[[^\]]*\])?(?:<[\d\.]*>)?/i | atom | ||||||||||||
| 132 | |||||||||||||
| 133 | value: atom | string | parenthized_list | ||||||||||||
| 134 | |||||||||||||
| 135 | atom: /[^"()\s{}[\]]+/ { | ||||||||||||
| 136 | # strictly speaking, the NIL atom should be undef, but P::RD isn't going to allow that. | ||||||||||||
| 137 | # returning a null character instead | ||||||||||||
| 138 | $return=($item[1] eq "NIL" ? Net::IMAP::SimpleX::NIL->new : $item[1]) | ||||||||||||
| 139 | } | ||||||||||||
| 140 | |||||||||||||
| 141 | string: '"' /[^\x0d\x0a"]*/ '"' {$return=$item[2]} | '{' /\d+/ "}\x0d\x0a" { | ||||||||||||
| 142 | $return = length($text) >= $item[2] | ||||||||||||
| 143 | ? substr($text,0,$item[2],"") # if the production is accepted, we alter the input stream | ||||||||||||
| 144 | : undef; | ||||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | parenthized_list: '(' value(s?) ')' {$return=$item[2]} | ||||||||||||
| 148 | &; | ||||||||||||
| 149 | |||||||||||||
| 150 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 151 | 0 | my $class = shift; | |||||||||||
| 152 | 0 | ▶ | if (my $self = $class->SUPER::new(@_)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 153 | |||||||||||||
| 154 | 0 | $self->{parser}{body_summary} = Parse::RecDescent->new($body_grammar); | |||||||||||
| 155 | 0 | $self->{parser}{fetch} = Parse::RecDescent->new($fetch_grammar); | |||||||||||
| 156 | |||||||||||||
| 157 | 0 | return $self; | |||||||||||
| 158 | } | ||||||||||||
| 159 | } | ||||||||||||
| 160 | |||||||||||||
| 161 | 0 | ▶ | sub _id_parts { | ||||||||||
|
Subroutine
_id_parts: not called CC=5 SCAR=34.0
| |||||||||||||
| 162 | 0 | my $data = shift; | |||||||||||
| 163 | 0 | my $pre = shift; | |||||||||||
| 164 | 0 | ▶ | $pre = $pre ? "$pre." : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 165 | |||||||||||||
| 166 | 0 | my $id = 1; | |||||||||||
| 167 | 0 | ▶ | if (my $parts = $data->{parts}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 168 | 0 | for my $sub (@$parts){ | |||||||||||
| 169 | 0 | ▶ | _id_parts($sub,"$pre$id") if $sub->{parts}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 170 | 0 | $sub->{part_number} = "$pre$id"; | |||||||||||
| 171 | 0 | $id++; | |||||||||||
| 172 | } | ||||||||||||
| 173 | |||||||||||||
| 174 | } else { | ||||||||||||
| 175 | 0 | $data->{part_number} = $id; | |||||||||||
| 176 | } | ||||||||||||
| 177 | |||||||||||||
| 178 | 0 | return; | |||||||||||
| 179 | } | ||||||||||||
| 180 | |||||||||||||
| 181 | 0 | ▶ | sub body_summary { | ||||||||||
|
Subroutine
body_summary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 182 | 0 | my ($self, $number) = @_; | |||||||||||
| 183 | |||||||||||||
| 184 | 0 | my $bodysummary; | |||||||||||
| 185 | |||||||||||||
| 186 | return $self->_process_cmd( | ||||||||||||
| 187 | cmd => [ 'FETCH' => qq[$number BODY] ], | ||||||||||||
| 188 | |||||||||||||
| 189 | 0 | ▶ | final => sub { return $bodysummary; }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 190 | |||||||||||||
| 191 | 0 | ▶ | process => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 192 | 0 | ▶ | if ($_[0] =~ m/\(BODY\s+(.*?)\)\s*$/i) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 193 | 0 | my $body_parts = $self->{parser}{body_summary}->body($1); | |||||||||||
| 194 | 0 | $bodysummary = Net::IMAP::SimpleX::BodySummary->new($body_parts); | |||||||||||
| 195 | } | ||||||||||||
| 196 | }, | ||||||||||||
| 197 | |||||||||||||
| 198 | 0 | ); | |||||||||||
| 199 | } | ||||||||||||
| 200 | |||||||||||||
| 201 | 0 | ▶ | sub uidfetch { | ||||||||||
|
Subroutine
uidfetch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 202 | 0 | my $self = shift; | |||||||||||
| 203 | |||||||||||||
| 204 | 0 | local $uidm = 1; # auto-pop this after the fetch | |||||||||||
| 205 | |||||||||||||
| 206 | 0 | return $self->fetch(@_); | |||||||||||
| 207 | } | ||||||||||||
| 208 | |||||||||||||
| 209 | 0 | ▶ | sub fetch { | ||||||||||
|
Subroutine
fetch: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||
| 210 | 0 | my $self = shift; | |||||||||||
| 211 | 0 | ▶ | my $msg = shift; $msg =~ s/[^\*\d:,-]//g; croak "which message?" unless $msg; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 212 | 0 | ▶ | my $spec = "@_" || 'FULL'; | ||||||||||
|
Condition0%0/2
join($", @_) || 'FULL'
MC/DC0%0/1
join($", @_) || 'FULL'
join($", @_)
Truth table0%0/2
A
A= join($", @_)
| |||||||||||||
| 213 | |||||||||||||
| 214 | 0 | ▶ | $spec = "BODY[$spec]" if $spec =~ m/^[\d\.]+\z/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 215 | |||||||||||||
| 216 | 0 | $self->_be_on_a_box; | |||||||||||
| 217 | |||||||||||||
| 218 | # cut and pasted from ::Server | ||||||||||||
| 219 | 0 | ▶ | $spec = [qw/FLAGS INTERNALDATE RFC822.SIZE ENVELOPE/] if uc $spec eq "ALL"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 220 | 0 | ▶ | $spec = [qw/FLAGS INTERNALDATE RFC822.SIZE/] if uc $spec eq "FAST"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 221 | 0 | ▶ | $spec = [qw/FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY/] if uc $spec eq "FULL"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 222 | 0 | ▶ | $spec = [ $spec ] unless ref $spec; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 223 | |||||||||||||
| 224 | 0 | my $stxt = join(" ", map {s/[^()[\]\s<>\da-zA-Z.-]//g; uc($_)} @$spec); ## no critic: really? don't modify $_? pfft | |||||||||||
| 225 | |||||||||||||
| 226 | 0 | ▶ | $self->_debug( caller, __LINE__, parsed_fetch=> "$msg ($stxt)" ) if $self->{debug}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 227 | |||||||||||||
| 228 | 0 | my $entire_response = ""; | |||||||||||
| 229 | |||||||||||||
| 230 | return $self->_process_cmd( | ||||||||||||
| 231 | cmd => [ ($uidm ? "UID FETCH" : "FETCH")=> qq[$msg ($stxt)] ], | ||||||||||||
| 232 | |||||||||||||
| 233 | 0 | ▶ | final => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||
| 234 | #open my $fh, ">", "entire_response.dat"; | ||||||||||||
| 235 | #print $fh $entire_response; | ||||||||||||
| 236 | |||||||||||||
| 237 | 0 | ▶ | if( my $res = $self->{parser}{fetch}->fetch($entire_response) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 238 | 0 | ▶ | $self->_debug( caller, __LINE__, parsed_fetch=> "PARSED") if $self->{debug}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 239 | 0 | ▶ | return wantarray ? %$res : $res; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 240 | } | ||||||||||||
| 241 | |||||||||||||
| 242 | 0 | ▶ | $self->_debug( caller, __LINE__, parsed_fetch=> "PARSE FAIL") if $self->{debug}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 243 | 0 | return; | |||||||||||
| 244 | }, | ||||||||||||
| 245 | |||||||||||||
| 246 | 0 | ▶ | process => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 247 | 0 | $entire_response .= $_[0]; | |||||||||||
| 248 | 0 | return 1; | |||||||||||
| 249 | }, | ||||||||||||
| 250 | |||||||||||||
| 251 | 0 | ▶ | ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 252 | } | ||||||||||||
| 253 | |||||||||||||
| 254 | 1 | 1; | |||||||||||