Comparing version 3.3.2 to 3.4.0
@@ -48,3 +48,3 @@ 'use strict'; | ||
'no-mixed-spaces-and-tabs': 2, | ||
'no-console': 0 | ||
'no-console': 2 | ||
}, | ||
@@ -51,0 +51,0 @@ env: { |
# Changelog | ||
## 3.4.0 2016-02-05 | ||
* Added new method `setRaw` | ||
* Bumped nodemailer-fetch version | ||
## 3.3.2 | ||
@@ -4,0 +9,0 @@ |
@@ -106,2 +106,8 @@ 'use strict'; | ||
/** | ||
* If set then use this value as the stream content instead of building it | ||
* @type {String|Buffer|Stream} | ||
*/ | ||
this._raw = false; | ||
/** | ||
* Additional transform streams that the message will be piped before | ||
@@ -665,4 +671,27 @@ * exposing by createReadStream | ||
outputStream.write(this.buildHeaders() + '\r\n\r\n'); | ||
setImmediate(sendContent); | ||
if (this._raw) { | ||
setImmediate(function () { | ||
if (Object.prototype.toString.call(_self._raw) === '[object Error]') { | ||
// content is already errored | ||
return callback(_self._raw); | ||
} | ||
// remove default error handler (if set) | ||
if (typeof _self._raw.pipe === 'function') { | ||
_self._raw.removeListener('error', _self._contentErrorHandler); | ||
} | ||
var raw = _self._getStream(_self._raw); | ||
raw.pipe(outputStream, { | ||
end: false | ||
}); | ||
raw.on('error', function (err) { | ||
outputStream.emit('error', err); | ||
}); | ||
raw.on('end', finalize); | ||
}); | ||
} else { | ||
outputStream.write(this.buildHeaders() + '\r\n\r\n'); | ||
setImmediate(sendContent); | ||
} | ||
}; | ||
@@ -765,2 +794,25 @@ | ||
/** | ||
* Sets pregenerated content that will be used as the output of this node | ||
* | ||
* @param {String|Buffer|Stream} Raw MIME contents | ||
*/ | ||
MimeNode.prototype.setRaw = function (raw) { | ||
var _self = this; | ||
this._raw = raw; | ||
if (this._raw && typeof this._raw.pipe === 'function') { | ||
// pre-stream handler. might be triggered if a stream is set as content | ||
// and 'error' fires before anything is done with this stream | ||
this._contentErrorHandler = function (err) { | ||
_self._raw.removeListener('error', _self._contentErrorHandler); | ||
_self._raw = err; | ||
}; | ||
_self._raw.once('error', this._contentErrorHandler); | ||
} | ||
return this; | ||
}; | ||
/////// PRIVATE METHODS | ||
@@ -767,0 +819,0 @@ |
{ | ||
"name": "buildmail", | ||
"version": "3.3.2", | ||
"version": "3.4.0", | ||
"description": "buildmail is a low level rfc2822 message composer. Define your own mime tree, no magic included.", | ||
@@ -24,13 +24,13 @@ "author": "Andris Reinman <andris@kreata.ee>", | ||
"libqp": "1.1.0", | ||
"nodemailer-fetch": "1.2.1", | ||
"nodemailer-fetch": "1.3.0", | ||
"nodemailer-shared": "1.0.3" | ||
}, | ||
"devDependencies": { | ||
"chai": "~3.4.1", | ||
"chai": "~3.5.0", | ||
"grunt": "~0.4.5", | ||
"grunt-eslint": "^17.3.1", | ||
"grunt-mocha-test": "~0.12.7", | ||
"mocha": "^2.3.4", | ||
"sinon": "^1.17.2" | ||
"mocha": "^2.4.5", | ||
"sinon": "^1.17.3" | ||
} | ||
} |
@@ -327,2 +327,33 @@ # buildmail | ||
## setRaw | ||
Sets pre-generated output value for current node. When building the final message | ||
then this value is returned instead of building a fresh rfc822 mime message from | ||
normal input. | ||
This also means that other methods (`getAddresses`, `getEnvelope` etc.) that use normal | ||
input do not return valid values as the raw message is not parsed. You must set | ||
envelope contents manually with `setEnvelope` and you probably should set the | ||
*Message-Id* header (even though it wouldn't break anything if you would not set it). | ||
```javascript | ||
node.setRaw(message) | ||
``` | ||
Where | ||
* **message** - *String|Buffer|Stream|Object* MIME message | ||
If the value is an object, it should include one of the following properties | ||
* **path** - path to a file that will be used as the content | ||
* **href** - URL that will be used as the content | ||
**Example** | ||
```javascript | ||
new BuildMail().setRaw(fs.createReadStream('message.eml')); | ||
``` | ||
## build | ||
@@ -329,0 +360,0 @@ |
@@ -12,2 +12,3 @@ /* eslint no-unused-expressions:0 */ | ||
var Transform = stream.Transform; | ||
var PassThrough = stream.PassThrough; | ||
@@ -558,3 +559,2 @@ var expect = chai.expect; | ||
msg = msg.toString(); | ||
console.log(msg); | ||
expect(/^From: the safewithme testuser <safewithme.testuser@xn\-\-jgeva-dua.com>$/m.test(msg)).to.be.true; | ||
@@ -1066,3 +1066,3 @@ expect(/^Cc: the safewithme testuser <safewithme.testuser@xn\-\-jgeva-dua.com>$/m.test(msg)).to.be.true; | ||
it('#should return a error for an errored stream', function (done) { | ||
var s = new stream.PassThrough(); | ||
var s = new PassThrough(); | ||
var mb = new Buildmail('text/plain'). | ||
@@ -1083,3 +1083,3 @@ setContent(s); | ||
it('#should return a stream error', function (done) { | ||
var s = new stream.PassThrough(); | ||
var s = new PassThrough(); | ||
var mb = new Buildmail('text/plain'). | ||
@@ -1142,2 +1142,86 @@ setContent(s); | ||
}); | ||
describe('Raw content', function () { | ||
it('should return pregenerated content', function (done) { | ||
var expected = new Array(100).join('Test\n'); | ||
var mb = new Buildmail('text/plain').setRaw(expected); | ||
mb.build(function (err, msg) { | ||
expect(err).to.not.exist; | ||
msg = msg.toString(); | ||
expect(msg).to.equal(expected); | ||
done(); | ||
}); | ||
}); | ||
it('should return pregenerated content for a child node', function (done) { | ||
var expected = new Array(100).join('Test\n'); | ||
var mb = new Buildmail('multipart/mixed', { | ||
baseBoundary: 'test' | ||
}).setHeader({ | ||
date: '12345', | ||
'message-id': '67890' | ||
}); | ||
var child = mb.createChild(); | ||
child.setRaw(expected); | ||
mb.build(function (err, msg) { | ||
expect(err).to.not.exist; | ||
msg = msg.toString(); | ||
expect(msg).to.equal('Content-Type: multipart/mixed; boundary="----sinikael-?=_1-test"\r\n' + | ||
'Date: 12345\r\n' + | ||
'Message-Id: <67890>\r\n' + | ||
'MIME-Version: 1.0\r\n' + | ||
'\r\n' + | ||
'------sinikael-?=_1-test\r\n' + | ||
expected + | ||
'\r\n' + | ||
'------sinikael-?=_1-test--\r\n'); | ||
done(); | ||
}); | ||
}); | ||
it('should return pregenerated content from a stream', function (done) { | ||
var expected = new Array(100).join('Test\n'); | ||
var raw = new PassThrough(); | ||
var mb = new Buildmail('text/plain').setRaw(raw); | ||
setImmediate(function () { | ||
raw.end(expected); | ||
}); | ||
mb.build(function (err, msg) { | ||
expect(err).to.not.exist; | ||
msg = msg.toString(); | ||
expect(msg).to.equal(expected); | ||
done(); | ||
}); | ||
}); | ||
it('should catch error from a raw stream 1', function (done) { | ||
var raw = new PassThrough(); | ||
var mb = new Buildmail('text/plain').setRaw(raw); | ||
raw.emit('error', new Error('Stream error')); | ||
mb.build(function (err) { | ||
expect(err).to.exist; | ||
done(); | ||
}); | ||
}); | ||
it('should catch error from a raw stream 2', function (done) { | ||
var raw = new PassThrough(); | ||
var mb = new Buildmail('text/plain').setRaw(raw); | ||
mb.build(function (err) { | ||
expect(err).to.exist; | ||
done(); | ||
}); | ||
setImmediate(function () { | ||
raw.emit('error', new Error('Stream error')); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97167
2035
634
+ Addednodemailer-fetch@1.3.0(transitive)
Updatednodemailer-fetch@1.3.0