Module: Sisimai::Lhost::X1
- Defined in:
- lib/sisimai/lhost/x1.rb
Overview
Sisimai::Lhost::X1 decodes a bounce email which created by Unknown MTA #1. Methods in the module are called from only Sisimai::Message.
Constant Summary collapse
- Indicators =
Sisimai::Lhost.INDICATORS
- Boundaries =
['Content-Type: message/rfc822', 'Received: from '].freeze
- MarkingsOf =
{message: ['The original message was received at ']}.freeze
Class Method Summary collapse
Class Method Details
.description ⇒ Object
75 |
# File 'lib/sisimai/lhost/x1.rb', line 75 def description; return 'Unknown MTA #1'; end |
.inquire(mhead, mbody) ⇒ Hash, Nil
This method is abstract.
Decodes the bounce message from Unknown MTA #1
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 |
# File 'lib/sisimai/lhost/x1.rb', line 17 def inquire(mhead, mbody) proceedsto = false proceedsto = true if mhead['subject'].start_with?('Returned Mail: ') proceedsto = true if mhead['subject'].start_with?('Mail Delivery Failure') proceedsto = true if Sisimai::String.aligned(mhead['from'], ['"Mail Deliver', 'System" ']) return nil if proceedsto == false 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 datestring = '' # (String) Date string 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 e.start_with?(MarkingsOf[:message][0]) next end next if (readcursor & Indicators[:deliverystatus]) == 0 || e.empty? # The original message was received at Thu, 29 Apr 2010 23:34:45 +0900 (JST) # from shironeko@example.jp # # ---The following addresses had delivery errors--- # # kijitora@example.co.jp [User unknown] v = dscontents[-1] if Sisimai::String.aligned(e, ['@', ' [', ']']) # kijitora@example.co.jp [User unknown] if v["recipient"] != "" # There are multiple recipient addresses in the message body. dscontents << Sisimai::Lhost.DELIVERYSTATUS v = dscontents[-1] end p1 = e.index(' ') p2 = e.index(']') v['recipient'] = e[0, p1] v['diagnosis'] = e[p1 + 2, p2 - p1 - 2] recipients += 1 elsif e.start_with?(MarkingsOf[:message][0]) # The original message was received at Thu, 29 Apr 2010 23:34:45 +0900 (JST) datestring = e[MarkingsOf[:message][0].size, e.size] end end return nil if recipients == 0 dscontents.each do |e| e['date'] = datestring || '' end return {"ds" => dscontents, "rfc822" => emailparts[1]} end |