fix: handle potential undefined domain (#178)
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user