FEATURE: Limit maximum recipients for group emails (#17971)

New maximum_recipients_per_new_group_email site setting can be used to
prevent spam group emails with many recipients.
This commit is contained in:
Bianca Nenciu
2022-08-18 18:18:58 +03:00
committed by GitHub
parent e49167b311
commit b082f459c9
6 changed files with 77 additions and 0 deletions

View File

@ -33,6 +33,14 @@ module Email
class OldDestinationError < ProcessingError; end
class ReplyToDigestError < ProcessingError; end
class TooManyRecipientsError < ProcessingError
attr_reader :recipients_count
def initialize(recipients_count:)
@recipients_count = recipients_count
end
end
attr_reader :incoming_email
attr_reader :raw_email
attr_reader :mail
@ -156,6 +164,11 @@ module Email
raise UserNotFoundError unless SiteSetting.enable_staged_users
end
recipients = get_all_recipients(@mail)
if recipients.size > SiteSetting.maximum_recipients_per_new_group_email
raise TooManyRecipientsError.new(recipients_count: recipients.size)
end
body, elided = select_body
body ||= ""
@ -230,6 +243,23 @@ module Email
raise SilencedUserError if user.silenced?
end
def get_all_recipients(mail)
recipients = Set.new
%i(to cc bcc).each do |field|
next if mail[field].blank?
mail[field].each do |address_field|
begin
address_field.decoded
recipients << address_field.address.downcase
end
end
end
recipients
end
def is_bounce?
@mail.bounced? || bounce_key
end