Class: Gitlab::Email::ReplyParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/email/reply_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, trim_reply: true) ⇒ ReplyParser

Returns a new instance of ReplyParser.


9
10
11
12
# File 'lib/gitlab/email/reply_parser.rb', line 9

def initialize(message, trim_reply: true)
  @message = message
  @trim_reply = trim_reply
end

Instance Attribute Details

#messageObject

Returns the value of attribute message


7
8
9
# File 'lib/gitlab/email/reply_parser.rb', line 7

def message
  @message
end

Instance Method Details

#executeObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/email/reply_parser.rb', line 14

def execute
  body = select_body(message)

  encoding = body.encoding

  if @trim_reply
    body = EmailReplyTrimmer.trim(body)
  end

  return '' unless body

  # not using /\s+$/ here because that deletes empty lines
  body = body.gsub(/[ \t]$/, '')

  # 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?('>') }

  body.force_encoding(encoding).encode("UTF-8")
end