Server/Message.pm

filter: Statementstmt 17.7% 43 / 243 Branchbran 0.0% 0 / 128 Conditioncond 0.0% 0 / 48 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 37.1% 13 / 35 Podpod 100% 21 / 21 totaltotal 15.2% 77 / 506 CC 93 SCAR 54.8
CC
93
Cov
10%
fetch
462.0
mime_select
462.0
mime_bodystructure
462.0
CRAP 240.6
« Server/Command/Search.pm ↑ Summary Server/Mailbox.pm »
1 package Net::IMAP::Server::Message;
2  
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use Email::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Email::MIME;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Email::MIME::ContentType;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use Regexp::Common qw/balanced/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use DateTime::Format::Mail;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use constant INTERNALDATE_PARSER => DateTime::Format::Strptime->new(pattern => "%e-%b-%Y %T %z");
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use constant HEADERDATE_PARSER => DateTime::Format::Mail->new->loose;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Canonical capitalization
19 13 my %FLAGS;
20 13 $FLAGS{ lc $_ } = $_ for qw(\Answered \Flagged \Deleted \Seen \Draft);
21  
22 13 ▶use base 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 13 __PACKAGE__->mk_accessors(
25 qw(sequence mailbox uid _flags mime expunged));
26  
27 =head1 NAME
28  
29 Net::IMAP::Server::Message - Represents a message stored in a user's mailbox
30  
31 =head1 METHODS
32  
33 =head2 new STR
34  
35 Creates a new message, from an RFC2822 string.
36  
37 =cut
38  
39 sub new {
40 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
41 0 my $self = bless {}, $class;
42 0 ▶ $self->mime( Email::MIME->new(@_) ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
43 0 $self->internaldate( DateTime->now( time_zone => 'local' ) );
44 0 $self->_flags( {} );
45 0 return $self;
46 }
47  
48 =head2 mailbox [MAILBOX]
49  
50 Gets or sets the L<Net::IMAP::Server::Mailbox> that this message is
51 in.
52  
53 =head2 sequence [INTEGER]
54  
55 Gets or sets the sequence number of this message in its mailbox.
56 Note, however, that due to the semi-transactional nature of IMAP,
57 different connections may see a message as having different sequence
58 numbers! The sequence number stored on the message is the sequence
59 number that a new connection would see; to find out what a connection
60 believes the sequence number of a message to be, use
61 L<Net::IMAP::Server::Connection/sequence>.
62  
63 =head2 uid [INTEGER]
64  
65 Gets or sets the UID of the message. This, paired with the name and
66 UIDVALIDITY of its mailbox, is a unique designator of the message.
67  
68 =head2 internaldate [STRING or DATETIME]
69  
70 Gets or sets the string representing when the message was received by
71 the server. According to RFC specification, this must be formatted as
72 C<01-Jan-2008 15:42:00 -0500> if it is a C<STRING>.
73  
74 =cut
75  
76 sub internaldate {
77 0 ▶ my $self = shift;
Subroutine internaldate: not called CC=4 SCAR=30.0
Pod documented
78 0 ▶ return $self->{internaldate} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
79 0 my $value = shift;
80  
81 0 ▶ my $dt = ref $value ? $value : $self->INTERNALDATE_PARSER->parse_datetime($value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 0 0
82 0 ▶ return undef unless $dt;
Branch: 1 branch
BranchTrueFalseTotal
unless $dt 0 0 0
83  
84 0 $self->{internaldate} = $dt->strftime("%e-%b-%Y %T %z");
85 0 $dt->truncate( to => "day" );
86 0 $dt->set_time_zone( "floating" );
87 0 $dt->set_time_zone( "UTC" );
88 0 $self->{epoch_day_utc} = $dt->epoch;
89 0 return $self->{internaldate};
90 }
91  
92 =head2 epoch_day_utc
93  
94 Returns the epoch time of the L</internaldate>, ignoring times and
95 time zones. This is almost certainly only useful for C<SEARCH BEFORE>
96 and friends.
97  
98 =cut
99  
100 sub epoch_day_utc {
101 0 ▶ my $self = shift;
Subroutine epoch_day_utc: not called CC=1 SCAR=6.9
Pod documented
102 0 return $self->{epoch_day_utc};
103 }
104  
105 =head2 date
106  
107 Returns the Date header of the message, as a L<DateTime> object.
108 Returns undef if the date cannot be parsed.
109  
110 =cut
111  
112 sub date {
113 0 ▶ my $self = shift;
Subroutine date: not called CC=2 SCAR=17.9
Pod documented
114 0 my $date = $self->mime_header->header("Date");
115 0 ▶ return unless $date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 0 0
116  
117 0 return eval {
118 0 $self->HEADERDATE_PARSER->parse_datetime(
119 $date
120 )
121 };
122 }
123  
124 =head2 date_day_utc
125  
126 Similar to L</epoch_day_utc>, but for the L</date> header. That is,
127 it returns the Date header, having stripped off the timezone and time.
128 Returns undef if the Date header cannot be parsed.
129  
130 =cut
131  
132 sub date_day_utc {
133 0 ▶ my $self = shift;
Subroutine date_day_utc: not called CC=2 SCAR=17.9
Pod documented
134 0 my $date = $self->date;
135 0 ▶ return unless $date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 0 0
136  
137 0 $date->truncate( to => "day" );
138 0 $date->set_time_zone( "floating" );
139 0 $date->set_time_zone( "UTC" );
140 0 return $date;
141 }
142  
143 =head2 expunge
144  
145 Marks the message as expunged -- this is called by
146 L<Net::IMAP::Server::Mailbox/expunge>, which deals with actually
147 removing the message from the appropriate places..
148  
149 =cut
150  
151 sub expunge {
152 0 ▶ my $self = shift;
Subroutine expunge: not called CC=1 SCAR=6.9
Pod documented
153 0 $self->expunged(1);
154 }
155  
156 =head2 expunged
157  
158 Returns true if the message has been marked as "to be expunged" by
159 L</expunge>.
160  
161 =head2 copy_allowed MAILBOX
162  
163 Returns true if copying this message to the given
164 L<Net::IMAP::Server::Mailbox> C<MAILBOX> is allowed. By default,
165 always returns true;
166  
167 =cut
168  
169 sub copy_allowed {
170 0 ▶ return 1;
Subroutine copy_allowed: not called CC=1 SCAR=6.9
Pod documented
171 }
172  
173 =head2 copy MAILBOX
174  
175 Copies the message into the given L<Net::IMAP::Server::Mailbox>
176 C<MAILBOX>, and returns the new message.
177  
178 =cut
179  
180 sub copy {
181 0 ▶ my $self = shift;
Subroutine copy: not called CC=2 SCAR=17.9
Pod documented
182 0 my $mailbox = shift;
183  
184 0 my $clone = bless {}, ref $self;
185 0 $clone->mime( $self->mime ); # This leads to sharing the same MIME
186 # object, but since they're
187 # immutable, I don't think we care
188 0 $clone->internaldate( $self->internaldate ); # Ditto for the date
189 0 $clone->_flags( {} );
190 0 $clone->set_flag( $_, 1 ) for ( '\Recent', $self->flags );
191  
192 0 $mailbox->add_message($clone);
193  
194 0 return $clone;
195 }
196  
197 =head2 session_flags
198  
199 Returns the names of flags that are stored per-session. Defaults to
200 only the C<\Recent> flag.
201  
202 =cut
203  
204 sub session_flags {
205 0 ▶ return ('\Recent');
Subroutine session_flags: not called CC=1 SCAR=6.9
Pod documented
206 }
207  
208 sub _session_flags {
209 0 ▶ my $self = shift;
Subroutine _session_flags: not called CC=3 SCAR=24.8
210 0 my $conn = Net::IMAP::Server->connection;
211 0 ▶ return {} unless $conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $conn 0 0 0
212 0 ▶ return $conn->_session_flags->{$self} ||= {};
Condition0%0/2
$conn->_session_flags->{$self} ||= {}
l!l
00
MC/DC0%0/1
$conn->_session_flags->{$self} ||= {}
$conn->_session_flags->{$self}
Truth table0%0/2
A
A= $conn->_session_flags->{$self}
Aresult
11
00
213 }
214  
215 =head2 set_flag FLAG [, SILENT]
216  
217 Sets the given flag on the message; if a true value is passed for
218 C<SILENT>, mailboxes will not send notification of the change to the
219 client. Returns the old value.
220  
221 =cut
222  
223 sub set_flag {
224 0 ▶ my $self = shift;
Subroutine set_flag: not called CC=7 SCAR=40.3
Pod documented
225 0 my ( $flag, $silent ) = @_;
226 0 ▶ $flag = $FLAGS{ lc $flag } || $flag;
Condition0%0/3
$FLAGS{lc $flag} || $flag
l!l&&r!l&&!r
000
MC/DC0%0/2
$FLAGS{lc $flag} || $flag
$FLAGS{lc $flag} $flag
Truth table0%0/3
A || B
A= $FLAGS{lc $flag}B= $flag
ABresult
1X1
011
000
227  
228 0 ▶ my $hash = (grep $flag eq $_, $self->session_flags) ? $self->_session_flags : $self->_flags;
Branch: 1 branch
BranchTrueFalseTotal
grep(($flag eq $_), $self->session_flags) ? : 0 0 0
229  
230 0 my $old = exists $hash->{$flag};
231 0 $hash->{$flag} = 1;
232  
233 0 my $changed = not $old;
234 0 ▶ if ( $changed and not $silent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed and not $silent) 0 0 0
Condition0%0/3
$changed and not $silent
!ll&&!rl&&r
000
MC/DC0%0/2
$changed and not $silent
$changed not $silent
Truth table0%0/3
A and not(B)
A= $changedB= not $silent
ABresult
0X0
100
111
235 0 for my $c (
236 Net::IMAP::Server->concurrent_mailbox_connections(
237 $self->mailbox
238 )
239 )
240 {
241 0 ▶ $c->_unsent_fetch->{ $c->sequence($self) }{FLAGS}++
Branch: 1 branch
BranchTrueFalseTotal
unless $c->ignore_flags 0 0 0
242 unless $c->ignore_flags;
243 }
244 }
245  
246 0 return $changed;
247 }
248  
249 =head2 clear_flag FLAG [, SILENT]
250  
251 Clears the given flag on the message; if a true value is passed for
252 C<SILENT>, mailboxes will not send notification of the change to the
253 client. Returns the old value.
254  
255 =cut
256  
257 sub clear_flag {
258 0 ▶ my $self = shift;
Subroutine clear_flag: not called CC=7 SCAR=40.3
Pod documented
259 0 my ( $flag, $silent ) = @_;
260 0 ▶ $flag = $FLAGS{ lc $flag } || $flag;
Condition0%0/3
$FLAGS{lc $flag} || $flag
l!l&&r!l&&!r
000
MC/DC0%0/2
$FLAGS{lc $flag} || $flag
$FLAGS{lc $flag} $flag
Truth table0%0/3
A || B
A= $FLAGS{lc $flag}B= $flag
ABresult
1X1
011
000
261  
262 0 ▶ my $hash = (grep $flag eq $_, $self->session_flags) ? $self->_session_flags : $self->_flags;
Branch: 1 branch
BranchTrueFalseTotal
grep(($flag eq $_), $self->session_flags) ? : 0 0 0
263  
264 0 my $old = exists $hash->{$flag};
265 0 delete $hash->{$flag};
266  
267 0 my $changed = $old;
268 0 ▶ if ( $changed and not $silent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed and not $silent) 0 0 0
Condition0%0/3
$changed and not $silent
!ll&&!rl&&r
000
MC/DC0%0/2
$changed and not $silent
$changed not $silent
Truth table0%0/3
A and not(B)
A= $changedB= not $silent
ABresult
0X0
100
111
269 0 for my $c (
270 Net::IMAP::Server->concurrent_mailbox_connections(
271 $self->mailbox
272 )
273 )
274 {
275 0 ▶ $c->_unsent_fetch->{ $c->sequence($self) }{FLAGS}++
Branch: 1 branch
BranchTrueFalseTotal
unless $c->ignore_flags 0 0 0
276 unless $c->ignore_flags;
277 }
278 }
279  
280 0 return $changed;
281 }
282  
283 =head2 has_flag FLAG
284  
285 Returns true if the message has the given flag set.
286  
287 =cut
288  
289 sub has_flag {
290 0 ▶ my $self = shift;
Subroutine has_flag: not called CC=3 SCAR=24.8
Pod documented
291 0 my $flag = shift;
292 0 ▶ $flag = $FLAGS{ lc $flag } || $flag;
Condition0%0/3
$FLAGS{lc $flag} || $flag
l!l&&r!l&&!r
000
MC/DC0%0/2
$FLAGS{lc $flag} || $flag
$FLAGS{lc $flag} $flag
Truth table0%0/3
A || B
A= $FLAGS{lc $flag}B= $flag
ABresult
1X1
011
000
293  
294 0 ▶ my $hash = (grep $flag eq $_, $self->session_flags) ? $self->_session_flags : $self->_flags;
Branch: 1 branch
BranchTrueFalseTotal
grep(($flag eq $_), $self->session_flags) ? : 0 0 0
295  
296 0 return exists $hash->{$flag};
297 }
298  
299 =head2 flags
300  
301 Returns the list of flags which are set on the message.
302  
303 =cut
304  
305 sub flags {
306 0 ▶ my $self = shift;
Subroutine flags: not called CC=1 SCAR=6.9
Pod documented
307 0 my %flags = ( %{ $self->_flags }, %{ $self->_session_flags } );
308 0 return sort keys %flags;
309 }
310  
311 =head2 store STRING FLAGS
312  
313 Sets the given C<FLAGS>, which should be an array reference, on the
314 message. C<STRING> should be C<+FLAGS>, C<-FLAGS>, or C<FLAGS>; the
315 first sets the set of flags, the second unsets the set of flags, and
316 the third changes the message's flags to exactly match the given set.
317  
318 =cut
319  
320 sub store {
321 0 ▶ my $self = shift;
Subroutine store: not called CC=7 SCAR=40.3
Pod documented
322 0 my ( $what, $flags ) = @_;
323 0 my @flags = @{$flags};
324 0 ▶ if ( $what =~ /^-/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($what =~ /^-/) { } 0 0 0
elsif ($what =~ /^\+/) { } 0 0 0
325 0 $self->clear_flag($_) for grep { $self->has_flag($_) } @flags;
326 } elsif ( $what =~ /^\+/ ) {
327 0 $self->set_flag($_) for grep { not $self->has_flag($_) } @flags;
328 } else {
329 0 $self->set_flag($_) for grep { not $self->has_flag($_) } @flags;
330 0 $self->clear_flag($_) for grep {
331 0 $a = $_;
332 0 not grep { lc $a eq lc $_ } @flags
333 } $self->flags;
334 }
335 }
336  
337 =head2 mime_header
338  
339 Returns the L<Email::Simple::Header> of the message.
340  
341 =cut
342  
343 sub mime_header {
344 0 ▶ my $self = shift;
Subroutine mime_header: not called CC=1 SCAR=6.9
Pod documented
345 0 return $self->mime->header_obj;
346 }
347  
348 =head2 mime [OBJ]
349  
350 Gets or sets the L<Email::MIME> object for this message.
351  
352 =cut
353  
354 =head2 fetch SPEC
355  
356 Takes C<SPEC>, which is either a string or an array reference of
357 strings, and returns a list of strings or data structures which match
358 the specification. The specification is defined by section 7.4.2 of
359 RFC 3501.
360  
361 =cut
362  
363 sub fetch {
364 0 ▶ my $self = shift;
Subroutine fetch: not called CC=21 SCAR=61.4
Pod documented
365 0 my $spec = shift;
366  
367 0 ▶ $spec = [qw/FLAGS INTERNALDATE RFC822.SIZE ENVELOPE/]
Branch: 1 branch
BranchTrueFalseTotal
if uc $spec eq "ALL" 0 0 0
368 if uc $spec eq "ALL";
369 0 ▶ $spec = [qw/FLAGS INTERNALDATE RFC822.SIZE/] if uc $spec eq "FAST";
Branch: 1 branch
BranchTrueFalseTotal
if uc $spec eq "FAST" 0 0 0
370 0 ▶ $spec = [qw/FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY/]
Branch: 1 branch
BranchTrueFalseTotal
if uc $spec eq "FULL" 0 0 0
371 if uc $spec eq "FULL";
372  
373 0 ▶ my @parts = ref $spec ? @{$spec} : $spec;
Branch: 1 branch
BranchTrueFalseTotal
ref $spec ? : 0 0 0
374  
375 # Look if this will change the \Seen flag
376 0 ▶ if ( grep { $_ =~ /^BODY\[/i } @parts and not $self->has_flag('\Seen') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ =~ /^BODY\[/i;} @parts and not $self->has_flag("\\Seen")) 0 0 0
Condition0%0/3
grep {$_ =~ /^BODY\[/i;} @parts and not $self->has_flag("\\Seen")
!ll&&!rl&&r
000
MC/DC0%0/2
grep {$_ =~ /^BODY\[/i;} @parts and not $self->has_flag("\\Seen")
grep {$_ =~ /^BODY\[/i;} @parts not $self->has_flag("\\Seen")
Truth table0%0/3
A and not(B)
A= grep {$_ =~ /^BODY\[/i;} @partsB= not $self->has_flag("\\Seen")
ABresult
0X0
100
111
377  
378 # If so, update, and possibly also inform the user; do it
379 # "silently" because we'll report the FLAGS change ourselves
380 0 $self->set_flag('\Seen', 1);
381 0 ▶ unshift @parts, "FLAGS" if not grep { uc $_ eq "FLAGS" } @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {uc $_ eq "FLAGS";} @parts 0 0 0
382 }
383  
384 0 my @out;
385 0 for my $part (@parts) {
386 0 push @out, \( uc $part );
387  
388 # Now that we've split out the right tag, do some aliasing
389 0 ▶ if ( uc $part eq "RFC822" ) {
Branch: 3 branches
BranchTrueFalseTotal
if (uc $part eq 'RFC822') { } 0 0 0
elsif (uc $part eq 'RFC822.HEADER') { } 0 0 0
elsif (uc $part eq 'RFC822.TEXT') { } 0 0 0
390 0 $part = "BODY[]";
391 } elsif ( uc $part eq "RFC822.HEADER" ) {
392 0 $part = "BODY.PEEK[HEADER]";
393 } elsif ( uc $part eq "RFC822.TEXT" ) {
394 0 $part = "BODY[TEXT]";
395 }
396  
397 0 ▶ if ( uc $part eq "UID" ) {
Branch: 8 branches
BranchTrueFalseTotal
if (uc $part eq 'UID') { } 0 0 0
elsif (uc $part eq 'INTERNALDATE') { } 0 0 0
elsif ($part =~ /^BODY(?:\.PEEK)?\[(.*?)(?:\s+\((.*?)\))?\](?:<(\d+)(?:\.(\d+))>)?$/i) { } 0 0 0
elsif (uc $part eq 'FLAGS') { } 0 0 0
elsif (uc $part eq 'RFC822.SIZE') { } 0 0 0
elsif (uc $part eq 'BODY') { } 0 0 0
elsif (uc $part eq 'BODYSTRUCTURE') { } 0 0 0
elsif (uc $part eq 'ENVELOPE') { } 0 0 0
398 0 push @out, $self->uid;
399 } elsif ( uc $part eq "INTERNALDATE" ) {
400 0 push @out, $self->internaldate;
401 } elsif ( $part
402 =~ /^BODY(?:\.PEEK)?\[(.*?)(?:\s+\((.*?)\))?\](?:<(\d+)(?:\.(\d+))>)?$/i
403 )
404 {
405 0 ▶ push @out,
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
406 $self->mime_select( [ split /\./, $1 ],
407 $3, $4, [ split ' ', ( $2 || "" ) ] );
408 0 ${ $out[-2] } =~ s/^BODY\.PEEK/BODY/i;
409 } elsif ( uc $part eq "FLAGS" ) {
410 0 push @out, [ map { \$_ } $self->flags ];
411 } elsif ( uc $part eq "RFC822.SIZE" ) {
412 0 push @out, length $self->mime_select( [], undef, undef );
413 } elsif ( uc $part eq "BODY" ) {
414 0 push @out, $self->mime_bodystructure( 0 );
415 } elsif ( uc $part eq "BODYSTRUCTURE" ) {
416 0 push @out, $self->mime_bodystructure( 1 );
417 } elsif ( uc $part eq "ENVELOPE" ) {
418 0 push @out, $self->mime_envelope;
419 } else {
420 0 pop @out;
421 }
422 }
423 0 return @out;
424 }
425  
426 =head2 mime_select SECTIONS [, START [, END [, EXTRA]]]
427  
428 This method is generally only used internally by L</fetch>.
429  
430 C<SECTIONS> should be an array reference of indexes into MIME parts,
431 or pulled from the set of strings: C<HEADER>, C<MIME>, C<FIELDS>,
432 C<TEXT>. C<START> and C<END> determine which bytes of the resulting
433 content to send. C<EXTRA> is used only for C<FIELDS>, and supplies
434 the names of headers to fetch.
435  
436 =cut
437  
438 sub mime_select {
439 0 ▶ my $self = shift;
Subroutine mime_select: not called CC=21 SCAR=61.4
Pod documented
440 0 my ( $sections, $start, $end, $extras ) = @_;
441  
442 0 my $mime;
443  
444 0 ▶ my @sections = @{$sections || []};
Branch: 1 branch
BranchTrueFalseTotal
$sections or [] 0 0 0
445 0 my $result;
446 0 ▶ $result = $self->mime->as_string unless @sections;
Branch: 1 branch
BranchTrueFalseTotal
unless @sections 0 0 0
447 0 for (@sections) {
448 0 ▶ if ( uc $_ eq "HEADER" or uc $_ eq "MIME" ) {
Branch: 4 branches
BranchTrueFalseTotal
if (uc $_ eq 'HEADER' or uc $_ eq 'MIME') { } 0 0 0
elsif (uc $_ eq 'FIELDS') { } 0 0 0
elsif (uc $_ eq 'TEXT') { } 0 0 0
elsif ($_ =~ /^\d+$/i) { } 0 0 0
Condition0%0/3
uc $_ eq "HEADER" or uc $_ eq "MIME"
l!l&&r!l&&!r
000
MC/DC0%0/2
uc $_ eq "HEADER" or uc $_ eq "MIME"
uc $_ eq "HEADER" uc $_ eq "MIME"
Truth table0%0/3
A or B
A= uc $_ eq "HEADER"B= uc $_ eq "MIME"
ABresult
1X1
011
000
449 0 ▶ $result = ( $mime ? $mime->header_obj : $self->mime_header )
Branch: 1 branch
BranchTrueFalseTotal
$mime ? : 0 0 0
450 ->as_string . "\r\n";
451 } elsif ( uc $_ eq "FIELDS" ) {
452 0 my %case;
453 0 ▶ my $mime_header = $mime ? $mime->header_obj : $self->mime_header;
Branch: 1 branch
BranchTrueFalseTotal
$mime ? : 0 0 0
454 0 $case{ uc $_ } = $_ for $mime_header->header_names;
455 0 my $copy = Email::Simple::Header->new("");
456 0 ▶ for my $h ( @{$extras || []} ) {
Branch: 1 branch
BranchTrueFalseTotal
$extras or [] 0 0 0
457 0 ▶ $copy->header_set( $case{$h}
Condition0%0/3
$case{$h} || $h
l!l&&r!l&&!r
000
MC/DC0%0/2
$case{$h} || $h
$case{$h} $h
Truth table0%0/3
A || B
A= $case{$h}B= $h
ABresult
1X1
011
000
458 || $h => $mime_header->header_raw($h) );
459 }
460 0 ▶ $result = $copy->as_string ? $copy->as_string . "\r\n" : "";
Branch: 1 branch
BranchTrueFalseTotal
$copy->as_string ? : 0 0 0
461 } elsif ( uc $_ eq "TEXT" ) {
462 0 ▶ $mime ||= $self->mime;
Condition0%0/3
$mime ||= $self->mime
l!l&&r!l&&!r
000
MC/DC0%0/2
$mime ||= $self->mime
$mime $self->mime
Truth table0%0/3
A ||= B
A= $mimeB= $self->mime
ABresult
1X1
011
000
463 0 $result = $mime->body_raw;
464 } elsif ( $_ =~ /^\d+$/i ) {
465 0 ▶ $mime ||= $self->mime;
Condition0%0/3
$mime ||= $self->mime
l!l&&r!l&&!r
000
MC/DC0%0/2
$mime ||= $self->mime
$mime $self->mime
Truth table0%0/3
A ||= B
A= $mimeB= $self->mime
ABresult
1X1
011
000
466 0 my @parts = $mime->parts;
467 0 $mime = $parts[ $_ - 1 ];
468 0 $result = $mime->body_raw;
469 }
470 }
471  
472 0 ▶ return $result unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 0 0
473 0 ▶ return "" if $start > length $result;
Branch: 1 branch
BranchTrueFalseTotal
if $start > length $result 0 0 0
474 0 ▶ return substr( $result, $start ) unless defined $end;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end 0 0 0
475 0 return substr( $result, $start, $end );
476 }
477  
478 =head2 mime_bodystructure [LONG [, MIME]]
479  
480 Returns a string describing the MIME body structure of the message.
481  
482 =cut
483  
484 sub mime_bodystructure {
485 0 ▶ my $self = shift;
Subroutine mime_bodystructure: not called CC=21 SCAR=61.4
Pod documented
486 0 my ( $long, $mime ) = @_;
487 0 ▶ $mime ||= $self->mime;
Condition0%0/3
$mime ||= $self->mime
l!l&&r!l&&!r
000
MC/DC0%0/2
$mime ||= $self->mime
$mime $self->mime
Truth table0%0/3
A ||= B
A= $mimeB= $self->mime
ABresult
1X1
011
000
488 0 my $mime_header = $mime->header_obj;
489  
490 # Grab the content type
491 0 my $data = parse_content_type( $mime->content_type );
492  
493 # And the content disposition
494 0 my $dis_header = $mime_header->header("Content-Disposition");
495 0 my ( $attrs, $disposition );
496 0 ▶ if ($dis_header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dis_header) 0 0 0
497  
498 # Ugly hack. Culled from Email::MIME::Modifier
499 0 ($disposition) = ( $dis_header =~ /^([^;]+)/ );
500 0 $dis_header =~ s/^$disposition(?:;\s*)?//;
501 0 $attrs = Email::MIME::ContentType::_parse_attributes($dis_header);
502 }
503  
504 0 ▶ if ( $data->{discrete} eq "multipart" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{'discrete'} eq 'multipart') { } 0 0 0
505  
506 # The first element is a bunch of lists, which looks like
507 # (...)(...) -- note the lack of space! RFC 3501, how do we
508 # hate thee. Make the mime structures, hack them into the
509 # IMAP format, concat them, and insert their reference so they
510 # get spat out as-is.
511 0 my @parts = $mime->parts;
512 0 ▶ @parts = () if @parts == 1 and $parts[0] == $mime;
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 1 and $parts[0] == $mime 0 0 0
Condition0%0/3
@parts == 1 and $parts[0] == $mime
!ll&&!rl&&r
000
MC/DC0%0/2
@parts == 1 and $parts[0] == $mime
@parts == 1 $parts[0] == $mime
Truth table0%0/3
A and B
A= @parts == 1B= $parts[0] == $mime
ABresult
0X0
100
111
513 my $parts = join '', map {
514 0 Net::IMAP::Server::Command->data_out(
515 $self->mime_bodystructure( $long, $_ ) )
516 } @parts;
517  
518 return [
519 $parts ? \$parts : undef,
520 $data->{composite},
521 ( $long
522 0 ? ( ( %{ $data->{attributes} }
523 0 ▶ ? [ %{ $data->{attributes} } ]
Branch: 2 branches
BranchTrueFalseTotal
$disposition ? : 0 0 0
$attrs && %{$attrs;} ? : 0 0 0
Condition0%0/3
$attrs and %{$attrs;}
!ll&&!rl&&r
000
MC/DC0%0/2
$attrs and %{$attrs;}
$attrs %{$attrs;}
Truth table0%0/3
A and B
A= $attrsB= %{$attrs;}
ABresult
0X0
100
111
524 : undef
525 ),
526 ( $disposition
527 ? [ $disposition,
528 0 ▶ ( $attrs && %{$attrs} ? [ %{$attrs} ] : undef ),
Branch: 3 branches
BranchTrueFalseTotal
$parts ? : 0 0 0
$long ? : 0 0 0
%{$data->{'attributes'};} ? : 0 0 0
529 ]
530 : undef
531 ),
532 scalar $mime_header->header_raw("Content-Language"),
533 scalar $mime_header->header_raw("Content-Location"),
534 )
535 : ()
536 ),
537 ];
538 } else {
539 0 my $lines;
540 0 my $body = $mime->body_raw;
541 0 ▶ if ( lc $data->{discrete} eq "text" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $data->{"discrete"} eq "text") 0 0 0
542 0 $lines = 0;
543 0 ▶ $lines++ while $body =~ /\n/g;
Branch: 1 branch
BranchTrueFalseTotal
$body =~ /\n/g and do { ++$lines } 0 0 0
544 }
545 return [
546 $data->{discrete},
547 $data->{composite},
548 0 ( %{ $data->{attributes} }
549 0 ▶ ? [ %{ $data->{attributes} } ]
Branch: 4 branches
BranchTrueFalseTotal
defined $lines ? : 0 0 0
$long ? : 0 0 0
$disposition ? : 0 0 0
$attrs && %{$attrs;} ? : 0 0 0
Condition0%0/5
scalar $mime_header->header_raw('Content-Transfer-Encoding') || '7BIT'
l!l
00
$attrs and %{$attrs;}
!ll&&!rl&&r
000
MC/DC0%0/1
scalar $mime_header->header_raw('Content-Transfer-Encoding') || '7BIT'
scalar $mime_header->header_raw('Content-Transfer-Encoding')
MC/DC0%0/2
$attrs and %{$attrs;}
$attrs %{$attrs;}
Truth table0%0/2
A
A= scalar $mime_header->header_raw('Content-Transfer-Encoding')
Aresult
11
00
Truth table0%0/3
A and B
A= $attrsB= %{$attrs;}
ABresult
0X0
100
111
550 : undef
551 ),
552 scalar $mime_header->header_raw("Content-ID"),
553 scalar $mime_header->header_raw("Content-Description"),
554 ( scalar $mime_header->header_raw("Content-Transfer-Encoding") or "7BIT" ),
555 length $body,
556 ( defined $lines
557 ? ( $lines, )
558 : ()
559 ),
560 ( $long
561 ? ( scalar $mime_header->header_raw("Content-MD5"),
562 ( $disposition
563 ? [ $disposition,
564 0 ▶ ( $attrs && %{$attrs} ? [ %{$attrs} ] : undef ),
Branch: 1 branch
BranchTrueFalseTotal
%{$data->{'attributes'};} ? : 0 0 0
565 ]
566 : undef
567 ),
568 scalar $mime_header->header_raw("Content-Language"),
569 scalar $mime_header->header_raw("Content-Location"),
570 )
571 : ()
572 ),
573 ];
574 }
575 }
576  
577 =head2 address_envelope HEADER
578  
579 Returns a data structure defining the email addresses listed in the
580 given C<HEADER>. This is used internally by L</mime_envelope>.
581  
582 =cut
583  
584 sub address_envelope {
585 0 ▶ my $self = shift;
Subroutine address_envelope: not called CC=2 SCAR=17.9
Pod documented
586 0 my $header = shift;
587 0 my $mime_header = $self->mime_header;
588  
589 0 ▶ return undef unless $mime_header->header($header);
Branch: 1 branch
BranchTrueFalseTotal
unless $mime_header->header($header) 0 0 0
590 return [
591 map {
592 0 [ { type => "string", value => $_->name },
593 undef,
594 { type => "string", value => $_->user },
595 { type => "string", value => $_->host }
596 ]
597 } Email::Address->parse( $mime_header->header_raw($header) )
598 ];
599 }
600  
601 =head2 mime_envelope
602  
603 Returns a data structure defining properties of significant header
604 fields. This is used internally by L</fetch>.
605  
606 =cut
607  
608 sub mime_envelope {
609 0 ▶ my $self = shift;
Subroutine mime_envelope: not called CC=3 SCAR=24.8
Pod documented
610 0 my $mime_header = $self->mime_header;
611  
612 return [
613 0 ▶ scalar $mime_header->header_raw("Date"),
Branch: 2 branches
BranchTrueFalseTotal
$mime_header->header('Sender') ? : 0 0 0
$mime_header->header('Reply-To') ? : 0 0 0
614 scalar $mime_header->header_raw("Subject"),
615  
616 $self->address_envelope("From"),
617 $self->address_envelope(
618 $mime_header->header("Sender") ? "Sender" : "From"
619 ),
620 $self->address_envelope(
621 $mime_header->header("Reply-To") ? "Reply-To" : "From"
622 ),
623 $self->address_envelope("To"),
624 $self->address_envelope("Cc"),
625 $self->address_envelope("Bcc"),
626  
627 scalar $mime_header->header_raw("In-Reply-To"),
628 scalar $mime_header->header_raw("Message-ID"),
629 ];
630 }
631  
632 =head2 prep_for_destroy
633  
634 Called by the mailbox before the message is torn down; breaks down any
635 circular references.
636  
637 =cut
638  
639 sub prep_for_destroy {
640 0 ▶ my $self = shift;
Subroutine prep_for_destroy: not called CC=1 SCAR=6.9
Pod documented
641 0 $self->mailbox(undef);
642 }
643  
644 13 1;
« Server/Command/Search.pm ↑ Summary Server/Mailbox.pm »