| 1 | package Sisimai::RFC5322; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 93 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 93 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 93 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 93 | ▶ | use Sisimai::RFC791; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 93 | ▶ | use Sisimai::Address; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 93 | ▶ | use constant HEADERTABLE => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 'messageid' => ['message-id'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 'subject' => ['subject'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 'listid' => ['list-id'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 'date' => [qw|date posted-date posted resent-date|], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 'addresser' => [qw|from return-path reply-to errors-to reverse-path x-postfix-sender envelope-from x-envelope-from|], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 'recipient' => [qw|to delivered-to forward-path envelope-to x-envelope-to resent-to apparently-to|], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 93 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 93 | ▶ | use constant FIELDINDEX => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # The following fields are not referred in Sisimai | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # Resent-From Resent-Sender Resent-Cc Cc Bcc Resent-Bcc In-Reply-To References | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Comments Keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | qw|Resent-Date From Sender Reply-To To Message-ID Subject Return-Path Received Date X-Mailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | Content-Type Content-Transfer-Encoding Content-Description Content-Disposition| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 93 | ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # The part of "Received:" headers generated by qmail or qmail-clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # - Received: (qmail 2202 invoked from network); 15 Oct 2015 06:22:22 -0000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # - Received: (qmail 2220 invoked by uid 2); 17 Jul 2014 08:30:40 -0000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Do not exclude the following strings: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # - Received: (qmail 2204 invoked for bounce); 29 Apr 2010 00:00:00 -000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 93 | ▶ | use constant woReceived => [" invoked by uid", " invoked from network"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | sub HEADERFIELDS { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
HEADERFIELDS: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Grouped RFC822 headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # @param [String] group RFC822 Header group name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # @return [Array] RFC822 Header list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | my $group = shift || return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || (return [])
MC/DC0%0/1
shift() || (return [])
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | return HEADERTABLE->{ $group } if exists HEADERTABLE->{ $group }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | return []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 4530 | ▶ | sub received { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
received: called CC=48 SCAR=38.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Convert Received headers to a structured data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # @param [String] argv1 Received header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # @return [Array] Each item in the Received header order by the following: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # 0: (from) "hostname" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # 1: (by) "hostname" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # 2: (via) "protocol/tcp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # 3: (with) "protocol/smtp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # 4: (id) "queue-id" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # 5: (for) "envelope-to address" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 4530 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 4530 | ▶ | my $argv1 = shift || return []; return [] if ref $argv1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
shift() || (return [])
MC/DC100%1/1
shift() || (return [])
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4523 | ▶ | return [] if index($argv1, woReceived->[0]) > 0 || index($argv1, woReceived->[1]) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
index($argv1, [" invoked by uid"," invoked from network"]->[0]) > 0 or index($argv1, [" invoked by uid"," invoked from network"]->[1]) > 0
MC/DC100%2/2
index($argv1, [" invoked by uid"," invoked from network"]->[0]) > 0 or index($argv1, [" invoked by uid"," invoked from network"]->[1]) > 0
index($argv1, [" invoked by uid"," invoked from network"]->[0]) > 0
index($argv1, [" invoked by uid"," invoked from network"]->[1]) > 0
Truth table100%3/3
A or B
A= index($argv1, [" invoked by uid"," invoked from network"]->[0]) > 0B= index($argv1, [" invoked by uid"," invoked from network"]->[1]) > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # - https://datatracker.ietf.org/doc/html/rfc5322 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # received = "Received:" *received-token ";" date-time CRLF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # received-token = word / angle-addr / addr-spec / domain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # - Appendix A.4. Message with Trace Fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Received: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # from x.y.test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # by example.net | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # via TCP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # with ESMTP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # id ABC12345 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # for <mary@example.net>; 21 Nov 1997 10:05:43 -0600 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4521 | my $recvd = [split(' ', $argv1)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4521 | my $label = [qw|from by via with id for|]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4521 | my $token = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4521 | my $other = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4521 | my $alter = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 4521 | my $right = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 4521 | my $range = scalar @$recvd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 4521 | my $index = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 4521 | for my $e ( @$recvd ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # Look up each label defined in $label from Received header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 80138 | ▶ | last unless ++$index < $range; my $f = lc $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 80138 | ▶ | next unless grep { $f eq $_ } @$label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 18762 | ▶ | $token->{ $f } = $recvd->[$index + 1] || next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$recvd[$index + 1] || (next)
MC/DC100%1/1
$$recvd[$index + 1] || (next)
$$recvd[$index + 1]
Truth table100%2/2
A
A= $$recvd[$index + 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 18751 | $token->{ $f } = lc $token->{ $f }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 18751 | $token->{ $f } =~ y/();//d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 18751 | ▶ | next unless $f eq 'from'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3788 | ▶ | last unless $index + 2 < $range; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 3783 | ▶ | next unless index($recvd->[$index + 2], '(') == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Get and keep a hostname in the comment as follows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # from mx1.example.com (c213502.kyoto.example.ne.jp [192.0.2.135]) by mx.example.jp (V8/cf) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # "from", # index + 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # "mx1.example.com", # index + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # "(c213502.kyoto.example.ne.jp", # index + 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # "[192.0.2.135])", # index + 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # "by", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # "mx.example.jp", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # "(V8/cf)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # The 2nd element after the current element is NOT a continuation of the current element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # such as "(c213502.kyoto.example.ne.jp)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 3196 | push @$other, $recvd->[$index + 2]; $other->[0] =~ y/();//d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # The 2nd element after the current element is a continuation of the current element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # such as "(c213502.kyoto.example.ne.jp", "[192.0.2.135])" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3196 | ▶ | last unless $index + 3 < $range; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3196 | push @$other, $recvd->[$index + 3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3196 | $other->[1] =~ y/();//d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4521 | for my $e ( @$other ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # Check alternatives in $other, and then delete uninformative values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 6392 | ▶ | next if length $e < 4 || $e eq 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $e < 4 or $e eq "unknown"
MC/DC100%2/2
length $e < 4 or $e eq "unknown"
length $e < 4
$e eq "unknown"
Truth table100%3/3
A or B
A= length $e < 4B= $e eq "unknown"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 5409 | ▶ | next if $e eq 'localhost' || $e eq '[127.0.0.1]' || $e eq '[IPv6:::1]'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$e eq "localhost" or $e eq "[127.0.0.1]" or $e eq "[IPv6:::1]"
$e eq "localhost" or $e eq "[127.0.0.1]"
MC/DC100%3/3
$e eq "localhost" or $e eq "[127.0.0.1]" or $e eq "[IPv6:::1]"
$e eq "localhost"
$e eq "[127.0.0.1]"
$e eq "[IPv6:::1]"
Truth table100%4/4
A or B or C
A= $e eq "localhost"B= $e eq "[127.0.0.1]"C= $e eq "[IPv6:::1]"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 4547 | ▶ | next if index($e, '.') == -1 || index($e, '=') > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
index($e, ".") == -1 or index($e, "=") > 1
MC/DC100%2/2
index($e, ".") == -1 or index($e, "=") > 1
index($e, ".") == -1
index($e, "=") > 1
Truth table100%3/3
A or B
A= index($e, ".") == -1B= index($e, "=") > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3969 | push @$alter, $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 4521 | for my $e ('from', 'by') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Remove square brackets from the IP address such as "[192.0.2.25]" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 9042 | ▶ | next unless defined $token->{ $e }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 8163 | ▶ | next unless length $token->{ $e }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 8163 | ▶ | next unless index($token->{ $e }, '[') == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 235 | ▶ | $token->{ $e } = shift Sisimai::RFC791->find($token->{ $e })->@* || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift @{'Sisimai::RFC791'->find($token->{$e})} || ''
MC/DC100%1/1
shift @{'Sisimai::RFC791'->find($token->{$e})} || ''
shift @{'Sisimai::RFC791'->find($token->{$e})}
Truth table100%2/2
A
A= shift @{'Sisimai::RFC791'->find($token->{$e})}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4521 | ▶ | $token->{'from'} ||= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$token->{"from"} ||= ""
MC/DC100%1/1
$token->{"from"} ||= ""
$token->{"from"}
Truth table100%2/2
A
A= $token->{"from"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 4521 | while(1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Prefer hostnames over IP addresses, except for localhost.localdomain and similar. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 4521 | ▶ | last if $token->{'from'} eq 'localhost' || $token->{'from'} eq 'localhost.localdomain'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$token->{"from"} eq "localhost" or $token->{"from"} eq "localhost.localdomain"
MC/DC100%2/2
$token->{"from"} eq "localhost" or $token->{"from"} eq "localhost.localdomain"
$token->{"from"} eq "localhost"
$token->{"from"} eq "localhost.localdomain"
Truth table100%3/3
A or B
A= $token->{"from"} eq "localhost"B= $token->{"from"} eq "localhost.localdomain"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 4134 | ▶ | last if index($token->{'from'}, '.') < 0; # A hostname without a domain name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2948 | ▶ | last if scalar Sisimai::RFC791->find($token->{'from'})->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # No need to rewrite $token->{'from'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2533 | $right = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2533 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 4521 | while(1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Try to rewrite uninformative hostnames and IP addresses in $token->{'from'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4521 | ▶ | last if $right; # There is no need to rewrite | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1988 | ▶ | last if scalar @$alter == 0; # There is no alternative to rewriting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 584 | ▶ | last if index($alter->[0], $token->{'from'}) > -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 358 | ▶ | if( index($token->{'from'}, 'localhost') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # localhost or localhost.localdomain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 25 | $token->{'from'} = $alter->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } elsif( index($token->{'from'}, '.') == -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # A hostname without a domain name such as "mail", "mx", or "mbox" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 80 | ▶ | $token->{'from'} = $alter->[0] if index($alter->[0], '.') > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # An IPv4 address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 253 | $token->{'from'} = $alter->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 358 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 4521 | ▶ | delete $token->{'by'} unless defined $token->{'by'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 4521 | ▶ | delete $token->{'from'} unless defined $token->{'from'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4521 | ▶ | $token->{'for'} = Sisimai::Address->s3s4($token->{'for'}) if exists $token->{'for'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4521 | for my $e ( keys %$token ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # Delete an invalid value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 19414 | ▶ | $token->{ $e } = '' if index($token->{ $e }, ' ') > -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 19414 | $token->{ $e } =~ y/[]//d; # Remove "[]" from the IP address | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | $token->{'from'} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | $token->{'by'} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | $token->{'via'} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | $token->{'with'} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | $token->{'id'} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 4521 | ▶ | $token->{'for'} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%12/12
$token->{'from'} || ''
$token->{'by'} || ''
$token->{'via'} || ''
$token->{'with'} || ''
$token->{'id'} || ''
$token->{'for'} || ''
MC/DC100%1/1
$token->{'from'} || ''
$token->{'from'}
MC/DC100%1/1
$token->{'by'} || ''
$token->{'by'}
MC/DC100%1/1
$token->{'via'} || ''
$token->{'via'}
MC/DC100%1/1
$token->{'with'} || ''
$token->{'with'}
MC/DC100%1/1
$token->{'id'} || ''
$token->{'id'}
MC/DC100%1/1
$token->{'for'} || ''
$token->{'for'}
Truth table100%2/2
A
A= $token->{'from'}
Truth table100%2/2
A
A= $token->{'by'}
Truth table100%2/2
A
A= $token->{'via'}
Truth table100%2/2
A
A= $token->{'with'}
Truth table100%2/2
A
A= $token->{'id'}
Truth table100%2/2
A
A= $token->{'for'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 4480 | ▶ | sub part { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
part: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Split given entire message body into error message lines and the original message part only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # include email headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # @param [String] email Entire message body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # @param [Array] cutby List of strings which is a boundary of the original message part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # @param [Bool] keeps Flag for keeping strings after "\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # @return [Array] [Error message lines, The original message] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # @since v5.0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 4480 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 4480 | ▶ | my $email = shift || return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || (return undef)
MC/DC100%1/1
shift() || (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 4479 | ▶ | my $cutby = shift || return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || (return undef)
MC/DC100%1/1
shift() || (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 4478 | ▶ | my $keeps = shift // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // 0
MC/DC100%1/1
shift() // 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 4478 | my $boundaryor = ''; # A boundary string divides the error message part and the original message part | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 4478 | my $positionor = -1; # A Position of the boundary string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 4478 | my $formerpart = ''; # The error message part | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4478 | my $latterpart = ''; # The original message part | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 4478 | for my $e ( @$cutby ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # Find a boundary string(2nd argument) from the 1st argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 6403 | ▶ | $positionor = index($$email, $e); next if $positionor == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3462 | $boundaryor = $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 3462 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 4478 | ▶ | if( $positionor > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # There is the boundary string in the message body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 3417 | $formerpart = substr($$email, 0, $positionor); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 3417 | ▶ | $latterpart = substr($$email, ($positionor + length($boundaryor) + 1), ) || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
substr($$email, $positionor + length($boundaryor) + 1) || ''
MC/DC0%0/1
substr($$email, $positionor + length($boundaryor) + 1) || ''
substr($$email, $positionor + length($boundaryor) + 1)
Truth table50%1/2
A
A= substr($$email, $positionor + length($boundaryor) + 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # Substitute the entire message to the former part when the boundary string is not included | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # the $$email | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1061 | $formerpart = $$email; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 4478 | ▶ | if( length $latterpart > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # Remove blank lines, the message body of the original message, and append "\n" at the end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # of the original message headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # 1. Remove leading blank lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # 2. Remove text after the first blank line: \n\n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # 3. Append "\n" at the end of test block when the last character is not "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3417 | $latterpart =~ s/\A[\r\n\s]+//m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3417 | ▶ | if( $keeps == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Remove text after the first blank line: \n\n when $keeps is 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 3397 | ▶ | substr($latterpart, index($latterpart, "\n\n") + 1, length($latterpart), '') if index($latterpart, "\n\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 3417 | ▶ | $latterpart .= "\n" unless substr($latterpart, -1, 1) eq "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 4478 | return [$formerpart, $latterpart]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 93 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||