New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mailsplit

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mailsplit - npm Package Compare versions

Comparing version 4.2.0 to 4.2.1

118

lib/message-splitter.js

@@ -6,2 +6,5 @@ 'use strict';

const MAX_HEAD_SIZE = 1 * 1024 * 1024;
const MAX_CHILD_NODES = 1000;
const HEAD = 0x01;

@@ -19,4 +22,4 @@ const BODY = 0x02;

this.config = config || {};
this.maxHeadSize = this.config.maxHeadSize || Infinity;
this.maxChildNodes = 1000;
this.maxHeadSize = this.config.maxHeadSize || MAX_HEAD_SIZE;
this.maxChildNodes = this.config.maxChildNodes || MAX_CHILD_NODES;
this.tree = [];

@@ -302,2 +305,53 @@ this.nodeCounter = 0;

if (this.nodeCounter > this.maxChildNodes) {
let err = new Error('Max allowed child nodes exceeded');
err.code = 'EMAXLEN';
return next(err);
}
// we check boundary outside the HEAD/BODY scope as it may appear anywhere
let boundary = this.checkBoundary(line);
if (boundary) {
// reached boundary, switch context
switch (boundary) {
case 1:
// next child
this.newNode(this.node);
flush = true;
break;
case 2:
// reached end of children, keep current node
break;
case 3: {
// next sibling
let parentNode = this.node.parentNode;
if (parentNode && parentNode.contentType === 'message/rfc822') {
// special case where immediate parent is an inline message block
// move up another step
parentNode = parentNode.parentNode;
}
this.newNode(parentNode);
flush = true;
break;
}
case 4:
// move up
if (this.tree.length) {
this.node = this.tree.pop();
}
this.state = BODY;
break;
}
return next(
null,
{
node: this.node,
type: 'data',
value: line
},
flush
);
}
switch (this.state) {

@@ -344,60 +398,2 @@ case HEAD: {

case BODY: {
let boundary = this.checkBoundary(line);
if (!boundary) {
// not a boundary line
if (this.node.multipart) {
next(
null,
{
node: this.node,
type: 'data',
value: line
},
flush
);
} else {
next(
null,
{
node: this.node,
type: 'body',
value: line
},
flush
);
}
return;
}
// reached boundary. switch context
switch (boundary) {
case 1:
// next child
this.newNode(this.node);
flush = true;
break;
case 2:
// reached end of children, keep current node
break;
case 3: {
// next sibling
let parentNode = this.node.parentNode;
if (parentNode && parentNode.contentType === 'message/rfc822') {
// special case where immediate parent is an inline message block
// move up another step
parentNode = parentNode.parentNode;
}
this.newNode(parentNode);
flush = true;
break;
}
case 4:
// move up
if (this.tree.length) {
this.node = this.tree.pop();
}
this.state = BODY;
break;
}
return next(

@@ -407,3 +403,3 @@ null,

node: this.node,
type: 'data',
type: this.node.multipart ? 'data' : 'body',
value: line

@@ -410,0 +406,0 @@ },

{
"name": "mailsplit",
"version": "4.2.0",
"version": "4.2.1",
"description": "Split email messages into an object stream",

@@ -13,3 +13,3 @@ "main": "index.js",

"author": "Andris Reinman",
"license": "EUPL-1.1",
"license": "EUPL-1.1+",
"dependencies": {

@@ -25,6 +25,9 @@ "libmime": "4.0.0",

"grunt-contrib-nodeunit": "^2.0.0",
"grunt-eslint": "^20.2.0",
"grunt-eslint": "^21.0.0",
"random-message": "^1.1.0"
},
"files": ["lib", "index.js"]
"files": [
"lib",
"index.js"
]
}

@@ -32,5 +32,5 @@ # mailsplit

* **options** is an optional options object
* **options.ignoreEmbedded** (boolean, defaults to false) if true then treat message/rfc822 node as normal leaf node and do not try to parse it
* **options.maxHeadSize** (number, defaults to Infinity) limits message header size in bytes
- **options** is an optional options object
- **options.ignoreEmbedded** (boolean, defaults to false) if true then treat message/rfc822 node as normal leaf node and do not try to parse it
- **options.maxHeadSize** (number, defaults to Infinity) limits message header size in bytes

@@ -43,9 +43,9 @@ #### Events

* **type**
* `'node'` means that we reached the next mime node and the previous one is completely processed
* `'data'` provides us multipart body parts, including boundaries. This data is not directly related to any specific multipart node, basically it includes everything between the end of one normal node and the header of next node
* `'body'` provides us next chunk for the last seen `'node'` element
* **value** is a buffer value for `'body'` and `'data'` parts
* **getDecoder()** is a function that returns a stream object you can use to decode node contents. Write data from 'body' to decoder and read decoded Buffer value out from it
* **getEncoder()** is a function that returns a stream object you can use to encode node contents. Write buffer data to encoder and read encoded object value out that you can pass to a Joiner
- **type**
- `'node'` means that we reached the next mime node and the previous one is completely processed
- `'data'` provides us multipart body parts, including boundaries. This data is not directly related to any specific multipart node, basically it includes everything between the end of one normal node and the header of next node
- `'body'` provides us next chunk for the last seen `'node'` element
- **value** is a buffer value for `'body'` and `'data'` parts
- **getDecoder()** is a function that returns a stream object you can use to decode node contents. Write data from 'body' to decoder and read decoded Buffer value out from it
- **getEncoder()** is a function that returns a stream object you can use to encode node contents. Write buffer data to encoder and read encoded object value out that you can pass to a Joiner

@@ -87,26 +87,26 @@ Element with type `'node'` has a bunch of header related methods and properties, see [below](#manipulating-headers).

* **node.getHeaders()** returns a Buffer value with generated headers. If you have not modified the headers object in any way then you should get the exact copy of the original. In case you have done something (for example removed a key, or added a new header key), then all linebreaks are forced to <CR><LF> even if the original headers used just <LF>
* **node.setContentType(contentType)** sets or updates mime type for the node
* **node.setCharset(charset)** sets or updates character set in the Content-Type header
* **node.setFilename(filename)** sets or updates filename in the Content-Disposition header (unicode allowed)
- **node.getHeaders()** returns a Buffer value with generated headers. If you have not modified the headers object in any way then you should get the exact copy of the original. In case you have done something (for example removed a key, or added a new header key), then all linebreaks are forced to <CR><LF> even if the original headers used just <LF>
- **node.setContentType(contentType)** sets or updates mime type for the node
- **node.setCharset(charset)** sets or updates character set in the Content-Type header
- **node.setFilename(filename)** sets or updates filename in the Content-Disposition header (unicode allowed)
You can manipulate specific header keys as well using the `headers` object
* **node.headers.get(key)** returns an array of strings with all header rows for the selected key (these are full header lines, so key name is part of the row string, eg `["Subject: This is subject line"]`)
* **node.headers.getFirst(key)** returns string value of the specified header key (eg `"This is subject line"`)
* **node.headers.add(key, value [,index])** adds a new header value to the specified index or to the top of the header block if index is not specified
* **node.headers.update(key, value)** replaces a header value for the specified key
* **node.headers.delete(key)** remove header value
* **node.headers.mbox** If this is a MBOX formatted message then this value holds the prefix line (eg. "From MAILER-DAEMON Fri Jul 8 12:08:34 2011")
* **node.headers.mbox** If this is a POST form-data then this value holds the HTTP prefix line (eg. "POST /upload.php HTTP/1.1")
- **node.headers.get(key)** returns an array of strings with all header rows for the selected key (these are full header lines, so key name is part of the row string, eg `["Subject: This is subject line"]`)
- **node.headers.getFirst(key)** returns string value of the specified header key (eg `"This is subject line"`)
- **node.headers.add(key, value [,index])** adds a new header value to the specified index or to the top of the header block if index is not specified
- **node.headers.update(key, value)** replaces a header value for the specified key
- **node.headers.delete(key)** remove header value
- **node.headers.mbox** If this is a MBOX formatted message then this value holds the prefix line (eg. "From MAILER-DAEMON Fri Jul 8 12:08:34 2011")
- **node.headers.mbox** If this is a POST form-data then this value holds the HTTP prefix line (eg. "POST /upload.php HTTP/1.1")
Additionally you can check the details of the node with the following properties automatically parsed from the headers:
* **node.root** if true then it means this is the message root, so this node should contain Subject, From, To etc. headers
* **node.contentType** returns the mime type of the node (eg. 'text/html')
* **node.disposition** either `'attachment'`, `'inline'` or `false` if not set
* **node.charset** returns the charset of the node as defined in 'Content-Type' header (eg. 'UTF-8') or false if not defined
* **node.encoding** returns the Transfer-Encoding value (eg. 'base64' or 'quoted-printable') or false if not defined
* **node.multipart** if has value, then this is a multipart node (does not have 'body' parts)
* **node.filename** is set if the headers contain a filename value. This is decoded to unicode, so it is a normal string or false if not found
- **node.root** if true then it means this is the message root, so this node should contain Subject, From, To etc. headers
- **node.contentType** returns the mime type of the node (eg. 'text/html')
- **node.disposition** either `'attachment'`, `'inline'` or `false` if not set
- **node.charset** returns the charset of the node as defined in 'Content-Type' header (eg. 'UTF-8') or false if not defined
- **node.encoding** returns the Transfer-Encoding value (eg. 'base64' or 'quoted-printable') or false if not defined
- **node.multipart** if has value, then this is a multipart node (does not have 'body' parts)
- **node.filename** is set if the headers contain a filename value. This is decoded to unicode, so it is a normal string or false if not found

@@ -135,10 +135,10 @@ ### Join parsed message stream

* **filterFunc** gets the current node as argument and starts processing it if `filterFunc` returns true
- **filterFunc** gets the current node as argument and starts processing it if `filterFunc` returns true
Once Rewriter finds a matching node, it emits the following event:
* _'node'_ with an object argument `data`
* `data.node` includes the current node with headers
* `data.decoder` is the decoder stream that you can read data from
* `data.encoder` is the encoder stream that you can write data to. Whatever you write into that stream will be encoded properly and inserted as the content of the current node
- _'node'_ with an object argument `data`
- `data.node` includes the current node with headers
- `data.decoder` is the decoder stream that you can read data from
- `data.encoder` is the encoder stream that you can write data to. Whatever you write into that stream will be encoded properly and inserted as the content of the current node

@@ -172,10 +172,10 @@ ```javascript

* **filterFunc** gets the current node as argument and starts processing it if `filterFunc` returns true
- **filterFunc** gets the current node as argument and starts processing it if `filterFunc` returns true
Once Streamer finds a matching node, it emits the following event:
* _'node'_ with an object argument `data`
* `data.node` includes the current node with headers (informational only, you can't modify it)
* `data.decoder` is the decoder stream that you can read data from
* `data.done` is a function you must call once you have processed the stream
- _'node'_ with an object argument `data`
- `data.node` includes the current node with headers (informational only, you can't modify it)
- `data.decoder` is the decoder stream that you can read data from
- `data.done` is a function you must call once you have processed the stream

@@ -216,2 +216,2 @@ ```javascript

**EUPLv1.1**
**EUPLv1.1+**
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc