Comparing version 1.0.129 to 1.0.130
115
lib/tools.js
@@ -427,2 +427,89 @@ /* eslint no-control-regex:0 */ | ||
getStructuredParams(arr) { | ||
let key; | ||
let params = {}; | ||
[].concat(arr || []).forEach((val, j) => { | ||
if (j % 2) { | ||
params[key] = libmime.decodeWords(((val && val.value) || '').toString()); | ||
} else { | ||
key = ((val && val.value) || '').toString().toLowerCase(); | ||
} | ||
}); | ||
// preprocess values | ||
Object.keys(params).forEach(key => { | ||
let actualKey; | ||
let nr; | ||
let value; | ||
let match = key.match(/\*((\d+)\*?)?$/); | ||
if (!match) { | ||
// nothing to do here, does not seem like a continuation param | ||
return; | ||
} | ||
actualKey = key.substr(0, match.index).toLowerCase(); | ||
nr = Number(match[2]) || 0; | ||
if (!params[actualKey] || typeof params[actualKey] !== 'object') { | ||
params[actualKey] = { | ||
charset: false, | ||
values: [] | ||
}; | ||
} | ||
value = params[key]; | ||
if (nr === 0 && match[0].charAt(match[0].length - 1) === '*' && (match = value.match(/^([^']*)'[^']*'(.*)$/))) { | ||
params[actualKey].charset = match[1] || 'utf-8'; | ||
value = match[2]; | ||
} | ||
params[actualKey].values.push({ nr, value }); | ||
// remove the old reference | ||
delete params[key]; | ||
}); | ||
// concatenate split rfc2231 strings and convert encoded strings to mime encoded words | ||
Object.keys(params).forEach(key => { | ||
let value; | ||
if (params[key] && Array.isArray(params[key].values)) { | ||
value = params[key].values | ||
.sort((a, b) => a.nr - b.nr) | ||
.map(val => (val && val.value) || '') | ||
.join(''); | ||
if (params[key].charset) { | ||
// convert "%AB" to "=?charset?Q?=AB?=" and then to unicode | ||
params[key] = libmime.decodeWords( | ||
'=?' + | ||
params[key].charset + | ||
'?Q?' + | ||
value | ||
// fix invalidly encoded chars | ||
.replace(/[=?_\s]/g, s => { | ||
let c = s.charCodeAt(0).toString(16); | ||
if (s === ' ') { | ||
return '_'; | ||
} else { | ||
return '%' + (c.length < 2 ? '0' : '') + c; | ||
} | ||
}) | ||
// change from urlencoding to percent encoding | ||
.replace(/%/g, '=') + | ||
'?=' | ||
); | ||
} else { | ||
params[key] = libmime.decodeWords(value); | ||
} | ||
} | ||
}); | ||
return params; | ||
}, | ||
parseBodystructure(entry) { | ||
@@ -434,3 +521,2 @@ let walk = (node, path) => { | ||
i = 0, | ||
key, | ||
part = 0; | ||
@@ -458,10 +544,3 @@ | ||
if (node[i]) { | ||
curNode.parameters = {}; | ||
[].concat(node[i] || []).forEach((val, j) => { | ||
if (j % 2) { | ||
curNode.parameters[key] = libmime.decodeWords(((val && val.value) || '').toString()); | ||
} else { | ||
key = ((val && val.value) || '').toString().toLowerCase(); | ||
} | ||
}); | ||
curNode.parameters = this.getStructuredParams(node[i]); | ||
} | ||
@@ -476,10 +555,3 @@ i++; | ||
if (node[i]) { | ||
curNode.parameters = {}; | ||
[].concat(node[i] || []).forEach((val, j) => { | ||
if (j % 2) { | ||
curNode.parameters[key] = libmime.decodeWords(((val && val.value) || '').toString()); | ||
} else { | ||
key = ((val && val.value) || '').toString().toLowerCase(); | ||
} | ||
}); | ||
curNode.parameters = this.getStructuredParams(node[i]); | ||
} | ||
@@ -565,10 +637,3 @@ i++; | ||
if (Array.isArray(node[i][1])) { | ||
curNode.dispositionParameters = {}; | ||
[].concat(node[i][1] || []).forEach((val, j) => { | ||
if (j % 2) { | ||
curNode.dispositionParameters[key] = libmime.decodeWords(((val && val.value) || '').toString()); | ||
} else { | ||
key = ((val && val.value) || '').toString().toLowerCase(); | ||
} | ||
}); | ||
curNode.dispositionParameters = this.getStructuredParams(node[i][1]); | ||
} | ||
@@ -575,0 +640,0 @@ } |
{ | ||
"name": "imapflow", | ||
"version": "1.0.129", | ||
"version": "1.0.130", | ||
"description": "IMAP Client for Node", | ||
@@ -34,3 +34,3 @@ "main": "./lib/imap-flow.js", | ||
"@babel/preset-env": "7.22.5", | ||
"@types/node": "20.3.0", | ||
"@types/node": "20.3.1", | ||
"braintree-jsdoc-template": "3.3.0", | ||
@@ -37,0 +37,0 @@ "eslint": "8.42.0", |
553511
12316