fix: handle potential undefined domain (#178)

This commit is contained in:
KM Koushik
2025-06-16 21:48:19 +10:00
committed by GitHub
parent 629f09100a
commit 0bc75e4474

View File

@@ -9,9 +9,17 @@ import { UnsendApiError } from "../public-api/api-error";
const dnsResolveTxt = util.promisify(dns.resolveTxt);
export async function validateDomainFromEmail(email: string, teamId: number) {
// Extract email from format like 'Name <email@domain>' this will allow entries such as "Someone @ something <some@domain.com>" to parse correctly as well.
const match = email.match(/<([^>]+)>/);
let fromDomain = match ? match[1].split("@")[1] : email.split("@")[1];
// Extract email from format like 'Name <email@domain>' this will allow entries such as "Someone @ something <some@domain.com>" to parse correctly as well.
const match = email.match(/<([^>]+)>/);
let fromDomain: string | undefined;
if (match && match[1]) {
const parts = match[1].split("@");
fromDomain = parts.length > 1 ? parts[1] : undefined;
} else {
const parts = email.split("@");
fromDomain = parts.length > 1 ? parts[1] : undefined;
}
if (fromDomain?.endsWith(">")) {
fromDomain = fromDomain.slice(0, -1);