line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::POP3::Folder::mbox::parse_to_disk; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
31
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
118
|
|
4
|
4
|
|
|
4
|
|
23
|
use IO::File; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
576
|
|
5
|
4
|
|
|
4
|
|
26
|
use Fcntl ':flock'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
386
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
24
|
use vars qw(@ISA); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
4173
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Mail::POP3::Folder::mbox); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $CRLF = "\015\012"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my ( |
14
|
2
|
|
|
2
|
1
|
3109
|
$class, |
15
|
|
|
|
|
|
|
$user_name, |
16
|
|
|
|
|
|
|
$password, |
17
|
|
|
|
|
|
|
$user_id, |
18
|
|
|
|
|
|
|
$mailgroup, |
19
|
|
|
|
|
|
|
$spoolfile, |
20
|
|
|
|
|
|
|
$message_start, |
21
|
|
|
|
|
|
|
$message_end, |
22
|
|
|
|
|
|
|
$tmpdir, |
23
|
|
|
|
|
|
|
$debug, |
24
|
|
|
|
|
|
|
) = @_; |
25
|
2
|
|
|
|
|
65
|
my $self = $class->SUPER::new( |
26
|
|
|
|
|
|
|
$user_name, |
27
|
|
|
|
|
|
|
$password, |
28
|
|
|
|
|
|
|
$user_id, |
29
|
|
|
|
|
|
|
$mailgroup, |
30
|
|
|
|
|
|
|
$spoolfile, |
31
|
|
|
|
|
|
|
$message_start, |
32
|
|
|
|
|
|
|
$message_end, |
33
|
|
|
|
|
|
|
); |
34
|
2
|
|
|
|
|
11
|
$self->{TMPDIR} = $tmpdir; |
35
|
2
|
|
|
|
|
22
|
$self->{DEBUG} = $debug; |
36
|
2
|
|
|
|
|
15
|
$self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _start_new_message { |
40
|
6
|
|
|
6
|
|
18
|
my ($self, $newmessageno, $fromline) = @_; |
41
|
6
|
|
|
|
|
39
|
$self->SUPER::_start_new_message($newmessageno, $fromline); |
42
|
6
|
|
|
|
|
47
|
$> = 0; |
43
|
6
|
50
|
|
|
|
88
|
unless (-d $self->{TMPDIR}) { |
44
|
0
|
0
|
|
|
|
0
|
mkdir $self->{TMPDIR}, 0700 |
45
|
|
|
|
|
|
|
or die "Couldn't create spool dir '$self->{TMPDIR}': $!\n"; |
46
|
|
|
|
|
|
|
} |
47
|
6
|
|
|
|
|
163
|
my $file = $self->_tmpdir_lockfile; |
48
|
6
|
|
|
|
|
74
|
$self->{TMPDIRLOCK} = IO::File->new(">$file"); |
49
|
6
|
50
|
|
|
|
698
|
unless (flock $self->{TMPDIRLOCK}, LOCK_EX|LOCK_NB) { |
50
|
0
|
|
|
|
|
0
|
die "Could not flock $file\n"; |
51
|
|
|
|
|
|
|
} |
52
|
6
|
|
|
|
|
27
|
$file = $self->_msg2filename($newmessageno); |
53
|
6
|
50
|
|
|
|
79
|
$self->{MESSAGE_FH} = IO::File->new(">$file") |
54
|
|
|
|
|
|
|
or die "Couldn't create spool file: $!\n"; |
55
|
6
|
|
|
|
|
655
|
chmod 0600, $file; |
56
|
6
|
|
|
|
|
90
|
$> = $self->{CLIENT_USER_ID}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _close_old_message { |
60
|
8
|
|
|
8
|
|
23
|
my ($self, $oldmessageno, $messageuidl, $messageoctets) = @_; |
61
|
8
|
100
|
|
|
|
28
|
return if $oldmessageno <= 0; |
62
|
6
|
|
|
|
|
51
|
$self->SUPER::_close_old_message( |
63
|
|
|
|
|
|
|
$oldmessageno, $messageuidl, $messageoctets |
64
|
|
|
|
|
|
|
); |
65
|
6
|
|
|
|
|
47
|
$> = 0; |
66
|
6
|
50
|
|
|
|
183
|
close $self->{MESSAGE_FH} if $self->{MESSAGE_FH}; |
67
|
6
|
|
|
|
|
67
|
$> = $self->{CLIENT_USER_ID}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub lock_release { |
71
|
2
|
|
|
2
|
1
|
6
|
my $self = shift; |
72
|
2
|
|
|
|
|
26
|
close $self->{TMPDIRLOCK}; |
73
|
2
|
|
|
|
|
9
|
unlink $self->_tmpdir_lockfile; |
74
|
2
|
|
|
|
|
109
|
$self->SUPER::lock_release; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Build message arrays or write the next line to disk |
78
|
|
|
|
|
|
|
sub _push_message { |
79
|
68
|
|
|
68
|
|
136
|
my ($self, $messagecnt, $data) = @_; |
80
|
68
|
|
|
|
|
475
|
$> = 0; |
81
|
68
|
|
|
|
|
382
|
$self->{MESSAGE_FH}->print("$data\n"); |
82
|
68
|
|
|
|
|
927
|
$> = $self->{CLIENT_USER_ID}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _tmpdir_lockfile { |
86
|
8
|
|
|
8
|
|
26
|
my ($self, $message) = @_; |
87
|
8
|
|
|
|
|
32
|
"$self->{TMPDIR}/.mpopd.lock"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _msg2filename { |
91
|
20
|
|
|
20
|
|
58
|
my ($self, $message) = @_; |
92
|
20
|
|
|
|
|
85
|
"$self->{TMPDIR}/$message"; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# $message starts at 1 |
96
|
|
|
|
|
|
|
# returns number of bytes |
97
|
|
|
|
|
|
|
sub top { |
98
|
2
|
|
|
2
|
1
|
568
|
my ($self, $message, $output_fh, $body_lines) = @_; |
99
|
2
|
|
|
|
|
5
|
my $top_bytes = 0; |
100
|
2
|
|
|
|
|
18
|
$> = 0; |
101
|
2
|
|
|
|
|
13
|
local *MSG; |
102
|
2
|
|
|
|
|
7
|
open MSG, $self->_msg2filename($message); |
103
|
|
|
|
|
|
|
# print the headers |
104
|
2
|
|
|
|
|
130
|
while () { |
105
|
20
|
|
|
|
|
41
|
chomp; |
106
|
20
|
|
|
|
|
57
|
$self->_lock_update; |
107
|
20
|
|
|
|
|
56
|
my $out = "$_$CRLF"; |
108
|
20
|
|
|
|
|
52
|
$output_fh->print($out); |
109
|
20
|
|
|
|
|
215
|
$top_bytes += length($out); |
110
|
20
|
100
|
|
|
|
100
|
last if /^\s*$/; |
111
|
|
|
|
|
|
|
} |
112
|
2
|
|
|
|
|
7
|
my $cnt = 0; |
113
|
|
|
|
|
|
|
# print the TOP arg number of body lines |
114
|
2
|
|
|
|
|
16
|
while () { |
115
|
6
|
|
|
|
|
11
|
chomp; |
116
|
6
|
100
|
|
|
|
15
|
last if ++$cnt > $body_lines; |
117
|
|
|
|
|
|
|
# byte-stuff lines starting with . |
118
|
4
|
|
|
|
|
10
|
s/^\./\.\./o; |
119
|
4
|
|
|
|
|
14
|
$self->_lock_update; |
120
|
4
|
|
|
|
|
12
|
my $out = "$_$CRLF"; |
121
|
4
|
|
|
|
|
15
|
$output_fh->print($out); |
122
|
4
|
|
|
|
|
49
|
$top_bytes += length($out); |
123
|
|
|
|
|
|
|
} |
124
|
2
|
|
|
|
|
28
|
close MSG; |
125
|
2
|
|
|
|
|
20
|
$> = $self->{CLIENT_USER_ID}; |
126
|
2
|
|
|
|
|
18
|
$top_bytes; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub flush_delete { |
130
|
2
|
|
|
2
|
1
|
6
|
my ($self) = @_; |
131
|
2
|
|
|
|
|
28
|
$self->SUPER::flush_delete; |
132
|
2
|
50
|
|
|
|
15
|
if (not $self->{DEBUG}) { |
133
|
2
|
|
|
|
|
16
|
foreach my $cnt (1..$self->{MESSAGECNT}) { |
134
|
6
|
|
|
|
|
214
|
unlink $self->_msg2filename($cnt); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub retrieve { |
140
|
6
|
|
|
6
|
1
|
944
|
my ($self, $message, $output_fh, $mbox_destined) = @_; |
141
|
6
|
|
|
|
|
50
|
$> = 0; |
142
|
6
|
|
|
|
|
22
|
local *MSG; |
143
|
6
|
|
|
|
|
21
|
open MSG, $self->_msg2filename($message); |
144
|
6
|
|
|
|
|
318
|
while () { |
145
|
76
|
|
|
|
|
553
|
chomp; |
146
|
76
|
100
|
|
|
|
156
|
s/^\./\.\./o unless $mbox_destined; |
147
|
76
|
|
|
|
|
189
|
$self->_lock_update; |
148
|
76
|
100
|
|
|
|
214
|
my $line = $mbox_destined ? "$_\n" : "$_$CRLF"; |
149
|
76
|
|
|
|
|
149
|
$output_fh->print($line); |
150
|
|
|
|
|
|
|
} |
151
|
6
|
|
|
|
|
122
|
close MSG; |
152
|
6
|
|
|
|
|
84
|
$> = $self->{CLIENT_USER_ID}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__END__ |