1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/action_mailroom/mailbox.rb

41 lines
779 B
Ruby
Raw Normal View History

require "active_support/rescuable"
2018-09-18 19:42:38 -04:00
require "action_mailroom/mailbox/callbacks"
class ActionMailroom::Mailbox
2018-09-18 19:42:38 -04:00
include ActiveSupport::Rescuable, Callbacks
2018-09-17 20:49:47 -04:00
class << self
def receive(inbound_email)
new(inbound_email).perform_processing
2018-09-17 20:49:47 -04:00
end
def routing(routes)
@router = ActionMailroom::Router.new(routes)
end
end
attr_reader :inbound_email
delegate :mail, to: :inbound_email
def initialize(inbound_email)
@inbound_email = inbound_email
end
def perform_processing
inbound_email.processing!
2018-09-18 19:42:38 -04:00
run_callbacks :process do
process
end
inbound_email.delivered!
rescue => exception
inbound_email.failed!
rescue_with_handler(exception) || raise
end
2018-09-17 20:49:47 -04:00
def process
# Overwrite in subclasses
2018-09-17 20:49:47 -04:00
end
end