| 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::Locker::Mutt;{ |
|
13
|
|
|
|
|
|
|
our $VERSION = '4.01'; |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
2158
|
use parent 'Mail::Box::Locker'; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
14
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
183
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
48
|
|
|
19
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
114
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
10
|
use Log::Report 'mail-box', import => [ qw/__x fault warning/ ]; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
15
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
363
|
use POSIX qw/sys_wait_h/; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
20
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#-------------------- |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init($) |
|
28
|
0
|
|
|
0
|
0
|
|
{ my ($self, $args) = @_; |
|
29
|
0
|
|
|
|
|
|
$self->SUPER::init($args); |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
$self->{MBLM_exe} = $args->{exe} || 'mutt_dotlock'; |
|
32
|
0
|
|
|
|
|
|
$self; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub name() { 'MUTT' } |
|
36
|
0
|
|
|
0
|
0
|
|
sub lockfile() { $_[0]->filename . '.lock' } |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#-------------------- |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
0
|
1
|
|
sub exe() { $_[0]->{MBLM_exe} } |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#-------------------- |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub unlock() |
|
45
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
|
46
|
0
|
0
|
|
|
|
|
$self->hasLock or return $self; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
system $self->exe, '-u', $self->filename |
|
49
|
|
|
|
|
|
|
and warning __x"couldn't remove mutt-unlock {folder}", folder => $self->folder; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self->SUPER::unlock; |
|
52
|
0
|
|
|
|
|
|
$self; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub lock() |
|
57
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
|
58
|
0
|
|
|
|
|
|
my $filename = $self->filename; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
$self->hasLock |
|
61
|
|
|
|
|
|
|
and warning(__x"folder {name} already mutt-locked with {file}.", name => $self->folder, file => $filename), return 1; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $lockfn = $self->lockfile; |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $timeout = $self->timeout; |
|
66
|
0
|
0
|
|
|
|
|
my $end = $timeout eq 'NOTIMEOUT' ? -1 : $timeout; |
|
67
|
0
|
|
|
|
|
|
my $expire = $self->expires / 86400; # in days for -A |
|
68
|
0
|
|
|
|
|
|
my $exe = $self->exe; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
while(1) |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
0
|
0
|
|
|
|
|
system $exe, '-p', '-r', 1, $filename |
|
73
|
|
|
|
|
|
|
or return $self->SUPER::lock; # success |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
0
|
0
|
|
|
|
WIFEXITED($?) && WEXITSTATUS($?)==3 |
|
76
|
|
|
|
|
|
|
or fault __x"folder {name} will never get a mutt-lock with {file}", name => $self->folder, file => $filename; |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
0
|
0
|
|
|
|
if(-e $lockfn && -A $lockfn > $expire) |
|
79
|
0
|
0
|
|
|
|
|
{ system $exe, '-f', '-u', $filename |
|
80
|
|
|
|
|
|
|
and warning(__x"removed expired mutt-lock file {file}.", file => $lockfn), redo; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
fault __x"failed to remove expired mutt-lock {file}", file => $lockfn; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
--$end or last; |
|
86
|
0
|
|
|
|
|
|
sleep 1; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
0; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub isLocked() |
|
93
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
|
94
|
0
|
|
|
|
|
|
system $self->exe, '-t', $self->filename; |
|
95
|
0
|
0
|
|
|
|
|
WIFEXITED($?) && WEXITSTATUS($?)==3; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |