Module: Sisimai::Lhost::EZweb
- Defined in:
- lib/sisimai/lhost/ezweb.rb
Overview
Sisimai::Lhost::EZweb decodes a bounce email which created by au EZweb www.au.com/mobile/. Methods in the module are called from only Sisimai::Message.
Constant Summary collapse
- Indicators =
Sisimai::Lhost.INDICATORS
- Boundaries =
["--------------------------------------------------", "Content-Type: message/rfc822"].freeze
- StartingOf =
{message: ['The user(s) ', 'Your message ', 'Each of the following', '<']}.freeze
- UnpaidUser =
[ # http://www.naruhodo-au.kddi.com/qa3429203.html # The recipient may be unpaid user...? 'The user(s) account is disabled.', 'The user(s) account is temporarily limited.', ].freeze
Class Method Summary collapse
Class Method Details
.description ⇒ Object
115 |
# File 'lib/sisimai/lhost/ezweb.rb', line 115 def description; return 'au EZweb: http://www.au.kddi.com/mobile/'; end |
.inquire(mhead, mbody) ⇒ Hash, Nil
This method is abstract.
Decodes the bounce message from au EZweb
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/sisimai/lhost/ezweb.rb', line 23 def inquire(mhead, mbody) match = 0 match += 1 if mhead['from'].include?('Postmaster@ezweb.ne.jp') match += 1 if mhead['from'].include?('Postmaster@au.com') match += 1 if mhead['subject'] == 'Mail System Error - Returned Mail' match += 1 if mhead['received'].any? { |a| a.include?('ezweb.ne.jp (EZweb Mail) with') } match += 1 if mhead['received'].any? { |a| a.include?('.au.com (') } if mhead['message-id'] match += 1 if mhead['message-id'].end_with?('.ezweb.ne.jp>', '.au.com>') end return nil if match < 2 fieldtable = Sisimai::RFC1894.FIELDTABLE dscontents = [Sisimai::Lhost.DELIVERYSTATUS]; v = nil emailparts = Sisimai::RFC5322.part(mbody, Boundaries) bodyslices = emailparts[0].split("\n") readcursor = 0 # (Integer) Points the current cursor position recipients = 0 # (Integer) The number of 'Final-Recipient' header while e = bodyslices.shift do # Read error messages and delivery status lines from the head of the email to the previous # line of the beginning of the original message. if readcursor == 0 # Beginning of the bounce message or delivery status part readcursor |= Indicators[:deliverystatus] if StartingOf[:message].any? { |a| e.include?(a) } end next if (readcursor & Indicators[:deliverystatus]) == 0 || e.empty? # The user(s) account is disabled. # # <***@ezweb.ne.jp>: 550 user unknown (in reply to RCPT TO command) # # -- OR -- # Each of the following recipients was rejected by a remote # mail server. # # Recipient: <******@ezweb.ne.jp> # >>> RCPT TO:<******@ezweb.ne.jp> # <<< 550 <******@ezweb.ne.jp>: User unknown v = dscontents[-1] if Sisimai::String.aligned(e, ['<', '@', '>']) && (e.include?('Recipient: <') || e.start_with?('<')) # Recipient: <******@ezweb.ne.jp> OR <***@ezweb.ne.jp>: 550 user unknown ... p1 = e.index('<') || -1 p2 = e.index('>') || -1 if v["recipient"] != "" # There are multiple recipient addresses in the message body. dscontents << Sisimai::Lhost.DELIVERYSTATUS v = dscontents[-1] end v["recipient"] = Sisimai::Address.s3s4(e[p1, p2 - p1]) v["diagnosis"] += " #{e}" recipients += 1 elsif Sisimai::RFC1894.match(e) > 0 # "e" matched with any field defined in RFC3464 next unless o = Sisimai::RFC1894.field(e) next unless fieldtable[o[0]] v[fieldtable[o[0]]] = o[2] else # Other error messages # >>> RCPT TO:<******@ezweb.ne.jp> # <<< 550 ... next if Sisimai::String.is_8bit(e) v["command"] = Sisimai::SMTP::Command.find(e) if e.include?(" >>> ") v["diagnosis"] += " #{e}" end end return nil if recipients == 0 dscontents.each do |e| # Check each value of DeliveryMatter{}, try to detect the bounce reason. e['diagnosis'] = e['diagnosis'].split.join(" ") e["command"] = Sisimai::SMTP::Command.find(e["diagnosis"]) if e["command"].empty? if mhead['x-spasign'].to_s == 'NG' # Content-Type: text/plain; ..., X-SPASIGN: NG (spamghetti, au by EZweb) # Filtered recipient returns message that include 'X-SPASIGN' header e['reason'] = 'filtered' else # There is no X-SPASIGN header or the value of the header is not "NG" e['reason'] = "suspend" if UnpaidUser.any? { |a| e['diagnosis'].include?(a) } end next if e['reason'] != "" next if e['recipient'].end_with?('@ezweb.ne.jp', '@au.com') e["reason"] = "userunknown" if e["diagnosis"].start_with?("<") end return {"ds" => dscontents, "rfc822" => emailparts[1]} end |