FIX: Auto-generated emails causing group SMTP email storm (#16372)

When emailing a group inbox and including other support-type
emails (or even just regular ones with autoresponders) in the
CC field, each automated reply to the group inbox triggered
more emails to be sent out to all CC addresses to notify them
of the new reply, which in turn caused more automated emails
to be sent to the group inbox.

This commit fixes the issue by preventing any emails being sent
by the PostAlerter when the new post has an incoming email record
which is_auto_generated, which we detect in Email::Receiver.
This commit is contained in:
Martin Brennan 2022-04-05 13:18:49 +10:00 committed by GitHub
parent e03593d75c
commit b982992ef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -719,6 +719,13 @@ class PostAlerter
# email to the user who was just added by CC. In this case the OP probably # email to the user who was just added by CC. In this case the OP probably
# replied and CC'd some people, and they are the only other topic users. # replied and CC'd some people, and they are the only other topic users.
return if post.incoming_email.cc_addresses_split.include?(to_address) return if post.incoming_email.cc_addresses_split.include?(to_address)
# We don't want to create an email storm if someone emails the group and
# CC's 50 support addresses from various places, which all then respond
# with auto-responders saying they have received our email. Any auto-generated
# emails should not propagate notifications to anyone else, not even
# the regular topic user notifications.
return email_addresses.dup.uniq if post.incoming_email.is_auto_generated?
end end
# Send a single email using group SMTP settings to cut down on the # Send a single email using group SMTP settings to cut down on the

View File

@ -1710,6 +1710,16 @@ describe PostAlerter do
) )
end end
it "does not send a group smtp email for anyone if the reply post originates from an incoming email that is auto generated" do
incoming_email_post = create_post_with_incoming
topic = incoming_email_post.topic
post = Fabricate(:post, topic: topic)
Fabricate(:incoming_email, post: post, topic: topic, is_auto_generated: true)
expect_not_enqueued_with(job: :group_smtp_email) do
expect { PostAlerter.new.after_save_post(post, true) }.to change { ActionMailer::Base.deliveries.size }.by(0)
end
end
it "skips sending a notification email to the group and all other email addresses that are _not_ members of the group, it "skips sending a notification email to the group and all other email addresses that are _not_ members of the group,
sends a group_smtp_email instead" do sends a group_smtp_email instead" do
NotificationEmailer.enable NotificationEmailer.enable