| 1 | package Sisimai::Mail::Maildir; | ||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use IO::Dir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Sisimai::Eb; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Class::Accessor::Lite ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | 'new' => 0, | |||||||||||||||||||||||||||
| 10 | 'ro' => [ | ||||||||||||||||||||||||||||
| 11 | 'dir', # [String] Path to Maildir/ | ||||||||||||||||||||||||||||
| 12 | ], | ||||||||||||||||||||||||||||
| 13 | 'rw' => [ | ||||||||||||||||||||||||||||
| 14 | 'path', # [String] Path to each file | ||||||||||||||||||||||||||||
| 15 | 'file', # [String] Each file name of a mail in the Maildir/ | ||||||||||||||||||||||||||||
| 16 | 'size', # [Integer] The number of email files in the Maildir/ | ||||||||||||||||||||||||||||
| 17 | 'offset', # [Integer] The number of email files which have been read | ||||||||||||||||||||||||||||
| 18 | 'handle', # [IO::Dir] Directory handle | ||||||||||||||||||||||||||||
| 19 | ] | ||||||||||||||||||||||||||||
| 20 | 7 | ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | # Constructor of Sisimai::Mail::Maildir | ||||||||||||||||||||||||||||
| 24 | # @param [String] argv1 Path to Maildir/ | ||||||||||||||||||||||||||||
| 25 | # @return [Sisimai::Mail::Maildir] Object | ||||||||||||||||||||||||||||
| 26 | # [Undef] is not a directory or does not exist | ||||||||||||||||||||||||||||
| 27 | 11 | my $class = shift; | |||||||||||||||||||||||||||
| 28 | 11 | ▶ | my $argv1 = shift // return undef; return undef unless -d $argv1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
shift() // (return undef)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 29 | 10 | my $files = 0; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 10 | eval { | |||||||||||||||||||||||||||
| 32 | # Count the number of files in the Maildir/ | ||||||||||||||||||||||||||||
| 33 | 10 | opendir MAILDIR, $argv1; | |||||||||||||||||||||||||||
| 34 | 10 | ▶ | while( my $e = readdir MAILDIR ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 3918 | ▶ | next unless -f sprintf("%s/%s", $argv1, $e); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 3898 | $files += 1; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 10 | closedir MAILDIR; | |||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 10 | my $param = { | |||||||||||||||||||||||||||
| 42 | 'dir' => $argv1, | ||||||||||||||||||||||||||||
| 43 | 'file' => undef, | ||||||||||||||||||||||||||||
| 44 | 'path' => undef, | ||||||||||||||||||||||||||||
| 45 | 'size' => $files, | ||||||||||||||||||||||||||||
| 46 | 'offset' => 0, | ||||||||||||||||||||||||||||
| 47 | 'handle' => IO::Dir->new($argv1), | ||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||
| 49 | 10 | return bless($param, __PACKAGE__); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3275 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=14 SCAR=27.0
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | # Maildir reader, works as an iterator. | ||||||||||||||||||||||||||||
| 54 | # @return [String] Contents of file in Maildir/ | ||||||||||||||||||||||||||||
| 55 | 3275 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 3275 | ▶ | return "" unless defined $self->{'dir'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 3275 | ▶ | return "" unless -d $self->{'dir'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 3275 | ▶ | return "" unless $self->{'offset'} < $self->{'size'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 3266 | my $seekhandle = $self->{'handle'}; | |||||||||||||||||||||||||||
| 61 | 3266 | my $readbuffer = ''; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 3266 | eval { | |||||||||||||||||||||||||||
| 64 | 3266 | ▶ | $seekhandle = IO::Dir->new($self->{'dir'}) unless $seekhandle; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 3266 | ▶ | while( my $r = $seekhandle->read ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | # Read each file in the directory | ||||||||||||||||||||||||||||
| 67 | 3284 | ▶ | next if( $r eq '.' || $r eq '..' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$r eq "." or $r eq ".."
MC/DC100%2/2
$r eq "." or $r eq ".."
$r eq "."
$r eq ".."
Truth table100%3/3
A or B
A= $r eq "."B= $r eq ".."
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 3266 | my $emailindir = $self->{'dir'}.'/'.$r; $emailindir =~ y{/}{}s; | |||||||||||||||||||||||||||
| 70 | 3266 | ▶ | my $emailbytes = -s $emailindir // 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
-s $emailindir // 0
MC/DC0%0/1
-s $emailindir // 0
-s $emailindir
Truth table50%1/2
A
A= -s $emailindir
| |||||||||||||||||||||||||||||
| 71 | 3266 | $self->{'offset'} += 1; | |||||||||||||||||||||||||||
| 72 | 3266 | ▶ | next unless -f $emailindir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 3266 | ▶ | next unless -r $emailindir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 3266 | ▶ | next unless $emailbytes; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 3266 | ▶ | next unless $emailbytes < $Sisimai::Eb::XeBYTE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 3266 | $self->{'path'} = $emailindir; | |||||||||||||||||||||||||||
| 78 | 3266 | $self->{'file'} = $r; | |||||||||||||||||||||||||||
| 79 | 3266 | my $filehandle = IO::File->new($emailindir, 'r'); | |||||||||||||||||||||||||||
| 80 | 3266 | $readbuffer = do { local $/; <$filehandle> }; | |||||||||||||||||||||||||||
| 81 | 3266 | $filehandle->close; | |||||||||||||||||||||||||||
| 82 | 3266 | last; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 3266 | ▶ | $seekhandle->close unless $self->{'offset'} < $self->{'size'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||
| 86 | 3266 | return $readbuffer; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 7 | 1; | |||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||