Module: Sisimai::Lhost::Zoho
- Defined in:
- lib/sisimai/lhost/zoho.rb
Overview
Sisimai::Lhost::Zoho decodes a bounce email which created by Zoho Mail www.zoho.com/mail/. Methods in the module are called from only Sisimai::Message.
Constant Summary collapse
- Indicators =
Sisimai::Lhost.INDICATORS
- Boundaries =
['Received: from mail.zoho.com by mx.zohomail.com'].freeze
- StartingOf =
{message: ['This message was created automatically by mail delivery']}.freeze
Class Method Summary collapse
Class Method Details
.description ⇒ Object
92 |
# File 'lib/sisimai/lhost/zoho.rb', line 92 def description; return 'Zoho Mail: https://www.zoho.com'; end |
.inquire(mhead, mbody) ⇒ Hash, Nil
This method is abstract.
Decodes the bounce message from Zoho Mail
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 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sisimai/lhost/zoho.rb', line 17 def inquire(mhead, mbody) # X-ZohoMail: Si CHF_MF_NL SS_10 UW48 UB48 FMWL UW48 UB48 SGR3_1_09124_42 # X-Zoho-Virus-Status: 2 # X-Mailer: Zoho Mail return nil if mhead['x-zohomail'].nil? 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 qprintable = false 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?(StartingOf[:message][0]) next end next if (readcursor & Indicators[:deliverystatus]) == 0 || e.empty? # This message was created automatically by mail delivery software. # A message that you sent could not be delivered to one or more of its recip= # ients. This is a permanent error.=20 # # kijitora@example.co.jp Invalid Address, ERROR_CODE :550, ERROR_CODE :5.1.= # 1 <kijitora@example.co.jp>... User Unknown # This message was created automatically by mail delivery software. # A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. # # shironeko@example.org Invalid Address, ERROR_CODE :550, ERROR_CODE :Requested action not taken: mailbox unavailable v = dscontents[-1] if Sisimai::String.aligned(e, ['@', ' ', 'ERROR_CODE :']) # kijitora@example.co.jp Invalid Address, ERROR_CODE :550, ERROR_CODE :5.1.= if v["recipient"] != "" # There are multiple recipient addresses in the message body. dscontents << Sisimai::Lhost.DELIVERYSTATUS v = dscontents[-1] end v['recipient'] = e[0, e.index(' ')] v['diagnosis'] = e[e.index(' ') + 1, e.size] if v['diagnosis'].end_with?('=') # Quoted printable v['diagnosis'] = v['diagnosis'].chomp('=') qprintable = true end recipients += 1 elsif e.start_with?('[Status: ') && e.include?('<') && e.include?('>') # Expired # [Status: Error, Address: <kijitora@6kaku.example.co.jp>, ResponseCode 421, , Host not reachable.] 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('>', p1 + 2) v['recipient'] = Sisimai::Address.s3s4(e[p1, p2 - p1]) v['diagnosis'] = e recipients += 1 else # Continued line next if qprintable == false v['diagnosis'] += e end end return nil if recipients == 0 return {"ds" => dscontents, "rfc822" => emailparts[1]} end |