line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MBX; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Mail::MBX - Read MBX mailbox files |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Mail::MBX (); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $mbx = Mail::MBX->open('mailbox.mbx'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
while (my $message = $mbx->message) { |
14
|
|
|
|
|
|
|
while ($message->read(my $buf, 4096)) { |
15
|
|
|
|
|
|
|
# Do something with the message body |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$mbx->close; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
C provides a reasonable way to read mailboxes in the MBX format, as |
24
|
|
|
|
|
|
|
used by the University of Washington's UW-IMAP reference implementation. At |
25
|
|
|
|
|
|
|
present, only sequential reading is supported, though this is ideal for mailbox |
26
|
|
|
|
|
|
|
format conversion tasks. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 OPENING MAILBOXES |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=over |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
471
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
35
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
317
|
use Mail::MBX::Message (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
395
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our $VERSION = '0.01_0001'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item Copen(I<$file>)> |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Open an MBX mailbox file, returning a new C object. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub open { |
48
|
0
|
|
|
0
|
1
|
|
my ( $class, $file ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $uidvalidity; |
51
|
|
|
|
|
|
|
my @keywords; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
open( my $fh, '<', $file ) or die("Unable to open mailbox file $file: $!"); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $line = readline($fh); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# If the first line of the file is empty, then |
59
|
|
|
|
|
|
|
# |
60
|
0
|
0
|
|
|
|
|
if ( !defined $line ) { |
|
|
0
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
elsif ( $line ne "*mbx*\r\n" ) { |
65
|
0
|
|
|
|
|
|
die("File $file is not an MBX file"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$line = readline($fh); |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if ( $line =~ /^([[:xdigit:]]{8})([[:xdigit:]]{8})\r\n$/ ) { |
71
|
0
|
|
|
|
|
|
$uidvalidity = hex($1); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
0
|
|
|
|
|
|
die("File $file has invalid UID line"); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
foreach ( 0 .. 29 ) { |
78
|
0
|
|
|
|
|
|
chomp( $line = readline($fh) ); |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if ( $line ne '' ) { |
81
|
0
|
|
|
|
|
|
push( @keywords, $line ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
seek( $fh, 2048, 0 ); |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return bless { |
88
|
|
|
|
|
|
|
'file' => $file, |
89
|
|
|
|
|
|
|
'fh' => $fh, |
90
|
|
|
|
|
|
|
'uidvalidity' => $uidvalidity, |
91
|
|
|
|
|
|
|
'keyword' => \@keywords, |
92
|
|
|
|
|
|
|
'uid' => 0 |
93
|
|
|
|
|
|
|
}, $class; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item C<$mbx-Eclose()> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Close the current mailbox object. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub close { |
103
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if ( defined $self->{'fh'} ) { |
106
|
0
|
|
|
|
|
|
close $self->{'fh'}; |
107
|
0
|
|
|
|
|
|
undef $self->{'fh'}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub DESTROY { |
114
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$self->close; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item C<$mbx-Emessage()> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Return the current MBX message, in the form of a C> |
124
|
|
|
|
|
|
|
object, and move the internal file handle to the next message. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
See C> for further details on accessing message contents. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub message { |
131
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
if ( eof $self->{'fh'} ) { |
134
|
0
|
|
|
|
|
|
return; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my $message = Mail::MBX::Message->parse( $self->{'fh'} ); |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
if ( $message->{'uid'} == 0 ) { |
140
|
0
|
|
|
|
|
|
$message->{'uid'} = ++$self->{'uid'}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return $message; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__END__ |