tmail 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README +157 -0
- data/bat/changelog +19 -0
- data/bat/clobber/package +10 -0
- data/bat/compile +42 -0
- data/bat/config.yaml +8 -0
- data/bat/prepare +8 -0
- data/bat/publish +51 -0
- data/bat/rdoc +42 -0
- data/bat/release +12 -0
- data/bat/setup +1616 -0
- data/bat/stats +138 -0
- data/bat/tag +25 -0
- data/bat/test +25 -0
- data/ext/tmail/Makefile +25 -0
- data/ext/tmail/base64/MANIFEST +4 -0
- data/ext/tmail/base64/base64.c +264 -0
- data/ext/tmail/base64/depend +1 -0
- data/ext/tmail/base64/extconf.rb +38 -0
- data/ext/tmail/scanner_c/MANIFEST +4 -0
- data/ext/tmail/scanner_c/depend +1 -0
- data/ext/tmail/scanner_c/extconf.rb +38 -0
- data/ext/tmail/scanner_c/scanner_c.c +582 -0
- data/lib/tmail.rb +4 -0
- data/lib/tmail/Makefile +19 -0
- data/lib/tmail/address.rb +245 -0
- data/lib/tmail/attachments.rb +47 -0
- data/lib/tmail/base64.rb +75 -0
- data/lib/tmail/compat.rb +39 -0
- data/lib/tmail/config.rb +71 -0
- data/lib/tmail/core_extensions.rb +67 -0
- data/lib/tmail/encode.rb +524 -0
- data/lib/tmail/header.rb +931 -0
- data/lib/tmail/index.rb +8 -0
- data/lib/tmail/interface.rb +540 -0
- data/lib/tmail/loader.rb +1 -0
- data/lib/tmail/mail.rb +507 -0
- data/lib/tmail/mailbox.rb +435 -0
- data/lib/tmail/mbox.rb +1 -0
- data/lib/tmail/net.rb +282 -0
- data/lib/tmail/obsolete.rb +137 -0
- data/lib/tmail/parser.rb +1475 -0
- data/lib/tmail/parser.y +381 -0
- data/lib/tmail/port.rb +379 -0
- data/lib/tmail/quoting.rb +142 -0
- data/lib/tmail/require_arch.rb +56 -0
- data/lib/tmail/scanner.rb +44 -0
- data/lib/tmail/scanner_r.rb +263 -0
- data/lib/tmail/stringio.rb +279 -0
- data/lib/tmail/tmail.rb +1 -0
- data/lib/tmail/utils.rb +281 -0
- data/lib/tmail/version.rb +38 -0
- data/meta/icli.yaml +16 -0
- data/meta/tmail-1.1.1.roll +24 -0
- data/sample/data/multipart +23 -0
- data/sample/data/normal +29 -0
- data/sample/data/sendtest +5 -0
- data/sample/data/simple +14 -0
- data/sample/data/test +27 -0
- data/sample/extract-attachements.rb +33 -0
- data/sample/from-check.rb +26 -0
- data/sample/multipart.rb +26 -0
- data/sample/parse-bench.rb +68 -0
- data/sample/parse-test.rb +19 -0
- data/sample/sendmail.rb +94 -0
- data/test/extctrl.rb +6 -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_quoted_with_0d0a +14 -0
- data/test/fixtures/raw_email_simple +11 -0
- data/test/fixtures/raw_email_with_illegal_boundary +58 -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_illegal_boundary +58 -0
- data/test/kcode.rb +14 -0
- data/test/test_address.rb +1128 -0
- data/test/test_attachments.rb +35 -0
- data/test/test_base64.rb +63 -0
- data/test/test_encode.rb +77 -0
- data/test/test_header.rb +885 -0
- data/test/test_helper.rb +2 -0
- data/test/test_mail.rb +623 -0
- data/test/test_mbox.rb +126 -0
- data/test/test_port.rb +430 -0
- data/test/test_scanner.rb +209 -0
- data/test/test_utils.rb +37 -0
- metadata +205 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'tmail'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class TestAttachments < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_attachment
|
8
|
+
mail = TMail::Mail.new
|
9
|
+
mail.mime_version = "1.0"
|
10
|
+
mail.set_content_type 'multipart', 'mixed', {'boundary' => 'Apple-Mail-13-196941151'}
|
11
|
+
mail.body =<<HERE
|
12
|
+
--Apple-Mail-13-196941151
|
13
|
+
Content-Transfer-Encoding: quoted-printable
|
14
|
+
Content-Type: text/plain;
|
15
|
+
charset=ISO-8859-1;
|
16
|
+
delsp=yes;
|
17
|
+
format=flowed
|
18
|
+
|
19
|
+
This is the first part.
|
20
|
+
|
21
|
+
--Apple-Mail-13-196941151
|
22
|
+
Content-Type: text/x-ruby-script; name="hello.rb"
|
23
|
+
Content-Transfer-Encoding: 7bit
|
24
|
+
Content-Disposition: attachment;
|
25
|
+
filename="api.rb"
|
26
|
+
|
27
|
+
puts "Hello, world!"
|
28
|
+
gets
|
29
|
+
|
30
|
+
--Apple-Mail-13-196941151--
|
31
|
+
HERE
|
32
|
+
assert_equal(true, mail.multipart?)
|
33
|
+
assert_equal(1, mail.attachments.length)
|
34
|
+
end
|
35
|
+
end
|
data/test/test_base64.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'tmail/base64'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestTMailBase64 < Test::Unit::TestCase
|
5
|
+
def try(orig)
|
6
|
+
ok = [orig].pack('m').delete("\r\n")
|
7
|
+
result = TMail::Base64.c_encode(orig)
|
8
|
+
assert_equal ok, result, "str=#{orig.inspect}"
|
9
|
+
assert_equal orig, TMail::Base64.c_decode(result), "str=#{orig.inspect}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_normal
|
13
|
+
try ''
|
14
|
+
try 'a'
|
15
|
+
try 'ab'
|
16
|
+
try 'abc'
|
17
|
+
try 'abcd'
|
18
|
+
try 'abcde'
|
19
|
+
try 'abcdef'
|
20
|
+
try 'abcdefg'
|
21
|
+
try 'abcdefgh'
|
22
|
+
try 'abcdefghi'
|
23
|
+
try 'abcdefghij'
|
24
|
+
try 'abcdefghijk'
|
25
|
+
try 'abcdefghijkl'
|
26
|
+
try 'abcdefghijklm'
|
27
|
+
try 'abcdefghijklmn'
|
28
|
+
try 'abcdefghijklmno'
|
29
|
+
try 'abcdefghijklmnop'
|
30
|
+
try 'abcdefghijklmnopq'
|
31
|
+
try 'abcdefghijklmnopqr'
|
32
|
+
try 'abcdefghijklmnopqrs'
|
33
|
+
try 'abcdefghijklmnopqrst'
|
34
|
+
try 'abcdefghijklmnopqrstu'
|
35
|
+
try 'abcdefghijklmnopqrstuv'
|
36
|
+
try 'abcdefghijklmnopqrstuvw'
|
37
|
+
try 'abcdefghijklmnopqrstuvwx'
|
38
|
+
try 'abcdefghijklmnopqrstuvwxy'
|
39
|
+
try 'abcdefghijklmnopqrstuvwxyz'
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_dangerous_chars
|
43
|
+
["\0", "\001", "\002", "\003", "\0xfd", "\0xfe", "\0xff"].each do |ch|
|
44
|
+
1.upto(96) do |len|
|
45
|
+
try ch * len
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_random
|
51
|
+
16.times do
|
52
|
+
try make_random_string(96)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def make_random_string(len)
|
57
|
+
buf = ''
|
58
|
+
len.times do
|
59
|
+
buf << rand(255)
|
60
|
+
end
|
61
|
+
buf
|
62
|
+
end
|
63
|
+
end
|
data/test/test_encode.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'tmail/port'
|
2
|
+
require 'tmail/encode'
|
3
|
+
require 'nkf'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestEncode < Test::Unit::TestCase
|
7
|
+
|
8
|
+
SRCS = [
|
9
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあいうえお",
|
10
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあいうえ",
|
11
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあいう",
|
12
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあい",
|
13
|
+
"a cde あいうえおあいうえおあいうえおあいうえおあ",
|
14
|
+
"a cde あいうえおあいうえおあいうえおあいうえお", #
|
15
|
+
"a cde あいうえおあいうえおあいうえおあいうえ",
|
16
|
+
"a cde あいうえおあいうえおあいうえおあいう",
|
17
|
+
"a cde あいうえおあいうえおあいうえおあい",
|
18
|
+
"a cde あいうえおあいうえおあいうえおあ",
|
19
|
+
"a cde あいうえおあいうえおあいうえお",
|
20
|
+
"a cde あいうえおあいうえおあいうえ",
|
21
|
+
"a cde あいうえおあいうえおあいう",
|
22
|
+
"a cde あいうえおあいうえおあい",
|
23
|
+
"a cde あいうえおあいうえおあ",
|
24
|
+
"a cde あいうえおあいうえお",
|
25
|
+
"a cde あいうえおあいうえ",
|
26
|
+
"a cde あいうえおあいう",
|
27
|
+
"a cde あいうえおあい",
|
28
|
+
"a cde あいうえおあ",
|
29
|
+
"a cde あいうえお",
|
30
|
+
"a cde あいうえ",
|
31
|
+
"a cde あいう",
|
32
|
+
"a cde あい",
|
33
|
+
"a cde あ",
|
34
|
+
"aあa aあa aあa aあa"
|
35
|
+
]
|
36
|
+
|
37
|
+
OK = [
|
38
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQkJiQoJCokIiQkJCYkKCQqGyhC?=",
|
39
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQkJiQoJCokIiQkJCYkKBsoQg==?=",
|
40
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=",
|
41
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQkJiQoJCokIiQkGyhC?=",
|
42
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQkJiQoJCokIhsoQg==?=",
|
43
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQkJiQoJCobKEI=?=",
|
44
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQkJiQoGyhC?=",
|
45
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQkJhsoQg==?=",
|
46
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiJCQbKEI=?=",
|
47
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKiQiGyhC?=",
|
48
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgkKhsoQg==?=",
|
49
|
+
"a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=\n\t=?iso-2022-jp?B?GyRCJCgbKEI=?=",
|
50
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkJCYbKEI=?=',
|
51
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIiQkGyhC?=',
|
52
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCokIhsoQg==?=',
|
53
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoJCobKEI=?=',
|
54
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJiQoGyhC?=',
|
55
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQkJhsoQg==?=',
|
56
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiJCQbKEI=?=',
|
57
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQiGyhC?=',
|
58
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgkKhsoQg==?=',
|
59
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmJCgbKEI=?=',
|
60
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJCQmGyhC?=',
|
61
|
+
'a cde =?iso-2022-jp?B?GyRCJCIkJBsoQg==?=',
|
62
|
+
'a cde =?iso-2022-jp?B?GyRCJCIbKEI=?=',
|
63
|
+
"=?iso-2022-jp?B?YRskQiQiGyhCYSBhGyRCJCIbKEJhIGEbJEIkIhsoQmEgYQ==?=\n\t=?iso-2022-jp?B?GyRCJCIbKEJh?="
|
64
|
+
]
|
65
|
+
|
66
|
+
def test_s_encode
|
67
|
+
SRCS.each_index do |i|
|
68
|
+
assert_equal crlf(OK[i]),
|
69
|
+
TMail::Encoder.encode(NKF.nkf('-j', SRCS[i]))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def crlf( str )
|
74
|
+
str.gsub(/\n|\r\n|\r/) { "\r\n" }
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
data/test/test_header.rb
ADDED
@@ -0,0 +1,885 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'tmail'
|
3
|
+
require 'tmail/header'
|
4
|
+
require 'kcode'
|
5
|
+
require 'extctrl'
|
6
|
+
require 'test/unit'
|
7
|
+
require 'time'
|
8
|
+
require 'test_helper'
|
9
|
+
|
10
|
+
class UnstructuredHeaderTester < Test::Unit::TestCase
|
11
|
+
def test_s_new
|
12
|
+
%w( Subject SUBJECT sUbJeCt
|
13
|
+
X-My-Header ).each do |name|
|
14
|
+
h = TMail::HeaderField.new(name, 'This is test header.')
|
15
|
+
assert_instance_of TMail::UnstructuredHeader, h,
|
16
|
+
'Header.new: name=' + name.dump
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_to_s
|
21
|
+
# I must write more and more test.
|
22
|
+
[
|
23
|
+
'This is test header.',
|
24
|
+
# "This is \r\n\ttest header"
|
25
|
+
# "JAPANESE STRING"
|
26
|
+
''
|
27
|
+
]\
|
28
|
+
.each do |str|
|
29
|
+
h = TMail::HeaderField.new('Subject', str)
|
30
|
+
assert_equal str, h.decoded
|
31
|
+
assert_equal str, h.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class DateTimeHeaderTester < Test::Unit::TestCase
|
37
|
+
def test_s_new
|
38
|
+
%w( Date Resent-Date ).each do |name|
|
39
|
+
h = TMail::HeaderField.new(name, 'Tue, 4 Dec 2001 10:49:32 +0900')
|
40
|
+
assert_instance_of TMail::DateTimeHeader, h, name
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_date
|
45
|
+
h = TMail::HeaderField.new('Date', 'Tue, 4 Dec 2001 10:49:32 +0900')
|
46
|
+
assert_instance_of Time, h.date
|
47
|
+
assert_equal false, h.date.gmt?
|
48
|
+
assert_equal Time.parse('Tue, 4 Dec 2001 10:49:32 +0900'), h.date
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_empty__illegal?
|
52
|
+
[ [false, 'Tue, 4 Dec 2001 10:49:32 +0900'],
|
53
|
+
[false, 'Sat, 15 Dec 2001 12:51:38 +0900'],
|
54
|
+
[true, 'Sat, 15 Dec 2001 12:51:38'],
|
55
|
+
[true, 'Sat, 15 Dec 2001 12:51'],
|
56
|
+
[true, 'Sat,'] ].each do |wrong, str|
|
57
|
+
|
58
|
+
h = TMail::HeaderField.new('Date', str)
|
59
|
+
assert_equal wrong, h.empty?, str
|
60
|
+
assert_equal wrong, h.illegal?, str
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_to_s
|
65
|
+
h = TMail::HeaderField.new('Date', 'Tue, 4 Dec 2001 10:49:32 +0900')
|
66
|
+
time = Time.parse('Tue, 4 Dec 2001 10:49:32 +0900').strftime("%a,%e %b %Y %H:%M:%S %z")
|
67
|
+
assert_equal time, h.to_s
|
68
|
+
assert_equal h.to_s, h.decoded
|
69
|
+
ok = h.to_s
|
70
|
+
|
71
|
+
h = TMail::HeaderField.new('Date', 'Tue, 4 Dec 2001 01:49:32 +0000')
|
72
|
+
assert_equal ok, h.to_s
|
73
|
+
|
74
|
+
h = TMail::HeaderField.new('Date', 'Tue, 4 Dec 2001 01:49:32 GMT')
|
75
|
+
assert_equal ok, h.to_s
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class AddressHeaderTester < Test::Unit::TestCase
|
80
|
+
def test_s_new
|
81
|
+
%w( To Cc Bcc From Reply-To
|
82
|
+
Resent-To Resent-Cc Resent-Bcc
|
83
|
+
Resent-From Resent-Reply-To ).each do |name|
|
84
|
+
h = TMail::HeaderField.new(name, 'aamine@loveruby.net')
|
85
|
+
assert_instance_of TMail::AddressHeader, h, name
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def validate_case( str, isempty, to_s, comments, succ )
|
90
|
+
h = TMail::HeaderField.new('To', str)
|
91
|
+
assert_equal isempty, h.empty?, str.inspect + " (empty?)\n"
|
92
|
+
assert_instance_of Array, h.addrs, str.inspect + " (is a)\n"
|
93
|
+
assert_equal succ.size, h.addrs.size, str.inspect + " (size)\n"
|
94
|
+
h.addrs.each do |a|
|
95
|
+
ok = succ.shift
|
96
|
+
assert_equal ok[:phrase], a.phrase, str.inspect + " (phrase)\n"
|
97
|
+
assert_equal ok[:routes], a.routes, str.inspect + " (routes)\n"
|
98
|
+
assert_equal ok[:spec], a.spec, str.inspect + " (spec)\n"
|
99
|
+
end
|
100
|
+
assert_equal comments, h.comments, str.inspect + " (comments)\n"
|
101
|
+
assert_equal to_s, h.to_s, str.inspect + " (to_s)\n" if to_s
|
102
|
+
assert_equal to_s, h.decoded, str.inspect + " (decoded)\n" if to_s
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_ATTRS
|
106
|
+
validate_case 'aamine@loveruby.net',
|
107
|
+
false,
|
108
|
+
'aamine@loveruby.net',
|
109
|
+
[],
|
110
|
+
[{ :phrase => nil,
|
111
|
+
:routes => [],
|
112
|
+
:spec => 'aamine@loveruby.net' }]
|
113
|
+
|
114
|
+
validate_case 'Minero Aoki <aamine@loveruby.net> (comment)',
|
115
|
+
false,
|
116
|
+
'Minero Aoki <aamine@loveruby.net> (comment)',
|
117
|
+
['comment'],
|
118
|
+
[{ :phrase => 'Minero Aoki',
|
119
|
+
:routes => [],
|
120
|
+
:spec => 'aamine@loveruby.net' }]
|
121
|
+
|
122
|
+
validate_case 'aamine@loveruby.net, , taro@softica.org',
|
123
|
+
false,
|
124
|
+
'aamine@loveruby.net, taro@softica.org',
|
125
|
+
[],
|
126
|
+
[{ :phrase => nil,
|
127
|
+
:routes => [],
|
128
|
+
:spec => 'aamine@loveruby.net' },
|
129
|
+
{ :phrase => nil,
|
130
|
+
:routes => [],
|
131
|
+
:spec => 'taro@softica.org' }]
|
132
|
+
|
133
|
+
validate_case '',
|
134
|
+
true,
|
135
|
+
nil,
|
136
|
+
[],
|
137
|
+
[]
|
138
|
+
|
139
|
+
validate_case '(comment only)',
|
140
|
+
true,
|
141
|
+
nil,
|
142
|
+
['comment only'],
|
143
|
+
[]
|
144
|
+
|
145
|
+
kcode('EUC') {
|
146
|
+
validate_case 'hoge@example.jp (=?ISO-2022-JP?B?GyRCJUYlOSVIGyhC?=)',
|
147
|
+
false,
|
148
|
+
"hoge@example.jp (\245\306\245\271\245\310)",
|
149
|
+
["\245\306\245\271\245\310"],
|
150
|
+
[{ :phrase => nil,
|
151
|
+
:routes => [],
|
152
|
+
:spec => 'hoge@example.jp'}]
|
153
|
+
}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
class SingleAddressHeaderTester < Test::Unit::TestCase
|
158
|
+
def test_s_new
|
159
|
+
h = TMail::HeaderField.new('Sender', 'aamine@loveruby.net')
|
160
|
+
assert_instance_of TMail::SingleAddressHeader, h
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_addr
|
164
|
+
h = TMail::HeaderField.new('Sender', 'aamine@loveruby.net')
|
165
|
+
assert_not_nil h.addr
|
166
|
+
assert_instance_of TMail::Address, h.addr
|
167
|
+
assert_equal 'aamine@loveruby.net', h.addr.spec
|
168
|
+
assert_equal nil, h.addr.phrase
|
169
|
+
assert_equal [], h.addr.routes
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_to_s
|
173
|
+
str = 'Minero Aoki <aamine@loveruby.net>, "AOKI, Minero" <aamine@softica.org>'
|
174
|
+
h = TMail::HeaderField.new('Sender', str)
|
175
|
+
assert_equal 'Minero Aoki <aamine@loveruby.net>', h.to_s
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
class ReturnPathHeaderTester < Test::Unit::TestCase
|
180
|
+
def test_s_new
|
181
|
+
%w( Return-Path ).each do |name|
|
182
|
+
h = TMail::HeaderField.new(name, '<aamine@loveruby.net>')
|
183
|
+
assert_instance_of TMail::ReturnPathHeader, h, name
|
184
|
+
assert_equal false, h.empty?
|
185
|
+
assert_equal false, h.illegal?
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_ATTRS
|
190
|
+
h = TMail::HeaderField.new('Return-Path', '<@a,@b,@c:aamine@loveruby.net>')
|
191
|
+
assert_not_nil h.addr
|
192
|
+
assert_instance_of TMail::Address, h.addr
|
193
|
+
assert_equal 'aamine@loveruby.net', h.addr.spec
|
194
|
+
assert_equal nil, h.addr.phrase
|
195
|
+
assert_equal ['a', 'b', 'c'], h.addr.routes
|
196
|
+
|
197
|
+
assert_not_nil h.routes
|
198
|
+
assert_instance_of Array, h.routes
|
199
|
+
assert_equal ['a', 'b', 'c'], h.routes
|
200
|
+
assert_equal h.addr.routes, h.routes
|
201
|
+
|
202
|
+
assert_not_nil h.spec
|
203
|
+
assert_instance_of String, h.spec
|
204
|
+
assert_equal 'aamine@loveruby.net', h.spec
|
205
|
+
|
206
|
+
# missing '<' '>'
|
207
|
+
h = TMail::HeaderField.new('Return-Path', 'xxxx@yyyy')
|
208
|
+
assert_equal 'xxxx@yyyy', h.spec
|
209
|
+
|
210
|
+
h = TMail::HeaderField.new('Return-Path', '<>')
|
211
|
+
assert_instance_of TMail::Address, h.addr
|
212
|
+
assert_nil h.addr.local
|
213
|
+
assert_nil h.addr.domain
|
214
|
+
assert_nil h.addr.spec
|
215
|
+
assert_nil h.spec
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_to_s
|
219
|
+
body = 'Minero Aoki <@a,@b,@c:aamine@loveruby.net>'
|
220
|
+
h = TMail::HeaderField.new('Return-Path', body)
|
221
|
+
assert_equal '<@a,@b,@c:aamine@loveruby.net>', h.to_s
|
222
|
+
assert_equal h.to_s, h.decoded
|
223
|
+
|
224
|
+
body = 'aamine@loveruby.net'
|
225
|
+
h = TMail::HeaderField.new('Return-Path', body)
|
226
|
+
assert_equal '<aamine@loveruby.net>', h.to_s
|
227
|
+
assert_equal h.to_s, h.decoded
|
228
|
+
|
229
|
+
body = '<>'
|
230
|
+
h = TMail::HeaderField.new('Return-Path', body)
|
231
|
+
assert_equal '<>', h.to_s
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
class MessageIdHeaderTester < Test::Unit::TestCase
|
236
|
+
def test_s_new
|
237
|
+
%w( Message-Id MESSAGE-ID Message-ID
|
238
|
+
Resent-Message-Id Content-Id ).each do |name|
|
239
|
+
h = TMail::HeaderField.new(name, '<20020103xg88.k0@mail.loveruby.net>')
|
240
|
+
assert_instance_of TMail::MessageIdHeader, h
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_id
|
245
|
+
str = '<20020103xg88.k0@mail.loveruby.net>'
|
246
|
+
h = TMail::HeaderField.new('Message-Id', str)
|
247
|
+
assert_not_nil h.id
|
248
|
+
assert_equal str, h.id
|
249
|
+
|
250
|
+
id = '<20020103xg88.k0@mail.loveruby.net>'
|
251
|
+
str = id + ' (comm(ent))'
|
252
|
+
h = TMail::HeaderField.new('Message-Id', str)
|
253
|
+
assert_not_nil h.id
|
254
|
+
assert_equal id, h.id
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_id=
|
258
|
+
h = TMail::HeaderField.new('Message-Id', '')
|
259
|
+
h.id = str = '<20020103xg88.k0@mail.loveruby.net>'
|
260
|
+
assert_not_nil h.id
|
261
|
+
assert_equal str, h.id
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
class ReferencesHeaderTester < Test::Unit::TestCase
|
266
|
+
def test_s_new
|
267
|
+
str = '<20020103xg88.k0@mail.loveruby.net>'
|
268
|
+
%w( References REFERENCES ReFeReNcEs
|
269
|
+
In-Reply-To ).each do |name|
|
270
|
+
h = TMail::HeaderField.new(name, str)
|
271
|
+
assert_instance_of TMail::ReferencesHeader, h, name
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_ATTRS
|
276
|
+
id1 = '<20020103xg88.k0@mail.loveruby.net>'
|
277
|
+
id2 = '<20011204103415.64DB.GGB03124@nifty.ne.jp>'
|
278
|
+
phr = 'message of "Wed, 17 Mar 1999 18:42:07 +0900"'
|
279
|
+
str = id1 + ' ' + phr + ' ' + id2
|
280
|
+
|
281
|
+
h = TMail::HeaderField.new('References', str)
|
282
|
+
|
283
|
+
ok = [id1, id2]
|
284
|
+
h.each_id do |i|
|
285
|
+
assert_equal ok.shift, i
|
286
|
+
end
|
287
|
+
ok = [id1, id2]
|
288
|
+
assert_equal ok, h.ids
|
289
|
+
h.each_id do |i|
|
290
|
+
assert_equal ok.shift, i
|
291
|
+
end
|
292
|
+
|
293
|
+
ok = [phr]
|
294
|
+
assert_equal ok, h.phrases
|
295
|
+
h.each_phrase do |i|
|
296
|
+
assert_equal ok.shift, i
|
297
|
+
end
|
298
|
+
ok = [phr]
|
299
|
+
h.each_phrase do |i|
|
300
|
+
assert_equal ok.shift, i
|
301
|
+
end
|
302
|
+
|
303
|
+
|
304
|
+
# test 2
|
305
|
+
# 'In-Reply-To'
|
306
|
+
# 'aamine@dp.u-netsurf.ne.jp's message of "Fri, 8 Jan 1999 03:49:37 +0900"'
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_to_s
|
310
|
+
id1 = '<20020103xg88.k0@mail.loveruby.net>'
|
311
|
+
id2 = '<20011204103415.64DB.GGB03124@nifty.ne.jp>'
|
312
|
+
phr = 'message of "Wed, 17 Mar 1999 18:42:07 +0900"'
|
313
|
+
str = id1 + ' ' + phr + ' ' + id2
|
314
|
+
|
315
|
+
h = TMail::HeaderField.new('References', str)
|
316
|
+
assert_equal id1 + ' ' + id2, h.to_s
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
class ReceivedHeaderTester < Test::Unit::TestCase
|
321
|
+
HEADER1 = <<EOS
|
322
|
+
from helium.ruby-lang.org (helium.ruby-lang.org [210.251.121.214])
|
323
|
+
by doraemon.edit.ne.jp (8.12.1/8.12.0) via TCP with ESMTP
|
324
|
+
id fB41nwEj007438 for <aamine@mx.edit.ne.jp>;
|
325
|
+
Tue, 4 Dec 2001 10:49:58 +0900 (JST)
|
326
|
+
EOS
|
327
|
+
HEADER2 = <<EOS
|
328
|
+
from helium.ruby-lang.org (localhost [127.0.0.1])
|
329
|
+
by helium.ruby-lang.org (Postfix) with ESMTP
|
330
|
+
id 8F8951AF3F; Tue, 4 Dec 2001 10:49:32 +0900 (JST)
|
331
|
+
EOS
|
332
|
+
HEADER3 = <<EOS
|
333
|
+
from smtp1.dti.ne.jp (smtp1.dti.ne.jp [202.216.228.36])
|
334
|
+
by helium.ruby-lang.org (Postfix) with ESMTP id CE3A1C3
|
335
|
+
for <ruby-list@ruby-lang.org>; Tue, 4 Dec 2001 10:49:31 +0900 (JST)
|
336
|
+
EOS
|
337
|
+
|
338
|
+
=begin dangerous headers
|
339
|
+
# 2-word WITH (this header is also wrong in semantic)
|
340
|
+
# I cannot support this.
|
341
|
+
Received: by mebius with Microsoft Mail
|
342
|
+
id <01BE2B9D.9051EAA0@mebius>; Sat, 19 Dec 1998 22:18:54 -0800
|
343
|
+
=end
|
344
|
+
|
345
|
+
def test_s_new
|
346
|
+
%w( Received ).each do |name|
|
347
|
+
h = TMail::HeaderField.new(name, HEADER1)
|
348
|
+
assert_instance_of TMail::ReceivedHeader, h, name
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_ATTRS
|
353
|
+
h = TMail::HeaderField.new('Received', HEADER1)
|
354
|
+
assert_instance_of String, h.from
|
355
|
+
assert_equal 'helium.ruby-lang.org', h.from
|
356
|
+
|
357
|
+
assert_instance_of String, h.by
|
358
|
+
assert_equal 'doraemon.edit.ne.jp', h.by
|
359
|
+
|
360
|
+
assert_instance_of String, h.via
|
361
|
+
assert_equal 'TCP', h.via
|
362
|
+
|
363
|
+
assert_instance_of Array, h.with
|
364
|
+
assert_equal %w(ESMTP), h.with
|
365
|
+
|
366
|
+
assert_instance_of String, h.id
|
367
|
+
assert_equal 'fB41nwEj007438', h.id
|
368
|
+
|
369
|
+
assert_instance_of String, h._for
|
370
|
+
assert_equal 'aamine@mx.edit.ne.jp', h._for # must be <a> ?
|
371
|
+
|
372
|
+
assert_instance_of Time, h.date
|
373
|
+
time = Time.parse('Tue, 4 Dec 2001 10:49:58 +0900')
|
374
|
+
assert_equal time, h.date
|
375
|
+
|
376
|
+
h = TMail::HeaderField.new('Received', '; Tue, 4 Dec 2001 10:49:58 +0900')
|
377
|
+
assert_nil h.from
|
378
|
+
assert_nil h.by
|
379
|
+
assert_nil h.via
|
380
|
+
assert_equal [], h.with
|
381
|
+
assert_nil h.id
|
382
|
+
assert_nil h._for
|
383
|
+
time = Time.parse('Tue, 4 Dec 2001 10:49:58 +0900')
|
384
|
+
assert_equal time, h.date
|
385
|
+
|
386
|
+
# without date
|
387
|
+
h = TMail::HeaderField.new('Received', 'by NeXT.Mailer (1.144.2)')
|
388
|
+
assert_nil h.from
|
389
|
+
assert_equal 'NeXT.Mailer', h.by
|
390
|
+
assert_nil h.via
|
391
|
+
assert_equal [], h.with
|
392
|
+
assert_nil h.id
|
393
|
+
assert_nil h._for
|
394
|
+
assert_nil h.date
|
395
|
+
|
396
|
+
# FROM is not a domain
|
397
|
+
h = TMail::HeaderField.new('Received',
|
398
|
+
'from someuser@example.com; Tue, 24 Nov 1998 07:59:39 -0500')
|
399
|
+
assert_equal 'example.com', h.from
|
400
|
+
assert_nil h.by
|
401
|
+
assert_nil h.via
|
402
|
+
assert_equal [], h.with
|
403
|
+
assert_nil h.id
|
404
|
+
assert_nil h._for
|
405
|
+
time = Time.parse('Tue, 24 Nov 1998 07:59:39 -0500')
|
406
|
+
assert_equal time, h.date
|
407
|
+
|
408
|
+
=begin
|
409
|
+
# FOR is not route-addr.
|
410
|
+
# item order is wrong.
|
411
|
+
h = TMail::HeaderField.new('Received',
|
412
|
+
'from aamine by mail.softica.org with local for list@softica.org id 12Vm3N-00044L-01; Fri, 17 Mar 2000 10:59:53 +0900')
|
413
|
+
assert_equal 'aamine', h.from
|
414
|
+
assert_equal 'mail.softica.org', h.by
|
415
|
+
assert_nil h.via
|
416
|
+
assert_equal ['local'], h.with
|
417
|
+
assert_equal '12Vm3N-00044L-01', h.id
|
418
|
+
assert_equal 'list@softica.org', h._for
|
419
|
+
assert_equal Time.local(2000,4,17, 10,59,53), h.date
|
420
|
+
=end
|
421
|
+
|
422
|
+
# word + domain-literal in FROM
|
423
|
+
h = TMail::HeaderField.new('Received',
|
424
|
+
'from localhost [192.168.1.1]; Sat, 19 Dec 1998 22:19:50 PST')
|
425
|
+
assert_equal 'localhost', h.from
|
426
|
+
assert_nil h.by
|
427
|
+
assert_nil h.via
|
428
|
+
assert_equal [], h.with
|
429
|
+
assert_nil h.id
|
430
|
+
assert_nil h._for
|
431
|
+
time = Time.parse('Sat, 19 Dec 1998 22:19:50 PST')
|
432
|
+
assert_equal time, h.date
|
433
|
+
|
434
|
+
# addr-spec in BY (must be a domain)
|
435
|
+
h = TMail::HeaderField.new('Received',
|
436
|
+
'by aamine@loveruby.net; Wed, 24 Feb 1999 14:34:20 +0900')
|
437
|
+
assert_equal 'loveruby.net', h.by
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_to_s
|
441
|
+
h = TMail::HeaderField.new('Received', HEADER1)
|
442
|
+
time = Time.parse('Tue, 4 Dec 2001 10:49:58 +0900').strftime("%a,%e %b %Y %H:%M:%S %z")
|
443
|
+
assert_equal "from helium.ruby-lang.org by doraemon.edit.ne.jp via TCP with ESMTP id fB41nwEj007438 for <aamine@mx.edit.ne.jp>; #{time}", h.to_s
|
444
|
+
|
445
|
+
[
|
446
|
+
'from harmony.loveruby.net',
|
447
|
+
'by mail.loveruby.net',
|
448
|
+
'via TCP',
|
449
|
+
'with ESMTP',
|
450
|
+
'id LKJHSDFG',
|
451
|
+
'for <aamine@loveruby.net>',
|
452
|
+
"; #{time}"
|
453
|
+
]\
|
454
|
+
.each do |str|
|
455
|
+
h = TMail::HeaderField.new('Received', str)
|
456
|
+
assert_equal str, h.to_s, 'ReceivedHeader#to_s: data=' + str.dump
|
457
|
+
end
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
class KeywordsHeaderTester < Test::Unit::TestCase
|
462
|
+
def test_s_new
|
463
|
+
%w( Keywords KEYWORDS KeYwOrDs ).each do |name|
|
464
|
+
h = TMail::HeaderField.new(name, 'key, word, is, keyword')
|
465
|
+
assert_instance_of TMail::KeywordsHeader, h
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
def test_keys
|
470
|
+
h = TMail::HeaderField.new('Keywords', 'key, word, is, keyword')
|
471
|
+
assert_instance_of Array, h.keys
|
472
|
+
assert_equal %w(key word is keyword), h.keys
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
class EncryptedHeaderTester < Test::Unit::TestCase
|
477
|
+
def test_s_new
|
478
|
+
%w( Encrypted ).each do |name|
|
479
|
+
h = TMail::HeaderField.new(name, 'lot17 solt')
|
480
|
+
assert_instance_of TMail::EncryptedHeader, h
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_encrypter
|
485
|
+
h = TMail::HeaderField.new('Encrypted', 'lot17 solt')
|
486
|
+
assert_equal 'lot17', h.encrypter
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_encrypter=
|
490
|
+
h = TMail::HeaderField.new('Encrypted', 'lot17 solt')
|
491
|
+
h.encrypter = 'newscheme'
|
492
|
+
assert_equal 'newscheme', h.encrypter
|
493
|
+
end
|
494
|
+
|
495
|
+
def test_keyword
|
496
|
+
h = TMail::HeaderField.new('Encrypted', 'lot17 solt')
|
497
|
+
assert_equal 'solt', h.keyword
|
498
|
+
h = TMail::HeaderField.new('Encrypted', 'lot17')
|
499
|
+
assert_equal nil, h.keyword
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_keyword=
|
503
|
+
h = TMail::HeaderField.new('Encrypted', 'lot17 solt')
|
504
|
+
h.keyword = 'newscheme'
|
505
|
+
assert_equal 'newscheme', h.keyword
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
class MimeVersionHeaderTester < Test::Unit::TestCase
|
510
|
+
def test_s_new
|
511
|
+
%w( Mime-Version MIME-VERSION MiMe-VeRsIoN ).each do |name|
|
512
|
+
h = TMail::HeaderField.new(name, '1.0')
|
513
|
+
assert_instance_of TMail::MimeVersionHeader, h
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_ATTRS
|
518
|
+
h = TMail::HeaderField.new('Mime-Version', '1.0')
|
519
|
+
assert_equal 1, h.major
|
520
|
+
assert_equal 0, h.minor
|
521
|
+
assert_equal '1.0', h.version
|
522
|
+
|
523
|
+
h = TMail::HeaderField.new('Mime-Version', '99.77 (is ok)')
|
524
|
+
assert_equal 99, h.major
|
525
|
+
assert_equal 77, h.minor
|
526
|
+
assert_equal '99.77', h.version
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_major=
|
530
|
+
h = TMail::HeaderField.new('Mime-Version', '1.1')
|
531
|
+
h.major = 2
|
532
|
+
assert_equal 2, h.major
|
533
|
+
assert_equal 1, h.minor
|
534
|
+
assert_equal 2, h.major
|
535
|
+
h.major = 3
|
536
|
+
assert_equal 3, h.major
|
537
|
+
end
|
538
|
+
|
539
|
+
def test_minor=
|
540
|
+
h = TMail::HeaderField.new('Mime-Version', '2.3')
|
541
|
+
assert_equal 3, h.minor
|
542
|
+
h.minor = 5
|
543
|
+
assert_equal 5, h.minor
|
544
|
+
assert_equal 2, h.major
|
545
|
+
end
|
546
|
+
|
547
|
+
def test_to_s
|
548
|
+
h = TMail::HeaderField.new('Mime-Version', '1.0 (first version)')
|
549
|
+
assert_equal '1.0', h.to_s
|
550
|
+
end
|
551
|
+
|
552
|
+
def test_empty?
|
553
|
+
h = TMail::HeaderField.new('Mime-Version', '')
|
554
|
+
assert_equal true, h.empty?
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
class ContentTypeHeaderTester < Test::Unit::TestCase
|
559
|
+
def test_s_new
|
560
|
+
%w( Content-Type CONTENT-TYPE CoNtEnT-TyPe ).each do |name|
|
561
|
+
h = TMail::HeaderField.new(name, 'text/plain; charset=iso-2022-jp')
|
562
|
+
assert_instance_of TMail::ContentTypeHeader, h, name
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
def test_ATTRS
|
567
|
+
h = TMail::HeaderField.new('Content-Type', 'text/plain; charset=iso-2022-jp')
|
568
|
+
assert_equal 'text', h.main_type
|
569
|
+
assert_equal 'plain', h.sub_type
|
570
|
+
assert_equal 1, h.params.size
|
571
|
+
assert_equal 'iso-2022-jp', h.params['charset']
|
572
|
+
|
573
|
+
h = TMail::HeaderField.new('Content-Type', 'Text/Plain; Charset=shift_jis')
|
574
|
+
assert_equal 'text', h.main_type
|
575
|
+
assert_equal 'plain', h.sub_type
|
576
|
+
assert_equal 1, h.params.size
|
577
|
+
assert_equal 'shift_jis', h.params['charset']
|
578
|
+
end
|
579
|
+
|
580
|
+
def test_multipart_with_legal_unquoted_boundary
|
581
|
+
h = TMail::HeaderField.new('Content-Type', 'multipart/mixed; boundary=dDRMvlgZJXvWKvBx')
|
582
|
+
assert_equal 'multipart', h.main_type
|
583
|
+
assert_equal 'mixed', h.sub_type
|
584
|
+
assert_equal 1, h.params.size
|
585
|
+
assert_equal 'dDRMvlgZJXvWKvBx', h.params['boundary']
|
586
|
+
end
|
587
|
+
|
588
|
+
def test_multipart_with_legal_quoted_boundary_should_retain_quotations
|
589
|
+
h = TMail::HeaderField.new('Content-Type', 'multipart/mixed; boundary="dDRMvlgZJXvWKvBx"')
|
590
|
+
assert_equal 'multipart', h.main_type
|
591
|
+
assert_equal 'mixed', h.sub_type
|
592
|
+
assert_equal 1, h.params.size
|
593
|
+
assert_equal 'dDRMvlgZJXvWKvBx', h.params['boundary']
|
594
|
+
end
|
595
|
+
|
596
|
+
def test_multipart_with_illegal_unquoted_boundary_should_add_quotations
|
597
|
+
h = TMail::HeaderField.new('Content-Type', 'multipart/alternative; boundary=----=_=NextPart_000_0093_01C81419.EB75E850')
|
598
|
+
assert_equal 'multipart', h.main_type
|
599
|
+
assert_equal 'alternative', h.sub_type
|
600
|
+
assert_equal 1, h.params.size
|
601
|
+
assert_equal '----=_=NextPart_000_0093_01C81419.EB75E850', h.params['boundary']
|
602
|
+
end
|
603
|
+
|
604
|
+
def test_multipart_with_illegal_quoted_boundary_should_retain_quotations
|
605
|
+
h = TMail::HeaderField.new('Content-Type', 'multipart/alternative; boundary="----=_=NextPart_000_0093_01C81419.EB75E850"')
|
606
|
+
assert_equal 'multipart', h.main_type
|
607
|
+
assert_equal 'alternative', h.sub_type
|
608
|
+
assert_equal 1, h.params.size
|
609
|
+
assert_equal '----=_=NextPart_000_0093_01C81419.EB75E850', h.params['boundary']
|
610
|
+
end
|
611
|
+
|
612
|
+
def test_main_type=
|
613
|
+
h = TMail::HeaderField.new('Content-Type', 'text/plain; charset=iso-2022-jp')
|
614
|
+
assert_equal 'text', h.main_type
|
615
|
+
h.main_type = 'multipart'
|
616
|
+
assert_equal 'multipart', h.main_type
|
617
|
+
assert_equal 'multipart', h.main_type
|
618
|
+
h.main_type = 'TEXT'
|
619
|
+
assert_equal 'text', h.main_type
|
620
|
+
end
|
621
|
+
|
622
|
+
def test_sub_type=
|
623
|
+
h = TMail::HeaderField.new('Content-Type', 'text/plain; charset=iso-2022-jp')
|
624
|
+
assert_equal 'plain', h.sub_type
|
625
|
+
h.sub_type = 'html'
|
626
|
+
assert_equal 'html', h.sub_type
|
627
|
+
h.sub_type = 'PLAIN'
|
628
|
+
assert_equal 'plain', h.sub_type
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
class ContentEncodingHeaderTester < Test::Unit::TestCase
|
633
|
+
def test_s_new
|
634
|
+
%w( Content-Transfer-Encoding CONTENT-TRANSFER-ENCODING
|
635
|
+
COnteNT-TraNSFer-ENCodiNG ).each do |name|
|
636
|
+
h = TMail::HeaderField.new(name, 'Base64')
|
637
|
+
assert_instance_of TMail::ContentTransferEncodingHeader, h
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
def test_encoding
|
642
|
+
h = TMail::HeaderField.new('Content-Transfer-Encoding', 'Base64')
|
643
|
+
assert_equal 'base64', h.encoding
|
644
|
+
|
645
|
+
h = TMail::HeaderField.new('Content-Transfer-Encoding', '7bit')
|
646
|
+
assert_equal '7bit', h.encoding
|
647
|
+
end
|
648
|
+
|
649
|
+
def test_encoding=
|
650
|
+
h = TMail::HeaderField.new('Content-Transfer-Encoding', 'Base64')
|
651
|
+
assert_equal 'base64', h.encoding
|
652
|
+
h.encoding = '7bit'
|
653
|
+
assert_equal '7bit', h.encoding
|
654
|
+
end
|
655
|
+
|
656
|
+
def test_to_s
|
657
|
+
h = TMail::HeaderField.new('Content-Transfer-Encoding', 'Base64')
|
658
|
+
assert_equal 'Base64', h.to_s
|
659
|
+
assert_equal h.to_s, h.decoded
|
660
|
+
assert_equal h.to_s, h.encoded
|
661
|
+
end
|
662
|
+
|
663
|
+
def test_insertion_of_headers_and_encoding_them_short
|
664
|
+
mail = TMail::Mail.new
|
665
|
+
mail['X-Mail-Header'] = "short bit of data"
|
666
|
+
assert_equal("X-Mail-Header: short bit of data\r\n\r\n", mail.encoded)
|
667
|
+
end
|
668
|
+
|
669
|
+
def test_insertion_of_headers_and_encoding_them_more_than_78_char_total_with_whitespace
|
670
|
+
mail = TMail::Mail.new
|
671
|
+
mail['X-Ruby-Talk'] = "<11152772-AAFA-4614-95FD-9071A4BDF4A111152772-AAFA 4614-95FD-9071A4BDF4A1@grayproductions.net>"
|
672
|
+
assert_equal("X-Ruby-Talk: <11152772-AAFA-4614-95FD-9071A4BDF4A111152772-AAFA\r\n\t4614-95FD-9071A4BDF4A1@grayproductions.net>\r\n\r\n", mail.encoded)
|
673
|
+
result = TMail::Mail.parse(mail.encoded)
|
674
|
+
assert_equal(mail['X-Ruby-Talk'].to_s, result['X-Ruby-Talk'].to_s)
|
675
|
+
end
|
676
|
+
|
677
|
+
def test_insertion_of_headers_and_encoding_them_more_than_78_char_total_with_whitespace
|
678
|
+
mail = TMail::Mail.new
|
679
|
+
mail['X-Ruby-Talk'] = "<11152772-AAFA-4614-95FD-9071A4BDF4A111152772-AAFA 4614-95FD-9071A4BDF4A1@grayproductions.net11152772-AAFA-4614-95FD-9071A4BDF4A111152772-AAFA 4614-95FD-9071A4BDF4A1@grayproductions.net>"
|
680
|
+
assert_equal("X-Ruby-Talk: <11152772-AAFA-4614-95FD-9071A4BDF4A111152772-AAFA\r\n\t4614-95FD-9071A4BDF4A1@grayproductions.net11152772-AAFA-4614-95FD-9071A4BDF4A111152772-AAFA\r\n\t4614-95FD-9071A4BDF4A1@grayproductions.net>\r\n\r\n", mail.encoded)
|
681
|
+
result = TMail::Mail.parse(mail.encoded)
|
682
|
+
assert_equal(mail['X-Ruby-Talk'].to_s, result['X-Ruby-Talk'].to_s)
|
683
|
+
end
|
684
|
+
|
685
|
+
def test_insertion_of_headers_and_encoding_them_more_than_78_char_total_without_whitespace
|
686
|
+
mail = TMail::Mail.new
|
687
|
+
mail['X-Ruby-Talk'] = "<11152772-AAFA-4614-95FD-9071A4BDF4A111152772-AAFA-4614-95FD-9071A4BDF4A1@grayproductions.net>"
|
688
|
+
assert_equal("X-Ruby-Talk: <11152772-AAFA-4614-95FD-9071A4BDF4A111152772-AAFA-4614-95FD-9071A4BDF4A1@grayproductions.net>\r\n\r\n", mail.encoded)
|
689
|
+
result = TMail::Mail.parse(mail.encoded)
|
690
|
+
assert_equal(mail['X-Ruby-Talk'].to_s, result['X-Ruby-Talk'].to_s)
|
691
|
+
end
|
692
|
+
|
693
|
+
def test_insertion_of_headers_and_encoding_them_less_than_998_char_total_without_whitespace
|
694
|
+
mail = TMail::Mail.new
|
695
|
+
text_with_whitespace = ""; 985.times{text_with_whitespace << "a"}
|
696
|
+
mail['Reply-To'] = "#{text_with_whitespace}"
|
697
|
+
assert_equal("Reply-To: #{text_with_whitespace}\r\n\r\n", mail.encoded)
|
698
|
+
result = TMail::Mail.parse(mail.encoded)
|
699
|
+
assert_equal(mail['Reply-To'].to_s, result['Reply-To'].to_s)
|
700
|
+
end
|
701
|
+
|
702
|
+
def test_insertion_of_headers_and_encoding_them_more_than_998_char_total_without_whitespace
|
703
|
+
mail = TMail::Mail.new
|
704
|
+
text_with_whitespace = ""; 1200.times{text_with_whitespace << "a"}
|
705
|
+
before_text = ""; 985.times{before_text << "a"}
|
706
|
+
after_text = ""; 215.times{after_text << "a"}
|
707
|
+
mail['X-Ruby-Talk'] = "#{text_with_whitespace}"
|
708
|
+
assert_equal("X-Ruby-Talk: #{before_text}\r\n\t#{after_text}\r\n\r\n", mail.encoded)
|
709
|
+
end
|
710
|
+
|
711
|
+
def test_insertion_of_headers_and_encoding_with_1_more_than_998_char_total_without_whitespace
|
712
|
+
mail = TMail::Mail.new
|
713
|
+
text_with_whitespace = ""; 996.times{text_with_whitespace << "a"}
|
714
|
+
before_text = ""; 995.times{before_text << "a"}
|
715
|
+
after_text = ""; 1.times{after_text << "a"}
|
716
|
+
mail['X'] = "#{text_with_whitespace}"
|
717
|
+
assert_equal("X: #{before_text}\r\n\t#{after_text}\r\n\r\n", mail.encoded)
|
718
|
+
end
|
719
|
+
|
720
|
+
def test_insertion_of_headers_and_encoding_with_exactly_998_char_total_without_whitespace
|
721
|
+
mail = TMail::Mail.new
|
722
|
+
text_with_whitespace = ""; 995.times{text_with_whitespace << "a"}
|
723
|
+
before_text = ""; 995.times{before_text << "a"}
|
724
|
+
mail['X'] = "#{text_with_whitespace}"
|
725
|
+
assert_equal("X: #{before_text}\r\n\r\n", mail.encoded)
|
726
|
+
end
|
727
|
+
end
|
728
|
+
|
729
|
+
class ContentDispositionHeaderTester < Test::Unit::TestCase
|
730
|
+
def test_s_new
|
731
|
+
%w( Content-Disposition CONTENT-DISPOSITION
|
732
|
+
ConTENt-DIsPOsition ).each do |name|
|
733
|
+
h = TMail::HeaderField.new(name, 'attachment; filename="README.txt.pif"')
|
734
|
+
assert_instance_of TMail::ContentDispositionHeader, h
|
735
|
+
end
|
736
|
+
end
|
737
|
+
|
738
|
+
def test_ATTRS
|
739
|
+
begin
|
740
|
+
_test_ATTRS
|
741
|
+
_test_tspecials
|
742
|
+
_test_rfc2231_decode
|
743
|
+
#_test_rfc2231_encode
|
744
|
+
_test_raw_iso2022jp
|
745
|
+
_test_raw_eucjp
|
746
|
+
_test_raw_sjis
|
747
|
+
_test_code_conversion
|
748
|
+
ensure
|
749
|
+
$KCODE = 'NONE'
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
def _test_ATTRS
|
754
|
+
$KCODE = 'NONE'
|
755
|
+
|
756
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
757
|
+
'attachment; filename="README.txt.pif"')
|
758
|
+
assert_equal 'attachment', h.disposition
|
759
|
+
assert_equal 1, h.params.size
|
760
|
+
assert_equal 'README.txt.pif', h.params['filename']
|
761
|
+
|
762
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
763
|
+
'attachment; Filename="README.txt.pif"')
|
764
|
+
assert_equal 'attachment', h.disposition
|
765
|
+
assert_equal 1, h.params.size
|
766
|
+
assert_equal 'README.txt.pif', h.params['filename']
|
767
|
+
|
768
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
769
|
+
'attachment; filename=')
|
770
|
+
assert_equal true, h.empty?
|
771
|
+
assert_nil h.params
|
772
|
+
assert_nil h['filename']
|
773
|
+
end
|
774
|
+
|
775
|
+
def _test_tspecials
|
776
|
+
h = TMail::HeaderField.new('Content-Disposition', 'a; n=a')
|
777
|
+
h['n'] = %q|()<>[];:@\\,"/?=|
|
778
|
+
assert_equal 'a; n="()<>[];:@\\\\,\"/?="',
|
779
|
+
h.encoded
|
780
|
+
end
|
781
|
+
|
782
|
+
def _test_rfc2231_decode
|
783
|
+
$KCODE = 'EUC'
|
784
|
+
|
785
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
786
|
+
"attachment; filename*=iso-2022-jp'ja'%1b$B$Q$i$`%1b%28B")
|
787
|
+
assert_equal 'attachment', h.disposition
|
788
|
+
assert_equal 1, h.params.size
|
789
|
+
assert_equal "\244\321\244\351\244\340", h.params['filename']
|
790
|
+
end
|
791
|
+
|
792
|
+
def _test_rfc2231_encode
|
793
|
+
$KCODE = 'EUC'
|
794
|
+
|
795
|
+
h = TMail::HeaderField.new('Content-Disposition', 'a; n=a')
|
796
|
+
h['n'] = "\245\265\245\363\245\327\245\353.txt"
|
797
|
+
assert_equal "a; n*=iso-2022-jp'ja'%1B$B%255%25s%25W%25k%1B%28B.txt",
|
798
|
+
h.encoded
|
799
|
+
|
800
|
+
h = TMail::HeaderField.new('Content-Disposition', 'a; n=a')
|
801
|
+
h['n'] = "\245\265()<>[];:@\\,\"/?=%*'"
|
802
|
+
assert_equal "a;\r\n\tn*=iso-2022-jp'ja'%1B$B%255%1B%28B%28%29%3C%3E%5B%5D%3B%3A%40%5C%2C%22%2F%3F%3D%25%2A%27",
|
803
|
+
h.encoded
|
804
|
+
end
|
805
|
+
|
806
|
+
def _test_raw_iso2022jp
|
807
|
+
$KCODE = 'EUC'
|
808
|
+
# raw iso2022jp string in value (token)
|
809
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
810
|
+
%Q<attachment; filename=\e$BF|K\\8l\e(B.doc>)
|
811
|
+
assert_equal 'attachment', h.disposition
|
812
|
+
assert_equal 1, h.params.size
|
813
|
+
# assert_equal "\e$BF|K\\8l\e(B.doc", h.params['filename']
|
814
|
+
assert_equal "\306\374\313\334\270\354.doc", h.params['filename']
|
815
|
+
|
816
|
+
# raw iso2022jp string in value (quoted string)
|
817
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
818
|
+
%Q<attachment; filename="\e$BF|K\\8l\e(B.doc">)
|
819
|
+
assert_equal 'attachment', h.disposition
|
820
|
+
assert_equal 1, h.params.size
|
821
|
+
# assert_equal "\e$BF|K\\8l\e(B.doc", h.params['filename']
|
822
|
+
assert_equal "\306\374\313\334\270\354.doc", h.params['filename']
|
823
|
+
end
|
824
|
+
|
825
|
+
def _test_raw_eucjp
|
826
|
+
$KCODE = 'EUC'
|
827
|
+
# raw EUC-JP string in value (token)
|
828
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
829
|
+
%Q<attachment; filename=\306\374\313\334\270\354.doc>)
|
830
|
+
assert_equal 'attachment', h.disposition
|
831
|
+
assert_equal 1, h.params.size
|
832
|
+
assert_equal "\306\374\313\334\270\354.doc", h.params['filename']
|
833
|
+
|
834
|
+
# raw EUC-JP string in value (quoted-string)
|
835
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
836
|
+
%Q<attachment; filename="\306\374\313\334\270\354.doc">)
|
837
|
+
assert_equal 'attachment', h.disposition
|
838
|
+
assert_equal 1, h.params.size
|
839
|
+
assert_equal "\306\374\313\334\270\354.doc", h.params['filename']
|
840
|
+
end
|
841
|
+
|
842
|
+
def _test_raw_sjis
|
843
|
+
$KCODE = 'SJIS'
|
844
|
+
# raw SJIS string in value (token)
|
845
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
846
|
+
%Q<attachment; filename=\223\372\226{\214\352.doc>)
|
847
|
+
assert_equal 'attachment', h.disposition
|
848
|
+
assert_equal 1, h.params.size
|
849
|
+
assert_equal "\223\372\226{\214\352.doc", h.params['filename']
|
850
|
+
|
851
|
+
# raw SJIS string in value (quoted-string)
|
852
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
853
|
+
%Q<attachment; filename="\223\372\226{\214\352.doc">)
|
854
|
+
assert_equal 'attachment', h.disposition
|
855
|
+
assert_equal 1, h.params.size
|
856
|
+
assert_equal "\223\372\226{\214\352.doc", h.params['filename']
|
857
|
+
end
|
858
|
+
|
859
|
+
def _test_code_conversion
|
860
|
+
# JIS -> $KCODE auto conversion
|
861
|
+
$KCODE = 'EUC'
|
862
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
863
|
+
%Q<attachment; filename=\e$BF|K\\8l\e(B.doc>)
|
864
|
+
assert_equal 'attachment', h.disposition
|
865
|
+
assert_equal 1, h.params.size
|
866
|
+
assert_equal "\306\374\313\334\270\354.doc", h.params['filename']
|
867
|
+
|
868
|
+
$KCODE = 'SJIS'
|
869
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
870
|
+
%Q<attachment; filename=\e$BF|K\\8l\e(B.doc>)
|
871
|
+
assert_equal 'attachment', h.disposition
|
872
|
+
assert_equal 1, h.params.size
|
873
|
+
assert_equal "\223\372\226{\214\352.doc", h.params['filename']
|
874
|
+
end
|
875
|
+
|
876
|
+
def test_disposition=
|
877
|
+
h = TMail::HeaderField.new('Content-Disposition',
|
878
|
+
'attachment; filename="README.txt.pif"')
|
879
|
+
assert_equal 'attachment', h.disposition
|
880
|
+
h.disposition = 'virus'
|
881
|
+
assert_equal 'virus', h.disposition
|
882
|
+
h.disposition = 'AtTaChMeNt'
|
883
|
+
assert_equal 'attachment', h.disposition
|
884
|
+
end
|
885
|
+
end
|