Class: MailBounce::Report
- Inherits:
-
Object
- Object
- MailBounce::Report
- 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]*:/- 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
- #any? ⇒ Boolean
-
#for(address = nil) ⇒ Object
One unnamed recipient may stand in for any address; a named report only for the address it names.
-
#initialize(raw) ⇒ Report
constructor
A new instance of Report.
- #recipients ⇒ Object
Constructor Details
#initialize(raw) ⇒ Report
Returns a new instance of Report.
30 31 32 33 34 |
# File 'lib/mailbounce/report.rb', line 30 def initialize(raw) @mail = Mail.new(raw.to_s) rescue StandardError @mail = nil end |
Class Method Details
.parse(raw) ⇒ Object
26 27 28 |
# File 'lib/mailbounce/report.rb', line 26 def self.parse(raw) new(raw) end |
Instance Method Details
#any? ⇒ Boolean
50 51 52 |
# File 'lib/mailbounce/report.rb', line 50 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.
42 43 44 45 46 47 48 |
# File 'lib/mailbounce/report.rb', line 42 def for(address = nil) if named = recipients.find { |recipient| recipient.addressed_to?(address) } named else sole_recipient_for(address) end end |
#recipients ⇒ Object
36 37 38 |
# File 'lib/mailbounce/report.rb', line 36 def recipients @recipients ||= reported_blocks.map { |block| recipient_from(block) } end |