Socket
Socket
Sign inDemoInstall

smtp-server

Package Overview
Dependencies
0
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.1 to 1.4.0

4

CHANGELOG.md
# Changelog
## v1.4.0 2015-04-30
* Added support for RFC1870 SIZE extension
## v1.3.1 2015-04-21

@@ -4,0 +8,0 @@

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

var SERVER_PORT = 1337;
var SERVER_PORT = 2525;
var SERVER_HOST = '0.0.0.0';

@@ -30,2 +30,5 @@

// Accept messages up to 10 MB
size: 10 * 1024 * 1024,
// Setup authentication

@@ -74,3 +77,11 @@ // Allow only users with username 'testuser' and password 'testpass'

stream.pipe(process.stdout);
stream.on('end', callback); // accept the message once the stream is ended
stream.on('end', function(){
var err;
if(stream.sizeExceeded){
err = new Error('Maximum allowed message size 1kB exceeded');
err.statusCode = 552;
return callback(err);
}
callback(null, 'Message queued as abcdef'); // accept the message once the stream is ended
});
}

@@ -77,0 +88,0 @@ });

@@ -411,2 +411,6 @@ 'use strict';

if (this._server.options.size) {
features.push('SIZE ' + this._server.options.size);
}
this._startSession(); // EHLO is effectively the same as RSET

@@ -507,3 +511,3 @@ this.send(250, ['OK: Nice to meet you ' + this.clientHostname].concat(features || []));

ctx = ctxMap.get(servername);
}else{
} else {
ctx = ctxMap[servername];

@@ -591,2 +595,7 @@ }

