This commit is contained in:
2025-05-21 14:28:33 +00:00
parent 38811dbf23
commit 10ab09894b
8 changed files with 652 additions and 162 deletions

View File

@ -147,8 +147,29 @@ export function createResponseFormatter(socket: plugins.net.Socket | plugins.tls
* @returns Command name in uppercase
*/
export function extractCommandName(commandLine: string): string {
const parts = commandLine.trim().split(' ');
return parts[0].toUpperCase();
if (!commandLine || typeof commandLine !== 'string') {
return '';
}
// Handle specific command patterns first
const ehloMatch = commandLine.match(/^(EHLO|HELO)\b/i);
if (ehloMatch) {
return ehloMatch[1].toUpperCase();
}
const mailMatch = commandLine.match(/^MAIL\b/i);
if (mailMatch) {
return 'MAIL';
}
const rcptMatch = commandLine.match(/^RCPT\b/i);
if (rcptMatch) {
return 'RCPT';
}
// Default handling
const parts = commandLine.trim().split(/\s+/);
return (parts[0] || '').toUpperCase();
}
/**
@ -157,6 +178,30 @@ export function extractCommandName(commandLine: string): string {
* @returns Arguments string
*/
export function extractCommandArgs(commandLine: string): string {
if (!commandLine || typeof commandLine !== 'string') {
return '';
}
const command = extractCommandName(commandLine);
if (!command) {
return commandLine.trim();
}
// Special handling for specific commands
if (command === 'EHLO' || command === 'HELO') {
const match = commandLine.match(/^(?:EHLO|HELO)\s+(.+)$/i);
return match ? match[1].trim() : '';
}
if (command === 'MAIL') {
return commandLine.replace(/^MAIL\s+/i, '');
}
if (command === 'RCPT') {
return commandLine.replace(/^RCPT\s+/i, '');
}
// Default extraction
const firstSpace = commandLine.indexOf(' ');
if (firstSpace === -1) {
return '';