line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sisimai::Mail::STDIN; |
2
|
3
|
|
|
3
|
|
68635
|
use feature ':5.10'; |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
334
|
|
3
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
58
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
77
|
|
5
|
3
|
|
|
3
|
|
580
|
use IO::Handle; |
|
3
|
|
|
|
|
7035
|
|
|
3
|
|
|
|
|
202
|
|
6
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
7
|
3
|
|
|
|
|
25
|
'new' => 0, |
8
|
|
|
|
|
|
|
'ro' => [ |
9
|
|
|
|
|
|
|
'path', # [String] Fixed string "" |
10
|
|
|
|
|
|
|
'size', # [Integer] Data size which has been read |
11
|
|
|
|
|
|
|
], |
12
|
|
|
|
|
|
|
'rw' => [ |
13
|
|
|
|
|
|
|
'offset', # [Integer] The number of emails which have been read |
14
|
|
|
|
|
|
|
'handle', # [IO::File] File handle |
15
|
|
|
|
|
|
|
] |
16
|
3
|
|
|
3
|
|
500
|
); |
|
3
|
|
|
|
|
1168
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
# Constructor of Sisimai::Mail::STDIN |
20
|
|
|
|
|
|
|
# @return [Sisimai::Mail::STDIN] Object |
21
|
3
|
|
|
3
|
1
|
2371
|
my $class = shift; |
22
|
3
|
|
|
|
|
19
|
my $param = { |
23
|
|
|
|
|
|
|
'path' => '', |
24
|
|
|
|
|
|
|
'size' => 0, |
25
|
|
|
|
|
|
|
'offset' => 0, |
26
|
|
|
|
|
|
|
'handle' => IO::Handle->new->fdopen(fileno(STDIN), 'r'), |
27
|
|
|
|
|
|
|
}; |
28
|
3
|
|
|
|
|
262
|
return bless($param, __PACKAGE__); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub read { |
32
|
|
|
|
|
|
|
# Mbox reader, works as a iterator. |
33
|
|
|
|
|
|
|
# @return [String] Contents of mbox |
34
|
1
|
|
|
1
|
1
|
2749
|
my $self = shift; |
35
|
1
|
50
|
|
|
|
37
|
return undef unless -T $self->{'handle'}; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
4
|
my $readhandle = $self->{'handle'}; |
38
|
1
|
|
|
|
|
3
|
my $readbuffer = ''; |
39
|
1
|
|
|
|
|
2
|
eval { |
40
|
1
|
50
|
|
|
|
5
|
$readhandle = $self->{'handle'}->fdopen(fileno(STDIN), 'r') unless eof $readhandle; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
6
|
while( my $r = <$readhandle> ) { |
43
|
|
|
|
|
|
|
# Read an email from the mailbox file |
44
|
0
|
0
|
0
|
|
|
0
|
last if( $readbuffer && substr($r, 0, 5) eq 'From ' ); |
45
|
0
|
|
|
|
|
0
|
$readbuffer .= $r; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
}; |
48
|
1
|
|
|
|
|
3
|
$self->{'size'} += length $readbuffer; |
49
|
1
|
|
|
|
|
2
|
$self->{'offset'} += 1; |
50
|
1
|
|
|
|
|
4
|
return $readbuffer; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
__END__ |