Commit b1bb7e29 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'issue_337598' into 'master'

Allow to create service desk issues when all lines of the email are quoted

See merge request gitlab-org/gitlab!73397
parents ab36a8e9 bcdf73f9
......@@ -108,7 +108,7 @@ module Gitlab
end
def message_including_template
description = message_including_reply
description = process_message(trim_reply: false, allow_only_quotes: true)
template_content = service_desk_setting&.issue_template_content
if template_content.present?
......
......@@ -4,12 +4,13 @@
module Gitlab
module Email
class ReplyParser
attr_accessor :message
attr_accessor :message, :allow_only_quotes
def initialize(message, trim_reply: true, append_reply: false)
def initialize(message, trim_reply: true, append_reply: false, allow_only_quotes: false)
@message = message
@trim_reply = trim_reply
@append_reply = append_reply
@allow_only_quotes = allow_only_quotes
end
def execute
......@@ -25,7 +26,12 @@ module Gitlab
# NOTE: We currently don't support empty quotes.
# EmailReplyTrimmer allows this as a special case,
# so we detect it manually here.
return "" if body.lines.all? { |l| l.strip.empty? || l.start_with?('>') }
#
# If allow_only_quotes is true a message where all lines starts with ">" is allowed.
# This could happen if an email has an empty quote, forwarded without any new content.
return "" if body.lines.all? do |l|
l.strip.empty? || (!allow_only_quotes && l.start_with?('>'))
end
encoded_body = body.force_encoding(encoding).encode("UTF-8")
return encoded_body unless @append_reply
......
Return-Path: <jake@adventuretime.ooo>
Received: from iceking.adventuretime.ooo ([unix socket]) by iceking (Cyrus v2.2.13-Debian-2.2.13-19+squeeze3) with LMTPA; Thu, 13 Jun 2013 17:03:50 -0400
Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b0:4001:c03::234]) by iceking.adventuretime.ooo (8.14.3/8.14.3/Debian-9.4) with ESMTP id r5DL3nFJ016967 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for <incoming+gitlabhq/gitlabhq@appmail.adventuretime.ooo>; Thu, 13 Jun 2013 17:03:50 -0400
Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <incoming+email-test-project_id-issue-@appmail.adventuretime.ooo>; Thu, 13 Jun 2013 14:03:48 -0700
Received: by 10.0.0.1 with HTTP; Thu, 13 Jun 2013 14:03:48 -0700
Date: Thu, 13 Jun 2013 17:03:48 -0400
From: Jake the Dog <jake@adventuretime.ooo>
To: incoming+email-test-project_id-issue-@appmail.adventuretime.ooo
Message-ID: <CADkmRc+rNGAGGbV2iE5p918UVy4UyJqVcXRO2=otppgzduJSg@mail.gmail.com>
Subject: The message subject! @all
Mime-Version: 1.0
Content-Type: text/plain;
charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Sieve: CMU Sieve 2.2
X-Received: by 10.0.0.1 with SMTP id n7mr11234144ipb.85.1371157428600; Thu,
13 Jun 2013 14:03:48 -0700 (PDT)
X-Scanned-By: MIMEDefang 2.69 on IPv6:2001:470:1d:165::1
> This is an empty quote
> someone did forward this email without
> adding any new content.
......@@ -197,6 +197,17 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
end
end
context 'when all lines of email are quoted' do
let(:email_raw) { email_fixture('emails/service_desk_all_quoted.eml') }
it 'creates email with correct body' do
receiver.execute
issue = Issue.last
expect(issue.description).to include('> This is an empty quote')
end
end
context 'when using custom service desk address' do
let(:receiver) { Gitlab::Email::ServiceDeskReceiver.new(email_raw) }
......
......@@ -21,6 +21,30 @@ RSpec.describe Gitlab::Email::ReplyParser do
expect(test_parse_body(fixture_file("emails/no_content_reply.eml"))).to eq("")
end
context 'when allow_only_quotes is true' do
it "returns quoted text from email" do
text = test_parse_body(fixture_file("emails/no_content_reply.eml"), allow_only_quotes: true)
expect(text).to eq(
<<-BODY.strip_heredoc.chomp
>
>
>
> eviltrout posted in 'Adventure Time Sux' on Discourse Meta:
>
> ---
> hey guys everyone knows adventure time sucks!
>
> ---
> Please visit this link to respond: http://localhost:3000/t/adventure-time-sux/1234/3
>
> To unsubscribe from these emails, visit your [user preferences](http://localhost:3000/user_preferences).
>
BODY
)
end
end
it "properly renders plaintext-only email" do
expect(test_parse_body(fixture_file("emails/plaintext_only.eml")))
.to eq(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment