15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/sisimai/lhost/trendmicro.rb', line 15
def inquire(mhead, mbody)
match = 0
tryto = [
'Mail could not be delivered',
'メッセージを配信できません。',
'メール配信に失敗しました',
]
match += 1 if mhead['from'].start_with?('"InterScan MSS"')
match += 1 if mhead['from'].start_with?('"InterScan Notification"')
match += 1 if tryto.any? { |a| mhead['subject'] == a }
return nil if match == 0
require 'sisimai/smtp/command'
dscontents = [Sisimai::Lhost.DELIVERYSTATUS]; v = nil
emailparts = Sisimai::RFC5322.part(mbody, Boundaries)
bodyslices = emailparts[0].split("\n")
recipients = 0
while e = bodyslices.shift do
next if e.empty?
v = dscontents[-1]
p1 = e.index(' <<< ') || -1 p2 = e.index(' >>> ') || -1 if e.include?('@') && e.include?(' <') && ( p1 > 1 || p2 > 1 || e.include?('Unable to deliver ') )
cr = e[e.rindex('<') + 1, e.rindex('>') - e.rindex('<') - 1]
if v["recipient"] != "" && cr != v['recipient']
dscontents << Sisimai::Lhost.DELIVERYSTATUS
v = dscontents[-1]
end
v['recipient'] = cr
v['diagnosis'] = e if e.include?('Unable to deliver ')
recipients = dscontents.size
end
case
when e.start_with?('Sent <<< ')
v['command'] = Sisimai::SMTP::Command.find(e)
when e.start_with?('Received >>> ')
v['diagnosis'] = e[e.index(' >>> ') + 4, e.size]
else
v['command'] = Sisimai::SMTP::Command.find(e) if e.include?(' >>> ')
p3 = e.index(' <<< '); next if p3.nil?
v['diagnosis'] = e[p3 + 4, e.size]
end
end
return nil if recipients == 0
dscontents.each do |e|
e['reason'] = 'userunknown' if e['diagnosis'].include?('Unable to deliver')
end
return { 'ds' => dscontents, 'rfc822' => emailparts[1] }
end
|