mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #32335 from dex4er/smtp-server
smtp-server: onData stream object provides additional properties
This commit is contained in:
Vendored
+17
-4
@@ -1,4 +1,4 @@
|
||||
// Type definitions for smtp-server 3.4
|
||||
// Type definitions for smtp-server 3.5
|
||||
// Project: https://github.com/nodemailer/smtp-server
|
||||
// Definitions by: markisme <https://github.com/markisme>
|
||||
// taisiias <https://github.com/Taisiias>
|
||||
@@ -12,7 +12,7 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import * as net from 'net';
|
||||
import * as shared from 'nodemailer/lib/shared';
|
||||
import { Readable } from 'stream';
|
||||
import { PassThrough } from 'stream';
|
||||
import * as tls from 'tls';
|
||||
|
||||
export type ms = number;
|
||||
@@ -113,6 +113,19 @@ export interface SMTPServerSession {
|
||||
tlsOptions: tls.TlsOptions;
|
||||
}
|
||||
|
||||
export interface SMTPServerDataStream extends PassThrough {
|
||||
/**
|
||||
* number of bytes read from DATA stream
|
||||
*/
|
||||
byteLength: number;
|
||||
/**
|
||||
* boolean, if set to true, the message was oversized.
|
||||
* When creating the server you can define maximum allowed message size with
|
||||
* the size option, see RFC1870 for details.
|
||||
*/
|
||||
sizeExceeded: boolean;
|
||||
}
|
||||
|
||||
export interface SMTPServerEnvelope {
|
||||
/**
|
||||
* includes an address object or is set to false
|
||||
@@ -270,7 +283,7 @@ export interface SMTPServerOptions extends tls.TlsOptions {
|
||||
/**
|
||||
* the callback to handle incoming messages ([see details](https://github.com/andris9/smtp-server#processing-incoming-message))
|
||||
*/
|
||||
onData?(stream: Readable, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
|
||||
onData?(stream: SMTPServerDataStream, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
|
||||
/**
|
||||
* the callback that informs about closed client connection
|
||||
*/
|
||||
@@ -310,7 +323,7 @@ export class SMTPServer extends EventEmitter {
|
||||
/** Override this */
|
||||
onConnect(session: SMTPServerSession, callback: (err?: Error | null) => void): void;
|
||||
/** Override this */
|
||||
onData(stream: Readable, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
|
||||
onData(stream: SMTPServerDataStream, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
|
||||
/** Override this */
|
||||
onMailFrom(address: SMTPServerAddress, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
|
||||
/** Override this */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AddressInfo } from 'net';
|
||||
import { SMTPServer, SMTPServerAddress, SMTPServerAuthentication, SMTPServerAuthenticationResponse, SMTPServerOptions, SMTPServerSession } from 'smtp-server';
|
||||
import { SMTPServer, SMTPServerAddress, SMTPServerAuthentication, SMTPServerAuthenticationResponse, SMTPServerDataStream, SMTPServerOptions, SMTPServerSession } from 'smtp-server';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
function test_with_handlers_as_options() {
|
||||
@@ -42,9 +42,14 @@ function test_with_handlers_as_options() {
|
||||
callback();
|
||||
}
|
||||
|
||||
function onData(stream: Readable, session: SMTPServerSession, callback: (err?: Error) => void): void {
|
||||
function onData(stream: SMTPServerDataStream, session: SMTPServerSession, callback: (err?: Error) => void): void {
|
||||
console.log(`[${session.id}] onData started`);
|
||||
|
||||
if (stream.sizeExceeded) {
|
||||
callback(new Error('Message too big'));
|
||||
return;
|
||||
}
|
||||
|
||||
let messageLength = 0;
|
||||
|
||||
stream.on('data', (chunk: Buffer) => {
|
||||
|
||||
Reference in New Issue
Block a user