Updates
This commit is contained in:
+35
-52
@@ -1,55 +1,38 @@
|
||||
"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.default = validateEmail;
|
||||
const handleNodemailer_1 = __importDefault(require("../../backend/handleNodemailer"));
|
||||
const email_mx_lookup_1 = __importDefault(require("../verification/email-mx-lookup"));
|
||||
const email_regex_test_1 = __importDefault(require("../verification/email-regex-test"));
|
||||
function validateEmail(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ email, welcomeEmailOptions, }) {
|
||||
var _b;
|
||||
if (!email) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email is required.",
|
||||
};
|
||||
}
|
||||
if (!(0, email_regex_test_1.default)(email)) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Invalid email format.",
|
||||
};
|
||||
}
|
||||
const checkEmailMxRecords = yield (0, email_mx_lookup_1.default)(email);
|
||||
if (!checkEmailMxRecords) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email domain does not have valid MX records.",
|
||||
};
|
||||
}
|
||||
if (welcomeEmailOptions) {
|
||||
const welcomeEmail = yield (0, handleNodemailer_1.default)(welcomeEmailOptions);
|
||||
if (!((_b = welcomeEmail === null || welcomeEmail === void 0 ? void 0 : welcomeEmail.accepted) === null || _b === void 0 ? void 0 : _b[0])) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email verification failed.",
|
||||
};
|
||||
}
|
||||
}
|
||||
import handleNodemailer from "../../backend/handleNodemailer";
|
||||
import emailMxLookup from "../verification/email-mx-lookup";
|
||||
import emailRegexCheck from "../verification/email-regex-test";
|
||||
export default async function validateEmail({ email, welcomeEmailOptions, }) {
|
||||
var _a;
|
||||
if (!email) {
|
||||
return {
|
||||
isValid: true,
|
||||
message: "Email is valid.",
|
||||
isValid: false,
|
||||
message: "Email is required.",
|
||||
};
|
||||
});
|
||||
}
|
||||
if (!emailRegexCheck(email)) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Invalid email format.",
|
||||
};
|
||||
}
|
||||
const checkEmailMxRecords = await emailMxLookup(email);
|
||||
if (!checkEmailMxRecords) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email domain does not have valid MX records.",
|
||||
};
|
||||
}
|
||||
if (welcomeEmailOptions) {
|
||||
const welcomeEmail = await handleNodemailer(welcomeEmailOptions);
|
||||
if (!((_a = welcomeEmail === null || welcomeEmail === void 0 ? void 0 : welcomeEmail.accepted) === null || _a === void 0 ? void 0 : _a[0])) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email verification failed.",
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
isValid: true,
|
||||
message: "Email is valid.",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = emailMxLookup;
|
||||
const dns_1 = __importDefault(require("dns"));
|
||||
const debug_log_1 = __importDefault(require("../../../utils/logging/debug-log"));
|
||||
function emailMxLookup(email, debug) {
|
||||
import dns from "dns";
|
||||
import debugLog from "../../../utils/logging/debug-log";
|
||||
export default function emailMxLookup(email, debug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!email) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
const domain = email.split("@")[1];
|
||||
dns_1.default.resolveMx(domain, (err, addresses) => {
|
||||
dns.resolveMx(domain, (err, addresses) => {
|
||||
if (err || !addresses.length) {
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
debugLog({
|
||||
log: (err === null || err === void 0 ? void 0 : err.message) || "No MX records found",
|
||||
addTime: true,
|
||||
label: "Email MX Lookup",
|
||||
@@ -27,7 +21,7 @@ function emailMxLookup(email, debug) {
|
||||
}
|
||||
else {
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
debugLog({
|
||||
log: addresses,
|
||||
addTime: true,
|
||||
label: "MX Records",
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = emailRegexCheck;
|
||||
function emailRegexCheck(email) {
|
||||
export default function emailRegexCheck(email) {
|
||||
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return regex.test(email);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = verifyEmailSMTP;
|
||||
const net_1 = __importDefault(require("net"));
|
||||
const dns_1 = __importDefault(require("dns"));
|
||||
function verifyEmailSMTP(email) {
|
||||
import net from "net";
|
||||
import dns from "dns";
|
||||
export default function verifyEmailSMTP(email) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const domain = email.split("@")[1];
|
||||
dns_1.default.resolveMx(domain, (err, addresses) => {
|
||||
dns.resolveMx(domain, (err, addresses) => {
|
||||
if (err || !addresses.length) {
|
||||
console.log("Invalid email domain.");
|
||||
return;
|
||||
}
|
||||
const mxServer = addresses[0].exchange;
|
||||
console.log(`Connecting to ${mxServer} to verify email...`);
|
||||
const client = net_1.default.createConnection(25, mxServer);
|
||||
const client = net.createConnection(25, mxServer);
|
||||
client.on("connect", () => {
|
||||
console.log("Connected to SMTP server.");
|
||||
client.write("HELO example.com\r\n");
|
||||
|
||||
Reference in New Issue
Block a user