| 1 | package Sisimai::Mail; | ||||||||||||||||||||||||||||||||
| 2 | 88 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 88 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 88 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 88 | ▶ | use Sisimai::Eb; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 88 | ▶ | use Class::Accessor::Lite ( | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 88 | 'new' => 0, | |||||||||||||||||||||||||||||||
| 8 | 'ro' => [ | ||||||||||||||||||||||||||||||||
| 9 | 'path', # [String] path to mbox or Maildir/ | ||||||||||||||||||||||||||||||||
| 10 | 'kind', # [String] Data type: mailbox, maildir, stdin, or memory | ||||||||||||||||||||||||||||||||
| 11 | ], | ||||||||||||||||||||||||||||||||
| 12 | 'rw' => [ | ||||||||||||||||||||||||||||||||
| 13 | 'data', # [Sisimai::Mail::[Mbox,Maildir,Memory,STDIO] Object | ||||||||||||||||||||||||||||||||
| 14 | ] | ||||||||||||||||||||||||||||||||
| 15 | 88 | ); | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 754 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 18 | # Constructor of Sisimai::Mail | ||||||||||||||||||||||||||||||||
| 19 | # @param [String] argv1 Path to mbox or Maildir/ | ||||||||||||||||||||||||||||||||
| 20 | # @return [Sisimai::Mail] Object | ||||||||||||||||||||||||||||||||
| 21 | # [Undef] The argument is wrong | ||||||||||||||||||||||||||||||||
| 22 | 754 | my $class = shift; | |||||||||||||||||||||||||||||||
| 23 | 754 | my $argv1 = shift; | |||||||||||||||||||||||||||||||
| 24 | 754 | my $klass = undef; | |||||||||||||||||||||||||||||||
| 25 | 754 | my $loads = 'Sisimai/Mail/'; | |||||||||||||||||||||||||||||||
| 26 | 754 | my $param = {'kind' => '', 'data' => undef, 'path' => $argv1}; | |||||||||||||||||||||||||||||||
| 27 | 754 | my $xbyte = $Sisimai::Eb::XeBYTE * 32; # 64MB * 32 = 2GB | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | # The argumenet is a mailbox or a Maildir/. | ||||||||||||||||||||||||||||||||
| 30 | 754 | ▶ | if( -f $argv1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 31 | # The argument is a file, it is an mbox or email file in Maildir/ | ||||||||||||||||||||||||||||||||
| 32 | 743 | ▶ | my $xb = -s $argv1; return undef if $xb > $xbyte; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 33 | 743 | $klass = __PACKAGE__.'::Mbox'; | |||||||||||||||||||||||||||||||
| 34 | 743 | $loads .= 'Mbox.pm'; | |||||||||||||||||||||||||||||||
| 35 | 743 | $param->{'kind'} = 'mailbox'; | |||||||||||||||||||||||||||||||
| 36 | 743 | $param->{'path'} = $argv1; | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | } elsif( -d $argv1 ) { | ||||||||||||||||||||||||||||||||
| 39 | # The agument is not a file, it is a Maildir/ | ||||||||||||||||||||||||||||||||
| 40 | 7 | $klass = __PACKAGE__.'::Maildir'; | |||||||||||||||||||||||||||||||
| 41 | 7 | $loads .= 'Maildir.pm'; | |||||||||||||||||||||||||||||||
| 42 | 7 | $param->{'kind'} = 'maildir'; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | } else { | ||||||||||||||||||||||||||||||||
| 45 | # The argumen1 neither a mailbox nor a Maildir/. | ||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | if( ref($argv1) eq 'GLOB' || $argv1 eq 'STDIN' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
ref $argv1 eq "GLOB" or $argv1 eq "STDIN"
MC/DC50%1/2
ref $argv1 eq "GLOB" or $argv1 eq "STDIN"
ref $argv1 eq "GLOB"
$argv1 eq "STDIN"
Truth table66%2/3
A or B
A= ref $argv1 eq "GLOB"B= $argv1 eq "STDIN"
| |||||||||||||||||||||||||||||||||
| 47 | # Read from STDIN | ||||||||||||||||||||||||||||||||
| 48 | 1 | $klass = __PACKAGE__.'::STDIN'; | |||||||||||||||||||||||||||||||
| 49 | 1 | $loads .= 'STDIN.pm'; | |||||||||||||||||||||||||||||||
| 50 | 1 | $param->{'kind'} = 'stdin'; | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | } elsif( ref($argv1) eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||
| 53 | # Read from a variable as a scalar reference | ||||||||||||||||||||||||||||||||
| 54 | 3 | $klass = __PACKAGE__.'::Memory'; | |||||||||||||||||||||||||||||||
| 55 | 3 | $loads .= 'Memory.pm'; | |||||||||||||||||||||||||||||||
| 56 | 3 | $param->{'kind'} = 'memory'; | |||||||||||||||||||||||||||||||
| 57 | 3 | $param->{'path'} = 'MEMORY'; | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | 754 | ▶ | return undef unless $klass; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 754 | require $loads; | |||||||||||||||||||||||||||||||
| 63 | 754 | $param->{'data'} = $klass->new($argv1); | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 754 | return bless($param, __PACKAGE__); | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | sub read { | ||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 69 | # Alias method of Sisimai::Mail::*->read() | ||||||||||||||||||||||||||||||||
| 70 | # @return [String] Contents of mbox/Maildir | ||||||||||||||||||||||||||||||||
| 71 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | return "" unless ref $self->{'data'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 1 | return $self->{'data'}->read; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 88 | 1; | |||||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||||||