sisimai 4.25.13-java → 4.25.15-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,118 +5,253 @@ module Sisimai
5
5
  # is "aspmx.l.google.com". This class is called only Sisimai::Data class.
6
6
  module GoogleApps
7
7
  class << self
8
- # Imported from p5-Sisimail/lib/Sisimai/Rhost/GoogleApps.pm
9
- StatusList = {
10
- # https://support.google.com/a/answer/3726730
11
- 'X.1.1' => [{ reason: 'userunknown', string: ['The email account that you tried to reach does not exist.'] }],
12
- 'X.1.2' => [{ reason: 'hostunknown', string: ["We weren't able to find the recipient domain."] }],
13
- 'X.2.1' => [
14
- { reason: 'suspend', string: ['The email account that you tried to reach is disabled.'] },
15
- { reason: 'exceedlimit', string: ['The user you are trying to contact is receiving mail '] },
16
- ],
17
- 'X.2.2' => [{ reason: 'mailboxfull', string: ['The email account that you tried to reach is over quota.'] }],
18
- 'X.2.3' => [{ reason: 'exceedlimit', string: ["Your message exceeded Google's message size limits."] }],
19
- 'X.3.0' => [
20
- { reason: 'syntaxerror', string: ['Multiple destination domains per transaction is unsupported.'] },
21
- { reason: 'undefined', string: ['Mail server temporarily rejected message.'] },
22
- ],
23
- 'X.4.2' => [{ reason: 'expired', string: ['Timeout - closing connection.'] }],
24
- 'X.4.5' => [
25
- { reason: 'exceedlimit', string: ['Daily sending quota exceeded.'] },
26
- { reason: 'undefined', string: ['Server busy, try again later.'] },
27
- ],
28
- 'X.5.0' => [{ reason: 'syntaxerror', string: ['SMTP protocol violation'] }],
29
- 'X.5.1' => [
30
- { reason: 'securityerror', string: ['Authentication Required.'] },
31
- { reason: 'syntaxerror', string: [
32
- 'STARTTLS may not be repeated',
33
- 'Too many unrecognized commands, goodbye.',
34
- 'Unimplemented command.',
35
- 'Unrecognized command.',
36
- 'EHLO/HELO first.',
37
- 'MAIL first.',
38
- 'RCPT first.',
39
- ]},
40
- ],
41
- 'X.5.2' => [
42
- { reason: 'securityerror', string: ['Cannot Decode response.'] }, # 2FA related error, maybe.
43
- { reason: 'syntaxerror', string: ['Syntax error.'] },
44
- ],
45
- 'X.5.3' => [
46
- { reason: 'mailboxfull', string: ['Domain policy size per transaction exceeded,'] },
47
- { reason: 'policyviolation', string: ['Your message has too many recipients.'] },
48
- ],
49
- 'X.5.4' => [{ reason: 'syntaxerror', string: ['Optional Argument not permitted for that AUTH mode.'] }],
50
- 'X.6.0' => [
51
- { reason: 'contenterror', string: ['Mail message is malformed.'] },
52
- { reason: 'networkerror', string: ['Message exceeded 50 hops'] }
53
- ],
54
- 'X.7.0' => [
55
- { reason: 'blocked', string: [
56
- 'IP not in whitelist for RCPT domain, closing connection.',
57
- 'unusual rate of unsolicited mail originating from your IP address.',
58
- ]},
59
- { reason: 'expired', string: [
60
- 'Temporary System Problem. Try again later.',
61
- 'Try again later, closing connection.',
62
- ]},
63
- { reason: 'securityerror', string: [
64
- 'TLS required for RCPT domain, closing connection.',
65
- 'No identity changes permitted.',
66
- 'Must issue a STARTTLS command first.',
67
- 'Too Many Unauthenticated commands.',
68
- ]},
69
- { reason: 'policyviolation', string: [
70
- 'an illegal attachment on your message',
71
- 'This message was blocked because its content presents a potential',
72
- ]},
73
- { reason: 'systemerror', string: ['Cannot authenticate due to temporary system problem.'] },
74
- { reason: 'norelaying', string: ['Mail relay denied.'] },
75
- { reason: 'rejected', string: ['Mail Sending denied.'] },
76
- ],
77
- 'X.7.1' => [
78
- { reason: 'mailboxfull', string: ['Email quota exceeded.'] },
79
- { reason: 'securityerror', string: [
80
- 'Application-specific password required.',
81
- 'Please log in with your web browser and then try again.',
82
- 'Username and Password not accepted.',
83
- ]},
84
- { reason: 'blocked', string: [
85
- 'The IP address sending this message does not have a PTR record setup.',
86
- "The IP you're using to send mail is not authorized to send email directly to our servers.",
87
- 'this message is likely suspicious due to the very low reputation of the sending IP address',
88
- 'unusual rate of unsolicited mail originating from your IP address.',
89
- ]},
90
- { reason: 'spamdetected', string: ['this message is likely unsolicited mail.'] },
91
- { reason: 'policyviolation',string: [
92
- 'Messages with multiple addresses in From: header are not accepted.',
93
- 'The user or domain that you are sending to (or from) has a policy',
94
- ]},
95
- { reason: 'rejected', string: [
96
- 'This message does not have authentication information or fails to pass authentication checks',
97
- 'Unauthenticated email is not accepted from this domain.',
98
- ]},
99
- ],
100
- 'X.7.4' => [{ reason: 'syntaxerror', string: ['Unrecognized Authentication Type.'] }],
8
+ MessagesOf = {
9
+ 'blocked' => [
10
+ ['421', '4.7.0', 'ip not in whitelist for rcpt domain, closing connection.'],
11
+
12
+ # - 421 4.7.0 Our system has detected an unusual rate of unsolicited mail originating
13
+ # from your IP address. To protect our users from spam, mail sent from your IP ad-
14
+ # dress has been temporarily blocked.
15
+ # For more information, visit https://support.google.com/mail/answer/81126
16
+ ['421', '4.7.0', 'our system has detected an unusual rate of unsolicited mail originating from your ip address'],
17
+
18
+ # - 421 4.7.0 Try again later, closing connection. This usually indicates a Denial of
19
+ # Service (DoS) for the SMTP relay at the HELO stage.
20
+ ['421', '4.7.0', 'try again later, closing connection.'],
21
+
22
+ # - 501 5.5.4 HELO/EHLO argument is invalid. For more information, visit [HELO/EHLO e-
23
+ # mail error].
24
+ ['501', '5.5.4', 'helo/ehlo argument is invalid'],
25
+
26
+ # - 550 5.7.1 Our system has detected an unusual rate of unsolicited mail originating
27
+ # from your IP address. To protect our users from spam, mail sent from your IP ad-
28
+ # dress has been blocked. Review https://support.google.com/mail/answer/81126
29
+ ['550', '5.7.1', 'our system has detected an unusual rate of unsolicited mail originating from your ip address'],
30
+
31
+ # - 550 5.7.1 The IP you're using to send mail is not authorized to send email directly
32
+ # to our servers. Please use the SMTP relay at your service provider instead. For
33
+ # more information, visit https://support.google.com/mail/answer/10336
34
+ ['550', '5.7.1', "the ip you're using to send mail is not authorized to send email directly to our servers"],
35
+
36
+ # - 550 5.7.25 The IP address sending this message does not have a PTR record setup, or
37
+ # the corresponding forward DNS entry does not point to the sending IP. As a policy,
38
+ # Gmail does not accept messages from IPs with missing PTR records.
39
+ ['550', '5.7.25', 'the ip address sending this message does not have a ptr record setup'],
40
+
41
+ # - 550 5.7.26 Unauthenticated email from domain-name is not accepted due to domain's
42
+ # DMARC policy. Please contact the administrator of domain-name domain. If this was
43
+ # a legitimate mail please visit [Control unauthenticated mail from your domain] to
44
+ # learn about the DMARC initiative. If the messages are valid and aren't spam, con-
45
+ # tact the administrator of the receiving mail server to determine why your outgoing
46
+ # messages don't pass authentication checks.
47
+ ['550', '5.7.26', "is not accepted due to domain's dmarc policy"],
48
+
49
+ # - 550 5.7.26 This message does not have authentication information or fails to pass
50
+ # authentication checks (SPF or DKIM). To best protect our users from spam, the mes-
51
+ # sage has been blocked. Please visit https://support.google.com/mail/answer/81126
52
+ # for more information.
53
+ ['550', '5.7.1', 'fails to pass authentication checks'],
54
+ ['550', '5.7.26', 'fails to pass authentication checks'],
55
+
56
+ # - 550 5.7.26 This message fails to pass SPF checks for an SPF record with a hard fail
57
+ # policy (-all). To best protect our users from spam and phishing, the message has
58
+ # been blocked. Please visit https://support.google.com/mail/answer/81126 for more
59
+ # information.
60
+ ['550', '5.7.26', 'this message fails to pass spf checks for an spf record with a hard fail'],
61
+ # - 550 5.7.1 Our system has detected that this message is likely suspicious due to the
62
+ # very low reputation of the sending IP address. To best protect our users from spam,
63
+ # the message has been blocked.
64
+ # Please visit https://support.google.com/mail/answer/188131 for more information.
65
+ ['550', '5.7.1', 'this message is likely suspicious due to the very low reputation of the sending ip address'],
66
+ ],
67
+ 'contenterror' => [
68
+ ['554', '5.6.0', 'mail message is malformed. Not accepted'],
69
+ ],
70
+ 'exceedlimit' => [
71
+ # - 552 5.2.3 Your message exceeded Google's message size limits. For more information,
72
+ # visit https://support.google.com/mail/answer/6584
73
+ ['552', '5.2.3', "your message exceeded Google's message size limits"],
74
+ ],
75
+ 'expired' => [
76
+ ['451', '4.4.2', 'timeout - closing connection'],
77
+ ],
78
+ 'mailboxfull' => [
79
+ # - 452 4.2.2 The email account that you tried to reach is over quota. Please direct
80
+ # the recipient to Clear Google Drive space & increase storage.
81
+ ['452', '4.2.2', 'the email account that you tried to reach is over quota'],
82
+ ['552', '5.2.2', 'the email account that you tried to reach is over quota'],
83
+ ['550', '5.7.1', 'email quota exceeded'],
84
+ ],
85
+ 'networkerror' => [
86
+ ['554', '5.6.0', 'message exceeded 50 hops, this may indicate a mail loop'],
87
+ ],
88
+ 'norelaying' => [
89
+ ['550', '5.7.0', 'mail relay denied'],
90
+ ],
91
+ 'policyviolation' => [
92
+ ['550', '5.7.1', 'messages with multiple addresses in from: header are not accepted'],
93
+
94
+ # - 550 5.7.1 The user or domain that you are sending to (or from) has a policy that
95
+ # prohibited the mail that you sent. Please contact your domain administrator for
96
+ # further details.
97
+ # For more information, visit https://support.google.com/a/answer/172179
98
+ ['550', '5.7.1', 'the user or domain that you are sending to (or from) has a policy that prohibited'],
99
+
100
+ # - 552 5.7.0 Our system detected an illegal attachment on your message. Please visit
101
+ # http://mail.google.com/support/bin/answer.py?answer=6590 to review our attachment
102
+ # guidelines.
103
+ ['552', '5.7.0', 'our system detected an illegal attachment on your message'],
104
+
105
+ # - 552 5.7.0 This message was blocked because its content presents a potential securi-
106
+ # ty issue. Please visit https://support.google.com/mail/?p=BlockedMessage to review
107
+ # our message content and attachment content guidelines.
108
+ ['552', '5.7.0', 'this message was blocked because its content presents a potential security issue'],
109
+ ],
110
+ 'rejected' => [
111
+ # - 550 5.7.0, Mail Sending denied. This error occurs if the sender account is disabled
112
+ # or not registered within your Google Workspace domain.
113
+ ['550', '5.7.0', 'mail sending denied'],
114
+
115
+ ['550', '5.7.1', 'unauthenticated email is not accepted from this domain'],
116
+ ],
117
+ 'securityerror' => [
118
+ ['421', '4.7.0', 'tls required for rcpt domain, closing connection'],
119
+ ['501', '5.5.2', 'cannot decode response'], # 2FA related error, maybe.
120
+
121
+ # - 530 5.5.1 Authentication Required. For more information, visit
122
+ # https://support.google.com/accounts/troubleshooter/2402620
123
+ ['530', '5.5.1', 'authentication required.'],
124
+
125
+ # - 535 5.7.1 Application-specific password required.
126
+ # For more information, visit https://support.google.com/accounts/answer/185833
127
+ ['535', '5.7.1', 'application-specific password required'],
128
+
129
+ # - 535 5.7.1 Please log in with your web browser and then try again. For more infor-
130
+ # mation, visit https://support.google.com/mail/bin/accounts/answer/78754
131
+ ['535', '5.7.1', 'please log in with your web browser and then try again'],
132
+
133
+ # - 535 5.7.1 Username and Password not accepted. For more information, visit
134
+ # https://support.google.com/accounts/troubleshooter/2402620
135
+ ['535', '5.7.1', 'username and password not accepted'],
136
+
137
+ ['550', '5.7.1', 'invalid credentials for relay'],
138
+ ],
139
+ 'spamdetected' => [
140
+ # - 550 5.7.1 Our system has detected that this message is likely unsolicited mail. To
141
+ # reduce the amount of spam sent to Gmail, this message has been blocked.
142
+ # For more information, visit https://support.google.com/mail/answer/188131
143
+ ['550', '5.7.1', 'our system has detected that this message is likely unsolicited mail'],
144
+ ],
145
+ 'suspend' => [
146
+ ['550', '5.2.1', 'the email account that you tried to reach is disabled'],
147
+ ],
148
+ 'syntaxerror' => [
149
+ ['451', '4.5.0', 'smtp protocol violation, visit rfc 2821'],
150
+ ['454', '4.5.0', 'smtp protocol violation, no commands allowed to pipeline after starttls'],
151
+ ['454', '5.5.1', 'starttls may not be repeated'],
152
+ ['502', '5.5.1', 'too many unrecognized commands, goodbye'],
153
+ ['502', '5.5.1', 'unimplemented command'],
154
+ ['502', '5.5.1', 'unrecognized command'],
155
+ ['503', '5.5.1', 'ehlo/helo first'],
156
+ ['503', '5.5.1', 'mail first'],
157
+ ['503', '5.5.1', 'rcpt first'],
158
+ ['503', '5.7.0', 'no identity changes permitted'],
159
+ ['504', '5.7.4', 'unrecognized authentication type'],
160
+ ['530', '5.7.0', 'must issue a starttls command first'],
161
+ ['535', '5.5.4', 'optional argument not permitted for that auth mode'],
162
+ ['554', '5.7.0', 'too many unauthenticated commands'],
163
+ ['555', '5.5.2', 'syntax error'],
164
+ ],
165
+ 'systemerror' => [
166
+ ['421', '4.3.0', 'temporary system problem'],
167
+ ['421', '4.7.0', 'temporary system problem'],
168
+ ['421', '4.4.5', 'server busy'],
169
+ ['451', '4.3.0', 'mail server temporarily rejected message'],
170
+ ['454', '4.7.0', 'cannot authenticate due to temporary system problem'],
171
+
172
+ # - 452 4.5.3 Domain policy size per transaction exceeded, please try this recipient in
173
+ # a separate transaction. This message means the email policy size (size of policies,
174
+ # number of policies, or both) for the recipient domain has been exceeded.
175
+ ['452', '4.5.3', 'domain policy size per transaction exceeded'],
176
+ ],
177
+ 'toomanyconn' => [
178
+ ['451', '4.3.0', 'multiple destination domains per transaction is unsupported'],
179
+
180
+ # - 452 4.5.3 Your message has too many recipients. For more information regarding
181
+ # Google's sending limits, visit https://support.google.com/mail/answer/6592
182
+ ['452', '4.5.3', 'your message has too many recipients'],
183
+
184
+ # - 450 4.2.1 The user you are trying to contact is receiving mail too quickly. Please
185
+ # resend your message at a later time. If the user is able to receive mail at that
186
+ # time, your message will be delivered.
187
+ # For more information, visit https://support.google.com/mail/answer/22839
188
+ ['450', '4.2.1', 'is receiving mail too quickly'],
189
+
190
+ # - 450 4.2.1 The user you are trying to contact is receiving mail at a rate that pre-
191
+ # vents additional messages from being delivered. Please resend your message at a
192
+ # later time. If the user is able to receive mail at that time, your message will be
193
+ # delivered. For more information, visit https://support.google.com/mail/answer/6592
194
+ ['450', '4.2.1', 'is receiving mail at a rate that prevents additional messages from being delivered'],
195
+ ['550', '5.2.1', 'is receiving mail at a rate that prevents additional messages from being delivered'],
196
+
197
+ # - 450 4.2.1 Peak SMTP relay limit exceeded for customer. This is a temporary error.
198
+ # For more information on SMTP relay limits, please contact your administrator or
199
+ # visit https://support.google.com/a/answer/6140680
200
+ ['450', '4.2.1', 'peak smtp relay limit exceeded for customer'],
201
+
202
+ # - 550 5.4.5 Daily SMTP relay limit exceeded for user. For more information on SMTP
203
+ # relay sending limits please contact your administrator or visit SMTP relay service
204
+ # error messages.
205
+ ['550', '5.4.5', 'daily smtp relay limit exceeded for user'],
206
+ ['550', '5.4.5', 'daily sending quota exceeded'],
207
+
208
+ # - 550 5.7.1 Daily SMTP relay limit exceeded for customer. For more information on
209
+ # SMTP relay sending limits please contact your administrator or visit
210
+ # https://support.google.com/a/answer/6140680
211
+ ['550', '5.7.1', 'daily smtp relay limit exceeded for customer'],
212
+ ],
213
+ 'userunknown' => [
214
+ # - 550 5.1.1 The email account that you tried to reach does not exist. Please try dou-
215
+ # ble-checking the recipient's email address for typos or unnecessary spaces.
216
+ # For more information, visit https://support.google.com/mail/answer/6596
217
+ ['550', '5.1.1', 'the email account that you tried to reach does not exist'],
218
+
219
+ # - 553 5.1.2 We weren't able to find the recipient domain. Please check for any spell-
220
+ # ing errors, and make sure you didn't enter any spaces, periods, or other punctua-
221
+ # tion after the recipient's email address.
222
+ ['553', '5.1.2', "we weren't able to find the recipient domain"],
223
+ ],
101
224
  }.freeze
102
225
 
103
- # Detect bounce reason from Google Apps
104
- # @param [Sisimai::Data] argvs Parsed email object
105
- # @return [String] The bounce reason for Google Apps
226
+ # Detect bounce reason from Google Workspace
227
+ # @param [Sisimai::Fact] argvs Parsed email object
228
+ # @return [String] The bounce reason for Google Workspace
106
229
  # @see https://support.google.com/a/answer/3726730?hl=en
107
230
  def get(argvs)
108
231
  return argvs.reason unless argvs.reason.empty?
232
+ return '' if argvs.diagnosticcode.empty?
233
+ return '' if argvs.replycode.empty?
234
+ return '' if argvs.deliverystatus.empty?
235
+ return '' unless argvs.deliverystatus =~ /\A[245][.]\d[.]\d+\z/
109
236
 
110
- (statuscode = argvs.deliverystatus.clone)[0] = 'X'
111
- return '' unless StatusList[statuscode]
112
-
237
+ statuscode = argvs.deliverystatus[2,6]
238
+ esmtpreply = argvs.replycode[1,2]
239
+ esmtperror = argvs.diagnosticcode.downcase
113
240
  reasontext = ''
114
- StatusList[statuscode].each do |e|
115
- # Try to match
116
- next unless e[:string].any? { |a| argvs.diagnosticcode.include?(a) }
117
- reasontext = e[:reason]
118
- break
241
+
242
+ MessagesOf.each_key do |e|
243
+ # Each key is a reason name
244
+ MessagesOf[e].each do |f|
245
+ # Try to match an SMTP reply code, a D.S.N, and an error message
246
+ next unless esmtperror.include?(f[2])
247
+ next unless f[0].end_with?(esmtpreply)
248
+ next unless f[1].end_with?(statuscode)
249
+ reasontext = e
250
+ break
251
+ end
252
+ break unless reasontext.empty?
119
253
  end
254
+
120
255
  return reasontext
121
256
  end
122
257