Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "buildmail", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "buildmail is a low level rfc2822 message composer. Define your own mime tree, no magic included.", | ||
@@ -23,3 +23,4 @@ "author": "Andris Reinman <andris@kreata.ee>", | ||
"libbase64": "^0.1.0", | ||
"libqp": "^0.1.1" | ||
"libqp": "^0.1.1", | ||
"hyperquest": "^0.3.0" | ||
}, | ||
@@ -31,5 +32,4 @@ "devDependencies": { | ||
"grunt-mocha-test": "~0.10.0", | ||
"sinon": "^1.9.0", | ||
"slow-stream": "0.0.4" | ||
"sinon": "^1.9.0" | ||
} | ||
} | ||
} |
@@ -289,4 +289,9 @@ # buildmail | ||
* **body** - *String|Buffer|Stream* body content | ||
* **body** - *String|Buffer|Stream|Object* body content | ||
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** | ||
@@ -293,0 +298,0 @@ |
@@ -10,2 +10,4 @@ 'use strict'; | ||
var PassThrough = stream.PassThrough; | ||
var fs = require('fs'); | ||
var hyperquest = require('hyperquest'); | ||
@@ -491,2 +493,3 @@ module.exports = MimeNode; | ||
var contentStream; | ||
var localStream; | ||
@@ -519,24 +522,16 @@ // pushes node content | ||
if (typeof _self.content.pipe === 'function') { | ||
_self.content.pipe(contentStream); | ||
} else { | ||
contentStream.write(_self.content); | ||
contentStream.end(); | ||
} | ||
localStream = _self._getStream(_self.content); | ||
localStream.pipe(contentStream); | ||
return; | ||
} else { | ||
if (_self._isFlowedContent) { | ||
outputStream.write(libmime.encodeFlowed(_self.content)); | ||
localStream = _self._getStream(libmime.encodeFlowed(_self.content)); | ||
} else { | ||
if (typeof _self.content.pipe === 'function') { | ||
_self.content.pipe(outputStream, { | ||
end: false | ||
}); | ||
_self.content.once('end', finalize); | ||
return; | ||
} else { | ||
outputStream.write(_self.content); | ||
} | ||
localStream = _self._getStream(_self.content); | ||
} | ||
return setImmediate(finalize); | ||
localStream.pipe(outputStream, { | ||
end: false | ||
}); | ||
localStream.once('end', finalize); | ||
return; | ||
} | ||
@@ -577,2 +572,23 @@ } else { | ||
/** | ||
* Detects and returns handle to a stream related with the content. | ||
* | ||
* @param {Mixed} content Node content | ||
* @returns {Object} Stream object | ||
*/ | ||
MimeNode.prototype._getStream = function(content) { | ||
var contentStream; | ||
if (typeof content.pipe === 'function') { | ||
return content; | ||
} else if (content && typeof content.path === 'string') { | ||
return fs.createReadStream(content.path); | ||
} else if (content && typeof content.href === 'string') { | ||
return hyperquest(content.href); | ||
} else { | ||
contentStream = new PassThrough(); | ||
contentStream.end(content || ''); | ||
return contentStream; | ||
} | ||
}; | ||
/** | ||
* Generates and returns SMTP envelope with the sender address and a list of recipients addresses | ||
@@ -579,0 +595,0 @@ * |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var Buildmail = require('../src/buildmail'); | ||
var http = require('http'); | ||
@@ -713,2 +714,45 @@ var expect = chai.expect; | ||
}); | ||
describe('HTTP streaming', function() { | ||
var port = 10337; | ||
var server; | ||
beforeEach(function(done) { | ||
server = http.createServer(function(req, res) { | ||
res.writeHead(200, { | ||
'Content-Type': 'text/plain' | ||
}); | ||
var data = new Buffer(new Array(1024 + 1).join('ä'), 'utf-8'); | ||
var i = 0; | ||
var sendByte = function() { | ||
if (i >= data.length) { | ||
return res.end(); | ||
} | ||
res.write(new Buffer([data[i++]])); | ||
setImmediate(sendByte); | ||
}; | ||
sendByte(); | ||
}); | ||
server.listen(port, done); | ||
}); | ||
afterEach(function(done) { | ||
server.close(done); | ||
}); | ||
it('should pipe URL as an attachment', function(done) { | ||
var mb = new Buildmail('text/plain'). | ||
setContent({ | ||
href: 'http://localhost:' + port | ||
}); | ||
mb.build(function(err, msg) { | ||
msg = msg.toString(); | ||
expect(/^=C3=A4/m.test(msg)).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
64382
5
1372
465
5
1
1
+ Addedhyperquest@^0.3.0
+ Addedduplexer@0.1.2(transitive)
+ Addedhyperquest@0.3.0(transitive)
+ Addedthrough@2.2.7(transitive)