Skip to content

Commit

Permalink
Merge pull request #522 from sisimai/increase-the-coverage-7e85
Browse files Browse the repository at this point in the history
Increase the coverage 7e85
  • Loading branch information
azumakuniyuki authored May 26, 2024
2 parents 9ce5960 + 38d4ded commit ec9885c
Show file tree
Hide file tree
Showing 33 changed files with 201 additions and 50 deletions.
2 changes: 0 additions & 2 deletions lib/Sisimai/DateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ sub monthname {
my $class = shift;
my $argv1 = shift // 0;
my $value = $argv1 ? 'full' : 'abbr';

return MonthName->{ $value }->@* if wantarray;
return MonthName->{ $value };
}

Expand Down
4 changes: 0 additions & 4 deletions lib/Sisimai/MDA.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ sub inquire {
my $class = shift;
my $mhead = shift // return undef;
my $mbody = shift // return undef;

return undef unless defined $mhead;
return undef unless length $$mbody;

my $mfrom = lc $mhead->{'from'};
my $match = 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/Sisimai/Reason.pm
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ sub match {
}
return $reasontext if $reasontext;

if( uc $issuedcode eq 'X-UNIX' ) {
if( CORE::index(uc $issuedcode, 'X-UNIX; ') > -1 ) {
# X-Unix; ...
$reasontext = 'mailererror';

Expand Down
1 change: 1 addition & 0 deletions lib/Sisimai/Reason/AuthFailure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sub true {
return 1 if $argvs->{'reason'} eq 'authfailure';
return 1 if (Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '') eq 'authfailure';
return 1 if __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
return 0;
}

1;
Expand Down
1 change: 1 addition & 0 deletions lib/Sisimai/Reason/BadReputation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sub true {

return 1 if $argvs->{'reason'} eq 'badreputation';
return 1 if __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
return 0;
}

1;
Expand Down
1 change: 1 addition & 0 deletions lib/Sisimai/Reason/Blocked.pm
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ sub true {
return 1 if $argvs->{'reason'} eq 'blocked';
return 1 if (Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '') eq 'blocked';
return 1 if __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
return 0;
}

1;
Expand Down
1 change: 1 addition & 0 deletions lib/Sisimai/Reason/RequirePTR.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sub true {
return 1 if $argvs->{'reason'} eq 'requireptr';
return 1 if (Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '') eq 'requireptr';
return 1 if __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
return 0;
}

1;
Expand Down
4 changes: 2 additions & 2 deletions lib/Sisimai/Rhost/Mimecast.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ sub get {
my $class = shift;
my $argvs = shift // return undef;

return undef unless length $argvs->{'diagnosticcode'};
return undef unless Sisimai::SMTP::Reply->test($argvs->{'replycode'});
return '' unless length $argvs->{'diagnosticcode'};
return '' unless Sisimai::SMTP::Reply->test($argvs->{'replycode'});

state $messagesof = {
# https://community.mimecast.com/s/article/Mimecast-SMTP-Error-Codes-842605754
Expand Down
7 changes: 4 additions & 3 deletions lib/Sisimai/SMTP/Reply.pm
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ sub test {

if( $first == 2 ) {
# 2yz
return 0 if $reply < 211;
return 0 if $reply > 252;
return 0 if $reply > 221 && $reply < 250;
return 1 if $reply == 235;
return 0 if $reply < 211;
return 0 if $reply > 252;
return 0 if $reply > 221 && $reply < 250;
return 1;
}

Expand Down
5 changes: 5 additions & 0 deletions t/001-sisimai.t
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ MAKETEST: {
ok length $reasonlist->{ $e }, '->reason->{'.$e.'} = '.$reasonlist->{ $e };
}
}

MATCH: {
is(Sisimai->match('550 5.1.1 User unknown'), 'userunknown');
is(Sisimai->match(''), undef);
}
}
done_testing;

28 changes: 20 additions & 8 deletions t/010-address.t
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ MAKETEST: {
NEW: {
# ->new()
$v = $p->new(shift @{ $p->find($e->{'v'}) });
is $v->new(''), undef;
is $v->new([]), undef;
is $v->new({'address' => ''}), undef;

if( $e->{'a'} =~ /\A(.+)[@]([^@]+)\z/ ){ $a->[0] = $1; $a->[1] = $2; }
if( $Package->is_mailerdaemon($e->{'v'}) ){ $a->[0] = $e->{'a'}; $a->[1] = ''; }

Expand Down Expand Up @@ -289,14 +293,17 @@ MAKETEST: {
$a = '[email protected]';
$v = $p->new({ 'address' => $a });
is $p->expand_verp($a), '[email protected]', sprintf("%s->expand_verp(%s) = %s", $p, $a, $v);
is $p->expand_verp(undef), undef;
is $v->verp, $a, sprintf("%s->new(v)->verp = %s", $p, $a);

}

ALIAS: {
$a = '[email protected]';
$v = $p->new({ 'address' => $a });

is $p->expand_alias($a), '[email protected]', sprintf("%s->expand_alias(%s) = %s", $p, $a, $v);
is $p->expand_alias(undef), undef;
is $v->alias, $a, sprintf("%s->new(v)->alias = %s", $p, $a);
}

Expand All @@ -310,21 +317,26 @@ MAKETEST: {
for my $e ( @$postmaster ) {
ok $p->is_mailerdaemon($e), sprintf("%s->is_mailerdaemon = %s", $p, $e);
}
is $p->is_mailerdaemon(undef), 0;
}

for my $e ( @$isnotemail ) {
$v = $p->s3s4($e); is $v, $e, sprintf("%s->s3s4(v) = %s", $p, $e);
$v = $p->new({ 'address' => $e }); is $v, undef, sprintf("%s->new(v) = undef", $p);
$v = $p->find($e); is $v, undef, sprintf("%s->find(v) = undef", $p);
$v = $p->is_emailaddress($e); is $v, 0, sprintf("%s->is_emailaddress = 0", $p);
IS_NOT_EMAIL: {
for my $e ( @$isnotemail ) {
$v = $p->s3s4($e); is $v, $e, sprintf("%s->s3s4(v) = %s", $p, $e);
$v = $p->new({ 'address' => $e }); is $v, undef, sprintf("%s->new(v) = undef", $p);
$v = $p->find($e); is $v, undef, sprintf("%s->find(v) = undef", $p);
$v = $p->is_emailaddress($e); is $v, 0, sprintf("%s->is_emailaddress = 0", $p);
}
is $p->is_emailaddress(('neko-nyaan' x 25).'@example.jp'), 0;
}

UNDISCLOSED: {
my $r = '[email protected]';
my $s = '[email protected]';
is $p->undisclosed(1), $r, sprintf("%s->undisclosed(r) = %s", $p, $r);
is $p->undisclosed(0), $s, sprintf("%s->undisclosed(s) = %s", $p, $s);
is $p->undisclosed(2), $r, sprintf("%s->undisclosed() = %s", $p, $r);
is $p->undisclosed(1), $r, sprintf("%s->undisclosed(1) = %s", $p, $r);
is $p->undisclosed(0), $s, sprintf("%s->undisclosed(0) = %s", $p, $s);
is $p->undisclosed(2), $r, sprintf("%s->undisclosed(2) = %s", $p, $r);
is $p->undisclosed(), $s, sprintf("%s->undisclosed( ) = %s", $p, $s);
}
}

Expand Down
12 changes: 11 additions & 1 deletion t/011-rfc2045.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ MAKETEST: {
is $Package->is_encoded(\$p2), 0, '->is_encoded = 0';
is $Package->is_encoded(\$b2), 1, '->is_encoded = 1';
is $Package->is_encoded(\$q3), 1, '->is_encoded = 1';
is $Package->is_encoded(''), undef;

for my $e ( $p1, $p2 ) {
$v0 = $Package->decodeH([$e]);
$v0 = Encode::encode_utf8 $v0 if utf8::is_utf8 $v0;
is $v0, $e, '->decodeH = '.$e;
}

is $Package->decodeH(''), '';
$v0 = $Package->decodeH([$b2]);
$v0 = Encode::encode_utf8 $v0 if utf8::is_utf8 $v0;
is $v0, $p2, '->decodeH = '.$p2;
Expand Down Expand Up @@ -70,6 +72,9 @@ MAKETEST: {
# Base64, Quoted-Printable
my $b6 = '44Gr44KD44O844KT';
my $p6 = 'にゃーん';

is $Package->decodeB(undef), undef;
is $Package->decodeQ(undef), undef;
is ${ $Package->decodeB(\$b6) }, $p6, '->decodeB = '.$p6;
is ${ $Package->decodeQ(\'=4e=65=6b=6f') }, 'Neko', '->decodeQ = Neko';
}
Expand Down Expand Up @@ -139,6 +144,8 @@ Reason: 550 [email protected]... No such user';
is scalar @$v2, 2;
is $v2->[0], 'text/plain; charset="utf-8"', '->haircut->[0] = text/plain; charset=utf-8';
is $v2->[1], 'quoted-printable', '->haircut->[1] = quoted-printable';

is $Package->haircut(undef), undef;
}

LEVELOUT: {
Expand Down Expand Up @@ -184,6 +191,8 @@ Arrival-Date: Tue, 23 Dec 2014 20:39:34 +0000
ok length $e->[0];
ok length $e->[2];
}
isa_ok $Package->levelout('', 'neko'), 'ARRAY';
isa_ok $Package->levelout('neko', ''), 'ARRAY';
}

MAKEFLAT: {
Expand Down Expand Up @@ -246,7 +255,8 @@ Received: ...
unlike $v9, qr/4AAQSkZJRgABAQEBLAEsAAD/m, '->makeflat() does not contain base64';
like $v9, qr/kijitora[@]/m, '->makeflat() contains message/delivery-status part';
like $v9, qr/Received:/m, '->makeflat() contains message/rfc822 part';
is $Package->makeflat(), undef;
is $Package->makeflat(undef, undef), undef;
is $Package->makeflat('neko', undef), undef;
}

IRREGULAR_CASE: {
Expand Down
13 changes: 13 additions & 0 deletions t/012-string.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ MAKETEST: {
is(Sisimai::String->token($s, $r), '', '->token = ""');
ok(Sisimai::String->token($s, $r, 0), '->token');

is(Sisimai::String->is_8bit(), undef, '->is_8bit = undef');
is(Sisimai::String->is_8bit(\$s), 0, '->is_8bit = 0');
is(Sisimai::String->is_8bit(\'日本語'), 1, '->is_8bit = 1');

Expand All @@ -35,13 +36,19 @@ MAKETEST: {
is(Sisimai::String->aligned(\$v, ['rfc822', ' <', '@', '>']), 1, '->aligned(rfc822, <, @, >)');
is(Sisimai::String->aligned(\$v, ['rfc822', '<<', ' ', '>']), 0, '->aligned(rfc822, <, @, >)');
is(Sisimai::String->aligned(\$v, ['rfc822']), 1, '->aligned(rfc822)');
is(Sisimai::String->aligned(undef, ['rfc822']), undef, '->aligned(undef)');
is(Sisimai::String->aligned(\'', ['rfc822']), undef, '->aligned("")');
is(Sisimai::String->aligned(\$v, undef), undef, '->aligned(undef)');
is(Sisimai::String->aligned(\$v, []), undef, '->aligned([])');

is(Sisimai::String->ipv4('host smtp.example.jp 127.0.0.4 SMTP error from remote mail server')->[0], '127.0.0.4', '->ipv4 returns 127.0.0.4');
is(Sisimai::String->ipv4('mx.example.jp (192.0.2.2) reason: 550 5.2.0 Mail rejete.')->[0], '192.0.2.2', '->ipv4 returns 192.0.2.2');
is(Sisimai::String->ipv4('Client host [192.0.2.49] blocked using cbl.abuseat.org (state 13).')->[0], '192.0.2.49', '->ipv4 returns 192.0.2.49');
is(Sisimai::String->ipv4('127.0.0.1')->[0], '127.0.0.1', '->ipv4 returns 127.0.0.1');
is(Sisimai::String->ipv4('365.31.7.1')->[0], undef, '->ipv4(365.31.7.1) returns undef');
is(Sisimai::String->ipv4('a.b.c.d')->[0], undef, '->ipv4(a.b.c.d) returns undef');
is(Sisimai::String->ipv4(''), undef, '->ipv4("") returns undef');
is(Sisimai::String->ipv4('3.14')->@*, []->@*, '->ipv4("3.15") returns []');

my $h = '
<html>
Expand Down Expand Up @@ -78,6 +85,12 @@ MAKETEST: {
ok length $$p;
like $$p, qr/<body>/, '->to_plain(<body>)';
like $$p, qr/Nyaan/, '->to_plain("<body>Nyaan</body>")';

$p = Sisimai::String->to_plain(undef);
is length $$p, 0;

$p = Sisimai::String->to_plain([]);
is length $$p, 0;
}

done_testing;
10 changes: 9 additions & 1 deletion t/013-datetime.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ MAKETEST: {
};

MONTH_NAME: {
my $month = undef;
my $month = $v->monthname();
isa_ok $month, 'ARRAY', $v.'->monthname()';
is $month->[0], 'Jan', $v.'->monthname()->[0]';
is $month->[6], 'Jul', $v.'->monthname()->[6]';

$month = $v->monthname(0);
isa_ok $month, 'ARRAY', $v.'->monthname(0)';
Expand Down Expand Up @@ -71,6 +74,7 @@ MAKETEST: {
'Sun, 29 May 2014 1:2 +0900',
'4/29/01 11:34:45 PM',
'2014-03-26 00-01-19',
'29-04-2017 22:22',
];

my $invaliddates = [
Expand Down Expand Up @@ -98,6 +102,9 @@ MAKETEST: {
my $text = $v->parse($e);
ok length($text || '') == 0, '->parse('.$e.') = '.($text || '');
}

my $e = $v->parse();
is $e, undef, '->parse() = undef';
}

ABBR2TZ: {
Expand All @@ -110,6 +117,7 @@ MAKETEST: {
is $v->abbr2tz('EDT'), '-0400', 'EDT = -0400';
is $v->abbr2tz('HST'), '-1000', 'HST = -1000';
is $v->abbr2tz('UT'), '-0000', 'UT = -0000';
is $v->abbr2tz(), undef, '"" = undef';
}

TIMEZONE_TO_SECOND: {
Expand Down
2 changes: 2 additions & 0 deletions t/021-mail-mbox.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ MAKETEST: {
}
is $mailbox->offset, -s $SampleEmail;
is $emindex, 37;

is $Package->new(undef), undef;
}
}

Expand Down
2 changes: 2 additions & 0 deletions t/022-mail-maildir.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ MAKETEST: {
$emindex++;
}
ok $emindex > 1;

is $Package->new(undef), undef;
}
}

Expand Down
11 changes: 11 additions & 0 deletions t/026-smtp-status.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ MAKETEST: {

is $Package->test(''), undef, '->test("") = undef';
is $Package->test('3.14'), 0, '->test("3.14") = 0';
is $Package->test('9.99'), 0, '->test("9.99") = 0';
is $Package->test('5.0.3.2'), 0, '->test("5.0.3.2") = 0';
is $Package->test('1.0.0'), 0, '->test("1.0.0") = 0';
is $Package->test('3.1.4'), 0, '->test("3.1.4") = 0';
is $Package->test('6.7.8'), 0, '->test("6.7.8") = 0';
is $Package->test('5.-1.0'), 0, '->test("5.-1.0") = 0';
is $Package->test('5.12.0'), 0, '->test("5.12.0") = 0';
is $Package->test('5.2.-2'), 0, '->test("5.2.-2") = 0';
is $Package->test('5.2.2220'), 0, '->test("5.2.2220") = 0';

is $Package->find(''), undef, '->find("") = undef';
for my $e ( @$smtperrors ) {
Expand All @@ -87,6 +96,8 @@ MAKETEST: {
is $Package->prefer('4.4.7', '4.2.2'), '4.2.2';
is $Package->prefer('5.7.8', '4.4.0', 550), '5.7.8';
is $Package->prefer('4.2.1', '5.7.0', 421), '4.2.1';
is $Package->prefer('5.7', '5.7.26', 421), '5.7.26';
is $Package->prefer('5.7.26', '5.7', 421), '5.7.26';
}

done_testing;
4 changes: 3 additions & 1 deletion t/027-smtp-reply.t
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ MAKETEST: {
like $v, qr/\A[2345][0-5][0-9]\z/, 'SMTP Reply Code = '.$v;
ok $Package->test($v), '->test('.$v.') returns 1';
}
is $Package->find('x-unix; Quota exceeded message delivery failed to'), '';

for my $e ( qw|101 192 270 386 499 567 640 727| ) {
for my $e ( 235, 354 ) { is $Package->test($e), 1 }
for my $e ( qw|101 192 210 230 240 270 365 386 499 567 640 727| ) {
is $Package->test($e), 0, '->test('.$e.') returns 0';
}
}
Expand Down
4 changes: 4 additions & 0 deletions t/028-smtp-error.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ MAKETEST: {
];
my $temperrors = [
'smtp; 450 4.0.0 Temporary failure',
'smtp; 554 4.4.7 Message expired: unable to deliver in 840 minutes.<421 4.4.2 Connection timed out>',
'SMTP; 450 4.7.1 Access denied. IP name lookup failed [192.0.2.222]',
'smtp; 451 4.7.650 The mail server [192.0.2.25] has been',
'4.4.1 (Persistent transient failure - routing/network: no answer from host)',
];
my $permerrors = [
'smtp;550 5.2.2 <[email protected]>... Mailbox Full',
Expand Down
1 change: 1 addition & 0 deletions t/029-smtp-transcript.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MAKETEST: {
my $transcript = Sisimai::SMTP::Transcript->rise(\$entiremesg, 'In:', 'Out:');
my $resmtpcomm = qr/(?:CONN|HELO|EHLO|AUTH|MAIL|RCPT|DATA|QUIT|RSET|X[A-Z]+)/;

is $Package->rise([]), undef;
isa_ok $transcript, 'ARRAY';
ok scalar @$transcript;

Expand Down
7 changes: 6 additions & 1 deletion t/030-smtp-command.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ MAKETEST: {
};

my $v = '';
is $Package->test(), undef, '->test() returns undef';
is $Package->test(''), undef, '->test("") returns undef';
is $Package->test('NEKO'), 0, '->test("NEKO") returns 0';
is $Package->find(''), undef, '->find("") returns undef';
is $Package->test('CONN'), 1, '->test("CONN") returns 1';

is $Package->find(), undef, '->find("") returns undef';
is $Package->find(''), undef, '->find() returns undef';
is $Package->find('NEKO'), undef, '->find("NEKO") returns undef';

for my $e ( keys %$smtperrors ) {
ok $Package->test($e);
Expand Down
Loading

0 comments on commit ec9885c

Please sign in to comment.