Module: Sisimai

Defined in:
lib/sisimai/version.rb,
lib/sisimai.rb,
lib/sisimai/arf.rb,
lib/sisimai/lda.rb,
lib/sisimai/fact.rb,
lib/sisimai/mail.rb,
lib/sisimai/smtp.rb,
lib/sisimai/time.rb,
lib/sisimai/lhost.rb,
lib/sisimai/order.rb,
lib/sisimai/rhost.rb,
lib/sisimai/reason.rb,
lib/sisimai/rfc791.rb,
lib/sisimai/string.rb,
lib/sisimai/address.rb,
lib/sisimai/message.rb,
lib/sisimai/rfc1123.rb,
lib/sisimai/rfc1894.rb,
lib/sisimai/rfc2045.rb,
lib/sisimai/rfc3464.rb,
lib/sisimai/rfc3834.rb,
lib/sisimai/rfc5322.rb,
lib/sisimai/rfc5965.rb,
lib/sisimai/datetime.rb,
lib/sisimai/fact/json.rb,
lib/sisimai/fact/yaml.rb,
lib/sisimai/mail/mbox.rb,
lib/sisimai/rhost/aol.rb,
lib/sisimai/rhost/cox.rb,
lib/sisimai/rhost/iua.rb,
lib/sisimai/mail/stdin.rb,
lib/sisimai/rhost/kddi.rb,
lib/sisimai/rhost/zoho.rb,
lib/sisimai/smtp/reply.rb,
lib/sisimai/mail/memory.rb,
lib/sisimai/rhost/apple.rb,
lib/sisimai/smtp/status.rb,
lib/sisimai/mail/maildir.rb,
lib/sisimai/rhost/google.rb,
lib/sisimai/rhost/gsuite.rb,
lib/sisimai/smtp/command.rb,
lib/sisimai/smtp/failure.rb,
lib/sisimai/reason/onhold.rb,
lib/sisimai/rhost/godaddy.rb,
lib/sisimai/rhost/outlook.rb,
lib/sisimai/rhost/tencent.rb,
lib/sisimai/reason/blocked.rb,
lib/sisimai/reason/expired.rb,
lib/sisimai/reason/suspend.rb,
lib/sisimai/rhost/facebook.rb,
lib/sisimai/rhost/mimecast.rb,
lib/sisimai/rhost/spectrum.rb,
lib/sisimai/rhost/yahooinc.rb,
lib/sisimai/reason/feedback.rb,
lib/sisimai/reason/filtered.rb,
lib/sisimai/reason/hasmoved.rb,
lib/sisimai/reason/rejected.rb,
lib/sisimai/reason/vacation.rb,
lib/sisimai/rhost/franceptt.rb,
lib/sisimai/rhost/microsoft.rb,
lib/sisimai/rhost/nttdocomo.rb,
lib/sisimai/smtp/transcript.rb,
lib/sisimai/reason/delivered.rb,
lib/sisimai/reason/notaccept.rb,
lib/sisimai/reason/undefined.rb,
lib/sisimai/rhost/cloudflare.rb,
lib/sisimai/reason/norelaying.rb,
lib/sisimai/reason/requireptr.rb,
lib/sisimai/reason/suppressed.rb,
lib/sisimai/reason/systemfull.rb,
lib/sisimai/rhost/messagelabs.rb,
lib/sisimai/reason/authfailure.rb,
lib/sisimai/reason/hostunknown.rb,
lib/sisimai/reason/mailboxfull.rb,
lib/sisimai/reason/mailererror.rb,
lib/sisimai/reason/ratelimited.rb,
lib/sisimai/reason/syntaxerror.rb,
lib/sisimai/reason/systemerror.rb,
lib/sisimai/reason/userunknown.rb,
lib/sisimai/rfc3464/thirdparty.rb,
lib/sisimai/reason/contenterror.rb,
lib/sisimai/reason/networkerror.rb,
lib/sisimai/reason/spamdetected.rb,
lib/sisimai/reason/badreputation.rb,
lib/sisimai/reason/emailtoolarge.rb,
lib/sisimai/reason/securityerror.rb,
lib/sisimai/reason/virusdetected.rb,
lib/sisimai/reason/failedstarttls.rb,
lib/sisimai/reason/notcompliantrfc.rb,
lib/sisimai/reason/policyviolation.rb

