fix parsing when root node is message/rfc822

This commit is contained in:
Andris Reinman 2017-05-24 11:48:27 +03:00
parent 963965c86c
commit 31fe3c7442
2 changed files with 15 additions and 1 deletions

View file

@ -38,7 +38,7 @@ class BodyStructure {
case 'text':
return this.processTextNode(node, options);
case 'message':
if (node.parsedHeader['content-type'].subtype === 'rfc822' && !/attachment/i.test(node.parsedHeader['content-disposition'])) {
if (node.parsedHeader['content-type'].subtype === 'rfc822') {
if (!options.attachmentRFC822) {
return this.processRFC822Node(node, options);
}

View file

@ -107,8 +107,22 @@ class MIMEParser {
* from the tree (circular references prohibit conversion to JSON)
*/
finalizeTree() {
if (this._node.state === 'header') {
this.processNodeHeader();
this.processContentType();
}
if (this.tree.parsedHeader && this.tree.parsedHeader['content-type'].value === 'message/rfc822') {
this.tree.message = parse(this.tree.body.join(''));
}
let walker = node => {
if (node.body) {
if (node.parentNode === this.tree && node.parsedHeader['content-type'].value === 'message/rfc822') {
node.message = parse(node.body.join(''));
}
node.lineCount = node.body.length;
node.body = Buffer.from(
node.body.join('').