summaryrefslogtreecommitdiff
path: root/lib/gitlab/email
diff options
context:
space:
mode:
authorhttp://jneen.net/ <jneen@jneen.net>2016-11-11 14:09:49 +0900
committerhttp://jneen.net/ <jneen@jneen.net>2016-12-21 09:51:39 -0800
commita3bb2463c41124d6d7f5927bbff578a4991c15cb (patch)
tree487eed9e3fb4bcb94dc13dff18b0bd7f2996d8c4 /lib/gitlab/email
parent174dd4cee0958b0b5eaf9e11cf1df48ee675cf7c (diff)
downloadgitlab-ce-a3bb2463c41124d6d7f5927bbff578a4991c15cb.tar.gz
switch to email_reply_trimmer from discourse
Diffstat (limited to 'lib/gitlab/email')
-rw-r--r--lib/gitlab/email/reply_parser.rb30
1 files changed, 4 insertions, 26 deletions
diff --git a/lib/gitlab/email/reply_parser.rb b/lib/gitlab/email/reply_parser.rb
index f586c5ab062..e53a99cd8e0 100644
--- a/lib/gitlab/email/reply_parser.rb
+++ b/lib/gitlab/email/reply_parser.rb
@@ -13,9 +13,11 @@ module Gitlab
encoding = body.encoding
- body = discourse_email_trimmer(body)
+ body = EmailReplyTrimmer.trim(body)
- body = EmailReplyParser.parse_reply(body)
+ # TODO [jneen]: do we want to allow empty-quoting? (replies only containing a blockquote)
+ # 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?('>') }
body.force_encoding(encoding).encode("UTF-8")
end
@@ -57,30 +59,6 @@ module Gitlab
rescue
nil
end
-
- REPLYING_HEADER_LABELS = %w(From Sent To Subject Reply To Cc Bcc Date)
- REPLYING_HEADER_REGEX = Regexp.union(REPLYING_HEADER_LABELS.map { |label| "#{label}:" })
-
- def discourse_email_trimmer(body)
- lines = body.scrub.lines.to_a
- range_end = 0
-
- lines.each_with_index do |l, idx|
- # This one might be controversial but so many reply lines have years, times and end with a colon.
- # Let's try it and see how well it works.
- break if (l =~ /\d{4}/ && l =~ /\d:\d\d/ && l =~ /\:$/) ||
- (l =~ /On \w+ \d+,? \d+,?.*wrote:/)
-
- # Headers on subsequent lines
- break if (0..2).all? { |off| lines[idx + off] =~ REPLYING_HEADER_REGEX }
- # Headers on the same line
- break if REPLYING_HEADER_LABELS.count { |label| l.include?(label) } >= 3
-
- range_end = idx
- end
-
- lines[0..range_end].join.strip
- end
end
end
end