Overview

X.7.7 — Message integrity failure:(RFC 3463)

A transport system otherwise authorized to validate a message was unable to do so
because the message was corrupted or altered. This may be useful as a permanent,
transient persistent, or successful delivery code.

X.7.8 535 Trust relationship required:(RFC 4954)

554      This response to the AUTH command indicates that the authentication failed due to
         invalid or insufficient authentication credentials. In this case, the client
         SHOULD ask the user to supply new credentials (such as by presenting a password
         dialog box).

X.7.9 534 Authentication mechanism is too weak:(RFC 4954)

This response to the AUTH command indicates that the selected authentication
mechanism is weaker than server policy permits for that user. The client SHOULD
retry with a new authentication mechanism.

X.7.10 523 Encryption Needed:(RFC 5248)

This indicates that external strong privacy layer is needed in order to use the
requested authentication mechanism. This is primarily intended for use with clear
text authentication mechanisms. A client which receives this may activate a
security layer such as TLS prior to authenticating, or attempt to use a stronger
mechanism.

X.7.11 524 Encryption required for requested authentication mechanism:(RFC 4954)

538      This response to the AUTH command indicates that the selected authentication
         mechanism may only be used when the underlying SMTP connection is encrypted. Note
         that this response code is documented here for historical purposes only. Modern
         implementations SHOULD NOT advertise mechanisms that are not permitted due to lack
         of encryption, unless an encryption layer of sufficient strength is currently
         being employed.

X.7.12 422 A password transition is needed:(RFC 4954)

432      This response to the AUTH command indicates that the user needs to transition to
         the selected authentication mechanism. This is typically done by authenticating
         once using the [PLAIN] authentication mechanism. The selected mechanism SHOULD
         then work for authentications in subsequent sessions.

X.7.13 525 User Account Disabled:(RFC 5248)

Sometimes a system administrator will have to disable a user's account (e.g., due
to lack of payment, abuse, evidence of a break-in attempt, etc). This error code
occurs after a successful authentication to a disabled account. This informs the
client that the failure is permanent until the user contacts their system
administrator to get the account re-enabled. It differs from a generic
authentication failure where the client's best option is to present the passphrase
entry dialog in case the user simply mistyped their passphrase.

X.7.14 535 Trust relationship required:(RFC 5248)

554      The submission server requires a configured trust relationship with a third-party
         server in order to access the message content. This value replaces the prior use
         of X.7.8 for this error condition. thereby updating [RFC4468].

X.7.15 450 Priority Level is too low:(RFC6710)

550      The specified priority level is below the lowest priority acceptable for the
4xx      receiving SMTP server. This condition might be temporary, for example the server
5xx      is operating in a mode where only higher priority messages are accepted for
         transfer and delivery, while lower priority messages are rejected.

X.7.16 552 Message is too big for the specified priority:(RFC 6710)

4xx      The message is too big for the specified priority. This condition might be
5xx      temporary, for example the server is operating in a mode where only higher
         priority messages below certain size are accepted for transfer and delivery.

X.7.17 5xx Mailbox owner has changed:(RFC 7293)

This status code is returned when a message is received with a
Require-Recipient-Valid-Since field or RRVS extension and the receiving system is
able to determine that the intended recipient mailbox has not been under
continuous ownership since the specified date-time.

X.7.18 5xx Domain owner has changed:(RFC 7293)

This status code is returned when a message is received with a
Require-Recipient-Valid-Since field or RRVS extension and the receiving system
wishes to disclose that the owner of the domain name of the recipient has changed
since the specified date-time.

X.7.19 5xx RRVS test cannot be completed:(RFC 7293)

This status code is returned when a message is received with a
Require-Recipient-Valid-Since field or RRVS extension and the receiving system
cannot complete the requested evaluation because the required timestamp was not
recorded. The message originator needs to decide whether to reissue the message
without RRVS protection.

