line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sisimai::Mail; |
2
|
80
|
|
|
80
|
|
238799
|
use feature ':5.10'; |
|
80
|
|
|
|
|
161
|
|
|
80
|
|
|
|
|
8023
|
|
3
|
80
|
|
|
80
|
|
512
|
use strict; |
|
80
|
|
|
|
|
131
|
|
|
80
|
|
|
|
|
1454
|
|
4
|
80
|
|
|
80
|
|
333
|
use warnings; |
|
80
|
|
|
|
|
121
|
|
|
80
|
|
|
|
|
3226
|
|
5
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
6
|
80
|
|
|
|
|
628
|
'new' => 0, |
7
|
|
|
|
|
|
|
'ro' => [ |
8
|
|
|
|
|
|
|
'path', # [String] path to mbox or Maildir/ |
9
|
|
|
|
|
|
|
'kind', # [String] Data type: mailbox, maildir, stdin, or memory |
10
|
|
|
|
|
|
|
], |
11
|
|
|
|
|
|
|
'rw' => [ |
12
|
|
|
|
|
|
|
'data', # [Sisimai::Mail::[Mbox,Maildir,Memory,STDIO] Object |
13
|
|
|
|
|
|
|
] |
14
|
80
|
|
|
80
|
|
31808
|
); |
|
80
|
|
|
|
|
85951
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
|
|
|
|
|
|
# Constructor of Sisimai::Mail |
18
|
|
|
|
|
|
|
# @param [String] argv1 Path to mbox or Maildir/ |
19
|
|
|
|
|
|
|
# @return [Sisimai::Mail] Object |
20
|
|
|
|
|
|
|
# [Undef] The argument is wrong |
21
|
570
|
|
|
570
|
1
|
464539
|
my $class = shift; |
22
|
570
|
|
|
|
|
1223
|
my $argv1 = shift; |
23
|
570
|
|
|
|
|
1024
|
my $klass = undef; |
24
|
570
|
|
|
|
|
1020
|
my $loads = 'Sisimai/Mail/'; |
25
|
570
|
|
|
|
|
2381
|
my $param = { 'kind' => '', 'data' => undef, 'path' => $argv1 }; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# The argumenet is a mailbox or a Maildir/. |
28
|
570
|
100
|
|
|
|
10390
|
if( -f $argv1 ) { |
|
|
100
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# The argument is a file, it is an mbox or email file in Maildir/ |
30
|
557
|
|
|
|
|
1929
|
$klass = __PACKAGE__.'::Mbox'; |
31
|
557
|
|
|
|
|
1269
|
$loads .= 'Mbox.pm'; |
32
|
557
|
|
|
|
|
1405
|
$param->{'kind'} = 'mailbox'; |
33
|
557
|
|
|
|
|
1151
|
$param->{'path'} = $argv1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} elsif( -d $argv1 ) { |
36
|
|
|
|
|
|
|
# The agument is not a file, it is a Maildir/ |
37
|
9
|
|
|
|
|
38
|
$klass = __PACKAGE__.'::Maildir'; |
38
|
9
|
|
|
|
|
29
|
$loads .= 'Maildir.pm'; |
39
|
9
|
|
|
|
|
28
|
$param->{'kind'} = 'maildir'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} else { |
42
|
|
|
|
|
|
|
# The argumen1 neither a mailbox nor a Maildir/. |
43
|
4
|
100
|
66
|
|
|
47
|
if( ref($argv1) eq 'GLOB' || $argv1 eq 'STDIN' ) { |
|
|
50
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Read from STDIN |
45
|
1
|
|
|
|
|
3
|
$klass = __PACKAGE__.'::STDIN'; |
46
|
1
|
|
|
|
|
2
|
$loads .= 'STDIN.pm'; |
47
|
1
|
|
|
|
|
3
|
$param->{'kind'} = 'stdin'; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} elsif( ref($argv1) eq 'SCALAR' ) { |
50
|
|
|
|
|
|
|
# Read from a variable as a scalar reference |
51
|
3
|
|
|
|
|
10
|
$klass = __PACKAGE__.'::Memory'; |
52
|
3
|
|
|
|
|
5
|
$loads .= 'Memory.pm'; |
53
|
3
|
|
|
|
|
8
|
$param->{'kind'} = 'memory'; |
54
|
3
|
|
|
|
|
7
|
$param->{'path'} = 'MEMORY'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
570
|
50
|
|
|
|
1685
|
return undef unless $klass; |
58
|
|
|
|
|
|
|
|
59
|
570
|
|
|
|
|
35284
|
require $loads; |
60
|
570
|
|
|
|
|
3586
|
$param->{'data'} = $klass->new($argv1); |
61
|
|
|
|
|
|
|
|
62
|
570
|
|
|
|
|
2616
|
return bless($param, __PACKAGE__); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub read { |
66
|
|
|
|
|
|
|
# Alias method of Sisimai::Mail::*->read() |
67
|
|
|
|
|
|
|
# @return [String] Contents of mbox/Maildir |
68
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
69
|
0
|
0
|
|
|
|
|
return undef unless ref $self->{'data'}; |
70
|
0
|
|
|
|
|
|
return $self->{'data'}->read; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |