diff --git a/imap-core/lib/imap-tools.js b/imap-core/lib/imap-tools.js index 3cb9d2db..aac8bdde 100644 --- a/imap-core/lib/imap-tools.js +++ b/imap-core/lib/imap-tools.js @@ -338,7 +338,7 @@ module.exports.filterFolders = function(folders, query) { // setup * .replace(/[*]/g, '.*') // setup % - .replace(/[%]/g, '[^\/]*'); + .replace(/[%]/g, '[^/]*'); let regex = new RegExp('^' + query + '$', ''); @@ -374,13 +374,13 @@ module.exports.getMessageRange = function(uidList, range, isUid) { return false; }; - for ((i = 0), (len = uidList.length); i < len; i++) { + for (i = 0, len = uidList.length; i < len; i++) { if (uidList[i] > maxUid) { maxUid = uidList[i]; } } - for ((i = 0), (len = uidList.length); i < len; i++) { + for (i = 0, len = uidList.length; i < len; i++) { uid = uidList[i] || 1; if (inRange(isUid ? uid : i + 1, rangeParts, isUid ? maxUid : totalMessages)) { result.push(uidList[i]); @@ -592,7 +592,11 @@ module.exports.getQueryResponse = function(query, message, options) { if (!Buffer.isBuffer(val) && val.buffer) { val = val.buffer; } - addr[3] = punycode.toASCII(val.toString()); + try { + addr[3] = punycode.toASCII(val.toString()); + } catch (E) { + addr[3] = val.toString(); + } } }); } diff --git a/imap-core/lib/indexer/create-envelope.js b/imap-core/lib/indexer/create-envelope.js index 69d8fa50..1979003f 100644 --- a/imap-core/lib/indexer/create-envelope.js +++ b/imap-core/lib/indexer/create-envelope.js @@ -74,7 +74,11 @@ function processAddress(arr, defaults) { } if (domain) { - domain = Buffer.from(punycode.toUnicode(domain)); + try { + domain = Buffer.from(punycode.toUnicode(domain)); + } catch (E) { + domain = Buffer.from(domain); + } } result.push([name, null, user, domain]); diff --git a/imap-core/lib/indexer/indexer.js b/imap-core/lib/indexer/indexer.js index 79eca74b..54d0e1b8 100644 --- a/imap-core/lib/indexer/indexer.js +++ b/imap-core/lib/indexer/indexer.js @@ -343,7 +343,12 @@ class Indexer { if (contentType === 'text/html') { htmlContent.push(content.trim()); if (!alternative) { - textContent.push(htmlToText.fromString(content).trim()); + try { + let text = htmlToText.fromString(content); + textContent.push(text.trim()); + } catch (E) { + // ignore + } } } else { textContent.push(content.trim()); diff --git a/lib/maildrop.js b/lib/maildrop.js index 0c2cde4a..136ac98e 100644 --- a/lib/maildrop.js +++ b/lib/maildrop.js @@ -49,7 +49,13 @@ function parseAddressses(headerList, withNames) { } function normalizeDomain(domain) { - return punycode.toASCII(domain.toLowerCase().trim()); + domain = domain.toLowerCase().trim(); + try { + domain = punycode.toASCII(domain); + } catch (E) { + // ignore + } + return domain; } // helper function to flatten arrays diff --git a/lib/tools.js b/lib/tools.js index 6cc3d544..bb8720e1 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -13,7 +13,14 @@ function normalizeAddress(address, withNames) { } let user = address.address.substr(0, address.address.lastIndexOf('@')).normalize('NFC').toLowerCase().trim(); let domain = address.address.substr(address.address.lastIndexOf('@') + 1).toLowerCase().trim(); - let addr = user + '@' + punycode.toUnicode(domain); + let encodedDomain = domain; + try { + encodedDomain = punycode.toUnicode(domain); + } catch (E) { + // ignore + } + + let addr = user + '@' + encodedDomain; if (withNames) { return { diff --git a/package.json b/package.json index 04919731..a5b24427 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wildduck", - "version": "1.0.46", + "version": "1.0.47", "description": "IMAP server built with Node.js and MongoDB", "main": "server.js", "scripts": { @@ -27,7 +27,7 @@ "html-to-text": "^3.3.0", "iconv-lite": "^0.4.17", "joi": "^10.5.2", - "libbase64": "^0.1.0", + "libbase64": "^0.2.0", "libmime": "^3.1.0", "libqp": "^1.1.0", "mailsplit": "^4.0.2",