mailparser 0.5.2 → 0.5.3
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.
- checksums.yaml +7 -0
- data/lib/mailparser/rfc2047.rb +29 -36
- data/test/test_rfc2047.rb +6 -15
- metadata +9 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: acab11e0f5b50260e17f32e1fea879d8505fff45
|
4
|
+
data.tar.gz: f0ce38c8bb40d11a3332515b4aabb7d835cb692f
|
5
|
+
!binary "U0hBNTEy":
|
6
|
+
metadata.gz: 4edf18f3211be9fb2d2114db16265fd728a4f5a69eb1d96ab9a7fc430e0cdcc740f1d3b00ae04290a6203b611cfcd0b22531ac8c5962d7a513798bbdda57c53d
|
7
|
+
data.tar.gz: ee05e15d52db8517094e5c9189787c7e3f557a5c17c9d2dd8a8d3868111e671e086121296b1d13493e9ee6d43fc0ab6576fcd35bd3dda4b39dbfb91451904a95
|
data/lib/mailparser/rfc2047.rb
CHANGED
@@ -20,53 +20,32 @@ module MailParser::RFC2047
|
|
20
20
|
charset = opt
|
21
21
|
end
|
22
22
|
charset_converter ||= MailParser::ConvCharset.method(:conv_charset)
|
23
|
-
last_charset = nil
|
24
23
|
words = []
|
25
24
|
mime_word = false
|
26
|
-
str.gsub(/\r?\n/, '')
|
27
|
-
|
28
|
-
if
|
25
|
+
ss = StringScanner.new(str.gsub(/\r?\n/, ''))
|
26
|
+
until ss.eos?
|
27
|
+
if s = ss.scan(/\=\?[^\(\)\<\>\@\,\;\:\"\/\[\]\?\.\=]+\?[QB]\?[^\? ]+\?\=/i)
|
29
28
|
begin
|
30
|
-
s =
|
29
|
+
s = Encoded.new s, charset, charset_converter
|
30
|
+
words.pop if words.length >= 2 and words[-1].is_a? Space and words[-2].is_a? Encoded
|
31
31
|
rescue
|
32
|
-
|
33
|
-
cs = nil
|
32
|
+
# ignore
|
34
33
|
end
|
34
|
+
words.push s
|
35
|
+
elsif s = ss.scan(/\s+/)
|
36
|
+
words.push Space.new(s)
|
37
|
+
elsif s = ss.scan(/[^\s=]+/)
|
38
|
+
words.push s
|
39
|
+
else
|
40
|
+
words.push ss.scan(/./)
|
35
41
|
end
|
36
|
-
if cs
|
37
|
-
words.pop if mime_word and words.last =~ /\A\s*\z/
|
38
|
-
mime_word = true
|
39
|
-
elsif s !~ /\A\s*\z/
|
40
|
-
mime_word = false
|
41
|
-
end
|
42
|
-
words.push pre if pre
|
43
|
-
words.push s
|
44
|
-
words.push post if post
|
45
42
|
end
|
46
43
|
begin
|
47
44
|
ret = words.join
|
48
45
|
rescue
|
49
|
-
ret = words.map{|s| s.force_encoding('binary')}.join
|
50
|
-
end
|
51
|
-
ret
|
52
|
-
end
|
53
|
-
|
54
|
-
def decode_word(str)
|
55
|
-
charset = nil
|
56
|
-
if str =~ /\=\?([^\(\)\<\>\@\,\;\:\"\/\[\]\?\.\=]+)\?([QB])\?([^\? ]+)\?\=/i
|
57
|
-
pre, post = $`, $'
|
58
|
-
charset, encoding, enc_text = $1.downcase, $2.downcase, $3
|
59
|
-
raw = str
|
60
|
-
str = encoding == "q" ? q_decode(enc_text) : b_decode(enc_text)
|
61
|
-
if String.method_defined? :force_encoding
|
62
|
-
begin
|
63
|
-
str.force_encoding(charset)
|
64
|
-
rescue
|
65
|
-
str.force_encoding('ascii-8bit')
|
66
|
-
end
|
67
|
-
end
|
46
|
+
ret = words.map{|s| s.to_s.force_encoding('binary')}.join
|
68
47
|
end
|
69
|
-
|
48
|
+
charset ? charset_converter.call(charset, charset, ret) : ret
|
70
49
|
end
|
71
50
|
|
72
51
|
def q_decode(str)
|
@@ -77,4 +56,18 @@ module MailParser::RFC2047
|
|
77
56
|
return str.gsub(/[^A-Z0-9\+\/=]/i,"").unpack("m")[0]
|
78
57
|
end
|
79
58
|
|
59
|
+
class Space < String
|
60
|
+
end
|
61
|
+
|
62
|
+
class Encoded
|
63
|
+
def initialize(str, charset, converter)
|
64
|
+
_, cs, encoding, enc_text, = str.split(/\?/)
|
65
|
+
str = encoding.downcase == 'q' ? MailParser::RFC2047.q_decode(enc_text) : MailParser::RFC2047.b_decode(enc_text)
|
66
|
+
@decoded = converter.call(cs, charset||cs, str)
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_s
|
70
|
+
@decoded
|
71
|
+
end
|
72
|
+
end
|
80
73
|
end
|
data/test/test_rfc2047.rb
CHANGED
@@ -23,7 +23,7 @@ class TC_RFC2047 < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_q_decode_end_equal()
|
26
|
-
|
26
|
+
assert_match(/\Aabc=?\z/, MailParser::RFC2047.q_decode("abc="))
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_b_decode_ascii()
|
@@ -38,20 +38,6 @@ class TC_RFC2047 < Test::Unit::TestCase
|
|
38
38
|
assert_equal("とみた", MailParser::RFC2047.b_decode("44Go 44 G/4 4Gf"))
|
39
39
|
end
|
40
40
|
|
41
|
-
def test_decode_word()
|
42
|
-
s, cs, raw = MailParser::RFC2047.decode_word("=?us-ascii?q?hoge?=")
|
43
|
-
assert_equal 'hoge', s
|
44
|
-
assert_equal 'us-ascii', cs
|
45
|
-
assert_equal '=?us-ascii?q?hoge?=', raw
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_decode_word_upcase()
|
49
|
-
s, cs, raw = MailParser::RFC2047.decode_word("=?US-ASCII?Q?hoge?=")
|
50
|
-
assert_equal 'hoge', s
|
51
|
-
assert_equal 'us-ascii', cs
|
52
|
-
assert_equal '=?US-ASCII?Q?hoge?=', raw
|
53
|
-
end
|
54
|
-
|
55
41
|
def test_decode_q_ascii()
|
56
42
|
s = MailParser::RFC2047.decode("=?us-ascii?q?hoge?=")
|
57
43
|
assert_equal("hoge", s)
|
@@ -154,4 +140,9 @@ class TC_RFC2047 < Test::Unit::TestCase
|
|
154
140
|
assert_equal "abc defghijkl mno", s
|
155
141
|
end
|
156
142
|
|
143
|
+
def test_decode_invalid_from_docomo
|
144
|
+
s = MailParser::RFC2047.decode("=?us-ascii?q?a?=(=?us-ascii?q?b?=)")
|
145
|
+
assert_equal "a(b)", s
|
146
|
+
end
|
147
|
+
|
157
148
|
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- TOMITA Masahiro
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mmapscanner
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: MailParser is a parser for mail message
|
@@ -60,27 +57,26 @@ files:
|
|
60
57
|
homepage: http://github.com/tmtm/mailparser
|
61
58
|
licenses:
|
62
59
|
- Ruby's
|
60
|
+
metadata: {}
|
63
61
|
post_install_message:
|
64
62
|
rdoc_options: []
|
65
63
|
require_paths:
|
66
64
|
- lib
|
67
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
66
|
requirements:
|
70
|
-
- -
|
67
|
+
- - ">="
|
71
68
|
- !ruby/object:Gem::Version
|
72
69
|
version: '0'
|
73
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
71
|
requirements:
|
76
|
-
- -
|
72
|
+
- - ">="
|
77
73
|
- !ruby/object:Gem::Version
|
78
74
|
version: '0'
|
79
75
|
requirements: []
|
80
76
|
rubyforge_project:
|
81
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.0.0.preview3.1
|
82
78
|
signing_key:
|
83
|
-
specification_version:
|
79
|
+
specification_version: 4
|
84
80
|
summary: Mail Parser
|
85
81
|
test_files:
|
86
82
|
- test.rb
|
@@ -91,4 +87,3 @@ test_files:
|
|
91
87
|
- test/test_rfc2822.rb
|
92
88
|
- test/test_mailparser.rb
|
93
89
|
- test/test_rfc2045.rb
|
94
|
-
has_rdoc:
|