import * as plugins from '../plugins.js'; import * as authInterfaces from '../data/auth.js'; export type TEmailStatus = 'delivered' | 'bounced' | 'rejected' | 'deferred' | 'pending' | 'accepted' | 'flagged'; export type TEmailDirection = 'inbound' | 'outbound'; export interface IEmail { id: string; direction: TEmailDirection; status: TEmailStatus; from: string; to: string; subject: string; timestamp: string; messageId: string; size: string; } export type TEmailLogTrafficWindow = '24h' | '7d' | '14d' | '30d'; export interface IEmailLogTrafficPoint { timestamp: number; value: number; } export interface IEmailLogTraffic { window: TEmailLogTrafficWindow; label: string; durationMs: number; windowStart: number; windowEnd: number; bucketSizeMs: number; sent: IEmailLogTrafficPoint[]; received: IEmailLogTrafficPoint[]; failed: IEmailLogTrafficPoint[]; } export interface IEmailSecurityFinding { id: string; timestamp: string; from: string; to: string; subject: string; disposition: 'flagged' | 'rejected'; failures: string[]; failureSummary: string; } export interface ISmtpLogEntry { timestamp: string; direction: 'client' | 'server' | 'system'; command: string; responseCode?: number; } export type TSmtpDeliveryPhase = 'connect' | 'greeting' | 'ehlo' | 'starttls' | 'tls_handshake' | 'post_tls_ehlo' | 'auth' | 'mail_from' | 'rcpt_to' | 'data_command' | 'message_body' | 'final_response' | 'rset' | 'quit' | 'unknown'; export interface ISmtpTranscriptEntry { timestampMs: number; phase: TSmtpDeliveryPhase; direction: 'client' | 'server' | 'system'; text: string; responseCode?: number; } export interface IOutboundAuthenticationCheck { state: 'pending' | 'completed' | 'indeterminate' | 'not-evaluated'; overall: 'pass' | 'fail' | 'indeterminate'; checkedAt: string; signedMessageSha256?: string; error?: string; identity?: { sourceIp: string; addressFamily: 'ipv4' | 'ipv6'; heloDomain: string; receiverHostname: string; envelopeFrom: string; dkimDomain?: string; dkimSelector?: string; }; dkim?: Array<{ is_valid: boolean; domain: string | null; selector: string | null; status: string; details: string | null; }>; spf?: { result: string; domain: string; ip: string; explanation: string | null; } | null; dmarc?: { passed: boolean; policy: string; domain: string; dkim_result: string; spf_result: string; action: string; details: string | null; } | null; } export interface ISmtpTransactionAttempt { id: string; queueItemId: string; queueAttempt: number; targetHost: string; targetPort: number; recipientDomain?: string; recipients: string[]; startedAt: string; completedAt: string; durationMs: number; outcome: 'succeeded' | 'failed'; retryable: boolean; errorType?: string; smtpCode?: number; recipientResults?: Array<{ recipient: string; accepted: boolean; responseCode: number; }>; failurePhase?: TSmtpDeliveryPhase; error?: string; outboundAuthentication?: IOutboundAuthenticationCheck; transcript: ISmtpTranscriptEntry[]; } export interface IConnectionInfo { sourceIp: string; sourceHostname: string; destinationIp: string; destinationPort: number; tlsVersion: string; tlsCipher: string; authenticated: boolean; authMethod: string; authUser: string; } export interface IAuthenticationResults { spf: 'pass' | 'fail' | 'softfail' | 'neutral' | 'none'; spfDomain: string; dkim: 'pass' | 'fail' | 'none'; dkimDomain: string; dmarc: 'pass' | 'fail' | 'none'; dmarcPolicy: string; } export interface IEmailDetail extends IEmail { smtpTransactions?: ISmtpTransactionAttempt[]; /** Epoch ms of the next scheduled delivery attempt (pending/deferred only). */ nextAttemptAt?: number; /** 1-based number of the next scheduled delivery attempt. */ nextAttemptNumber?: number; toList: string[]; cc?: string[]; smtpLog: ISmtpLogEntry[]; connectionInfo: IConnectionInfo; authenticationResults: IAuthenticationResults; outboundAuthentication?: IOutboundAuthenticationCheck; rejectionReason?: string; bounceMessage?: string; headers: Record; body: string; } export interface IReq_GetAllEmails extends plugins.typedrequestInterfaces.implementsTR { method: 'getAllEmails'; request: { identity?: authInterfaces.IIdentity; apiToken?: string; /** Restrict the listing to one direction. Absent = both. */ direction?: TEmailDirection; /** Maximum number of entries to return (default 200). */ limit?: number; /** Literal search across sender, recipients, subject, and message ID. */ search?: string; /** Inclusive accepted-at lower bound in epoch milliseconds. Requires `to`. */ from?: number; /** Inclusive accepted-at upper bound in epoch milliseconds. Requires `from`. */ to?: number; }; response: { emails: IEmail[]; traffic: IEmailLogTraffic; }; } export interface IReq_GetEmailSecurityFindings extends plugins.typedrequestInterfaces.implementsTR { method: 'getEmailSecurityFindings'; request: { identity?: authInterfaces.IIdentity; apiToken?: string; /** Maximum number of findings to return (default/max 200). */ limit?: number; }; response: { findings: IEmailSecurityFinding[]; }; } export interface IReq_GetEmailDetail extends plugins.typedrequestInterfaces.implementsTR { method: 'getEmailDetail'; request: { identity?: authInterfaces.IIdentity; apiToken?: string; emailId: string; }; response: { email: IEmailDetail | null; }; } export interface IReq_ResendEmail extends plugins.typedrequestInterfaces.implementsTR { method: 'resendEmail'; request: { identity?: authInterfaces.IIdentity; apiToken?: string; emailId: string; }; response: { success: boolean; newQueueId?: string; error?: string; }; }