aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-10-30 17:44:11 -0400
committerGeorge Claghorn <george@basecamp.com>2018-10-30 17:44:11 -0400
commitc474daefb18e9bab96f6f0bb0bb30dfc00058cb3 (patch)
treea0baefe64e6f304de78f45f6c29f6de7bf98b863 /lib
parentec1ad80b0b1b5652459b41957f345779a4d4c246 (diff)
downloadrails-c474daefb18e9bab96f6f0bb0bb30dfc00058cb3.tar.gz
rails-c474daefb18e9bab96f6f0bb0bb30dfc00058cb3.tar.bz2
rails-c474daefb18e9bab96f6f0bb0bb30dfc00058cb3.zip
Validate address on route definition
Diffstat (limited to 'lib')
-rw-r--r--lib/action_mailbox/router/route.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/action_mailbox/router/route.rb b/lib/action_mailbox/router/route.rb
index e123a93bb1..34cc684381 100644
--- a/lib/action_mailbox/router/route.rb
+++ b/lib/action_mailbox/router/route.rb
@@ -1,10 +1,10 @@
class ActionMailbox::Router::Route
- class InvalidAddressError < StandardError; end
-
attr_reader :address, :mailbox_name
def initialize(address, to:)
@address, @mailbox_name = address, to
+
+ ensure_valid_address
end
def match?(inbound_email)
@@ -16,7 +16,7 @@ class ActionMailbox::Router::Route
when Proc
address.call(inbound_email)
else
- address.try(:match?, inbound_email) || raise(InvalidAddressError)
+ address.match?(inbound_email)
end
end
@@ -25,6 +25,12 @@ class ActionMailbox::Router::Route
end
private
+ def ensure_valid_address
+ unless [ String, Regexp, Proc ].any? { |klass| address.is_a?(klass) } || address.respond_to?(:match?)
+ raise ArgumentError, "Expected a String, Regexp, Proc, or matchable, got #{address.inspect}"
+ end
+ end
+
def recipients_from(mail)
Array(mail.to) + Array(mail.cc) + Array(mail.bcc)
end