FEATURE: send rejection email for unrecognized errors

This commit is contained in:
Leo McArdle
2017-07-21 18:24:31 +01:00
parent e1ce47a901
commit 407a23663d
4 changed files with 83 additions and 7 deletions

View File

@ -52,6 +52,7 @@ module Email
when ActiveRecord::Rollback then :email_reject_invalid_post
when Email::Receiver::InvalidPostAction then :email_reject_invalid_post_action
when Discourse::InvalidAccess then :email_reject_invalid_access
else :email_reject_unrecognized_error
end
template_args = {}
@ -63,6 +64,14 @@ module Email
template_args[:post_error] = e.message
end
if message_template == :email_reject_unrecognized_error
msg = "Unrecognized error type (#{e.class}: #{e.message}) when processing incoming email"
msg += "\n\nBacktrace:\n#{e.backtrace.map { |l| " #{l}" }.join("\n")}"
msg += "\n\nMail:\n#{mail_string}"
Rails.logger.error(msg)
end
if message_template
# inform the user about the rejection
message = Mail::Message.new(mail_string)
@ -76,18 +85,14 @@ module Email
if can_send_rejection_email?(message.from, message_template)
Email::Sender.new(client_message, message_template).send
end
else
msg = "Unrecognized error type (#{e.class}: #{e.message}) when processing incoming email"
msg += "\n\nBacktrace:\n#{e.backtrace.map { |l| " #{l}" }.join("\n")}"
msg += "\n\nMail:\n#{mail_string}"
Rails.logger.error(msg)
end
client_message
end
def can_send_rejection_email?(email, type)
return true if type == :email_reject_unrecognized_error
key = "rejection_email:#{email}:#{type}:#{Date.today}"
if $redis.setnx(key, "1")