Project

General

Profile

Feature #16962 » 16962.2.patch

Felix Schäfer, 2014-05-23 14:06

View differences:

Gemfile
8 8
gem "builder", "3.0.0"
9 9
gem "request_store"
10 10
gem "mime-types"
11
gem "loofah"
11 12

  
12 13
# Optional gem for LDAP authentication
13 14
group :ldap do
app/models/mail_handler.rb
423 423
    @plain_text_body = parts.map do |p|
424 424
      body_charset = p.charset.respond_to?(:force_encoding) ?
425 425
                       Mail::RubyVer.pick_encoding(p.charset).to_s : p.charset
426
      Redmine::CodesetUtil.to_utf8(p.body.decoded, body_charset)
426
      body = Redmine::CodesetUtil.to_utf8(p.body.decoded, body_charset)
427
      # convert html parts to text
428
      p.mime_type == 'text/html' ? Loofah.document(body).to_text : body
427 429
    end.join("\r\n")
428 430

  
429
    # strip html tags and remove doctype directive
430
    if parts.any? {|p| p.mime_type == 'text/html'}
431
      @plain_text_body = strip_tags(@plain_text_body.strip)
432
      @plain_text_body.sub! %r{^<!DOCTYPE .*$}, ''
433
    end
434

  
435 431
    @plain_text_body
436 432
  end
437 433

  
test/fixtures/mail_handler/ticket_html_only.eml
15 15
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
16 16
<html>
17 17
<head>
18
<style>p {font-size:12.0pt;}</style>
18 19
</head>
19 20
<body bgcolor="#ffffff" text="#000000">
20
This is a <b>html-only</b> email.<br>
21
This is a <b>html-only</b> email.<br><h1>With a title</h1><p>and a paragraph.</p>
21 22
</body>
22 23
</html>
test/unit/mail_handler_test.rb
763 763
    assert !issue.new_record?
764 764
    issue.reload
765 765
    assert_equal 'HTML email', issue.subject
766
    assert_equal 'This is a html-only email.', issue.description
766
    assert_equal "This is a html-only email.\r\nWith a title\r\n\r\nand a paragraph.", issue.description
767 767
  end
768 768

  
769 769
  test "truncate emails with no setting should add the entire email into the issue" do
(2-2/4)