2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

Merge pull request #4148 from tgxworld/dont_reply_to_emails_that_are_autogenerated

FIX: Don't send rejection mailer to bounced emails.
This commit is contained in:
Régis Hanol 2016-04-13 15:36:14 +02:00
commit 4d9c81fde7
10 changed files with 188 additions and 13 deletions

View file

@ -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
@ -424,6 +428,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