X.7.20 550 No passing DKIM signature found:(RFC 7372)

This status code is returned when a message did not contain any passing DKIM
signatures. (This violates the advice of Section 6.1 of [RFC6376].)

X.7.21 550 No acceptable DKIM signature found:(RFC 7372, 6476)

This status code is returned when a message contains one or more passing DKIM
signatures, but none are acceptable. (This violates the advice of Section 6.1 of
[RFC6376].)

X.7.22 550 No valid author-matched DKIM signature found:(RFC 7372)

This status code is returned when a message contains one or more passing DKIM
signatures, but none are acceptable because none have an identifier(s) that
matches the author address(es) found in the From header field. This is a special
case of X.7.21. (This violates the advice of Section 6.1 of [RFC6376].)

X.7.23 550 SPF validation failed:(RFC 7273, 7208)

This status code is returned when a message completed an SPF check that produced
a "fail" result, contrary to local policy requirements. Used in place of 5.7.1 as
described in Section 8.4 of [RFC7208].

X.7.24 451 SPF validation error:(RFC 7372, 7208)

550      This status code is returned when evaluation of SPF relative to an arriving
         message resulted in an error. Used in place of 4.4.3 or 5.5.2 as described in
         Sections 8.6 and 8.7 of [RFC7208].

X.7.25 550 Reverse DNS validation failed:(RFC 7372, 7601)

This status code is returned when an SMTP client's IP address failed a reverse
DNS validation check, contrary to local policy requirements.

X.7.26 550 Multiple authentication checks failed:(RFC 7372)

This status code is returned when a message failed more than one message
authentication check, contrary to local policy requirements. The particular
mechanisms that failed are not specified.

X.7.27 550 Sender address has null MX:(RFC 7505)

This status code is returned when the associated sender address has a null MX,
and the SMTP receiver is configured to reject mail from such sender
(e.g., because it could not return a DSN).

SAMPLES

554 5.5.0   No recipients have been specified
503 5.5.0   Valid RCPT TO required before BURL
554 5.6.3   Conversion required but not supported
554 5.3.4   Message too big for system
554 5.7.8   URL resolution requires trust relationship
552 5.2.2   Mailbox full
554 5.6.6   IMAP URL resolution failed
250 2.5.0   Waiting for additional BURL or BDAT commands
451 4.4.1   IMAP server unavailable
250 2.5.0   Ok.
250 2.6.4   MIME header conversion with loss performed
235 2.7.0   Authentication Succeeded
432 4.7.12  A password transition is needed
454 4.7.0   Temporary authentication failure
534 5.7.9   Authentication mechanism is too weak
535 5.7.8   Authentication credentials invalid
500 5.5.6   Authentication Exchange line is too long
530 5.7.0   Authentication required
538 5.7.11  Encryption required for requested authentication
    5.7.8   Authentication credentials invalid
    5.7.9   Authentication mechanism is too weak
    5.7.11  Encryption required for requested authentication mechanism

Defined Under Namespace

Modules: ARF, DateTime, LDA, Lhost, Message, Order, RFC1123, RFC1894, RFC2045, RFC3464, RFC3834, RFC5322, RFC5965, RFC791, Reason, Rhost, SMTP, String Classes: Address, Fact, Mail, Time

Constant Summary collapse

VERSION =
'5.7.0'.freeze

Class Method Summary collapse

Class Method Details

.dump(argv0, **argv1) ⇒ String

Wrapper method to decode mailbox/Maildir and dump as JSON

Parameters:

  • argv0 (String)

    Path to mbox or Maildir/

  • argv0 (Hash)

    or Hash (decoded JSON)

  • argv0 (IO)

    or STDIN object

  • argv1 (Hash)

    Options for decoding

Returns:

  • (String)

    Decoded data as JSON text



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sisimai.rb', line 63

