mailparser 0.5.0.beta3 → 0.5.0.beta4

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.
@@ -23,8 +23,8 @@ module MailParser::RFC2047
23
23
  last_charset = nil
24
24
  words = []
25
25
  mime_word = false
26
- str.split(/(\s+)/).each do |s|
27
- s, cs, raw = decode_word(s)
26
+ str.gsub(/\r?\n/, '').split(/(\s+)/).each do |s|
27
+ s, cs, raw, pre, post = decode_word(s)
28
28
  if charset
29
29
  begin
30
30
  s = charset_converter.call(cs || charset, charset, s)
@@ -39,7 +39,9 @@ module MailParser::RFC2047
39
39
  elsif s !~ /\A\s*\z/
40
40
  mime_word = false
41
41
  end
42
+ words.push pre if pre
42
43
  words.push s
44
+ words.push post if post
43
45
  end
44
46
  begin
45
47
  ret = words.join
@@ -52,6 +54,7 @@ module MailParser::RFC2047
52
54
  def decode_word(str)
53
55
  charset = nil
54
56
  if str =~ /\=\?([^\(\)\<\>\@\,\;\:\"\/\[\]\?\.\=]+)\?([QB])\?([^\? ]+)\?\=/i
57
+ pre, post = $`, $'
55
58
  charset, encoding, enc_text = $1.downcase, $2.downcase, $3
56
59
  raw = str
57
60
  str = encoding == "q" ? q_decode(enc_text) : b_decode(enc_text)
@@ -63,7 +66,7 @@ module MailParser::RFC2047
63
66
  end
64
67
  end
65
68
  end
66
- [str, charset, raw]
69
+ [str, charset, raw, pre, post]
67
70
  end
68
71
 
69
72
  def q_decode(str)
data/test/test_rfc2047.rb CHANGED
@@ -144,4 +144,14 @@ class TC_RFC2047 < Test::Unit::TestCase
144
144
  assert_equal("hXge", s)
145
145
  end
146
146
 
147
+ def test_decode_with_crlf
148
+ s = MailParser::RFC2047.decode("abc\r\n def\r\n")
149
+ assert_equal "abc def", s
150
+ end
151
+
152
+ def test_decode_with_invalid_encoded
153
+ s = MailParser::RFC2047.decode("abc def=?us-ascii?q?ghi?=jkl mno")
154
+ assert_equal "abc def ghi jkl mno", s
155
+ end
156
+
147
157
  end
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.5.0.beta3
4
+ version: 0.5.0.beta4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-23 00:00:00.000000000 Z
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mmapscanner
@@ -37,26 +37,26 @@ files:
37
37
  - lib/mailparser.rb
38
38
  - lib/mailparser/rfc2183/scanner.rb
39
39
  - lib/mailparser/rfc2183/parser.rb
40
+ - lib/mailparser/conv_charset.rb
41
+ - lib/mailparser/rfc2047.rb
40
42
  - lib/mailparser/error.rb
43
+ - lib/mailparser/rfc2822.rb
41
44
  - lib/mailparser/rfc2045/scanner.rb
42
45
  - lib/mailparser/rfc2045/parser.rb
43
- - lib/mailparser/rfc2047.rb
44
- - lib/mailparser/conv_charset.rb
45
46
  - lib/mailparser/loose.rb
46
47
  - lib/mailparser/rfc2183.rb
47
- - lib/mailparser/rfc2045.rb
48
- - lib/mailparser/rfc2822.rb
49
48
  - lib/mailparser/rfc2822/scanner.rb
50
49
  - lib/mailparser/rfc2822/parser.rb
51
50
  - lib/mailparser/rfc2231.rb
51
+ - lib/mailparser/rfc2045.rb
52
52
  - test.rb
53
+ - test/test_rfc2183.rb
53
54
  - test/test_loose.rb
55
+ - test/test_rfc2045.rb
54
56
  - test/test_rfc2231.rb
55
- - test/test_rfc2183.rb
57
+ - test/test_mailparser.rb
56
58
  - test/test_rfc2047.rb
57
59
  - test/test_rfc2822.rb
58
- - test/test_mailparser.rb
59
- - test/test_rfc2045.rb
60
60
  homepage: http://github.com/tmtm/mailparser
61
61
  licenses:
62
62
  - Ruby's
@@ -84,11 +84,11 @@ specification_version: 3
84
84
  summary: Mail Parser
85
85
  test_files:
86
86
  - test.rb
87
+ - test/test_rfc2183.rb
87
88
  - test/test_loose.rb
89
+ - test/test_rfc2045.rb
88
90
  - test/test_rfc2231.rb
89
- - test/test_rfc2183.rb
91
+ - test/test_mailparser.rb
90
92
  - test/test_rfc2047.rb
91
93
  - test/test_rfc2822.rb
92
- - test/test_mailparser.rb
93
- - test/test_rfc2045.rb
94
94
  has_rdoc: