mailcvt 0.2.29 → 0.2.30
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/encoded_word.rb +34 -10
- data/lib/mailcvt/version.rb +1 -1
- metadata +1 -1
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(
|
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
|
-
|
98
|
-
|
99
|
-
|
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")
|
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
|
-
|
155
|
+
words = []
|
147
156
|
parts.each do |p|
|
148
|
-
|
157
|
+
wd = word_decode(p)
|
158
|
+
words << wd
|
149
159
|
end
|
150
|
-
|
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
|
data/lib/mailcvt/version.rb
CHANGED