File Coverage

lib/Sisimai/Lhost/GoogleGroups.pm
Criterion Covered Total %
statement 40 42 95.2
branch 9 16 56.2
condition 6 8 75.0
subroutine 6 6 100.0
pod 2 2 100.0
total 63 74 85.1


line stmt bran cond sub pod time code
1             package Sisimai::Lhost::GoogleGroups;
2 37     37   3268 use parent 'Sisimai::Lhost';
  37         61  
  37         185  
3 37     37   2492 use v5.26;
  37         102  
4 37     37   131 use strict;
  37         49  
  37         822  
5 37     37   122 use warnings;
  37         74  
  37         19002  
6              
7 1     1 1 2 sub description { 'Google Groups: https://groups.google.com' }
8             sub inquire {
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 decode or the arguments are missing
14             # @since v4.25.6
15 962     962 1 2900 my $class = shift;
16 962   100     1995 my $mhead = shift // return undef;
17 961   100     1860 my $mbody = shift // return undef;
18              
19 960 100       3836 return undef unless index($$mbody, "Google Group") > -1;
20 71 50       229 return undef unless rindex($mhead->{'from'}, '') > -1;
21 71 50       171 return undef unless index($mhead->{'subject'}, 'Delivery Status Notification') > -1;
22 71 50       143 return undef unless exists $mhead->{'x-failed-recipients'};
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 71         97 state $boundaries = ['----- Original message -----', 'Content-Type: message/rfc822'];
42 71         170 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = $dscontents->[-1];
  71         132  
43 71         152 my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries);
44 71         91 my $recipients = 0;
45 71         269 my @entiremesg = split(/\n\n/, $emailparts->[0], 5); pop @entiremesg;
  71         93  
46 71         229 my $issuedcode = join(' ', @entiremesg); $issuedcode =~ y/\n/ /;
  71         207  
47 71   50     167 my $receivedby = $mhead->{'received'} || [];
48 71         217 my $recordwide = {
49             'rhost' => Sisimai::RFC5322->received($receivedby->[0])->[1],
50             'reason' => 'onhold',
51             'diagnosis' => $issuedcode,
52             };
53              
54             # * You might have spelled or formatted the group name incorrectly.
55             # * The owner of the group may have removed this group.
56             # * You may need to join the group before receiving permission to post.
57             # * This group may not be open to posting.
58 71   50     697 my $fewdetails = [$emailparts->[0] =~ /^[ ]?[*][ ]?/gm] || [];
59 71 50       239 $recordwide->{'reason'} = 'rejected' if scalar @$fewdetails == 4;
60              
61 71         197 for my $e ( split(',', $mhead->{'x-failed-recipients'}) ) {
62             # X-Failed-Recipients: neko@example.jp, nyaan@example.org, ...
63 71 50       222 next unless Sisimai::Address->is_emailaddress($e);
64              
65 71 50       203 if( $v->{'recipient'} ) {
66             # There are multiple recipient addresses in the message body.
67 0         0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
68 0         0 $v = $dscontents->[-1];
69             }
70 71         160 $v->{'recipient'} = Sisimai::Address->s3s4($e);
71 71         91 $recipients++;
72 71         408 $v->{ $_ } = $recordwide->{ $_ } for keys %$recordwide;
73             }
74 71 50       124 return undef unless $recipients;
75 71         497 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
76             }
77              
78             1;
79             __END__