rims 0.2.4 → 0.2.5

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.
@@ -34,11 +34,7 @@ module RIMS::Test
34
34
 
35
35
  def make_fetch_parser(read_only: false)
36
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
37
+ @folder = @mail_store.open_folder(@inbox_id, read_only: read_only).reload
42
38
  @parser = RIMS::Protocol::FetchParser.new(@mail_store, @folder)
43
39
  end
44
40
  private :make_fetch_parser
@@ -449,93 +445,93 @@ module RIMS::Test
449
445
  parse_fetch_attribute(fetch_att_bodystruct) {
450
446
  assert_fetch(0, [
451
447
  "#{fetch_att_bodystruct} " +
452
- encode_list([ 'TEXT',
453
- 'PLAIN',
454
- %w[ charset us-ascii ],
455
- nil,
456
- nil,
457
- '7BIT',
458
- @simple_mail.raw_source.bytesize,
459
- @simple_mail.raw_source.each_line.count
460
- ])
448
+ encode_bodystructure([ 'TEXT',
449
+ 'PLAIN',
450
+ %w[ charset us-ascii ],
451
+ nil,
452
+ nil,
453
+ '7BIT',
454
+ @simple_mail.raw_source.bytesize,
455
+ @simple_mail.raw_source.each_line.count
456
+ ])
461
457
  ])
462
458
  assert_fetch(1, [
463
459
  "#{fetch_att_bodystruct} " +
464
- encode_list([ [ 'TEXT', 'PLAIN', %w[ charset us-ascii], nil, nil, nil,
465
- @mpart_mail.parts[0].raw_source.bytesize,
466
- @mpart_mail.parts[0].raw_source.each_line.count
467
- ],
468
- [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
469
- @mpart_mail.parts[1].raw_source.bytesize
470
- ],
471
- [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
472
- @mpart_mail.parts[2].raw_source.bytesize,
473
- [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
474
- [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
475
- ],
476
- [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
477
- @mpart_mail.parts[2].message.parts[0].raw_source.bytesize,
478
- @mpart_mail.parts[2].message.parts[0].raw_source.each_line.count
479
- ],
480
- [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
481
- @mpart_mail.parts[2].message.parts[1].raw_source.bytesize
482
- ],
483
- 'MIXED'
484
- ],
485
- @mpart_mail.parts[2].raw_source.each_line.count
486
- ],
487
- [ [ 'IMAGE', 'GIF', [], nil, nil, nil,
488
- @mpart_mail.parts[3].parts[0].raw_source.bytesize
489
- ],
490
- [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
491
- @mpart_mail.parts[3].parts[1].raw_source.bytesize,
492
- [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
493
- [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
494
- ],
495
- [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
496
- @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.bytesize,
497
- @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.each_line.count
498
- ],
499
- [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
500
- @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.bytesize,
501
- @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.each_line.count
502
- ],
503
- [ 'TEXT', 'HTML', %w[ charset us-ascii ], nil, nil, nil,
504
- @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.bytesize,
505
- @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.each_line.count
506
- ],
507
- 'ALTERNATIVE'
508
- ],
509
- 'MIXED'
510
- ],
511
- @mpart_mail.parts[3].parts[1].raw_source.each_line.count
512
- ],
513
- 'MIXED',
514
- ],
515
- 'MIXED'
516
- ])
460
+ encode_bodystructure([ [ 'TEXT', 'PLAIN', %w[ charset us-ascii], nil, nil, nil,
461
+ @mpart_mail.parts[0].raw_source.bytesize,
462
+ @mpart_mail.parts[0].raw_source.each_line.count
463
+ ],
464
+ [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
465
+ @mpart_mail.parts[1].raw_source.bytesize
466
+ ],
467
+ [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
468
+ @mpart_mail.parts[2].raw_source.bytesize,
469
+ [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
470
+ [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
471
+ ],
472
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
473
+ @mpart_mail.parts[2].message.parts[0].raw_source.bytesize,
474
+ @mpart_mail.parts[2].message.parts[0].raw_source.each_line.count
475
+ ],
476
+ [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
477
+ @mpart_mail.parts[2].message.parts[1].raw_source.bytesize
478
+ ],
479
+ 'MIXED'
480
+ ],
481
+ @mpart_mail.parts[2].raw_source.each_line.count
482
+ ],
483
+ [ [ 'IMAGE', 'GIF', [], nil, nil, nil,
484
+ @mpart_mail.parts[3].parts[0].raw_source.bytesize
485
+ ],
486
+ [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
487
+ @mpart_mail.parts[3].parts[1].raw_source.bytesize,
488
+ [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
489
+ [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
490
+ ],
491
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
492
+ @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.bytesize,
493
+ @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.each_line.count
494
+ ],
495
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
496
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.bytesize,
497
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.each_line.count
498
+ ],
499
+ [ 'TEXT', 'HTML', %w[ charset us-ascii ], nil, nil, nil,
500
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.bytesize,
501
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.each_line.count
502
+ ],
503
+ 'ALTERNATIVE'
504
+ ],
505
+ 'MIXED'
506
+ ],
507
+ @mpart_mail.parts[3].parts[1].raw_source.each_line.count
508
+ ],
509
+ 'MIXED',
510
+ ],
511
+ 'MIXED'
512
+ ])
517
513
  ])
