mailcvt 0.2.29 → 0.2.30

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/lib/encoded_word.rb CHANGED
@@ -63,6 +63,12 @@ class EncodedWord
63
63
  end
64
64
  end
65
65
 
66
+ def concat_one_line(words)
67
+ line = words.join('')
68
+ parts = mysplit(line, "\n")
69
+ parts.join('')
70
+ end
71
+
66
72
  def mysplit(line, sep = "\t")
67
73
  return [] unless line
68
74
  return [] unless line.length > 0
@@ -72,7 +78,7 @@ class EncodedWord
72
78
  pos1 = -1
73
79
  while true do
74
80
  pos1 += 1
75
- pos2 = line.index("\t", pos1)
81
+ pos2 = line.index(sep, pos1)
76
82
  if pos2
77
83
  parts << line[pos1...pos2]
78
84
  pos1 = pos2
@@ -94,9 +100,13 @@ class EncodedWord
94
100
 
95
101
  def decode_subject(sub)
96
102
  return '' unless sub and sub.length > 0
97
- sub = sub.encode('utf-8', @input_enc, :undef=>:replace, :invalid=>:replace)
98
- one = sub.gsub("\a", '')
99
- plain = mime_decode(one).gsub("\n", '')
103
+ parts = mysplit(sub, "\a")
104
+ words = []
105
+ parts.each do |p|
106
+ wd = word_decode(p)
107
+ words << wd
108
+ end
109
+ concat_one_line(words)
100
110
  end
101
111
 
102
112
  def trim_emails(emails)
@@ -136,18 +146,31 @@ class EncodedWord
136
146
  attaches << decode_attach(parts[i])
137
147
  end
138
148
  return '' unless attaches.length > 0
139
- attaches.join("\a").gsub("\n", '')
149
+ attaches.join("\a")
140
150
  end
141
151
 
142
152
  def decode_attach(attach)
143
153
  return '' unless attach and attach.length > 0
144
- attach = attach.encode('utf-8', @input_enc, :undef=>:replace, :invalid=>:replace)
145
154
  parts = mysplit(attach, "\a")
146
- newparts = []
155
+ words = []
147
156
  parts.each do |p|
148
- newparts << mime_decode(p)
157
+ wd = word_decode(p)
158
+ words << wd
149
159
  end
150
- newparts.join('')
160
+ concat_one_line(words)
161
+ end
162
+
163
+ def word_decode(input, out_charset = 'utf-8')
164
+ u8 = input.encode('utf-8', @u8_enc, :undef=>:replace, :invalid=>:replace)
165
+ pos1 = u8.index('=?')
166
+ return input unless pos1
167
+ pos2 = u8.index('?=', pos1+1)
168
+ trim = u8[pos1..pos2+1]
169
+ parts = trim.scan(/=\?([A-Za-z0-9_-]+)\?([BQbq])\?([^\?]+)\?=/).first
170
+ charset = parts[0]
171
+ enc = parts[1].upcase
172
+ wd = parts[2].unpack({ "B"=>"m*", "Q"=>"M*" }[enc]).first
173
+ wd.encode(out_charset, charset, :undef=>:replace, :invalid=>:replace)
151
174
  end
152
175
 
153
176
  def mime_decode(input, out_charset = 'utf-8')
@@ -161,7 +184,8 @@ class EncodedWord
161
184
  word.encode(out_charset, charset, :undef=>:replace, :invalid=>:replace)
162
185
  }
163
186
  return ret ? mime_decode(input) : input
164
- rescue
187
+ rescue => e
188
+ puts e
165
189
  return input
166
190
  end
167
191
  end
@@ -1,3 +1,3 @@
1
1
  module Mailcvt
2
- VERSION = '0.2.29'
2
+ VERSION = '0.2.30'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailcvt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.29
4
+ version: 0.2.30
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: