| 1 | package Sisimai; | ||||||||||||||||||||
| 2 | 11 | ▶ | use v5.26; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 11 | ▶ | use version; our $VERSION = version->declare('v5.8.0'); our $PATCHLV = 0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | sub version { return substr($VERSION->stringify, 1).($PATCHLV > 0 ? 'p'.$PATCHLV : '') } | ||||||||||||||||||
|
Subroutine
version: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 7 | 1 | ▶ | sub libname { 'Sisimai' } | ||||||||||||||||||
|
Subroutine
libname: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 115 | ▶ | sub rise { | ||||||||||||||||||
|
Subroutine
rise: called CC=15 SCAR=27.7
Pod
documented
| |||||||||||||||||||||
| 10 | # Wrapper method for decoding mailbox or Maildir/ | ||||||||||||||||||||
| 11 | # @param [String] argv0 Path to mbox or Maildir/ | ||||||||||||||||||||
| 12 | # @param [Hash] argv0 or Hash (decoded JSON) | ||||||||||||||||||||
| 13 | # @param [Handle] argv0 or STDIN | ||||||||||||||||||||
| 14 | # @param [Hash] argv1 Options for decoding | ||||||||||||||||||||
| 15 | # @options argv1 [Integer] delivered 1 = Including "delivered" reason | ||||||||||||||||||||
| 16 | # @options argv1 [Integer] vacation 1 = Including "vacation" reason | ||||||||||||||||||||
| 17 | # @options argv1 [Array] c___ Code references to a callback method for the message and each file | ||||||||||||||||||||
| 18 | # @return [Array] Decoded objects | ||||||||||||||||||||
| 19 | # @return [undef] undef if the argument was wrong or an empty array | ||||||||||||||||||||
| 20 | 115 | my $class = shift; | |||||||||||||||||||
| 21 | 115 | ▶ | my $argv0 = shift // return undef; die ' ***error: wrong number of arguments' if scalar @_ % 2; | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
shift() // (return undef)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||
| 22 | 113 | my $argv1 = { @_ }; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 113 | require Sisimai::Eb; | |||||||||||||||||||
| 25 | 113 | require Sisimai::Mail; | |||||||||||||||||||
| 26 | 113 | require Sisimai::Fact; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 113 | ▶ | my $mail = Sisimai::Mail->new($argv0) || return undef; | ||||||||||||||||||
|
Condition50%1/2
'Sisimai::Mail'->new($argv0) || (return undef)
MC/DC0%0/1
'Sisimai::Mail'->new($argv0) || (return undef)
'Sisimai::Mail'->new($argv0)
Truth table50%1/2
A
A= 'Sisimai::Mail'->new($argv0)
| |||||||||||||||||||||
| 29 | 113 | ▶ | my $c___ = ref $argv1->{'c___'} eq 'ARRAY' ? $argv1->{'c___'} : [undef, undef]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 113 | my $sisi = []; | |||||||||||||||||||
| 31 | 113 | my $maxb = $Sisimai::Eb::XeBYTE; # 64MB * 32 = 2GB | |||||||||||||||||||
| 32 | 113 | my $sumb = 0; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 113 | ▶ | while( my $r = $mail->data->read ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | # Read and decode each email file | ||||||||||||||||||||
| 36 | 2884 | ▶ | next if length($r) > $Sisimai::Eb::XeBYTE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2884 | ▶ | if( $mail->kind eq 'stdin' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | # Check and limit the max size of entire email data read from STDIN: 2GB | ||||||||||||||||||||
| 40 | 0 | $sumb += length $r; | |||||||||||||||||||
| 41 | 0 | ▶ | die ' ***warning: Input email is too large: '.$sumb.' bytes' if $sumb > $maxb; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 2884 | my $path = $mail->data->path; | |||||||||||||||||||
| 45 | my $args = { | ||||||||||||||||||||
| 46 | 'data' => $r, 'hook' => $c___->[0], 'origin' => $path, | ||||||||||||||||||||
| 47 | 2884 | 'delivered' => $argv1->{'delivered'}, 'vacation' => $argv1->{'vacation'} | |||||||||||||||||||
| 48 | }; | ||||||||||||||||||||
| 49 | 2884 | ▶ | my $fact = Sisimai::Fact->rise($args) || []; | ||||||||||||||||||
|
Condition100%2/2
'Sisimai::Fact'->rise($args) || []
MC/DC100%1/1
'Sisimai::Fact'->rise($args) || []
'Sisimai::Fact'->rise($args)
Truth table100%2/2
A
A= 'Sisimai::Fact'->rise($args)
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 2884 | ▶ | if( $c___->[1] ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | # Run the callback function specified with "c___" parameter of Sisimai->rise after reading | ||||||||||||||||||||
| 53 | # each email file in Maildir/ every time | ||||||||||||||||||||
| 54 | 670 | $args = {'kind' => $mail->kind, 'mail' => \$r, 'path' => $path, 'fact' => $fact}; | |||||||||||||||||||
| 55 | 670 | ▶ | eval { $c___->[1]->($args) if ref $c___->[1] eq 'CODE' }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 670 | ▶ | warn sprintf(" ***warning: Something is wrong in the second element of the 'c___': %s", $@) if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | 2884 | ▶ | push @$sisi, @$fact if scalar @$fact; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | 113 | ▶ | return undef unless scalar @$sisi; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 105 | return $sisi; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 8 | ▶ | sub dump { | ||||||||||||||||||
|
Subroutine
dump: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 65 | # Wrapper method to decode mailbox/Maildir and dump as JSON | ||||||||||||||||||||
| 66 | # @param [String] argv0 Path to mbox or Maildir/ | ||||||||||||||||||||
| 67 | # @param [Hash] argv0 or Hash (decoded JSON) | ||||||||||||||||||||
| 68 | # @param [Handle] argv0 or STDIN | ||||||||||||||||||||
| 69 | # @param [Hash] argv1 Options for decoding | ||||||||||||||||||||
| 70 | # @options argv1 [Integer] delivered 1 = Including "delivered" reason | ||||||||||||||||||||
| 71 | # @options argv1 [Integer] vacation 1 = Including "vacation" reason | ||||||||||||||||||||
| 72 | # @options argv1 [Code] hook Code reference to a callback method | ||||||||||||||||||||
| 73 | # @return [String] Decoded data as JSON text | ||||||||||||||||||||
| 74 | 8 | my $class = shift; | |||||||||||||||||||
| 75 | 8 | ▶ | my $argv0 = shift // return undef; die ' ***error: wrong number of arguments' if scalar @_ % 2; | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
shift() // (return undef)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||
| 76 | 6 | my $argv1 = { @_ }; | |||||||||||||||||||
| 77 | 6 | ▶ | my $nyaan = __PACKAGE__->rise($argv0, %$argv1) // []; | ||||||||||||||||||
|
Condition100%2/2
__PACKAGE__->rise($argv0, %$argv1) // []
MC/DC100%1/1
__PACKAGE__->rise($argv0, %$argv1) // []
__PACKAGE__->rise($argv0, %$argv1)
Truth table100%2/2
A
A= __PACKAGE__->rise($argv0, %$argv1)
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 6 | for my $e ( @$nyaan ) { | |||||||||||||||||||
| 80 | # Set UTF8 flag before converting to JSON string | ||||||||||||||||||||
| 81 | 693 | utf8::decode $e->{'subject'}; | |||||||||||||||||||
| 82 | 693 | utf8::decode $e->{'diagnosticcode'}; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 6 | require Module::Load; | |||||||||||||||||||
| 86 | 6 | Module::Load::load('JSON', '-convert_blessed_universally'); | |||||||||||||||||||
| 87 | 6 | my $jsonparser = JSON->new->allow_blessed->convert_blessed->utf8; | |||||||||||||||||||
| 88 | 6 | my $jsonstring = $jsonparser->encode($nyaan); | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 6 | ▶ | utf8::encode $jsonstring if utf8::is_utf8 $jsonstring; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 6 | return $jsonstring; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 1 | ▶ | sub engine { | ||||||||||||||||||
|
Subroutine
engine: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 95 | # Decoding engine list (MTA modules) | ||||||||||||||||||||
| 96 | # @return [Hash] Decoding engine table | ||||||||||||||||||||
| 97 | 1 | my $class = shift; | |||||||||||||||||||
| 98 | 1 | my $table = {}; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 1 | for my $e ('Lhost', 'ARF', 'RFC3464', 'RFC3834') { | |||||||||||||||||||
| 101 | 4 | my $r = 'Sisimai::'.$e; | |||||||||||||||||||
| 102 | 4 | (my $loads = $r) =~ s|::|/|g; | |||||||||||||||||||
| 103 | 4 | require $loads.'.pm'; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 4 | ▶ | if( $e eq 'Lhost' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | # Sisimai::Lhost::* | ||||||||||||||||||||
| 107 | 1 | for my $ee ( $r->index->@* ) { | |||||||||||||||||||
| 108 | # Load and get the value of "description" from each module | ||||||||||||||||||||
| 109 | 38 | my $rr = 'Sisimai::'.$e.'::'.$ee; | |||||||||||||||||||
| 110 | 38 | ($loads = $rr) =~ s|::|/|g; | |||||||||||||||||||
| 111 | 38 | require $loads.'.pm'; | |||||||||||||||||||
| 112 | 38 | $table->{ $rr } = $rr->description; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||
| 115 | # Sisimai::ARF, Sisimai::RFC3464, and Sisimai::RFC3834 | ||||||||||||||||||||
| 116 | 3 | $table->{ $r } = $r->description; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | 1 | return $table; | |||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 2 | ▶ | sub reason { | ||||||||||||||||||
|
Subroutine
reason: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 123 | # Reason list Sisimai can detect | ||||||||||||||||||||
| 124 | # @return [Hash] Reason list table | ||||||||||||||||||||
| 125 | 2 | my $class = shift; | |||||||||||||||||||
| 126 | 2 | my $table = {}; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | # These reasons are not included in the results of Sisimai::Reason->index | ||||||||||||||||||||
| 129 | 2 | require Sisimai::Reason; | |||||||||||||||||||
| 130 | 2 | my @names = ($Sisimai::Eb::ReSENT, $Sisimai::Eb::ReFEED, $Sisimai::Eb::Re___0, $Sisimai::Eb::ReAWAY); | |||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 2 | for my $e ( Sisimai::Reason->index->@*, @names) { | |||||||||||||||||||
| 133 | # Call ->description() method of Sisimai::Reason::* | ||||||||||||||||||||
| 134 | 74 | my $r = 'Sisimai::Reason::'.$e; | |||||||||||||||||||
| 135 | 74 | (my $loads = $r) =~ s|::|/|g; | |||||||||||||||||||
| 136 | 74 | require $loads.'.pm'; | |||||||||||||||||||
| 137 | 74 | $table->{ $e } = $r->description; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | 2 | return $table; | |||||||||||||||||||
| 140 | } | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 95 | ▶ | sub match { | ||||||||||||||||||
|
Subroutine
match: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 143 | # Try to match with message patterns | ||||||||||||||||||||
| 144 | # @param [String] Error message text | ||||||||||||||||||||
| 145 | # @return [String] Reason text | ||||||||||||||||||||
| 146 | 95 | my $class = shift; | |||||||||||||||||||
| 147 | 95 | ▶ | my $argvs = shift || return ""; | ||||||||||||||||||
|
Condition100%2/2
shift() || (return '')
MC/DC100%1/1
shift() || (return '')
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 94 | require Sisimai::Reason; | |||||||||||||||||||
| 150 | 94 | return Sisimai::Reason->match(lc $argvs); | |||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 11 | 1; | |||||||||||||||||||
| 154 | __END__ | ||||||||||||||||||||