| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# This code is part of Perl distribution Mail-Box 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::Manage::User;{ |
|
13
|
|
|
|
|
|
|
our $VERSION = '4.01'; |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
3
|
|
|
3
|
|
3385
|
use parent 'Mail::Box::Manager'; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
23
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
|
208
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
63
|
|
|
19
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
223
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
3
|
|
|
3
|
|
17
|
use Log::Report 'mail-box', import => [ qw/__x error panic trace warning/ ]; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
23
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
3
|
|
|
3
|
|
1477
|
use Mail::Box::Collection (); |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
3279
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#-------------------- |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init($) |
|
28
|
2
|
|
|
2
|
0
|
514413
|
{ my ($self, $args) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
25
|
$self->SUPER::init($args); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $identity = $self->{MBMU_id} = $args->{identity} |
|
33
|
2
|
50
|
|
|
|
18
|
or error __x"user manager requires an identity."; |
|
34
|
|
|
|
|
|
|
|
|
35
|
2
|
|
50
|
|
|
162
|
my $top = $args->{folder_id_type} // 'Mail::Box::Identity'; |
|
36
|
2
|
|
50
|
|
|
15
|
my $coltype = $args->{collection_type} // 'Mail::Box::Collection'; |
|
37
|
|
|
|
|
|
|
|
|
38
|
2
|
50
|
|
|
|
33
|
unless(blessed $top) |
|
39
|
2
|
|
|
|
|
7
|
{ my $name = $args->{topfolder_name}; |
|
40
|
2
|
|
50
|
|
|
14
|
$name //= '='; # MailBox's abbrev to top |
|
41
|
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
20
|
$top = $top->new( |
|
43
|
|
|
|
|
|
|
name => $name, |
|
44
|
|
|
|
|
|
|
manager => $self, |
|
45
|
|
|
|
|
|
|
location => scalar($self->folderdir), |
|
46
|
|
|
|
|
|
|
folder_type => $self->defaultFolderType, |
|
47
|
|
|
|
|
|
|
collection_type => $coltype, |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
8
|
$self->{MBMU_top} = $top; |
|
52
|
2
|
|
50
|
|
|
13
|
$self->{MBMU_delim} = $args->{delimiter} || '/'; |
|
53
|
2
|
|
|
|
|
7
|
$self->{MBMU_inbox} = $args->{inbox}; |
|
54
|
2
|
|
|
|
|
8
|
$self; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#-------------------- |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
|
|
1
|
1
|
1378
|
sub identity() { $_[0]->{MBMU_id} } |
|
60
|
0
|
|
|
0
|
1
|
0
|
sub delimiter() { $_[0]->{MBMU_delim} } |
|
61
|
2
|
|
|
2
|
1
|
1792
|
sub topfolder() { $_[0]->{MBMU_top} } |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub inbox(;$) |
|
65
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
|
66
|
0
|
0
|
|
|
|
|
@_ ? ($self->{MBMU_inbox} = shift) : $self->{MBMU_inbox}; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#-------------------- |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# A lot of work still has to be done here: all moves etc must inform |
|
72
|
|
|
|
|
|
|
# the "existence" administration as well. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#-------------------- |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub folder($) |
|
77
|
0
|
|
|
0
|
1
|
|
{ my ($self, $name) = @_; |
|
78
|
0
|
0
|
|
|
|
|
my $top = $self->topFolder or return (); |
|
79
|
0
|
|
|
|
|
|
my @path = split $self->delimiter, $name; |
|
80
|
0
|
0
|
|
|
|
|
(shift @path) eq $top->name or return (); |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$top->folder(@path); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub folderCollection($) |
|
87
|
0
|
|
|
0
|
1
|
|
{ my ($self, $name) = @_; |
|
88
|
0
|
0
|
|
|
|
|
my $top = $self->topFolder or return (); |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my @path = split $self->delimiter, $name; |
|
91
|
0
|
0
|
|
|
|
|
shift @path eq $top->name |
|
92
|
|
|
|
|
|
|
or error __x"folder {name} not under top.", name => $name; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $base = pop @path; |
|
95
|
0
|
|
|
|
|
|
($top->folder(@path), $base); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# This feature is thoroughly tested in the Mail::Box::Netzwert distribution |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub create($@) |
|
102
|
0
|
|
|
0
|
1
|
|
{ my ($self, $name, %args) = @_; |
|
103
|
0
|
|
|
|
|
|
my ($dir, $base) = $self->folderCollection($name); |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
unless(defined $dir) |
|
106
|
|
|
|
|
|
|
{ $args{create_supers} |
|
107
|
0
|
0
|
|
|
|
|
or error __x"cannot create folder {name}: higher levels missing.", name => $name; |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $delim = $self->delimiter; |
|
110
|
0
|
0
|
|
|
|
|
my $upper = $name =~ s!$delim$base!!r or panic "$name - $base"; |
|
111
|
0
|
|
|
|
|
|
$dir = $self->create($upper, %args, deleted => 1); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $id = $dir->folder($base); |
|
115
|
0
|
0
|
|
|
|
|
if(!defined $id) |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
116
|
0
|
|
0
|
|
|
|
{ my $idopt = $args{id_options} || []; |
|
117
|
0
|
|
|
|
|
|
$id = $dir->addSubfolder($base, @$idopt, deleted => $args{deleted}); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
elsif($args{deleted}) |
|
120
|
0
|
|
|
|
|
|
{ $id->deleted(1); |
|
121
|
0
|
|
|
|
|
|
return $id; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
elsif($id->deleted) |
|
124
|
|
|
|
|
|
|
{ # Revive! Raise the death! |
|
125
|
0
|
|
|
|
|
|
$id->deleted(0); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
else |
|
128
|
|
|
|
|
|
|
{ # Bumped into existing folder |
|
129
|
0
|
|
|
|
|
|
error __x"folder {name} already exists.", name => $name; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$self->defaultFolderType->create($id->location, %args) |
|
133
|
0
|
0
|
0
|
|
|
|
if ! exists $args{create_real} || $args{create_real}; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$id; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub delete($) |
|
140
|
0
|
|
|
0
|
1
|
|
{ my ($self, $name) = @_; |
|
141
|
0
|
0
|
|
|
|
|
my $folder = $self->folder($name) or return (); |
|
142
|
0
|
|
|
|
|
|
$folder->remove; |
|
143
|
0
|
|
|
|
|
|
$self->SUPER::delete($name); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub rename($$@) |
|
148
|
0
|
|
|
0
|
1
|
|
{ my ($self, $oldname, $newname, %args) = @_; |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
my $old = $self->folder($oldname) |
|
151
|
|
|
|
|
|
|
or error __x"source folder for rename does not exist: {from} to {to}.", from => $oldname, to => $newname; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my ($newdir, $base) = $self->folderCollection($newname); |
|
154
|
0
|
0
|
|
|
|
|
unless(defined $newdir) |
|
155
|
|
|
|
|
|
|
{ $args{create_supers} |
|
156
|
0
|
0
|
|
|
|
|
or error __x"cannot rename folder {from} to {to}: higher levels are missing.", from => $oldname, to => $newname; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my $delim = $self->delimiter; |
|
159
|
0
|
0
|
|
|
|
|
my $upper = $newname =~ s!$delim$base!!r or panic "$newname - $base"; |
|
160
|
0
|
|
|
|
|
|
$newdir = $self->create($upper, %args, deleted => 1); |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $oldlocation = $old->location; |
|
164
|
0
|
|
|
|
|
|
my $new = $old->rename($newdir, $base); |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $newlocation = $new->location; |
|
167
|
0
|
0
|
|
|
|
|
$oldlocation eq $newlocation |
|
168
|
|
|
|
|
|
|
or panic "Physical folder relocation not yet implemented"; #XXX |
|
169
|
|
|
|
|
|
|
# this needs a $old->rename(xx,yy) which isn't implemented yet |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
trace "renamed folder $oldname to $newname"; |
|
172
|
0
|
|
|
|
|
|
$new; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |