Project

General

Profile

Patch #11684 ยป mailTruncate.patch

Joel Thompson, 2012-08-23 02:14

View differences:

app/models/mail_handler.rb
441 441

  
442 442
  # Removes the email body of text after the truncation configurations.
443 443
  def cleanup_body(body)
444
    delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)}
445
    unless delimiters.empty?
446
      regex = Regexp.new("^[> ]*(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE)
447
      body = body.gsub(regex, '')
444
    address = Setting.mail_from
445
    regex_arr = [
446
      Regexp.new("From:\s*" + Regexp.escape(address), Regexp::IGNORECASE),
447
      Regexp.new("<" + Regexp.escape(address) + ">", Regexp::IGNORECASE),
448
      Regexp.new(Regexp.escape(address) + "\s+wrote:", Regexp::IGNORECASE),
449
      Regexp.new("^.*On.*(\n)?wrote:$", Regexp::IGNORECASE),
450
      Regexp.new("-+original\s+message-+\s*$", Regexp::IGNORECASE),
451
      Regexp.new("from:\s*$", Regexp::IGNORECASE)
452
    ]
453
    body_length = body.length
454
    index = regex_arr.inject(body_length) do |min, regex|
455
      [(body.index(regex) || body_length), min].min
448 456
    end
449
    body.strip
457
    body[0, index].strip
450 458
  end
451 459

  
452 460
  def find_assignee_from_keyword(keyword, issue)
    (1-1/1)