valodzka-tmail 1.2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +74 -0
- data/LICENSE +21 -0
- data/NOTES +7 -0
- data/README +169 -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 +583 -0
- data/lib/tmail/Makefile +18 -0
- data/lib/tmail/address.rb +392 -0
- data/lib/tmail/attachments.rb +46 -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 +960 -0
- data/lib/tmail/index.rb +9 -0
- data/lib/tmail/interface.rb +1152 -0
- data/lib/tmail/loader.rb +3 -0
- data/lib/tmail/mail.rb +582 -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 +125 -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 +337 -0
- data/lib/tmail/version.rb +39 -0
- data/lib/tmail.rb +5 -0
- data/log/BugTrackingLog.txt +1245 -0
- data/log/Changelog.txt +534 -0
- data/log/Testlog.txt +2340 -0
- data/log/Todo.txt +30 -0
- data/meta/MANIFEST +128 -0
- data/meta/VERSION +1 -0
- data/meta/project.yaml +30 -0
- data/meta/unixname +1 -0
- data/sample/bench_base64.rb +48 -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/setup.rb +1482 -0
- data/site/contributing/index.html +183 -0
- data/site/css/clean.css +27 -0
- data/site/css/layout.css +31 -0
- data/site/css/style.css +60 -0
- data/site/download/index.html +61 -0
- data/site/img/envelope.jpg +0 -0
- data/site/img/mailman.gif +0 -0
- data/site/img/stamp-sm.jpg +0 -0
- data/site/img/stamp.jpg +0 -0
- data/site/img/stampborder.jpg +0 -0
- data/site/img/tfire.jpg +0 -0
- data/site/img/tmail.png +0 -0
- data/site/index.html +270 -0
- data/site/js/jquery.js +31 -0
- data/site/log/Changelog.xsl +33 -0
- data/site/log/changelog.xml +1677 -0
- data/site/outdated/BUGS +3 -0
- data/site/outdated/DEPENDS +1 -0
- data/site/outdated/Incompatibilities +89 -0
- data/site/outdated/Incompatibilities.ja +102 -0
- data/site/outdated/NEWS +9 -0
- data/site/outdated/README.ja +73 -0
- data/site/outdated/doc.ja/address.html +275 -0
- data/site/outdated/doc.ja/basics.html +405 -0
- data/site/outdated/doc.ja/config.html +49 -0
- data/site/outdated/doc.ja/details.html +146 -0
- data/site/outdated/doc.ja/index.html +39 -0
- data/site/outdated/doc.ja/mail.html +793 -0
- data/site/outdated/doc.ja/mailbox.html +265 -0
- data/site/outdated/doc.ja/port.html +95 -0
- data/site/outdated/doc.ja/tmail.html +58 -0
- data/site/outdated/doc.ja/usage.html +202 -0
- data/site/outdated/rdd/address.rrd.m +229 -0
- data/site/outdated/rdd/basics.rd.m +275 -0
- data/site/outdated/rdd/config.rrd.m +26 -0
- data/site/outdated/rdd/details.rd.m +117 -0
- data/site/outdated/rdd/index.rhtml.m +54 -0
- data/site/outdated/rdd/mail.rrd.m +701 -0
- data/site/outdated/rdd/mailbox.rrd.m +228 -0
- data/site/outdated/rdd/port.rrd.m +69 -0
- data/site/outdated/rdd/tmail.rrd.m +33 -0
- data/site/outdated/rdd/usage.rd.m +247 -0
- data/site/quickstart/index.html +69 -0
- data/site/quickstart/quickstart.html +52 -0
- data/site/quickstart/usage.html +193 -0
- data/site/reference/address.html +247 -0
- data/site/reference/config.html +30 -0
- data/site/reference/index.html +101 -0
- data/site/reference/mail.html +726 -0
- data/site/reference/mailbox.html +245 -0
- data/site/reference/port.html +75 -0
- data/site/reference/tmail.html +35 -0
- data/test/extctrl.rb +6 -0
- data/test/fixtures/mailbox +414 -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/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_multiple_from +30 -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_with_bad_date +48 -0
- data/test/fixtures/raw_email_with_double_carriage_return +179 -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_illegal_boundary +58 -0
- data/test/kcode.rb +14 -0
- data/test/temp_test_one.rb +46 -0
- data/test/test_address.rb +1214 -0
- data/test/test_attachments.rb +73 -0
- data/test/test_base64.rb +64 -0
- data/test/test_encode.rb +85 -0
- data/test/test_header.rb +1002 -0
- data/test/test_helper.rb +9 -0
- data/test/test_mail.rb +761 -0
- data/test/test_mbox.rb +184 -0
- data/test/test_port.rb +436 -0
- data/test/test_quote.rb +107 -0
- data/test/test_scanner.rb +209 -0
- data/test/test_utils.rb +36 -0
- data/work/script/make +26 -0
- data/work/script/rdoc +39 -0
- data/work/script/setup +1616 -0
- data/work/script/test +30 -0
- metadata +298 -0
data/test/test_mbox.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tmail/mailbox'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class MailboxTester < Test::Unit::TestCase
|
6
|
+
include FileUtils
|
7
|
+
|
8
|
+
MAILBOX = '_mh'
|
9
|
+
N = 5
|
10
|
+
|
11
|
+
def setup
|
12
|
+
rm_rf MAILBOX
|
13
|
+
mkdir MAILBOX
|
14
|
+
N.downto(1) do |i|
|
15
|
+
File.open( "#{MAILBOX}/#{i}", 'w' ) {|f|
|
16
|
+
f.puts 'From: aamine'
|
17
|
+
f.puts 'To: aamine@loveruby.net'
|
18
|
+
f.puts "Subject: #{i}"
|
19
|
+
f.puts ''
|
20
|
+
f.puts 'body'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
@n = N
|
24
|
+
|
25
|
+
@ld = TMail::MhMailbox.new( MAILBOX )
|
26
|
+
end
|
27
|
+
|
28
|
+
def make_mails_older( diff )
|
29
|
+
Dir.entries( MAILBOX ).collect {|n| "#{MAILBOX}/#{n}" }.each do |path|
|
30
|
+
if File.file? path then
|
31
|
+
t = File.mtime(path) - diff
|
32
|
+
File.utime t, t, path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
rm_rf MAILBOX
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_s_new
|
42
|
+
ld = TMail::MhMailbox.new( MAILBOX )
|
43
|
+
assert_instance_of TMail::MhMailbox, ld
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_each_port
|
47
|
+
dir = File.expand_path(MAILBOX)
|
48
|
+
c = 0
|
49
|
+
n = 0
|
50
|
+
TMail::MhMailbox.new( MAILBOX ).each_port do |port|
|
51
|
+
assert_kind_of TMail::FilePort, port
|
52
|
+
assert_equal dir, File.dirname(port.filename)
|
53
|
+
assert_match(/\A\d+\z/, File.basename(port.filename))
|
54
|
+
nn = File.basename(port.filename).to_i
|
55
|
+
assert nn > n
|
56
|
+
n = nn
|
57
|
+
c += 1
|
58
|
+
end
|
59
|
+
assert_equal N, c
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_reverse_each_port
|
63
|
+
dir = File.expand_path(MAILBOX)
|
64
|
+
c = 0
|
65
|
+
n = 100000
|
66
|
+
TMail::MhMailbox.new( MAILBOX ).reverse_each_port do |port|
|
67
|
+
assert_kind_of TMail::FilePort, port
|
68
|
+
assert_equal dir, File.dirname(port.filename)
|
69
|
+
assert_match(/\A\d+\z/, File.basename(port.filename))
|
70
|
+
nn = File.basename(port.filename).to_i
|
71
|
+
assert nn < n
|
72
|
+
n = nn
|
73
|
+
c += 1
|
74
|
+
end
|
75
|
+
assert_equal N, c
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_new_port
|
79
|
+
port = @ld.new_port
|
80
|
+
assert_kind_of TMail::FilePort, port
|
81
|
+
assert_equal File.expand_path('.') + '/' + MAILBOX,
|
82
|
+
File.dirname(port.filename)
|
83
|
+
assert_equal( (N+1).to_s, File.basename(port.filename) )
|
84
|
+
|
85
|
+
create port
|
86
|
+
end
|
87
|
+
|
88
|
+
def create( port )
|
89
|
+
port.wopen {|f|
|
90
|
+
f.puts 'From: aamine'
|
91
|
+
f.puts 'To: aamine@loveruby.net'
|
92
|
+
f.puts "Subject: #{@n + 1}"
|
93
|
+
f.puts ''
|
94
|
+
f.puts 'body'
|
95
|
+
}
|
96
|
+
@n += 1
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_each_new_port
|
100
|
+
make_mails_older 5
|
101
|
+
|
102
|
+
c = 0
|
103
|
+
@ld.each_new_port do |port|
|
104
|
+
assert_kind_of TMail::FilePort, port
|
105
|
+
c += 1
|
106
|
+
end
|
107
|
+
assert_equal @n, c
|
108
|
+
|
109
|
+
t = Time.now - 2
|
110
|
+
create @ld.new_port
|
111
|
+
c = 0
|
112
|
+
@ld.each_new_port( t ) do |port|
|
113
|
+
assert_kind_of TMail::FilePort, port
|
114
|
+
c += 1
|
115
|
+
end
|
116
|
+
assert_equal 1, c
|
117
|
+
|
118
|
+
make_mails_older 5
|
119
|
+
c = 0
|
120
|
+
@ld.each_new_port do |port|
|
121
|
+
assert_kind_of TMail::FilePort, port
|
122
|
+
c += 1
|
123
|
+
end
|
124
|
+
assert_equal 0, c
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_unix_mbox_fromaddr_method
|
128
|
+
p = TMail::FilePort.new("#{File.dirname(__FILE__)}/fixtures/mailbox")
|
129
|
+
assert_equal(TMail::UNIXMbox.fromaddr(p), "mikel@return_path.com")
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_unix_mbox_fromaddr_method_missing_return_path
|
133
|
+
p = TMail::FilePort.new("#{File.dirname(__FILE__)}/fixtures/mailbox_without_return_path")
|
134
|
+
assert_equal(TMail::UNIXMbox.fromaddr(p), "mikel@from_address.com")
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_unix_mbox_fromaddr_method_missing_from_address
|
138
|
+
p = TMail::FilePort.new("#{File.dirname(__FILE__)}/fixtures/mailbox_without_from")
|
139
|
+
assert_equal(TMail::UNIXMbox.fromaddr(p), "mike@envelope_sender.com.au")
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_unix_mbox_from_addr_method_missing_all_from_fields_in_the_email
|
143
|
+
p = TMail::FilePort.new("#{File.dirname(__FILE__)}/fixtures/mailbox_without_any_from_or_sender")
|
144
|
+
assert_equal(TMail::UNIXMbox.fromaddr(p), "nobody")
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_opening_mailbox_to_read_does_not_raise_IO_error
|
148
|
+
mailbox = TMail::UNIXMbox.new("#{File.dirname(__FILE__)}/fixtures/mailbox", nil, true)
|
149
|
+
assert_nothing_raised do
|
150
|
+
mailbox.each_port do |port|
|
151
|
+
TMail::Mail.new(port)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_reading_correct_number_of_emails_from_a_mailbox
|
157
|
+
mailbox = TMail::UNIXMbox.new("#{File.dirname(__FILE__)}/fixtures/mailbox", nil, true)
|
158
|
+
@emails = []
|
159
|
+
mailbox.each_port { |m| @emails << TMail::Mail.new(m) }
|
160
|
+
assert_equal(4, @emails.length)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_truncating_a_mailbox_to_zero_if_it_is_opened_with_readonly_false
|
164
|
+
filename = "#{File.dirname(__FILE__)}/fixtures/mailbox"
|
165
|
+
FileUtils.copy(filename, "#{filename}_test")
|
166
|
+
filename = "#{filename}_test"
|
167
|
+
mailbox = TMail::UNIXMbox.new(filename, nil, false)
|
168
|
+
@emails = []
|
169
|
+
mailbox.each_port { |m| @emails << TMail::Mail.new(m) }
|
170
|
+
assert_equal(4, @emails.length)
|
171
|
+
assert_equal('', File.read(filename))
|
172
|
+
File.delete(filename)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_fromline2time_should_return_nil_on_out_of_range_dates
|
176
|
+
filename = "#{File.dirname(__FILE__)}/fixtures/mailbox"
|
177
|
+
FileUtils.copy(filename, "#{filename}_test")
|
178
|
+
filename = "#{filename}_test"
|
179
|
+
line = "From mikel mikel March 24 01:02:03 1900"
|
180
|
+
mailbox = TMail::UNIXMbox.new(filename, nil, false)
|
181
|
+
assert_equal(nil, mailbox.send(:fromline2time, line))
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
data/test/test_port.rb
ADDED
@@ -0,0 +1,436 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tmail/loader'
|
3
|
+
require 'tmail/port'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
class FilePortTester < Test::Unit::TestCase
|
7
|
+
include FileUtils
|
8
|
+
|
9
|
+
def setup
|
10
|
+
rm_rf 'tmp'
|
11
|
+
mkdir 'tmp'
|
12
|
+
5.times do |n|
|
13
|
+
File.open('tmp/' + n.to_s, 'w') {|f|
|
14
|
+
f.puts "file #{n}"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
rm_rf 'tmp'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_s_new
|
24
|
+
port = TMail::FilePort.new('tmp/1')
|
25
|
+
assert_instance_of TMail::FilePort, port
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_inspect
|
29
|
+
port = TMail::FilePort.new('tmp/1')
|
30
|
+
port.inspect
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_EQUAL # ==
|
34
|
+
port = TMail::FilePort.new('tmp/1')
|
35
|
+
assert_equal port, port
|
36
|
+
p2 = TMail::FilePort.new('tmp/1')
|
37
|
+
assert_equal port, p2
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_eql?
|
41
|
+
port = TMail::FilePort.new('tmp/1')
|
42
|
+
assert_equal true, port.eql?(port)
|
43
|
+
p2 = TMail::FilePort.new('tmp/1')
|
44
|
+
assert_equal true, port.eql?(p2)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_hash
|
48
|
+
port = TMail::FilePort.new('tmp/1')
|
49
|
+
assert_equal port.hash, port.hash
|
50
|
+
p2 = TMail::FilePort.new('tmp/1')
|
51
|
+
assert_equal port.hash, p2.hash
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_filename
|
55
|
+
port = TMail::FilePort.new('tmp/1')
|
56
|
+
assert_not_nil port.filename
|
57
|
+
assert_equal File.expand_path('tmp/1'), port.filename
|
58
|
+
assert_equal File.expand_path('tmp/1'), port.filename
|
59
|
+
|
60
|
+
port = TMail::FilePort.new('tmp/2')
|
61
|
+
assert_not_nil port.filename
|
62
|
+
assert_equal File.expand_path('tmp/2'), port.filename
|
63
|
+
assert_equal File.expand_path('tmp/2'), port.filename
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_ident
|
67
|
+
ports = []
|
68
|
+
5.times do |n|
|
69
|
+
ports.push TMail::FilePort.new("tmp/#{n}")
|
70
|
+
end
|
71
|
+
|
72
|
+
until ports.empty? do
|
73
|
+
base = ports.shift
|
74
|
+
ports.each do |other|
|
75
|
+
assert_not_equal base.ident, other.ident
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_size
|
81
|
+
5.times do |n|
|
82
|
+
port = TMail::FilePort.new("tmp/#{n}")
|
83
|
+
assert_equal File.size("tmp/#{n}"), port.size
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_ropen
|
88
|
+
port = TMail::FilePort.new("tmp/1")
|
89
|
+
f = port.ropen
|
90
|
+
assert_instance_of File, f
|
91
|
+
assert_equal false, f.closed?
|
92
|
+
assert_equal 'f', f.read(1)
|
93
|
+
f.close
|
94
|
+
|
95
|
+
f = nil
|
96
|
+
port.ropen {|ff|
|
97
|
+
assert_instance_of File, ff
|
98
|
+
assert_equal false, ff.closed?
|
99
|
+
assert_equal 'f', ff.read(1)
|
100
|
+
f = ff
|
101
|
+
}
|
102
|
+
assert_equal true, f.closed?
|
103
|
+
|
104
|
+
assert_raises( Errno::ENOENT ) {
|
105
|
+
TMail::FilePort.new('tmp/100').ropen
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_wopen
|
110
|
+
port = TMail::FilePort.new('tmp/1')
|
111
|
+
f = port.wopen
|
112
|
+
assert_instance_of File, f
|
113
|
+
assert_equal false, f.closed?
|
114
|
+
f.puts 'ok'
|
115
|
+
f.close
|
116
|
+
|
117
|
+
f = nil
|
118
|
+
port.wopen {|ff|
|
119
|
+
assert_instance_of File, ff
|
120
|
+
assert_equal false, ff.closed?
|
121
|
+
ff.puts 'ok'
|
122
|
+
f = ff
|
123
|
+
}
|
124
|
+
assert_equal true, f.closed?
|
125
|
+
|
126
|
+
TMail::FilePort.new('tmp/100').wopen {|ff| }
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_aopen
|
130
|
+
port = TMail::FilePort.new('tmp/1')
|
131
|
+
size = port.size
|
132
|
+
f = port.aopen
|
133
|
+
assert_instance_of File, f
|
134
|
+
assert_equal false, f.closed?
|
135
|
+
f.print 'N'
|
136
|
+
f.close
|
137
|
+
assert_equal size + 1, port.size
|
138
|
+
port.ropen {|ff|
|
139
|
+
assert_equal 'f', ff.read(1)
|
140
|
+
}
|
141
|
+
|
142
|
+
f = nil
|
143
|
+
port.aopen {|ff|
|
144
|
+
assert_instance_of File, ff
|
145
|
+
assert_equal false, ff.closed?
|
146
|
+
ff.print 'N'
|
147
|
+
f = ff
|
148
|
+
}
|
149
|
+
assert_equal true, f.closed?
|
150
|
+
assert_equal size + 1 + 1, port.size
|
151
|
+
port.ropen {|ff|
|
152
|
+
assert_equal 'f', ff.read(1)
|
153
|
+
}
|
154
|
+
|
155
|
+
TMail::FilePort.new('tmp/100').aopen {|ff| }
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_read_all
|
159
|
+
5.times do |n|
|
160
|
+
port = TMail::FilePort.new("tmp/#{n}")
|
161
|
+
assert_equal readall("tmp/#{n}"), port.read_all
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_copy_to
|
166
|
+
src = TMail::FilePort.new('tmp/1')
|
167
|
+
dest = TMail::FilePort.new('tmp/10')
|
168
|
+
src.copy_to dest
|
169
|
+
assert_equal readall('tmp/1'), readall('tmp/10')
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_move_to
|
173
|
+
src = TMail::FilePort.new('tmp/1')
|
174
|
+
str = src.read_all
|
175
|
+
dest = TMail::FilePort.new('tmp/10')
|
176
|
+
src.move_to dest
|
177
|
+
assert_equal str, readall('tmp/10')
|
178
|
+
assert_raises( Errno::ENOENT ) { src.ropen }
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_remove
|
182
|
+
port = TMail::FilePort.new('tmp/1')
|
183
|
+
port.remove
|
184
|
+
assert_raises(Errno::ENOENT) {
|
185
|
+
port.ropen
|
186
|
+
}
|
187
|
+
|
188
|
+
port = TMail::FilePort.new('tmp/100')
|
189
|
+
assert_raises(Errno::ENOENT) {
|
190
|
+
port.remove
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
194
|
+
def readall(fname)
|
195
|
+
File.open(fname) {|f|
|
196
|
+
return f.read
|
197
|
+
}
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class StringPortTester < Test::Unit::TestCase
|
202
|
+
def test_s_new
|
203
|
+
port = TMail::StringPort.new
|
204
|
+
assert_instance_of TMail::StringPort, port
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_EQUAL # ==
|
208
|
+
port = TMail::StringPort.new(str = '')
|
209
|
+
port2 = TMail::StringPort.new(str)
|
210
|
+
other = TMail::StringPort.new
|
211
|
+
assert_equal port, port
|
212
|
+
assert_equal port, port2
|
213
|
+
assert_not_equal port, other
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_eql?
|
217
|
+
port = TMail::StringPort.new(str = '')
|
218
|
+
port2 = TMail::StringPort.new(str)
|
219
|
+
other = TMail::StringPort.new
|
220
|
+
assert_equal true, port.eql?(port)
|
221
|
+
assert_equal true, port.eql?(port2)
|
222
|
+
assert_equal false, port.eql?(other)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_hash
|
226
|
+
port = TMail::StringPort.new(str = '')
|
227
|
+
port2 = TMail::StringPort.new(str)
|
228
|
+
other = TMail::StringPort.new
|
229
|
+
assert_equal port.hash, port.hash
|
230
|
+
assert_equal port.hash, port2.hash
|
231
|
+
# assert_not_equal port.hash, other.hash
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_string
|
235
|
+
port = TMail::StringPort.new(str = '')
|
236
|
+
assert_same str, port.string
|
237
|
+
assert_same port.string, port.string
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_to_s
|
241
|
+
port = TMail::StringPort.new(str = 'abc')
|
242
|
+
assert_equal str, port.to_s
|
243
|
+
port.to_s.concat 'XXX'
|
244
|
+
assert_equal str, port.to_s
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_inspect
|
248
|
+
TMail::StringPort.new.inspect
|
249
|
+
TMail::StringPort.new('abc').inspect
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_size
|
253
|
+
port = TMail::StringPort.new(str = 'abc')
|
254
|
+
assert_equal str.size, port.size
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_ropen
|
258
|
+
port = TMail::StringPort.new(str = 'abc')
|
259
|
+
f = port.ropen
|
260
|
+
assert_equal false, f.closed?
|
261
|
+
assert_equal 'a', f.read(1)
|
262
|
+
f.close
|
263
|
+
|
264
|
+
port.ropen {|ff|
|
265
|
+
assert_equal false, ff.closed?
|
266
|
+
assert_equal 'a', ff.read(1)
|
267
|
+
f = ff
|
268
|
+
}
|
269
|
+
assert_equal true, f.closed?
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_wopen
|
273
|
+
port = TMail::StringPort.new(str = 'abc')
|
274
|
+
f = port.wopen
|
275
|
+
assert_equal false, f.closed?
|
276
|
+
f.print 'N'
|
277
|
+
f.close
|
278
|
+
assert_equal 'N', port.read_all
|
279
|
+
|
280
|
+
port.wopen {|ff|
|
281
|
+
assert_equal false, ff.closed?
|
282
|
+
ff.print 'NN'
|
283
|
+
f = ff
|
284
|
+
}
|
285
|
+
assert_equal true, f.closed?
|
286
|
+
assert_equal 'NN', port.read_all
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_aopen
|
290
|
+
port = TMail::StringPort.new(str = 'abc')
|
291
|
+
f = port.aopen
|
292
|
+
assert_equal false, f.closed?
|
293
|
+
f.print 'N'
|
294
|
+
f.close
|
295
|
+
assert_equal 'abcN', port.read_all
|
296
|
+
|
297
|
+
port.aopen {|ff|
|
298
|
+
assert_equal false, ff.closed?
|
299
|
+
ff.print 'F'
|
300
|
+
f = ff
|
301
|
+
}
|
302
|
+
assert_equal true, f.closed?
|
303
|
+
assert_equal 'abcNF', port.read_all
|
304
|
+
end
|
305
|
+
|
306
|
+
include FileUtils
|
307
|
+
|
308
|
+
def test_copy_to
|
309
|
+
src = TMail::StringPort.new('abc')
|
310
|
+
dest = TMail::StringPort.new
|
311
|
+
src.copy_to dest
|
312
|
+
assert_equal src.read_all, dest.read_all
|
313
|
+
assert_not_equal src.string.object_id, dest.string.object_id
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_move_to
|
317
|
+
src = TMail::StringPort.new(str = 'abc')
|
318
|
+
dest = TMail::StringPort.new
|
319
|
+
src.move_to dest
|
320
|
+
assert_same str, dest.string
|
321
|
+
assert_raises(Errno::ENOENT) {
|
322
|
+
src.ropen
|
323
|
+
}
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_remove
|
327
|
+
port = TMail::StringPort.new(str = 'abc')
|
328
|
+
port.remove
|
329
|
+
assert_raises(Errno::ENOENT) {
|
330
|
+
port.ropen
|
331
|
+
}
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
class MhPortTester < Test::Unit::TestCase
|
336
|
+
include FileUtils
|
337
|
+
|
338
|
+
def setup
|
339
|
+
rm_rf 'tmp'
|
340
|
+
mkdir 'tmp'
|
341
|
+
3.times do |n|
|
342
|
+
File.open( "tmp/#{n}", 'w' ) {|f|
|
343
|
+
f.puts 'From: Minero Aoki <aamine@loveruby.net>'
|
344
|
+
f.puts "Subject: test file #{n}"
|
345
|
+
f.puts
|
346
|
+
f.puts 'This is body.'
|
347
|
+
}
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
def teardown
|
352
|
+
rm_rf 'tmp'
|
353
|
+
end
|
354
|
+
|
355
|
+
def test_flags
|
356
|
+
port = TMail::MhPort.new('tmp/1')
|
357
|
+
assert_equal false, port.flagged?
|
358
|
+
port.flagged = true
|
359
|
+
assert_equal true, port.flagged?
|
360
|
+
|
361
|
+
assert_equal false, port.replied?
|
362
|
+
port.replied = true
|
363
|
+
assert_equal true, port.replied?
|
364
|
+
|
365
|
+
assert_equal false, port.seen?
|
366
|
+
port.seen = true
|
367
|
+
assert_equal true, port.seen?
|
368
|
+
|
369
|
+
port = TMail::MhPort.new('tmp/1')
|
370
|
+
assert_equal true, port.flagged?
|
371
|
+
assert_equal true, port.replied?
|
372
|
+
assert_equal true, port.seen?
|
373
|
+
|
374
|
+
port = TMail::MhPort.new('tmp/1')
|
375
|
+
port.flagged = false
|
376
|
+
port.replied = false
|
377
|
+
port.seen = false
|
378
|
+
|
379
|
+
port = TMail::MhPort.new('tmp/1')
|
380
|
+
assert_equal false, port.flagged?
|
381
|
+
assert_equal false, port.replied?
|
382
|
+
assert_equal false, port.seen?
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
class MaildirPortTester < Test::Unit::TestCase
|
387
|
+
include FileUtils
|
388
|
+
|
389
|
+
def setup
|
390
|
+
rm_rf 'tmp'
|
391
|
+
mkdir 'tmp'
|
392
|
+
3.times do |n|
|
393
|
+
File.open( "tmp/000.00#{n}.a", 'w' ) {|f|
|
394
|
+
f.puts 'From: Minero Aoki <aamine@loveruby.net>'
|
395
|
+
f.puts "Subject: test file #{n}"
|
396
|
+
f.puts
|
397
|
+
f.puts 'This is body.'
|
398
|
+
}
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
def teardown
|
403
|
+
rm_rf 'tmp'
|
404
|
+
end
|
405
|
+
|
406
|
+
def test_flags
|
407
|
+
port = TMail::MaildirPort.new('tmp/000.001.a')
|
408
|
+
|
409
|
+
assert_equal false, port.flagged?
|
410
|
+
port.flagged = true
|
411
|
+
assert_equal true, port.flagged?
|
412
|
+
|
413
|
+
assert_equal false, port.replied?
|
414
|
+
port.replied = true
|
415
|
+
assert_equal true, port.replied?
|
416
|
+
|
417
|
+
assert_equal false, port.seen?
|
418
|
+
port.seen = true
|
419
|
+
assert_equal true, port.seen?
|
420
|
+
|
421
|
+
port = TMail::MaildirPort.new(port.filename)
|
422
|
+
assert_equal true, port.flagged?
|
423
|
+
assert_equal true, port.replied?
|
424
|
+
assert_equal true, port.seen?
|
425
|
+
|
426
|
+
port = TMail::MaildirPort.new(port.filename)
|
427
|
+
port.flagged = false
|
428
|
+
port.replied = false
|
429
|
+
port.seen = false
|
430
|
+
|
431
|
+
port = TMail::MaildirPort.new(port.filename)
|
432
|
+
assert_equal false, port.flagged?
|
433
|
+
assert_equal false, port.replied?
|
434
|
+
assert_equal false, port.seen?
|
435
|
+
end
|
436
|
+
end
|