Add X-Original-To to mail using Mailgun recipient (#38738)

Expose the Mailgun SMTP recipient to Action Mailbox as X-Original-To, like Postfix.

Allows handling BCCed recipients who aren't listed in To/CC fields.
This commit is contained in:
Rikki Pitt 2020-03-24 01:10:48 +00:00 committed by GitHub
parent fc4ef77d47
commit 667d69cc5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* Mailgun ingress now passes through the envelope recipient as `X-Original-To`.
*Rikki Pitt*
* Deprecate `Rails.application.credentials.action_mailbox.api_key` and `MAILGUN_INGRESS_API_KEY` in favor of `Rails.application.credentials.action_mailbox.signing_key` and `MAILGUN_INGRESS_SIGNING_KEY`.
*Matthijs Vos*

View File

@ -46,10 +46,16 @@ module ActionMailbox
before_action :authenticate
def create
ActionMailbox::InboundEmail.create_and_extract_message_id! params.require("body-mime")
ActionMailbox::InboundEmail.create_and_extract_message_id! mail
end
private
def mail
params.require("body-mime").tap do |raw_email|
raw_email.prepend("X-Original-To: ", params.require(:recipient), "\n") if params.key?(:recipient)
end
end
def authenticate
head :unauthorized unless authenticated?
end

View File

@ -25,6 +25,25 @@ class ActionMailbox::Ingresses::Mailgun::InboundEmailsControllerTest < ActionDis
assert_equal "0CB459E0-0336-41DA-BC88-E6E28C697DDB@37signals.com", inbound_email.message_id
end
test "add X-Original-To to email from Mailgun" do
assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do
travel_to "2018-10-09 15:15:00 EDT"
post rails_mailgun_inbound_emails_url, params: {
timestamp: 1539112500,
token: "7VwW7k6Ak7zcTwoSoNm7aTtbk1g67MKAnsYLfUB7PdszbgR5Xi",
signature: "ef24c5225322217bb065b80bb54eb4f9206d764e3e16abab07f0a64d1cf477cc",
"body-mime" => file_fixture("../files/welcome.eml").read,
recipient: "replies@example.com"
}
end
assert_response :no_content
inbound_email = ActionMailbox::InboundEmail.last
mail = Mail.from_source(inbound_email.raw_email.download)
assert_equal "replies@example.com", mail.header["X-Original-To"].decoded
end
test "rejecting a delayed inbound email from Mailgun" do
assert_no_difference -> { ActionMailbox::InboundEmail.count } do
travel_to "2018-10-09 15:26:00 EDT"