mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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
|
Email::Receiver.new(mail_string).process
|
||||||
rescue => e
|
rescue => e
|
||||||
message_template = nil
|
message_template = nil
|
||||||
|
template_args = {}
|
||||||
case e
|
case e
|
||||||
when Email::Receiver::UserNotSufficientTrustLevelError
|
when Email::Receiver::UserNotSufficientTrustLevelError
|
||||||
message_template = :email_reject_trust_level
|
message_template = :email_reject_trust_level
|
||||||
@ -39,8 +40,13 @@ module Jobs
|
|||||||
when ActiveRecord::Rollback
|
when ActiveRecord::Rollback
|
||||||
message_template = :email_reject_post_error
|
message_template = :email_reject_post_error
|
||||||
when Email::Receiver::InvalidPost
|
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
|
message_template = :email_reject_post_error
|
||||||
|
else
|
||||||
|
message_template = :email_reject_post_error_specified
|
||||||
|
template_args[:post_error] = e.message
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
message_template = nil
|
message_template = nil
|
||||||
end
|
end
|
||||||
@ -48,7 +54,10 @@ module Jobs
|
|||||||
if message_template
|
if message_template
|
||||||
# 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_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
|
Email::Sender.new(client_message, message_template).send
|
||||||
else
|
else
|
||||||
Discourse.handle_exception(e, error_context(@args, "Unrecognized error type when processing incoming email", mail: mail_string))
|
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
|
class RejectionMailer < ActionMailer::Base
|
||||||
include Email::BuildEmailHelper
|
include Email::BuildEmailHelper
|
||||||
|
|
||||||
def send_rejection(message_from, message_body, message_subject, forum_address, template)
|
DISALLOWED_TEMPLATE_ARGS = [:to, :from, :site_name, :base_url,
|
||||||
build_email(message_from,
|
:user_preferences_url,
|
||||||
template: "system_messages.#{template}",
|
:include_respond_instructions, :html_override,
|
||||||
source: message_body,
|
:add_unsubscribe_link, :respond_instructions,
|
||||||
former_title: message_subject,
|
:style, :body, :post_id, :topic_id, :subject,
|
||||||
destination: forum_address)
|
: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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1419,7 +1419,18 @@ en:
|
|||||||
text_body_template: |
|
text_body_template: |
|
||||||
We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.
|
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:
|
email_reject_reply_key:
|
||||||
subject_template: "Email issue -- Bad Reply Key"
|
subject_template: "Email issue -- Bad Reply Key"
|
||||||
|
@ -49,7 +49,7 @@ module Email
|
|||||||
return unless html_override = @opts[:html_override]
|
return unless html_override = @opts[:html_override]
|
||||||
if @opts[:add_unsubscribe_link]
|
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
|
respond_instructions = PrettyText.cook(response_instructions).html_safe
|
||||||
html_override.gsub!("%{respond_instructions}", respond_instructions)
|
html_override.gsub!("%{respond_instructions}", respond_instructions)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user