File Coverage

lib/Sisimai/Lhost/GoogleGroups.pm
Criterion Covered Total %
statement 44 46 95.6
branch 11 16 68.7
condition 4 6 66.6
subroutine 6 6 100.0
pod 2 2 100.0
total 67 76 88.1


line stmt bran cond sub pod time code
1             package Sisimai::Lhost::GoogleGroups;
2 22     22   6075 use parent 'Sisimai::Lhost';
  22         44  
  22         124  
3 22     22   1343 use feature ':5.10';
  22         40  
  22         1536  
4 22     22   120 use strict;
  22         40  
  22         537  
5 22     22   113 use warnings;
  22         55  
  22         12721  
6              
7 2     2 1 1165 sub description { 'Google Groups: https://groups.google.com' }
8             sub make {
9             # Detect an error from Google Groups
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 parse or the arguments are missing
14             # @since v4.25.6
15 567     567 1 1356 my $class = shift;
16 567   100     1364 my $mhead = shift // return undef;
17 566   50     1425 my $mbody = shift // return undef;
18              
19 566 100       1739 return undef unless rindex($mhead->{'from'}, '') > -1;
20 148 50       647 return undef unless index($mhead->{'subject'}, 'Delivery Status Notification') > -1;
21 148 100       396 return undef unless exists $mhead->{'x-failed-recipients'};
22 128 100       360 return undef unless exists $mhead->{'x-google-smtp-source'};
23              
24             # Hello kijitora@libsisimai.org,
25             #
26             # We're writing to let you know that the group you tried to contact (group-name)
27             # may not exist, or you may not have permission to post messages to the group.
28             # A few more details on why you weren't able to post:
29             #
30             # * You might have spelled or formatted the group name incorrectly.
31             # * The owner of the group may have removed this group.
32             # * You may need to join the group before receiving permission to post.
33             # * This group may not be open to posting.
34             #
35             # If you have questions related to this or any other Google Group,
36             # visit the Help Center at https://groups.google.com/support/.
37             #
38             # Thanks,
39             #
40             # Google Groups
41 72         132 state $indicators = __PACKAGE__->INDICATORS;
42 72         122 state $rebackbone = qr/^-----[ ]Original[ ]message[ ]-----$/m;
43              
44 72         210 my $dscontents = [__PACKAGE__->DELIVERYSTATUS];
45 72         673 my $emailsteak = Sisimai::RFC5322->fillet($mbody, $rebackbone);
46 72         686 my $recordwide = { 'rhost' => '', 'reason' => '', 'diagnosis' => '' };
47 72         204 my $recipients = 0;
48 72         157 my $v = $dscontents->[-1];
49              
50             # * You might have spelled or formatted the group name incorrectly.
51             # * The owner of the group may have removed this group.
52             # * You may need to join the group before receiving permission to post.
53             # * This group may not be open to posting.
54 72   50     753 my $fewdetails = [$emailsteak->[0] =~ /^[ ]?[*][ ]?/gm] || [];
55 72 50       315 $recordwide->{'reason'} = scalar @$fewdetails == 4 ? 'rejected' : 'onhold';
56              
57 72         459 my @entiremesg = split(/\n\n/, $emailsteak->[0], 5); pop @entiremesg;
  72         158  
58 72         393 my $diagnostic = join(' ', @entiremesg); $diagnostic =~ y/\n/ /;
  72         223  
59 72         414 $recordwide->{'diagnosis'} = Sisimai::String->sweep($diagnostic);
60              
61 72         433 my $serverlist = Sisimai::RFC5322->received($mhead->{'received'}->[0]);
62 72         348 $recordwide->{'rhost'} = shift @$serverlist;
63              
64 72         366 for my $e ( split(',', $mhead->{'x-failed-recipients'}) ) {
65             # X-Failed-Recipients: neko@example.jp, nyaan@example.org, ...
66 72 50       251 next unless Sisimai::RFC5322->is_emailaddress($e);
67              
68 72 50       380 if( $v->{'recipient'} ) {
69             # There are multiple recipient addresses in the message body.
70 0         0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
71 0         0 $v = $dscontents->[-1];
72             }
73 72         365 $v->{'recipient'} = Sisimai::Address->s3s4($e);
74 72         270 $recipients++;
75 72         498 $v->{ $_ } = $recordwide->{ $_ } for keys %$recordwide;
76             }
77 72 50       183 return undef unless $recipients;
78 72         512 return { 'ds' => $dscontents, 'rfc822' => $emailsteak->[1] };
79             }
80              
81             1;
82             __END__