update
This commit is contained in:
@ -34,10 +34,6 @@ export function validateMailFrom(args: string): {
|
||||
return { isValid: false, errorMessage: 'Missing arguments' };
|
||||
}
|
||||
|
||||
// EXTREMELY PERMISSIVE TESTING MODE:
|
||||
// Accept anything with an email address format, for maximum compatibility
|
||||
// with test clients and various client implementations
|
||||
|
||||
// Handle "MAIL FROM:" already in the args
|
||||
let cleanArgs = args;
|
||||
if (args.toUpperCase().startsWith('MAIL FROM')) {
|
||||
@ -57,10 +53,8 @@ export function validateMailFrom(args: string): {
|
||||
return { isValid: true, address: '', params: {} };
|
||||
}
|
||||
|
||||
// For test email client compatibility, be extremely permissive
|
||||
// Parse email addresses both with and without angle brackets
|
||||
|
||||
// First attempt: if there are angle brackets, extract content between them
|
||||
// According to test expectations, validate that the address is enclosed in angle brackets
|
||||
// Check for angle brackets and RFC-compliance
|
||||
if (cleanArgs.includes('<') && cleanArgs.includes('>')) {
|
||||
const startBracket = cleanArgs.indexOf('<');
|
||||
const endBracket = cleanArgs.indexOf('>', startBracket);
|
||||
@ -74,11 +68,15 @@ export function validateMailFrom(args: string): {
|
||||
return { isValid: true, address: '', params: {} };
|
||||
}
|
||||
|
||||
// During testing, we should validate the email format
|
||||
// Check for basic email format (something@somewhere)
|
||||
if (!SMTP_PATTERNS.EMAIL.test(emailPart)) {
|
||||
return { isValid: false, errorMessage: 'Invalid email address format' };
|
||||
}
|
||||
|
||||
// Parse parameters if they exist
|
||||
const params: Record<string, string> = {};
|
||||
if (paramsString) {
|
||||
// Extremely permissive parameter parsing
|
||||
// Match anything that looks like a parameter
|
||||
const paramRegex = /\s+([A-Za-z0-9][A-Za-z0-9\-]*)(?:=([^\s]+))?/g;
|
||||
let match;
|
||||
|
||||
@ -89,30 +87,13 @@ export function validateMailFrom(args: string): {
|
||||
}
|
||||
}
|
||||
|
||||
// Even more permissive - accept literally anything as an email address
|
||||
// including 'test@example.com' as well as 'postmaster' etc.
|
||||
return { isValid: true, address: emailPart, params };
|
||||
}
|
||||
}
|
||||
|
||||
// Second attempt: if there are no angle brackets, try to find an email-like pattern
|
||||
// This is for clients that don't properly use angle brackets
|
||||
const emailPattern = /([^\s<>]+@[^\s<>]+)/;
|
||||
const emailMatch = cleanArgs.match(emailPattern);
|
||||
|
||||
if (emailMatch) {
|
||||
// For clients sending plain email addresses without brackets (non-RFC compliant)
|
||||
return { isValid: true, address: emailMatch[1], params: {} };
|
||||
}
|
||||
|
||||
// Third attempt: for even more compatibility, accept anything that's not empty
|
||||
if (cleanArgs.trim() !== '') {
|
||||
// Just accept anything for testing purposes
|
||||
return { isValid: true, address: cleanArgs.trim(), params: {} };
|
||||
}
|
||||
|
||||
// If nothing matched, it's invalid
|
||||
return { isValid: false, errorMessage: 'Invalid syntax' };
|
||||
// If no angle brackets, the format is invalid for MAIL FROM
|
||||
// Tests expect us to reject formats without angle brackets
|
||||
return { isValid: false, errorMessage: 'Invalid syntax - angle brackets required' };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,9 +111,6 @@ export function validateRcptTo(args: string): {
|
||||
return { isValid: false, errorMessage: 'Missing arguments' };
|
||||
}
|
||||
|
||||
// EXTREMELY PERMISSIVE TESTING MODE:
|
||||
// Accept anything with an email address format, for maximum compatibility
|
||||
|
||||
// Handle "RCPT TO:" already in the args
|
||||
let cleanArgs = args;
|
||||
if (args.toUpperCase().startsWith('RCPT TO')) {
|
||||
@ -144,9 +122,8 @@ export function validateRcptTo(args: string): {
|
||||
cleanArgs = args.substring(3).trim();
|
||||
}
|
||||
|
||||
// For testing purposes, we'll be very permissive with RCPT TO as well
|
||||
|
||||
// First attempt: if there are angle brackets, extract content between them
|
||||
// According to test expectations, validate that the address is enclosed in angle brackets
|
||||
// Check for angle brackets and RFC-compliance
|
||||
if (cleanArgs.includes('<') && cleanArgs.includes('>')) {
|
||||
const startBracket = cleanArgs.indexOf('<');
|
||||
const endBracket = cleanArgs.indexOf('>', startBracket);
|
||||
@ -155,11 +132,15 @@ export function validateRcptTo(args: string): {
|
||||
const emailPart = cleanArgs.substring(startBracket + 1, endBracket).trim();
|
||||
const paramsString = cleanArgs.substring(endBracket + 1).trim();
|
||||
|
||||
// During testing, we should validate the email format
|
||||
// Check for basic email format (something@somewhere)
|
||||
if (!SMTP_PATTERNS.EMAIL.test(emailPart)) {
|
||||
return { isValid: false, errorMessage: 'Invalid email address format' };
|
||||
}
|
||||
|
||||
// Parse parameters if they exist
|
||||
const params: Record<string, string> = {};
|
||||
if (paramsString) {
|
||||
// Extremely permissive parameter parsing
|
||||
// Match anything that looks like a parameter
|
||||
const paramRegex = /\s+([A-Za-z0-9][A-Za-z0-9\-]*)(?:=([^\s]+))?/g;
|
||||
let match;
|
||||
|
||||
@ -174,24 +155,9 @@ export function validateRcptTo(args: string): {
|
||||
}
|
||||
}
|
||||
|
||||
// Second attempt: if there are no angle brackets, try to find an email-like pattern
|
||||
// This is for clients that don't properly use angle brackets
|
||||
const emailPattern = /([^\s<>]+@[^\s<>]+)/;
|
||||
const emailMatch = cleanArgs.match(emailPattern);
|
||||
|
||||
if (emailMatch) {
|
||||
// For clients sending plain email addresses without brackets (non-RFC compliant)
|
||||
return { isValid: true, address: emailMatch[1], params: {} };
|
||||
}
|
||||
|
||||
// Third attempt: for even more compatibility, accept anything that's not empty
|
||||
if (cleanArgs.trim() !== '') {
|
||||
// Just accept anything for testing purposes
|
||||
return { isValid: true, address: cleanArgs.trim(), params: {} };
|
||||
}
|
||||
|
||||
// If nothing matched, it's invalid
|
||||
return { isValid: false, errorMessage: 'Invalid syntax' };
|
||||
// If no angle brackets, the format is invalid for RCPT TO
|
||||
// Tests expect us to reject formats without angle brackets
|
||||
return { isValid: false, errorMessage: 'Invalid syntax - angle brackets required' };
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user