518
514
  assert_fetch(2, [
519
515
  "#{fetch_att_bodystruct} " +
520
- encode_list([ 'APPLICATION',
521
- 'OCTET-STREAM',
522
- [],
523
- nil,
524
- nil,
525
- nil,
526
- @empty_mail.raw_source.bytesize
527
- ])
516
+ encode_bodystructure([ 'APPLICATION',
517
+ 'OCTET-STREAM',
518
+ [],
519
+ nil,
520
+ nil,
521
+ nil,
522
+ @empty_mail.raw_source.bytesize
523
+ ])
528
524
  ])
529
525
  assert_fetch(3, [
530
526
  "#{fetch_att_bodystruct} " +
531
- encode_list([ 'APPLICATION',
532
- 'OCTET-STREAM',
533
- [],
534
- nil,
535
- nil,
536
- nil,
537
- @no_body_mail.raw_source.bytesize
538
- ])
527
+ encode_bodystructure([ 'APPLICATION',
528
+ 'OCTET-STREAM',
529
+ [],
530
+ nil,
531
+ nil,
532
+ nil,
533
+ @no_body_mail.raw_source.bytesize
534
+ ])
539
535
  ])
540
536
  }
541
537
  end
@@ -589,7 +585,7 @@ module RIMS::Test
589
585
  '((NIL NIL "alice" "test.com") ("bob" NIL "bob" "test.com"))', # To
590
586
  '(("Kate" NIL "kate" "test.com"))', # Cc
591
587
  '((NIL NIL "foo" "nonet.com"))', # Bcc
592
- '"<20131106081723.5KJU1774292@smtp.testt.com>"',# In-Reply-To
588
+ '"<20131106081723.5KJU1774292@smtp.test.com>"', # In-Reply-To
593
589
  '"<20131107214750.445A1255B9F@smtp.nonet.com>"' # Message-Id
594
590
  ]
595
591
  ])
@@ -707,15 +703,15 @@ module RIMS::Test
707
703
  'NIL' # Message-Id
708
704
  ],
709
705
  'BODY',
710
- encode_list([ 'TEXT',
711
- 'PLAIN',
712
- %w[ charset us-ascii ],
713
- nil,
714
- nil,
715
- '7BIT',
716
- @simple_mail.raw_source.bytesize,
717
- @simple_mail.raw_source.each_line.count
718
- ])
706
+ encode_bodystructure([ 'TEXT',
707
+ 'PLAIN',
708
+ %w[ charset us-ascii ],
709
+ nil,
710
+ nil,
711
+ '7BIT',
712
+ @simple_mail.raw_source.bytesize,
713
+ @simple_mail.raw_source.each_line.count
714
+ ])
719
715
  ])
