rmail 0.17 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/NEWS +10 -0
  2. data/Rakefile +186 -0
  3. data/TODO +3 -0
  4. data/lib/rmail/header.rb +3 -9
  5. data/{tests → test}/addrgrammar.txt +0 -0
  6. data/{tests → test}/data/mbox.odd +0 -0
  7. data/{tests → test}/data/mbox.simple +0 -0
  8. data/{tests → test}/data/multipart/data.1 +0 -0
  9. data/{tests → test}/data/multipart/data.10 +0 -0
  10. data/{tests → test}/data/multipart/data.11 +0 -0
  11. data/{tests → test}/data/multipart/data.12 +0 -0
  12. data/{tests → test}/data/multipart/data.13 +0 -0
  13. data/{tests → test}/data/multipart/data.14 +0 -0
  14. data/{tests → test}/data/multipart/data.15 +0 -0
  15. data/{tests → test}/data/multipart/data.16 +0 -0
  16. data/{tests → test}/data/multipart/data.17 +0 -0
  17. data/{tests → test}/data/multipart/data.2 +0 -0
  18. data/{tests → test}/data/multipart/data.3 +0 -0
  19. data/{tests → test}/data/multipart/data.4 +0 -0
  20. data/{tests → test}/data/multipart/data.5 +0 -0
  21. data/{tests → test}/data/multipart/data.6 +0 -0
  22. data/{tests → test}/data/multipart/data.7 +0 -0
  23. data/{tests → test}/data/multipart/data.8 +0 -0
  24. data/{tests → test}/data/multipart/data.9 +0 -0
  25. data/{tests → test}/data/parser.badmime1 +0 -0
  26. data/{tests → test}/data/parser.badmime2 +0 -0
  27. data/{tests → test}/data/parser.nested-multipart +0 -0
  28. data/{tests → test}/data/parser.nested-simple +0 -0
  29. data/{tests → test}/data/parser.nested-simple2 +0 -0
  30. data/{tests → test}/data/parser.nested-simple3 +0 -0
  31. data/{tests → test}/data/parser.rfc822 +0 -0
  32. data/{tests → test}/data/parser.simple-mime +0 -0
  33. data/{tests → test}/data/parser/multipart.1 +0 -0
  34. data/{tests → test}/data/parser/multipart.10 +0 -0
  35. data/{tests → test}/data/parser/multipart.11 +0 -0
  36. data/{tests → test}/data/parser/multipart.12 +0 -0
  37. data/{tests → test}/data/parser/multipart.13 +0 -0
  38. data/{tests → test}/data/parser/multipart.14 +0 -0
  39. data/{tests → test}/data/parser/multipart.15 +0 -0
  40. data/{tests → test}/data/parser/multipart.16 +0 -0
  41. data/{tests → test}/data/parser/multipart.2 +0 -0
  42. data/{tests → test}/data/parser/multipart.3 +0 -0
  43. data/{tests → test}/data/parser/multipart.4 +0 -0
  44. data/{tests → test}/data/parser/multipart.5 +0 -0
  45. data/{tests → test}/data/parser/multipart.6 +0 -0
  46. data/{tests → test}/data/parser/multipart.7 +0 -0
  47. data/{tests → test}/data/parser/multipart.8 +0 -0
  48. data/{tests → test}/data/parser/multipart.9 +0 -0
  49. data/{tests → test}/data/transparency/absolute.1 +0 -0
  50. data/{tests → test}/data/transparency/absolute.2 +0 -0
  51. data/{tests → test}/data/transparency/absolute.3 +0 -0
  52. data/{tests → test}/data/transparency/absolute.4 +0 -0
  53. data/{tests → test}/data/transparency/absolute.5 +0 -0
  54. data/{tests → test}/data/transparency/absolute.6 +0 -0
  55. data/{tests → test}/data/transparency/message.1 +0 -0
  56. data/{tests → test}/data/transparency/message.2 +0 -0
  57. data/{tests → test}/data/transparency/message.3 +0 -0
  58. data/{tests → test}/data/transparency/message.4 +0 -0
  59. data/{tests → test}/data/transparency/message.5 +0 -0
  60. data/{tests → test}/data/transparency/message.6 +0 -0
  61. data/{tests → test}/runtests.rb +1 -1
  62. data/{tests → test}/testaddress.rb +9 -9
  63. data/{tests → test}/testbase.rb +9 -12
  64. data/{tests → test}/testheader.rb +70 -52
  65. data/{tests → test}/testmailbox.rb +1 -1
  66. data/{tests → test}/testmboxreader.rb +1 -1
  67. data/{tests → test}/testmessage.rb +3 -3
  68. data/{tests → test}/testparser.rb +3 -3
  69. data/{tests → test}/testparsermultipart.rb +1 -1
  70. data/{tests → test}/testpushbackreader.rb +2 -2
  71. data/{tests → test}/testserialize.rb +1 -1
  72. data/{tests → test}/testtestbase.rb +8 -4
  73. data/{tests → test}/testtranspparency.rb +3 -3
  74. data/version +1 -0
  75. metadata +153 -135
  76. data/rmail.gemspec +0 -17
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #--
3
- # Copyright (C) 2001, 2002, 2003, 2004 Matt Armstrong. All rights reserved.
3
+ # Copyright (C) 2001, 2002, 2003, 2004, 2007 Matt Armstrong. All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions are met:
@@ -25,7 +25,7 @@
25
25
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  #
27
27
 
