FEATURE: automatically elides gmail quotes
This commit is contained in:
parent
26d5ae61dd
commit
fd33090646
|
@ -261,9 +261,16 @@ module Email
|
|||
end
|
||||
|
||||
markdown, elided_markdown = if html.present?
|
||||
markdown = HtmlToMarkdown.new(html, keep_img_tags: true, keep_cid_imgs: true).to_markdown
|
||||
markdown = trim_discourse_markers(markdown)
|
||||
trim_reply_and_extract_elided(markdown)
|
||||
if html[%{<div class="gmail_quote">}]
|
||||
html, elided_html = extract_gmail_quote(html)
|
||||
markdown = HtmlToMarkdown.new(html, keep_img_tags: true, keep_cid_imgs: true).to_markdown
|
||||
elided_markdown = HtmlToMarkdown.new(elided_html).to_markdown
|
||||
[markdown, elided_markdown]
|
||||
else
|
||||
markdown = HtmlToMarkdown.new(html, keep_img_tags: true, keep_cid_imgs: true).to_markdown
|
||||
markdown = trim_discourse_markers(markdown)
|
||||
trim_reply_and_extract_elided(markdown)
|
||||
end
|
||||
end
|
||||
|
||||
if text.blank? || (SiteSetting.incoming_email_prefer_html && markdown.present?)
|
||||
|
@ -273,6 +280,12 @@ module Email
|
|||
end
|
||||
end
|
||||
|
||||
def extract_gmail_quote(html)
|
||||
doc = Nokogiri::HTML.fragment(html)
|
||||
elided = doc.css("div.gmail_quote")[0].remove
|
||||
[doc.to_html, elided.to_html]
|
||||
end
|
||||
|
||||
def trim_reply_and_extract_elided(text)
|
||||
return [text, ""] if @opts[:skip_trimming]
|
||||
EmailReplyTrimmer.trim(text, true)
|
||||
|
|
|
@ -191,6 +191,12 @@ describe Email::Receiver do
|
|||
expect(topic.posts.last.raw).to eq("This is a **HTML** reply ;)")
|
||||
end
|
||||
|
||||
it "automatically elides gmail quotes" do
|
||||
SiteSetting.always_show_trimmed_content = true
|
||||
expect { process(:gmail_html_reply) }.to change { topic.posts.count }
|
||||
expect(topic.posts.last.raw).to eq("This is a **GMAIL** reply ;)\n\n<details class='elided'>\n<summary title='Show trimmed content'>···</summary>\n\nThis is the *elided* part!\n\n</details>")
|
||||
end
|
||||
|
||||
it "doesn't process email with same message-id more than once" do
|
||||
expect do
|
||||
process(:text_reply)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
Return-Path: <discourse@bar.com>
|
||||
From: Foo Bar <discourse@bar.com>
|
||||
To: alt+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com
|
||||
Date: Fri, 15 Jan 2016 00:12:43 +0100
|
||||
Message-ID: <180@foo.bar.mail>
|
||||
Mime-Version: 1.0
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
<div>
|
||||
<div dir="auto">
|
||||
<p>This is a <b>GMAIL</b> reply ;)</p>
|
||||
</div>
|
||||
<div class="gmail_quote">
|
||||
<p>This is the <i>elided</i> part!</p>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue