update
This commit is contained in:
@ -54,7 +54,10 @@ export class CommandHandler extends EventEmitter {
|
||||
* Send MAIL FROM command
|
||||
*/
|
||||
public async sendMailFrom(connection: ISmtpConnection, fromAddress: string): Promise<ISmtpResponse> {
|
||||
const command = `${SMTP_COMMANDS.MAIL_FROM}:<${fromAddress}>`;
|
||||
// Handle empty return path for bounce messages
|
||||
const command = fromAddress === ''
|
||||
? `${SMTP_COMMANDS.MAIL_FROM}:<>`
|
||||
: `${SMTP_COMMANDS.MAIL_FROM}:<${fromAddress}>`;
|
||||
return this.sendCommand(connection, command);
|
||||
}
|
||||
|
||||
@ -77,15 +80,19 @@ export class CommandHandler extends EventEmitter {
|
||||
* Send email data content
|
||||
*/
|
||||
public async sendDataContent(connection: ISmtpConnection, emailData: string): Promise<ISmtpResponse> {
|
||||
// Ensure email data ends with CRLF.CRLF
|
||||
let data = emailData;
|
||||
// Normalize line endings to CRLF
|
||||
let data = emailData.replace(/\r\n/g, '\n').replace(/\r/g, '\n').replace(/\n/g, '\r\n');
|
||||
|
||||
// Ensure email data ends with CRLF
|
||||
if (!data.endsWith(LINE_ENDINGS.CRLF)) {
|
||||
data += LINE_ENDINGS.CRLF;
|
||||
}
|
||||
data += '.' + LINE_ENDINGS.CRLF;
|
||||
|
||||
// Perform dot stuffing (escape lines starting with a dot)
|
||||
data = data.replace(/\n\./g, '\n..');
|
||||
data = data.replace(/\r\n\./g, '\r\n..');
|
||||
|
||||
// Add termination sequence
|
||||
data += '.' + LINE_ENDINGS.CRLF;
|
||||
|
||||
return this.sendRawData(connection, data);
|
||||
}
|
||||
@ -306,7 +313,7 @@ export class CommandHandler extends EventEmitter {
|
||||
const response = parseSmtpResponse(this.responseBuffer);
|
||||
this.responseBuffer = '';
|
||||
|
||||
if (isSuccessCode(response.code) || response.code >= 400) {
|
||||
if (isSuccessCode(response.code) || (response.code >= 300 && response.code < 400) || response.code >= 400) {
|
||||
this.pendingCommand.resolve(response);
|
||||
} else {
|
||||
this.pendingCommand.reject(new Error(`Command failed: ${response.message}`));
|
||||
|
Reference in New Issue
Block a user