Skip to content

A platform for community discussion. Free, open, simple.

FIX: Disallow replies to categories when reply by email disabled (#33641)

Ted Johanssone05ef50c709a
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb
index d188b420a59..137e281ef2b 100644
--- a/lib/email/receiver.rb
+++ b/lib/email/receiver.rb
@@ -870,7 +870,7 @@ module Email
return group if group
category = Category.find_by_email(address)
- return category if category
+ return category if category && SiteSetting.reply_by_email_enabled?
end
# reply
diff --git a/spec/lib/email/processor_spec.rb b/spec/lib/email/processor_spec.rb
index 5099edac38c..f486d58acb1 100644
--- a/spec/lib/email/processor_spec.rb
+++ b/spec/lib/email/processor_spec.rb
@@ -140,6 +140,10 @@ RSpec.describe Email::Processor do
end
describe "from reply to email address" do
+ SiteSetting.reply_by_email_address = "reply+%{reply_key}@bar.com"
+ SiteSetting.manual_polling_enabled = true
+ SiteSetting.reply_by_email_enabled = true
+
let(:mail) do
"Date: Fri, 15 Jan 2016 00:12:43 +0100\nFrom: [email protected]\nTo: [email protected]\nSubject: FOO BAR\n\nFoo foo bar bar?"
end
diff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rb
index 1f7c2626d06..636ee1f3818 100644
--- a/spec/lib/email/receiver_spec.rb
+++ b/spec/lib/email/receiver_spec.rb
@@ -7,6 +7,8 @@ RSpec.describe Email::Receiver do
SiteSetting.email_in = true
SiteSetting.reply_by_email_address = "reply+%{reply_key}@bar.com"
SiteSetting.alternative_reply_by_email_addresses = "alt+%{reply_key}@bar.com"
+ SiteSetting.manual_polling_enabled = true
+ SiteSetting.reply_by_email_enabled = true
end
def process(email_name, opts = {})
@@ -1785,23 +1787,49 @@ RSpec.describe Email::Receiver do
end
end
- describe "check_address" do
- before { SiteSetting.reply_by_email_address = "foo+%{reply_key}@bar.com" }
+ describe "#check_address" do
+ context "when e-mail is associated with a reply key" do
+ before { SiteSetting.reply_by_email_address = "foo+%{reply_key}@bar.com" }
- it "returns nil when the key is invalid" do
- expect(Email::Receiver.check_address("[email protected]")).to be_nil
- expect(
- Email::Receiver.check_address("[email protected]"),
- ).to be_nil
+ it "returns nil when the key is invalid" do
+ expect(Email::Receiver.check_address("[email protected]")).to be_nil
+ expect(
+ Email::Receiver.check_address("[email protected]"),
+ ).to be_nil
+ end
+
+ context "with a valid reply" do
+ it "returns the destination when the key is valid" do
+ post_reply_key = Fabricate(:post_reply_key, reply_key: "4f97315cc828096c9cb34c6f1a0d6fe8")
+
+ dest = Email::Receiver.check_address("[email protected]")
+
+ expect(dest).to eq(post_reply_key)
+ end
+ end
end
- context "with a valid reply" do
- it "returns the destination when the key is valid" do
- post_reply_key = Fabricate(:post_reply_key, reply_key: "4f97315cc828096c9cb34c6f1a0d6fe8")
+ context "when address is associated with a category" do
+ fab!(:category) { Fabricate(:category, email_in: "[email protected]") }
+
+ context "when replying by email is enabled" do
+ it "returns the destination category" do
+ SiteSetting.reply_by_email_enabled = true
- dest = Email::Receiver.check_address("[email protected]")
+ dest = described_class.check_address("[email protected]")
- expect(dest).to eq(post_reply_key)
+ expect(dest).to eq(category)
+ end
+ end
+
+ context "when replying by email is disabled" do
+ it "returns nil" do
+ SiteSetting.reply_by_email_enabled = false
+
+ dest = described_class.check_address("[email protected]")
+
+ expect(dest).to be_nil
+ end
end
end
end