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

Handle all recipients of an email as part of the routing

This commit is contained in:
David Heinemeier Hansson 2018-09-25 16:58:00 -07:00
parent 96b6e7ce66
commit 1087d70182
2 changed files with 17 additions and 3 deletions

View file

@ -10,9 +10,9 @@ class ActionMailroom::Router::Route
def match?(inbound_email)
case address
when String
inbound_email.mail.to.include?(address)
recipients_from(inbound_email.mail).include?(address)
when Regexp
inbound_email.mail.to.detect { |recipient| address.match?(recipient) }
recipients_from(inbound_email.mail).detect { |recipient| address.match?(recipient) }
when Proc
address.call(inbound_email)
else
@ -23,4 +23,9 @@ class ActionMailroom::Router::Route
def mailbox_class
"#{mailbox_name.to_s.capitalize}Mailbox".constantize
end
private
def recipients_from(mail)
Array(mail.to) + Array(mail.cc) + Array(mail.bcc)
end
end

View file

@ -32,7 +32,16 @@ module ActionMailroom
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
assert_equal inbound_email.mail, $processed_mail
end
test "single string routing on cc" do
@router.add_routes("first@example.com" => :first)
inbound_email = create_inbound_email_from_mail(to: "someone@example.com", cc: "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