This commit is contained in:
quoije
2023-05-10 21:03:22 -04:00
parent ef1b411c12
commit bd732815c7
1304 changed files with 192970 additions and 5407 deletions
+25
View File
@@ -0,0 +1,25 @@
/// <reference types="node" />
export declare const ErrorCodes: {
211: string;
214: string;
220: string;
221: string;
250: string;
251: string;
354: string;
421: string;
450: string;
451: string;
452: string;
500: string;
501: string;
502: string;
503: string;
504: string;
550: string;
551: string;
552: string;
553: string;
554: string;
};
export declare const hasCode: (message: Buffer, code: keyof typeof ErrorCodes) => boolean;
+30
View File
@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasCode = exports.ErrorCodes = void 0;
exports.ErrorCodes = {
211: 'SMTP Error: A system status or help reply.',
214: 'SMTP Error: Help Message.',
220: 'SMTP Error: The server is ready.',
221: 'SMTP Error: The server is ending the conversation.',
250: 'SMTP Error: The requested action was completed.',
251: 'SMTP Error: The specified user is not local, but the server will forward the mail message.',
354: 'SMTP Error: This is a reply to the DATA command. After getting this, start sending the body of the mail message, ending with "\r\n.\r\n."',
421: 'SMTP Error: The mail server will be shut down. Save the mail message and try again later.',
450: 'SMTP Error: The mailbox that you are trying to reach is busy. Wait a little while and try again.',
451: 'SMTP Error: The requested action was not done. Some error occurmiles in the mail server.',
452: 'SMTP Error: The requested action was not done. The mail server ran out of system storage.',
500: 'SMTP Error: The last command contained a syntax error or the command line was too long.',
501: 'SMTP Error: The parameters or arguments in the last command contained a syntax error.',
502: 'SMTP Error: The mail server has not implemented the last command.',
503: 'SMTP Error: The last command was sent out of sequence. For example, you might have sent DATA before sending RECV.',
504: 'SMTP Error: One of the parameters of the last command has not been implemented by the server.',
550: "SMTP Error: The mailbox that you are trying to reach can't be found or you don't have access rights.",
551: 'SMTP Error: The specified user is not local; part of the text of the message will contain a forwarding address.',
552: 'SMTP Error: The mailbox that you are trying to reach has run out of space. Store the message and try again tomorrow or in a few days-after the user gets a chance to delete some messages.',
553: 'SMTP Error: The mail address that you specified was not syntactically correct.',
554: 'SMTP Error: The mail transaction has failed for unknown causes.',
};
exports.hasCode = (message, code) => {
return message.indexOf(`${code}`) === 0 || message.indexOf(`${code}\n`) > -1;
};
//# sourceMappingURL=errorCodes.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"errorCodes.js","sourceRoot":"","sources":["../../src/smtp/errorCodes.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACxB,GAAG,EAAE,4CAA4C;IACjD,GAAG,EAAE,2BAA2B;IAChC,GAAG,EAAE,kCAAkC;IACvC,GAAG,EAAE,oDAAoD;IACzD,GAAG,EAAE,iDAAiD;IACtD,GAAG,EAAE,4FAA4F;IACjG,GAAG,EAAE,2IAA2I;IAChJ,GAAG,EAAE,2FAA2F;IAChG,GAAG,EAAE,kGAAkG;IACvG,GAAG,EAAE,0FAA0F;IAC/F,GAAG,EAAE,2FAA2F;IAChG,GAAG,EAAE,yFAAyF;IAC9F,GAAG,EAAE,uFAAuF;IAC5F,GAAG,EAAE,mEAAmE;IACxE,GAAG,EAAE,mHAAmH;IACxH,GAAG,EAAE,+FAA+F;IACpG,GAAG,EAAE,sGAAsG;IAC3G,GAAG,EAAE,iHAAiH;IACtH,GAAG,EAAE,4LAA4L;IACjM,GAAG,EAAE,gFAAgF;IACrF,GAAG,EAAE,iEAAiE;CACvE,CAAA;AAEY,QAAA,OAAO,GAAG,CACrB,OAAe,EACf,IAA6B,EACpB,EAAE;IACX,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAC9E,CAAC,CAAA"}
+2
View File
@@ -0,0 +1,2 @@
import { OutputFormat } from '../output/output';
export declare const checkSMTP: (sender: string, recipient: string, exchange: string) => Promise<OutputFormat>;
+96
View File
@@ -0,0 +1,96 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkSMTP = void 0;
const net_1 = __importDefault(require("net"));
const output_1 = require("../output/output");
const errorCodes_1 = require("./errorCodes");
const log = (...args) => {
if (process.env.DEBUG === 'true') {
console.log(...args);
}
};
exports.checkSMTP = (sender, recipient, exchange) => __awaiter(void 0, void 0, void 0, function* () {
const timeout = 1000 * 10; // 10 seconds
return new Promise(r => {
let receivedData = false;
const socket = net_1.default.createConnection(25, exchange);
socket.setEncoding('ascii');
socket.setTimeout(timeout);
socket.on('error', error => {
log('error', error);
socket.emit('fail', error);
});
socket.on('close', hadError => {
if (!receivedData && !hadError) {
socket.emit('fail', 'Mail server closed connection without sending any data.');
}
});
socket.once('fail', msg => {
r(output_1.createOutput('smtp', msg));
if (socket.writable && !socket.destroyed) {
socket.write(`quit\r\n`);
socket.end();
socket.destroy();
}
});
socket.on('success', () => {
if (socket.writable && !socket.destroyed) {
socket.write(`quit\r\n`);
socket.end();
socket.destroy();
}
r(output_1.createOutput());
});
const commands = [
`helo ${exchange}\r\n`,
`mail from: <${sender}>\r\n`,
`rcpt to: <${recipient}>\r\n`,
];
let i = 0;
socket.on('next', () => {
if (i < 3) {
if (socket.writable) {
socket.write(commands[i++]);
}
else {
socket.emit('fail', 'SMTP communication unexpectedly closed.');
}
}
else {
socket.emit('success');
}
});
socket.on('timeout', () => {
socket.emit('fail', 'Timeout');
});
socket.on('connect', () => {
socket.on('data', msg => {
receivedData = true;
log('data', msg);
if (errorCodes_1.hasCode(msg, 220) || errorCodes_1.hasCode(msg, 250)) {
socket.emit('next', msg);
}
else if (errorCodes_1.hasCode(msg, 550)) {
socket.emit('fail', 'Mailbox not found.');
}
else {
const [code] = Object.typedKeys(errorCodes_1.ErrorCodes).filter(x => errorCodes_1.hasCode(msg, x));
socket.emit('fail', errorCodes_1.ErrorCodes[code] || 'Unrecognized SMTP response.');
}
});
});
});
});
//# sourceMappingURL=smtp.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"smtp.js","sourceRoot":"","sources":["../../src/smtp/smtp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAAqB;AACrB,6CAA6D;AAC7D,6CAAkD;AAElD,MAAM,GAAG,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;IACjC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,MAAM,EAAE;QAChC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;KACrB;AACH,CAAC,CAAA;AAEY,QAAA,SAAS,GAAG,CACvB,MAAc,EACd,SAAiB,EACjB,QAAgB,EACO,EAAE;IACzB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAE,CAAA,CAAC,aAAa;IACvC,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE;QACrB,IAAI,YAAY,GAAY,KAAK,CAAC;QAClC,MAAM,MAAM,GAAG,aAAG,CAAC,gBAAgB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;QACjD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAC3B,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QAC1B,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE;YACzB,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;YACnB,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;QACF,MAAM,CAAC,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