Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mailcomposer

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mailcomposer - npm Package Compare versions

Comparing version 3.9.0 to 3.10.0

2

Gruntfile.js

@@ -8,3 +8,3 @@ 'use strict';

eslint: {
all: ['lib/*.js', 'test/*.js', 'Gruntfile.js', '.eslintrc.js']
all: ['lib/*.js', 'test/*.js', 'Gruntfile.js']
},

@@ -11,0 +11,0 @@

@@ -31,7 +31,7 @@ 'use strict';

MailComposer.prototype.compile = function () {
this._alternatives = this._getAlternatives();
this._alternatives = this.getAlternatives();
this._htmlNode = this._alternatives.filter(function (alternative) {
return /^text\/html\b/i.test(alternative.contentType);
}).pop();
this._attachments = this._getAttachments(!!this._htmlNode);
this._attachments = this.getAttachments(!!this._htmlNode);

@@ -97,156 +97,2 @@ this._useRelated = !!(this._htmlNode && this._attachments.related.length);

/**
* Builds multipart/mixed node. It should always contain different type of elements on the same level
* eg. text + attachments
*
* @param {Object} parentNode Parent for this note. If it does not exist, a root node is created
* @returns {Object} BuildMail node element
*/
MailComposer.prototype._createMixed = function (parentNode) {
var node;
if (!parentNode) {
node = new BuildMail('multipart/mixed', {
baseBoundary: this.mail.baseBoundary,
textEncoding: this.mail.textEncoding
});
} else {
node = parentNode.createChild('multipart/mixed');
}
if (this._useAlternative) {
this._createAlternative(node);
} else if (this._useRelated) {
this._createRelated(node);
}
[].concat(!this._useAlternative && this._alternatives || []).concat(this._attachments.attached || []).forEach(function (element) {
// if the element is a html node from related subpart then ignore it
if (!this._useRelated || element !== this._htmlNode) {
this._createContentNode(node, element);
}
}.bind(this));
return node;
};
/**
* Builds multipart/alternative node. It should always contain same type of elements on the same level
* eg. text + html view of the same data
*
* @param {Object} parentNode Parent for this note. If it does not exist, a root node is created
* @returns {Object} BuildMail node element
*/
MailComposer.prototype._createAlternative = function (parentNode) {
var node;
if (!parentNode) {
node = new BuildMail('multipart/alternative', {
baseBoundary: this.mail.baseBoundary,
textEncoding: this.mail.textEncoding
});
} else {
node = parentNode.createChild('multipart/alternative');
}
this._alternatives.forEach(function (alternative) {
if (this._useRelated && this._htmlNode === alternative) {
this._createRelated(node);
} else {
this._createContentNode(node, alternative);
}
}.bind(this));
return node;
};
/**
* Builds multipart/related node. It should always contain html node with related attachments
*
* @param {Object} parentNode Parent for this note. If it does not exist, a root node is created
* @returns {Object} BuildMail node element
*/
MailComposer.prototype._createRelated = function (parentNode) {
var node;
if (!parentNode) {
node = new BuildMail('multipart/related; type="text/html"', {
baseBoundary: this.mail.baseBoundary,
textEncoding: this.mail.textEncoding
});
} else {
node = parentNode.createChild('multipart/related; type="text/html"');
}
this._createContentNode(node, this._htmlNode);
this._attachments.related.forEach(function (alternative) {
this._createContentNode(node, alternative);
}.bind(this));
return node;
};
/**
* Creates a regular node with contents
*
* @param {Object} parentNode Parent for this note. If it does not exist, a root node is created
* @param {Object} element Node data
* @returns {Object} BuildMail node element
*/
MailComposer.prototype._createContentNode = function (parentNode, element) {
element = element || {};
element.content = element.content || '';
var node;
var encoding = (element.encoding || 'utf8')
.toString()
.toLowerCase()
.replace(/[-_\s]/g, '');
if (!parentNode) {
node = new BuildMail(element.contentType, {
filename: element.filename,
baseBoundary: this.mail.baseBoundary,
textEncoding: this.mail.textEncoding
});
} else {
node = parentNode.createChild(element.contentType, {
filename: element.filename
});
}
// add custom headers
if (element.headers) {
node.addHeader(element.headers);
}
if (element.cid) {
node.setHeader('Content-Id', '<' + element.cid.replace(/[<>]/g, '') + '>');
}
if (element.contentTransferEncoding) {
node.setHeader('Content-Transfer-Encoding', element.contentTransferEncoding);
} else if (this.mail.encoding && /^text\//i.test(element.contentType)) {
node.setHeader('Content-Transfer-Encoding', this.mail.encoding);
}
if (!/^text\//i.test(element.contentType) || element.contentDisposition) {
node.setHeader('Content-Disposition', element.contentDisposition || 'attachment');
}
if (typeof element.content === 'string' && ['utf8', 'usascii', 'ascii'].indexOf(encoding) < 0) {
element.content = new Buffer(element.content, encoding);
}
// prefer pregenerated raw content
if (element.raw) {
node.setRaw(element.raw);
} else {
node.setContent(element.content);
}
return node;
};
/**
* List all attachments. Resulting attachment objects can be used as input for BuildMail nodes

@@ -257,3 +103,3 @@ *

*/
MailComposer.prototype._getAttachments = function (findRelated) {
MailComposer.prototype.getAttachments = function (findRelated) {
var attachments = [].concat(this.mail.attachments || []).map(function (attachment, i) {

@@ -339,3 +185,3 @@ var data;

*/
MailComposer.prototype._getAlternatives = function () {
MailComposer.prototype.getAlternatives = function () {
var alternatives = [],

@@ -449,2 +295,156 @@ text, html, watchHtml, icalEvent;

/**
* Builds multipart/mixed node. It should always contain different type of elements on the same level
* eg. text + attachments
*
* @param {Object} parentNode Parent for this note. If it does not exist, a root node is created
* @returns {Object} BuildMail node element
*/
MailComposer.prototype._createMixed = function (parentNode) {
var node;
if (!parentNode) {
node = new BuildMail('multipart/mixed', {
baseBoundary: this.mail.baseBoundary,
textEncoding: this.mail.textEncoding
});
} else {
node = parentNode.createChild('multipart/mixed');
}
if (this._useAlternative) {
this._createAlternative(node);
} else if (this._useRelated) {
this._createRelated(node);
}
[].concat(!this._useAlternative && this._alternatives || []).concat(this._attachments.attached || []).forEach(function (element) {
// if the element is a html node from related subpart then ignore it
if (!this._useRelated || element !== this._htmlNode) {
this._createContentNode(node, element);
}
}.bind(this));
return node;
};
/**
* Builds multipart/alternative node. It should always contain same type of elements on the same level
* eg. text + html view of the same data
*
* @param {Object} parentNode Parent for this note. If it does not exist, a root node is created
* @returns {Object} BuildMail node element
*/
MailComposer.prototype._createAlternative = function (parentNode) {
var node;
if (!parentNode) {
node = new BuildMail('multipart/alternative', {
baseBoundary: this.mail.baseBoundary,
textEncoding: this.mail.textEncoding
});
} else {
node = parentNode.createChild('multipart/alternative');
}
this._alternatives.forEach(function (alternative) {
if (this._useRelated && this._htmlNode === alternative) {
this._createRelated(node);
} else {
this._createContentNode(node, alternative);
}
}.bind(this));
return node;
};
/**
* Builds multipart/related node. It should always contain html node with related attachments
*
* @param {Object} parentNode Parent for this note. If it does not exist, a root node is created
* @returns {Object} BuildMail node element
*/
MailComposer.prototype._createRelated = function (parentNode) {
var node;
if (!parentNode) {
node = new BuildMail('multipart/related; type="text/html"', {
baseBoundary: this.mail.baseBoundary,
textEncoding: this.mail.textEncoding
});
} else {
node = parentNode.createChild('multipart/related; type="text/html"');
}
this._createContentNode(node, this._htmlNode);
this._attachments.related.forEach(function (alternative) {
this._createContentNode(node, alternative);
}.bind(this));
return node;
};
/**
* Creates a regular node with contents
*
* @param {Object} parentNode Parent for this note. If it does not exist, a root node is created
* @param {Object} element Node data
* @returns {Object} BuildMail node element
*/
MailComposer.prototype._createContentNode = function (parentNode, element) {
element = element || {};
element.content = element.content || '';
var node;
var encoding = (element.encoding || 'utf8')
.toString()
.toLowerCase()
.replace(/[-_\s]/g, '');
if (!parentNode) {
node = new BuildMail(element.contentType, {
filename: element.filename,
baseBoundary: this.mail.baseBoundary,
textEncoding: this.mail.textEncoding
});
} else {
node = parentNode.createChild(element.contentType, {
filename: element.filename
});
}
// add custom headers
if (element.headers) {
node.addHeader(element.headers);
}
if (element.cid) {
node.setHeader('Content-Id', '<' + element.cid.replace(/[<>]/g, '') + '>');
}
if (element.contentTransferEncoding) {
node.setHeader('Content-Transfer-Encoding', element.contentTransferEncoding);
} else if (this.mail.encoding && /^text\//i.test(element.contentType)) {
node.setHeader('Content-Transfer-Encoding', this.mail.encoding);
}
if (!/^text\//i.test(element.contentType) || element.contentDisposition) {
node.setHeader('Content-Disposition', element.contentDisposition || (element.cid ? 'inline' : 'attachment'));
}
if (typeof element.content === 'string' && ['utf8', 'usascii', 'ascii'].indexOf(encoding) < 0) {
element.content = new Buffer(element.content, encoding);
}
// prefer pregenerated raw content
if (element.raw) {
node.setRaw(element.raw);
} else {
node.setContent(element.content);
}
return node;
};
/**
* Parses data uri and converts it to a Buffer

@@ -451,0 +451,0 @@ *

{
"name": "mailcomposer",
"description": "Compose E-Mail messages",
"version": "3.9.0",
"version": "3.10.0",
"author": "Andris Reinman",

@@ -18,7 +18,7 @@ "license": "MIT",

"scripts": {
"test": "grunt"
"test": "grunt mochaTest"
},
"main": "./lib/mailcomposer",
"dependencies": {
"buildmail": "3.7.0",
"buildmail": "3.8.0",
"libmime": "2.0.3"

@@ -30,5 +30,5 @@ },

"grunt-cli": "^1.2.0",
"grunt-eslint": "^18.1.0",
"grunt-eslint": "^19.0.0",
"grunt-mocha-test": "^0.12.7",
"mocha": "^2.4.5",
"mocha": "^2.5.3",
"sinon": "^1.17.4"

@@ -35,0 +35,0 @@ },

@@ -93,3 +93,3 @@ # mailcomposer

* **filename** - filename to be reported as the name of the attached file, use of unicode is allowed. If you do not want to use a filename, set this value as `false`, otherwise a filename is generated automatically
* **cid** - optional content id for using inline images in HTML message source
* **cid** - optional content id for using inline images in HTML message source. Using `cid` sets the default `contentDisposition` to `'inline'` and moves the attachment into a *multipart/related* mime node, so use it only if you actually want to use this attachment as an embedded image
* **content** - String, Buffer or a Stream contents for the attachment

@@ -96,0 +96,0 @@ * **encoding** - If set and `content` is string, then encodes the content to a Buffer using the specified encoding. Example values: `base64`, `hex`, `binary` etc. Useful if you want to use binary attachments in a JSON formatted e-mail object

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