28
- require 'tests/testbase'
28
+ require 'test/testbase'
29
29
  require 'rmail/header'
30
30
 
31
31
  class TestRMailHeader < TestBase
@@ -84,7 +84,7 @@ class TestRMailHeader < TestBase
84
84
  # Test that passing in symbols will not get converted into strings
85
85
  # strings
86
86
  h = RMail::Header.new
87
- assert_exception(NO_METHOD_ERROR) {
87
+ assert_raise(NoMethodError) {
88
88
  h[:Kelly] = :the_value
89
89
  }
90
90
 
@@ -140,6 +140,13 @@ class TestRMailHeader < TestBase
140
140
  assert(! (h1 == Array.new))
141
141
  end
142
142
 
143
+ def test_address_list_fetch
144
+ h = RMail::Header.new
145
+ assert_equal([], h.address_list_fetch("From"))
146
+ h.add("From", "bob@example.com")
147
+ assert_equal(["bob@example.com"], h.address_list_fetch("From"))
148
+ end
149
+
143
150
  def test_add
144
151
  #
145
152
  # Test that the object stores the exact objects we pass it in (at
@@ -173,7 +180,7 @@ class TestRMailHeader < TestBase
173
180
 
174
181
  # Test that passing in symbol values raises an exception
175
182
  h = RMail::Header.new
176
- assert_exception(NO_METHOD_ERROR) {
183
+ assert_raise(NoMethodError) {
177
184
  assert_same(h, h.add("bob", :the_value))
178
185
  }
179
186
 
@@ -277,7 +284,7 @@ class TestRMailHeader < TestBase
277
284
  # Make sure singleton methods are not carried over through a dup
278
285
  def h1.my_singleton_method
279
286
  end
280
- assert_respond_to(:my_singleton_method, h1)
287
+ assert_respond_to(h1, :my_singleton_method)
281
288
  h2 = h1.dup
282
289
  assert(! h2.respond_to?(:my_singleton_method))
283
290
  end
@@ -315,10 +322,10 @@ class TestRMailHeader < TestBase
315
322
  h1 = RMail::Header.new
316
323
  def h1.my_singleton_method
317
324
  end
318
- assert_respond_to(:my_singleton_method, h1)
325
+ assert_respond_to(h1, :my_singleton_method)
319
326
  h2 = h1.clone
320
327
  assert(!h1.equal?(h2))
321
- assert_respond_to(:my_singleton_method, h2)
328
+ assert_respond_to(h2, :my_singleton_method)
322
329
  end
323
330
 
324
331
  def test_replace
@@ -337,7 +344,7 @@ class TestRMailHeader < TestBase
337
344
  assert_same(h1['To'], h2['To'])
338
345
  assert_same(h1.mbox_from, h2.mbox_from)
339
346
 
340
- e = assert_exception(TypeError) {
347
+ e = assert_raise(TypeError) {
341
348
  h2.replace("hi mom")
342
349
  }
343
350
  assert_equal('String is not of type RMail::Header', e.message)
@@ -357,15 +364,15 @@ class TestRMailHeader < TestBase
357
364
  def test_delete_at
358
365
  h = RMail::Header.new
359
366
  h['Foo'] = 'bar'
360
- h['Bazo'] = 'bingo'
367
+ h['Baz'] = 'bingo'
361
368
  h['Foo'] = 'yo'
362
369
  assert_same(h, h.delete_at(1))
363
- assert_nil(h['Bazo'])
370
+ assert_equal(2, h.length)
371
+ assert_nil(h['Baz'])
364
372
  assert_equal('bar', h[0])
365
373
  assert_equal('yo', h[1])
366
- assert_equal(2, h.length)
367
374
 
368
- assert_exception(TypeError) {
375
+ assert_raise(TypeError) {
369
376
  h.delete_at("1")
370
377
  }
371
378
  end
@@ -373,14 +380,14 @@ class TestRMailHeader < TestBase
373
380
  def test_delete_if
374
381
  h = RMail::Header.new
375
382
  h['Foo'] = 'bar'
376
- h['Bazo'] = 'bingo'
383
+ h['Baz'] = 'bingo'
377
384
  h['Foo'] = 'yo'
378
385
  assert_same(h, h.delete_if { |n, v| v =~ /^b/ })
379
- assert_nil(h['Bazo'])
386
+ assert_nil(h['Baz'])
380
387
  assert_equal('yo', h['Foo'])
381
388
  assert_equal(1, h.length)
382
389
 
383
- assert_exception(LocalJumpError) {
390
+ assert_raise(LocalJumpError) {
384
391
  h.delete_if
385
392
  }
386
393
  end
@@ -397,7 +404,7 @@ class TestRMailHeader < TestBase
397
404
  i += 1
398
405
  }
399
406
 
400
- assert_exception(LocalJumpError) {
407
+ assert_raise(LocalJumpError) {
401
408
  h.send(method)
402
409
  }
403
410
  end
@@ -421,7 +428,7 @@ class TestRMailHeader < TestBase
421
428
  i += 1
422
429
  }
423
430
 
424
- assert_exception(LocalJumpError) {
431
+ assert_raise(LocalJumpError) {
425
432
  h.send(method)
426
433
  }
427
434
  end
@@ -445,7 +452,7 @@ class TestRMailHeader < TestBase
445
452
  i += 1
446
453
  }
447
454
 
448
- assert_exception(LocalJumpError) {
455
+ assert_raise(LocalJumpError) {
449
456
  h.each_value
450
457
  }
451
458
  end
@@ -466,7 +473,7 @@ class TestRMailHeader < TestBase
466
473
  assert_equal(1, h.fetch('notthere', 1))
467
474
  assert_equal(2, h.fetch('notthere', 1) { 2 })
468
475
 
469
- e = assert_exception(ArgumentError) {
476
+ e = assert_raise(ArgumentError) {
470
477
  h.fetch(1,2,3)
471
478
  }
472
479
  assert_equal('wrong # of arguments(3 for 2)', e.message)
@@ -482,7 +489,7 @@ class TestRMailHeader < TestBase
482
489
  assert_equal(1, h.fetch('notthere', 1))
483
490
  assert_equal(2, h.fetch('notthere', 1) { 2 })
484
491
 
485
- e = assert_exception(ArgumentError) {
492
+ e = assert_raise(ArgumentError) {
486
493
  h.fetch_all(1,2,3)
487
494
  }
488
495
  assert_equal('wrong # of arguments(3 for 2)', e.message)
@@ -515,12 +522,18 @@ class TestRMailHeader < TestBase
515
522
  field_helper(:key?)
516
523
  end
517
524
 
525
+ def test_select_on_empty_header_returns_empty_array
526
+ h = RMail::Header.new
527
+ assert_equal([], h.select("From"))
528
+ end
529
+
518
530
  def test_select
519
531
  h = RMail::Header.new
520
532
  h['To'] = 'matt@example.net'
521
533
  h['From'] = 'bob@example.net'
522
534
  h['Subject'] = 'test_select'
523
-
535
+ assert_equal([ [ 'To', 'matt@example.net' ] ],
536
+ h.select('To'))
524
537
  assert_equal([ [ 'To', 'matt@example.net' ],
525
538
  [ 'From', 'bob@example.net' ] ],
526
539
  h.select('To', 'From'))
@@ -620,33 +633,38 @@ EOF
620
633
  # Compare header contents against an expected result. 'result'
621
634
  # should be an array of arrays, with the first element being the
622
635
  # required key name and the second element being the whole line.
623
- def compare_header(header, result)
624
- index = -1
636
+ def compare_header(header, expected)
637
+ testcase_desc = "TestCase header: #{header.inspect} " +
638
+ "expected result: #{expected.inspect}"
639
+ count = 0
625
640
  header.each_with_index { |value, index|
626
- assert_operator(index, '<', result.length,
627
- "result has too few elements")
628
- assert_operator(2, '<=', result[index].length,
629
- "Expected result item must have at last two elements.")
630
- assert_operator(3, '>=', result[index].length,
641
+ count = count.succ
642
+ assert_operator(index, '<', expected.length,
643
+ "result has too few elements. #{testcase_desc}")
644
+ assert_operator(2, '<=', expected[index].length,
645
+ "Expected result item must have at last two elements. " +
646
+ testcase_desc)
647
+ assert_operator(3, '>=', expected[index].length,
631
648
  "Expected result item must have no more than three " +
632
- "elements.")
633
- assert_equal(2, value.length)
649
+ "elements. " + testcase_desc)
650
+ assert_equal(2, value.length, testcase_desc)
634
651
 
635
- expected_tag, expected_header = result[index]
652
+ expected_tag, expected_header = expected[index]
636
653
  got_tag, got_header = value
637
654
 
638
- assert_equal(header[index], got_header)
655
+ assert_equal(header[index], got_header, testcase_desc)
639
656
 
640
657
  assert_equal(expected_tag, got_tag,
641
- "field #{index} has incorrect name")
658
+ "field #{index} has incorrect name. " + testcase_desc)
642
659
  assert_equal(expected_header, got_header,
643
660
  "field #{index} has incorrect line, " +
644
661
  "expected #{expected_header.inspect} got " +
645
- "#{got_header.inspect}")
646
- assert_equal(header[expected_tag], expected_header)
662
+ "#{got_header.inspect}. " + testcase_desc)
663
+ assert_equal(header[expected_tag], expected_header, testcase_desc)
647
664
  }
648
- assert_equal(index + 1, result.length,
649
- "result has too few elements (#{index} < #{result.length})")
665
+ assert_equal(count, expected.length,
666
+ "result has too few elements " +
667
+ "(#{count} < #{expected.length}). " + testcase_desc)
650
668
  end
651
669
 
652
670
  def verify_match(header, name, value, expected_result)
@@ -668,24 +686,24 @@ EOF
668
686
  h['Subject'] = 'yoda lives!'
669
687
 
670
688
  # First verify argument type checking
671
- e = assert_exception(ArgumentError) {
689
+ e = assert_raise(ArgumentError) {
672
690
  h.match(12, "foo")
673
691
  }
674
692
  assert_match(/name not a Regexp or String/, e.message)
675
- assert_no_exception {
693
+ assert_nothing_raised {
676
694
  h.match(/not_case_insensitive/, "foo")
677
695
  }
678
- e = assert_exception(ArgumentError) {
696
+ e = assert_raise(ArgumentError) {
679
697
  h.match(/this is okay/i, 12)
680
698
  }
681
699
  assert_match(/value not a Regexp or String/, e.message)
682
- assert_no_exception {
700
+ assert_nothing_raised {
683
701
  h.match(/this is okay/i, /this_not_multiline_or_insensitive/)
684
702
  }
685
- assert_no_exception {
703
+ assert_nothing_raised {
686
704
  h.match(/this is okay/i, /this_not_multiline/i)
687
705
  }
688
- assert_no_exception {
706
+ assert_nothing_raised {
689
707
  h.match(/this is okay/i, /this_not_inesnsitive/m)
690
708
  }
691
709
 
@@ -716,24 +734,24 @@ EOF
716
734
  h['Subject'] = "yoda\n lives! [bob]\\s"
717
735
 
718
736
  # First verify argument type checking
719
- e = assert_exception(ArgumentError) {
737
+ e = assert_raise(ArgumentError) {
720
738
  h.match?(12, "foo")
721
739
  }
722
740
  assert_match(/name not a Regexp or String/, e.message)
723
- assert_no_exception {
741
+ assert_nothing_raised {
724
742
  h.match?(/not_case_insensitive/, "foo")
725
743
  }
726
- e = assert_exception(ArgumentError) {
744
+ e = assert_raise(ArgumentError) {
727
745
  h.match?(/this is okay/i, 12)
728
746
  }
729
747
  assert_match(/value not a Regexp or String/, e.message)
730
- assert_no_exception {
748
+ assert_nothing_raised {
731
749
  h.match?(/this is okay/i, /this_not_multiline_or_insensitive/)
732
750
  }
733
- assert_no_exception {
751
+ assert_nothing_raised {
734
752
  h.match?(/this is okay/i, /this_not_multiline/i)
735
753
  }
736
- assert_no_exception {
754
+ assert_nothing_raised {
737
755
  h.match?(/this is okay/i, /this_not_inesnsitive/m)
738
756
  }
739
757
 
@@ -913,7 +931,7 @@ EOF
913
931
  end
914
932
  }.to_s ]
915
933
  strings.each {|string|
916
- assert_no_exception("failed for string #{string.inspect}") {
934
+ assert_nothing_raised("failed for string #{string.inspect}") {
917
935
  h = RMail::Header.new
918
936
  h['header'] = string
919
937
  params = h.params('header')
@@ -999,7 +1017,7 @@ EOF
999
1017
  h = RMail::Header.new
1000
1018
  # This one is bogus and can't even be parsed.
1001
1019
  h.add_raw("Date: 21/01/2002 09:29:33 Pacific Daylight Time")
1002
- t = assert_no_exception {
1020
+ t = assert_nothing_raised {
1003
1021
  h.date
1004
1022
  }
1005
1023
  assert_nil(t)
@@ -1010,7 +1028,7 @@ EOF
1010
1028
  # This time is out of the range that can be represented by a
1011
1029
  # Time object.
1012
1030
  h.add_raw("Date: Sun, 14 Jun 2065 05:51:55 +0200")
1013
- t = assert_no_exception {
1031
+ t = assert_nothing_raised {
1014
1032
  h.date
1015
1033
  }
1016
1034
  assert_nil(t)
@@ -25,7 +25,7 @@
25
25
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  #
27
27
 
28
- require 'tests/testbase'
28
+ require 'test/testbase'
29
29
  require 'rmail/mailbox'
30
30
 
31
31
  class TestRMailMailbox < TestBase
@@ -25,7 +25,7 @@
25
25
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  #
27
27
 
28
- require 'tests/testbase'
28
+ require 'test/testbase'
29
29
  require 'rmail/mailbox/mboxreader'
30
30
 
31
31
  class TextRMailMBoxReader < TestBase
@@ -26,7 +26,7 @@
26
26
  #
27
27
 
28
28
  require 'rmail/message'
29
- require 'tests/testbase'
29
+ require 'test/testbase'
30
30
 
31
31
  class TestRMailMessage < TestBase
32
32
 
@@ -162,7 +162,7 @@ Second body line
162
162
  qp_message.body = qp_data
163
163
  message.add_part(qp_message)
164
164
 
165
- e = assert_exception(TypeError) {
165
+ e = assert_raise(TypeError) {
166
166
  message.decode
167
167
  }
168
168
  assert_equal('Can not decode a multipart message.', e.message)
@@ -180,7 +180,7 @@ Second body line
180
180
  def test_part
181
181
  message = RMail::Message.new
182
182
 
183
- e = assert_exception(TypeError) {
183
+ e = assert_raise(TypeError) {
184
184
  message.part(0)
185
185
  }
186
186
  assert_equal('Can not get part on a single part message.', e.message)
@@ -25,7 +25,7 @@
25
25
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  #
27
27
 
28
- require 'tests/testbase'
28
+ require 'test/testbase'
29
29
  require 'rmail/parser'
30
30
 
31
31
  class TestRMailStreamParser < TestBase
@@ -333,7 +333,7 @@ It DOES end with a linebreak.
333
333
  m = nil
334
334
  data_as_file('parser.badmime1') do |f|
335
335
  p.chunk_size = size
336
- assert_no_exception("failed for chunk size #{size.to_s}") {
336
+ assert_nothing_raised("failed for chunk size #{size.to_s}") {
337
337
  m = p.parse(f)
338
338
  }
339
339
  end
@@ -347,7 +347,7 @@ It DOES end with a linebreak.
347
347
  m = nil
348
348
  data_as_file('parser.badmime2') do |f|
349
349
  p.chunk_size = size
350
- assert_no_exception("failed for chunk size #{size.to_s}") {
350
+ assert_nothing_raised("failed for chunk size #{size.to_s}") {
351
351
  m = p.parse(f)
352
352
  }
353
353
  end
@@ -25,7 +25,7 @@
25
25
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  #
27
27
 
28
- require 'tests/testbase'
28
+ require 'test/testbase'
29
29
  require 'rmail/parser/multipart'
30
30
 
31
31
  class TestRMailParserMultipart < TestBase
@@ -25,14 +25,14 @@
25
25
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  #
27
27
 
28
- require 'tests/testbase'
28
+ require 'test/testbase'
29
29
  require 'rmail/mailbox/mboxreader'
30
30
 
31
31
  class TextRMailParserPushbackReader < TestBase
32
32
 
33
33
  def test_pushback
34
34
  reader = RMail::Parser::PushbackReader.new("")
35
- assert_exception(RMail::Parser::Error) {
35
+ assert_raise(RMail::Parser::Error) {
36
36
  reader.pushback("hi bob")
37
37
  }
38
38
  end
@@ -25,7 +25,7 @@
25
25
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
  #
27
27
 
28
- require 'tests/testbase'
28
+ require 'test/testbase'
29
29
  require 'rmail/serialize'
30
30
  require 'rmail/message'
31
31
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #--
3
- # Copyright (C) 2001, 2002 Matt Armstrong. All rights reserved.
3
+ # Copyright (C) 2001, 2002, 2007 Matt Armstrong. All rights reserved.
4
4
  #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions are met:
@@ -27,8 +27,7 @@
27
27
 
28
28
  # Test the TestBase class itself
29
29
 
30
- require 'rubyunit'
31
- require 'tests/testbase.rb'
30
+ require 'test/testbase.rb'
32
31
 
33
32
  class TestTestBase < TestBase
34
33
 
@@ -73,7 +72,12 @@ class TestTestBase < TestBase
73
72
  end
74
73
 
75
74
  def verify_scratch_dir_name(dir)
76
- assert_match(/scratch.*TestTestBase.*test/, dir)
75
+ assert_match(/_scratch.*TestTestBase/, dir)
76
+ end
77
+
78
+ def test_name
79
+ assert_match(/\btest_name\b/, name)
80
+ assert_match(/\bTestTestBase\b/, name)
77
81
  end
78
82
 
79
83
  def test_scratch_dir