Debian Codegraph @

lib/Sisimai/Lhost/EinsUndEins.pm

raw symbols SCIP
1 package Sisimai::Lhost::EinsUndEinsscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/;
2 use parentscip-perl cpan Sisimai v5.7.0 parent/ 'Sisimai::Lhost';
3 use v5.26scip-perl cpan Sisimai v5.7.0 `v5.26`/;
4 use strictscip-perl cpan Sisimai v5.7.0 strict/;
5 use warningsscip-perl cpan Sisimai v5.7.0 warnings/;
6
7 # X-UI-Out-Filterresults: unknown:0;
8 sub descriptionscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/description(). { '1&1: https://www.1und1.de/' }
9 sub inquirescip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/inquire(). {
10 # Detect an error from 1&1
11 # @param [Hash] mhead Message headers of a bounce email
12 # @param [String] mbody Message body of a bounce email
13 # @return [Hash] Bounce data list and message/rfc822 part
14 # @return [undef] failed to decodes or the arguments are missing
15 # @since v4.1.9
16 my $class = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/shift().;
17 my $mhead = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/shift(). // return undef;
18 my $mbody = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/shift(). // return undef;
19
20 return undef unless indexscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/index().($mhead->{'from'}, '"Mail Delivery System"') == 0;
21 return undef unless $mhead->{'subject'} eq 'Mail delivery failed: returning message to sender';
22
23 state $indicators = __PACKAGE__->INDICATORSscip-perl cpan Sisimai v5.7.0 __PACKAGE__/INDICATORS().;
24 state $boundaries = ['--- The header of the original message is following. ---'];
25 state $startingof = {
26 'message' => ['This message was created automatically by mail delivery software'],
27 'error' => ['For the following reason:'],
28 };
29
30 my $dscontents = [__PACKAGE__->DELIVERYSTATUSscip-perl cpan Sisimai v5.7.0 __PACKAGE__/DELIVERYSTATUS().]; my $v = undef;
31 my $emailparts = Sisimai::RFC5322->partscip-perl cpan Sisimai v5.7.0 Sisimai/RFC5322/part().($mbody, $boundaries);
32 my $readcursor = 0; # (Integer) Points the current cursor position
33 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
34
35 for my $e ( splitscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/split().("\n", $emailparts->[0]) ) {
36 # Read error messages and delivery status lines from the head of the email to the previous
37 # line of the beginning of the original message.
38 unless( $readcursor ) {
39 # Beginning of the bounce message or message/delivery-status part
40 $readcursor |= $indicators->{'deliverystatus'} if indexscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/index().($e, $startingof->{'message'}->[0]) == 0;
41 next;
42 }
43 next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
44
45 # The following address failed:
46 #
47 # [email protected]
48 #
49 # For the following reason:
50 #
51 # Mail size limit exceeded. For explanation visit
52 # http://postmaster.1and1.com/en/error-messages?ip=%1s
53 $v = $dscontents->[-1];
54
55 if( $e =~ /\A\s*([^ ]+[@][^ ]+?)[:]?\z/ ) {
56 # [email protected] OR
57 # the line begin with 4 space characters, end with ":" like " [email protected]:"
58 if( $v->{'recipient'} ) {
59 # There are multiple recipient addresses in the message body.
60 pushscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/push(). @$dscontents, __PACKAGE__->DELIVERYSTATUSscip-perl cpan Sisimai v5.7.0 __PACKAGE__/DELIVERYSTATUS().;
61 $v = $dscontents->[-1];
62 }
63 $v->{'recipient'} = Sisimai::Address->s3s4scip-perl cpan Sisimai v5.7.0 Sisimai/Address/s3s4().($e);
64 $recipients++;
65
66 } elsif( indexscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/index().($e, $startingof->{'error'}->[0]) == 0 ) {
67 # For the following reason:
68 $v->{'diagnosis'} = $e;
69
70 } else {
71 if( lengthscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/length(). $v->{'diagnosis'} ) {
72 # Get error message and append the error message strings
73 $v->{'diagnosis'} .= ' '.$e;
74
75 } else {
76 # OR the following format:
77 # [email protected]:
78 # SMTP error from remote server for TEXT command, host: ...
79 $v->{'alterrors'} .= ' '.$e;
80 }
81 }
82 }
83 return undef unless $recipients;
84
85 requirescip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/require(). Sisimai::SMTP::Command;
86 for my $e ( @$dscontents ) {
87 $e->{'diagnosis'} ||= $e->{'alterrors'} || '';
88 $e->{'command'} = Sisimai::SMTP::Command->findscip-perl cpan Sisimai v5.7.0 Sisimai/SMTP/Command/find().($e->{'diagnosis'});
89
90 if( Sisimai::String->alignedscip-perl cpan Sisimai v5.7.0 Sisimai/String/aligned().(\$e->{'diagnosis'}, ['host: ', ' reason:']) ) {
91 # SMTP error from remote server for TEXT command,
92 # host: smtp-in.orange.fr (193.252.22.65)
93 # reason: 550 5.2.0 Mail rejete. Mail rejected. ofr_506 [506]
94 my $p1 = indexscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/index().($e->{'diagnosis'}, 'host: ');
95 my $p2 = indexscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/index().($e->{'diagnosis'}, ' reason:');
96
97 $e->{'rhost'} = substrscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/substr().($e->{'diagnosis'}, $p1 + 6, $p2 - $p1 - 6);
98 $e->{'command'} = 'DATA' if indexscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/index().($e->{'diagnosis'}, 'for TEXT command') > -1;
99 $e->{'spec'} = 'SMTP' if indexscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/index().($e->{'diagnosis'}, 'SMTP error') > -1;
100 $e->{'status'} = Sisimai::SMTP::Status->findscip-perl cpan Sisimai v5.7.0 Sisimai/SMTP/Status/find().($e->{'diagnosis'});
101 } else {
102 # For the following reason:
103 substrscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/substr().($e->{'diagnosis'}, 0, lengthscip-perl cpan Sisimai v5.7.0 Sisimai/Lhost/EinsUndEins/length(). $startingof->{'error'}->[0], '');
104 }
105 }
106 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
107 }
108
109 1;
110 __END__
111
112 =encoding utf-8
113
114 =head1 NAME
115
116 Sisimai::Lhost::EinsUndEins - bounce mail decoder class for 1&1 L<https://www.1und1.de/>.
117
118 =head1 SYNOPSIS
119
120 use Sisimai::Lhost::EinsUndEins;
121
122 =head1 DESCRIPTION
123
124 C<Sisimai::Lhost::EinsUndEins> decodes a bounce email which created by 1&1 L<https://www.1und1.de/>.
125 Methods in the module are called from only C<Sisimai::Message>.
126
127 =head1 CLASS METHODS
128
129 =head2 C<B<description()>>
130
131 C<description()> returns description string of this module.
132
133 print Sisimai::Lhost::EinsUndEins->description;
134
135 =head2 C<B<inquire(I<header data>, I<reference to body string>)>>
136
137 C<inquire()> method decodes a bounced email and return results as a array reference.
138 See C<Sisimai::Message> for more details.
139
140 =head1 AUTHOR
141
142 azumakuniyuki
143
144 =head1 COPYRIGHT
145
146 Copyright (C) 2014-2026 azumakuniyuki, All rights reserved.
147
148 =head1 LICENSE
149
150 This software is distributed under The BSD 2-Clause License.
151
152 =cut
153