update
This commit is contained in:
@ -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 '';
|
||||
|
Reference in New Issue
Block a user