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