tmail_es 1.2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +83 -0
- data/LICENSE +21 -0
- data/NOTES +7 -0
- data/README +182 -0
- data/Rakefile +2 -0
- data/ext/Makefile +20 -0
- data/ext/tmailscanner/tmail/MANIFEST +4 -0
- data/ext/tmailscanner/tmail/depend +1 -0
- data/ext/tmailscanner/tmail/extconf.rb +33 -0
- data/ext/tmailscanner/tmail/tmailscanner.c +614 -0
- data/lib/tmail/Makefile +18 -0
- data/lib/tmail/address.rb +392 -0
- data/lib/tmail/attachments.rb +65 -0
- data/lib/tmail/base64.rb +46 -0
- data/lib/tmail/compat.rb +41 -0
- data/lib/tmail/config.rb +67 -0
- data/lib/tmail/core_extensions.rb +63 -0
- data/lib/tmail/encode.rb +590 -0
- data/lib/tmail/header.rb +962 -0
- data/lib/tmail/index.rb +9 -0
- data/lib/tmail/interface.rb +1162 -0
- data/lib/tmail/loader.rb +3 -0
- data/lib/tmail/mail.rb +578 -0
- data/lib/tmail/mailbox.rb +496 -0
- data/lib/tmail/main.rb +6 -0
- data/lib/tmail/mbox.rb +3 -0
- data/lib/tmail/net.rb +250 -0
- data/lib/tmail/obsolete.rb +132 -0
- data/lib/tmail/parser.rb +1060 -0
- data/lib/tmail/parser.y +416 -0
- data/lib/tmail/port.rb +379 -0
- data/lib/tmail/quoting.rb +164 -0
- data/lib/tmail/require_arch.rb +58 -0
- data/lib/tmail/scanner.rb +49 -0
- data/lib/tmail/scanner_r.rb +261 -0
- data/lib/tmail/stringio.rb +280 -0
- data/lib/tmail/utils.rb +361 -0
- data/lib/tmail/vendor/rchardet-1.3/COPYING +504 -0
- data/lib/tmail/vendor/rchardet-1.3/README +12 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/big5freq.rb +927 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/big5prober.rb +42 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb +238 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/charsetgroupprober.rb +112 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/charsetprober.rb +75 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/codingstatemachine.rb +64 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/constants.rb +42 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb +89 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/escsm.rb +244 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/eucjpprober.rb +88 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/euckrfreq.rb +596 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/euckrprober.rb +42 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/euctwfreq.rb +430 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/euctwprober.rb +42 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312freq.rb +474 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312prober.rb +42 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/hebrewprober.rb +289 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/jisfreq.rb +570 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/jpcntx.rb +229 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langbulgarianmodel.rb +229 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langcyrillicmodel.rb +330 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langgreekmodel.rb +227 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langhebrewmodel.rb +202 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langhungarianmodel.rb +226 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langthaimodel.rb +201 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/latin1prober.rb +147 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/mbcharsetprober.rb +89 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/mbcsgroupprober.rb +45 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/mbcssm.rb +542 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/sbcharsetprober.rb +124 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/sbcsgroupprober.rb +56 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/sjisprober.rb +88 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/universaldetector.rb +167 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb +87 -0
- data/lib/tmail/vendor/rchardet-1.3/lib/rchardet.rb +67 -0
- data/lib/tmail/version.rb +40 -0
- data/lib/tmail.rb +6 -0
- data/setup.rb +1482 -0
- data/test/extctrl.rb +6 -0
- data/test/fixtures/apple_unquoted_content_type +44 -0
- data/test/fixtures/inline_attachment.txt +2095 -0
- data/test/fixtures/iso_8859_1_email_without_encoding_and_message_id.txt +16 -0
- data/test/fixtures/mailbox +414 -0
- data/test/fixtures/mailbox.zip +0 -0
- data/test/fixtures/mailbox_without_any_from_or_sender +10 -0
- data/test/fixtures/mailbox_without_from +11 -0
- data/test/fixtures/mailbox_without_return_path +12 -0
- data/test/fixtures/marked_as_iso_8859_1_but_it_is_utf_8.txt +33 -0
- data/test/fixtures/marked_as_utf_8_but_it_is_iso_8859_1.txt +56 -0
- data/test/fixtures/raw_attack_email_with_zero_length_whitespace +29 -0
- data/test/fixtures/raw_base64_decoded_string +0 -0
- data/test/fixtures/raw_base64_email +83 -0
- data/test/fixtures/raw_base64_encoded_string +1 -0
- data/test/fixtures/raw_email +14 -0
- data/test/fixtures/raw_email10 +20 -0
- data/test/fixtures/raw_email11 +34 -0
- data/test/fixtures/raw_email12 +32 -0
- data/test/fixtures/raw_email13 +29 -0
- data/test/fixtures/raw_email2 +114 -0
- data/test/fixtures/raw_email3 +70 -0
- data/test/fixtures/raw_email4 +59 -0
- data/test/fixtures/raw_email5 +19 -0
- data/test/fixtures/raw_email6 +20 -0
- data/test/fixtures/raw_email7 +66 -0
- data/test/fixtures/raw_email8 +47 -0
- data/test/fixtures/raw_email9 +28 -0
- data/test/fixtures/raw_email_bad_time +62 -0
- data/test/fixtures/raw_email_double_at_in_header +14 -0
- data/test/fixtures/raw_email_multiple_from +30 -0
- data/test/fixtures/raw_email_only_attachment +17 -0
- data/test/fixtures/raw_email_quoted_with_0d0a +14 -0
- data/test/fixtures/raw_email_reply +32 -0
- data/test/fixtures/raw_email_simple +11 -0
- data/test/fixtures/raw_email_string_in_date_field +17 -0
- data/test/fixtures/raw_email_trailing_dot +21 -0
- data/test/fixtures/raw_email_with_bad_date +48 -0
- data/test/fixtures/raw_email_with_illegal_boundary +58 -0
- data/test/fixtures/raw_email_with_mimepart_without_content_type +94 -0
- data/test/fixtures/raw_email_with_multipart_mixed_quoted_boundary +50 -0
- data/test/fixtures/raw_email_with_nested_attachment +100 -0
- data/test/fixtures/raw_email_with_partially_quoted_subject +14 -0
- data/test/fixtures/raw_email_with_quoted_attachment_filename +60 -0
- data/test/fixtures/raw_email_with_quoted_illegal_boundary +58 -0
- data/test/fixtures/raw_email_with_wrong_splitted_multibyte_encoded_word_subject +15 -0
- data/test/fixtures/the_only_part_is_a_word_document.txt +425 -0
- data/test/fixtures/unquoted_filename_in_attachment +177 -0
- data/test/kcode.rb +14 -0
- data/test/temp_test_one.rb +46 -0
- data/test/test_address.rb +1216 -0
- data/test/test_attachments.rb +133 -0
- data/test/test_base64.rb +64 -0
- data/test/test_encode.rb +139 -0
- data/test/test_header.rb +1021 -0
- data/test/test_helper.rb +9 -0
- data/test/test_mail.rb +756 -0
- data/test/test_mbox.rb +184 -0
- data/test/test_port.rb +440 -0
- data/test/test_quote.rb +107 -0
- data/test/test_scanner.rb +209 -0
- data/test/test_utils.rb +36 -0
- data/tmail_es.gemspec +35 -0
- metadata +257 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
require 'test_helper'
|
4
|
+
require 'tmail'
|
5
|
+
|
6
|
+
class TestAttachments < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_attachment
|
9
|
+
mail = TMail::Mail.new
|
10
|
+
mail.mime_version = "1.0"
|
11
|
+
mail.set_content_type 'multipart', 'mixed', {'boundary' => 'Apple-Mail-13-196941151'}
|
12
|
+
mail.body =<<HERE
|
13
|
+
--Apple-Mail-13-196941151
|
14
|
+
Content-Transfer-Encoding: quoted-printable
|
15
|
+
Content-Type: text/plain;
|
16
|
+
charset=ISO-8859-1;
|
17
|
+
delsp=yes;
|
18
|
+
format=flowed
|
19
|
+
|
20
|
+
This is the first part.
|
21
|
+
|
22
|
+
--Apple-Mail-13-196941151
|
23
|
+
Content-Type: text/x-ruby-script; name="hello.rb"
|
24
|
+
Content-Transfer-Encoding: 7bit
|
25
|
+
Content-Disposition: attachment;
|
26
|
+
filename="api.rb"
|
27
|
+
|
28
|
+
puts "Hello, world!"
|
29
|
+
gets
|
30
|
+
|
31
|
+
--Apple-Mail-13-196941151--
|
32
|
+
HERE
|
33
|
+
assert_equal(true, mail.multipart?)
|
34
|
+
assert_equal(1, mail.attachments.length)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_recursive_multipart_processing
|
38
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
|
39
|
+
mail = TMail::Mail.parse(fixture)
|
40
|
+
assert_equal "This is the first part.\n\nAttachment: test.rb\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_decode_encoded_attachment_filename
|
44
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8")
|
45
|
+
mail = TMail::Mail.parse(fixture)
|
46
|
+
attachment = mail.attachments.last
|
47
|
+
expected = "01 Quien Te Dij\212at. Pitbull.mp3"
|
48
|
+
expected.force_encoding(Encoding::ASCII_8BIT) if expected.respond_to?(:force_encoding)
|
49
|
+
assert_equal expected, attachment.original_filename
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_attachment_with_quoted_filename
|
53
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email_with_quoted_attachment_filename")
|
54
|
+
mail = TMail::Mail.parse(fixture)
|
55
|
+
attachment = mail.attachments.last
|
56
|
+
str = "Eelanalüüsi päring.jpg"
|
57
|
+
assert_equal str, attachment.original_filename
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_assigning_attachment_crashing_due_to_missing_boundary
|
61
|
+
mail = TMail::Mail.new
|
62
|
+
mail.mime_version = '1.0'
|
63
|
+
mail.set_content_type("multipart", "mixed")
|
64
|
+
|
65
|
+
mailpart=TMail::Mail.new
|
66
|
+
mailpart.set_content_type("application", "octet-stream")
|
67
|
+
mailpart['Content-Disposition'] = "attachment; filename=mailbox.zip"
|
68
|
+
|
69
|
+
assert_nothing_raised { mail.parts.push(mailpart) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_only_has_attachment
|
73
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email_only_attachment")
|
74
|
+
mail = TMail::Mail.parse(fixture)
|
75
|
+
assert_equal(1, mail.attachments.length)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_content_nil_returned_if_name_of_attachment_type_unquoted
|
79
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/unquoted_filename_in_attachment")
|
80
|
+
mail = TMail::Mail.parse(fixture)
|
81
|
+
assert_equal("image/png", mail.attachments.first.content_type)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_unquoted_apple_mail_content_type
|
85
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/apple_unquoted_content_type")
|
86
|
+
mail = TMail::Mail.parse(fixture)
|
87
|
+
assert_equal("application/pdf", mail.attachments.first.content_type)
|
88
|
+
end
|
89
|
+
|
90
|
+
# TMail::Mail.has_attachments? & TMail::Mail.attachments
|
91
|
+
# http://rubyforge.org/tracker/index.php?func=detail&aid=23099&group_id=4512&atid=17370
|
92
|
+
def test_the_only_part_is_a_word_document
|
93
|
+
mail = load_fixture('the_only_part_is_a_word_document.txt')
|
94
|
+
|
95
|
+
assert_equal('application/msword', mail.content_type)
|
96
|
+
assert !mail.multipart?, 'The mail should not be multipart'
|
97
|
+
assert mail.attachment?(mail), 'The mail should be considered has an attachment'
|
98
|
+
|
99
|
+
# The original method TMail::Mail.has_attachments? returns false
|
100
|
+
assert mail.has_attachments?, 'PATCH: TMail should consider that this email has an attachment'
|
101
|
+
|
102
|
+
# The original method TMail::Mail.attachments returns nil
|
103
|
+
assert_not_nil mail.attachments, 'PATCH: TMail should return the attachment'
|
104
|
+
assert_equal 1, mail.attachments.size, 'PATCH: TMail should detect one attachment'
|
105
|
+
assert_instance_of TMail::Attachment, mail.attachments.first, 'The first attachment found should be an instance of TMail::Attachment'
|
106
|
+
end
|
107
|
+
|
108
|
+
# new method TMail::Mail.inline_attachment?
|
109
|
+
def test_inline_attachment_should_detect_inline_attachments
|
110
|
+
mail = load_fixture('inline_attachment.txt')
|
111
|
+
|
112
|
+
assert !mail.inline_attachment?(mail.parts[0]), 'The first part is an empty text'
|
113
|
+
assert mail.inline_attachment?(mail.parts[1]), 'The second part is an inline attachment'
|
114
|
+
|
115
|
+
mail = load_fixture('the_only_part_is_a_word_document.txt')
|
116
|
+
assert !mail.inline_attachment?(mail), 'The first and only part is an normal attachment'
|
117
|
+
end
|
118
|
+
|
119
|
+
# new method TMail::Mail.text_content_type?
|
120
|
+
def test_text_content_type?
|
121
|
+
mail = load_fixture('inline_attachment.txt')
|
122
|
+
|
123
|
+
assert mail.parts[0].text_content_type?, 'The first part of inline_attachment.txt is a text'
|
124
|
+
assert !mail.parts[1].text_content_type?, 'The second part of inline_attachment.txt is not a text'
|
125
|
+
end
|
126
|
+
|
127
|
+
protected
|
128
|
+
|
129
|
+
def load_fixture(name)
|
130
|
+
TMail::Mail.load(File.join('test', 'fixtures', name))
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
data/test/test_base64.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tmail/base64'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestTMailBase64 < Test::Unit::TestCase
|
6
|
+
def try(orig)
|
7
|
+
ok = [orig].pack('m').delete("\r\n")
|
8
|
+
result = TMail::Base64.encode(orig)
|
9
|
+
assert_equal ok, result, "str=#{orig.inspect}"
|
10
|
+
assert_equal orig, TMail::Base64.decode(result), "str=#{orig.inspect}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_normal
|
14
|
+
try ''
|
15
|
+
try 'a'
|
16
|
+
try 'ab'
|
17
|
+
try 'abc'
|
18
|
+
try 'abcd'
|
19
|
+
try 'abcde'
|
20
|
+
try 'abcdef'
|
21
|
+
try 'abcdefg'
|
22
|
+
try 'abcdefgh'
|
23
|
+
try 'abcdefghi'
|
24
|
+
try 'abcdefghij'
|
25
|
+
try 'abcdefghijk'
|
26
|
+
try 'abcdefghijkl'
|
27
|
+
try 'abcdefghijklm'
|
28
|
+
try 'abcdefghijklmn'
|
29
|
+
try 'abcdefghijklmno'
|
30
|
+
try 'abcdefghijklmnop'
|
31
|
+
try 'abcdefghijklmnopq'
|
32
|
+
try 'abcdefghijklmnopqr'
|
33
|
+
try 'abcdefghijklmnopqrs'
|
34
|
+
try 'abcdefghijklmnopqrst'
|
35
|
+
try 'abcdefghijklmnopqrstu'
|
36
|
+
try 'abcdefghijklmnopqrstuv'
|
37
|
+
try 'abcdefghijklmnopqrstuvw'
|
38
|
+
try 'abcdefghijklmnopqrstuvwx'
|
39
|
+
try 'abcdefghijklmnopqrstuvwxy'
|
40
|
+
try 'abcdefghijklmnopqrstuvwxyz'
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_dangerous_chars
|
44
|
+
["\0", "\001", "\002", "\003", "\0xfd", "\0xfe", "\0xff"].each do |ch|
|
45
|
+
1.upto(96) do |len|
|
46
|
+
try ch * len
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_random
|
52
|
+
16.times do
|
53
|
+
try make_random_string(96)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def make_random_string(len)
|
58
|
+
buf = ''
|
59
|
+
len.times do
|
60
|
+
buf << rand(255)
|
61
|
+
end
|
62
|
+
buf
|
63
|
+
end
|
64
|
+
end
|
data/test/test_encode.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'tmail/port'
|
4
|
+
require 'tmail/encode'
|
5
|
+
require 'nkf'
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
class TestEncode < Test::Unit::TestCase
|
9
|
+
|
10
|
+
SRCS = [
|
11
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあいうえお", #1
|
12
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあいうえ", #2
|
13
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあいう", #3
|
14
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあい", #4
|
15
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあ", #5
|
16
|
+
"a cde あいうえおあいうえおあいうえおあいうえお", #6 #
|
17
|
+
"a cde あいうえおあいうえおあいうえおあいうえ", #7
|
18
|
+
"a cde あいうえおあいうえおあいうえおあいう", #8
|
19
|
+
"a cde あいうえおあいうえおあいうえおあい", #9
|
20
|
+
"a cde あいうえおあいうえおあいうえおあ", #10
|
21
|
+
"a cde あいうえおあいうえおあいうえお", #11
|
22
|
+
"a cde あいうえおあいうえおあいうえ", #12
|
23
|
+
"a cde あいうえおあいうえおあいう", #13
|
24
|
+
"a cde あいうえおあいうえおあい", #14
|
25
|
+
"a cde あいうえおあいうえおあ", #15
|
26
|
+
"a cde あいうえおあいうえお", #16
|
27
|
+
"a cde あいうえおあいうえ", #17
|
28
|
+
"a cde あいうえおあいう", #18
|
29
|
+
"a cde あいうえおあい", #19
|
30
|
+
"a cde あいうえおあ", #20
|
31
|
+
"a cde あいうえお", #21
|
32
|
+
"a cde あいうえ", #22
|
33
|
+
"a cde あいう", #23
|
34
|
+
"a cde あい", #24
|
35
|
+
"a cde あ", #25
|
36
|
+
"aあa aあa aあa aあa aあa aあa" #26
|
37
|
+
]
|
38
|
+
|
39
|
+
OK = [
|
40
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQkJiQoJCokIiQkJCYkKCQqGyhC?=", #1
|
41
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQkJiQoJCokIiQkJCYkKBsoQg==?=", #2
|
42
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQkJiQoJCokIiQkJCYbKEI=?=", #3
|
43
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQkJiQoJCokIiQkGyhC?=", #4
|
44
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQkJiQoJCokIhsoQg==?=", #5
|
45
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQkJiQoJCobKEI=?=", #6
|
46
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQkJiQoGyhC?=", #7
|
47
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQkJhsoQg==?=", #8
|
48
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCQbKEI=?=", #9
|
49
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqJCIbKEI=?=", #10
|
50
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqGyhC?=", #11
|
51
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYkKBsoQg==?=", #12
|
52
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=', #13
|
53
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkGyhC?=', #14
|
54
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIhsoQg==?=', #15
|
55
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCobKEI=?=', #16
|
56
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoGyhC?=', #17
|
57
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJhsoQg==?=', #18
|
58
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQbKEI=?=', #19
|
59
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiGyhC?=', #20
|
60
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKhsoQg==?=', #21
|
61
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgbKEI=?=', #22
|
62
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmGyhC?=', #23
|
63
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJBsoQg==?=', #24
|
64
|
+
'a cde =?iso-2022-jp?B?GyRCJCIbKEI=?=', #25
|
65
|
+
"=?iso-2022-jp?B?YRskQiQiGyhCYSBhGyRCJCIbKEJhIGEbJEIkIhsoQmEgYRskQiQiGyhCYSBh?=\r\n\t=?iso-2022-jp?B?GyRCJCIbKEJhIGEbJEIkIhsoQmE=?=" #26
|
66
|
+
]
|
67
|
+
|
68
|
+
unless RUBY_VERSION.match(/1.9/)
|
69
|
+
def test_s_encode
|
70
|
+
SRCS.each_index do |i|
|
71
|
+
assert_equal crlf(OK[i]),
|
72
|
+
TMail::Encoder.encode(NKF.nkf('-j', SRCS[i]))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def crlf( str )
|
78
|
+
str.gsub(/\n|\r\n|\r/) { "\r\n" }
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_wrapping_an_email_with_whitespace_at_position_zero
|
82
|
+
# This email is a spam mail designed to break mailers... evil.
|
83
|
+
mail = TMail::Mail.load("#{File.dirname(__FILE__)}/fixtures/raw_attack_email_with_zero_length_whitespace")
|
84
|
+
assert_nothing_raised(Exception) { mail.encoded }
|
85
|
+
end
|
86
|
+
|
87
|
+
# =?utf-8?Q? Nicolas=20Fouch=E9?= is not UTF-8, it's ISO-8859-1 !
|
88
|
+
def test_marked_as_utf_8_but_it_is_iso_8859_1
|
89
|
+
mail = load_fixture('marked_as_utf_8_but_it_is_iso_8859_1.txt')
|
90
|
+
|
91
|
+
name = mail.to_addrs.first.name
|
92
|
+
assert_equal ' Nicolas Fouché', TMail::Unquoter.unquote_and_convert_to(name, 'utf-8')
|
93
|
+
|
94
|
+
# Without the patch, TMail raises:
|
95
|
+
# Iconv::InvalidCharacter: "\351"
|
96
|
+
# method iconv in quoting.rb at line 99
|
97
|
+
# method convert_to in quoting.rb at line 99
|
98
|
+
# method unquote_quoted_printable_and_convert_to in quoting.rb at line 88
|
99
|
+
# method unquote_and_convert_to in quoting.rb at line 72
|
100
|
+
# method gsub in quoting.rb at line 63
|
101
|
+
# method unquote_and_convert_to in quoting.rb at line 63
|
102
|
+
end
|
103
|
+
|
104
|
+
# =?iso-8859-1?b?77y5772B772O772Q772J772O772HIA==?= =?iso-8859-1?b?77y377yh77yu77yn?= is not ISO-8859-1, it's UTF-8 !
|
105
|
+
def test_marked_as_iso_8859_1_but_it_is_utf_8
|
106
|
+
mail = load_fixture('marked_as_iso_8859_1_but_it_is_utf_8.txt')
|
107
|
+
|
108
|
+
name = mail.to_addrs.first.name
|
109
|
+
assert_equal 'Yanping WANG', TMail::Unquoter.unquote_and_convert_to(name, 'utf-8')
|
110
|
+
# Even GMail could not detect this one :)
|
111
|
+
|
112
|
+
# Without the patch, TMail returns: "ï¼¹ï½ï½ï½ï½ï½ï½ WANG"
|
113
|
+
end
|
114
|
+
|
115
|
+
# Be sure not to copy/paste the content of the fixture to another file, it could be automatically converted to utf-8
|
116
|
+
def test_iso_8859_1_email_without_encoding_and_message_id
|
117
|
+
mail = load_fixture('iso_8859_1_email_without_encoding_and_message_id.txt')
|
118
|
+
|
119
|
+
text = TMail::Unquoter.unquote_and_convert_to(mail.body, 'utf-8')
|
120
|
+
|
121
|
+
assert(text.include?('é'), 'Text content should include the "é" character')
|
122
|
+
|
123
|
+
# I'm not very proud of this one, chardet detects iso-8859-2, so I have to force the encoding to iso-8859-1.
|
124
|
+
assert(!text.include?('ŕ'), 'Text content should not iso-8859-2, "ŕ" should be "à"')
|
125
|
+
|
126
|
+
# Without the patch, TMail::Unquoter.unquote_and_convert_to returns:
|
127
|
+
# Il semblerait que vous n'ayez pas consult� votre messagerie depuis plus
|
128
|
+
# d'un an. Aussi, celle-ci a �t� temporairement desactiv�e.
|
129
|
+
# Aucune demande n'est necessaire pour r�activer votre messagerie : la simple
|
130
|
+
# consultation de ce message indique que la boite est � nouveau utilisable.
|
131
|
+
end
|
132
|
+
|
133
|
+
protected
|
134
|
+
|
135
|
+
def load_fixture(name)
|
136
|
+
TMail::Mail.load(File.join('test', 'fixtures', name))
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|