Class: Resend::ActionMailbox::MessageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/resend/action_mailbox/message_builder.rb

Overview

Rebuilds the full RFC 822 source of a received email so it can be ingested by Action Mailbox.

Resend's email.received webhook only carries metadata, so the message is fetched from the Received Emails API. When the API exposes a raw message download it is used as-is; otherwise the message is reconstructed as a Mail::Message from its parts, downloading each attachment through the attachments API.

Constant Summary collapse

STRUCTURAL_HEADERS =

Headers that describe the reconstructed MIME structure and therefore cannot be copied verbatim from the original message.

%w[content-type content-transfer-encoding mime-version].freeze
ENVELOPE_FIELDS =

Envelope fields that are set from the API response when the original header of the same name is not available.

%i[from to cc bcc reply_to subject message_id].freeze

Instance Method Summary collapse

Constructor Details

#initialize(email_id) ⇒ MessageBuilder

Returns a new instance of MessageBuilder.

Parameters:

  • email_id (String) —

    The ID of the received email



25
26
27
# File 'lib/resend/action_mailbox/message_builder.rb', line 25

def initialize(email_id)
  @email_id = email_id
end

Instance Method Details

#raw_email ⇒ String

Returns the full RFC 822 source of the received email.

Returns:

  • (String) —

    the full RFC 822 source of the received email



30
31
32
# File 'lib/resend/action_mailbox/message_builder.rb', line 30

def raw_email
  raw_download || rebuild_message.to_s
end