Sha256: 6f34c799eba9dd1f5329aaafe0e2747bd14ee60a3999193ba0562a58a311eb19

Contents?: true

Size: 1.87 KB

Versions: 20

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

require "mail"

module ActionMailbox
  # The +InboundEmail+ is an Active Record that keeps a reference to the raw email stored in Active Storage
  # and tracks the status of processing. By default, incoming emails will go through the following lifecycle:
  #
  # * Pending: Just received by one of the ingress controllers and scheduled for routing.
  # * Processing: During active processing, while a specific mailbox is running its #process method.
  # * Delivered: Successfully processed by the specific mailbox.
  # * Failed: An exception was raised during the specific mailbox's execution of the +#process+ method.
  # * Bounced: Rejected processing by the specific mailbox and bounced to sender.
  #
  # Once the +InboundEmail+ has reached the status of being either +delivered+, +failed+, or +bounced+,
  # it'll count as having been +#processed?+. Once processed, the +InboundEmail+ will be scheduled for
  # automatic incineration at a later point.
  #
  # When working with an +InboundEmail+, you'll usually interact with the parsed version of the source,
  # which is available as a +Mail+ object from +#mail+. But you can also access the raw source directly
  # using the +#source+ method.
  #
  # Examples:
  #
  #   inbound_email.mail.from # => 'david@loudthinking.com'
  #   inbound_email.source # Returns the full rfc822 source of the email as text
  class InboundEmail < Record
    self.table_name = "action_mailbox_inbound_emails"

    include Incineratable, MessageId, Routable

    has_one_attached :raw_email
    enum status: %i[ pending processing delivered failed bounced ]

    def mail
      @mail ||= Mail.from_source(source)
    end

    def source
      @source ||= raw_email.download
    end

    def processed?
      delivered? || failed? || bounced?
    end
  end
end

ActiveSupport.run_load_hooks :action_mailbox_inbound_email, ActionMailbox::InboundEmail

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
actionmailbox-6.1.4.7 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.4.6 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.4.5 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.4.4 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.4.3 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.4.2 app/models/action_mailbox/inbound_email.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/actionmailbox-6.1.4.1/app/models/action_mailbox/inbound_email.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/actionmailbox-6.1.4.1/app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.4.1 app/models/action_mailbox/inbound_email.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/actionmailbox-6.1.4/app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.4 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.3.2 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.3.1 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.3 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.2.1 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.2 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.1 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.0 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.0.rc2 app/models/action_mailbox/inbound_email.rb
actionmailbox-6.1.0.rc1 app/models/action_mailbox/inbound_email.rb