update
This commit is contained in:
@ -100,7 +100,35 @@ export function isValidEmail(email: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
return SMTP_PATTERNS.EMAIL.test(email);
|
||||
// Basic pattern check
|
||||
if (!SMTP_PATTERNS.EMAIL.test(email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Additional validation for common invalid patterns
|
||||
const [localPart, domain] = email.split('@');
|
||||
|
||||
// Check for double dots
|
||||
if (email.includes('..')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check domain doesn't start or end with dot
|
||||
if (domain && (domain.startsWith('.') || domain.endsWith('.'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check local part length (max 64 chars per RFC)
|
||||
if (localPart && localPart.length > 64) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check domain length (max 253 chars per RFC - accounting for trailing dot)
|
||||
if (domain && domain.length > 253) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,7 +188,7 @@ export function validateMailFrom(args: string): {
|
||||
|
||||
// During testing, we should validate the email format
|
||||
// Check for basic email format (something@somewhere)
|
||||
if (!SMTP_PATTERNS.EMAIL.test(emailPart)) {
|
||||
if (!isValidEmail(emailPart)) {
|
||||
return { isValid: false, errorMessage: 'Invalid email address format' };
|
||||
}
|
||||
|
||||
@ -185,7 +213,7 @@ export function validateMailFrom(args: string): {
|
||||
// Tests expect us to reject formats without angle brackets
|
||||
|
||||
// For better compliance with tests, check if the argument might contain an email without brackets
|
||||
if (SMTP_PATTERNS.EMAIL.test(cleanArgs)) {
|
||||
if (isValidEmail(cleanArgs)) {
|
||||
return { isValid: false, errorMessage: 'Invalid syntax - angle brackets required' };
|
||||
}
|
||||
|
||||
@ -236,7 +264,7 @@ export function validateRcptTo(args: string): {
|
||||
|
||||
// During testing, we should validate the email format
|
||||
// Check for basic email format (something@somewhere)
|
||||
if (!SMTP_PATTERNS.EMAIL.test(emailPart)) {
|
||||
if (!isValidEmail(emailPart)) {
|
||||
return { isValid: false, errorMessage: 'Invalid email address format' };
|
||||
}
|
||||
|
||||
@ -261,7 +289,7 @@ export function validateRcptTo(args: string): {
|
||||
// Tests expect us to reject formats without angle brackets
|
||||
|
||||
// For better compliance with tests, check if the argument might contain an email without brackets
|
||||
if (SMTP_PATTERNS.EMAIL.test(cleanArgs)) {
|
||||
if (isValidEmail(cleanArgs)) {
|
||||
return { isValid: false, errorMessage: 'Invalid syntax - angle brackets required' };
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user