Class: Protege::Gateway::Mail::MessageId
- Inherits:
-
Object
- Object
- Protege::Gateway::Mail::MessageId
- Defined in:
- lib/protege/gateway/mail/message_id.rb
Overview
Value object representing an RFC 5322 Message-ID.
Instances are frozen on construction; equality is based on the
normalized string value. Construct via the factory methods —
.parse, .synthetic, or .ensure — rather than .new.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Normalized message-id string (always angle-bracketed).
Class Method Summary collapse
-
.ensure(value) ⇒ MessageId
Parse
value, or fall back to a synthetic id when it is missing. -
.parse(value) ⇒ MessageId
Parse a raw value into a normalized, angle-bracketed
MessageId. -
.synthetic(domain: 'protege.local') ⇒ MessageId
Build a unique synthetic
MessageIdfor inputs that lack one.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare by normalized value.
-
#hash ⇒ Integer
Hash by normalized value so a
MessageIdworks as a Hash key. -
#initialize(value) ⇒ MessageId
constructor
Wrap a pre-normalized value and freeze.
-
#to_s ⇒ String
Return the normalized string value.
Constructor Details
#initialize(value) ⇒ MessageId
Wrap a pre-normalized value and freeze. Prefer the factory methods.
73 74 75 76 |
# File 'lib/protege/gateway/mail/message_id.rb', line 73 def initialize(value) @value = value freeze end |
Instance Attribute Details
#value ⇒ Object (readonly)
Normalized message-id string (always angle-bracketed).
68 69 70 |
# File 'lib/protege/gateway/mail/message_id.rb', line 68 def value @value end |
Class Method Details
.ensure(value) ⇒ MessageId
Parse value, or fall back to a synthetic id when it is missing.
47 48 49 50 51 |
# File 'lib/protege/gateway/mail/message_id.rb', line 47 def ensure(value) return synthetic if value.nil? || value.to_s.strip.empty? parse(value) end |
.parse(value) ⇒ MessageId
Parse a raw value into a normalized, angle-bracketed MessageId.
Trims surrounding whitespace and preserves case. Already-bracketed values pass through; half-bracketed values lose the stray bracket before being re-wrapped.
26 27 28 |
# File 'lib/protege/gateway/mail/message_id.rb', line 26 def parse(value) new(normalize(value)) end |
.synthetic(domain: 'protege.local') ⇒ MessageId
Build a unique synthetic MessageId for inputs that lack one.
The domain should be the real sending domain for outbound mail, so the Message-ID is
well-formed and recipients (e.g. Gmail) trust it and thread replies. It defaults to
protege.local only for the inbound/console fallback case, where the id is internal and
never travels back out.
39 40 41 |
# File 'lib/protege/gateway/mail/message_id.rb', line 39 def synthetic(domain: 'protege.local') new("<synthetic.#{SecureRandom.uuid}@#{domain}>") end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare by normalized value.
82 83 84 |
# File 'lib/protege/gateway/mail/message_id.rb', line 82 def ==(other) other.is_a?(MessageId) && @value == other.value end |
#hash ⇒ Integer
Hash by normalized value so a MessageId works as a Hash key.
91 92 93 |
# File 'lib/protege/gateway/mail/message_id.rb', line 91 def hash @value.hash end |
#to_s ⇒ String
Return the normalized string value.
98 99 100 |
# File 'lib/protege/gateway/mail/message_id.rb', line 98 def to_s @value end |