FIX: information about reply via email is removed (#13)

FIX: information about reply via email is removed (#13)

When we send email notifications about the encrypted private message - instruction that user can respond via email should be removed.

In addition, the message should be sent from no-reply email address.

diff --git a/app/mailers/user_notifications_extensions.rb b/app/mailers/user_notifications_extensions.rb
new file mode 100644
index 0000000..03f440c
--- /dev/null
+++ b/app/mailers/user_notifications_extensions.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+module UserNotificationsExtensions
+  def notification_email(user, opts)
+    opts[:allow_reply_by_email] = false if opts[:post] && opts[:post].is_encrypted?
+    super
+  end
+end
diff --git a/plugin.rb b/plugin.rb
index f35663f..d018a4c 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -30,6 +30,7 @@ after_initialize do
   load File.expand_path('../lib/topics_controller_extensions.rb', __FILE__)
   load File.expand_path('../lib/user_extensions.rb', __FILE__)
   load File.expand_path('../lib/email_sender_extensions.rb', __FILE__)
+  load File.expand_path('../app/mailers/user_notifications_extensions.rb', __FILE__)
 
   class DiscourseEncrypt::Engine < Rails::Engine
     engine_name DiscourseEncrypt::PLUGIN_NAME
@@ -49,11 +50,12 @@ after_initialize do
   end
 
   reloadable_patch do |plugin|
-    Post.class_eval             { prepend PostExtensions }
-    Topic.class_eval            { prepend TopicExtensions }
-    TopicsController.class_eval { prepend TopicsControllerExtensions }
-    User.class_eval             { prepend UserExtensions }
-    Email::Sender.class_eval    { prepend EmailSenderExtensions }
+    Post.class_eval              { prepend PostExtensions }
+    Topic.class_eval             { prepend TopicExtensions }
+    TopicsController.class_eval  { prepend TopicsControllerExtensions }
+    User.class_eval              { prepend UserExtensions }
+    Email::Sender.class_eval     { prepend EmailSenderExtensions }
+    UserNotifications.class_eval { prepend UserNotificationsExtensions }
   end
 
   # Send plugin-specific topic data to client via serializers.
diff --git a/spec/lib/email_sender_spec.rb b/spec/lib/email_sender_spec.rb
index 966282b..fad9ffc 100644
--- a/spec/lib/email_sender_spec.rb
+++ b/spec/lib/email_sender_spec.rb
@@ -3,6 +3,16 @@
 require 'rails_helper'
 
 describe Email::Sender do
+  before do
+    POP3PollingEnabledSettingValidator.any_instance.stubs(:authentication_works?).returns(true)
+    SiteSetting.pop3_polling_host = "localhost"
+    SiteSetting.pop3_polling_username = "test"
+    SiteSetting.pop3_polling_password = "test"
+    SiteSetting.pop3_polling_enabled = true
+    SiteSetting.reply_by_email_address = "test+%{reply_key}@example.com"
+    SiteSetting.reply_by_email_enabled = true
+  end
+
   fab!(:small_pdf) do
     SiteSetting.authorized_extensions = 'pdf'
     UploadCreator.new(file_from_fixtures("small.pdf", "pdf"), "small.pdf")
@@ -32,11 +42,13 @@ describe Email::Sender do
       )
     end
 
-    it "removes attachments from the email" do
+    it "removes attachments from the email and does not allow to respond via email" do
       SiteSetting.email_total_attachment_size_limit_kb = 10_000
       Email::Sender.new(message, :valid_type).send
 
       expect(message.attachments.length).to eq(0)
+      expect(message.reply_to).to eq(["noreply@test.localhost"])
+      expect(message.body.raw_source).not_to match("or reply to this email to respond")
     end
   end
 
@@ -61,11 +73,13 @@ describe Email::Sender do
       )
     end
 
-    it "adds non-image uploads as attachments to the email" do
+    it "adds non-image uploads as attachments to the email and allows to respond via email" do
       SiteSetting.email_total_attachment_size_limit_kb = 10_000
       Email::Sender.new(message, :valid_type).send
 
       expect(message.attachments.length).to eq(1)
+      expect(message.reply_to).to eq(["test+%{reply_key}@example.com"])
+      expect(message.body.raw_source).to match("or reply to this email to respond")
     end
   end
 end

GitHub sha: 1f09e180

This commit appears in #13 which was approved by eviltrout. It was merged by lis2.