mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
FIX: Don't send rejection mailer to bounced emails.
This commit is contained in:
parent
2ecff60af2
commit
5734c7f3f3
10 changed files with 188 additions and 13 deletions
|
@ -17,6 +17,9 @@ module Email
|
|||
class MessageBuilder
|
||||
attr_reader :template_args
|
||||
|
||||
REPLY_TO_AUTO_GENERATED_HEADER_KEY = "X-Discourse-Reply-to-Auto-Generated".freeze
|
||||
REPLY_TO_AUTO_GENERATED_HEADER_VALUE = "marked".freeze
|
||||
|
||||
def initialize(to, opts=nil)
|
||||
@to = to
|
||||
@opts = opts || {}
|
||||
|
@ -132,7 +135,11 @@ module Email
|
|||
def header_args
|
||||
result = {}
|
||||
if @opts[:add_unsubscribe_link]
|
||||
result['List-Unsubscribe'] = "<#{template_args[:user_preferences_url]}>" if @opts[:add_unsubscribe_link]
|
||||
result['List-Unsubscribe'] = "<#{template_args[:user_preferences_url]}>"
|
||||
end
|
||||
|
||||
if @opts[:mark_as_reply_to_auto_generated]
|
||||
result[REPLY_TO_AUTO_GENERATED_HEADER_KEY] = REPLY_TO_AUTO_GENERATED_HEADER_VALUE
|
||||
end
|
||||
|
||||
result['X-Discourse-Post-Id'] = @opts[:post_id].to_s if @opts[:post_id]
|
||||
|
|
|
@ -12,6 +12,8 @@ module Email
|
|||
class EmptyEmailError < ProcessingError; end
|
||||
class UserNotFoundError < ProcessingError; end
|
||||
class AutoGeneratedEmailError < ProcessingError; end
|
||||
class AutoGeneratedEmailReplyError < ProcessingError; end
|
||||
class BouncedEmailError < ProcessingError; end
|
||||
class NoBodyDetectedError < ProcessingError; end
|
||||
class InactiveUserError < ProcessingError; end
|
||||
class BlockedUserError < ProcessingError; end
|
||||
|
@ -62,6 +64,8 @@ module Email
|
|||
body, @elided = select_body
|
||||
body ||= ""
|
||||
|
||||
raise BouncedEmailError if (@mail.bounced? && !@mail.retryable?)
|
||||
raise AutoGeneratedEmailReplyError if check_reply_to_auto_generated_header
|
||||
raise AutoGeneratedEmailError if is_auto_generated?
|
||||
raise NoBodyDetectedError if body.blank? && !@mail.has_attachments?
|
||||
raise InactiveUserError if !user.active && !user.staged
|
||||
|
@ -422,6 +426,20 @@ module Email
|
|||
!topic.topic_allowed_groups.where("group_id IN (SELECT group_id FROM group_users WHERE user_id = ?)", user.id).exists?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_reply_to_auto_generated_header
|
||||
headers = Mail::Header.new(@mail.body.to_s.gsub("\r\n\r\n", "\r\n")).to_a
|
||||
|
||||
index = headers.find_index do |f|
|
||||
f.name == Email::MessageBuilder::REPLY_TO_AUTO_GENERATED_HEADER_KEY
|
||||
end
|
||||
|
||||
if index
|
||||
headers[index].value == Email::MessageBuilder::REPLY_TO_AUTO_GENERATED_HEADER_VALUE
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue