@@ -0,0 +1,55 | |||||
|
1 | From JSmith@somenet.foo Fri Mar 22 08:30:28 2013 | |||
|
2 | From: John Smith <JSmith@somenet.foo> | |||
|
3 | Content-Type: multipart/mixed; boundary="Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9" | |||
|
4 | Message-Id: <BB533668-3CC8-41CA-A951-0A5D8EA37FB0@somenet.foo> | |||
|
5 | Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) | |||
|
6 | Subject: Test with multiple text parts | |||
|
7 | Date: Fri, 22 Mar 2013 17:30:20 +0200 | |||
|
8 | To: redmine@somenet.foo | |||
|
9 | X-Mailer: Apple Mail (2.1503) | |||
|
10 | ||||
|
11 | ||||
|
12 | ||||
|
13 | --Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 | |||
|
14 | Content-Transfer-Encoding: quoted-printable | |||
|
15 | Content-Type: text/plain; | |||
|
16 | charset=us-ascii | |||
|
17 | ||||
|
18 | The first text part. | |||
|
19 | ||||
|
20 | --Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 | |||
|
21 | Content-Disposition: inline; | |||
|
22 | filename=1st.pdf | |||
|
23 | Content-Type: application/pdf; | |||
|
24 | x-unix-mode=0644; | |||
|
25 | name="1st.pdf" | |||
|
26 | Content-Transfer-Encoding: base64 | |||
|
27 | ||||
|
28 | JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAgUiAvRmlsdGVyIC9G | |||
|
29 | ||||
|
30 | --Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 | |||
|
31 | Content-Transfer-Encoding: quoted-printable | |||
|
32 | Content-Type: text/plain; | |||
|
33 | charset=us-ascii | |||
|
34 | ||||
|
35 | The second text part. | |||
|
36 | ||||
|
37 | --Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 | |||
|
38 | Content-Disposition: inline; | |||
|
39 | filename=2nd.pdf | |||
|
40 | Content-Type: application/pdf; | |||
|
41 | x-unix-mode=0644; | |||
|
42 | name="2nd.pdf" | |||
|
43 | Content-Transfer-Encoding: base64 | |||
|
44 | ||||
|
45 | JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAgUiAvRmlsdGVyIC9G | |||
|
46 | ||||
|
47 | ||||
|
48 | --Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 | |||
|
49 | Content-Transfer-Encoding: quoted-printable | |||
|
50 | Content-Type: text/plain; | |||
|
51 | charset=us-ascii | |||
|
52 | ||||
|
53 | The third one. | |||
|
54 | ||||
|
55 | --Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9-- |
@@ -377,12 +377,21 class MailHandler < ActionMailer::Base | |||||
377 | def plain_text_body |
|
377 | def plain_text_body | |
378 | return @plain_text_body unless @plain_text_body.nil? |
|
378 | return @plain_text_body unless @plain_text_body.nil? | |
379 |
|
379 | |||
380 | part = email.text_part || email.html_part || email |
|
380 | parts = if (text_parts = email.all_parts.select {|p| p.mime_type == 'text/plain'}).present? | |
381 | @plain_text_body = Redmine::CodesetUtil.to_utf8(part.body.decoded, part.charset) |
|
381 | text_parts | |
|
382 | elsif (html_parts = email.all_parts.select {|p| p.mime_type == 'text/html'}).present? | |||
|
383 | html_parts | |||
|
384 | else | |||
|
385 | [email] | |||
|
386 | end | |||
|
387 | @plain_text_body = parts.map {|p| Redmine::CodesetUtil.to_utf8(p.body.decoded, p.charset)}.join("\r\n") | |||
382 |
|
388 | |||
383 | # strip html tags and remove doctype directive |
|
389 | # strip html tags and remove doctype directive | |
384 | @plain_text_body = strip_tags(@plain_text_body.strip) |
|
390 | if parts.any? {|p| p.mime_type == 'text/html'} | |
385 | @plain_text_body.sub! %r{^<!DOCTYPE .*$}, '' |
|
391 | @plain_text_body = strip_tags(@plain_text_body.strip) | |
|
392 | @plain_text_body.sub! %r{^<!DOCTYPE .*$}, '' | |||
|
393 | end | |||
|
394 | ||||
386 | @plain_text_body |
|
395 | @plain_text_body | |
387 | end |
|
396 | end | |
388 |
|
397 |
@@ -492,6 +492,13 class MailHandlerTest < ActiveSupport::TestCase | |||||
492 | assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest |
|
492 | assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest | |
493 | end |
|
493 | end | |
494 |
|
494 | |||
|
495 | def test_multiple_text_parts | |||
|
496 | issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'}) | |||
|
497 | assert_include 'first', issue.description | |||
|
498 | assert_include 'second', issue.description | |||
|
499 | assert_include 'third', issue.description | |||
|
500 | end | |||
|
501 | ||||
495 | def test_add_issue_with_iso_8859_1_subject |
|
502 | def test_add_issue_with_iso_8859_1_subject | |
496 | issue = submit_email( |
|
503 | issue = submit_email( | |
497 | 'subject_as_iso-8859-1.eml', |
|
504 | 'subject_as_iso-8859-1.eml', |
General Comments 0
You need to be logged in to leave comments.
Login now