File Coverage

lib/Sisimai/Lhost/Biglobe.pm
Criterion Covered Total %
statement 42 44 95.4
branch 18 22 81.8
condition 8 10 80.0
subroutine 6 6 100.0
pod 2 2 100.0
total 76 84 90.4


line stmt bran cond sub pod time code
1             package Sisimai::Lhost::Biglobe;
2 36     36   3464 use parent 'Sisimai::Lhost';
  36         67  
  36         193  
3 36     36   2353 use v5.26;
  36         104  
4 36     36   143 use strict;
  36         61  
  36         756  
5 36     36   133 use warnings;
  36         54  
  36         17037  
6              
7 1     1 1 3 sub description { 'BIGLOBE: https://www.biglobe.ne.jp' }
8             sub inquire {
9             # Detect an error from Biglobe
10             # @param [Hash] mhead Message headers of a bounce email
11             # @param [String] mbody Message body of a bounce email
12             # @return [Hash] Bounce data list and message/rfc822 part
13             # @return [undef] failed to decode or the arguments are missing
14             # @since v4.0.0
15 912     912 1 2433 my $class = shift;
16 912   100     1976 my $mhead = shift // return undef;
17 911   100     1547 my $mbody = shift // return undef;
18              
19 910 100       3244 return undef unless index($mhead->{'from'}, 'postmaster@') > -1;
20 199 100       345 return undef unless grep { index($mhead->{'from'}, '@'.$_.'.ne.jp') > -1 } (qw|biglobe inacatv tmtv ttv|);
  796         1488  
21 6 50       20 return undef unless index($mhead->{'subject'}, 'Returned mail:') == 0;
22              
23 6         22 state $indicators = __PACKAGE__->INDICATORS;
24 6         12 state $boundaries = ['Content-Type: message/rfc822'];
25 6         16 state $startingof = {
26             'message' => [' ----- The following addresses had delivery problems -----'],
27             'error' => [' ----- Non-delivered information -----'],
28             };
29 6         27 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
  6         9  
30 6         26 my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries);
31 6         9 my $readcursor = 0; # (Integer) Points the current cursor position
32 6         8 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
33              
34 6         24 for my $e ( split("\n", $emailparts->[0]) ) {
35             # Read error messages and delivery status lines from the head of the email to the previous
36             # line of the beginning of the original message.
37 42 100       51 unless( $readcursor ) {
38             # Beginning of the bounce message or message/delivery-status part
39 18 100       55 $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0;
40 18         17 next;
41             }
42 24 100 66     63 next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
43              
44             # This is a MIME-encapsulated message.
45             #
46             # ----_Biglobe000000/00000.biglobe.ne.jp
47             # Content-Type: text/plain; charset="iso-2022-jp"
48             #
49             # ----- The following addresses had delivery problems -----
50             # ********@***.biglobe.ne.jp
51             #
52             # ----- Non-delivered information -----
53             # The number of messages in recipient's mailbox exceeded the local limit.
54             #
55             # ----_Biglobe000000/00000.biglobe.ne.jp
56             # Content-Type: message/rfc822
57             #
58 18         20 $v = $dscontents->[-1];
59              
60 18 100 66     43 if( index($e, '@') > 1 && index($e, ' ') == -1 ) {
61             # ----- The following addresses had delivery problems -----
62             # ********@***.biglobe.ne.jp
63 6 50       15 if( $v->{'recipient'} ) {
64             # There are multiple recipient addresses in the message body.
65 0         0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
66 0         0 $v = $dscontents->[-1];
67             }
68 6 50       31 next unless Sisimai::Address->is_emailaddress($e);
69 6         14 $v->{'recipient'} = $e;
70 6         9 $recipients++;
71              
72             } else {
73 12 100       21 next if index($e, '--') > -1;
74 6         21 $v->{'diagnosis'} .= $e.' ';
75             }
76             }
77 6 50       18 return undef unless $recipients;
78 6         25 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
79             }
80              
81             1;
82             __END__