A platform for community discussion. Free, open, simple.
FEATURE: Add X-Discourse-Sender Header to outgoing mail (#33123)
Martin Brennanf05786607011
diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rbindex c8a94daa606..939e50274fb 100644--- a/lib/email/message_builder.rb+++ b/lib/email/message_builder.rb@@ -269,7 +269,7 @@ module Emailresult["X-Discourse-Topic-Id"] = @opts[:topic_id].to_s if @opts[:topic_id]result["X-Discourse-Topic-Ids"] = @opts[:topic_ids].join(",") if @opts[:topic_ids].present?- # at this point these have been filtered by the recipient's guardian for visibility,+ # At this point these have been filtered by the recipient's guardian for visibility,# see UserNotifications#send_notification_emailresult["X-Discourse-Tags"] = @template_args[:show_tags_in_subject] if @opts[:show_tags_in_subject@@ -278,7 +278,11 @@ module Email:show_category_in_subject]- # please, don't send us automatic responses...+ # Mimics X-GitHub-Sender, which identifies the GitHub user that originated the message,+ # useful to filter and prioritize mail.+ result["X-Discourse-Sender"] = @opts[:username] if @opts[:username].present?++ # Please, don't send us automatic responses...result["X-Auto-Response-Suppress"] = "All"if !allow_reply_by_email?diff --git a/spec/lib/email/message_builder_spec.rb b/spec/lib/email/message_builder_spec.rbindex c86a2c7a85d..ee8735afa73 100644--- a/spec/lib/email/message_builder_spec.rb+++ b/spec/lib/email/message_builder_spec.rb@@ -380,6 +380,7 @@ RSpec.describe Email::MessageBuilder dopost_id: 4567,show_tags_in_subject: "foo bar baz",show_category_in_subject: "random",+ username: "elbarto",}.merge(additional_opts),)end@@ -406,6 +407,10 @@ RSpec.describe Email::MessageBuilder doexpect(message_with_header_args.header_args["X-Discourse-Category"]).to eq("random")end+ it "passes through the username" do+ expect(message_with_header_args.header_args["X-Discourse-Sender"]).to eq("elbarto")+ end+context "when allow_reply_by_email is enabled " dolet(:additional_opts) { { allow_reply_by_email: true } }