mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
FEATURE: hide elided part of incoming emails behind a [details] tag
This commit is contained in:
parent
1009dc9be1
commit
2747e14b4c
3 changed files with 13 additions and 8 deletions
|
@ -54,7 +54,11 @@ module Email
|
|||
def process_internal
|
||||
user = find_or_create_user(@from_email, @from_display_name)
|
||||
@incoming_email.update_columns(user_id: user.id)
|
||||
body = select_body || ""
|
||||
|
||||
body, elided = select_body
|
||||
|
||||
body ||= ""
|
||||
body << "\n\n[details=...]\n#{elided}\n[/details]" if elided.present?
|
||||
|
||||
raise AutoGeneratedEmailError if is_auto_generated?
|
||||
raise NoBodyDetectedError if body.blank? && !@mail.has_attachments?
|
||||
|
@ -115,6 +119,7 @@ module Email
|
|||
def select_body
|
||||
text = nil
|
||||
html = nil
|
||||
elided = nil
|
||||
|
||||
if @mail.multipart?
|
||||
text = fix_charset(@mail.text_part)
|
||||
|
@ -127,14 +132,14 @@ module Email
|
|||
|
||||
# prefer text over html
|
||||
text = trim_discourse_markers(text) if text.present?
|
||||
text = EmailReplyTrimmer.trim(text) if text.present?
|
||||
return text if text.present?
|
||||
text, elided = EmailReplyTrimmer.trim(text, true) if text.present?
|
||||
return [text, elided] if text.present?
|
||||
|
||||
# clean the html if that's all we've got
|
||||
html = Email::HtmlCleaner.new(html).output_html if html.present?
|
||||
html = trim_discourse_markers(html) if html.present?
|
||||
html = EmailReplyTrimmer.trim(html) if html.present?
|
||||
return html if html.present?
|
||||
html, elided = EmailReplyTrimmer.trim(html, true) if html.present?
|
||||
return [html, elided] if html.present?
|
||||
end
|
||||
|
||||
def fix_charset(mail_part)
|
||||
|
|
|
@ -118,7 +118,7 @@ describe Email::Receiver do
|
|||
|
||||
it "removes the 'on <date>, <contact> wrote' quoting line" do
|
||||
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.\n\n[details=...]\nOn Tue, Jan 14, 2016 at 0:42 AM, Bar Foo <wat@discourse.org> wrote:\n\n> This is the previous email.\n> And it had\n>\n> a lot\n>\n>\n> of lines ;)\n[/details]")
|
||||
end
|
||||
|
||||
it "removes the 'Previous Replies' marker" do
|
||||
|
@ -193,7 +193,7 @@ describe Email::Receiver do
|
|||
|
||||
it "strips 'original message' context" do
|
||||
expect { process(:original_message) }.to change { topic.posts.count }
|
||||
expect(topic.posts.last.raw).to eq("This is a reply :)")
|
||||
expect(topic.posts.last.raw).to eq("This is a reply :)\n\n[details=...]\n---Original Message---\nThis part should not be included\n[/details]")
|
||||
end
|
||||
|
||||
it "supports attached images" do
|
||||
|
|
|
@ -258,7 +258,7 @@ describe PostAlerter do
|
|||
post.revise(admin, { raw: "Mention @eviltrout in this edit." })
|
||||
}.to change(evil_trout.notifications, :count)
|
||||
n = evil_trout.notifications.last
|
||||
n.data_hash["original_username"].should == admin.username
|
||||
expect(n.data_hash["original_username"]).to eq(admin.username)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue