Server/IMAP4/User.pm

filter: Statementstmt 28.3% 15 / 53 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 40.0% 4 / 10 Podpod 80.0% 4 / 5 totaltotal 21.1% 23 / 109 CC 19 SCAR 36.3
CC
19
Cov
17%
create
72.0
_delete
56.0
init
12.0
CRAP 37.8
« Server/IMAP4/Fetch.pm ↑ Summary Server/IMAP4/List.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::Server::IMAP4::User;{
13 1 our $VERSION = '4.01';
14 }
15  
16 1 ▶use parent 'Mail::Box::Manage::User';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Log::Report 'mail-box-imap4', import => [ qw/__x fault warning/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #--------------------
24  
25 sub init($)
26 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=3 SCAR=24.8
Pod undocumented
27 0 ▶ $self->SUPER::init($args) or return ();
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($args) or return () 0 0 0
28 0 ▶ $self->{MSNU_indexfile} = $args->{indexfile} // ($self->folderdir . '/index');
Condition0%0/2
$args->{"indexfile"} // $self->folderdir . '/index'
l!l
00
MC/DC0%0/1
$args->{"indexfile"} // $self->folderdir . '/index'
$args->{"indexfile"}
Truth table0%0/2
A
A= $args->{"indexfile"}
Aresult
11
00
29 0 $self;
30 }
31  
32 #--------------------
33  
34 0 ▶sub indexFilename() { $_[0]->{MSNU_indexfile} };
Subroutine indexFilename: not called CC=1 SCAR=6.9
Pod documented
35  
36 #--------------------
37  
38 sub folderInfo($)
39 0 ▶{ my $index = $_[0]->index or return ();
Subroutine folderInfo: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $index = $_[0]->index or return () 0 0 0
40 0 $index->folder(shift);
41 }
42  
43  
44 sub delete($)
45 0 ▶{ my ($self, $name) = @_;
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
46 0 ▶ my $index = $self->index->startModify or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $index = $self->index->startModify or return 0 0 0 0
47  
48 0 ▶ unless($self->_delete($index, $name))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_delete($index, $name)) 0 0 0
49 0 { $self->cancelModification($index);
50 0 return 0;
51 }
52  
53 0 $index->write;
54 }
55  
56 sub _delete($$)
57 0 ▶{ my ($self, $index, $name) = @_;
Subroutine _delete: not called CC=7 SCAR=40.3
58  
59 # First clean all subfolders recursively
60 0 foreach my $subf ($index->subfolders($name))
61 0 ▶ { $self->_delete($index, $subf) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_delete($index, $subf) or return 0 0 0 0
62 }
63  
64 # Already disappeared? Shouldn't happen, but ok
65 0 ▶ my $info = $index->folder($name)
Branch: 1 branch
BranchTrueFalseTotal
my $info = $index->folder($name) or return 1 0 0 0
66 or return 1;
67  
68 # Bluntly clean-out the directory
69 0 ▶ if(my $dir = $info->{Directory})
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = $info->{"Directory"}) 0 0 0
70 { # Bluntly try to remove, but error is not set
71 0 ▶ if(remove(\1, $dir) != 0 && -d $dir)
Branch: 1 branch
BranchTrueFalseTotal
if (remove(\1, $dir) != 0 and -d $dir) 0 0 0
Condition0%0/3
remove(\1, $dir) != 0 and -d $dir
!ll&&!rl&&r
000
MC/DC0%0/2
remove(\1, $dir) != 0 and -d $dir
remove(\1, $dir) != 0 -d $dir
Truth table0%0/3
A and B
A= remove(\1, $dir) != 0B= -d $dir
ABresult
0X0
100
111
72 0 { fault __x"Unable to remove folder {name}", name => $dir;
73 0 return 0;
74 }
75 }
76  
77 # Remove (sub)folder from index
78 0 $index->folder($name, undef);
79 0 1;
80 }
81  
82  
83 sub create($@)
84 0 ▶{ my ($self, $name) = (shift, shift);
Subroutine create: not called CC=8 SCAR=42.8
Pod documented
85 0 ▶ my $index = $self->index->startModify or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $index = $self->index->startModify or return undef 0 0 0
86  
87 0 ▶ if(my $info = $index->folder($name))
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = $index->folder($name)) 0 0 0
88 0 { warning __x"folder {name} already exists, creation skipped.", name => $name;
89 0 return $info;
90 }
91  
92 0 my $uniq = $index->createUnique;
93  
94 # Create the directory
95 # Also in this case, we bluntly try to create it, and when it doesn't
96 # work, we check whether we did too much. This may safe an NFS stat.
97  
98 0 my $dir = $self->home . '/F' . $uniq;
99 0 ▶ -d $dir or mkdir $dir, 0750
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or mkdir $dir, 488 or &fault(&__x("cannot create folder directory {dir}", "dir", $dir)) 0 0 0
Condition0%0/3
-d $dir or mkdir $dir, 488
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $dir or mkdir $dir, 488
-d $dir mkdir $dir, 488
Truth table0%0/3
A or B
A= -d $dirB= mkdir $dir, 488
ABresult
1X1
011
000
100 or fault __x"cannot create folder directory {dir}", dir => $dir;
101  
102 # Write folder name in directory, for recovery purposes.
103 0 my $namefile = "$dir/name";
104 0 my $namefh;
105 0 ▶ open $namefh, '>:encoding(utf-8)', $namefile
Branch: 1 branch
BranchTrueFalseTotal
open $namefh, ">:encoding(utf-8)", $namefile or &fault(&__x("cannot write name for folder in {file}", "file", $namefile)) 0 0 0
106 or fault __x"cannot write name for folder in {file}", file => $namefile;
107  
108 0 $namefh->print("$name\n");
109  
110 0 ▶ $namefh->close
Branch: 1 branch
BranchTrueFalseTotal
$namefh->close or &fault(&__x("failed writing folder name to {file}", "file", $namefile)) 0 0 0
111 or fault __x"failed writing folder name to {file}", file => $namefile;
112  
113 # Add folder to the index
114  
115 0 my $facts = $self->folder(
116 $name,
117 Folder => $name,
118 Directory => $dir,
119 Messages => 0,
120 Size => 0,
121 );
122  
123 0 ▶ $self->write && $facts;
Branch: 1 branch
BranchTrueFalseTotal
$self->write and $facts 0 0 0
124 }
125  
126 #--------------------
127  
128 1 1;
« Server/IMAP4/Fetch.pm ↑ Summary Server/IMAP4/List.pm »