Class: MailBounce::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/mailbounce/report.rb

Overview

Machine-readable half of a bounce (RFC 3464). Unreadable input reports nothing.

Constant Summary collapse

DELIVERY_STATUS_TYPES =

RFC 6533 adds the global type for internationalized addresses.

%w[ message/delivery-status message/global-delivery-status ].freeze
BLANK_LINE =

RFC 3464 §2.1.

/\r?\n[ \t]*\r?\n/
FIELD_NAME =
/\A(?<name>[A-Za-z][A-Za-z0-9\-]*)[ \t]*:/
MAX_SIZE =

A bounce is a notice, not a mailbox — Postfix caps its own at 50 KB. Anything past this is not a report anyone meant to send.

1024 * 1024
FIELDS =

Value stays on its line so an empty field cannot swallow the next.

{
  action: /^Action[ \t]*:[ \t]*(?<value>.+)$/i,
  status: /^Status[ \t]*:[ \t]*(?<value>.+)$/i,
  final_recipient: /^Final-Recipient[ \t]*:[ \t]*(?<value>.+)$/i,
  original_recipient: /^Original-Recipient[ \t]*:[ \t]*(?<value>.+)$/i,
  diagnostic_code: /^Diagnostic-Code[ \t]*:[ \t]*(?<value>.+)$/i,
  remote_mta: /^Remote-MTA[ \t]*:[ \t]*(?<value>.+)$/i
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, max_size: MAX_SIZE) ⇒ Report

Returns a new instance of Report.



35
36
37
38
39
40
41
# File 'lib/mailbounce/report.rb', line 35

def initialize(raw, max_size: MAX_SIZE)
  report = raw.to_s

  @mail = Mail.new(report) if report.bytesize <= max_size
rescue StandardError
  @mail = nil
end

Class Method Details

.parse(raw, max_size: MAX_SIZE) ⇒ Object



31
32
33
# File 'lib/mailbounce/report.rb', line 31

def self.parse(raw, max_size: MAX_SIZE)
  new(raw, max_size: max_size)
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/mailbounce/report.rb', line 57

def any?
  recipients.any?
end

#for(address = nil) ⇒ Object

One unnamed recipient may stand in for any address; a named report only for the address it names.



49
50
51
52
53
54
55
# File 'lib/mailbounce/report.rb', line 49

def for(address = nil)
  if named = recipients.find { |recipient| recipient.addressed_to?(address) }
    named
  else
    sole_recipient_for(address)
  end
end

#recipientsObject



43
44
45
# File 'lib/mailbounce/report.rb', line 43

def recipients
  @recipients ||= reported_blocks.map { |block| recipient_from(block) }
end