720
716
  assert_fetch(1, [
721
717
  'FLAGS (\Recent)',
@@ -734,60 +730,60 @@ module RIMS::Test
734
730
  'NIL' # Message-Id
735
731
  ],
736
732
  'BODY',
737
- encode_list([ [ 'TEXT', 'PLAIN', %w[ charset us-ascii], nil, nil, nil,
738
- @mpart_mail.parts[0].raw_source.bytesize,
739
- @mpart_mail.parts[0].raw_source.each_line.count
740
- ],
741
- [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
742
- @mpart_mail.parts[1].raw_source.bytesize
743
- ],
744
- [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
745
- @mpart_mail.parts[2].raw_source.bytesize,
746
- [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
747
- [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
748
- ],
749
- [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
750
- @mpart_mail.parts[2].message.parts[0].raw_source.bytesize,
751
- @mpart_mail.parts[2].message.parts[0].raw_source.each_line.count
752
- ],
753
- [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
754
- @mpart_mail.parts[2].message.parts[1].raw_source.bytesize
755
- ],
756
- 'MIXED'
757
- ],
758
- @mpart_mail.parts[2].raw_source.each_line.count
759
- ],
760
- [
761
- [ 'IMAGE', 'GIF', [], nil, nil, nil,
762
- @mpart_mail.parts[3].parts[0].raw_source.bytesize
763
- ],
764
- [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
765
- @mpart_mail.parts[3].parts[1].raw_source.bytesize,
766
- [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
767
- [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
768
- ],
769
- [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
770
- @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.bytesize,
771
- @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.each_line.count
772
- ],
773
- [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
774
- @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.bytesize,
775
- @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.each_line.count
776
- ],
777
- [ 'TEXT', 'HTML', %w[ charset us-ascii ], nil, nil, nil,
778
- @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.bytesize,
779
- @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.each_line.count
780
- ],
781
- 'ALTERNATIVE'
782
- ],
783
- 'MIXED'
784
- ],
785
- @mpart_mail.parts[3].parts[1].raw_source.each_line.count
786
- ],
787
- 'MIXED',
788
- ],
789
- 'MIXED'
790
- ])
733
+ encode_bodystructure([ [ 'TEXT', 'PLAIN', %w[ charset us-ascii], nil, nil, nil,
734
+ @mpart_mail.parts[0].raw_source.bytesize,
735
+ @mpart_mail.parts[0].raw_source.each_line.count
736
+ ],
737
+ [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
738
+ @mpart_mail.parts[1].raw_source.bytesize
739
+ ],
740
+ [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
741
+ @mpart_mail.parts[2].raw_source.bytesize,
742
+ [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
743
+ [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
744
+ ],
745
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
746
+ @mpart_mail.parts[2].message.parts[0].raw_source.bytesize,
747
+ @mpart_mail.parts[2].message.parts[0].raw_source.each_line.count
748
+ ],
749
+ [ 'APPLICATION', 'OCTET-STREAM', [], nil, nil, nil,
750
+ @mpart_mail.parts[2].message.parts[1].raw_source.bytesize
751
+ ],
752
+ 'MIXED'
753
+ ],
754
+ @mpart_mail.parts[2].raw_source.each_line.count
755
+ ],
756
+ [
757
+ [ 'IMAGE', 'GIF', [], nil, nil, nil,
758
+ @mpart_mail.parts[3].parts[0].raw_source.bytesize
759
+ ],
760
+ [ 'MESSAGE', 'RFC822', [], nil, nil, nil,
761
+ @mpart_mail.parts[3].parts[1].raw_source.bytesize,
762
+ [ 'Fri, 8 Nov 2013 19:31:03 +0900', 'inner multipart',
763
+ [ [ nil, nil, 'foo', 'nonet.com' ] ], nil, nil, [ [ nil, nil, 'bar', 'nonet.com' ] ], nil, nil, nil, nil
764
+ ],
765
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
766
+ @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.bytesize,
767
+ @mpart_mail.parts[3].parts[1].message.parts[0].raw_source.each_line.count
768
+ ],
769
+ [ [ 'TEXT', 'PLAIN', %w[ charset us-ascii ], nil, nil, nil,
770
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.bytesize,
771
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[0].raw_source.each_line.count
772
+ ],
773
+ [ 'TEXT', 'HTML', %w[ charset us-ascii ], nil, nil, nil,
774
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.bytesize,
775
+ @mpart_mail.parts[3].parts[1].message.parts[1].parts[1].raw_source.each_line.count
776
+ ],
777
+ 'ALTERNATIVE'
778
+ ],
779
+ 'MIXED'
780
+ ],
781
+ @mpart_mail.parts[3].parts[1].raw_source.each_line.count
782
+ ],
783
+ 'MIXED',
784
+ ],
785
+ 'MIXED'
786
+ ])
791
787
  ])
792
788
  }
793
789
  end
@@ -914,6 +910,139 @@ module RIMS::Test
914
910
  class ProtocolFetchParserUtilsTest < Test::Unit::TestCase
915
911
  include ProtocolFetchMailSample
916
912
 
