mailparser 0.4.22a → 0.5.0.beta1
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.
- data/README.txt +2 -6
- data/lib/mailparser/conv_charset.rb +40 -19
- data/lib/mailparser/error.rb +1 -0
- data/lib/mailparser/loose.rb +22 -20
- data/lib/mailparser/rfc2045/parser.rb +140 -140
- data/lib/mailparser/rfc2045/scanner.rb +15 -14
- data/lib/mailparser/rfc2045.rb +1 -0
- data/lib/mailparser/rfc2047.rb +26 -37
- data/lib/mailparser/rfc2183/parser.rb +2 -1
- data/lib/mailparser/rfc2183/scanner.rb +1 -0
- data/lib/mailparser/rfc2183.rb +1 -0
- data/lib/mailparser/rfc2231.rb +6 -5
- data/lib/mailparser/rfc2822/parser.rb +584 -544
- data/lib/mailparser/rfc2822/scanner.rb +21 -21
- data/lib/mailparser/rfc2822.rb +1 -0
- data/lib/mailparser.rb +83 -209
- data/test/test_loose.rb +17 -8
- data/test/test_mailparser.rb +88 -183
- data/test/test_rfc2045.rb +1 -1
- data/test/test_rfc2047.rb +35 -13
- data/test/test_rfc2183.rb +1 -1
- data/test/test_rfc2822.rb +6 -2
- metadata +22 -9
- data/HISTORY +0 -141
- data/lib/mailparser/obsolete.rb +0 -403
- data/test/test_obsolete.rb +0 -615
data/test/test_mailparser.rb
CHANGED
@@ -381,7 +381,11 @@ Content-Type: text/plain; charset=iso-2022-jp
|
|
381
381
|
\e\$B\$\"\$\$\$\&\$\(\$\*\e(B
|
382
382
|
EOS
|
383
383
|
m = MailParser::Message.new(msg)
|
384
|
-
|
384
|
+
if String.method_defined? :encode
|
385
|
+
assert_equal("あいうえお\n".encode('iso-2022-jp'), m.body)
|
386
|
+
else
|
387
|
+
assert_equal("\e\$B\$\"\$\$\$\&\$\(\$\*\e(B\n", m.body)
|
388
|
+
end
|
385
389
|
end
|
386
390
|
|
387
391
|
def test_body_iso2022jp_charset()
|
@@ -391,7 +395,7 @@ Content-Type: text/plain; charset=iso-2022-jp
|
|
391
395
|
|
392
396
|
\e\$B\$\"\$\$\$\&\$\(\$\*\e(B
|
393
397
|
EOS
|
394
|
-
m = MailParser::Message.new(msg, :output_charset=>"
|
398
|
+
m = MailParser::Message.new(msg, :output_charset=>"utf-8")
|
395
399
|
assert_equal("あいうえお\n", m.body)
|
396
400
|
end
|
397
401
|
|
@@ -402,7 +406,7 @@ Content-Type: application/octet-stream; charset=iso-2022-jp
|
|
402
406
|
|
403
407
|
\e\$B\$\"\$\$\$\&\$\(\$\*\e(B
|
404
408
|
EOS
|
405
|
-
m = MailParser::Message.new(msg, :output_charset=>"
|
409
|
+
m = MailParser::Message.new(msg, :output_charset=>"utf-8")
|
406
410
|
assert_equal("\e\$B\$\"\$\$\$\&\$\(\$\*\e(B\n", m.body)
|
407
411
|
end
|
408
412
|
|
@@ -413,40 +417,43 @@ Content-Type: text/plain
|
|
413
417
|
|
414
418
|
abcdefg
|
415
419
|
EOS
|
416
|
-
m = MailParser::Message.new(msg, :output_charset=>"
|
420
|
+
m = MailParser::Message.new(msg, :output_charset=>"utf-8")
|
417
421
|
assert_equal("abcdefg\n", m.body)
|
418
422
|
end
|
419
423
|
|
420
424
|
def test_body_preconv
|
421
|
-
m = MailParser::Message.new(<<EOS, :output_charset=>"
|
425
|
+
m = MailParser::Message.new(<<EOS, :output_charset=>"utf-8")
|
422
426
|
From: TOMITA Masahiro <tommy@tmtm.org>
|
423
427
|
Content-Type: text/plain; charset=iso-2022-jp
|
424
428
|
|
425
429
|
\e$B$3$l$OK\\J8$G$9\e(B
|
426
430
|
EOS
|
427
431
|
assert_equal "これは本文です\n", m.body
|
428
|
-
|
432
|
+
if String.method_defined? :encode
|
433
|
+
assert_equal "これは本文です\n".encode('iso-2022-jp'), m.body_preconv
|
434
|
+
else
|
435
|
+
assert_equal "\e$B$3$l$OK\\J8$G$9\e(B\n", m.body_preconv
|
436
|
+
end
|
429
437
|
end
|
430
438
|
|
431
|
-
def
|
432
|
-
m = MailParser::Message.new(<<EOS
|
439
|
+
def test_body_preconv_with_unknown_charset
|
440
|
+
m = MailParser::Message.new(<<EOS)
|
433
441
|
From: TOMITA Masahiro <tommy@tmtm.org>
|
434
|
-
Content-Type: text/plain; charset=
|
442
|
+
Content-Type: text/plain; charset=hogehoge
|
435
443
|
|
436
|
-
|
444
|
+
abc
|
437
445
|
EOS
|
438
|
-
assert_equal "
|
446
|
+
assert_equal "abc\n", m.body_preconv
|
439
447
|
end
|
440
448
|
|
441
|
-
def
|
442
|
-
m = MailParser::Message.new(<<EOS, :output_charset=>"
|
449
|
+
def test_body_charset_converter
|
450
|
+
m = MailParser::Message.new(<<EOS, :output_charset=>"utf-8", :charset_converter=>proc{|f,t,s| "abcdefg"})
|
443
451
|
From: TOMITA Masahiro <tommy@tmtm.org>
|
444
452
|
Content-Type: text/plain; charset=iso-2022-jp
|
445
453
|
|
446
454
|
\e$B$3$l$OK\\J8$G$9\e(B
|
447
455
|
EOS
|
448
|
-
assert_equal "
|
449
|
-
assert_equal "\e$B$3$l$OK\\J8$G$9\e(B\n", m.body_preconv
|
456
|
+
assert_equal "abcdefg", m.body
|
450
457
|
end
|
451
458
|
|
452
459
|
def test_filename()
|
@@ -568,63 +575,36 @@ EOS
|
|
568
575
|
assert_equal("aaaa bbb", m.filename)
|
569
576
|
end
|
570
577
|
|
571
|
-
def
|
578
|
+
def test_multipart()
|
572
579
|
msg = StringIO.new(<<EOS)
|
573
580
|
From: from1@example.com
|
574
581
|
Content-Type: multipart/mixed; boundary="xxxx"
|
575
582
|
|
583
|
+
preamble
|
576
584
|
--xxxx
|
577
585
|
Content-Type: text/plain
|
578
586
|
|
579
587
|
body1
|
580
588
|
|
581
589
|
--xxxx
|
582
|
-
Content-Type:
|
583
|
-
|
584
|
-
From: from2@example.com
|
585
|
-
Content-Type: text/plain
|
590
|
+
Content-Type: application/octet-stream
|
586
591
|
|
587
592
|
body2
|
588
593
|
--xxxx--
|
594
|
+
epilogue
|
589
595
|
EOS
|
590
|
-
m = MailParser::Message.new(msg
|
591
|
-
assert_equal("<from1@example.com>", m.from.to_s)
|
592
|
-
assert_equal(2, m.part.size)
|
593
|
-
assert_equal("text", m.part[0].type)
|
594
|
-
assert_equal("body1\n", m.part[0].body)
|
595
|
-
assert_equal("message", m.part[1].type)
|
596
|
-
assert_equal("<from2@example.com>", m.part[1].message.from.to_s)
|
597
|
-
assert_equal("body2", m.part[1].message.body)
|
598
|
-
end
|
599
|
-
|
600
|
-
def test_extract_message_type_header_only
|
601
|
-
msg = StringIO.new(<<EOS)
|
602
|
-
From: from1@example.com
|
603
|
-
Content-Type: multipart/mixed; boundary="xxxx"
|
604
|
-
|
605
|
-
--xxxx
|
606
|
-
Content-Type: text/plain
|
607
|
-
|
608
|
-
body1
|
609
|
-
|
610
|
-
--xxxx
|
611
|
-
Content-Type: message/rfc822
|
612
|
-
|
613
|
-
From: from2@example.com
|
614
|
-
Content-Type: text/plain
|
615
|
-
--xxxx--
|
616
|
-
EOS
|
617
|
-
m = MailParser::Message.new(msg, :extract_message_type=>true)
|
596
|
+
m = MailParser::Message.new(msg)
|
618
597
|
assert_equal("<from1@example.com>", m.from.to_s)
|
619
598
|
assert_equal(2, m.part.size)
|
620
599
|
assert_equal("text", m.part[0].type)
|
600
|
+
assert_equal("plain", m.part[0].subtype)
|
621
601
|
assert_equal("body1\n", m.part[0].body)
|
622
|
-
assert_equal("
|
623
|
-
assert_equal("
|
624
|
-
assert_equal("", m.part[1].
|
602
|
+
assert_equal("application", m.part[1].type)
|
603
|
+
assert_equal("octet-stream", m.part[1].subtype)
|
604
|
+
assert_equal("body2", m.part[1].body)
|
625
605
|
end
|
626
606
|
|
627
|
-
def
|
607
|
+
def test_extract_message_type()
|
628
608
|
msg = StringIO.new(<<EOS)
|
629
609
|
From: from1@example.com
|
630
610
|
Content-Type: multipart/mixed; boundary="xxxx"
|
@@ -643,17 +623,17 @@ Content-Type: text/plain
|
|
643
623
|
body2
|
644
624
|
--xxxx--
|
645
625
|
EOS
|
646
|
-
m = MailParser::Message.new(msg, :extract_message_type=>true
|
626
|
+
m = MailParser::Message.new(msg, :extract_message_type=>true)
|
647
627
|
assert_equal("<from1@example.com>", m.from.to_s)
|
648
628
|
assert_equal(2, m.part.size)
|
649
629
|
assert_equal("text", m.part[0].type)
|
650
|
-
assert_equal("", m.part[0].body)
|
630
|
+
assert_equal("body1\n", m.part[0].body)
|
651
631
|
assert_equal("message", m.part[1].type)
|
652
632
|
assert_equal("<from2@example.com>", m.part[1].message.from.to_s)
|
653
|
-
assert_equal("", m.part[1].message.body)
|
633
|
+
assert_equal("body2", m.part[1].message.body)
|
654
634
|
end
|
655
635
|
|
656
|
-
def
|
636
|
+
def test_extract_message_type_header_only
|
657
637
|
msg = StringIO.new(<<EOS)
|
658
638
|
From: from1@example.com
|
659
639
|
Content-Type: multipart/mixed; boundary="xxxx"
|
@@ -668,19 +648,16 @@ Content-Type: message/rfc822
|
|
668
648
|
|
669
649
|
From: from2@example.com
|
670
650
|
Content-Type: text/plain
|
671
|
-
|
672
|
-
body2
|
673
|
-
|
674
651
|
--xxxx--
|
675
652
|
EOS
|
676
|
-
m = MailParser::Message.new(msg, :extract_message_type=>true
|
653
|
+
m = MailParser::Message.new(msg, :extract_message_type=>true)
|
677
654
|
assert_equal("<from1@example.com>", m.from.to_s)
|
678
655
|
assert_equal(2, m.part.size)
|
679
656
|
assert_equal("text", m.part[0].type)
|
680
657
|
assert_equal("body1\n", m.part[0].body)
|
681
658
|
assert_equal("message", m.part[1].type)
|
682
659
|
assert_equal("<from2@example.com>", m.part[1].message.from.to_s)
|
683
|
-
assert_equal("
|
660
|
+
assert_equal("", m.part[1].message.body)
|
684
661
|
end
|
685
662
|
|
686
663
|
def test_extract_multipart_alternative_attach()
|
@@ -714,8 +691,13 @@ EOS
|
|
714
691
|
m = MailParser::Message.new(msg)
|
715
692
|
assert_equal(2, m.part.size)
|
716
693
|
assert_equal(2, m.part[0].part.size)
|
717
|
-
|
718
|
-
|
694
|
+
if String.method_defined? :encode
|
695
|
+
assert_equal("hoge\n".encode('iso-2022-jp'), m.part[0].part[0].body)
|
696
|
+
assert_equal("fuga html\n".encode('iso-2022-jp'), m.part[0].part[1].body)
|
697
|
+
else
|
698
|
+
assert_equal("hoge\n", m.part[0].part[0].body)
|
699
|
+
assert_equal("fuga html\n", m.part[0].part[1].body)
|
700
|
+
end
|
719
701
|
assert_equal("attached file", m.part[1].body)
|
720
702
|
end
|
721
703
|
|
@@ -783,7 +765,7 @@ hogehoge
|
|
783
765
|
EOS
|
784
766
|
m = MailParser::Message.new msg
|
785
767
|
assert_equal "hoge", m.subject
|
786
|
-
assert_equal "
|
768
|
+
assert_equal "", m.body
|
787
769
|
end
|
788
770
|
|
789
771
|
def test_parse_header_only_part()
|
@@ -843,6 +825,39 @@ EOS
|
|
843
825
|
assert_equal "hoge\n", m.part[1].body
|
844
826
|
end
|
845
827
|
|
828
|
+
def test_parse_invalid_format_header
|
829
|
+
msg = StringIO.new <<EOS
|
830
|
+
From: hoge@example.com
|
831
|
+
invalid-header
|
832
|
+
Subject: hoge
|
833
|
+
|
834
|
+
body
|
835
|
+
EOS
|
836
|
+
m = MailParser::Message.new msg
|
837
|
+
assert_equal 'hoge', m.subject
|
838
|
+
assert_equal "body\n", m.body
|
839
|
+
end
|
840
|
+
|
841
|
+
def test_parse_invalid_format_header2
|
842
|
+
msg = StringIO.new <<EOS.chomp
|
843
|
+
From: hoge@example.com
|
844
|
+
invalid-header
|
845
|
+
EOS
|
846
|
+
m = MailParser::Message.new msg
|
847
|
+
assert_equal "From: hoge@example.com\ninvalid-header", m.rawheader
|
848
|
+
end
|
849
|
+
|
850
|
+
def test_rawheader
|
851
|
+
msg = StringIO.new(<<EOS)
|
852
|
+
From: from@example.com\r
|
853
|
+
Content-Type: text/plain\r
|
854
|
+
\r
|
855
|
+
hogehoge\r
|
856
|
+
EOS
|
857
|
+
m = MailParser::Message.new msg
|
858
|
+
assert_equal "From: from@example.com\r\nContent-Type: text/plain\r\n", m.rawheader
|
859
|
+
end
|
860
|
+
|
846
861
|
def test_raw_single_part
|
847
862
|
msg = StringIO.new(<<EOS)
|
848
863
|
From: from@example.com
|
@@ -852,7 +867,7 @@ hogehoge
|
|
852
867
|
|
853
868
|
fugafuga
|
854
869
|
EOS
|
855
|
-
m = MailParser::Message.new msg
|
870
|
+
m = MailParser::Message.new msg
|
856
871
|
assert_equal msg.string, m.raw
|
857
872
|
end
|
858
873
|
|
@@ -882,15 +897,15 @@ Content-Type: text/plain
|
|
882
897
|
fuga
|
883
898
|
--xxx--
|
884
899
|
EOS
|
885
|
-
m = MailParser::Message.new msg
|
900
|
+
m = MailParser::Message.new msg
|
886
901
|
assert_equal msg.string, m.raw
|
887
|
-
assert_equal <<EOS, m.part[0].part[0].raw
|
902
|
+
assert_equal <<EOS.chomp, m.part[0].part[0].raw
|
888
903
|
Content-Type: text/plain
|
889
904
|
|
890
905
|
hoge
|
891
906
|
hoge
|
892
907
|
EOS
|
893
|
-
assert_equal <<EOS, m.part[1].raw
|
908
|
+
assert_equal <<EOS.chomp, m.part[1].raw
|
894
909
|
Content-Type: text/plain
|
895
910
|
|
896
911
|
fuga
|
@@ -916,15 +931,14 @@ Content-Type: text/plain
|
|
916
931
|
body2
|
917
932
|
--xxxx--
|
918
933
|
EOS
|
919
|
-
m = MailParser::Message.new msg
|
934
|
+
m = MailParser::Message.new msg
|
920
935
|
assert_equal msg.string, m.raw
|
921
936
|
assert_equal <<EOS, m.part[0].raw
|
922
937
|
Content-Type: text/plain
|
923
938
|
|
924
939
|
body1
|
925
|
-
|
926
940
|
EOS
|
927
|
-
assert_equal <<EOS, m.part[1].raw
|
941
|
+
assert_equal <<EOS.chomp, m.part[1].raw
|
928
942
|
Content-Type: message/rfc822
|
929
943
|
|
930
944
|
From: from2@example.com
|
@@ -951,15 +965,14 @@ From: from2@example.com
|
|
951
965
|
Content-Type: text/plain
|
952
966
|
--xxxx--
|
953
967
|
EOS
|
954
|
-
m = MailParser::Message.new msg
|
968
|
+
m = MailParser::Message.new msg
|
955
969
|
assert_equal msg.string, m.raw
|
956
970
|
assert_equal <<EOS, m.part[0].raw
|
957
971
|
Content-Type: text/plain
|
958
972
|
|
959
973
|
body1
|
960
|
-
|
961
974
|
EOS
|
962
|
-
assert_equal <<EOS, m.part[1].raw
|
975
|
+
assert_equal <<EOS.chomp, m.part[1].raw
|
963
976
|
Content-Type: message/rfc822
|
964
977
|
|
965
978
|
From: from2@example.com
|
@@ -975,7 +988,7 @@ Subject: hogehoge
|
|
975
988
|
|
976
989
|
body1
|
977
990
|
EOS
|
978
|
-
m = MailParser::Message.new msg
|
991
|
+
m = MailParser::Message.new msg
|
979
992
|
assert_equal <<EOS, m.raw
|
980
993
|
From: from1@example.com
|
981
994
|
Subject: hogehoge
|
@@ -985,97 +998,6 @@ body1
|
|
985
998
|
EOS
|
986
999
|
end
|
987
1000
|
|
988
|
-
def test_raw_and_use_file
|
989
|
-
msg = StringIO.new(<<EOS)
|
990
|
-
From: from@example.com
|
991
|
-
Content-Type: text/plain
|
992
|
-
|
993
|
-
hogehoge
|
994
|
-
|
995
|
-
fugafuga
|
996
|
-
EOS
|
997
|
-
m = MailParser::Message.new msg, :keep_raw=>true, :use_file=>1
|
998
|
-
assert_equal msg.string, m.raw
|
999
|
-
end
|
1000
|
-
end
|
1001
|
-
|
1002
|
-
class TC_DelimIO < Test::Unit::TestCase
|
1003
|
-
include MailParser
|
1004
|
-
def setup()
|
1005
|
-
end
|
1006
|
-
def teardown()
|
1007
|
-
end
|
1008
|
-
|
1009
|
-
def test_gets
|
1010
|
-
s = StringIO.new <<EOS
|
1011
|
-
aaaa
|
1012
|
-
bbbb
|
1013
|
-
cccc
|
1014
|
-
dddd
|
1015
|
-
EOS
|
1016
|
-
dio = DelimIO.new(DelimIO.new(s), ["cccc"])
|
1017
|
-
assert_equal "aaaa\n", dio.gets
|
1018
|
-
assert_equal "bbbb\n", dio.gets
|
1019
|
-
assert_equal nil, dio.gets
|
1020
|
-
assert_equal true, dio.eof?
|
1021
|
-
dio.ungets
|
1022
|
-
assert_equal false, dio.eof?
|
1023
|
-
assert_equal "bbbb\n", dio.gets
|
1024
|
-
assert_equal nil, dio.gets
|
1025
|
-
assert_equal true, dio.eof?
|
1026
|
-
end
|
1027
|
-
|
1028
|
-
def test_each_line
|
1029
|
-
s = StringIO.new <<EOS
|
1030
|
-
aaaa
|
1031
|
-
bbbb
|
1032
|
-
cccc
|
1033
|
-
dddd
|
1034
|
-
EOS
|
1035
|
-
dio = DelimIO.new(DelimIO.new(s))
|
1036
|
-
ret = []
|
1037
|
-
dio.each_line do |line|
|
1038
|
-
ret << line
|
1039
|
-
end
|
1040
|
-
assert_equal ["aaaa\n","bbbb\n","cccc\n","dddd\n"], ret
|
1041
|
-
assert_equal true, dio.eof?
|
1042
|
-
end
|
1043
|
-
|
1044
|
-
def test_each_line_delim
|
1045
|
-
s = StringIO.new <<EOS
|
1046
|
-
aaaa
|
1047
|
-
bbbb
|
1048
|
-
cccc
|
1049
|
-
dddd
|
1050
|
-
EOS
|
1051
|
-
dio = DelimIO.new(DelimIO.new(s), ["cccc"])
|
1052
|
-
ret = []
|
1053
|
-
dio.each_line do |line|
|
1054
|
-
ret << line
|
1055
|
-
end
|
1056
|
-
assert_equal ["aaaa\n","bbbb\n"], ret
|
1057
|
-
assert_equal true, dio.eof?
|
1058
|
-
end
|
1059
|
-
|
1060
|
-
def test_ungets
|
1061
|
-
s = StringIO.new <<EOS
|
1062
|
-
aaaa
|
1063
|
-
bbbb
|
1064
|
-
cccc
|
1065
|
-
dddd
|
1066
|
-
EOS
|
1067
|
-
dio = DelimIO.new(DelimIO.new(s), ["cccc"])
|
1068
|
-
ret = []
|
1069
|
-
dio.each_line do |line|
|
1070
|
-
ret << line
|
1071
|
-
end
|
1072
|
-
assert_equal ["aaaa\n","bbbb\n"], ret
|
1073
|
-
assert_equal true, dio.eof?
|
1074
|
-
dio.ungets
|
1075
|
-
assert_equal false, dio.eof?
|
1076
|
-
assert_equal "bbbb\n", dio.gets
|
1077
|
-
end
|
1078
|
-
|
1079
1001
|
def test_base64_body
|
1080
1002
|
msg = <<EOS
|
1081
1003
|
Content-Transfer-Encoding: base64
|
@@ -1111,20 +1033,3 @@ EOS
|
|
1111
1033
|
end
|
1112
1034
|
|
1113
1035
|
end
|
1114
|
-
|
1115
|
-
class TC_DataBuffer < Test::Unit::TestCase
|
1116
|
-
def test_string
|
1117
|
-
b = MailParser::DataBuffer.new(nil)
|
1118
|
-
assert_equal '', b.str
|
1119
|
-
b << 'hogehoge'
|
1120
|
-
b << 'fugafuga'
|
1121
|
-
assert_equal 'hogehogefugafuga', b.str
|
1122
|
-
end
|
1123
|
-
def test_file
|
1124
|
-
b = MailParser::DataBuffer.new(1)
|
1125
|
-
assert_equal '', b.str
|
1126
|
-
b << 'hogehoge'
|
1127
|
-
b << 'fugafuga'
|
1128
|
-
assert_equal 'hogehogefugafuga', b.str
|
1129
|
-
end
|
1130
|
-
end
|
data/test/test_rfc2045.rb
CHANGED
data/test/test_rfc2047.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# coding: ascii-8bit
|
2
2
|
# Copyright (C) 2006-2010 TOMITA Masahiro
|
3
3
|
# mailto:tommy@tmtm.org
|
4
4
|
|
@@ -39,19 +39,19 @@ class TC_RFC2047 < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_split_decode_q_ascii()
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
MailParser::RFC2047.split_decode("=?us-ascii?q?hoge?=") do |s, cs, raw |
|
43
|
+
assert_equal 'hoge', s
|
44
|
+
assert_equal 'us-ascii', cs
|
45
|
+
assert_equal '=?us-ascii?q?hoge?=', raw
|
46
|
+
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_split_decode_q_ascii_upcase()
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
MailParser::RFC2047.split_decode("=?US-ASCII?Q?hoge?=") do |s, cs, raw|
|
51
|
+
assert_equal 'hoge', s
|
52
|
+
assert_equal 'us-ascii', cs
|
53
|
+
assert_equal '=?US-ASCII?Q?hoge?=', raw
|
54
|
+
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_decode_q_ascii()
|
@@ -69,6 +69,24 @@ class TC_RFC2047 < Test::Unit::TestCase
|
|
69
69
|
assert_equal("abcdefg", s)
|
70
70
|
end
|
71
71
|
|
72
|
+
def test_decode_with_output_charset
|
73
|
+
s = MailParser::RFC2047.decode('abcdefg', :output_charset=>'utf-8')
|
74
|
+
assert_equal Encoding::UTF_8, s.encoding if defined? Encoding
|
75
|
+
assert_equal('abcdefg', s)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_decode_raw_utf8
|
79
|
+
s = MailParser::RFC2047.decode('あいう')
|
80
|
+
assert_equal('あいう', s)
|
81
|
+
end
|
82
|
+
|
83
|
+
if defined? Encoding
|
84
|
+
def test_decode_raw_utf8_with_output_charset
|
85
|
+
s = MailParser::RFC2047.decode('あいう', :output_charset=>'utf-8')
|
86
|
+
assert_equal('あいう'.force_encoding('utf-8'), s)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
72
90
|
def test_decode_encode_plain()
|
73
91
|
s = MailParser::RFC2047.decode("012345 =?us-ascii?q?hoge?= abcdefg")
|
74
92
|
assert_equal("012345 hoge abcdefg", s)
|
@@ -101,12 +119,16 @@ class TC_RFC2047 < Test::Unit::TestCase
|
|
101
119
|
|
102
120
|
def test_decode_sjis()
|
103
121
|
s = MailParser::RFC2047.decode("=?sjis?b?h0A=?=", "UTF-8")
|
104
|
-
|
122
|
+
if String.method_defined? :force_encoding
|
123
|
+
assert_equal("\xe2\x91\xa0".force_encoding('utf-8'), s)
|
124
|
+
end
|
105
125
|
end
|
106
126
|
|
107
127
|
def test_decode_iso2022jp()
|
108
128
|
s = MailParser::RFC2047.decode("=?iso-2022-jp?b?GyRCLSEbKEI=?=", "UTF-8")
|
109
|
-
|
129
|
+
if String.method_defined? :force_encoding
|
130
|
+
assert_equal("\xe2\x91\xa0".force_encoding('utf-8'), s)
|
131
|
+
end
|
110
132
|
end
|
111
133
|
|
112
134
|
def test_decode_charset_converter()
|
data/test/test_rfc2183.rb
CHANGED
data/test/test_rfc2822.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
require "timeout"
|
6
6
|
require "mailparser/rfc2822"
|
7
7
|
|
8
|
-
|
8
|
+
if $0 == __FILE__ and not ARGV.empty?
|
9
9
|
ARGV.each do |fname|
|
10
10
|
File.open(fname) do |f|
|
11
11
|
header = []
|
@@ -89,7 +89,11 @@ class TC_RFC2822Parser < Test::Unit::TestCase
|
|
89
89
|
assert_equal("a@b.c", m.addr_spec.to_s)
|
90
90
|
|
91
91
|
m = MailParser::RFC2822::Parser.new(:decode_mime_header=>true).parse(:MAILBOX, "=?euc-jp?q?=A4=A2=A4=A4?= <a@b.c>")
|
92
|
-
|
92
|
+
if String.method_defined? :encode
|
93
|
+
assert_equal("あい".encode('euc-jp'), m.display_name.to_s)
|
94
|
+
else
|
95
|
+
assert_equal("\xA4\xA2\xA4\xA4", m.display_name.to_s)
|
96
|
+
end
|
93
97
|
assert_equal("a@b.c", m.addr_spec.to_s)
|
94
98
|
|
95
99
|
m = MailParser::RFC2822::Parser.new(:decode_mime_header=>true, :output_charset=>"utf-8").parse(:MAILBOX, "=?euc-jp?q?=A4=A2=A4=A4?= <a@b.c>")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.beta1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,16 +9,31 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2012-09-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mmapscanner
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: MailParser is a parser for mail message
|
15
31
|
email: tommy@tmtm.org
|
16
32
|
executables: []
|
17
33
|
extensions: []
|
18
34
|
extra_rdoc_files: []
|
19
35
|
files:
|
20
36
|
- README.txt
|
21
|
-
- HISTORY
|
22
37
|
- lib/mailparser.rb
|
23
38
|
- lib/mailparser/rfc2183/scanner.rb
|
24
39
|
- lib/mailparser/rfc2183/parser.rb
|
@@ -33,7 +48,6 @@ files:
|
|
33
48
|
- lib/mailparser/rfc2822.rb
|
34
49
|
- lib/mailparser/rfc2822/scanner.rb
|
35
50
|
- lib/mailparser/rfc2822/parser.rb
|
36
|
-
- lib/mailparser/obsolete.rb
|
37
51
|
- lib/mailparser/rfc2231.rb
|
38
52
|
- test.rb
|
39
53
|
- test/test_loose.rb
|
@@ -41,7 +55,6 @@ files:
|
|
41
55
|
- test/test_rfc2183.rb
|
42
56
|
- test/test_rfc2047.rb
|
43
57
|
- test/test_rfc2822.rb
|
44
|
-
- test/test_obsolete.rb
|
45
58
|
- test/test_mailparser.rb
|
46
59
|
- test/test_rfc2045.rb
|
47
60
|
homepage: http://github.com/tmtm/mailparser
|
@@ -65,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
78
|
version: 1.3.1
|
66
79
|
requirements: []
|
67
80
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.8.
|
81
|
+
rubygems_version: 1.8.23
|
69
82
|
signing_key:
|
70
83
|
specification_version: 3
|
71
84
|
summary: Mail Parser
|
@@ -76,6 +89,6 @@ test_files:
|
|
76
89
|
- test/test_rfc2183.rb
|
77
90
|
- test/test_rfc2047.rb
|
78
91
|
- test/test_rfc2822.rb
|
79
|
-
- test/test_obsolete.rb
|
80
92
|
- test/test_mailparser.rb
|
81
93
|
- test/test_rfc2045.rb
|
94
|
+
has_rdoc:
|