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

nodemailer-openpgp

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodemailer-openpgp - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

.github/FUNDING.yml

127

lib/nodemailer-openpgp.js

@@ -39,77 +39,70 @@ 'use strict';

_flush(done) {
//var signature = dkimSign(this._message, this.options);
let message = Buffer.concat(this._messageChunks, this._messageLength);
(async () => {
//var signature = dkimSign(this._message, this.options);
let message = Buffer.concat(this._messageChunks, this._messageLength);
let privKey;
let pubKeys = [];
[].concat(this.options.encryptionKeys || []).forEach(pubKey => {
let keys;
try {
keys = openpgp.key.readArmored(pubKey.toString()).keys;
pubKeys = pubKeys.concat(keys);
} catch (E) {
// just ignore if failed
let privKey;
const pubKeys = await Promise.all(this.options.encryptionKeys.map(armoredKey => openpgp.readKey({ armoredKey })));
if (!pubKeys.length) {
this.push(message);
return done();
}
});
if (!pubKeys.length) {
this.push(message);
return done();
}
if (this.options.signingKey) {
try {
privKey = await openpgp.readKey({
armoredKey: this.options.signingKey.toString()
});
if (this.options.signingKey) {
try {
privKey = openpgp.key.readArmored(this.options.signingKey.toString()).keys[0];
if (this.options.passphrase && !privKey.decrypt(this.options.passphrase)) {
privKey = false;
if (this.options.passphrase && !(await privKey.decrypt(this.options.passphrase))) {
privKey = false;
}
} catch (E) {
// just ignore if failed
}
} catch (E) {
// just ignore if failed
}
}
let messageParts = message.toString().split('\r\n\r\n');
let header = messageParts.shift();
let headers = [];
let bodyHeaders = [];
let lastHeader = false;
let boundary = 'nm_' + crypto.randomBytes(14).toString('hex');
header.split('\r\n').forEach((line, i) => {
if (!i || !lastHeader || !/^\s/.test(line)) {
lastHeader = [line];
if (/^(content-type|content-transfer-encoding):/i.test(line)) {
bodyHeaders.push(lastHeader);
let messageParts = message.toString().split('\r\n\r\n');
let header = messageParts.shift();
let headers = [];
let bodyHeaders = [];
let lastHeader = false;
let boundary = 'nm_' + crypto.randomBytes(14).toString('hex');
header.split('\r\n').forEach((line, i) => {
if (!i || !lastHeader || !/^\s/.test(line)) {
lastHeader = [line];
if (/^(content-type|content-transfer-encoding):/i.test(line)) {
bodyHeaders.push(lastHeader);
} else {
headers.push(lastHeader);
}
} else {
headers.push(lastHeader);
lastHeader.push(line);
}
} else {
lastHeader.push(line);
}
});
headers.push(['Content-Type: multipart/encrypted; protocol="application/pgp-encrypted";'], [' boundary="' + boundary + '"']);
});
headers.push(['Content-Type: multipart/encrypted; protocol="application/pgp-encrypted";'], [' boundary="' + boundary + '"']);
headers.push(['Content-Description: OpenPGP encrypted message']);
headers.push(['Content-Transfer-Encoding: 7bit']);
headers.push(['Content-Description: OpenPGP encrypted message']);
headers.push(['Content-Transfer-Encoding: 7bit']);
headers = headers.map(line => line.join('\r\n')).join('\r\n');
bodyHeaders = bodyHeaders.map(line => line.join('\r\n')).join('\r\n');
headers = headers.map(line => line.join('\r\n')).join('\r\n');
bodyHeaders = bodyHeaders.map(line => line.join('\r\n')).join('\r\n');
let body = messageParts.join('\r\n\r\n');
let body = messageParts.join('\r\n\r\n');
const data = `${bodyHeaders} \r\n\r\n ${body}`;
let options = {
data: bodyHeaders + '\r\n\r\n' + body,
publicKeys: pubKeys,
armor: true
};
let options = {
message: openpgp.Message.fromText(data),
publicKeys: pubKeys,
armor: true
};
if (privKey) {
options.privateKeys = privKey;
}
if (privKey) {
options.privateKeys = privKey;
}
openpgp
.encrypt(options)
.then(ciphertext => {
let encrypted = ciphertext.data;
let body =
try {
const encrypted = await openpgp.encrypt(options);
const mailBody =
'This is an OpenPGP/MIME encrypted message\r\n\r\n' +

@@ -136,6 +129,8 @@ '--' +

this.push(Buffer.from(headers + '\r\n\r\n' + body));
done();
})
.catch(done);
this.push(Buffer.from(`${headers}\r\n\r\n${mailBody}`));
return done();
} catch (E) {
return done();
}
})();
}

@@ -151,4 +146,4 @@ }

*/
module.exports.openpgpEncrypt = function(options) {
return function(mail, callback) {
module.exports.openpgpEncrypt = function (options) {
return function (mail, callback) {
if (!mail.data.encryptionKeys || (Array.isArray(mail.data.encryptionKeys) && !mail.data.encryptionKeys.length)) {

@@ -155,0 +150,0 @@ return setImmediate(callback);

{
"name": "nodemailer-openpgp",
"version": "1.2.0",
"version": "2.0.0",
"description": "Encrypt Nodemailer messages with PGP",

@@ -23,16 +23,19 @@ "main": "lib/nodemailer-openpgp",

"homepage": "https://github.com/nodemailer/nodemailer-openpgp",
"engines": {
"node": ">=12"
},
"dependencies": {
"openpgp": "3.0.11"
"openpgp": "5.0.0-1"
},
"devDependencies": {
"chai": "^4.1.2",
"eslint-config-nodemailer": "^1.2.0",
"grunt": "^1.0.3",
"grunt-cli": "^1.2.0",
"grunt-eslint": "^21.0.0",
"grunt-mocha-test": "^0.13.3",
"mocha": "^5.2.0",
"nodemailer": "^4.6.7",
"nodemailer-stub-transport": "^1.1.0"
"chai": "4.1.2",
"eslint-config-nodemailer": "1.2.0",
"grunt": "1.0.3",
"grunt-cli": "1.2.0",
"grunt-eslint": "23.0.0",
"grunt-mocha-test": "0.13.3",
"mocha": "8.3.2",
"nodemailer": "6.5.0",
"nodemailer-stub-transport": "1.1.0"
}
}

Sorry, the diff of this file is not supported yet

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