mailcvt 0.2.30 → 0.2.31
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/encoded_word.rb +2 -22
- data/lib/mailcvt/version.rb +1 -1
- metadata +1 -1
data/lib/encoded_word.rb
CHANGED
@@ -162,31 +162,11 @@ class EncodedWord
|
|
162
162
|
|
163
163
|
def word_decode(input, out_charset = 'utf-8')
|
164
164
|
u8 = input.encode('utf-8', @u8_enc, :undef=>:replace, :invalid=>:replace)
|
165
|
-
|
166
|
-
return input unless
|
167
|
-
pos2 = u8.index('?=', pos1+1)
|
168
|
-
trim = u8[pos1..pos2+1]
|
169
|
-
parts = trim.scan(/=\?([A-Za-z0-9_-]+)\?([BQbq])\?([^\?]+)\?=/).first
|
165
|
+
parts = u8.scan(/=\?([A-Za-z0-9_-]+)\?([BQbq])\?([^\?]+)\?=/).first
|
166
|
+
return input unless parts and parts.length == 3
|
170
167
|
charset = parts[0]
|
171
168
|
enc = parts[1].upcase
|
172
169
|
wd = parts[2].unpack({ "B"=>"m*", "Q"=>"M*" }[enc]).first
|
173
170
|
wd.encode(out_charset, charset, :undef=>:replace, :invalid=>:replace)
|
174
171
|
end
|
175
|
-
|
176
|
-
def mime_decode(input, out_charset = 'utf-8')
|
177
|
-
return '' unless input and input.length > 0
|
178
|
-
begin
|
179
|
-
ret = input.sub!(/=\?([A-Za-z0-9_-]+)\?([BQbq])\?([^\?]+)\?=/) {
|
180
|
-
charset = $1
|
181
|
-
enc = $2.upcase
|
182
|
-
word = $3
|
183
|
-
word = word.unpack({ "B"=>"m*", "Q"=>"M*" }[enc]).first
|
184
|
-
word.encode(out_charset, charset, :undef=>:replace, :invalid=>:replace)
|
185
|
-
}
|
186
|
-
return ret ? mime_decode(input) : input
|
187
|
-
rescue => e
|
188
|
-
puts e
|
189
|
-
return input
|
190
|
-
end
|
191
|
-
end
|
192
172
|
end
|
data/lib/mailcvt/version.rb
CHANGED