Skip to content

Commit

Permalink
v6.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Apr 28, 2021
1 parent 91108d7 commit 058d414
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 105 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 6.6.0 2021-04-28

- Added new option `newline` for MailComposer

## 6.5.0 2021-02-26

- Pass through textEncoding to subnodes
Expand Down
3 changes: 2 additions & 1 deletion examples/mailcomposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const mailOptions = {
from: 'Daemon <deamon@kreata.ee>',
to: 'mailer@kreata.ee, Mailer <mailer2@kreata.ee>'
},
text: 'Test message'
text: 'Test\n 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ö\r\nsage',
newline: '\r\n'
};

async function main() {
Expand Down
26 changes: 17 additions & 9 deletions lib/mail-composer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MailComposer {

// Compose MIME tree
if (this.mail.raw) {
this.message = new MimeNode().setRaw(this.mail.raw);
this.message = new MimeNode('message/rfc822', { newline: this.mail.newline }).setRaw(this.mail.raw);
} else if (this._useMixed) {
this.message = this._createMixed();
} else if (this._useAlternative) {
Expand Down Expand Up @@ -345,13 +345,15 @@ class MailComposer {
boundaryPrefix: this.mail.boundaryPrefix,
disableUrlAccess: this.mail.disableUrlAccess,
disableFileAccess: this.mail.disableFileAccess,
normalizeHeaderKey: this.mail.normalizeHeaderKey
normalizeHeaderKey: this.mail.normalizeHeaderKey,
newline: this.mail.newline
});
} else {
node = parentNode.createChild('multipart/mixed', {
disableUrlAccess: this.mail.disableUrlAccess,
disableFileAccess: this.mail.disableFileAccess,
normalizeHeaderKey: this.mail.normalizeHeaderKey
normalizeHeaderKey: this.mail.normalizeHeaderKey,
newline: this.mail.newline
});
}

Expand Down Expand Up @@ -391,13 +393,15 @@ class MailComposer {
boundaryPrefix: this.mail.boundaryPrefix,
disableUrlAccess: this.mail.disableUrlAccess,
disableFileAccess: this.mail.disableFileAccess,
normalizeHeaderKey: this.mail.normalizeHeaderKey
normalizeHeaderKey: this.mail.normalizeHeaderKey,
newline: this.mail.newline
});
} else {
node = parentNode.createChild('multipart/alternative', {
disableUrlAccess: this.mail.disableUrlAccess,
disableFileAccess: this.mail.disableFileAccess,
normalizeHeaderKey: this.mail.normalizeHeaderKey
normalizeHeaderKey: this.mail.normalizeHeaderKey,
newline: this.mail.newline
});
}

Expand Down Expand Up @@ -428,13 +432,15 @@ class MailComposer {
boundaryPrefix: this.mail.boundaryPrefix,
disableUrlAccess: this.mail.disableUrlAccess,
disableFileAccess: this.mail.disableFileAccess,
normalizeHeaderKey: this.mail.normalizeHeaderKey
normalizeHeaderKey: this.mail.normalizeHeaderKey,
newline: this.mail.newline
});
} else {
node = parentNode.createChild('multipart/related; type="text/html"', {
disableUrlAccess: this.mail.disableUrlAccess,
disableFileAccess: this.mail.disableFileAccess,
normalizeHeaderKey: this.mail.normalizeHeaderKey
normalizeHeaderKey: this.mail.normalizeHeaderKey,
newline: this.mail.newline
});
}

Expand Down Expand Up @@ -470,15 +476,17 @@ class MailComposer {
boundaryPrefix: this.mail.boundaryPrefix,
disableUrlAccess: this.mail.disableUrlAccess,
disableFileAccess: this.mail.disableFileAccess,
normalizeHeaderKey: this.mail.normalizeHeaderKey
normalizeHeaderKey: this.mail.normalizeHeaderKey,
newline: this.mail.newline
});
} else {
node = parentNode.createChild(element.contentType, {
filename: element.filename,
textEncoding: this.mail.textEncoding,
disableUrlAccess: this.mail.disableUrlAccess,
disableFileAccess: this.mail.disableFileAccess,
normalizeHeaderKey: this.mail.normalizeHeaderKey
normalizeHeaderKey: this.mail.normalizeHeaderKey,
newline: this.mail.newline
});
}

Expand Down
17 changes: 17 additions & 0 deletions lib/mime-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const addressparser = require('../addressparser');
const fetch = require('../fetch');
const LastNewline = require('./last-newline');

const LeWindows = require('./le-windows');
const LeUnix = require('./le-unix');

/**
* Creates a new mime tree node. Assumes 'multipart/*' as the content type
* if it is a branch, anything else counts as leaf. If rootNode is missing from
Expand Down Expand Up @@ -92,6 +95,11 @@ class MimeNode {
*/
this.hostname = options.hostname;

/**
* If set to 'win' then uses \r\n, if 'linux' then \n. If not set (or `raw` is used) then newlines are kept as is.
*/
this.newline = options.newline;

/**
* An array for possible child nodes
*/
Expand Down Expand Up @@ -626,6 +634,15 @@ class MimeNode {
outputStream = transform(outputStream);
}

