From f799b8bfb1af20275bc7bc9af1362192aa6dd699 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 8 Dec 2021 11:17:20 +0000 Subject: [PATCH] FIX: Ensure MessageIdService can handle hostname changes and multisite (#15231) --- lib/email/message_id_service.rb | 6 +++--- spec/lib/message_id_service_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/email/message_id_service.rb b/lib/email/message_id_service.rb index a3ba96424ae..4143d00d8de 100644 --- a/lib/email/message_id_service.rb +++ b/lib/email/message_id_service.rb @@ -80,11 +80,11 @@ module Email end def message_id_post_id_regexp - @message_id_post_id_regexp ||= Regexp.new "topic/\\d+/(\\d+|\\d+\.\\w+)@#{Regexp.escape(host)}" + Regexp.new "topic/\\d+/(\\d+|\\d+\.\\w+)@#{Regexp.escape(host)}" end def message_id_topic_id_regexp - @message_id_topic_id_regexp ||= Regexp.new "topic/(\\d+|\\d+\.\\w+)@#{Regexp.escape(host)}" + Regexp.new "topic/(\\d+|\\d+\.\\w+)@#{Regexp.escape(host)}" end def message_id_rfc_format(message_id) @@ -100,7 +100,7 @@ module Email end def host - @host ||= Email::Sender.host_for(Discourse.base_url) + Email::Sender.host_for(Discourse.base_url) end end end diff --git a/spec/lib/message_id_service_spec.rb b/spec/lib/message_id_service_spec.rb index 65077ca5818..3b8a581faac 100644 --- a/spec/lib/message_id_service_spec.rb +++ b/spec/lib/message_id_service_spec.rb @@ -120,4 +120,12 @@ describe Email::MessageIdService do expect(Email::MessageIdService.message_id_clean(message_id)).to eq(message_id) end end + + describe "#host" do + it "handles hostname changes at runtime" do + expect(Email::MessageIdService.host).to eq("test.localhost") + SiteSetting.force_hostname = "other.domain.example.com" + expect(Email::MessageIdService.host).to eq("other.domain.example.com") + end + end end