rims 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/ChangeLog +379 -0
  4. data/Gemfile +11 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +566 -0
  7. data/Rakefile +29 -0
  8. data/bin/rims +11 -0
  9. data/lib/rims.rb +45 -0
  10. data/lib/rims/auth.rb +133 -0
  11. data/lib/rims/cksum_kvs.rb +68 -0
  12. data/lib/rims/cmd.rb +809 -0
  13. data/lib/rims/daemon.rb +338 -0
  14. data/lib/rims/db.rb +793 -0
  15. data/lib/rims/error.rb +23 -0
  16. data/lib/rims/gdbm_kvs.rb +76 -0
  17. data/lib/rims/hash_kvs.rb +66 -0
  18. data/lib/rims/kvs.rb +101 -0
  19. data/lib/rims/lock.rb +151 -0
  20. data/lib/rims/mail_store.rb +663 -0
  21. data/lib/rims/passwd.rb +251 -0
  22. data/lib/rims/pool.rb +88 -0
  23. data/lib/rims/protocol.rb +71 -0
  24. data/lib/rims/protocol/decoder.rb +1469 -0
  25. data/lib/rims/protocol/parser.rb +1114 -0
  26. data/lib/rims/rfc822.rb +456 -0
  27. data/lib/rims/server.rb +567 -0
  28. data/lib/rims/test.rb +391 -0
  29. data/lib/rims/version.rb +11 -0
  30. data/load_test/Rakefile +93 -0
  31. data/rims.gemspec +38 -0
  32. data/test/test_auth.rb +174 -0
  33. data/test/test_cksum_kvs.rb +121 -0
  34. data/test/test_config.rb +533 -0
  35. data/test/test_daemon_status_file.rb +169 -0
  36. data/test/test_daemon_waitpid.rb +72 -0
  37. data/test/test_db.rb +602 -0
  38. data/test/test_db_recovery.rb +732 -0
  39. data/test/test_error.rb +97 -0
  40. data/test/test_gdbm_kvs.rb +32 -0
  41. data/test/test_hash_kvs.rb +116 -0
  42. data/test/test_lock.rb +161 -0
  43. data/test/test_mail_store.rb +750 -0
  44. data/test/test_passwd.rb +203 -0
  45. data/test/test_protocol.rb +91 -0
  46. data/test/test_protocol_auth.rb +121 -0
  47. data/test/test_protocol_decoder.rb +6490 -0
  48. data/test/test_protocol_fetch.rb +994 -0
  49. data/test/test_protocol_request.rb +332 -0
  50. data/test/test_protocol_search.rb +974 -0
  51. data/test/test_rfc822.rb +696 -0
  52. metadata +174 -0
