front-mailparser
Advanced tools
Comparing version 0.6.1-1 to 0.6.1-2
@@ -207,3 +207,6 @@ "use strict"; | ||
if (this._remainder.length > 1048576) { | ||
this._remainder = this._remainder.replace(/(.{1048576}(?!\r?\n|\r))/g, "$&\n"); | ||
if (this.options.fastChunking) | ||
this._remainder = force1MbLines(this._remainder); | ||
else | ||
this._remainder = this._remainder.replace(/(.{1048576}(?!\r?\n|\r))/g, "$&\n"); | ||
} | ||
@@ -261,2 +264,46 @@ } | ||
function force1MbLines(str) { | ||
const oneMb = 1048576; | ||
// this used to be: str.replace(/(.{1048576}(?!\r?\n|\r))/g, "$&\n"); | ||
// but regexp performance is terrible with such long strings | ||
// the regexp uses "x(?!y)" which means "x not followed by y" | ||
if (str.length < oneMb) | ||
return str; | ||
let current = str; | ||
const chunks = []; | ||
// force line-breaks every 1Mb | ||
// however, we must check if there's not already a line-break immediately afterwards | ||
// it could cause the message to be partially imported | ||
while (current.length >= oneMb) { | ||
let chunk = str.substring(0, oneMb); | ||
const rest = str.substring(oneMb); | ||
if (rest.substring(0, 2) === '\r\n') { | ||
// rest is \r\n... | ||
chunk = chunk + '\r\n'; | ||
rest = rest.substring(2); | ||
} else if (rest[0] === '\n') { | ||
// rest is \n... | ||
chunk = chunk + '\n'; | ||
rest = rest.substring(1); | ||
} else if (rest[0] === '\r') { | ||
// rest is \r... | ||
chunk = chunk + '\r'; | ||
rest = rest.substring(1); | ||
} else { | ||
// otherwise, force a line-break | ||
chunk = chunk + '\n'; | ||
} | ||
current = rest; | ||
chunks.push(chunk); | ||
} | ||
return chunks.join(''); | ||
} | ||
/** | ||
@@ -263,0 +310,0 @@ * <p>Processes a line while in header state</p> |
{ | ||
"name": "front-mailparser", | ||
"description": "Asynchronous and non-blocking parser for mime encoded e-mail messages", | ||
"version": "0.6.1-1", | ||
"version": "0.6.1-2", | ||
"author": "Andris Reinman", | ||
@@ -6,0 +6,0 @@ "maintainers": [{ |
146483
3340
10