diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 520183c..717e49b 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -441,12 +441,20 @@ # Removes the email body of text after the truncation configurations. def cleanup_body(body) - delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)} - unless delimiters.empty? - regex = Regexp.new("^[> ]*(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE) - body = body.gsub(regex, '') + address = Setting.mail_from + regex_arr = [ + Regexp.new("From:\s*" + Regexp.escape(address), Regexp::IGNORECASE), + Regexp.new("<" + Regexp.escape(address) + ">", Regexp::IGNORECASE), + Regexp.new(Regexp.escape(address) + "\s+wrote:", Regexp::IGNORECASE), + Regexp.new("^.*On.*(\n)?wrote:$", Regexp::IGNORECASE), + Regexp.new("-+original\s+message-+\s*$", Regexp::IGNORECASE), + Regexp.new("from:\s*$", Regexp::IGNORECASE) + ] + body_length = body.length + index = regex_arr.inject(body_length) do |min, regex| + [(body.index(regex) || body_length), min].min end - body.strip + body[0, index].strip end def find_assignee_from_keyword(keyword, issue)