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

Compare addresses case-insensitively

This commit is contained in:
George Claghorn 2018-10-03 20:44:31 -04:00
parent a91dc46b32
commit 015c33f4cd
2 changed files with 11 additions and 2 deletions

View file

@ -10,9 +10,9 @@ class ActionMailbox::Router::Route
def match?(inbound_email)
case address
when String
recipients_from(inbound_email.mail).include?(address)
recipients_from(inbound_email.mail).any? { |recipient| address.casecmp?(recipient) }
when Regexp
recipients_from(inbound_email.mail).detect { |recipient| address.match?(recipient) }
recipients_from(inbound_email.mail).any? { |recipient| address.match?(recipient) }
when Proc
address.call(inbound_email)
else

View file

@ -49,6 +49,15 @@ module ActionMailbox
assert_equal inbound_email.mail, $processed_mail
end
test "single string routing case-insensitively" do
@router.add_routes("first@example.com" => :first)
inbound_email = create_inbound_email_from_mail(to: "FIRST@example.com", subject: "This is a reply")
@router.route inbound_email
assert_equal "FirstMailbox", $processed_by
assert_equal inbound_email.mail, $processed_mail
end
test "multiple string routes" do
@router.add_routes("first@example.com" => :first, "second@example.com" => :second)