New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 3.3.2 to 4.0.0

src/smtp-server-as-promised.ts

6

CHANGELOG.md
# Changelog
## v4.0.0 2018-09-09
* Rewritten in Typescript.
* Requires Node >= 6
* Changed syntax for import.
## v3.3.2 2018-03-09

@@ -4,0 +10,0 @@

71

lib/smtp-server-as-promised.d.ts
/// <reference types="node" />
/// <reference types="nodemailer" />
import net from 'net'
export { Logger, LoggerLevel } from 'nodemailer/lib/shared'
import { Readable } from 'stream'
import tls from 'tls'
import { SMTPServer, SMTPServerAddress, SMTPServerAuthentication, SMTPServerAuthenticationResponse, SMTPServerOptions, SMTPServerSession } from 'smtp-server'
export * from 'smtp-server'
import net from 'net';
export { Logger, LoggerLevel } from 'nodemailer/lib/shared';
import { Readable } from 'stream';
import tls from 'tls';
import { SMTPServer, SMTPServerAddress, SMTPServerAuthentication, SMTPServerAuthenticationResponse, SMTPServerOptions, SMTPServerSession } from 'smtp-server';
export * from 'smtp-server';
export interface SMTPServerAsPromisedServerAddress {
address: string
family: string
port: number
address: string;
family: string;
port: number;
}
export interface SMTPServerAsPromisedOptions extends SMTPServerOptions {
host?: string
port?: number
backlog?: number
onAuth?: (auth: SMTPServerAuthentication, session: SMTPServerSession) => Promise<SMTPServerAuthenticationResponse>
onClose?: (session: SMTPServerSession) => Promise<void>
onConnect?: (session: SMTPServerSession) => Promise<void>
onData?: (stream: Readable, session: SMTPServerSession) => Promise<void>
onMailFrom?: (address: SMTPServerAddress, session: SMTPServerSession) => Promise<void>
onRcptTo?: (address: SMTPServerAddress, session: SMTPServerSession) => Promise<void>
onError?: (error: Error) => Promise<void>
onAuth?: (auth: SMTPServerAuthentication, session: SMTPServerSession) => Promise<SMTPServerAuthenticationResponse>;
onClose?: (session: SMTPServerSession) => Promise<void>;
onConnect?: (session: SMTPServerSession) => Promise<void>;
onData?: (stream: Readable, session: SMTPServerSession) => Promise<void>;
onMailFrom?: (address: SMTPServerAddress, session: SMTPServerSession) => Promise<void>;
onRcptTo?: (address: SMTPServerAddress, session: SMTPServerSession) => Promise<void>;
onError?: (error: Error) => Promise<void>;
}
export class SMTPServerAsPromised {
server: SMTPServer
constructor (options: SMTPServerAsPromisedOptions)
listen (port?: number, hostname?: string, backlog?: number): Promise<SMTPServerAsPromisedServerAddress>
listen (port?: number, hostname?: string): Promise<SMTPServerAsPromisedServerAddress>
listen (port?: number, backlog?: number): Promise<SMTPServerAsPromisedServerAddress>
listen (port?: number): Promise<SMTPServerAsPromisedServerAddress>
listen (path: string, backlog?: number): Promise<SMTPServerAsPromisedServerAddress>
listen (path: string): Promise<SMTPServerAsPromisedServerAddress>
listen (options: net.ListenOptions): Promise<SMTPServerAsPromisedServerAddress>
listen (handle: any, backlog?: number): Promise<SMTPServerAsPromisedServerAddress>
listen (handle: any): Promise<SMTPServerAsPromisedServerAddress>
close (): Promise<void>
updateSecureContext (options: tls.TlsOptions): void
export declare class SMTPServerAsPromised {
server: SMTPServer;
protected onError?: (error: Error) => Promise<void>;
constructor(options?: SMTPServerAsPromisedOptions);
listen(options?: net.ListenOptions): Promise<SMTPServerAsPromisedServerAddress>;
close(): Promise<void>;
updateSecureContext(options: tls.TlsOptions): void;
}
export default SMTPServerAsPromised
export default SMTPServerAsPromised;

@@ -1,97 +0,92 @@

'use strict'
const SMTPServer = require('smtp-server').SMTPServer
"use strict";
/// <reference types="node" />
/// <reference types="nodemailer" />
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const smtp_server_1 = require("smtp-server");
tslib_1.__exportStar(require("smtp-server"), exports);
class SMTPServerAsPromised {
constructor (options) {
options = options || {}
this.options = options
if (options.onConnect) {
const handler = options.onConnect
options.onConnect = (session, callback) => handler(session)
.then(() => callback())
.catch((err) => callback(err))
constructor(options = {}) {
const smtpSeverOptions = Object.assign({}, options);
if (options.onConnect) {
const handlerWithPromise = options.onConnect;
const handlerWithCallback = (session, callback) => handlerWithPromise(session)
.then(() => callback())
.catch((err) => callback(err));
smtpSeverOptions.onConnect = handlerWithCallback;
}
if (options.onAuth) {
const handlerWithPromise = options.onAuth;
const handlerWithCallback = (auth, session, callback) => handlerWithPromise(auth, session)
.then((response) => callback(null, response))
.catch((err) => callback(err));
smtpSeverOptions.onAuth = handlerWithCallback;
}
if (options.onMailFrom) {
const handlerWithPromise = options.onMailFrom;
const handlerWithCallback = (address, session, callback) => handlerWithPromise(address, session)
.then(() => callback())
.catch((err) => callback(err));
smtpSeverOptions.onMailFrom = handlerWithCallback;
}
if (options.onRcptTo) {
const handlerWithPromise = options.onRcptTo;
const handlerWithCallback = (address, session, callback) => handlerWithPromise(address, session)
.then(() => callback())
.catch((err) => callback(err));
smtpSeverOptions.onRcptTo = handlerWithCallback;
}
if (options.onData) {
const handlerWithPromise = options.onData;
const handlerWithCallback = (stream, session, callback) => handlerWithPromise(stream, session)
.then(() => callback())
.catch((err) => callback(err));
smtpSeverOptions.onData = handlerWithCallback;
}
if (options.onClose) {
const handlerWithPromise = options.onClose;
const handlerWithCallback = (session) => handlerWithPromise(session);
smtpSeverOptions.onClose = handlerWithCallback;
}
this.server = new smtp_server_1.SMTPServer(smtpSeverOptions);
if (options.onError) {
this.onError = options.onError;
this.server.on('error', this.onError);
}
}
if (options.onAuth) {
const handler = options.onAuth
options.onAuth = (auth, session, callback) => handler(auth, session)
.then((response) => callback(null, response))
.catch((err) => callback(err))
listen(options = {}) {
return new Promise((resolve, reject) => {
const netServer = this.server.server;
const listeningHandler = () => {
netServer.removeListener('error', errorHandler);
const address = netServer.address();
resolve(address);
};
const errorHandler = (err) => {
netServer.removeListener('listening', listeningHandler);
reject(err);
};
netServer.once('listening', listeningHandler);
netServer.once('error', errorHandler);
this.server.listen(options);
});
}
if (options.onMailFrom) {
const handler = options.onMailFrom
options.onMailFrom = (from, session, callback) => handler(from, session)
.then(() => callback())
.catch((err) => callback(err))
close() {
return new Promise((resolve, reject) => {
this.server.close((err) => {
if (err) {
return reject(err);
}
if (this.onError) {
this.server.removeListener('error', this.onError);
}
resolve();
});
});
}
if (options.onRcptTo) {
const handler = options.onRcptTo
options.onRcptTo = (to, session, callback) => handler(to, session)
.then(() => callback())
.catch((err) => callback(err))
updateSecureContext(options) {
this.server.updateSecureContext(options);
}
if (options.onData) {
const handler = options.onData
options.onData = (stream, session, callback) => handler(stream, session)
.then(() => callback())
.catch((err) => callback(err))
}
if (options.onClose) {
const handler = options.onClose
options.onClose = (session) => handler(session)
}
this.server = new SMTPServer(options)
if (options.onError) {
this.server.on('error', options.onError)
}
}
listen (port, host, backlog) {
port = port || this.options.port
host = host || this.options.host
backlog = backlog || this.options.backlog
return new Promise((resolve, reject) => {
const netServer = this.server.server
const listeningHandler = () => {
netServer.removeListener('error', errorHandler)
resolve(netServer.address())
}
const errorHandler = (err) => {
netServer.removeListener('listening', listeningHandler)
reject(err)
}
netServer.once('listening', listeningHandler)
netServer.once('error', errorHandler)
// node < 7 doesn't accept undefined as port number
this.server.listen(Number.isInteger(port) ? port : Number.isInteger(this.port) ? this.port : 0, this.host, this.backlog)
})
}
close () {
return new Promise((resolve, reject) => {
this.server.close(() => {
const options = this.options
if (options.onError) {
this.server.removeListener('error', options.onError)
}
resolve()
})
})
}
updateSecureContext (options) {
this.server.updateSecureContext(options)
}
}
SMTPServerAsPromised.SMTPServerAsPromised = SMTPServerAsPromised
module.exports = SMTPServerAsPromised
exports.SMTPServerAsPromised = SMTPServerAsPromised;
exports.default = SMTPServerAsPromised;
{
"name": "smtp-server-as-promised",
"version": "3.3.2",
"version": "4.0.0",
"description": "Promisify smtp-server module",

@@ -23,48 +23,57 @@ "main": "lib/smtp-server-as-promised.js",

"engines": {
"node": ">=5.0.0"
"node": ">=6.0.0"
},
"dependencies": {
"smtp-server": "^3.4.1"
"smtp-server": "^3.4.7",
"tslib": "^1.9.3"
},
"devDependencies": {
"@types/node": "^9.4.7",
"@types/nodemailer": "^4.6.0",
"@types/smtp-server": "^3.3.5",
"@types/chai": "^4.1.4",
"@types/chai-as-promised": "^7.1.0",
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.4",
"@types/nodemailer": "^4.6.2",
"@types/semver": "^5.5.0",
"@types/smtp-server": "^3.4.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"null-writable": "^0.2.0",
"onchange": "^3.3.0",
"promise-readable": "^3.1.3",
"promise-socket": "^3.0.1",
"snazzy": "^7.1.1",
"standard": "^11.0.0",
"tap": "^11.1.2",
"tap-given": "^0.6.0",
"tslint": "^5.9.1",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.7.2"
"coveralls": "^3.0.2",
"eslint": "^5.5.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"markdownlint-cli": "^0.13.0",
"mocha": "^5.2.0",
"null-writable": "^1.0.0",
"nyc": "^13.0.1",
"promise-readable": "^3.1.5",
"promise-socket": "^3.1.1",
"semver": "^5.5.1",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.0.3"
},
"scripts": {
"pretest": "standard --verbose | snazzy && tsc --noEmit --pretty && tslint -t stylish -p .",
"test": "tap test/*.js",
"test:coverage": "npm test -- --coverage",
"test:onchange:lcovonly": "npm run -s test-coverage -- -R min --coverage-report lcovonly; onchange '**/*.js' -- npm run -s test-coverage -- -R min --coverage-report lcovonly",
"update": "npm run update:upgrade && npm run update:reinstall",
"update:upgrade": "ncu --upgrade --upgradeAll",
"update:reinstall": "rm -f package-lock.json && rm -rf node_modules && npm cache clear --force && npm install"
"build": "tsc --pretty",
"clean": "rimraf lib",
"postpublish": "git tag v$npm_package_version -a -m \"Release $npm_package_version\" && git push --tags",
"prepublishOnly": "npm run build",
"pretest": "npm run build && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && markdownlint \"*.md\"",
"test": "npm run test:spec",
"test:spec": "npm run ts-mocha -- \"test/*.ts\"",
"test:coverage": "nyc --reporter json npm run test:spec && nyc report",
"ts-mocha": "mocha --use_strict --throw-deprecation --require source-map-support/register --require ts-node/register --timeout 90000"
},
"standard": {
"globals": [
"After",
"And",
"Feature",
"Given",
"Scenario",
"Then",
"When"
"nyc": {
"extension": [
".ts"
],
"exclude": [
".*.js",
"**/*.d.ts"
]
},
"nyc": {
"exclude": []
}
}
# smtp-server-as-promised
<!-- markdownlint-disable MD013 -->
[![Build Status](https://secure.travis-ci.org/dex4er/js-smtp-server-as-promised.svg)](http://travis-ci.org/dex4er/js-smtp-server-as-promised) [![Coverage Status](https://coveralls.io/repos/github/dex4er/js-smtp-server-as-promised/badge.svg)](https://coveralls.io/github/dex4er/js-smtp-server-as-promised) [![npm](https://img.shields.io/npm/v/smtp-server-as-promised.svg)](https://www.npmjs.com/package/smtp-server-as-promised)
<!-- markdownlint-enable MD013 -->

@@ -13,3 +15,3 @@ This module provides promisified version of

This module requires Node >= 5. For Node < 6 `--harmony` flag is required.
This module requires Node >= 6.

@@ -22,2 +24,20 @@ ## Installation

_Additionally for Typescript:_
```shell
npm install -D @types/node @types/nodemailer
```
Transpiling this module with own settings in `tsconfig.json`:
```json
{
"compilerOptions": {
"paths": {
"smtp-server-as-promised": ["node_modules/smtp-server-as-promised/src/smtp-server-as-promised"]
}
}
}
```
## Usage

@@ -28,3 +48,3 @@

```js
const SMTPServerAsPromised = require('smtp-server-as-promised')
const { SMTPServerAsPromised } = require('smtp-server-as-promised')
```

@@ -50,3 +70,2 @@

const server = new SMTPServerAsPromised({
port: 2525,
onConnect, onMailFrom, onData, onError

@@ -56,5 +75,4 @@ })

Options are the same as for original `smtp-server` constructor. Additionally the
default `host`, `port` and `backlog` might be provided for `listen` method.
Callback handlers are `Promise` objects or `async` functions:
Options are the same as for original `smtp-server` constructor. Callback
handlers are `Promise` objects or `async` functions:

@@ -71,2 +89,4 @@ ### onConnect

<!-- markdownlint-disable MD013 -->
```js

@@ -82,2 +102,4 @@ async function onAuth (auth, session) {

<!-- markdownlint-enable MD013 -->
This method must return the object with `user` property.

@@ -111,2 +133,4 @@

<!-- markdownlint-disable MD013 -->
```js

@@ -126,2 +150,4 @@ async function onData (stream, session) {

<!-- markdownlint-enable MD013 -->
`stream` object is a standard

@@ -137,3 +163,3 @@ [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)

```js
const NullWritable = require('null-writable')
const { NullWritable } = require('null-writable')

@@ -161,7 +187,8 @@ async function onData (stream, session) {

```js
const promise = server.listen(port[,host][,backlog])
const promise = server.listen(options)
```
Start the server instance. This method returns promise which returns `address`
as its value.
Start the server instance. Argument is the same as for
[`net.listen`](https://nodejs.org/api/net.html#net_server_listen_options_callback)
method. This method returns promise which resolves to `address` value.

@@ -172,3 +199,3 @@ _Example:_

async function main () {
const address = await server.listen(2525)
const address = await server.listen({ port: 2525 })
console.log(`Listening on [${address.address}]:${address.port}`)

@@ -175,0 +202,0 @@ }

{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"importHelpers": true,
"lib": [
"es6"
],
"module": "commonjs",
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./lib",
"target": "es6",
"strict": true,
"target": "ES2017"
}
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"./examples/**/*",
"./lib/**/*",
"./test/**/*"
]
}
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