A platform for community discussion. Free, open, simple.
FEATURE: new 'should_add_email_attachments' plugin modifier
Régis Hanol54a59be6176d
diff --git a/lib/email/sender.rb b/lib/email/sender.rbindex 43f473889b5..5ec4acd8dac 100644--- a/lib/email/sender.rb+++ b/lib/email/sender.rb@@ -360,6 +360,8 @@ module Emailemail_size = 0posts.each do |post|+ next unless DiscoursePluginRegistry.apply_modifier(:should_add_email_attachments, post)+post.uploads.each do |original_upload|optimized_1X = original_upload.optimized_images.firstdiff --git a/spec/lib/email/sender_spec.rb b/spec/lib/email/sender_spec.rbindex 830865a068c..31bc8651753 100644--- a/spec/lib/email/sender_spec.rb+++ b/spec/lib/email/sender_spec.rb@@ -561,6 +561,20 @@ RSpec.describe Email::Sender do)end+ context "with a plugin" do+ before { DiscoursePluginRegistry.clear_modifiers! }+ after { DiscoursePluginRegistry.clear_modifiers! }++ it "allows plugins to control whether attachments are included" do+ SiteSetting.email_total_attachment_size_limit_kb = 10_000++ Plugin::Instance.new.register_modifier(:should_add_email_attachments) { false }++ Email::Sender.new(message, :valid_type).send+ expect(message.attachments.size).to eq(0)+ end+ end+it "adds only non-image uploads as attachments to the email" doSiteSetting.email_total_attachment_size_limit_kb = 10_000Email::Sender.new(message, :valid_type).send