restore the 'incoming_email_prefer_html' site setting

This commit is contained in:
Régis Hanol 2017-04-27 14:31:11 +02:00
parent 304ace926e
commit 0ec15af970
4 changed files with 24 additions and 6 deletions

View File

@ -1308,6 +1308,7 @@ en:
reply_by_email_enabled: "Enable replying to topics via email." reply_by_email_enabled: "Enable replying to topics via email."
reply_by_email_address: "Template for reply by email incoming email address, for example: %{reply_key}@reply.example.com or replies+%{reply_key}@example.com" reply_by_email_address: "Template for reply by email incoming email address, for example: %{reply_key}@reply.example.com or replies+%{reply_key}@example.com"
alternative_reply_by_email_addresses: "List of alternative templates for reply by email incoming email addresses. Example: %{reply_key}@reply.example.com|replies+%{reply_key}@example.com" alternative_reply_by_email_addresses: "List of alternative templates for reply by email incoming email addresses. Example: %{reply_key}@reply.example.com|replies+%{reply_key}@example.com"
incoming_email_prefer_html: "Use the HTML instead of the text for incoming email."
disable_emails: "Prevent Discourse from sending any kind of emails" disable_emails: "Prevent Discourse from sending any kind of emails"

View File

@ -646,6 +646,7 @@ email:
pop3_polling_username: '' pop3_polling_username: ''
pop3_polling_password: '' pop3_polling_password: ''
log_mail_processing_failures: false log_mail_processing_failures: false
incoming_email_prefer_html: false
email_in: email_in:
default: false default: false
client: true client: true

View File

@ -188,17 +188,21 @@ module Email
text = fix_charset(@mail) text = fix_charset(@mail)
end end
if text.present? text, elided_text = if text.present?
text = trim_discourse_markers(text) text = trim_discourse_markers(text)
text, elided = EmailReplyTrimmer.trim(text, true) EmailReplyTrimmer.trim(text, true)
return [text, elided]
end end
if html.present? markdown, elided_markdown = if html.present?
markdown = HtmlToMarkdown.new(html).to_markdown markdown = HtmlToMarkdown.new(html).to_markdown
markdown = trim_discourse_markers(markdown) markdown = trim_discourse_markers(markdown)
markdown, elided = EmailReplyTrimmer.trim(markdown, true) EmailReplyTrimmer.trim(markdown, true)
return [markdown, elided] end
if text.blank? || (SiteSetting.incoming_email_prefer_html && markdown.present?)
return [markdown, elided_markdown]
else
return [text, elided_text]
end end
end end

View File

@ -174,6 +174,18 @@ describe Email::Receiver do
expect(topic.posts.last.raw).to eq("This is the *text* part.") expect(topic.posts.last.raw).to eq("This is the *text* part.")
end end
it "prefers html over text when site setting is enabled" do
SiteSetting.incoming_email_prefer_html = true
expect { process(:text_and_html_reply) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq('This is the **html** part.')
end
it "uses text when prefer_html site setting is enabled but no html is available" do
SiteSetting.incoming_email_prefer_html = true
expect { process(:text_reply) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This is a text reply :)")
end
it "removes the 'on <date>, <contact> wrote' quoting line" do it "removes the 'on <date>, <contact> wrote' quoting line" do
expect { process(:on_date_contact_wrote) }.to change { topic.posts.count } expect { process(:on_date_contact_wrote) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This is the actual reply.") expect(topic.posts.last.raw).to eq("This is the actual reply.")