Comparing version 3.0.3 to 3.0.4
@@ -73,3 +73,3 @@ 'use strict'; | ||
return this.processLine(chunk.slice(start, i), false, data => { | ||
return this.processLine(chunk.slice(start, i), false, (data, flush) => { | ||
if (!data) { | ||
@@ -79,2 +79,30 @@ return iterateData(); | ||
if (flush) { | ||
if (group && group.type !== 'none') { | ||
if (group.type === 'body' && groupend >= groupstart && group.node.parentNode) { | ||
// do not include the last line ending for body | ||
if (chunk[groupend - 1] === 0x0A) { | ||
groupend--; | ||
if (groupend >= groupstart && chunk[groupend - 1] === 0x0D) { | ||
groupend--; | ||
} | ||
} | ||
} | ||
if (groupstart !== groupend) { | ||
group.value = chunk.slice(groupstart, groupend); | ||
if (groupend < i) { | ||
data.value = chunk.slice(groupend, i); | ||
} | ||
} | ||
this.push(group); | ||
group = { | ||
type: 'none' | ||
}; | ||
groupstart = groupend = i; | ||
} | ||
this.push(data); | ||
groupend = i; | ||
return setImmediate(iterateData); | ||
} | ||
if (data.type === group.type) { | ||
@@ -100,2 +128,5 @@ // shift slice end position forward | ||
this.push(group); | ||
group = { | ||
type: 'none' | ||
}; | ||
} | ||
@@ -123,3 +154,2 @@ } | ||
} | ||
return setImmediate(iterateData); | ||
@@ -143,8 +173,9 @@ }); | ||
// we have a leftover data/body chunk to push out | ||
if (group.node === this.node || this.node.headers) { | ||
group.value = chunk.slice(groupstart, pos); | ||
} | ||
group.value = chunk.slice(groupstart, pos); | ||
if (group.value && group.value.length) { | ||
this.push(group); | ||
group = { | ||
type: 'none' | ||
}; | ||
} | ||
@@ -246,2 +277,4 @@ } | ||
processLine(line, final, next) { | ||
let flush = false; | ||
if (this.line && line) { | ||
@@ -282,3 +315,3 @@ line = Buffer.concat([this.line, line]); | ||
return next(currentNode); | ||
return next(currentNode, flush); | ||
} | ||
@@ -298,3 +331,3 @@ | ||
value: line | ||
}); | ||
}, flush); | ||
} else { | ||
@@ -305,3 +338,3 @@ next({ | ||
value: line | ||
}); | ||
}, flush); | ||
} | ||
@@ -317,2 +350,3 @@ return; | ||
this.state = HEAD; | ||
flush = true; | ||
break; | ||
@@ -333,2 +367,3 @@ case 2: | ||
this.state = HEAD; | ||
flush = true; | ||
break; | ||
@@ -347,3 +382,3 @@ } | ||
value: line | ||
}); | ||
}, flush); | ||
} | ||
@@ -350,0 +385,0 @@ } |
{ | ||
"name": "mailsplit", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Split email messages into an object stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
41596
828