From e97755ab5de5707b3fb1e4d2759c51a98b79ab69 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 29 Jan 2015 17:23:10 +0530 Subject: [PATCH] FIX: remove custom Discourse headers in email --- lib/email/sender.rb | 6 +++--- spec/components/email/sender_spec.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/email/sender.rb b/lib/email/sender.rb index 14f249f3362..d1720aedd98 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -117,9 +117,9 @@ module Email email_log.reply_key = reply_key if reply_key.present? # Remove headers we don't need anymore - @message.header['X-Discourse-Topic-Id'] = nil - @message.header['X-Discourse-Post-Id'] = nil - @message.header['X-Discourse-Reply-Key'] = nil + @message.header['X-Discourse-Topic-Id'] = nil if topic_id.present? + @message.header['X-Discourse-Post-Id'] = nil if post_id.present? + @message.header['X-Discourse-Reply-Key'] = nil if reply_key.present? # Suppress images from short emails if SiteSetting.strip_images_from_short_emails && @message.html_part.body.to_s.bytesize <= SiteSetting.short_email_length && @message.html_part.body =~ /]+>/ diff --git a/spec/components/email/sender_spec.rb b/spec/components/email/sender_spec.rb index e8d34b38f65..55f56e4c351 100644 --- a/spec/components/email/sender_spec.rb +++ b/spec/components/email/sender_spec.rb @@ -87,6 +87,24 @@ describe Email::Sender do Then { expect(message.header['Precedence']).to be_present } end + context "removes custom Discourse headers from topic notification mails" do + before do + message.header['X-Discourse-Topic-Id'] = 5577 + end + + When { email_sender.send } + Then { expect(message.header['X-Discourse-Topic-Id']).not_to be_present } + Then { expect(message.header['X-Discourse-Post-Id']).not_to be_present } + Then { expect(message.header['X-Discourse-Reply-Key']).not_to be_present } + end + + context "removes custom Discourse headers from digest/registration/other mails" do + When { email_sender.send } + Then { expect(message.header['X-Discourse-Topic-Id']).not_to be_present } + Then { expect(message.header['X-Discourse-Post-Id']).not_to be_present } + Then { expect(message.header['X-Discourse-Reply-Key']).not_to be_present } + end + context 'email logs' do let(:email_log) { EmailLog.last }