Sha256: 0702f685489bacc05c021fa67ac071b77923e2469cb07ef908adbf9d023efefb

Contents?: true

Size: 928 Bytes

Versions: 74

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

module ActionMailbox
  # Encapsulates the routes that live on the ApplicationMailbox and performs the actual routing when
  # an inbound_email is received.
  class 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 = mailbox_for(inbound_email)
        mailbox.receive(inbound_email)
      else
        inbound_email.bounced!

        raise RoutingError
      end
    end

    def mailbox_for(inbound_email)
      routes.detect { |route| route.match?(inbound_email) }&.mailbox_class
    end

    private
      attr_reader :routes
  end
end

require "action_mailbox/router/route"

Version data entries

74 entries across 70 versions & 6 rubygems

Version Path
actionmailbox-7.0.8.6 lib/action_mailbox/router.rb
actionmailbox-6.1.7.10 lib/action_mailbox/router.rb
actionmailbox-6.1.7.9 lib/action_mailbox/router.rb
actionmailbox-7.0.8.5 lib/action_mailbox/router.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actionmailbox-7.0.8.4/lib/action_mailbox/router.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actionmailbox-7.0.5.1/lib/action_mailbox/router.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actionmailbox-7.0.5.1/lib/action_mailbox/router.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actionmailbox-7.0.5.1/lib/action_mailbox/router.rb
actionmailbox-7.0.8.4 lib/action_mailbox/router.rb
actionmailbox-6.1.7.8 lib/action_mailbox/router.rb
actionmailbox-7.0.8.1 lib/action_mailbox/router.rb
actionmailbox-6.1.7.7 lib/action_mailbox/router.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actionmailbox-7.0.3.1/lib/action_mailbox/router.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actionmailbox-7.0.2.3/lib/action_mailbox/router.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actionmailbox-6.1.6.1/lib/action_mailbox/router.rb
actionmailbox-7.0.8 lib/action_mailbox/router.rb
actionmailbox-7.0.7.2 lib/action_mailbox/router.rb
actionmailbox-6.1.7.6 lib/action_mailbox/router.rb
actionmailbox-7.0.7.1 lib/action_mailbox/router.rb
actionmailbox-6.1.7.5 lib/action_mailbox/router.rb