def dump(argv0, **argv1)
  return "" unless argv0
  nyaan = Sisimai.rise(argv0, **argv1) || []

  if RUBY_PLATFORM.start_with?('java')
    # java-based ruby environment like JRuby.
    require 'jrjackson'
    jsonstring = JrJackson::Json.dump(nyaan)
  else
    require 'oj'
    jsonstring = Oj.dump(nyaan, :mode => :compat)
  end
  return jsonstring
end

.engineHash

Decoding engine list (MTA modules)

Returns:

  • (Hash)

    Decoding engine table



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/sisimai.rb', line 80

def engine
  table = {}

  %w[Lhost ARF RFC3464 RFC3834].each do |e|
    r = "Sisimai::#{e}"
    require r.gsub('::', '/').downcase

    if e == 'Lhost'
      # Sisimai::Lhost::*
      Module.const_get(r).send(:index).each do |ee|
        # Load and get the value of "description" from each module
        rr = "Sisimai::#{e}::#{ee}"
        require rr.gsub('::', '/').downcase
        table[rr.to_sym] = Module.const_get(rr).send(:description)
      end
    else
      # Sisimai::ARF, Sisimai::RFC3464, and Sisimai::RFC3834
      table[r.to_sym] = Module.const_get(r).send(:description)
    end
  end

  return table
end

.libnameObject



8
# File 'lib/sisimai.rb', line 8

def libname(); return 'Sisimai';        end

.match(argvs = '') ⇒ String

Try to match with message patterns

Parameters:

  • Error (String)

    message text

Returns:



126
127
128
129
130
# File 'lib/sisimai.rb', line 126

def match(argvs = '')
  return "" if argvs.empty?
  require 'sisimai/reason'
  return Sisimai::Reason.match(argvs.downcase)
end

.reasonHash

Reason list Sisimai can detect

Returns:

  • (Hash)

    Reason list table



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/sisimai.rb', line 106

def reason
  require 'sisimai/reason'
  table = {}
  names = Sisimai::Reason.index

  # These reasons are not included in the results of Sisimai::Reason.index
  names += %w[Delivered Feedback Undefined Vacation]
  while e = names.shift do
    # Call .description() method of Sisimai::Reason::*
    r = "Sisimai::Reason::#{e}"
    require r.gsub('::', '/').downcase
    table[e.to_sym] = Module.const_get(r).send(:description)
  end

  return table
end

.rise(argv0, **argv1) ⇒ Array?

Wrapper method for decoding mailbox/maidir

Parameters:

  • argv0 (String)

    Path to mbox or Maildir/

  • argv0 (Hash)

    or Hash (decoded JSON)

  • argv0 (IO)

    or STDIN object

  • argv1 (Hash)

    Options for decoding(delivered=false)

Returns:

  • (Array)

    Decoded objects

  • (nil)

    nil if the argument was wrong or an empty array



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
# File 'lib/sisimai.rb', line 20

def rise(argv0, **argv1)
  return nil unless argv0
  require 'sisimai/mail'
  require 'sisimai/fact'

  return nil unless mail = Sisimai::Mail.new(argv0)
  kind = mail.kind
  c___ = argv1[:c___].is_a?(Array) ? argv1[:c___] : [nil, nil]
  sisi = []

  while r = mail.data.read do
    # Read and decode each email file
    path = mail.data.path
    args = {data: r, hook: c___[0], origin: path, delivered: argv1[:delivered], vacation: argv1[:vacation]}
    fact = Sisimai::Fact.rise(**args) || []

    if c___[1]
      # Run the callback function specified with "c___" parameter of Sisimai.rise after reading
      # each email file in Maildir/ every time
      args = {'kind' => kind, 'mail' => r, 'path' => path, 'fact' => fact}
      begin
        c___[1].call(args) if c___[1].is_a?(Proc)
      rescue StandardError => ce
        warn ' ***warning: Something is wrong in the second element of the ":c___":' + ce.to_s
      end
    end

    sisi += fact if fact.empty? == false
  end

  return nil if sisi.empty?
  return sisi
end

.versionObject



7
# File 'lib/sisimai.rb', line 7

def version(); return Sisimai::VERSION; end