// The e-mail programs' lines as Java's windows show them, in the person's // language: the server's window appends each line its server tells it // (EmailServer, SMTPMitarbeiter, POP3Mitarbeiter, SMTPClient — only those that // are text: a failure the SMTP client throws does not show there); the // program's window shows a failure's message in a dialog (Exception.getMessage). import type { EmailServerLogEntry, MailFailure } from '@mdg-filius/core'; import type { Translate } from '../i18n/i18n.js'; /** EmailServer.LINE_SEPARATOR. */ const SEPARATOR = '----'; /** A line of the server's window; undefined for what Java's window does not show. */ export function emailServerLine(entry: EmailServerLogEntry, t: Translate): string | undefined { switch (entry.kind) { case 'connectionOpened': case 'connectionStarting': return SEPARATOR; case 'received': return `${entry.address}< ${entry.text}`; case 'sent': return `${entry.address}> ${entry.text}`; case 'sendFailed': return t('mail.sendFailed', { address: entry.address }); case 'stored': return t('mail.stored', { name: entry.username }); case 'switched': return t(entry.active ? 'emailServer.started' : 'emailServer.stopped'); case 'smtpConnected': return t('mail.connected', { address: `${entry.address}:${entry.port}` }); case 'smtpDisconnected': return t('mail.disconnected', { address: `${entry.address}:${entry.port}` }); case 'mailSent': return t('mail.mailSent', { recipients: entry.recipients }); case 'failed': return undefined; } } /** The message of a failure, as the program's window shows it. */ export function mailFailureText(failure: MailFailure, t: Translate): string { switch (failure.kind) { case 'answer': return failure.text; case 'connect': return t(`mail.failure.${failure.failure}`); case 'receiveFailed': return t('mail.failure.receiveFailed'); } }