sisimai 4.22.7 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sisimai might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ChangeLog.md +15 -0
- data/README-JA.md +13 -8
- data/README.md +14 -9
- data/lib/sisimai.rb +11 -12
- data/lib/sisimai/address.rb +13 -23
- data/lib/sisimai/arf.rb +10 -12
- data/lib/sisimai/bite/email/activehunter.rb +5 -9
- data/lib/sisimai/bite/email/amazonses.rb +12 -18
- data/lib/sisimai/bite/email/amazonworkmail.rb +7 -12
- data/lib/sisimai/bite/email/aol.rb +10 -16
- data/lib/sisimai/bite/email/apachejames.rb +8 -12
- data/lib/sisimai/bite/email/bigfoot.rb +10 -15
- data/lib/sisimai/bite/email/biglobe.rb +7 -11
- data/lib/sisimai/bite/email/courier.rb +11 -15
- data/lib/sisimai/bite/email/domino.rb +8 -13
- data/lib/sisimai/bite/email/einsundeins.rb +7 -11
- data/lib/sisimai/bite/email/exchange2003.rb +11 -15
- data/lib/sisimai/bite/email/exchange2007.rb +7 -11
- data/lib/sisimai/bite/email/exim.rb +20 -27
- data/lib/sisimai/bite/email/ezweb.rb +13 -22
- data/lib/sisimai/bite/email/facebook.rb +7 -10
- data/lib/sisimai/bite/email/fml.rb +4 -7
- data/lib/sisimai/bite/email/gmx.rb +7 -12
- data/lib/sisimai/bite/email/google.rb +6 -12
- data/lib/sisimai/bite/email/gsuite.rb +11 -18
- data/lib/sisimai/bite/email/imailserver.rb +6 -10
- data/lib/sisimai/bite/email/interscanmss.rb +7 -11
- data/lib/sisimai/bite/email/kddi.rb +10 -16
- data/lib/sisimai/bite/email/mailfoundry.rb +6 -9
- data/lib/sisimai/bite/email/mailmarshalsmtp.rb +6 -10
- data/lib/sisimai/bite/email/mailru.rb +12 -16
- data/lib/sisimai/bite/email/mcafee.rb +5 -9
- data/lib/sisimai/bite/email/messagelabs.rb +7 -10
- data/lib/sisimai/bite/email/messagingserver.rb +8 -14
- data/lib/sisimai/bite/email/mfilter.rb +6 -10
- data/lib/sisimai/bite/email/mxlogic.rb +11 -17
- data/lib/sisimai/bite/email/notes.rb +9 -13
- data/lib/sisimai/bite/email/office365.rb +8 -13
- data/lib/sisimai/bite/email/opensmtpd.rb +7 -11
- data/lib/sisimai/bite/email/outlook.rb +9 -13
- data/lib/sisimai/bite/email/postfix.rb +12 -18
- data/lib/sisimai/bite/email/qmail.rb +10 -15
- data/lib/sisimai/bite/email/receivingses.rb +10 -17
- data/lib/sisimai/bite/email/sendgrid.rb +8 -14
- data/lib/sisimai/bite/email/sendmail.rb +8 -12
- data/lib/sisimai/bite/email/surfcontrol.rb +5 -9
- data/lib/sisimai/bite/email/userdefined.rb +5 -8
- data/lib/sisimai/bite/email/v5sendmail.rb +7 -11
- data/lib/sisimai/bite/email/verizon.rb +14 -28
- data/lib/sisimai/bite/email/x1.rb +5 -8
- data/lib/sisimai/bite/email/x2.rb +5 -8
- data/lib/sisimai/bite/email/x3.rb +5 -9
- data/lib/sisimai/bite/email/x4.rb +10 -14
- data/lib/sisimai/bite/email/x5.rb +6 -11
- data/lib/sisimai/bite/email/yahoo.rb +6 -11
- data/lib/sisimai/bite/email/yandex.rb +8 -12
- data/lib/sisimai/bite/email/zoho.rb +7 -12
- data/lib/sisimai/bite/json/amazonses.rb +6 -12
- data/lib/sisimai/bite/json/sendgrid.rb +1 -7
- data/lib/sisimai/data.rb +26 -34
- data/lib/sisimai/datetime.rb +5 -5
- data/lib/sisimai/mail.rb +9 -3
- data/lib/sisimai/mail/maildir.rb +1 -3
- data/lib/sisimai/mail/mbox.rb +1 -1
- data/lib/sisimai/mail/memory.rb +47 -0
- data/lib/sisimai/mail/stdin.rb +1 -1
- data/lib/sisimai/mda.rb +7 -10
- data/lib/sisimai/message.rb +4 -6
- data/lib/sisimai/message/email.rb +16 -24
- data/lib/sisimai/message/json.rb +3 -5
- data/lib/sisimai/mime.rb +13 -18
- data/lib/sisimai/order/email.rb +5 -8
- data/lib/sisimai/order/json.rb +2 -2
- data/lib/sisimai/reason.rb +3 -7
- data/lib/sisimai/reason/blocked.rb +0 -4
- data/lib/sisimai/reason/contenterror.rb +1 -1
- data/lib/sisimai/reason/exceedlimit.rb +2 -5
- data/lib/sisimai/reason/expired.rb +1 -1
- data/lib/sisimai/reason/filtered.rb +1 -4
- data/lib/sisimai/reason/hasmoved.rb +1 -4
- data/lib/sisimai/reason/hostunknown.rb +1 -4
- data/lib/sisimai/reason/mailboxfull.rb +2 -5
- data/lib/sisimai/reason/mesgtoobig.rb +1 -4
- data/lib/sisimai/reason/networkerror.rb +1 -1
- data/lib/sisimai/reason/norelaying.rb +1 -4
- data/lib/sisimai/reason/notaccept.rb +1 -3
- data/lib/sisimai/reason/onhold.rb +1 -5
- data/lib/sisimai/reason/policyviolation.rb +1 -1
- data/lib/sisimai/reason/rejected.rb +2 -6
- data/lib/sisimai/reason/spamdetected.rb +1 -5
- data/lib/sisimai/reason/suspend.rb +2 -5
- data/lib/sisimai/reason/syntaxerror.rb +0 -3
- data/lib/sisimai/reason/systemerror.rb +1 -1
- data/lib/sisimai/reason/systemfull.rb +1 -1
- data/lib/sisimai/reason/toomanyconn.rb +1 -5
- data/lib/sisimai/reason/userunknown.rb +1 -4
- data/lib/sisimai/reason/vacation.rb +1 -1
- data/lib/sisimai/reason/virusdetected.rb +1 -1
- data/lib/sisimai/rfc2606.rb +3 -3
- data/lib/sisimai/rfc3464.rb +12 -20
- data/lib/sisimai/rfc3834.rb +1 -10
- data/lib/sisimai/rfc5322.rb +4 -6
- data/lib/sisimai/rhost.rb +0 -4
- data/lib/sisimai/rhost/exchangeonline.rb +5 -7
- data/lib/sisimai/rhost/franceptt.rb +1 -3
- data/lib/sisimai/rhost/godaddy.rb +2 -4
- data/lib/sisimai/rhost/googleapps.rb +2 -4
- data/lib/sisimai/rhost/kddi.rb +0 -3
- data/lib/sisimai/smtp/error.rb +0 -3
- data/lib/sisimai/smtp/reply.rb +5 -8
- data/lib/sisimai/smtp/status.rb +3 -4
- data/lib/sisimai/string.rb +13 -20
- data/lib/sisimai/version.rb +1 -1
- data/set-of-emails/maildir/bsd/email-office365-09.eml +596 -0
- data/set-of-emails/maildir/bsd/email-office365-10.eml +594 -0
- data/set-of-emails/maildir/bsd/email-postfix-45.eml +76 -0
- metadata +6 -2
@@ -28,10 +28,6 @@ module Sisimai::Bite::Email
|
|
28
28
|
# part or nil if it failed to parse or
|
29
29
|
# the arguments are missing
|
30
30
|
def scan(mhead, mbody)
|
31
|
-
return nil unless mhead
|
32
|
-
return nil unless mbody
|
33
|
-
require 'sisimai/mime'
|
34
|
-
|
35
31
|
match = 0
|
36
32
|
match += 1 if mhead['to'].to_s.include?('NotificationRecipients')
|
37
33
|
if mhead['from'].include?('TWFpbCBEZWxpdmVyeSBTdWJzeXN0ZW0')
|
@@ -66,7 +62,7 @@ module Sisimai::Bite::Email
|
|
66
62
|
havepassed << e
|
67
63
|
p = havepassed[-2]
|
68
64
|
|
69
|
-
if readcursor
|
65
|
+
if readcursor == 0
|
70
66
|
# Beginning of the bounce message or delivery status part
|
71
67
|
if e.start_with?(StartingOf[:message][0])
|
72
68
|
readcursor |= Indicators[:deliverystatus]
|
@@ -74,7 +70,7 @@ module Sisimai::Bite::Email
|
|
74
70
|
end
|
75
71
|
end
|
76
72
|
|
77
|
-
if (readcursor & Indicators[:'message-rfc822'])
|
73
|
+
if (readcursor & Indicators[:'message-rfc822']) == 0
|
78
74
|
# Beginning of the original message part
|
79
75
|
if e.start_with?(StartingOf[:rfc822][0])
|
80
76
|
readcursor |= Indicators[:'message-rfc822']
|
@@ -137,8 +133,8 @@ module Sisimai::Bite::Email
|
|
137
133
|
end
|
138
134
|
else
|
139
135
|
# After "message/rfc822"
|
140
|
-
next
|
141
|
-
next if (readcursor & Indicators['deliverystatus'])
|
136
|
+
next unless recipients > 0
|
137
|
+
next if (readcursor & Indicators['deliverystatus']) == 0
|
142
138
|
|
143
139
|
if e.empty?
|
144
140
|
blanklines += 1
|
@@ -148,10 +144,9 @@ module Sisimai::Bite::Email
|
|
148
144
|
rfc822list << e
|
149
145
|
end
|
150
146
|
end
|
151
|
-
return nil
|
147
|
+
return nil unless recipients > 0
|
152
148
|
|
153
|
-
|
154
|
-
dscontents.map do |e|
|
149
|
+
dscontents.each do |e|
|
155
150
|
e['agent'] = self.smtpagent
|
156
151
|
e['diagnosis'] ||= Sisimai::String.sweep(e['diagnosis'])
|
157
152
|
e.each_key { |a| e[a] ||= '' }
|
@@ -33,9 +33,6 @@ module Sisimai::Bite::Email
|
|
33
33
|
# part or nil if it failed to parse or
|
34
34
|
# the arguments are missing
|
35
35
|
def scan(mhead, mbody)
|
36
|
-
return nil unless mhead
|
37
|
-
return nil unless mbody
|
38
|
-
|
39
36
|
# :subject => %r/\AFailure Notice\z/,
|
40
37
|
return nil unless mhead['x-ymailisg']
|
41
38
|
|
@@ -48,7 +45,7 @@ module Sisimai::Bite::Email
|
|
48
45
|
v = nil
|
49
46
|
|
50
47
|
while e = hasdivided.shift do
|
51
|
-
if readcursor
|
48
|
+
if readcursor == 0
|
52
49
|
# Beginning of the bounce message or delivery status part
|
53
50
|
if e.start_with?(StartingOf[:message][0])
|
54
51
|
readcursor |= Indicators[:deliverystatus]
|
@@ -56,7 +53,7 @@ module Sisimai::Bite::Email
|
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
59
|
-
if (readcursor & Indicators[:'message-rfc822'])
|
56
|
+
if (readcursor & Indicators[:'message-rfc822']) == 0
|
60
57
|
# Beginning of the original message part
|
61
58
|
if e == StartingOf[:rfc822][0]
|
62
59
|
readcursor |= Indicators[:'message-rfc822']
|
@@ -74,7 +71,7 @@ module Sisimai::Bite::Email
|
|
74
71
|
rfc822list << e
|
75
72
|
else
|
76
73
|
# Before "message/rfc822"
|
77
|
-
next if (readcursor & Indicators[:deliverystatus])
|
74
|
+
next if (readcursor & Indicators[:deliverystatus]) == 0
|
78
75
|
next if e.empty?
|
79
76
|
|
80
77
|
# Sorry, we were unable to deliver your message to the following address.
|
@@ -125,12 +122,10 @@ module Sisimai::Bite::Email
|
|
125
122
|
end
|
126
123
|
end
|
127
124
|
end
|
128
|
-
return nil
|
125
|
+
return nil unless recipients > 0
|
129
126
|
|
130
|
-
|
131
|
-
|
132
|
-
e['diagnosis'] = e['diagnosis'].gsub(/\\n/, ' ')
|
133
|
-
e['diagnosis'] = Sisimai::String.sweep(e['diagnosis'])
|
127
|
+
dscontents.each do |e|
|
128
|
+
e['diagnosis'] = Sisimai::String.sweep(e['diagnosis'].gsub(/\\n/, ' '))
|
134
129
|
e['agent'] = self.smtpagent
|
135
130
|
e['command'] ||= 'RCPT' if e['diagnosis'] =~ /[<].+[@].+[>]/
|
136
131
|
end
|
@@ -36,8 +36,6 @@ module Sisimai::Bite::Email
|
|
36
36
|
# part or nil if it failed to parse or
|
37
37
|
# the arguments are missing
|
38
38
|
def scan(mhead, mbody)
|
39
|
-
return nil unless mhead
|
40
|
-
return nil unless mbody
|
41
39
|
return nil unless mhead['x-yandex-uniq']
|
42
40
|
return nil unless mhead['from'] == 'mailer-daemon@yandex.ru'
|
43
41
|
|
@@ -61,7 +59,7 @@ module Sisimai::Bite::Email
|
|
61
59
|
havepassed << e
|
62
60
|
p = havepassed[-2]
|
63
61
|
|
64
|
-
if readcursor
|
62
|
+
if readcursor == 0
|
65
63
|
# Beginning of the bounce message or delivery status part
|
66
64
|
if e.start_with?(StartingOf[:message][0])
|
67
65
|
readcursor |= Indicators[:deliverystatus]
|
@@ -69,7 +67,7 @@ module Sisimai::Bite::Email
|
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
72
|
-
if (readcursor & Indicators[:'message-rfc822'])
|
70
|
+
if (readcursor & Indicators[:'message-rfc822']) == 0
|
73
71
|
# Beginning of the original message part
|
74
72
|
if e.start_with?(StartingOf[:rfc822][0])
|
75
73
|
readcursor |= Indicators[:'message-rfc822']
|
@@ -87,7 +85,7 @@ module Sisimai::Bite::Email
|
|
87
85
|
rfc822list << e
|
88
86
|
else
|
89
87
|
# Before "message/rfc822"
|
90
|
-
next if (readcursor & Indicators[:deliverystatus])
|
88
|
+
next if (readcursor & Indicators[:deliverystatus]) == 0
|
91
89
|
next if e.empty?
|
92
90
|
|
93
91
|
if connvalues == connheader.keys.size
|
@@ -146,13 +144,13 @@ module Sisimai::Bite::Email
|
|
146
144
|
# Arrival-Date: Sat, 6 Dec 2014 20:12:27 +0300 (MSK)
|
147
145
|
if cv = e.match(/\AReporting-MTA:[ ]*(?:DNS|dns);[ ]*(.+)\z/)
|
148
146
|
# Reporting-MTA: dns; mx.example.jp
|
149
|
-
next
|
147
|
+
next unless connheader['lhost'].empty?
|
150
148
|
connheader['lhost'] = cv[1].downcase
|
151
149
|
connvalues += 1
|
152
150
|
|
153
151
|
elsif cv = e.match(/\AArrival-Date:[ ]*(.+)\z/)
|
154
152
|
# Arrival-Date: Wed, 29 Apr 2009 16:03:18 +0900
|
155
|
-
next
|
153
|
+
next unless connheader['date'].empty?
|
156
154
|
connheader['date'] = cv[1]
|
157
155
|
connvalues += 1
|
158
156
|
else
|
@@ -171,15 +169,13 @@ module Sisimai::Bite::Email
|
|
171
169
|
end
|
172
170
|
end
|
173
171
|
end
|
174
|
-
return nil
|
172
|
+
return nil unless recipients > 0
|
175
173
|
|
176
|
-
|
177
|
-
dscontents.map do |e|
|
174
|
+
dscontents.each do |e|
|
178
175
|
# Set default values if each value is empty.
|
179
176
|
connheader.each_key { |a| e[a] ||= connheader[a] || '' }
|
180
177
|
e['command'] = commandset.shift || ''
|
181
|
-
e['diagnosis'] = e['diagnosis'].gsub(/\\n/, '')
|
182
|
-
e['diagnosis'] = Sisimai::String.sweep(e['diagnosis'])
|
178
|
+
e['diagnosis'] = Sisimai::String.sweep(e['diagnosis'].gsub(/\\n/, ''))
|
183
179
|
e['agent'] = self.smtpagent
|
184
180
|
end
|
185
181
|
|
@@ -33,9 +33,6 @@ module Sisimai::Bite::Email
|
|
33
33
|
# part or nil if it failed to parse or
|
34
34
|
# the arguments are missing
|
35
35
|
def scan(mhead, mbody)
|
36
|
-
return nil unless mhead
|
37
|
-
return nil unless mbody
|
38
|
-
|
39
36
|
# :'from' => %r/mailer-daemon[@]mail[.]zoho[.]com\z/,
|
40
37
|
# :'subject' => %r{\A(?:
|
41
38
|
# Undelivered[ ]Mail[ ]Returned[ ]to[ ]Sender
|
@@ -55,7 +52,7 @@ module Sisimai::Bite::Email
|
|
55
52
|
v = nil
|
56
53
|
|
57
54
|
while e = hasdivided.shift do
|
58
|
-
if readcursor
|
55
|
+
if readcursor == 0
|
59
56
|
# Beginning of the bounce message or delivery status part
|
60
57
|
if e.start_with?(StartingOf[:message][0])
|
61
58
|
readcursor |= Indicators[:deliverystatus]
|
@@ -63,7 +60,7 @@ module Sisimai::Bite::Email
|
|
63
60
|
end
|
64
61
|
end
|
65
62
|
|
66
|
-
if (readcursor & Indicators[:'message-rfc822'])
|
63
|
+
if (readcursor & Indicators[:'message-rfc822']) == 0
|
67
64
|
# Beginning of the original message part
|
68
65
|
if e.include?(StartingOf[:rfc822][0])
|
69
66
|
readcursor |= Indicators[:'message-rfc822']
|
@@ -81,7 +78,7 @@ module Sisimai::Bite::Email
|
|
81
78
|
rfc822list << e
|
82
79
|
else
|
83
80
|
# Before "message/rfc822"
|
84
|
-
next if (readcursor & Indicators[:deliverystatus])
|
81
|
+
next if (readcursor & Indicators[:deliverystatus]) == 0
|
85
82
|
next if e.empty?
|
86
83
|
|
87
84
|
# This message was created automatically by mail delivery software.
|
@@ -132,17 +129,15 @@ module Sisimai::Bite::Email
|
|
132
129
|
end
|
133
130
|
end
|
134
131
|
end
|
135
|
-
return nil
|
132
|
+
return nil unless recipients > 0
|
136
133
|
|
137
|
-
|
138
|
-
dscontents.map do |e|
|
134
|
+
dscontents.each do |e|
|
139
135
|
e['agent'] = self.smtpagent
|
140
|
-
e['diagnosis'] = e['diagnosis'].gsub(/\\n/, ' ')
|
141
|
-
e['diagnosis'] = Sisimai::String.sweep(e['diagnosis'])
|
136
|
+
e['diagnosis'] = Sisimai::String.sweep(e['diagnosis'].gsub(/\\n/, ' '))
|
142
137
|
|
143
138
|
MessagesOf.each_key do |r|
|
144
139
|
# Verify each regular expression of session errors
|
145
|
-
next unless MessagesOf[r].
|
140
|
+
next unless MessagesOf[r].any? { |a| e['diagnosis'].include?(a) }
|
146
141
|
e['reason'] = r.to_s
|
147
142
|
break
|
148
143
|
end
|
@@ -39,10 +39,8 @@ module Sisimai::Bite::JSON
|
|
39
39
|
# the arguments are missing
|
40
40
|
# @since v4.20.0
|
41
41
|
def scan(mhead, mbody)
|
42
|
-
return nil unless mhead
|
43
|
-
return nil unless mbody
|
44
42
|
return nil unless mhead['x-amz-sns-message-id']
|
45
|
-
return nil
|
43
|
+
return nil if mhead['x-amz-sns-message-id'].empty?
|
46
44
|
|
47
45
|
hasdivided = mbody.split("\n")
|
48
46
|
jsonstring = ''
|
@@ -51,7 +49,7 @@ module Sisimai::Bite::JSON
|
|
51
49
|
|
52
50
|
while e = hasdivided.shift do
|
53
51
|
# Find JSON string from the message body
|
54
|
-
next if e.
|
52
|
+
next if e.empty?
|
55
53
|
break if e == '--'
|
56
54
|
break if e == '__END_OF_EMAIL_MESSAGE__'
|
57
55
|
|
@@ -102,10 +100,9 @@ module Sisimai::Bite::JSON
|
|
102
100
|
# @since v4.20.0
|
103
101
|
def adapt(argvs)
|
104
102
|
return nil unless argvs.is_a? Hash
|
105
|
-
return nil
|
103
|
+
return nil if argvs.empty?
|
106
104
|
return nil unless argvs.key?('notificationType')
|
107
105
|
|
108
|
-
require 'sisimai/rfc5322'
|
109
106
|
dscontents = [Sisimai::Bite.DELIVERYSTATUS]
|
110
107
|
rfc822head = {} # (Hash) Check flags for headers in RFC822 part
|
111
108
|
recipients = 0 # (Integer) The number of 'Final-Recipient' header
|
@@ -173,13 +170,10 @@ module Sisimai::Bite::JSON
|
|
173
170
|
end
|
174
171
|
|
175
172
|
v['date'] = o['timestamp'] || argvs['mail']['timestamp']
|
176
|
-
v['date']
|
173
|
+
v['date'].sub!(/[.]\d+Z\z/, '')
|
177
174
|
end
|
178
175
|
elsif argvs['notificationType'] == 'Delivery'
|
179
176
|
# { "notificationType":"Delivery", "delivery": { ...
|
180
|
-
require 'sisimai/smtp/status'
|
181
|
-
require 'sisimai/smtp/reply'
|
182
|
-
|
183
177
|
o = argvs['delivery'].dup
|
184
178
|
r = o['recipients'] || []
|
185
179
|
|
@@ -211,14 +205,14 @@ module Sisimai::Bite::JSON
|
|
211
205
|
v['action'] = 'deliverable'
|
212
206
|
|
213
207
|
v['date'] = o['timestamp'] || argvs['mail']['timestamp']
|
214
|
-
v['date']
|
208
|
+
v['date'].sub!(/[.]\d+Z\z/, '')
|
215
209
|
end
|
216
210
|
else
|
217
211
|
# The value of "notificationType" is not any of "Bounce", "Complaint",
|
218
212
|
# or "Delivery".
|
219
213
|
return nil
|
220
214
|
end
|
221
|
-
return nil
|
215
|
+
return nil unless recipients > 0
|
222
216
|
|
223
217
|
dscontents.each do |e|
|
224
218
|
e['agent'] = self.smtpagent
|
@@ -17,16 +17,10 @@ module Sisimai::Bite::JSON
|
|
17
17
|
# @since v4.20.0
|
18
18
|
def adapt(argvs)
|
19
19
|
return nil unless argvs.is_a? Hash
|
20
|
-
return nil
|
20
|
+
return nil if argvs.empty?
|
21
21
|
return nil unless argvs.key?('email')
|
22
22
|
return nil unless Sisimai::RFC5322.is_emailaddress(argvs['email'])
|
23
23
|
|
24
|
-
require 'sisimai/string'
|
25
|
-
require 'sisimai/address'
|
26
|
-
require 'sisimai/datetime'
|
27
|
-
require 'sisimai/smtp/reply'
|
28
|
-
require 'sisimai/smtp/status'
|
29
|
-
|
30
24
|
dscontents = nil
|
31
25
|
rfc822head = {}
|
32
26
|
v = nil
|
data/lib/sisimai/data.rb
CHANGED
@@ -3,12 +3,8 @@ module Sisimai
|
|
3
3
|
class Data
|
4
4
|
# Imported from p5-Sisimail/lib/Sisimai/Data.pm
|
5
5
|
require 'sisimai/address'
|
6
|
-
require 'sisimai/rfc5322'
|
7
|
-
require 'sisimai/smtp/error'
|
8
|
-
require 'sisimai/smtp/reply'
|
9
|
-
require 'sisimai/smtp/status'
|
10
|
-
require 'sisimai/string'
|
11
6
|
require 'sisimai/reason'
|
7
|
+
require 'sisimai/string'
|
12
8
|
require 'sisimai/rhost'
|
13
9
|
require 'sisimai/time'
|
14
10
|
require 'sisimai/datetime'
|
@@ -110,27 +106,28 @@ module Sisimai
|
|
110
106
|
require 'sisimai/smtp'
|
111
107
|
|
112
108
|
# Decide the order of email headers: user specified or system default.
|
113
|
-
if givenorder.is_a?(Hash) && givenorder.
|
109
|
+
if givenorder.is_a?(Hash) && !givenorder.empty?
|
114
110
|
# If the order of headers for searching is specified, use the order
|
115
111
|
# for detecting an email address.
|
116
112
|
fieldorder.each_key do |e|
|
117
113
|
# The order should be "Array Reference".
|
118
114
|
next unless givenorder[e]
|
119
115
|
next unless givenorder[e].is_a? Array
|
120
|
-
next
|
121
|
-
fieldorder[e]
|
116
|
+
next if givenorder[e].empty?
|
117
|
+
fieldorder[e] += givenorder[e]
|
122
118
|
end
|
123
119
|
end
|
124
120
|
|
125
121
|
fieldorder.each_key do |e|
|
126
122
|
# If the order is empty, use default order.
|
127
|
-
next
|
123
|
+
next unless fieldorder[e].empty?
|
128
124
|
|
129
125
|
# Load default order of each accessor.
|
130
126
|
fieldorder[e] = AddrHeader[e]
|
131
127
|
end
|
132
128
|
|
133
|
-
messageobj.ds.
|
129
|
+
eachobject = messageobj.ds.dup
|
130
|
+
while e = eachobject.shift do
|
134
131
|
# Create parameters for new() constructor.
|
135
132
|
p = {
|
136
133
|
'catch' => messageobj.catch || nil,
|
@@ -182,7 +179,7 @@ module Sisimai
|
|
182
179
|
datestring = nil
|
183
180
|
zoneoffset = 0
|
184
181
|
datevalues = []
|
185
|
-
datevalues << e['date']
|
182
|
+
datevalues << e['date'] unless e['date'].to_s.empty?
|
186
183
|
|
187
184
|
# Date information did not exist in message/delivery-status part,...
|
188
185
|
RFC822Head[:date].each do |f|
|
@@ -222,7 +219,7 @@ module Sisimai
|
|
222
219
|
|
223
220
|
# OTHER_TEXT_HEADERS:
|
224
221
|
recvheader = mailheader['received'] || []
|
225
|
-
|
222
|
+
unless recvheader.empty?
|
226
223
|
# Get localhost and remote host name from Received header.
|
227
224
|
%w[lhost rhost].each { |a| e[a] ||= '' }
|
228
225
|
e['lhost'] = Sisimai::RFC5322.received(recvheader[0]).shift if e['lhost'].empty?
|
@@ -231,13 +228,13 @@ module Sisimai
|
|
231
228
|
|
232
229
|
# Remove square brackets and curly brackets from the host variable
|
233
230
|
%w[rhost lhost].each do |v|
|
234
|
-
p[v]
|
235
|
-
p[v]
|
236
|
-
p[v]
|
231
|
+
p[v].delete!('[]()') # Remove square brackets and curly brackets from the host variable
|
232
|
+
p[v].sub!(/\A.+=/, '') # Remove string before "="
|
233
|
+
p[v].chomp!("\r") # Remove CR at the end of the value
|
237
234
|
|
238
235
|
# Check space character in each value and get the first element
|
239
236
|
p[v] = p[v].split(' ', 2).shift if p[v].include?(' ')
|
240
|
-
p[v]
|
237
|
+
p[v].chomp!('.') # Remove "." at the end of the value
|
241
238
|
end
|
242
239
|
|
243
240
|
# Subject: header of the original message
|
@@ -246,46 +243,44 @@ module Sisimai
|
|
246
243
|
|
247
244
|
# The value of "List-Id" header
|
248
245
|
p['listid'] = rfc822data['list-id'] || ''
|
249
|
-
|
246
|
+
unless p['listid'].empty?
|
250
247
|
# Get the value of List-Id header
|
251
248
|
if cv = p['listid'].match(/\A.*([<].+[>]).*\z/)
|
252
249
|
# List name <list-id@example.org>
|
253
250
|
p['listid'] = cv[1]
|
254
251
|
end
|
255
|
-
p['listid'] = p['listid'].delete('<>')
|
256
|
-
p['listid'] = p['listid'].chomp("\r")
|
252
|
+
p['listid'] = p['listid'].delete('<>').chomp("\r")
|
257
253
|
p['listid'] = '' if p['listid'].include?(' ')
|
258
254
|
end
|
259
255
|
|
260
256
|
# The value of "Message-Id" header
|
261
257
|
p['messageid'] = rfc822data['message-id'] || ''
|
262
|
-
|
258
|
+
unless p['messageid'].empty?
|
263
259
|
# Remove angle brackets
|
264
260
|
if cv = p['messageid'].match(/\A([^ ]+)[ ].*/)
|
265
261
|
p['messageid'] = cv[1]
|
266
262
|
end
|
267
|
-
p['messageid'] = p['messageid'].delete('<>')
|
268
|
-
p['messageid'] = p['messageid'].chomp("\r")
|
263
|
+
p['messageid'] = p['messageid'].delete('<>').chomp("\r")
|
269
264
|
end
|
270
265
|
|
271
266
|
# CHECK_DELIVERY_STATUS_VALUE:
|
272
267
|
# Cleanup the value of "Diagnostic-Code:" header
|
273
|
-
p['diagnosticcode']
|
268
|
+
p['diagnosticcode'].sub!(/[ \t.]+#{EndOfEmail}/, '')
|
274
269
|
|
275
|
-
|
270
|
+
unless p['diagnosticcode'].empty?
|
276
271
|
# Count the number of D.S.N. and SMTP Reply Code
|
277
272
|
vs = Sisimai::SMTP::Status.find(p['diagnosticcode'])
|
278
273
|
vr = Sisimai::SMTP::Reply.find(p['diagnosticcode'])
|
279
274
|
vm = 0
|
280
275
|
re = nil
|
281
276
|
|
282
|
-
|
277
|
+
unless vs.empty?
|
283
278
|
# How many times does the D.S.N. appeared
|
284
279
|
vm += p['diagnosticcode'].scan(/\b#{vs}\b/).size
|
285
280
|
p['deliverystatus'] = vs if vs =~ /\A[45][.][1-9][.][1-9]\z/
|
286
281
|
end
|
287
282
|
|
288
|
-
|
283
|
+
unless vr.empty?
|
289
284
|
# How many times does the SMTP reply code appeared
|
290
285
|
vm += p['diagnosticcode'].scan(/\b#{vr}\b/).size
|
291
286
|
p['replycode'] ||= vr
|
@@ -300,7 +295,7 @@ module Sisimai
|
|
300
295
|
# 550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail,
|
301
296
|
# 550-5.7.1 this message has been blocked. Please visit
|
302
297
|
# 550 5.7.1 https://support.google.com/mail/answer/188131 for more information.
|
303
|
-
p['diagnosticcode']
|
298
|
+
p['diagnosticcode'].gsub!(re, ' ')
|
304
299
|
p['diagnosticdoee'] = Sisimai::String.sweep(p['diagnosticcode'])
|
305
300
|
end
|
306
301
|
end
|
@@ -359,8 +354,7 @@ module Sisimai
|
|
359
354
|
|
360
355
|
if o.softbounce.to_s.empty?
|
361
356
|
# The value is not set yet
|
362
|
-
textasargv = p['deliverystatus'] + ' ' + p['diagnosticcode']
|
363
|
-
textasargv = textasargv.lstrip
|
357
|
+
textasargv = (p['deliverystatus'] + ' ' + p['diagnosticcode']).lstrip
|
364
358
|
softorhard = Sisimai::SMTP::Error.soft_or_hard(o.reason, textasargv)
|
365
359
|
|
366
360
|
o.softbounce = if softorhard.size > 0
|
@@ -374,14 +368,12 @@ module Sisimai
|
|
374
368
|
|
375
369
|
if o.deliverystatus.empty?
|
376
370
|
# Set pseudo status code
|
377
|
-
textasargv = o.replycode + ' ' + p['diagnosticcode']
|
378
|
-
textasargv = textasargv.lstrip
|
379
|
-
|
371
|
+
textasargv = (o.replycode + ' ' + p['diagnosticcode']).lstrip
|
380
372
|
getchecked = Sisimai::SMTP::Error.is_permanent(textasargv)
|
381
373
|
tmpfailure = getchecked.nil? ? false : (getchecked ? false : true)
|
382
374
|
pseudocode = Sisimai::SMTP::Status.code(o.reason, tmpfailure)
|
383
375
|
|
384
|
-
|
376
|
+
unless pseudocode.empty?
|
385
377
|
# Set the value of "deliverystatus" and "softbounce"
|
386
378
|
o.deliverystatus = pseudocode
|
387
379
|
|
@@ -400,7 +392,7 @@ module Sisimai
|
|
400
392
|
end
|
401
393
|
end
|
402
394
|
|
403
|
-
|
395
|
+
unless o.replycode.empty?
|
404
396
|
# Check both of the first digit of "deliverystatus" and "replycode"
|
405
397
|
o.replycode = '' unless o.replycode[0, 1] == o.deliverystatus[0, 1]
|
406
398
|
end
|