if (this.newline) {
const winbreak = ['win', 'windows', 'dos', '\r\n'].includes(this.newline.toString().toLowerCase());
const newlineTransform = winbreak ? new LeWindows() : new LeUnix();

const stream = outputStream.pipe(newlineTransform);
outputStream.on('error', err => stream.emit('error', err));
return stream;
}

return outputStream;
}

Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 2 additions & 8 deletions lib/sendmail-transport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

const spawn = require('child_process').spawn;
const packageData = require('../../package.json');
const LeWindows = require('./le-windows');
const LeUnix = require('./le-unix');
const shared = require('../shared');

/**
Expand Down Expand Up @@ -68,7 +66,6 @@ class SendmailTransport {
let args;
let sendmail;
let returned;
let transform;

const hasInvalidAddresses = []
.concat(envelope.from || [])
Expand Down Expand Up @@ -187,10 +184,8 @@ class SendmailTransport {
recipients.join(', ')
);

transform = this.winbreak ? new LeWindows() : new LeUnix();
let sourceStream = mail.message.createReadStream();

transform.once('error', err => {
sourceStream.once('error', err => {
this.logger.error(
{
err,
Expand All @@ -205,8 +200,7 @@ class SendmailTransport {
callback(err);
});

sourceStream.once('error', err => transform.emit('error', err));
sourceStream.pipe(transform).pipe(sendmail.stdin);
sourceStream.pipe(sendmail.stdin);
} else {
return callback(new Error('sendmail was not found'));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ses-transport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const EventEmitter = require('events');
const packageData = require('../../package.json');
const shared = require('../shared');
const LeWindows = require('../sendmail-transport/le-windows');
const LeWindows = require('../mime-node/le-windows');

/**
* Generates a Transport object for AWS SES
Expand Down
9 changes: 1 addition & 8 deletions lib/stream-transport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

const packageData = require('../../package.json');
const shared = require('../shared');
const LeWindows = require('../sendmail-transport/le-windows');
const LeUnix = require('../sendmail-transport/le-unix');

/**
* Generates a Transport object for streaming
Expand Down Expand Up @@ -61,15 +59,10 @@ class StreamTransport {
);

setImmediate(() => {
let sourceStream;
let stream;
let transform;

try {
transform = this.winbreak ? new LeWindows() : new LeUnix();
sourceStream = mail.message.createReadStream();
stream = sourceStream.pipe(transform);
sourceStream.on('error', err => stream.emit('error', err));
stream = mail.message.createReadStream();
} catch (E) {
this.logger.error(
{
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodemailer",
"version": "6.5.0",
"version": "6.6.0",
"description": "Easy as cake e-mail sending from your Node.js applications",
"main": "lib/nodemailer.js",
"scripts": {
Expand All @@ -21,21 +21,21 @@
"homepage": "https://nodemailer.com/",
"devDependencies": {
"bunyan": "1.8.15",
"chai": "4.3.0",
"chai": "4.3.4",
"eslint-config-nodemailer": "1.2.0",
"eslint-config-prettier": "8.1.0",
"grunt": "1.3.0",
"grunt-cli": "1.3.2",
"eslint-config-prettier": "8.3.0",
"grunt": "1.4.0",
"grunt-cli": "1.4.2",
"grunt-eslint": "23.0.0",
"grunt-mocha-test": "0.13.3",
"libbase64": "1.2.1",
"libmime": "5.0.0",
"libqp": "1.1.0",
"mocha": "8.3.0",
"mocha": "8.3.2",
"nodemailer-ntlm-auth": "1.0.1",
"proxy": "1.0.2",
"proxy-test-server": "1.0.0",
"sinon": "9.2.4",
"sinon": "10.0.0",
"smtp-server": "3.8.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion test/sendmail/le-unix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

'use strict';

const LeUnix = require('../../lib/sendmail-transport/le-unix');
const LeUnix = require('../../lib/mime-node/le-unix');
const chai = require('chai');
const expect = chai.expect;

Expand Down
2 changes: 1 addition & 1 deletion test/sendmail/le-windows-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

'use strict';

const LeWindows = require('../../lib/sendmail-transport/le-windows');
const LeWindows = require('../../lib/mime-node/le-windows');
const chai = require('chai');
const expect = chai.expect;

Expand Down
19 changes: 9 additions & 10 deletions test/sendmail/sendmail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const PassThrough = require('stream').PassThrough;
const EventEmitter = require('events').EventEmitter;
const sinon = require('sinon');
const SendmailTransport = require('../../lib/sendmail-transport');
const MailComposer = require('../../lib/mail-composer');
chai.config.includeStack = true;

class MockBuilder {
Expand Down Expand Up @@ -68,18 +69,16 @@ describe('Sendmail Transport Tests', function () {
client.send(
{
data: {},
message: new MockBuilder(
{
from: 'test@valid.sender',
to: 'test@valid.recipient'
},
'message\r\nline 2'
)
message: new MailComposer({
from: 'test@valid.sender',
to: 'test@valid.recipient',
newline: '\n',
raw: Buffer.from('message\r\nline 2')
}).compile()
},
function (err, data) {
function (err) {
expect(err).to.not.exist;
expect(data.messageId).to.equal('<test>');
expect(output).to.equal('message\nline 2');
expect(output).to.equal('message\nline 2\n');
client._spawn.restore();
done();
}
Expand Down

0 comments on commit 058d414

Please sign in to comment.