Box/IMAP4/Message.pm

filter: Statementstmt 18.7% 18 / 96 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 35.7% 5 / 14 Podpod 66.6% 6 / 9 totaltotal 14.1% 29 / 205 CC 34 SCAR 43.6
CC
34
Cov
11%
label
210.0
loadBody
42.0
writeDelayed
42.0
CRAP 78.4
« Transport/IMAP4.pm ↑ Summary Box/IMAP4/Head.pm »
1 # This code is part of Perl distribution Mail-Box-IMAP4 version 4.01.
2 # The POD got stripped from this file by OODoc version 3.05.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2025 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Box::IMAP4::Message;{
13 3 our $VERSION = '4.01';
14 }
15  
16 3 ▶use parent 'Mail::Box::Net::Message';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 ▶use Log::Report 'mail-box-imap4', import => [];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use Date::Parse qw/str2time/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #--------------------
26  
27 sub init($)
28 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
29 0 $self->SUPER::init($args);
30  
31 0 ▶ $self->{MBIM_write_labels} = exists $args->{write_labels} ? $args->{write_labels} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'write_labels'} ? : 0 0 0
32 0 $self->{MBIM_cache_labels} = $args->{cache_labels};
33 0 $self->{MBIM_cache_head} = $args->{cache_head};
34 0 $self->{MBIM_cache_body} = $args->{cache_body};
35 0 $self;
36 }
37  
38  
39 sub size($)
40 0 ▶{ my $self = shift;
Subroutine size: not called CC=2 SCAR=17.9
Pod documented
41 0 ▶ $self->isDelayed ? $self->fetch('RFC822.SIZE') : $self->SUPER::size;
Branch: 1 branch
BranchTrueFalseTotal
$self->isDelayed ? : 0 0 0
42 }
43  
44 sub recvstamp()
45 0 ▶{ my $date = shift->fetch('INTERNALDATE');
Subroutine recvstamp: not called CC=2 SCAR=17.9
Pod undocumented
46 0 ▶ defined $date ? str2time($date) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $date ? : 0 0 0
47 }
48  
49  
50 sub label(@)
51 0 ▶{ my $self = shift;
Subroutine label: not called CC=14 SCAR=53.5
Pod documented
52 0 ▶ my $imap = $self->folder->transporter or return;
Branch: 1 branch
BranchTrueFalseTotal
my $imap = $self->folder->transporter or return 0 0 0
53 0 ▶ my $id = $self->unique or return;
Branch: 1 branch
BranchTrueFalseTotal
my $id = $self->unique or return 0 0 0
54  
55 0 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
56 { # get one value only
57 0 my $label = shift;
58 0 my $labels = $self->{MM_labels};
59 return $labels->{$label}
60 0 ▶ if exists $labels->{$label} || exists $labels->{seen};
Branch: 1 branch
BranchTrueFalseTotal
if exists $labels->{$label} or exists $labels->{"seen"} 0 0 0
Condition0%0/3
exists $labels->{$label} or exists $labels->{"seen"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $labels->{$label} or exists $labels->{"seen"}
exists $labels->{$label} exists $labels->{"seen"}
Truth table0%0/3
A or B
A= exists $labels->{$label}B= exists $labels->{"seen"}
ABresult
1X1
011
000
61  
62 0 my $flags = $imap->getFlags($id);
63 0 ▶ if($self->{MBIM_cache_labels})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"MBIM_cache_labels"}) 0 0 0
64 { # the program may have added own labels
65 0 @{$labels}{keys %$flags} = values %$flags;
66 0 delete $self->{MBIM_labels_changed};
67 }
68 0 return $flags->{$label};
69 }
70  
71 0 my @private;
72 0 ▶ if($self->{MBIM_write_labels})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'MBIM_write_labels'}) { } 0 0 0
73 0 { @private = $imap->setFlags($id, @_);
74 0 delete $self->{MBIM_labels_changed};
75 }
76 else
77 0 { @private = @_;
78 }
79  
80 0 my $labels = $self->{MM_labels};
81 0 ▶ my @keep = $self->{MBIM_cache_labels} ? @_ : @private;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'MBIM_cache_labels'} ? : 0 0 0
82  
83 0 ▶ while(@keep)
Branch: 1 branch
BranchTrueFalseTotal
if (@keep) 0 0 0
84 0 { my ($k, $v) = (shift @keep, shift @keep);
85 0 ▶ next if defined $labels->{$k} && $labels->{$k} eq $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $labels->{$k} and $labels->{$k} eq $v 0 0 0
Condition0%0/3
defined $labels->{$k} and $labels->{$k} eq $v
!ll&&!rl&&r
000
MC/DC0%0/2
defined $labels->{$k} and $labels->{$k} eq $v
defined $labels->{$k} $labels->{$k} eq $v
Truth table0%0/3
A and B
A= defined $labels->{$k}B= $labels->{$k} eq $v
ABresult
0X0
100
111
86  
87 0 $self->{MBIM_labels_changed}++;
88 0 $labels->{$k} = $v;
89 }
90  
91 0 ▶ $self->modified(1) if @private && $self->{MBIM_labels_changed};
Branch: 1 branch
BranchTrueFalseTotal
if @private and $self->{"MBIM_labels_changed"} 0 0 0
Condition0%0/3
@private and $self->{"MBIM_labels_changed"}
!ll&&!rl&&r
000
MC/DC0%0/2
@private and $self->{"MBIM_labels_changed"}
@private $self->{"MBIM_labels_changed"}
Truth table0%0/3
A and B
A= @privateB= $self->{"MBIM_labels_changed"}
ABresult
0X0
100
111
92 0 $self;
93 }
94  
95  
96 sub labels()
97 0 ▶{ my $self = shift;
Subroutine labels: not called CC=5 SCAR=34.0
Pod documented
98 0 my $id = $self->unique;
99 0 my $labels = $self->SUPER::labels;
100 0 ▶ $labels = +{ %$labels } unless $self->{MBIM_cache_labels};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"MBIM_cache_labels"} 0 0 0
101  
102 0 ▶ if($id && !exists $labels->{seen})
Branch: 1 branch
BranchTrueFalseTotal
if ($id and not exists $labels->{"seen"}) 0 0 0
Condition0%0/3
$id and not exists $labels->{"seen"}
!ll&&!rl&&r
000
MC/DC0%0/2
$id and not exists $labels->{"seen"}
$id not exists $labels->{"seen"}
Truth table0%0/3
A and not(B)
A= $idB= not exists $labels->{"seen"}
ABresult
0X0
100
111
103 0 ▶ { my $imap = $self->folder->transporter or return;
Branch: 1 branch
BranchTrueFalseTotal
my $imap = $self->folder->transporter or return 0 0 0
104 0 my $flags = $imap->getFlags($id);
105 0 @{$labels}{keys %$flags} = values %$flags;
106 }
107  
108 0 $labels;
109 }
110  
111 #--------------------
112  
113 sub loadHead()
114 0 ▶{ my $self = shift;
Subroutine loadHead: not called CC=3 SCAR=24.8
Pod undocumented
115 0 my $head = $self->head;
116 0 ▶ $head->isDelayed or return $head;
Branch: 1 branch
BranchTrueFalseTotal
$head->isDelayed or return $head 0 0 0
117  
118 0 $head = $self->folder->getHead($self);
119 0 ▶ $self->head($head) if $self->{MBIM_cache_head};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBIM_cache_head"} 0 0 0
120 0 $head;
121 }
122  
123 sub loadBody()
124 0 ▶{ my $self = shift;
Subroutine loadBody: not called CC=6 SCAR=37.4
Pod documented
125  
126 0 my $body = $self->body;
127 0 ▶ $body->isDelayed or return $body;
Branch: 1 branch
BranchTrueFalseTotal
$body->isDelayed or return $body 0 0 0
128  
129 0 (my $head, $body) = $self->folder->getHeadAndBody($self);
130 0 ▶ defined $head or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $head or return undef 0 0 0
131  
132 0 ▶ $self->head($head) if $self->{MBIM_cache_head} && $head->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBIM_cache_head"} and $head->isDelayed 0 0 0
Condition0%0/3
$self->{"MBIM_cache_head"} and $head->isDelayed
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"MBIM_cache_head"} and $head->isDelayed
$self->{"MBIM_cache_head"} $head->isDelayed
Truth table0%0/3
A and B
A= $self->{"MBIM_cache_head"}B= $head->isDelayed
ABresult
0X0
100
111
133 0 ▶ $self->storeBody($body) if $self->{MBIM_cache_body};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBIM_cache_body"} 0 0 0
134 0 $body;
135 }
136  
137  
138 sub fetch(@)
139 0 ▶{ my ($self, @info) = @_;
Subroutine fetch: not called CC=2 SCAR=17.9
Pod documented
140 0 my $folder = $self->folder;
141 0 my $answer = ($folder->fetch( [$self], @info))[0];
142  
143 0 ▶ @info==1 ? $answer->{$info[0]} : @{$answer}{@info};
Branch: 1 branch
BranchTrueFalseTotal
@info == 1 ? : 0 0 0
144 }
145  
146  
147 sub writeDelayed($$)
148 0 ▶{ my ($self, $foldername, $imap) = @_;
Subroutine writeDelayed: not called CC=6 SCAR=37.4
Pod documented
149  
150 0 my $id = $self->unique;
151 0 my $labels = $self->labels;
152  
153 0 ▶ if($self->head->modified || $self->body->modified || !$id)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->head->modified or $self->body->modified or not $id) { } 0 0 0
elsif ($self->{'MBIM_labels_changed'}) { } 0 0 0
Condition0%0/6
$self->head->modified or $self->body->modified or not $id
l!l&&r!l&&!r
000
$self->head->modified or $self->body->modified
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->head->modified or $self->body->modified or not $id
$self->head->modified $self->body->modified not $id
Truth table0%0/4
A or B or not(C)
A= $self->head->modifiedB= $self->body->modifiedC= not $id
ABCresult
1XX1
01X1
0011
0000
154 0 { $imap->appendMessage($self, $foldername);
155 0 ▶ if($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 0 0 0
156 0 { $self->delete;
157 0 $self->unique(undef);
158 }
159 }
160 elsif($self->{MBIM_labels_changed})
161 0 { $imap->setFlags($id, %$labels); # non-IMAP4 labels disappear
162 0 delete $self->{MBIM_labels_changed};
163 }
164  
165 0 $self;
166 }
167  
168 #--------------------
169  
170 3 1;
« Transport/IMAP4.pm ↑ Summary Box/IMAP4/Head.pm »