More detailed email rejection responses

This commit is contained in:
riking 2014-06-23 17:16:56 -07:00
parent edc17dddb3
commit d2823fc5ee
3 changed files with 65 additions and 20 deletions

View file

@ -22,23 +22,36 @@ module Jobs
begin begin
mail_string = mail.pop mail_string = mail.pop
Email::Receiver.new(mail_string).process Email::Receiver.new(mail_string).process
rescue Email::Receiver::UserNotSufficientTrustLevelError rescue => e
# inform the user about the rejection # inform the user about the rejection
message = Mail::Message.new(mail_string) message = Mail::Message.new(mail_string)
client_message = RejectionMailer.send_trust_level(message.from, message.body) message_template = nil
Email::Sender.new(client_message, :email_reject_trust_level).send case e
rescue Email::Receiver::ProcessingError => e when Email::Receiver::UserNotSufficientTrustLevelError
Rails.logger.error e message_template = :email_reject_trust_level
message = Mail::Message.new(mail_string) when Email::Receiver::UserNotFoundError
client_message = RejectionMailer.send_rejection(message.from, message.body, e.message) message_template = :email_reject_no_account
when Email::Receiver::EmptyEmailError
message_template = :email_reject_empty
when Email::Receiver::EmailUnparsableError
message_template = :email_reject_parsing
when ActiveRecord::Rollback
message_template = :email_reject_post_error
else
nil
end
# inform admins about the error if message_template
data = { limit_once_per: false, message_params: { source: mail, error: e }} # Send message to the user
GroupMessage.create(Group[:admins].name, :email_error_notification, data) client_message = RejectionMailer.send_rejection(message.from, message.body, message_template.to_s, "#{e.message}\n\n#{e.backtrace.join("\n")}")
rescue StandardError => e Email::Sender.new(client_message, message_template).send
# inform admins about the error else
data = { limit_once_per: false, message_params: { source: mail, error: e }} Rails.logger.error e
GroupMessage.create(Group[:admins].name, :email_error_notification, data)
# If not known type, inform admins about the error
data = { limit_once_per: false, message_params: { from: message.from, source: message.body, error: "#{e.message}\n\n#{e.backtrace.join("\n")}" }}
GroupMessage.create(Group[:admins].name, :email_error_notification, data)
end
ensure ensure
mail.delete mail.delete
end end

View file

@ -3,11 +3,11 @@ require_dependency 'email/message_builder'
class RejectionMailer < ActionMailer::Base class RejectionMailer < ActionMailer::Base
include Email::BuildEmailHelper include Email::BuildEmailHelper
def send_rejection(from, body, error) def send_rejection(from, body, template, error)
build_email(from, template: 'email_error_notification', error: "#{error.message}\n\n#{error.backtrace.join("\n")}", source: body) build_email(from, template: template, error: error, source: body)
end end
def send_trust_level(from, body) def send_trust_level(from, template)
build_email(from, template: 'email_reject_trust_level') build_email(from, template: 'email_reject_trust_level')
end end
end end

View file

@ -1302,9 +1302,13 @@ en:
text_body_template: | text_body_template: |
This is an automated message. This is an automated message.
Parsing an incoming email failed. Please review the following Error: Parsing an incoming email from `%{from}` failed. Please review the following Error:
`%{error}` ---
%{error}
---
The original message follows. The original message follows.
@ -1313,12 +1317,40 @@ en:
%{source} %{source}
email_reject_trust_level: email_reject_trust_level:
subject_template: "Message rejected" subject_template: "Message rejected: Insufficient Trust Level"
text_body_template: | text_body_template: |
The message you've send to %{to} was rejected by the system. The message you've send to %{to} was rejected by the system.
You do not have the required trust to post new topics to this email address. You do not have the required trust to post new topics to this email address.
email_reject_no_account:
subject_template: "Message rejected: No Account"
text_body_template: |
The message you've send to %{to} was rejected by the system.
You do not have an account on the forum with this email address.
email_reject_empty:
subject_template: "Message rejected: No Content"
text_body_template: |
The message you've send to %{to} was rejected by the system.
There was no recognized content in the email.
email_reject_parsing:
subject_template: "Message rejected: Unparsable"
text_body_template: |
The message you've send to %{to} was rejected by the system.
The encoding was unknown or not supported. Try sending in UTF-8 plain text.
email_reject_post_error:
subject_template: "Message rejected: Posting error"
text_body_template: |
The message you've send to %{to} was rejected by the system.
The Markdown could not be processed.
too_many_spam_flags: too_many_spam_flags:
subject_template: "New account blocked" subject_template: "New account blocked"
text_body_template: | text_body_template: |