The oracle MailWindowRun uses Java's e-mail windows as a person does and answers their dialogs. The core sets and saves the program's account, deletes a mail, checks a form as Java's window does, and gives the server its domain, new and removed accounts and the window's own line; the room sends both programs' views and takes their actions; the editor has both windows. Better than Java: a name field for a new account, a user name the server has is refused, deleting hits the folder shown, a new domain goes into the accounts file at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
// 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');
|
|
}
|
|
}
|