Box/IMAP4/Message.pm

filter: Statementstmt 17.7% 17 / 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 13.6% 28 / 205 SCAR 67.7
CC
34
Cov
10%
label
210.0
loadBody
42.0
writeDelayed
42.0
CRAP 875.1
« Box/IMAP4.pm ↑ Summary Server/IMAP4/Fetch.pm »
1 # Copyrights 2001-2023 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution Mail-Box-IMAP4. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Box::IMAP4::Message;
10 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 $VERSION = '3.008';
12  
13 2 ▶use base 'Mail::Box::Net::Message';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Date::Parse 'str2time';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 sub init($)
22 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
23  
24 0 $self->SUPER::init($args);
25  
26 $self->{MBIM_write_labels}
27 0 ▶ = exists $args->{write_labels} ? $args->{write_labels} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'write_labels'} ? : 0 0 0
28  
29 0 $self->{MBIM_cache_labels} = $args->{cache_labels};
30 0 $self->{MBIM_cache_head} = $args->{cache_head};
31 0 $self->{MBIM_cache_body} = $args->{cache_body};
32  
33 0 $self;
34 }
35  
36  
37 sub size($)
38 0 ▶{ my $self = shift;
Subroutine size: not called CC=2 SCAR=17.9
Pod documented
39
40 0 ▶ return $self->SUPER::size
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isDelayed 0 0 0
41 unless $self->isDelayed;
42  
43 0 $self->fetch('RFC822.SIZE');
44 }
45  
46 sub recvstamp()
47 0 ▶{ my $date = shift->fetch('INTERNALDATE');
Subroutine recvstamp: not called CC=2 SCAR=17.9
Pod undocumented
48 0 ▶ defined $date ? str2time($date) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $date ? : 0 0 0
49 }
50  
51  
52 sub label(@)
53 0 ▶{ my $self = shift;
Subroutine label: not called CC=14 SCAR=53.5
Pod documented
54 0 ▶ my $imap = $self->folder->transporter or return;
Branch: 1 branch
BranchTrueFalseTotal
my $imap = $self->folder->transporter or return 0 0 0
55 0 ▶ my $id = $self->unique or return;
Branch: 1 branch
BranchTrueFalseTotal
my $id = $self->unique or return 0 0 0
56  
57 0 ▶ if(@_ == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
58 { # get one value only
59 0 my $label = shift;
60 0 my $labels = $self->{MM_labels};
61 return $labels->{$label}
62 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
63  
64 0 my $flags = $imap->getFlags($id);
65 0 ▶ if($self->{MBIM_cache_labels})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"MBIM_cache_labels"}) 0 0 0
66 { # the program may have added own labels
67 0 @{$labels}{keys %$flags} = values %$flags;
68 0 delete $self->{MBIM_labels_changed};
69 }
70 0 return $flags->{$label};
71 }
72  
73 0 my @private;
74 0 ▶ if($self->{MBIM_write_labels})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'MBIM_write_labels'}) { } 0 0 0
75 0 { @private = $imap->setFlags($id, @_);
76 0 delete $self->{MBIM_labels_changed};
77 }
78 else
79 0 { @private = @_;
80 }
81  
82 0 my $labels = $self->{MM_labels};
83 0 ▶ my @keep = $self->{MBIM_cache_labels} ? @_ : @private;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'MBIM_cache_labels'} ? : 0 0 0
84  
85 0 ▶ while(@keep)
Branch: 1 branch
BranchTrueFalseTotal
if (@keep) 0 0 0
86 0 { my ($k, $v) = (shift @keep, shift @keep);
87 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
88  
89 0 $self->{MBIM_labels_changed}++;
90 0 $labels->{$k} = $v;
91 }
92 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
93
94 0 $self;
95 }
96  
97  
98 sub labels()
99 0 ▶{ my $self = shift;
Subroutine labels: not called CC=5 SCAR=34.0
Pod documented
100 0 my $id = $self->unique;
101 0 my $labels = $self->SUPER::labels;
102 0 ▶ $labels = { %$labels } unless $self->{MBIM_cache_labels};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"MBIM_cache_labels"} 0 0 0
103  
104 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
105 0 ▶ { my $imap = $self->folder->transporter or return;
Branch: 1 branch
BranchTrueFalseTotal
my $imap = $self->folder->transporter or return 0 0 0
106 0 my $flags = $imap->getFlags($id);
107 0 @{$labels}{keys %$flags} = values %$flags;
108 }
109  
110 0 $labels;
111 }
112  
113 #-------------------------------------------
114  
115  
116 sub loadHead()
117 0 ▶{ my $self = shift;
Subroutine loadHead: not called CC=3 SCAR=24.8
Pod undocumented
118 0 my $head = $self->head;
119 0 ▶ return $head unless $head->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
unless $head->isDelayed 0 0 0
120  
121 0 $head = $self->folder->getHead($self);
122 0 ▶ $self->head($head) if $self->{MBIM_cache_head};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBIM_cache_head"} 0 0 0
123 0 $head;
124 }
125  
126 sub loadBody()
127 0 ▶{ my $self = shift;
Subroutine loadBody: not called CC=6 SCAR=37.4
Pod documented
128  
129 0 my $body = $self->body;
130 0 ▶ return $body unless $body->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
unless $body->isDelayed 0 0 0
131  
132 0 (my $head, $body) = $self->folder->getHeadAndBody($self);
133 0 ▶ return undef unless defined $head;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $head 0 0 0
134  
135 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
136 0 ▶ $self->storeBody($body) if $self->{MBIM_cache_body};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBIM_cache_body"} 0 0 0
137 0 $body;
138 }
139  
140  
141 sub fetch(@)
142 0 ▶{ my ($self, @info) = @_;
Subroutine fetch: not called CC=2 SCAR=17.9
Pod documented
143 0 my $folder = $self->folder;
144 0 my $answer = ($folder->fetch( [$self], @info))[0];
145  
146 0 ▶ @info==1 ? $answer->{$info[0]} : @{$answer}{@info};
Branch: 1 branch
BranchTrueFalseTotal
@info == 1 ? : 0 0 0
147 }
148  
149  
150 sub writeDelayed($$)
151 0 ▶{ my ($self, $foldername, $imap) = @_;
Subroutine writeDelayed: not called CC=6 SCAR=37.4
Pod documented
152  
153 0 my $id = $self->unique;
154 0 my $labels = $self->labels;
155  
156 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
157 {
158 0 $imap->appendMessage($self, $foldername);
159 0 ▶ if($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 0 0 0
160 0 { $self->delete;
161 0 $self->unique(undef);
162 }
163 }
164 elsif($self->{MBIM_labels_changed})
165 0 { $imap->setFlags($id, %$labels); # non-IMAP4 labels disappear
166 0 delete $self->{MBIM_labels_changed};
167 }
168  
169 0 $self;
170 }
171  
172 #-------------------------------------------
173  
174  
175 2 1;
« Box/IMAP4.pm ↑ Summary Server/IMAP4/Fetch.pm »