913
+ data('symbol' => [ '(foo)', [ :foo ] ],
914
+ 'string' => [ '("Hello world.")', [ 'Hello world.' ] ],
915
+ 'integer' => [ '(128)', [ 128 ] ],
916
+ 'nil' => [ '(NIL)', [ nil ] ],
917
+ 'array' => [ '(())', [ [] ] ],
918
+ 'all' => [ '(foo "Hello world." 128 NIL (bar "Good bye." 256 NIL))',
919
+ [ :foo,
920
+ 'Hello world.',
921
+ 128,
922
+ nil,
923
+ [ :bar,
924
+ 'Good bye.',
925
+ 256,
926
+ nil
927
+ ]
928
+ ]
929
+ ])
930
+ def test_encode_list(data)
931
+ expected_value, array = data
932
+ assert_equal(expected_value, RIMS::Protocol::FetchParser::Utils.encode_list(array))
933
+ end
934
+
935
+ data('text/plain' => [ '("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "BASE64" 16722 335)',
936
+ [ 'TEXT',
937
+ 'PLAIN',
938
+ %w[ CHARSET UTF-8 ],
939
+ nil,
940
+ nil,
941
+ 'BASE64',
942
+ 16722,
943
+ 335
944
+ ]
945
+ ],
946
+ 'multipart/alternative' => [ '(("TEXT" "PLAIN" ("CHARSET" "UTF-8" "DELSP" "yes" "FORMAT" "flowed") NIL NIL "BASE64" 1756 36)("TEXT" "HTML" ("CHARSET" "UTF-8") NIL NIL "QUOTED-PRINTABLE" 5921 119) "ALTERNATIVE")',
947
+ [ [ 'TEXT',
948
+ 'PLAIN',
949
+ %w[ CHARSET UTF-8 DELSP yes FORMAT flowed ],
950
+ nil,
951
+ nil,
952
+ 'BASE64',
953
+ 1756,
954
+ 36
955
+ ],
956
+ [ 'TEXT',
957
+ 'HTML',
958
+ %w[ CHARSET UTF-8 ],
959
+ nil,
960
+ nil,
961
+ 'QUOTED-PRINTABLE',
962
+ 5921,
963
+ 119
964
+ ],
965
+ 'ALTERNATIVE'
966
+ ]
967
+ ],
968
+ 'message/rfc822:plain/text' => [ '("MESSAGE" "RFC822" () NIL NIL NIL 16822 ("8 Nov 2013 06:47:50 +0900 (JST)" "test" (NIL NIL "alice" "example.net") NIL NIL (NIL NIL "bob" "example.net") NIL NIL NIL NIL) ("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "BASE64" 16722 335) 345)',
969
+ [ 'MESSAGE',
970
+ 'RFC822',
971
+ [],
972
+ nil,
973
+ nil,
974
+ nil,
975
+ 16822,
976
+ [ '8 Nov 2013 06:47:50 +0900 (JST)', # Date
977
+ 'test', # Subject
978
+ [ nil, nil, 'alice', 'example.net' ], # From
979
+ nil, # Reply-To
980
+ nil, # Sender
981
+ [ nil, nil, 'bob', 'example.net'], # To
982
+ nil, # Cc
983
+ nil, # Bcc
984
+ nil, # In-Reply-To
985
+ nil # Message-Id
986
+ ],
987
+ [ 'TEXT',
988
+ 'PLAIN',
989
+ %w[ CHARSET UTF-8 ],
990
+ nil,
991
+ nil,
992
+ 'BASE64',
993
+ 16722,
994
+ 335
995
+ ],
996
+ 345
997
+ ]
998
+ ],
999
+ 'message/rfc822:multipart/alternative' => [ '("MESSAGE" "RFC822" () NIL NIL NIL 16822 ("8 Nov 2013 06:47:50 +0900 (JST)" "test" (NIL NIL "alice" "example.net") NIL NIL (NIL NIL "bob" "example.net") NIL NIL NIL NIL) (("TEXT" "PLAIN" ("CHARSET" "UTF-8" "DELSP" "yes" "FORMAT" "flowed") NIL NIL "BASE64" 1756 36)("TEXT" "HTML" ("CHARSET" "UTF-8") NIL NIL "QUOTED-PRINTABLE" 5921 119) "ALTERNATIVE") 345)',
1000
+ [ 'MESSAGE',
1001
+ 'RFC822',
1002
+ [],
1003
+ nil,
1004
+ nil,
1005
+ nil,
1006
+ 16822,
1007
+ [ '8 Nov 2013 06:47:50 +0900 (JST)', # Date
1008
+ 'test', # Subject
1009
+ [ nil, nil, 'alice', 'example.net' ], # From
1010
+ nil, # Reply-To
1011
+ nil, # Sender
1012
+ [ nil, nil, 'bob', 'example.net'], # To
1013
+ nil, # Cc
1014
+ nil, # Bcc
1015
+ nil, # In-Reply-To
1016
+ nil # Message-Id
1017
+ ],
1018
+ [ [ 'TEXT',
1019
+ 'PLAIN',
1020
+ %w[ CHARSET UTF-8 DELSP yes FORMAT flowed ],
1021
+ nil,
1022
+ nil,
1023
+ 'BASE64',
1024
+ 1756,
1025
+ 36
1026
+ ],
1027
+ [ 'TEXT',
1028
+ 'HTML',
1029
+ %w[ CHARSET UTF-8 ],
1030
+ nil,
1031
+ nil,
1032
+ 'QUOTED-PRINTABLE',
1033
+ 5921,
1034
+ 119
1035
+ ],
1036
+ 'ALTERNATIVE'
1037
+ ],
1038
+ 345
1039
+ ]
1040
+ ])
1041
+ def test_encode_bodystructure(data)
1042
+ expected_value, array = data
1043
+ assert_equal(expected_value, RIMS::Protocol::FetchParser::Utils.encode_bodystructure(array))
1044
+ end
1045
+
917
1046
  def test_encode_header
918
1047
  assert_equal("To: foo@nonet.org\r\n" +
919
1048
  "From: bar@nonet.org\r\n" +