Pass rejection message along in rejection mail if present
This commit is contained in:
parent
23b237fd14
commit
d87edce6c3
|
@ -25,6 +25,7 @@ module Jobs
|
|||
Email::Receiver.new(mail_string).process
|
||||
rescue => e
|
||||
message_template = nil
|
||||
template_args = {}
|
||||
case e
|
||||
when Email::Receiver::UserNotSufficientTrustLevelError
|
||||
message_template = :email_reject_trust_level
|
||||
|
@ -39,8 +40,13 @@ module Jobs
|
|||
when ActiveRecord::Rollback
|
||||
message_template = :email_reject_post_error
|
||||
when Email::Receiver::InvalidPost
|
||||
# TODO there is a message in this exception, place it in email
|
||||
if e.message.length < 6
|
||||
message_template = :email_reject_post_error
|
||||
else
|
||||
message_template = :email_reject_post_error_specified
|
||||
template_args[:post_error] = e.message
|
||||
end
|
||||
|
||||
else
|
||||
message_template = nil
|
||||
end
|
||||
|
@ -48,7 +54,10 @@ module Jobs
|
|||
if message_template
|
||||
# inform the user about the rejection
|
||||
message = Mail::Message.new(mail_string)
|
||||
client_message = RejectionMailer.send_rejection(message.from, message.body, message.subject, message.to, message_template)
|
||||
template_args[:former_title] = message.subject
|
||||
template_args[:destination] = message.to
|
||||
|
||||
client_message = RejectionMailer.send_rejection(message_template, message.from, template_args)
|
||||
Email::Sender.new(client_message, message_template).send
|
||||
else
|
||||
Discourse.handle_exception(e, error_context(@args, "Unrecognized error type when processing incoming email", mail: mail_string))
|
||||
|
|
|
@ -3,12 +3,27 @@ require_dependency 'email/message_builder'
|
|||
class RejectionMailer < ActionMailer::Base
|
||||
include Email::BuildEmailHelper
|
||||
|
||||
def send_rejection(message_from, message_body, message_subject, forum_address, template)
|
||||
build_email(message_from,
|
||||
template: "system_messages.#{template}",
|
||||
source: message_body,
|
||||
former_title: message_subject,
|
||||
destination: forum_address)
|
||||
DISALLOWED_TEMPLATE_ARGS = [:to, :from, :site_name, :base_url,
|
||||
:user_preferences_url,
|
||||
:include_respond_instructions, :html_override,
|
||||
:add_unsubscribe_link, :respond_instructions,
|
||||
:style, :body, :post_id, :topic_id, :subject,
|
||||
:template, :allow_reply_by_email,
|
||||
:private_reply, :from_alias]
|
||||
|
||||
# Send an email rejection message.
|
||||
#
|
||||
# template - i18n key under system_messages
|
||||
# message_from - Who to send the rejection messsage to
|
||||
# template_args - arguments to pass to i18n for interpolation into the message
|
||||
# Certain keys are disallowed in template_args to avoid confusing the
|
||||
# BuildEmailHelper. You can see the list in DISALLOWED_TEMPLATE_ARGS.
|
||||
def send_rejection(template, message_from, template_args)
|
||||
if template_args.keys.any? { |k| DISALLOWED_TEMPLATE_ARGS.include? k }
|
||||
raise ArgumentError.new('Reserved key in template arguments')
|
||||
end
|
||||
|
||||
build_email(message_from, template_args.merge(template: "system_messages.#{template}"))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1419,7 +1419,18 @@ en:
|
|||
text_body_template: |
|
||||
We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.
|
||||
|
||||
Some possible causes are: complex formatting, message too large, message too small. Please try again.
|
||||
Some possible causes are: complex formatting, message too large, message too small. Please try again, or post via the website if this continues.
|
||||
|
||||
email_reject_post_error_specified:
|
||||
subject_template: "Email issue -- Posting error"
|
||||
text_body_template: |
|
||||
We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.
|
||||
|
||||
Rejection message:
|
||||
|
||||
%{post_error}
|
||||
|
||||
Please attempt to fix the errors and try again.
|
||||
|
||||
email_reject_reply_key:
|
||||
subject_template: "Email issue -- Bad Reply Key"
|
||||
|
|
|
@ -49,7 +49,7 @@ module Email
|
|||
return unless html_override = @opts[:html_override]
|
||||
if @opts[:add_unsubscribe_link]
|
||||
|
||||
if response_instructions = @template_args[:respond_instructions]
|
||||
if response_instructions = @opts[:respond_instructions]
|
||||
respond_instructions = PrettyText.cook(response_instructions).html_safe
|
||||
html_override.gsub!("%{respond_instructions}", respond_instructions)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue