124 lines
4.0 KiB
TypeScript
124 lines
4.0 KiB
TypeScript
|
|
/**
|
||
|
|
* SMTP Data Handler
|
||
|
|
* Responsible for processing email data during and after DATA command
|
||
|
|
*/
|
||
|
|
import * as plugins from '../../../plugins.js';
|
||
|
|
import type { ISmtpSession, ISmtpTransactionResult } from './interfaces.js';
|
||
|
|
import type { IDataHandler, ISmtpServer } from './interfaces.js';
|
||
|
|
import { Email } from '../../core/classes.email.js';
|
||
|
|
/**
|
||
|
|
* Handles SMTP DATA command and email data processing
|
||
|
|
*/
|
||
|
|
export declare class DataHandler implements IDataHandler {
|
||
|
|
/**
|
||
|
|
* Reference to the SMTP server instance
|
||
|
|
*/
|
||
|
|
private smtpServer;
|
||
|
|
/**
|
||
|
|
* Creates a new data handler
|
||
|
|
* @param smtpServer - SMTP server instance
|
||
|
|
*/
|
||
|
|
constructor(smtpServer: ISmtpServer);
|
||
|
|
/**
|
||
|
|
* Process incoming email data
|
||
|
|
* @param socket - Client socket
|
||
|
|
* @param data - Data chunk
|
||
|
|
* @returns Promise that resolves when the data is processed
|
||
|
|
*/
|
||
|
|
processEmailData(socket: plugins.net.Socket | plugins.tls.TLSSocket, data: string): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Handle raw data chunks during DATA mode (optimized for large messages)
|
||
|
|
* @param socket - Client socket
|
||
|
|
* @param data - Raw data chunk
|
||
|
|
*/
|
||
|
|
handleDataReceived(socket: plugins.net.Socket | plugins.tls.TLSSocket, data: string): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Process email data chunks efficiently for large messages
|
||
|
|
* @param chunks - Array of email data chunks
|
||
|
|
* @returns Processed email data string
|
||
|
|
*/
|
||
|
|
private processEmailDataStreaming;
|
||
|
|
/**
|
||
|
|
* Process a complete email
|
||
|
|
* @param rawData - Raw email data
|
||
|
|
* @param session - SMTP session
|
||
|
|
* @returns Promise that resolves with the Email object
|
||
|
|
*/
|
||
|
|
processEmail(rawData: string, session: ISmtpSession): Promise<Email>;
|
||
|
|
/**
|
||
|
|
* Parse email from raw data
|
||
|
|
* @param rawData - Raw email data
|
||
|
|
* @param session - SMTP session
|
||
|
|
* @returns Email object
|
||
|
|
*/
|
||
|
|
private parseEmailFromData;
|
||
|
|
/**
|
||
|
|
* Process a complete email (legacy method)
|
||
|
|
* @param session - SMTP session
|
||
|
|
* @returns Promise that resolves with the result of the transaction
|
||
|
|
*/
|
||
|
|
processEmailLegacy(session: ISmtpSession): Promise<ISmtpTransactionResult>;
|
||
|
|
/**
|
||
|
|
* Save an email to disk
|
||
|
|
* @param session - SMTP session
|
||
|
|
*/
|
||
|
|
saveEmail(session: ISmtpSession): void;
|
||
|
|
/**
|
||
|
|
* Parse an email into an Email object
|
||
|
|
* @param session - SMTP session
|
||
|
|
* @returns Promise that resolves with the parsed Email object
|
||
|
|
*/
|
||
|
|
parseEmail(session: ISmtpSession): Promise<Email>;
|
||
|
|
/**
|
||
|
|
* Basic fallback method for parsing emails
|
||
|
|
* @param session - SMTP session
|
||
|
|
* @returns The parsed Email object
|
||
|
|
*/
|
||
|
|
private parseEmailBasic;
|
||
|
|
/**
|
||
|
|
* Handle multipart content parsing
|
||
|
|
* @param email - Email object to update
|
||
|
|
* @param bodyText - Body text to parse
|
||
|
|
* @param boundary - MIME boundary
|
||
|
|
*/
|
||
|
|
private handleMultipartContent;
|
||
|
|
/**
|
||
|
|
* Handle end of data marker received
|
||
|
|
* @param socket - Client socket
|
||
|
|
* @param session - SMTP session
|
||
|
|
*/
|
||
|
|
private handleEndOfData;
|
||
|
|
/**
|
||
|
|
* Reset session after email processing
|
||
|
|
* @param session - SMTP session
|
||
|
|
*/
|
||
|
|
private resetSession;
|
||
|
|
/**
|
||
|
|
* Send a response to the client
|
||
|
|
* @param socket - Client socket
|
||
|
|
* @param response - Response message
|
||
|
|
*/
|
||
|
|
private sendResponse;
|
||
|
|
/**
|
||
|
|
* Check if a socket error is potentially recoverable
|
||
|
|
* @param error - The error that occurred
|
||
|
|
* @returns Whether the error is potentially recoverable
|
||
|
|
*/
|
||
|
|
private isRecoverableSocketError;
|
||
|
|
/**
|
||
|
|
* Handle recoverable socket errors with retry logic
|
||
|
|
* @param socket - Client socket
|
||
|
|
* @param error - The error that occurred
|
||
|
|
* @param response - The response that failed to send
|
||
|
|
*/
|
||
|
|
private handleSocketError;
|
||
|
|
/**
|
||
|
|
* Handle email data (interface requirement)
|
||
|
|
*/
|
||
|
|
handleData(socket: plugins.net.Socket | plugins.tls.TLSSocket, data: string, session: ISmtpSession): Promise<void>;
|
||
|
|
/**
|
||
|
|
* Clean up resources
|
||
|
|
*/
|
||
|
|
destroy(): void;
|
||
|
|
}
|