don't send more than 1 reply per day to auto-generated emails

This commit is contained in:
Régis Hanol
2016-06-28 16:42:05 +02:00
parent 1411eedad3
commit 214f5bff5c
8 changed files with 30 additions and 94 deletions

View File

@ -13,7 +13,6 @@ module Email
class ScreenedEmailError < 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
@ -82,8 +81,7 @@ module Email
if is_auto_generated?
@incoming_email.update_columns(is_auto_generated: true)
raise AutoGeneratedEmailReplyError if check_reply_to_auto_generated_header
raise AutoGeneratedEmailError if SiteSetting.block_auto_generated_emails?
raise AutoGeneratedEmailError if SiteSetting.block_auto_generated_emails?
end
if action = subscription_action_for(body, subject)
@ -151,20 +149,20 @@ module Email
if bounce_key && (email_log = EmailLog.find_by(bounce_key: bounce_key))
email_log.update_columns(bounced: true)
email = email_log.user.try(:email) || @from_email
if email.present?
if @mail.error_status.present?
if @mail.error_status.start_with?("4.")
Email::Receiver.update_bounce_score(email, SOFT_BOUNCE_SCORE)
elsif @mail.error_status.start_with?("5.")
Email::Receiver.update_bounce_score(email, HARD_BOUNCE_SCORE)
end
elsif is_auto_generated?
if email.present? && @mail.error_status.present?
if @mail.error_status.start_with?("4.")
Email::Receiver.update_bounce_score(email, SOFT_BOUNCE_SCORE)
else @mail.error_status.start_with?("5.")
Email::Receiver.update_bounce_score(email, HARD_BOUNCE_SCORE)
end
end
end
end
if is_auto_generated?
Email::Receiver.update_bounce_score(@from_email, SOFT_BOUNCE_SCORE)
end
true
end
@ -534,20 +532,6 @@ 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