@@ -0,0 +1,26 | |||||
|
1 | Date: Tue, 20 Nov 2012 23:08:25 +0900 | |||
|
2 | Message-ID: <CANBr5-UZM=Odz4U3Q6vHd_9cd2tCT-_P9xDd=hRJ0aoMNTWXbw@mail.gmail.com> | |||
|
3 | Subject: test | |||
|
4 | From: John Smith <JSmith@somenet.foo> | |||
|
5 | To: redmine@somenet.foo | |||
|
6 | Content-Type: multipart/mixed; boundary=14dae93a13bf76ca5d04ceedc458 | |||
|
7 | ||||
|
8 | --14dae93a13bf76ca5d04ceedc458 | |||
|
9 | Content-Type: text/plain; charset=ISO-8859-1 | |||
|
10 | ||||
|
11 | test | |||
|
12 | ||||
|
13 | --14dae93a13bf76ca5d04ceedc458 | |||
|
14 | Content-Type: text/plain; charset=US-ASCII; | |||
|
15 | name="=?ISO-8859-1?B?xOTW9tz8xOTW9tz8xOTW9tz8xOTW9tz8xOTW9tw=?= | |||
|
16 | =?ISO-8859-1?B?/MTk1vbc/MTk1vbc/MTk1vbc/MTk1vbc/MTk1vbc?= | |||
|
17 | =?ISO-8859-1?B?/MTk1vbc/C50eHQ=?=" | |||
|
18 | Content-Disposition: attachment; | |||
|
19 | filename="=?ISO-8859-1?B?xOTW9tz8xOTW9tz8xOTW9tz8xOTW9tz8xOTW9tw=?= | |||
|
20 | =?ISO-8859-1?B?/MTk1vbc/MTk1vbc/MTk1vbc/MTk1vbc/MTk1vbc?= | |||
|
21 | =?ISO-8859-1?B?/MTk1vbc/C50eHQ=?=" | |||
|
22 | Content-Transfer-Encoding: base64 | |||
|
23 | X-Attachment-Id: f_h9r3mcjz0 | |||
|
24 | ||||
|
25 | dGVzdAo= | |||
|
26 | --14dae93a13bf76ca5d04ceedc458-- |
@@ -0,0 +1,20 | |||||
|
1 | Date: Mon, 19 Nov 2012 10:17:45 +0900 | |||
|
2 | Message-ID: <CANBr5-U6cXMfLek5QiB2ZrBPR3vTThn9_Upvdkf3Dkod664+Xw@mail.gmail.com> | |||
|
3 | Subject: test | |||
|
4 | From: John Smith <JSmith@somenet.foo> | |||
|
5 | To: redmine@somenet.foo | |||
|
6 | Content-Type: multipart/mixed; boundary=bcaec54ee4ea84f77904cecee22e | |||
|
7 | ||||
|
8 | --bcaec54ee4ea84f77904cecee22e | |||
|
9 | Content-Type: text/plain; charset=ISO-8859-1 | |||
|
10 | ||||
|
11 | test | |||
|
12 | ||||
|
13 | --bcaec54ee4ea84f77904cecee22e | |||
|
14 | Content-Type: text/plain; charset=US-ASCII; name="=?ISO-2022-JP?B?GyRCJUYlOSVIGyhCLnR4dA==?=" | |||
|
15 | Content-Disposition: attachment; filename="=?ISO-2022-JP?B?GyRCJUYlOSVIGyhCLnR4dA==?=" | |||
|
16 | Content-Transfer-Encoding: base64 | |||
|
17 | X-Attachment-Id: f_h9owndpv0 | |||
|
18 | ||||
|
19 | dGVzdAo= | |||
|
20 | --bcaec54ee4ea84f77904cecee22e-- |
@@ -0,0 +1,34 | |||||
|
1 | Message-ID: <50AB9546.7020800@gmail.com> | |||
|
2 | Date: Tue, 20 Nov 2012 23:35:50 +0900 | |||
|
3 | From: John Smith <JSmith@somenet.foo> | |||
|
4 | User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc13 Thunderbird/3.1.10 | |||
|
5 | MIME-Version: 1.0 | |||
|
6 | To: redmine@somenet.foo | |||
|
7 | Subject: test | |||
|
8 | Content-Type: multipart/mixed; | |||
|
9 | boundary="------------050902080306030406090208" | |||
|
10 | ||||
|
11 | This is a multi-part message in MIME format. | |||
|
12 | --------------050902080306030406090208 | |||
|
13 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed | |||
|
14 | Content-Transfer-Encoding: 7bit | |||
|
15 | ||||
|
16 | test | |||
|
17 | ||||
|
18 | --------------050902080306030406090208 | |||
|
19 | Content-Type: image/png; | |||
|
20 | name="=?ISO-8859-1?Q?=C4=E4=D6=F6=DC=FC=C4=E4=D6=F6=DC=FC=C4=E4=D6=F6=DC=FC=C4=E4?= | |||
|
21 | =?ISO-8859-1?Q?=D6=F6=DC=FC=C4=E4=D6=F6=DC=FC=C4=E4=D6=F6=DC=FC=C4=E4=D6?= | |||
|
22 | =?ISO-8859-1?Q?=F6=DC=FC=C4=E4=D6=F6=DC=FC=C4=E4=D6=F6=DC=FC=C4=E4=D6=F6?= | |||
|
23 | =?ISO-8859-1?Q?=DC=FC=C4=E4=D6=F6=DC=FC=2Epng?=" | |||
|
24 | Content-Transfer-Encoding: base64 | |||
|
25 | Content-Disposition: attachment; | |||
|
26 | filename*0*=ISO-8859-1''%C4%E4%D6%F6%DC%FC%C4%E4%D6%F6%DC%FC%C4%E4%D6%F6; | |||
|
27 | filename*1*=%DC%FC%C4%E4%D6%F6%DC%FC%C4%E4%D6%F6%DC%FC%C4%E4%D6%F6%DC%FC; | |||
|
28 | filename*2*=%C4%E4%D6%F6%DC%FC%C4%E4%D6%F6%DC%FC%C4%E4%D6%F6%DC%FC%C4%E4; | |||
|
29 | filename*3*=%D6%F6%DC%FC%C4%E4%D6%F6%DC%FC%2E%70%6E%67 | |||
|
30 | ||||
|
31 | iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAAXNSR0IArs4c6QAAAAlwSFlz | |||
|
32 | AAALEwAACxMBAJqcGAAAAAd0SU1FB9wLFA4fJhRKIUQAAAAUSURBVAjXY/z//z8DEmBiQAWk | |||
|
33 | 8gHq9gMHP8uZWAAAAABJRU5ErkJggg== | |||
|
34 | --------------050902080306030406090208-- |
@@ -0,0 +1,26 | |||||
|
1 | Message-ID: <50AA00C6.4070108@gmail.com> | |||
|
2 | Date: Mon, 19 Nov 2012 18:49:58 +0900 | |||
|
3 | From: John Smith <JSmith@somenet.foo> | |||
|
4 | User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Fedora/3.0.10-1.fc12 Lightning/1.0b1 Thunderbird/3.0.10 | |||
|
5 | MIME-Version: 1.0 | |||
|
6 | To: redmine@somenet.foo | |||
|
7 | Subject: test | |||
|
8 | Content-Type: multipart/mixed; | |||
|
9 | boundary="------------030104060902010800050907" | |||
|
10 | ||||
|
11 | This is a multi-part message in MIME format. | |||
|
12 | --------------030104060902010800050907 | |||
|
13 | Content-Type: text/plain; charset=ISO-2022-JP | |||
|
14 | Content-Transfer-Encoding: 7bit | |||
|
15 | ||||
|
16 | test | |||
|
17 | ||||
|
18 | --------------030104060902010800050907 | |||
|
19 | Content-Type: text/plain; | |||
|
20 | name="=?ISO-2022-JP?B?GyRCJUYlOSVIGyhCLnR4dA==?=" | |||
|
21 | Content-Transfer-Encoding: base64 | |||
|
22 | Content-Disposition: attachment; | |||
|
23 | filename*=ISO-2022-JP''%1B%24%42%25%46%25%39%25%48%1B%28%42%2E%74%78%74 | |||
|
24 | ||||
|
25 | dGVzdAo= | |||
|
26 | --------------030104060902010800050907-- |
@@ -249,9 +249,26 class MailHandler < ActionMailer::Base | |||||
249 | def add_attachments(obj) |
|
249 | def add_attachments(obj) | |
250 | if email.attachments && email.attachments.any? |
|
250 | if email.attachments && email.attachments.any? | |
251 | email.attachments.each do |attachment| |
|
251 | email.attachments.each do |attachment| | |
|
252 | filename = attachment.filename | |||
|
253 | unless filename.respond_to?(:encoding) | |||
|
254 | # try to reencode to utf8 manually with ruby1.8 | |||
|
255 | h = attachment.header['Content-Disposition'] | |||
|
256 | unless h.nil? | |||
|
257 | begin | |||
|
258 | if m = h.value.match(/filename\*[0-9\*]*=([^=']+)'/) | |||
|
259 | filename = Redmine::CodesetUtil.to_utf8(filename, m[1]) | |||
|
260 | elsif m = h.value.match(/filename=.*=\?([^\?]+)\?[BbQq]\?/) | |||
|
261 | # http://tools.ietf.org/html/rfc2047#section-4 | |||
|
262 | filename = Redmine::CodesetUtil.to_utf8(filename, m[1]) | |||
|
263 | end | |||
|
264 | rescue | |||
|
265 | # nop | |||
|
266 | end | |||
|
267 | end | |||
|
268 | end | |||
252 | obj.attachments << Attachment.create(:container => obj, |
|
269 | obj.attachments << Attachment.create(:container => obj, | |
253 | :file => attachment.decoded, |
|
270 | :file => attachment.decoded, | |
254 |
:filename => |
|
271 | :filename => filename, | |
255 | :author => user, |
|
272 | :author => user, | |
256 | :content_type => attachment.mime_type) |
|
273 | :content_type => attachment.mime_type) | |
257 | end |
|
274 | end |
@@ -373,6 +373,80 class MailHandlerTest < ActiveSupport::TestCase | |||||
373 | assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest |
|
373 | assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest | |
374 | end |
|
374 | end | |
375 |
|
375 | |||
|
376 | def test_thunderbird_with_attachment_ja | |||
|
377 | issue = submit_email( | |||
|
378 | 'thunderbird_with_attachment_ja.eml', | |||
|
379 | :issue => {:project => 'ecookbook'} | |||
|
380 | ) | |||
|
381 | assert_kind_of Issue, issue | |||
|
382 | assert_equal 1, issue.attachments.size | |||
|
383 | ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt" | |||
|
384 | ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding) | |||
|
385 | attachment = issue.attachments.first | |||
|
386 | assert_equal ja, attachment.filename | |||
|
387 | assert_equal 5, attachment.filesize | |||
|
388 | assert File.exist?(attachment.diskfile) | |||
|
389 | assert_equal 5, File.size(attachment.diskfile) | |||
|
390 | assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest | |||
|
391 | end | |||
|
392 | ||||
|
393 | def test_gmail_with_attachment_ja | |||
|
394 | issue = submit_email( | |||
|
395 | 'gmail_with_attachment_ja.eml', | |||
|
396 | :issue => {:project => 'ecookbook'} | |||
|
397 | ) | |||
|
398 | assert_kind_of Issue, issue | |||
|
399 | assert_equal 1, issue.attachments.size | |||
|
400 | ja = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88.txt" | |||
|
401 | ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding) | |||
|
402 | attachment = issue.attachments.first | |||
|
403 | assert_equal ja, attachment.filename | |||
|
404 | assert_equal 5, attachment.filesize | |||
|
405 | assert File.exist?(attachment.diskfile) | |||
|
406 | assert_equal 5, File.size(attachment.diskfile) | |||
|
407 | assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest | |||
|
408 | end | |||
|
409 | ||||
|
410 | def test_thunderbird_with_attachment_latin1 | |||
|
411 | issue = submit_email( | |||
|
412 | 'thunderbird_with_attachment_iso-8859-1.eml', | |||
|
413 | :issue => {:project => 'ecookbook'} | |||
|
414 | ) | |||
|
415 | assert_kind_of Issue, issue | |||
|
416 | assert_equal 1, issue.attachments.size | |||
|
417 | u = "" | |||
|
418 | u.force_encoding('UTF-8') if u.respond_to?(:force_encoding) | |||
|
419 | u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc" | |||
|
420 | u1.force_encoding('UTF-8') if u1.respond_to?(:force_encoding) | |||
|
421 | 11.times { u << u1 } | |||
|
422 | attachment = issue.attachments.first | |||
|
423 | assert_equal "#{u}.png", attachment.filename | |||
|
424 | assert_equal 130, attachment.filesize | |||
|
425 | assert File.exist?(attachment.diskfile) | |||
|
426 | assert_equal 130, File.size(attachment.diskfile) | |||
|
427 | assert_equal '4d80e667ac37dddfe05502530f152abb', attachment.digest | |||
|
428 | end | |||
|
429 | ||||
|
430 | def test_gmail_with_attachment_latin1 | |||
|
431 | issue = submit_email( | |||
|
432 | 'gmail_with_attachment_iso-8859-1.eml', | |||
|
433 | :issue => {:project => 'ecookbook'} | |||
|
434 | ) | |||
|
435 | assert_kind_of Issue, issue | |||
|
436 | assert_equal 1, issue.attachments.size | |||
|
437 | u = "" | |||
|
438 | u.force_encoding('UTF-8') if u.respond_to?(:force_encoding) | |||
|
439 | u1 = "\xc3\x84\xc3\xa4\xc3\x96\xc3\xb6\xc3\x9c\xc3\xbc" | |||
|
440 | u1.force_encoding('UTF-8') if u1.respond_to?(:force_encoding) | |||
|
441 | 11.times { u << u1 } | |||
|
442 | attachment = issue.attachments.first | |||
|
443 | assert_equal "#{u}.txt", attachment.filename | |||
|
444 | assert_equal 5, attachment.filesize | |||
|
445 | assert File.exist?(attachment.diskfile) | |||
|
446 | assert_equal 5, File.size(attachment.diskfile) | |||
|
447 | assert_equal 'd8e8fca2dc0f896fd7cb4cb0031ba249', attachment.digest | |||
|
448 | end | |||
|
449 | ||||
376 | def test_add_issue_with_iso_8859_1_subject |
|
450 | def test_add_issue_with_iso_8859_1_subject | |
377 | issue = submit_email( |
|
451 | issue = submit_email( | |
378 | 'subject_as_iso-8859-1.eml', |
|
452 | 'subject_as_iso-8859-1.eml', |
General Comments 0
You need to be logged in to leave comments.
Login now