diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 75fb3e9bfc7..ba5fdb9a4cb 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -346,6 +346,7 @@ module Email return { type: :reply, obj: email_log } if email_log end end + nil end def process_destination(destination, user, body, elided) diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index 3242e55a414..fc531423cea 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -555,4 +555,26 @@ describe Email::Receiver do end + context "check_address" do + before do + SiteSetting.reply_by_email_address = "foo+%{reply_key}@bar.com" + end + + it "returns nil when the key is invalid" do + expect(Email::Receiver.check_address('fake@fake.com')).to be_nil + expect(Email::Receiver.check_address('foo+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com')).to be_nil + end + + context "with a valid reply" do + it "returns the destination when the key is valid" do + Fabricate(:email_log, reply_key: '4f97315cc828096c9cb34c6f1a0d6fe8') + + dest = Email::Receiver.check_address('foo+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com') + expect(dest).to be_present + expect(dest[:type]).to eq(:reply) + expect(dest[:obj]).to be_present + end + end + end + end