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

smtp-server-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smtp-server-as-promised - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

5

CHANGELOG.md
# Changelog
## v5.1.0 2018-09-19
* `onData` method is resolved when `stream` is finished. It is rejected if the
`stream` is already finished.
## v5.0.0 2018-09-17

@@ -4,0 +9,0 @@

@@ -31,10 +31,17 @@ /// <reference types="node" />

destroy(): Promise<void>;
/** This method can be overriden in subclass */
protected onAuth(auth: SMTPServerAuthentication, session: SMTPServerSession): Promise<SMTPServerAuthenticationResponse>;
/** This method can be overriden in subclass */
protected onClose(session: SMTPServerSession): Promise<void>;
/** This method can be overriden in subclass */
protected onConnect(session: SMTPServerSession): Promise<void>;
/** This method can be overriden in subclass */
protected onData(stream: Readable, session: SMTPServerSession): Promise<void>;
/** This method can be overriden in subclass */
protected onMailFrom(address: SMTPServerAddress, session: SMTPServerSession): Promise<void>;
/** This method can be overriden in subclass */
protected onRcptTo(address: SMTPServerAddress, session: SMTPServerSession): Promise<void>;
/** This method can be overriden in subclass */
protected onError(error: Error): Promise<void>;
}
export default SMTPServerAsPromised;

38

lib/smtp-server-as-promised.js

@@ -6,3 +6,5 @@ "use strict";

const tslib_1 = require("tslib");
const is_stream_ended_1 = tslib_1.__importDefault(require("is-stream-ended"));
const null_writable_1 = tslib_1.__importDefault(require("null-writable"));
const stream_finished_1 = tslib_1.__importDefault(require("stream.finished"));
const smtp_server_1 = require("smtp-server");

@@ -26,8 +28,25 @@ tslib_1.__exportStar(require("smtp-server"), exports);

.catch((err) => callback(err));
newOptions.onData = (stream, session, callback) => this.onData(stream, session)
.then(() => callback())
.catch((err) => {
stream.pipe(new null_writable_1.default());
callback(err);
});
newOptions.onData = (stream, session, callback) => {
const promiseStream = new Promise((resolve, reject) => {
if (is_stream_ended_1.default(stream)) {
return resolve();
}
stream_finished_1.default(stream, (err) => {
if (err)
reject(err);
else
resolve();
});
});
if (is_stream_ended_1.default(stream)) {
return callback(new Error('SMTP data stream is already ended'));
}
return this.onData(stream, session)
.then(() => promiseStream)
.then(() => callback())
.catch((err) => {
stream.pipe(new null_writable_1.default());
callback(err);
});
};
newOptions.onClose = (session) => this.onClose(session);

@@ -82,11 +101,15 @@ this.server = new smtp_server_1.SMTPServer(Object.assign({}, options, newOptions));

}
/** This method can be overriden in subclass */
onAuth(auth, session) {
return Promise.reject(new Error('onAuth method not overriden in subclass'));
}
/** This method can be overriden in subclass */
onClose(session) {
return Promise.resolve();
}
/** This method can be overriden in subclass */
onConnect(session) {
return Promise.resolve();
}
/** This method can be overriden in subclass */
onData(stream, session) {

@@ -96,8 +119,11 @@ stream.pipe(new null_writable_1.default());

}
/** This method can be overriden in subclass */
onMailFrom(address, session) {
return Promise.resolve();
}
/** This method can be overriden in subclass */
onRcptTo(address, session) {
return Promise.resolve();
}
/** This method can be overriden in subclass */
onError(error) {

@@ -104,0 +130,0 @@ return Promise.resolve();

4

package.json
{
"name": "smtp-server-as-promised",
"version": "5.0.0",
"version": "5.1.0",
"description": "Promisify smtp-server module",

@@ -26,3 +26,5 @@ "main": "lib/smtp-server-as-promised.js",

"dependencies": {
"is-stream-ended": "^0.1.4",
"smtp-server": "^3.4.7",
"stream.finished": "^1.1.1",
"tslib": "^1.9.3"

@@ -29,0 +31,0 @@ },

@@ -27,3 +27,3 @@ # smtp-server-as-promised

```shell
npm install -D @types/node @types/nodemailer
npm install -D @types/node @types/nodemailer @types/smtp-server
```

@@ -166,10 +166,3 @@

console.log(`[${session.id}] onData started`)
session.messageLength = 0
for (let chunk; (chunk = await stream.read());) {
console.log(`[${session.id}] onData got data chunk ${chunk.length} bytes`)
session.messageLength += chunk.length
}
console.log(`[${session.id}] onData finished after reading ${session.messageLength} bytes`)
stream.pipe(process.stdout)
}

@@ -185,5 +178,8 @@ }

If the method throws an error then the stream is silently consumed to prevent
SMTP stream to be blocked.
The method blocks SMTP session until `stream` is finished. It breaks session if
`stream` is already finished.
If the method throws an error then the `stream` is silently consumed to
prevent SMTP stream to be blocked.
### onError

@@ -190,0 +186,0 @@

/// <reference types="node" />
/// <reference types="nodemailer" />
import isStreamEnded from 'is-stream-ended'
import net from 'net'

@@ -8,2 +9,3 @@ export { Logger, LoggerLevel } from 'nodemailer/lib/shared'

import { Readable } from 'stream'
import finished from 'stream.finished'
import tls from 'tls'

@@ -56,3 +58,19 @@

newOptions.onData = (stream: Readable, session: SMTPServerSession, callback: (err?: Error | null) => void) => this.onData(stream, session)
newOptions.onData = (stream: Readable, session: SMTPServerSession, callback: (err?: Error | null) => void) => {
const promiseStream = new Promise((resolve, reject) => {
if (isStreamEnded(stream)) {
return resolve()
}
finished(stream, (err) => {
if (err) reject(err)
else resolve()
})
})
if (isStreamEnded(stream)) {
return callback(new Error('SMTP data stream is already ended'))
}
return this.onData(stream, session)
.then(() => promiseStream)
.then(() => callback())

@@ -63,2 +81,3 @@ .catch((err: Error) => {

})
}

@@ -123,2 +142,3 @@ newOptions.onClose = (session: SMTPServerSession) => this.onClose(session)

/** This method can be overriden in subclass */
protected onAuth (auth: SMTPServerAuthentication, session: SMTPServerSession): Promise<SMTPServerAuthenticationResponse> {

@@ -128,2 +148,3 @@ return Promise.reject(new Error('onAuth method not overriden in subclass'))

/** This method can be overriden in subclass */
protected onClose (session: SMTPServerSession): Promise<void> {

@@ -133,2 +154,3 @@ return Promise.resolve()

/** This method can be overriden in subclass */
protected onConnect (session: SMTPServerSession): Promise<void> {

@@ -138,2 +160,3 @@ return Promise.resolve()

/** This method can be overriden in subclass */
protected onData (stream: Readable, session: SMTPServerSession): Promise<void> {

@@ -144,2 +167,3 @@ stream.pipe(new NullWritable())

/** This method can be overriden in subclass */
protected onMailFrom (address: SMTPServerAddress, session: SMTPServerSession): Promise<void> {

@@ -149,2 +173,3 @@ return Promise.resolve()

/** This method can be overriden in subclass */
protected onRcptTo (address: SMTPServerAddress, session: SMTPServerSession): Promise<void> {

@@ -154,2 +179,3 @@ return Promise.resolve()

/** This method can be overriden in subclass */
protected onError (error: Error): Promise<void> {

@@ -156,0 +182,0 @@ return Promise.resolve()

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