Module: Sisimai::Lhost::Domino

Defined in:
lib/sisimai/lhost/domino.rb

Overview

Sisimai::Lhost::Domino decodes a bounce email which created by HCL Domino www.hcl-software.com/domino. 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: ['Your message']}.freeze
MessagesOf =
{
  "userunknown" => [
    "not listed in Domino Directory",
    "not listed in public Name & Address Book",
    "non répertorié dans l'annuaire Domino",
    "no se encuentra en el Directorio de Domino",
    "Domino ディレクトリには見つかりません",
  ],
}.freeze

Class Method Summary collapse

Class Method Details

.descriptionObject



138
# File 'lib/sisimai/lhost/domino.rb', line 138

def description; return 'IBM Domino Server'; end

.inquire(mhead, mbody) ⇒ Hash, Nil

This method is abstract.

Decodes the bounce message from HCL Domino (formerly IBM Domino Server (formerly Lotus Domino))

Parameters:

  • mhead (Hash)

    Message headers of a bounce email

  • mbody (String)

    Message body of a bounce email

Returns:

  • (Hash)

    Bounce data list and message/rfc822 part

  • (Nil)

    it failed to decode or the arguments are missing



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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/sisimai/lhost/domino.rb', line 26

def inquire(mhead, mbody)
  return nil if mhead['subject'].start_with?('DELIVERY FAILURE:', 'DELIVERY_FAILURE:') == false

  require 'sisimai/rfc1123'
  require 'sisimai/rfc1894'
  fieldtable = Sisimai::RFC1894.FIELDTABLE
  permessage = {}     # (Hash) Store values of each Per-Message field

  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
  subjecttxt = ''     # (String) The value of Subject:

  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.
    next if e.empty?

    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

    # Your message
    #
    #   Subject: Test Bounce
    #
    # was not delivered to:
    #
    #   kijitora@example.net
    #
    # because:
    #
    #   User some.name (kijitora@example.net) not listed in Domino Directory
    #
    v = dscontents[-1]

    if e.start_with?('was not delivered to:')
      # was not delivered to:
      #   kijitora@example.net
      if v["recipient"] != ""
        # There are multiple recipient addresses in the message body.
        dscontents << Sisimai::Lhost.DELIVERYSTATUS
        v = dscontents[-1]
      end
      v['recipient'] = e if v["recipient"].empty?
      recipients += 1

    elsif e.start_with?('  ') && e.include?('@') && e.index(' ', 3).nil?
      # Continued from the line "was not delivered to:"
      #   kijitora@example.net
      v['recipient'] = Sisimai::Address.s3s4(e[2, e.size])

    elsif e.start_with?('because:')
      # because:
      #   User some.name (kijitora@example.net) not listed in Domino Directory
      v['diagnosis'] = e
    else
      if v['diagnosis'] == "because:"
        # Error message, continued from the line "because:"
        v['diagnosis'] = e

      elsif e.start_with?('  Subject: ')
        #   Subject: Nyaa
        subjecttxt = e[11, e.size]

      else
        # Other fields defined in RFC3464
        f = Sisimai::RFC1894.match(e); next if f < 1
        o = Sisimai::RFC1894.field(e); next if o.nil?
        next if o[3] == 'addr'

        if o[3] == 'code'
          # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown
          v['spec']      = o[1] if v['spec'].empty?
          v['diagnosis'] = o[2] if v['diagnosis'].empty?
        else
          # Other DSN fields defined in RFC3464
          next if fieldtable[o[0]].nil?
          next if o[3] == "host" && Sisimai::RFC1123.is_internethost(o[2]) == false
          v[fieldtable[o[0]]] = o[2]

          next if f != 1
          permessage[fieldtable[o[0]]] = o[2]
        end
      end
    end
  end
  return nil if recipients == 0

  dscontents.each do |e|
    e['recipient'] = Sisimai::Address.s3s4(e['recipient'])
    permessage.each_key { |a| e[a] ||= permessage[a] || '' }

    MessagesOf.each_key do |r|
      # Check each regular expression of Domino error messages
      next if MessagesOf[r].none? { |a| e['diagnosis'].include?(a) }
      e['reason'] = r
      e['status'] = Sisimai::SMTP::Status.code(r, false) if e["status"].empty?
      break
    end
  end

  # Set the value of subjecttxt as a Subject if there is no original message in the bounce mail.
  emailparts[1] += "Subject: #{subjecttxt}\n" if emailparts[1].include?("\nSubject:") == false

  return {"ds" => dscontents, "rfc822" => emailparts[1]}
end