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/router.rb
David Heinemeier Hansson b25948bd50 Make an email that fails to deliver to a mailbox as bounced
Probably need a way to either provide more email on the nature of a bounce or have a separate status code for "undeliverable".
2018-09-27 16:44:41 -07:00

36 lines
721 B
Ruby

class ActionMailroom::Router
class RoutingError < StandardError; end
def initialize
@routes = []
end
def add_routes(routes)
routes.each do |(address, mailbox_name)|
add_route address, to: mailbox_name
end
end
def add_route(address, to:)
routes.append Route.new(address, to: to)
end
def route(inbound_email)
if mailbox = match_to_mailbox(inbound_email)
mailbox.receive(inbound_email)
else
inbound_email.bounced!
raise RoutingError
end
end
private
attr_reader :routes
def match_to_mailbox(inbound_email)
routes.detect { |route| route.match?(inbound_email) }.try(:mailbox_class)
end
end
require "action_mailroom/router/route"