|
|
|
@ -3,7 +3,8 @@ var EventEmitter = require('events').EventEmitter,
|
|
|
|
|
inherits = require('util').inherits,
|
|
|
|
|
inspect = require('util').inspect,
|
|
|
|
|
utf7 = require('utf7').imap,
|
|
|
|
|
iconv = require('iconv-lite');
|
|
|
|
|
iconv = require('iconv-lite'),
|
|
|
|
|
jsencoding/*lazy-loaded*/;
|
|
|
|
|
|
|
|
|
|
var CH_LF = 10,
|
|
|
|
|
LITPLACEHOLDER = String.fromCharCode(0),
|
|
|
|
@ -674,13 +675,26 @@ function convStr(str, literals) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function decodeBytes(buf, encoding) {
|
|
|
|
|
if (iconv.encodingExists(encoding))
|
|
|
|
|
return iconv.decode(buf, encoding);
|
|
|
|
|
else {
|
|
|
|
|
if (!jsencoding)
|
|
|
|
|
jsencoding = require('../deps/encoding/encoding');
|
|
|
|
|
if (jsencoding.encodingExists(encoding))
|
|
|
|
|
return jsencoding.TextDecoder(encoding).decode(buf);
|
|
|
|
|
else
|
|
|
|
|
return buf.toString('binary');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function decodeWords(str) {
|
|
|
|
|
return str.replace(RE_ENCWORD,
|
|
|
|
|
function(match, charset, encoding, word) {
|
|
|
|
|
encoding = encoding.toLowerCase();
|
|
|
|
|
if (encoding === 'q') {
|
|
|
|
|
// q-encoding, similar to quoted-printable
|
|
|
|
|
return iconv.decode(new Buffer(word.replace(RE_QENC,
|
|
|
|
|
return decodeBytes(new Buffer(word.replace(RE_QENC,
|
|
|
|
|
function(match2, byte) {
|
|
|
|
|
if (match2 === '_')
|
|
|
|
|
return ' ';
|
|
|
|
@ -690,7 +704,7 @@ function decodeWords(str) {
|
|
|
|
|
), 'binary'), charset);
|
|
|
|
|
} else {
|
|
|
|
|
// base64
|
|
|
|
|
return iconv.decode(new Buffer(word, 'base64'), charset);
|
|
|
|
|
return decodeBytes(new Buffer(word, 'base64'), charset);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|