From 19133af0571cbd800b8e43d56af6908a251d27d2 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Mon, 19 Jun 2023 18:52:00 +0530 Subject: [PATCH] FIX: don't add "Re:" prefix in email subject for first post of group PMs. (#22175) Previously, it will add a "Re:" prefix to all the emails passing through the group SMTP mailer. It's creating confusion while receiving the mail for the first time on a PM. --- app/mailers/group_smtp_mailer.rb | 2 +- spec/mailers/group_smtp_mailer_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/mailers/group_smtp_mailer.rb b/app/mailers/group_smtp_mailer.rb index 5d0fe11f7ad..5cd5836752a 100644 --- a/app/mailers/group_smtp_mailer.rb +++ b/app/mailers/group_smtp_mailer.rb @@ -40,7 +40,7 @@ class GroupSmtpMailer < ActionMailer::Base template: "user_notifications.user_posted_pm", use_topic_title_subject: true, topic_title: op_incoming_email&.subject || post.topic.title, - add_re_to_subject: true, + add_re_to_subject: !post.is_first_post?, locale: SiteSetting.default_locale, delivery_method_options: delivery_options, from: from_group.smtp_from_address, diff --git a/spec/mailers/group_smtp_mailer_spec.rb b/spec/mailers/group_smtp_mailer_spec.rb index 035ea1b7ef8..ecd6d945099 100644 --- a/spec/mailers/group_smtp_mailer_spec.rb +++ b/spec/mailers/group_smtp_mailer_spec.rb @@ -60,6 +60,28 @@ RSpec.describe GroupSmtpMailer do SiteSetting.reply_by_email_enabled = true end + it "sends an email for first post when IMAP is disabled" do + staged = Fabricate(:staged) + group.update(imap_enabled: false) + + PostCreator.create!( + user, + skip_validations: true, + title: "Hello from John", + archetype: Archetype.private_message, + target_usernames: staged.username, + target_group_names: group.name, + raw: raw, + ) + + expect(ActionMailer::Base.deliveries.size).to eq(1) + + sent_mail = ActionMailer::Base.deliveries[0] + expect(sent_mail.to).to contain_exactly(staged.email) + expect(sent_mail.subject).to eq("Hello from John") + expect(sent_mail.to_s).to include(raw) + end + it "sends an email as reply" do post = PostCreator.create(user, topic_id: receiver.incoming_email.topic.id, raw: raw)