1
0
mirror of https://github.com/eleith/emailjs.git synced 2024-07-05 20:10:37 +00:00

smtp: stricten property access modifiers

This commit is contained in:
Zack Schuster 2020-05-01 13:30:22 -07:00
parent dc1bd28e73
commit 3c1681c0fb
4 changed files with 30 additions and 28 deletions

View File

@ -17,11 +17,12 @@ export interface MessageStack {
} }
export class Client { export class Client {
public smtp: SMTPConnection; public readonly smtp: SMTPConnection;
public queue: MessageStack[] = []; public readonly queue: MessageStack[] = [];
public timer: NodeJS.Timer | null = null;
public sending = false; protected sending = false;
public ready = false; protected ready = false;
protected timer: NodeJS.Timer | null = null;
/** /**
* @param {SMTPConnectionOptions} server smtp options * @param {SMTPConnectionOptions} server smtp options

View File

@ -93,16 +93,16 @@ function convertDashDelimitedTextToSnakeCase(text: string) {
} }
export class Message { export class Message {
attachments: any[] = []; public readonly attachments: any[] = [];
alternative: AlternateMessageAttachment | null = null; public readonly header: Partial<MessageHeaders> = {
header: Partial<MessageHeaders> = {
'message-id': `<${new Date().getTime()}.${counter++}.${ 'message-id': `<${new Date().getTime()}.${counter++}.${
process.pid process.pid
}@${hostname()}>`, }@${hostname()}>`,
date: getRFC2822Date(), date: getRFC2822Date(),
}; };
content = 'text/plain; charset=utf-8'; public readonly content = 'text/plain; charset=utf-8';
text?: string; public readonly text?: string;
public alternative: AlternateMessageAttachment | null = null;
constructor(headers: Partial<MessageHeaders>) { constructor(headers: Partial<MessageHeaders>) {
for (const header in headers) { for (const header in headers) {

View File

@ -3,7 +3,7 @@ import type { Socket } from 'net'; // eslint-disable-line no-unused-vars
import type { TLSSocket } from 'tls'; // eslint-disable-line no-unused-vars import type { TLSSocket } from 'tls'; // eslint-disable-line no-unused-vars
export class SMTPResponse { export class SMTPResponse {
public stop: (err?: Error) => void; public readonly stop: (err?: Error) => void;
constructor( constructor(
stream: Socket | TLSSocket, stream: Socket | TLSSocket,

View File

@ -91,24 +91,30 @@ export interface ConnectOptions {
} }
export class SMTPConnection extends EventEmitter { export class SMTPConnection extends EventEmitter {
private _state: 0 | 1 | 2 = SMTPState.NOTCONNECTED; public readonly user: () => string;
private _secure = false; public readonly password: () => string;
public readonly timeout: number = DEFAULT_TIMEOUT;
protected readonly log = log;
protected readonly authentication: (keyof typeof AUTH_METHODS)[] = [
AUTH_METHODS['CRAM-MD5'],
AUTH_METHODS.LOGIN,
AUTH_METHODS.PLAIN,
AUTH_METHODS.XOAUTH2,
];
protected _state: 0 | 1 | 2 = SMTPState.NOTCONNECTED;
protected _secure = false;
protected loggedin = false;
protected sock: Socket | TLSSocket | null = null; protected sock: Socket | TLSSocket | null = null;
protected features: Indexed<string | boolean> | null = null; protected features: Indexed<string | boolean> | null = null;
protected monitor: SMTPResponse | null = null; protected monitor: SMTPResponse | null = null;
protected authentication: (keyof typeof AUTH_METHODS)[];
protected domain = hostname(); protected domain = hostname();
protected host = 'localhost'; protected host = 'localhost';
protected ssl: boolean | SMTPSocketOptions = false; protected ssl: boolean | SMTPSocketOptions = false;
protected tls: boolean | SMTPSocketOptions = false; protected tls: boolean | SMTPSocketOptions = false;
protected port: number; protected port: number;
protected loggedin = false;
protected log = log;
public user: () => string;
public password: () => string;
public timeout: number = DEFAULT_TIMEOUT;
/** /**
* SMTP class written using python's (2.7) smtplib.py as a base * SMTP class written using python's (2.7) smtplib.py as a base
@ -127,14 +133,9 @@ export class SMTPConnection extends EventEmitter {
}: Partial<SMTPConnectionOptions> = {}) { }: Partial<SMTPConnectionOptions> = {}) {
super(); super();
this.authentication = Array.isArray(authentication) if (Array.isArray(authentication)) {
? authentication this.authentication = authentication;
: [ }
AUTH_METHODS['CRAM-MD5'],
AUTH_METHODS.LOGIN,
AUTH_METHODS.PLAIN,
AUTH_METHODS.XOAUTH2,
];
if (typeof timeout === 'number') { if (typeof timeout === 'number') {
this.timeout = timeout; this.timeout = timeout;