if (this._server.options.size && parsed.args.SIZE && Number(parsed.args.SIZE) > this._server.options.size) {
this.send(552, 'Error: message exceeds fixed maximum message size ' + this._server.options.size);
return callback();
}
this._server.onMailFrom(parsed, this.session, function(err) {

@@ -656,3 +665,3 @@ if (err) {

this._dataStream = this._parser.startDataMode();
this._dataStream = this._parser.startDataMode(this._server.options.size);

@@ -659,0 +668,0 @@ var close = function(err, message) {

2

lib/smtp-server.js

@@ -245,2 +245,3 @@ 'use strict';

this.logger.info('SMTP Server closed');
this.emit('close');
};

@@ -254,4 +255,3 @@

SMTPServer.prototype._onError = function(err) {
this.logger.error(err);
this.emit('error', err);
};

@@ -27,2 +27,4 @@ 'use strict';

this._dataStream = null;
// How many bytes are allowed for a data stream
this._maxBytes = Infinity;
// How many bytes have been emitted to data stream

@@ -53,4 +55,5 @@ this.dataBytes = 0;

*/
SMTPStream.prototype.startDataMode = function() {
SMTPStream.prototype.startDataMode = function(maxBytes) {
this._dataMode = true;
this._maxBytes = maxBytes && Number(maxBytes) || Infinity;
this.dataBytes = 0;

@@ -249,2 +252,5 @@ this._dataStream = new PassThrough();

this._dataStream.byteLength = this.dataBytes;
this._dataStream.sizeExceeded = this.dataBytes > this._maxBytes;
if (chunk && chunk.length && this._dataStream.writable) {

@@ -251,0 +257,0 @@ this._dataStream.end(chunk);

{
"name": "smtp-server",
"version": "1.3.1",
"version": "1.4.0",
"description": "Create custom SMTP servers on the fly",

@@ -13,3 +13,3 @@ "main": "lib/smtp-server.js",

"devDependencies": {
"chai": "^2.2.0",
"chai": "^2.3.0",
"grunt": "^0.4.5",

@@ -16,0 +16,0 @@ "grunt-contrib-jshint": "^0.11.2",

@@ -10,4 +10,2 @@ # smtp-server

> **Beware!** This module is not battle tested (yet), I wrote it from scratch to replace simplesmtp server, so I might have overlooked some corner cases. [File an issue](https://github.com/andris9/smtp-server/issues) if you find anything strange going on when using this module.
## Support smtp-server development

@@ -39,5 +37,6 @@

* **options.banner** optional greeting message. This message is appended to the default ESMTP response.
* **options.size** optional maximum allowed message size in bytes, see details [here](#using-size-extension)
* **options.authMethods** optional array of allowed authentication methods, defaults to `['PLAIN', 'LOGIN']`. Only the methods listed in this array are allowed, so if you set it to `['XOAUTH2']` then PLAIN and LOGIN are not available. Use `['PLAIN', 'LOGIN', 'XOAUTH2']` to allow all three. Authentication is only allowed in secure mode (either the server is started with `secure: true` option or STARTTLS command is used)
* **options.disabledCommands** optional array of disabled commands (see all supported commands [here](#commands)). For example if you want to disable authentication, use `['AUTH']` as this value. If you want to allow authentication in clear text, set it to `['STARTTLS']`.
* **hideSTARTTLS** optional boolean, if set to true then allow using STARTTLS but do not advertise or require it. It only makes sense when creating integration test servers for testing the scenario where you want to try STARTTLS even when it is not advertised
* **options.hideSTARTTLS** optional boolean, if set to true then allow using STARTTLS but do not advertise or require it. It only makes sense when creating integration test servers for testing the scenario where you want to try STARTTLS even when it is not advertised
* **options.sniOptions** optional [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) or an object of TLS options for SNI where servername is the key

@@ -48,8 +47,8 @@ * **options.logger** optional [bunyan](https://github.com/trentm/node-bunyan) compatible logger instance. By default logs to console. If set to `false` then nothing is logged

* **options.closeTimeout** how many millisceonds to wait before disconnecting pending connections once server.close() has been called (defaults to 30 seconds)
* **onAuth** is the callback to handle authentications (see details [here](#handling-authentication))
* **onMailFrom** is the callback to validate MAIL FROM commands (see details [here](#validating-sender-addresses))
* **onRcptTo** is the callback to validate RCPT TO commands (see details [here](#validating-recipient-addresses))
* **onData** is the callback to handle incoming messages (see details [here](#processing-incoming-message))
* **options.onAuth** is the callback to handle authentications (see details [here](#handling-authentication))
* **options.onMailFrom** is the callback to validate MAIL FROM commands (see details [here](#validating-sender-addresses))
* **options.onRcptTo** is the callback to validate RCPT TO commands (see details [here](#validating-recipient-addresses))
* **options.onData** is the callback to handle incoming messages (see details [here](#processing-incoming-message))
Additionally you can use the options from [net.createServer](http://nodejs.org/api/net.html#net_net_createserver_options_connectionlistener) and [tls.createServer](http://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) (applies if `secure` is set to true). For example to set a `SNICallback` for the secure server, just set **options.SNICallback**.
Additionally you can use the options from [net.createServer](http://nodejs.org/api/net.html#net_net_createserver_options_connectionlistener) and [tls.createServer](http://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) (applies if `secure` is set to true)

@@ -111,2 +110,3 @@ ### TLS and STARTLS notice

* **accessToken** is the OAuth2 bearer access token if 'XOAUTH2' was used as the authentication method
* **validatePassword** is a function for validating CRAM-MD5 challenge responses. Takes the password of the user as an argument and returns `true` if the response matches the password
* **session** includes information about the session like `remoteAddress` for the remote IP, see details [here](#session-object)

@@ -136,3 +136,3 @@ * **callback** is the function to run once the user is authenticated. Takes 2 arguments: `(error, response)`

#### Oauth2 authentication
#### OAuth2 authentication

@@ -274,2 +274,24 @@ XOAUTH2 support needs to enabled with the `authMethods` array option as it is disabled by default.

## Using SIZE extension
When creating the server you can define maximum allowed message size with the `size` option, see [RFC1870](https://tools.ietf.org/html/rfc1870) for details. This is not a strict limitation, the client is informed about the size limit but the client can still send a larger message than allowed, it is up to your application to reject or accept the oversized message. To check if the message was oversized, see `stream.sizeExceeded` option.
```javascript
var server = new SMTPServer({
size: 1024, // allow messages up to 1 kb
onData: function(stream, session, callback){
stream.pipe(process.stdout); // print message to console
stream.on('end', function(){
var err;
if(stream.sizeExceeded){
err = new Error('Maximum allowed message size 1kB exceeded');
err.statusCode = 552;
return callback(err);
}
callback(null, 'Message queued as abcdef');
});
}
});
```
## Session object

@@ -276,0 +298,0 @@

@@ -816,3 +816,4 @@ 'use strict';

logger: false,
authMethods: ['PLAIN', 'LOGIN', 'XOAUTH2']
authMethods: ['PLAIN', 'LOGIN', 'XOAUTH2'],
size: 1024
});

@@ -857,8 +858,13 @@

var message = Buffer.concat(chunks, chunklen).toString();
var err;
if (/^deny/i.test(message)) {
callback(new Error('Not queued'));
} else {
callback();
return callback(new Error('Not queued'));
} else if(stream.sizeExceeded){
err = new Error('Maximum allowed message size 1kB exceeded');
err.statusCode = 552;
return callback(err);
}
callback(null, 'Message queued as abcdef'); // accept the message once the stream is ended
}.bind(this));

@@ -950,2 +956,12 @@ };

it('should reject too big message', function(done) {
connection.send({
from: 'sender@example.com',
to: ['recipient@exmaple.com']
}, new Array(1000).join('testmessage'), function(err) {
expect(err).to.exist;
done();
});
});
it('should send multiple messages', function(done) {

@@ -952,0 +968,0 @@ connection.send({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc