diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 442fab9fa..27d05b954 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -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) diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index a559555f7..164d60cb4 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -118,7 +118,7 @@ describe Email::Receiver do it "removes the 'on , 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 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 diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index 6c8b34e47..6d444e7d8 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -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