diff --git a/app/assets/javascripts/admin/controllers/admin-email-advanced-test.js.es6 b/app/assets/javascripts/admin/controllers/admin-email-advanced-test.js.es6 new file mode 100644 index 00000000000..2f9084b3641 --- /dev/null +++ b/app/assets/javascripts/admin/controllers/admin-email-advanced-test.js.es6 @@ -0,0 +1,29 @@ +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; + +export default Ember.Controller.extend({ + email: null, + text: null, + elided: null, + format: null, + + actions: { + run() { + this.set("loading", true); + + ajax("/admin/email/advanced-test", { + type: "POST", + data: { email: this.get("email") } + }) + .then(data => { + this.setProperties({ + text: data.text, + elided: data.elided, + format: data.format + }); + }) + .catch(popupAjaxError) + .finally(() => this.set("loading", false)); + } + } +}); diff --git a/app/assets/javascripts/admin/routes/admin-route-map.js.es6 b/app/assets/javascripts/admin/routes/admin-route-map.js.es6 index 110ec6231b2..89adcfbb157 100644 --- a/app/assets/javascripts/admin/routes/admin-route-map.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-route-map.js.es6 @@ -31,6 +31,7 @@ export default function() { this.route("received"); this.route("rejected"); this.route("previewDigest", { path: "/preview-digest" }); + this.route("advancedTest", { path: "/advanced-test" }); } ); diff --git a/app/assets/javascripts/admin/templates/email-advanced-test.hbs b/app/assets/javascripts/admin/templates/email-advanced-test.hbs new file mode 100644 index 00000000000..2fc02adeadc --- /dev/null +++ b/app/assets/javascripts/admin/templates/email-advanced-test.hbs @@ -0,0 +1,25 @@ +

{{i18n 'admin.email.advanced_test.desc'}}

+ +
+ + {{textarea name="email" value=email class="advanced-test"}} + +
+ +{{#conditional-loading-spinner condition=loading}} + +{{#if format}} +
+
+

{{i18n 'admin.email.advanced_test.text'}}

+
{{{text}}}
+
+ +
+
+

{{i18n 'admin.email.advanced_test.elided'}}

+
{{{elided}}}
+
+{{/if}} + +{{/conditional-loading-spinner}} diff --git a/app/assets/javascripts/admin/templates/email.hbs b/app/assets/javascripts/admin/templates/email.hbs index 509d5d20813..b8a379d8ae8 100644 --- a/app/assets/javascripts/admin/templates/email.hbs +++ b/app/assets/javascripts/admin/templates/email.hbs @@ -1,6 +1,7 @@ {{#admin-nav}} {{nav-item route='adminEmail.index' label='admin.email.settings'}} {{nav-item route='adminEmail.previewDigest' label='admin.email.preview_digest'}} + {{nav-item route='adminEmail.advancedTest' label='admin.email.advanced_test.title'}} {{nav-item route='adminCustomizeEmailTemplates' label='admin.email.templates'}} {{nav-item route='adminEmail.sent' label='admin.email.sent'}} {{nav-item route='adminEmail.skipped' label='admin.email.skipped'}} diff --git a/app/assets/stylesheets/common/admin/emails.scss b/app/assets/stylesheets/common/admin/emails.scss index d7bb83c5def..6be0f2bb2e4 100644 --- a/app/assets/stylesheets/common/admin/emails.scss +++ b/app/assets/stylesheets/common/admin/emails.scss @@ -83,3 +83,15 @@ border-width: 1px; } } + +.email-advanced-test { + .admin-controls { + display: block; + } + + textarea { + width: 95%; + height: 150px; + font-family: monospace; + } +} diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index 59d91fbc0ad..a3a5499a1c0 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -89,6 +89,19 @@ class Admin::EmailController < Admin::AdminController render json: MultiJson.dump(html_content: renderer.html, text_content: renderer.text) end + def advanced_test + params.require(:email) + + receiver = Email::Receiver.new(params['email']) + text, elided, format = receiver.select_body + + render json: success_json.merge!( + text: text, + elided: elided, + format: format + ) + end + def send_digest params.require(:last_seen_at) params.require(:username) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index de7874f10de..e1cad513213 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3413,6 +3413,13 @@ en: settings: "Settings" templates: "Templates" preview_digest: "Preview Summary" + advanced_test: + title: "Advanced Test" + desc: "See how Discourse processes recieved emails. To be able to correctly process the email, please paste below the whole original email message." + email: "Original message" + run: "Run Test" + text: "Selected Text Body" + elided: "Elided Text" sending_test: "Sending test Email..." error: "ERROR - %{server_error}" test_error: "There was a problem sending the test email. Please double-check your mail settings, verify that your host is not blocking mail connections, and try again." diff --git a/config/routes.rb b/config/routes.rb index c83a0eb9f51..96cee5324de 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -159,6 +159,8 @@ Discourse::Application.routes.draw do get "send-digest" => "email#send_digest" get "smtp_should_reject" post "handle_mail" + get "advanced-test" + post "advanced-test" => "email#advanced_test" end end