@@ -0,0 +1,994 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'logger'
4
+ require 'rims'
5
+ require 'set'
6
+ require 'stringio'
7
+ require 'test/unit'
8
+ require 'time'
9
+
10
+ module RIMS::Test
11
+ class ProtocolFetchParserTest < Test::Unit::TestCase
12
+ include AssertUtility
13
+ include ProtocolFetchMailSample
14
+ include RIMS::Protocol::FetchParser::Utils
15
+
16
+ def setup
17
+ @kv_store = {}
18
+ @kvs_open = proc{|path| RIMS::Hash_KeyValueStore.new(@kv_store[path] = {}) }
19
+ @mail_store = RIMS::MailStore.new(RIMS::DB::Meta.new(@kvs_open.call('meta')),
20
+ RIMS::DB::Message.new(@kvs_open.call('msg'))) {|mbox_id|
21
+ RIMS::DB::Mailbox.new(@kvs_open.call("mbox_#{mbox_id}"))
22
+ }
23
+ @inbox_id = @mail_store.add_mbox('INBOX')
24
+ end
25
+
26
+ def expunge(*uid_list)
27
+ for uid in uid_list
28
+ @mail_store.set_msg_flag(@inbox_id, uid, 'deleted', true)
29
+ end
30
+ @mail_store.expunge_mbox(@inbox_id)
31
+ nil
32
+ end
33
+ private :expunge
34
+
35
+ def make_fetch_parser(read_only: false)
36
+ yield if block_given?
37
+ if (read_only) then
38
+ @folder = @mail_store.examine_mbox(@inbox_id).reload
39
+ else
40
+ @folder = @mail_store.select_mbox(@inbox_id).reload
41
+ end
42
+ @parser = RIMS::Protocol::FetchParser.new(@mail_store, @folder)
43
+ end
44
+ private :make_fetch_parser
45
+
46
+ def parse_fetch_attribute(fetch_att_str)
47
+ @fetch = @parser.parse(fetch_att_str)
48
+ begin
49
+ yield
50
+ ensure
51
+ @fetch = nil
52
+ end
53
+ end
54
+ private :parse_fetch_attribute
55
+
56
+ def assert_fetch(msg_idx, expected_message_data_array, encoding: 'ascii-8bit')
57
+ assert_strenc_equal(encoding,
58
+ message_data_list(expected_message_data_array),
59
+ @fetch.call(@folder[msg_idx]))
60
+ end
61
+ private :assert_fetch
62
+
63
+ def get_msg_flag(msg_idx, flag_name)
64
+ @mail_store.msg_flag(@inbox_id, @folder[msg_idx].uid, flag_name)
65
+ end
66
+ private :get_msg_flag
67
+
68
+ def set_msg_flag(msg_idx, flag_name, flag_value)
69
+ @mail_store.set_msg_flag(@inbox_id, @folder[msg_idx].uid, flag_name, flag_value)
70
+ nil
71
+ end
72
+ private :set_msg_flag
73
+
74
+ def add_mail_simple
75
+ make_mail_simple
76
+ @mail_store.add_msg(@inbox_id, @simple_mail.raw_source, Time.new(2013, 11, 8, 6, 47, 50, '+09:00'))
77
+ end
78
+ private :add_mail_simple
79
+
80
+ def add_mail_multipart
81
+ make_mail_multipart
82
+ @mail_store.add_msg(@inbox_id, @mpart_mail.raw_source, Time.new(2013, 11, 8, 19, 31, 03, '+09:00'))
83
+ end
84
+ private :add_mail_multipart
85
+
86
+ def add_mail_mime_subject
87
+ make_mail_mime_subject
88
+ @mail_store.add_msg(@inbox_id, @mime_subject_mail.raw_source, Time.new(2013, 11, 8, 19, 31, 03, '+09:00'))
89
+ end
90
+ private :add_mail_mime_subject
91
+
92
+ def add_mail_empty
93
+ make_mail_empty
94
+ @mail_store.add_msg(@inbox_id, @empty_mail.raw_source)
95
+ end
96
+ private :add_mail_empty
97
+
98
+ def add_mail_no_body
99
+ make_mail_no_body
100
+ @mail_store.add_msg(@inbox_id, @no_body_mail.raw_source)
101
+ end
102
+ private :add_mail_no_body
103
+
104
+ def add_mail_address_header_pattern
105
+ make_mail_address_header_pattern
106
+ @mail_store.add_msg(@inbox_id, @address_header_pattern_mail.raw_source)
107
+ end
108
+ private :add_mail_address_header_pattern
109
+
110
+ def test_parse_all
111
+ make_fetch_parser{
112
+ add_mail_simple
113
+ add_mail_multipart
114
+ }
115
+ parse_fetch_attribute('ALL') {
116
+ assert_fetch(0, [
117
+ 'FLAGS (\Recent)',
118
+ 'INTERNALDATE "08-Nov-2013 06:47:50 +0900"',
119
+ "RFC822.SIZE #{@simple_mail.raw_source.bytesize}",
120
+ 'ENVELOPE',
121
+ [ '"Fri, 8 Nov 2013 06:47:50 +0900 (JST)"', # Date
122
+ '"test"', # Subject
123
+ '((NIL NIL "bar" "nonet.org"))', # From
124
+ 'NIL', # Sender
125
+ 'NIL', # Reply-To
126
+ '((NIL NIL "foo" "nonet.org"))', # To
127
+ 'NIL', # Cc
128
+ 'NIL', # Bcc
129
+ 'NIL', # In-Reply-To
130
+ 'NIL' # Message-Id
131
+ ]
132
+ ])
133
+ assert_fetch(1, [
134
+ 'FLAGS (\Recent)',
135
+ 'INTERNALDATE "08-Nov-2013 19:31:03 +0900"',
136
+ "RFC822.SIZE #{@mpart_mail.raw_source.bytesize}",
137
+ 'ENVELOPE',
138
+ [ '"Fri, 8 Nov 2013 19:31:03 +0900"', # Date
139
+ '"multipart test"', # Subject
140
+ '((NIL NIL "foo" "nonet.com"))', # From
141
+ 'NIL', # Sender
142
+ 'NIL', # Reply-To
143
+ '((NIL NIL "bar" "nonet.com"))', # To
144
+ 'NIL', # Cc
145
+ 'NIL', # Bcc
146
+ 'NIL', # In-Reply-To
147
+ 'NIL' # Message-Id
148
+ ]
149
+ ])
150
+ }
151
+ end
152
+
153
+ def test_parse_body
154
+ make_fetch_parser{
155
+ add_mail_simple
156
+ add_mail_multipart
157
+ add_mail_empty
158
+ add_mail_no_body
159
+ }
160
+
161
+ 4.times do |i|
162
+ set_msg_flag(i, 'seen', true)
163
+ end
164
+
165
+ parse_fetch_attribute(make_body('BODY[]')) {
166
+ assert_fetch(0, [ "BODY[] #{literal(@simple_mail.raw_source)}" ])
167
+ assert_fetch(1, [ "BODY[] #{literal(@mpart_mail.raw_source)}" ])
168
+ assert_fetch(2, [ 'BODY[] ""' ])
169
+ assert_fetch(3, [ %Q'BODY[] "#{@no_body_mail.raw_source}"' ])
170
+ }
171
+
172
+ parse_fetch_attribute(make_body('BODY[TEXT]')) {
173
+ assert_fetch(0, [ "BODY[TEXT] #{literal(@simple_mail.body.raw_source)}" ])
174
+ assert_fetch(1, [ "BODY[TEXT] #{literal(@mpart_mail.body.raw_source)}" ])
175
+ assert_fetch(2, [ 'BODY[TEXT] ""' ])
176
+ assert_fetch(3, [ 'BODY[TEXT] ""' ])
177
+ }
178
+
179
+ parse_fetch_attribute(make_body('BODY[HEADER]')) {
180
+ assert_fetch(0, [ "BODY[HEADER] #{literal(@simple_mail.header.raw_source)}" ])
181
+ assert_fetch(1, [ "BODY[HEADER] #{literal(@mpart_mail.header.raw_source)}" ])
182
+ assert_fetch(2, [ 'BODY[HEADER] ""' ])
183
+ assert_fetch(3, [ %Q'BODY[HEADER] "#{@no_body_mail.header.raw_source}"' ])
184
+ }
185
+
186
+ parse_fetch_attribute(make_body('BODY[HEADER.FIELDS (From To)]')) {
187
+ assert_fetch(0, [
188
+ 'BODY[HEADER.FIELDS (From To)] ' +
189
+ literal(make_header_text(@simple_mail.header, select_list: %w[ From To ]))
190
+ ])
191
+ assert_fetch(1, [
192
+ 'BODY[HEADER.FIELDS (From To)] ' +
193
+ literal(make_header_text(@mpart_mail.header, select_list: %w[ From To ]))
194
+ ])
195
+ assert_fetch(2, [ 'BODY[HEADER.FIELDS (From To)] ' + literal("\r\n") ])
196
+ assert_fetch(3, [ 'BODY[HEADER.FIELDS (From To)] ' + literal("\r\n") ])
197
+ }
198
+
199
+ parse_fetch_attribute(make_body('BODY[HEADER.FIELDS.NOT (From To Subject)]')) {
200
+ assert_fetch(0, [
201
+ 'BODY[HEADER.FIELDS.NOT (From To Subject)] ' +
202
+ literal(make_header_text(@simple_mail.header, reject_list: %w[ From To Subject]))
203
+ ])
204
+ assert_fetch(1, [
205
+ 'BODY[HEADER.FIELDS.NOT (From To Subject)] ' +
206
+ literal(make_header_text(@mpart_mail.header, reject_list: %w[ From To Subject]))
207
+ ])
208
+ assert_fetch(2, [ 'BODY[HEADER.FIELDS.NOT (From To Subject)] ' + literal("\r\n") ])
209
+ assert_fetch(3, [ 'BODY[HEADER.FIELDS.NOT (From To Subject)] ' + literal("\r\n") ])
210
+ }
211
+
212
+ parse_fetch_attribute(make_body('BODY[1]')) {
213
+ assert_fetch(0, [ "BODY[1] #{literal(@simple_mail.body.raw_source)}" ])
214
+ assert_fetch(1, [ %Q'BODY[1] "#{@mpart_mail.parts[0].body.raw_source}"' ])
215
+ }
216
+
217
+ parse_fetch_attribute(make_body('BODY[3]')) {
218
+ assert_fetch(0, [ 'BODY[3] NIL' ])
219
+ assert_fetch(1, [ "BODY[3] #{literal(@mpart_mail.parts[2].body.raw_source)}" ])
220
+ }
221
+
222
+ parse_fetch_attribute(make_body('BODY[3.1]')) {
223
+ assert_fetch(0, [ 'BODY[3.1] NIL' ])
224
+ assert_fetch(1, [ %Q'BODY[3.1] "#{@mpart_mail.parts[2].message.parts[0].body.raw_source}"' ])
225
+ }
226
+
227
+ parse_fetch_attribute(make_body('BODY[4.2.2]')) {
228
+ assert_fetch(0, [ 'BODY[4.2.2] NIL' ])
229
+ assert_fetch(1, [ "BODY[4.2.2] #{literal(@mpart_mail.parts[3].parts[1].message.parts[1].body.raw_source)}" ])
230
+ }
231
+
232
+ assert_raise(RIMS::SyntaxError) {
233
+ @parser.parse(make_body('BODY[MIME]'))
234
+ }
235
+
236
+ parse_fetch_attribute(make_body('BODY[1.MIME]')) {
237
+ assert_fetch(0, [ "BODY[1.MIME] #{literal(@simple_mail.header.raw_source)}" ])
238
+ assert_fetch(1, [ "BODY[1.MIME] #{literal(@mpart_mail.parts[0].header.raw_source)}" ])
239
+ }
240
+
241
+ parse_fetch_attribute(make_body('BODY[3.MIME]')) {
242
+ assert_fetch(0, [ 'BODY[3.MIME] NIL' ])
243
+ assert_fetch(1, [ "BODY[3.MIME] #{literal(@mpart_mail.parts[2].header.raw_source)}" ])
244
+ }
245
+
246
+ parse_fetch_attribute(make_body('BODY[3.1.MIME]')) {
247
+ assert_fetch(0, [ 'BODY[3.1.MIME] NIL' ])
248
+ assert_fetch(1, [ "BODY[3.1.MIME] #{literal(@mpart_mail.parts[2].message.parts[0].header.raw_source)}" ])
249
+ }
250
+
251
+ parse_fetch_attribute(make_body('BODY[4.2.2.MIME]')) {
252
+ assert_fetch(0, [ 'BODY[4.2.2.MIME] NIL' ])
253
+ assert_fetch(1, [ "BODY[4.2.2.MIME] #{literal(@mpart_mail.parts[3].parts[1].message.parts[1].header.raw_source)}" ])
254
+ }
255
+
256
+ parse_fetch_attribute(make_body('BODY[1.TEXT]')) {
257
+ assert_fetch(0, [ 'BODY[1.TEXT] NIL' ])
258
+ assert_fetch(1, [ 'BODY[1.TEXT] NIL' ])
259
+ }
260
+
261
+ parse_fetch_attribute(make_body('BODY[3.TEXT]')) {
262
+ assert_fetch(0, [ 'BODY[3.TEXT] NIL' ])
263
+ assert_fetch(1, [ "BODY[3.TEXT] #{literal(@mpart_mail.parts[2].message.body.raw_source)}" ])
264
+ }
265
+
266
+ parse_fetch_attribute(make_body('BODY[3.1.TEXT]')) {
267
+ assert_fetch(0, [ 'BODY[3.1.TEXT] NIL' ])
268
+ assert_fetch(1, [ 'BODY[3.1.TEXT] NIL' ])
269
+ }
270
+
271
+ parse_fetch_attribute(make_body('BODY[4.2.TEXT]')) {
272
+ assert_fetch(0, [ 'BODY[4.2.TEXT] NIL' ])
273
+ assert_fetch(1, [ "BODY[4.2.TEXT] #{literal(@mpart_mail.parts[3].parts[1].message.body.raw_source)}" ])
274
+ }
275
+
276
+ parse_fetch_attribute(make_body('BODY[1.HEADER]')) {
277
+ assert_fetch(0, [ 'BODY[1.HEADER] NIL' ])
278
+ assert_fetch(1, [ 'BODY[1.HEADER] NIL' ])
279
+ }
280
+
281
+ parse_fetch_attribute(make_body('BODY[3.HEADER]')) {
282
+ assert_fetch(0, [ 'BODY[3.HEADER] NIL' ])
283
+ assert_fetch(1, [ "BODY[3.HEADER] #{literal(@mpart_mail.parts[2].message.header.raw_source)}" ])
284
+ }
285
+
286
+ parse_fetch_attribute(make_body('BODY[3.1.HEADER]')) {
287
+ assert_fetch(0, [ 'BODY[3.1.HEADER] NIL' ])
288
+ assert_fetch(1, [ 'BODY[3.1.HEADER] NIL' ])
289
+ }
290
+
291
+ parse_fetch_attribute(make_body('BODY[4.2.HEADER]')) {
292
+ assert_fetch(0, [ 'BODY[4.2.HEADER] NIL' ])
293
+ assert_fetch(1, [ "BODY[4.2.HEADER] #{literal(@mpart_mail.parts[3].parts[1].message.header.raw_source)}" ])
294
+ }
295
+
296
+ parse_fetch_attribute(make_body('BODY[1.HEADER.FIELDS (To)]')) {
297
+ assert_fetch(0, [ 'BODY[1.HEADER.FIELDS (To)] NIL' ])
298
+ assert_fetch(1, [ 'BODY[1.HEADER.FIELDS (To)] NIL' ])
299
+ }
300
+
301
+ parse_fetch_attribute(make_body('BODY[3.HEADER.FIELDS (To)]')) {
302
+ assert_fetch(0, [ 'BODY[3.HEADER.FIELDS (To)] NIL' ])
303
+ assert_fetch(1, [
304
+ 'BODY[3.HEADER.FIELDS (To)] ' +
305
+ literal(make_header_text(@mpart_mail.parts[2].message.header, select_list: %w[ To ]))
306
+ ])
307
+ }
308
+
309
+ parse_fetch_attribute(make_body('BODY[3.1.HEADER.FIELDS (To)]')) {
310
+ assert_fetch(0, [ 'BODY[3.1.HEADER.FIELDS (To)] NIL' ])
311
+ assert_fetch(1, [ 'BODY[3.1.HEADER.FIELDS (To)] NIL' ])
312
+ }
313
+
314
+ parse_fetch_attribute(make_body('BODY[4.2.HEADER.FIELDS (To)]')) {
315
+ assert_fetch(0, [ 'BODY[4.2.HEADER.FIELDS (To)] NIL' ])
316
+ assert_fetch(1, [
317
+ 'BODY[4.2.HEADER.FIELDS (To)] ' +
318
+ literal(make_header_text(@mpart_mail.parts[3].parts[1].message.header, select_list: %w[ To ]))
319
+ ])
320
+ }
321
+
322
+ parse_fetch_attribute(make_body('BODY[1.HEADER.FIELDS.NOT (To From Subject)]')) {
323
+ assert_fetch(0, [ 'BODY[1.HEADER.FIELDS.NOT (To From Subject)] NIL' ])
324
+ assert_fetch(1, [ 'BODY[1.HEADER.FIELDS.NOT (To From Subject)] NIL' ])
325
+ }
326
+
327
+ parse_fetch_attribute(make_body('BODY[3.HEADER.FIELDS.NOT (To From Subject)]')) {
328
+ assert_fetch(0, [ 'BODY[3.HEADER.FIELDS.NOT (To From Subject)] NIL' ])
329
+ assert_fetch(1, [
330
+ 'BODY[3.HEADER.FIELDS.NOT (To From Subject)] ' +
331
+ literal(make_header_text(@mpart_mail.parts[2].message.header, reject_list: %w[ To From Subject ]))
332
+ ])
333
+ }
334
+
335
+ parse_fetch_attribute(make_body('BODY[3.1.HEADER.FIELDS.NOT (To From Subject)]')) {
336
+ assert_fetch(0, [ 'BODY[3.1.HEADER.FIELDS.NOT (To From Subject)] NIL' ])
337
+ assert_fetch(1, [ 'BODY[3.1.HEADER.FIELDS.NOT (To From Subject)] NIL' ])
338
+ }
339
+
340
+ parse_fetch_attribute(make_body('BODY[4.2.HEADER.FIELDS.NOT (To From Subject)]')) {
341
+ assert_fetch(0, [ 'BODY[4.2.HEADER.FIELDS.NOT (To From Subject)] NIL' ])
342
+ assert_fetch(1, [
343
+ 'BODY[4.2.HEADER.FIELDS.NOT (To From Subject)] ' +
344
+ literal(make_header_text(@mpart_mail.parts[3].parts[1].message.header, reject_list: %w[ To From Subject ]))
345
+ ])
346
+ }
347
+ end
348
+
349
+ def test_parse_body_enabled_seen_flag
350
+ make_fetch_parser{
351
+ add_mail_simple
352
+ }
353
+
354
+ parse_fetch_attribute(make_body('BODY[]')) {
355
+ assert_equal(false, get_msg_flag(0, 'seen'))
356
+ assert_fetch(0, [
357
+ 'FLAGS (\Seen \Recent)',
358
+ "BODY[] #{literal(@simple_mail.raw_source)}"
359
+ ])
360
+ assert_equal(true, get_msg_flag(0, 'seen'))
361
+ assert_fetch(0, [
362
+ "BODY[] #{literal(@simple_mail.raw_source)}"
363
+ ])
364
+ assert_equal(true, get_msg_flag(0, 'seen'))
365
+ }
366
+ end
367
+
368
+ def test_parse_body_peek
369
+ make_fetch_parser{
370
+ add_mail_simple
371
+ }
372
+ parse_fetch_attribute(make_body('BODY.PEEK[]')) {
373
+ assert_fetch(0, [ "BODY[] #{literal(@simple_mail.raw_source)}" ])
374
+ }
375
+ end
376
+
377
+ def test_parse_body_read_only
378
+ make_fetch_parser(read_only: true) {
379
+ add_mail_simple
380
+ }
381
+ parse_fetch_attribute(make_body('BODY[]')) {
382
+ assert_equal(false, get_msg_flag(0, 'seen'))
383
+ assert_fetch(0, [ "BODY[] #{literal(@simple_mail.raw_source)}" ])
384
+ assert_equal(false, get_msg_flag(0, 'seen'))
385
+ }
386
+ end
387
+
388
+ def test_parse_body_partial
389
+ make_fetch_parser{
390
+ uid = add_mail_simple
391
+ @mail_store.set_msg_flag(@inbox_id, uid, 'seen', true)
392
+ }
393
+
394
+ msg_txt = @simple_mail.raw_source
395
+ assert(100 < msg_txt.bytesize && msg_txt.bytesize < 1000)
396
+ msg_last_char_idx = msg_txt.bytesize - 1
397
+
398
+ parse_fetch_attribute(make_body('BODY[]<0.100>')) {
399
+ assert_fetch(0, [ "BODY[]<0> #{literal(msg_txt.byteslice(0, 100))}" ])
400
+ }
401
+
402
+ parse_fetch_attribute(make_body('BODY[]<0.1000>')) {
403
+ assert_fetch(0, [ "BODY[]<0> #{literal(msg_txt)}" ])
404
+ }
405
+
406
+ parse_fetch_attribute(make_body("BODY[]<0.#{2**256}>")) { # `2**256' may be Bignum
407
+ assert_fetch(0, [ "BODY[]<0> #{literal(msg_txt)}" ])
408
+ }
409
+
410
+ parse_fetch_attribute(make_body('BODY[]<100.100>')) {
411
+ assert_fetch(0, [ "BODY[]<100> #{literal(msg_txt.byteslice(100, 100))}" ])
412
+ }
413
+
414
+ parse_fetch_attribute(make_body("BODY[]<#{msg_last_char_idx}.1>")) {
415
+ assert_fetch(0, [ "BODY[]<#{msg_last_char_idx}> #{literal(msg_txt[msg_last_char_idx, 1])}" ])
416
+ }
417
+
418
+ parse_fetch_attribute(make_body("BODY[]<#{msg_last_char_idx + 1}.1>")) {
419
+ assert_fetch(0, [ "BODY[]<#{msg_last_char_idx + 1}> NIL" ])
420
+ }
421
+
422
+ parse_fetch_attribute(make_body('BODY[]<0.0>')) {
423
+ assert_fetch(0, [ 'BODY[]<0> ""' ])
424
+ }
425
+
426
+ parse_fetch_attribute(make_body('BODY[]<100.0>')) {
427
+ assert_fetch(0, [ 'BODY[]<100> ""' ])
428
+ }
429
+
430
+ parse_fetch_attribute(make_body("BODY[]<#{msg_last_char_idx}.0>")) {
431
+ assert_fetch(0, [ %Q'BODY[]<#{msg_last_char_idx}> ""' ])
432
+ }
433
+
434
+ parse_fetch_attribute(make_body("BODY[]<#{msg_last_char_idx + 1}.0>")) {
435
+ assert_fetch(0, [ "BODY[]<#{msg_last_char_idx + 1}> NIL" ])
436
+ }
437
+ end
438
+
439
+ def test_parse_bodystructure
440
+ make_fetch_parser{
441
+ add_mail_simple
442
+ add_mail_multipart
443
+ add_mail_empty
444
+ add_mail_no_body
445
+ }
446
+
447
+ for fetch_att_bodystruct in %w[ BODY BODYSTRUCTURE ]
448
+ parse_fetch_attribute(fetch_att_bodystruct) {
449
+ assert_fetch(0, [
450
+ "#{fetch_att_bodystruct} " +
451
+ encode_list([ 'TEXT',
452
+ 'PLAIN',
453
+ %w[ charset us-ascii ],
454
+ nil,
455
+ nil,
456
+ '7BIT',
457
+ @simple_mail.raw_source.bytesize,
458
+ @simple_mail.raw_source.each_line.count
459
+ ])
460
+ ])
461
+ assert_fetch(1, [
462
+ "#{fetch_att_bodystruct} " +
463
+ encode_list([ [ 'TEXT', 'PLAIN', %w[ charset us-ascii], nil, nil, nil,
464
+ @mpart_mail.parts[0].raw_source.bytesize,
465
+ @mpart_mail.parts[0].raw_source.each_line.count
466
+ ],
467
+ [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
468
+ @mpart_mail.parts[1].raw_source.bytesize
469
+ ],
470
+ [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
471
+ @mpart_mail.parts[2].raw_source.bytesize,
472
+ [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
473
+ [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
474
+ ],
475
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
476
+ @mpart_mail.parts[2].message.parts[0].raw_source.bytesize,
477
+ @mpart_mail.parts[2].message.parts[0].raw_source.each_line.count
478
+ ],
479
+ [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
480
+ @mpart_mail.parts[2].message.parts[1].raw_source.bytesize
481
+ ],
482
+ 'MIXED'
483
+ ],
484
+ @mpart_mail.parts[2].raw_source.each_line.count
485
+ ],
486
+ [ [ 'IMAGE', 'GIF', [], nil, nil, nil,
487
+ @mpart_mail.parts[3].parts[0].raw_source.bytesize
488
+ ],
489
+ [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
490
+ @mpart_mail.parts[3].parts[1].raw_source.bytesize,
491
+ [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
492
+ [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
493
+ ],
494
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
495
+ @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.bytesize,
496
+ @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.each_line.count
497
+ ],
498
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
499
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.bytesize,
500
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.each_line.count
501
+ ],
502
+ [ 'TEXT', 'HTML', %w[ charset us-ascii ], nil, nil, nil,
503
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.bytesize,
504
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.each_line.count
505
+ ],
506
+ 'ALTERNATIVE'
507
+ ],
508
+ 'MIXED'
509
+ ],
510
+ @mpart_mail.parts[3].parts[1].raw_source.each_line.count
511
+ ],
512
+ 'MIXED',
513
+ ],
514
+ 'MIXED'
515
+ ])
516
+ ])
517
+ assert_fetch(2, [
518
+ "#{fetch_att_bodystruct} " +
519
+ encode_list([ 'APPLICATION',
520
+ 'OCTET-STREAM',
521
+ [],
522
+ nil,
523
+ nil,
524
+ nil,
525
+ @empty_mail.raw_source.bytesize
526
+ ])
527
+ ])
528
+ assert_fetch(3, [
529
+ "#{fetch_att_bodystruct} " +
530
+ encode_list([ 'APPLICATION',
531
+ 'OCTET-STREAM',
532
+ [],
533
+ nil,
534
+ nil,
535
+ nil,
536
+ @no_body_mail.raw_source.bytesize
537
+ ])
538
+ ])
539
+ }
540
+ end
541
+ end
542
+
543
+ def test_parse_envelope
544
+ make_fetch_parser{
545
+ add_mail_simple
546
+ add_mail_multipart
547
+ add_mail_mime_subject
548
+ add_mail_empty
549
+ add_mail_no_body
550
+ add_mail_address_header_pattern
551
+ }
552
+ parse_fetch_attribute('ENVELOPE') {
553
+ assert_fetch(0, [
554
+ 'ENVELOPE',
555
+ [ '"Fri, 8 Nov 2013 06:47:50 +0900 (JST)"', # Date
556
+ '"test"', # Subject
557
+ '((NIL NIL "bar" "nonet.org"))', # From
558
+ 'NIL', # Sender
559
+ 'NIL', # Reply-To
560
+ '((NIL NIL "foo" "nonet.org"))', # To
561
+ 'NIL', # Cc
562
+ 'NIL', # Bcc
563
+ 'NIL', # In-Reply-To
564
+ 'NIL' # Message-Id
565
+ ]
566
+ ])
567
+ assert_fetch(1, [
568
+ 'ENVELOPE',
569
+ [ '"Fri, 8 Nov 2013 19:31:03 +0900"', # Date
570
+ '"multipart test"', # Subject
571
+ '((NIL NIL "foo" "nonet.com"))', # From
572
+ 'NIL', # Sender
573
+ 'NIL', # Reply-To
574
+ '((NIL NIL "bar" "nonet.com"))', # To
575
+ 'NIL', # Cc
576
+ 'NIL', # Bcc
577
+ 'NIL', # In-Reply-To
578
+ 'NIL' # Message-Id
579
+ ]
580
+ ])
581
+ assert_fetch(2, [
582
+ 'ENVELOPE',
583
+ [ '"Fri, 8 Nov 2013 19:31:03 +0900"', # Date
584
+ '"=?ISO-2022-JP?B?GyRCJEYkOSRIGyhC?="', # Subject
585
+ '((NIL NIL "foo" "nonet.com") ("bar" NIL "bar" "nonet.com"))', # From
586
+ '((NIL NIL "foo" "nonet.com"))', # Sender
587
+ '((NIL NIL "foo" "nonet.com"))', # Reply-To
588
+ '((NIL NIL "alice" "test.com") ("bob" NIL "bob" "test.com"))', # To
589
+ '(("Kate" NIL "kate" "test.com"))', # Cc
590
+ '((NIL NIL "foo" "nonet.com"))', # Bcc
591
+ '"<20131106081723.5KJU1774292@smtp.testt.com>"',# In-Reply-To
592
+ '"<20131107214750.445A1255B9F@smtp.nonet.com>"' # Message-Id
593
+ ]
594
+ ])
595
+ assert_fetch(3, [ 'ENVELOPE (NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)' ])
596
+ assert_fetch(4, [ 'ENVELOPE (NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)' ])
597
+ assert_fetch(5, [
598
+ 'ENVELOPE',
599
+ [ '"Fri, 8 Nov 2013 06:47:50 +0900 (JST)"', # Date
600
+ '"test"', # Subject
601
+ '((NIL NIL "bar" "nonet.org"))', # From
602
+ 'NIL', # Sender
603
+ 'NIL', # Reply-To
604
+ '(("foo@nonet.org" NIL "foo" "nonet.org"))', # To
605
+ 'NIL', # Cc
606
+ 'NIL', # Bcc
607
+ 'NIL', # In-Reply-To
608
+ 'NIL' # Message-Id
609
+ ]
610
+ ])
611
+ }
612
+ end
613
+
614
+ def test_parse_fast
615
+ make_fetch_parser{
616
+ add_mail_simple
617
+ add_mail_multipart
618
+ }
619
+ parse_fetch_attribute('FAST') {
620
+ assert_fetch(0, [
621
+ 'FLAGS (\Recent)',
622
+ 'INTERNALDATE "08-Nov-2013 06:47:50 +0900"',
623
+ "RFC822.SIZE #{@simple_mail.raw_source.bytesize}"
624
+ ])
625
+ assert_fetch(1, [
626
+ 'FLAGS (\Recent)',
627
+ 'INTERNALDATE "08-Nov-2013 19:31:03 +0900"',
628
+ "RFC822.SIZE #{@mpart_mail.raw_source.bytesize}"
629
+ ])
630
+ }
631
+ end
632
+
633
+ def test_parse_flags
634
+ make_fetch_parser{
635
+ add_mail_simple
636
+ add_mail_simple
637
+ add_mail_simple
638
+ add_mail_simple
639
+ add_mail_simple
640
+ add_mail_simple
641
+ add_mail_simple
642
+ add_mail_simple
643
+ }
644
+
645
+ set_msg_flag(0, 'recent', false)
646
+
647
+ set_msg_flag(1, 'recent', true)
648
+
649
+ set_msg_flag(2, 'recent', false)
650
+ set_msg_flag(2, 'answered', true)
651
+
652
+ set_msg_flag(3, 'recent', false)
653
+ set_msg_flag(3, 'flagged', true)
654
+
655
+ set_msg_flag(4, 'recent', false)
656
+ set_msg_flag(4, 'deleted', true)
657
+
658
+ set_msg_flag(5, 'recent', false)
659
+ set_msg_flag(5, 'seen', true)
660
+
661
+ set_msg_flag(6, 'recent', false)
662
+ set_msg_flag(6, 'draft', true)
663
+
664
+ set_msg_flag(7, 'recent', true)
665
+ set_msg_flag(7, 'answered', true)
666
+ set_msg_flag(7, 'flagged', true)
667
+ set_msg_flag(7, 'deleted', true)
668
+ set_msg_flag(7, 'seen', true)
669
+ set_msg_flag(7, 'draft', true)
670
+
671
+ parse_fetch_attribute('FLAGS') {
672
+ assert_fetch(0, [ 'FLAGS ()' ])
673
+ assert_fetch(1, [ 'FLAGS (\Recent)' ])
674
+ assert_fetch(2, [ 'FLAGS (\Answered)' ])
675
+ assert_fetch(3, [ 'FLAGS (\Flagged)' ])
676
+ assert_fetch(4, [ 'FLAGS (\Deleted)' ])
677
+ assert_fetch(5, [ 'FLAGS (\Seen)' ])
678
+ assert_fetch(6, [ 'FLAGS (\Draft)' ])
679
+ assert_fetch(7, [
680
+ 'FLAGS',
681
+ RIMS::MailStore::MSG_FLAG_NAMES.map{|n| "\\#{n.capitalize}" }
682
+ ])
683
+ }
684
+ end
685
+
686
+ def test_parse_full
687
+ make_fetch_parser{
688
+ add_mail_simple
689
+ add_mail_multipart
690
+ }
691
+ parse_fetch_attribute('FULL') {
692
+ assert_fetch(0, [
693
+ 'FLAGS (\Recent)',
694
+ 'INTERNALDATE "08-Nov-2013 06:47:50 +0900"',
695
+ "RFC822.SIZE #{@simple_mail.raw_source.bytesize}",
696
+ 'ENVELOPE',
697
+ [ '"Fri, 8 Nov 2013 06:47:50 +0900 (JST)"', # Date
698
+ '"test"', # Subject
699
+ '((NIL NIL "bar" "nonet.org"))', # From
700
+ 'NIL', # Sender
701
+ 'NIL', # Reply-To
702
+ '((NIL NIL "foo" "nonet.org"))', # To
703
+ 'NIL', # Cc
704
+ 'NIL', # Bcc
705
+ 'NIL', # In-Reply-To
706
+ 'NIL' # Message-Id
707
+ ],
708
+ 'BODY',
709
+ encode_list([ 'TEXT',
710
+ 'PLAIN',
711
+ %w[ charset us-ascii ],
712
+ nil,
713
+ nil,
714
+ '7BIT',
715
+ @simple_mail.raw_source.bytesize,
716
+ @simple_mail.raw_source.each_line.count
717
+ ])
718
+ ])
719
+ assert_fetch(1, [
720
+ 'FLAGS (\Recent)',
721
+ 'INTERNALDATE "08-Nov-2013 19:31:03 +0900"',
722
+ "RFC822.SIZE #{@mpart_mail.raw_source.bytesize}",
723
+ 'ENVELOPE',
724
+ [ '"Fri, 8 Nov 2013 19:31:03 +0900"', # Date
725
+ '"multipart test"', # Subject
726
+ '((NIL NIL "foo" "nonet.com"))', # From
727
+ 'NIL', # Sender
728
+ 'NIL', # Reply-To
729
+ '((NIL NIL "bar" "nonet.com"))', # To
730
+ 'NIL', # Cc
731
+ 'NIL', # Bcc
732
+ 'NIL', # In-Reply-To
733
+ 'NIL' # Message-Id
734
+ ],
735
+ 'BODY',
736
+ encode_list([ [ 'TEXT', 'PLAIN', %w[ charset us-ascii], nil, nil, nil,
737
+ @mpart_mail.parts[0].raw_source.bytesize,
738
+ @mpart_mail.parts[0].raw_source.each_line.count
739
+ ],
740
+ [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
741
+ @mpart_mail.parts[1].raw_source.bytesize
742
+ ],
743
+ [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
744
+ @mpart_mail.parts[2].raw_source.bytesize,
745
+ [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
746
+ [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
747
+ ],
748
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
749
+ @mpart_mail.parts[2].message.parts[0].raw_source.bytesize,
750
+ @mpart_mail.parts[2].message.parts[0].raw_source.each_line.count
751
+ ],
752
+ [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
753
+ @mpart_mail.parts[2].message.parts[1].raw_source.bytesize
754
+ ],
755
+ 'MIXED'
756
+ ],
757
+ @mpart_mail.parts[2].raw_source.each_line.count
758
+ ],
759
+ [
760
+ [ 'IMAGE', 'GIF', [], nil, nil, nil,
761
+ @mpart_mail.parts[3].parts[0].raw_source.bytesize
762
+ ],
763
+ [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
764
+ @mpart_mail.parts[3].parts[1].raw_source.bytesize,
765
+ [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
766
+ [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
767
+ ],
768
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
769
+ @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.bytesize,
770
+ @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.each_line.count
771
+ ],
772
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
773
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.bytesize,
774
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.each_line.count
775
+ ],
776
+ [ 'TEXT', 'HTML', %w[ charset us-ascii ], nil, nil, nil,
777
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.bytesize,
778
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.each_line.count
779
+ ],
780
+ 'ALTERNATIVE'
781
+ ],
782
+ 'MIXED'
783
+ ],
784
+ @mpart_mail.parts[3].parts[1].raw_source.each_line.count
785
+ ],
786
+ 'MIXED',
787
+ ],
788
+ 'MIXED'
789
+ ])
790
+ ])
791
+ }
792
+ end
793
+
794
+ def test_parse_internaldate
795
+ make_fetch_parser{
796
+ add_mail_simple
797
+ add_mail_multipart
798
+ }
799
+ parse_fetch_attribute('INTERNALDATE') {
800
+ assert_fetch(0, [ 'INTERNALDATE "08-Nov-2013 06:47:50 +0900"' ])
801
+ assert_fetch(1, [ 'INTERNALDATE "08-Nov-2013 19:31:03 +0900"' ])
802
+ }
803
+ end
804
+
805
+ def test_parse_rfc822
806
+ make_fetch_parser{
807
+ add_mail_simple
808
+ }
809
+ parse_fetch_attribute('RFC822') {
810
+ assert_equal(false, get_msg_flag(0, 'seen'))
811
+ assert_fetch(0, [
812
+ 'FLAGS (\Seen \Recent)',
813
+ "RFC822 #{literal(@simple_mail.raw_source)}"
814
+ ])
815
+ assert_equal(true, get_msg_flag(0, 'seen'))
816
+ assert_fetch(0, [
817
+ "RFC822 #{literal(@simple_mail.raw_source)}"
818
+ ])
819
+ assert_equal(true, get_msg_flag(0, 'seen'))
820
+ }
821
+ end
822
+
823
+ def test_parse_rfc822_read_only
824
+ make_fetch_parser(read_only: true) {
825
+ add_mail_simple
826
+ }
827
+ parse_fetch_attribute('RFC822') {
828
+ assert_equal(false, get_msg_flag(0, 'seen'))
829
+ assert_fetch(0, [ "RFC822 #{literal(@simple_mail.raw_source)}" ])
830
+ assert_equal(false, get_msg_flag(0, 'seen'))
831
+ }
832
+ end
833
+
834
+ def test_parse_rfc822_header
835
+ make_fetch_parser{
836
+ add_mail_simple
837
+ }
838
+ parse_fetch_attribute('RFC822.HEADER') {
839
+ assert_equal(false, get_msg_flag(0, 'seen'))
840
+ assert_fetch(0, [ "RFC822.HEADER #{literal(@simple_mail.header.raw_source)}" ])
841
+ assert_equal(false, get_msg_flag(0, 'seen'))
842
+ }
843
+ end
844
+
845
+ def test_parse_rfc822_size
846
+ make_fetch_parser{
847
+ add_mail_simple
848
+ }
849
+ parse_fetch_attribute('RFC822.SIZE') {
850
+ assert_fetch(0, [ "RFC822.SIZE #{@simple_mail.raw_source.bytesize}" ])
851
+ }
852
+ end
853
+
854
+ def test_parse_rfc822_text
855
+ make_fetch_parser{
856
+ add_mail_simple
857
+ }
858
+ parse_fetch_attribute('RFC822.TEXT') {
859
+ assert_equal(false, get_msg_flag(0, 'seen'))
860
+ assert_fetch(0, [
861
+ 'FLAGS (\Seen \Recent)',
862
+ "RFC822.TEXT #{literal(@simple_mail.body.raw_source)}"
863
+ ])
864
+ assert_equal(true, get_msg_flag(0, 'seen'))
865
+ assert_fetch(0, [
866
+ "RFC822.TEXT #{literal(@simple_mail.body.raw_source)}"
867
+ ])
868
+ assert_equal(true, get_msg_flag(0, 'seen'))
869
+ }
870
+ end
871
+
872
+ def test_parse_rfc822_text_read_only
873
+ make_fetch_parser(read_only: true) {
874
+ add_mail_simple
875
+ }
876
+ parse_fetch_attribute('RFC822.TEXT') {
877
+ assert_equal(false, get_msg_flag(0, 'seen'))
878
+ assert_fetch(0, [ "RFC822.TEXT #{literal(@simple_mail.body.raw_source)}" ])
879
+ assert_equal(false, get_msg_flag(0, 'seen'))
880
+ }
881
+ end
882
+
883
+ def test_parse_uid
884
+ make_fetch_parser{
885
+ add_mail_simple
886
+ add_mail_simple
887
+ add_mail_multipart
888
+ expunge(2)
889
+ assert_equal([ 1, 3 ], @mail_store.each_msg_uid(@inbox_id).to_a)
890
+ }
891
+ parse_fetch_attribute('UID') {
892
+ assert_fetch(0, [ 'UID 1' ])
893
+ assert_fetch(1, [ 'UID 3' ])
894
+ }
895
+ end
896
+
897
+ def test_parse_group
898
+ make_fetch_parser{
899
+ add_mail_simple
900
+ add_mail_multipart
901
+ }
902
+ parse_fetch_attribute([ :group ]) {
903
+ assert_fetch(0, [ '()' ])
904
+ assert_fetch(1, [ '()' ])
905
+ }
906
+ parse_fetch_attribute([ :group, 'RFC822.SIZE' ]) {
907
+ assert_fetch(0, [ "(RFC822.SIZE #{@simple_mail.raw_source.bytesize})" ])
908
+ assert_fetch(1, [ "(RFC822.SIZE #{@mpart_mail.raw_source.bytesize})" ])
909
+ }
910
+ end
911
+ end
912
+
913
+ class ProtocolFetchParserUtilsTest < Test::Unit::TestCase
914
+ include ProtocolFetchMailSample
915
+
916
+ def test_encode_header
917
+ assert_equal("To: foo@nonet.org\r\n" +
918
+ "From: bar@nonet.org\r\n" +
919
+ "\r\n",
920
+ RIMS::Protocol::FetchParser::Utils.encode_header([ %w[ To foo@nonet.org ],
921
+ %w[ From bar@nonet.org ]
922
+ ]))
923
+ end
924
+
925
+ def test_get_body_section
926
+ make_mail_simple
927
+ make_mail_multipart
928
+
929
+ assert_equal(@simple_mail,
930
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@simple_mail, []))
931
+ assert_equal(@simple_mail,
932
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@simple_mail, [ 1 ]))
933
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_section(@simple_mail, [ 1, 1 ]))
934
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_section(@simple_mail, [ 2 ]))
935
+
936
+ assert_equal(@mpart_mail.raw_source,
937
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, []).raw_source)
938
+ assert_equal(@mpart_mail.parts[0].raw_source,
939
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 1 ]).raw_source)
940
+ assert_equal(@mpart_mail.parts[1].raw_source,
941
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 2 ]).raw_source)
942
+ assert_equal(@mpart_mail.parts[2].raw_source,
943
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 3 ]).raw_source)
944
+ assert_equal(@mpart_mail.parts[2].message.parts[0].raw_source,
945
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 3, 1 ]).raw_source)
946
+ assert_equal(@mpart_mail.parts[2].message.parts[1].raw_source,
947
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 3, 2 ]).raw_source)
948
+ assert_equal(@mpart_mail.parts[3].raw_source,
949
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4 ]).raw_source)
950
+ assert_equal(@mpart_mail.parts[3].parts[0].raw_source,
951
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 1 ]).raw_source)
952
+ assert_equal(@mpart_mail.parts[3].parts[1].raw_source,
953
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 2 ]).raw_source)
954
+ assert_equal(@mpart_mail.parts[3].parts[1].message.parts[0].raw_source,
955
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 2, 1 ]).raw_source)
956
+ assert_equal(@mpart_mail.parts[3].parts[1].message.parts[1].raw_source,
957
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 2, 2 ]).raw_source)
958
+ assert_equal(@mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source,
959
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 2, 2, 1 ]).raw_source)
960
+ assert_equal(@mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source,
961
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 2, 2, 2 ]).raw_source)
962
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 5 ]))
963
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 3, 3 ]))
964
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 3 ]))
965
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 2, 3 ]))
966
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 2, 2, 3 ]))
967
+
968
+ assert_raise(RIMS::SyntaxError) {
969
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@simple_mail, [ 0 ])
970
+ }
971
+ assert_raise(RIMS::SyntaxError) {
972
+ RIMS::Protocol::FetchParser::Utils.get_body_section(@mpart_mail, [ 4, 2, 2, 0 ])
973
+ }
974
+ end
975
+
976
+ def test_get_body_content
977
+ make_mail_simple
978
+ make_mail_multipart
979
+
980
+ assert_equal('test', RIMS::Protocol::FetchParser::Utils.get_body_content(@simple_mail, :header)['Subject'])
981
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_content(@simple_mail, :header, nest_mail: true))
982
+
983
+ assert_equal('multipart test', RIMS::Protocol::FetchParser::Utils.get_body_content(@mpart_mail, :header)['Subject'])
984
+ assert_nil(RIMS::Protocol::FetchParser::Utils.get_body_content(@mpart_mail, :header, nest_mail: true))
985
+
986
+ assert_equal('inner multipart', RIMS::Protocol::FetchParser::Utils.get_body_content(@mpart_mail.parts[2], :header, nest_mail: true)['Subject'])
987
+ end
988
+ end
989
+ end
990
+
991
+ # Local Variables:
992
+ # mode: Ruby
993
+ # indent-tabs-mode: nil
994
+ # End: