Skip to content

Commit 50b9ec1

Browse files
committed
typescript: naive zero-build-error port
1 parent cc08daa commit 50b9ec1

File tree

9 files changed

+406
-523
lines changed

9 files changed

+406
-523
lines changed

email.js renamed to email.ts

File renamed without changes.

smtp/client.js renamed to smtp/client.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import addressparser from 'addressparser';
2-
import { Message, create } from './message.js';
2+
import { Message, create, MessageAttachment } from './message.js';
33
import { SMTP, SMTPState } from './smtp.js';
44

5+
export interface MessageStack {
6+
callback: (error: Error, message: Message) => void;
7+
message: Message;
8+
attachment: MessageAttachment;
9+
text: string;
10+
returnPath: string;
11+
from: string;
12+
to: string | string[];
13+
cc: string[];
14+
bcc: string[];
15+
}
16+
517
class Client {
18+
public smtp: SMTP;
19+
public queue: any[];
20+
public timer: any;
21+
public sending: boolean;
22+
public ready: boolean;
23+
624
/**
725
* @typedef {Object} MessageStack
8-
* @property {function(Error, Message): void} [callback]
9-
* @property {Message} [message]
10-
* @property {string} [returnPath]
11-
* @property {string} [from]
12-
* @property {string} [subject]
13-
* @property {string|Array} [to]
14-
* @property {Array} [cc]
15-
* @property {Array} [bcc]
16-
* @property {string} [text]
17-
* @property {*} [attachment]
1826
*
1927
* @typedef {Object} SMTPSocketOptions
2028
* @property {string} key
File renamed without changes.

smtp/error.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

smtp/error.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class SMTPError extends Error {
2+
public code: number | null = null;
3+
public smtp: any = null;
4+
public previous: Error | null = null;
5+
}
6+
7+
export function makeSMTPError(message: string, code: number, error?: Error, smtp?: any) {
8+
const msg = error != null && error.message ? `${message} (${error.message})` : message;
9+
const err = new SMTPError(msg);
10+
11+
err.code = code;
12+
err.smtp = smtp;
13+
14+
if (error) {
15+
err.previous = error;
16+
}
17+
18+
return err;
19+
};
20+
21+
export const enum SMTPErrorStates {
22+
COULDNOTCONNECT = 1,
23+
BADRESPONSE = 2,
24+
AUTHFAILED = 3,
25+
TIMEDOUT = 4,
26+
ERROR = 5,
27+
NOCONNECTION = 6,
28+
AUTHNOTSUPPORTED = 7,
29+
CONNECTIONCLOSED = 8,
30+
CONNECTIONENDED = 9,
31+
CONNECTIONAUTH = 10,
32+
}

0 commit comments

Comments
 (0)