Skip to content

Commit 215249a

Browse files
authored
Merge pull request rails#52734 from jorge-d/fix/postmark_inbound_original_recipient
Implement postmark conversion of OriginalRecipient to X-Original-To
2 parents 9b5b8b4 + dfcbce8 commit 215249a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

actionmailbox/app/controllers/action_mailbox/ingresses/postmark/inbound_emails_controller.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Ingresses::Postmark::InboundEmailsController < ActionMailbox::BaseControll
4949
param_encoding :create, "RawEmail", Encoding::ASCII_8BIT
5050

5151
def create
52-
ActionMailbox::InboundEmail.create_and_extract_message_id! params.require("RawEmail")
52+
ActionMailbox::InboundEmail.create_and_extract_message_id! mail
5353
rescue ActionController::ParameterMissing => error
5454
logger.error <<~MESSAGE
5555
#{error.message}
@@ -59,5 +59,12 @@ def create
5959
MESSAGE
6060
head :unprocessable_entity
6161
end
62+
63+
private
64+
def mail
65+
params.require("RawEmail").tap do |raw_email|
66+
raw_email.prepend("X-Original-To: ", params.require("OriginalRecipient"), "\n") if params.key?("OriginalRecipient")
67+
end
68+
end
6269
end
6370
end

actionmailbox/test/controllers/ingresses/postmark/inbound_emails_controller_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ class ActionMailbox::Ingresses::Postmark::InboundEmailsControllerTest < ActionDi
3131
assert_equal "[email protected]", inbound_email.message_id
3232
end
3333

34+
test "add X-Original-To to email from Postmark" do
35+
assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do
36+
post rails_postmark_inbound_emails_url,
37+
headers: { authorization: credentials }, params: {
38+
RawEmail: file_fixture("../files/welcome.eml").read,
39+
OriginalRecipient: "[email protected]",
40+
}
41+
end
42+
43+
assert_response :no_content
44+
45+
inbound_email = ActionMailbox::InboundEmail.last
46+
mail = Mail.from_source(inbound_email.raw_email.download)
47+
assert_equal "[email protected]", mail.header["X-Original-To"].decoded
48+
end
49+
3450
test "rejecting when RawEmail param is missing" do
3551
assert_no_difference -> { ActionMailbox::InboundEmail.count } do
3652
post rails_postmark_inbound_emails_url,

0 commit comments

Comments
 (0)