Files
mdg-filius/packages/protocol/src/mail.ts
T
julian.kiedaischandClaude Opus 5.5 11f13bca84 feat(editor): F4.6e the e-mail program and e-mail server on a computer's desktop
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>
2026-10-03 16:44:36 +00:00

46 lines
2.1 KiB
TypeScript

// What the e-mail program's and the e-mail server's windows show, as the
// room keeps them and every client shows them (plan §7.3), after
// GUIApplicationEmailAnwendungWindow and GUIApplicationEmailServerWindow
// (measured with tools/java-oracle's MailWindowRun).
import { addressText, type EmailClientAccount, type Mail } from '@mdg-filius/core';
/** The e-mail program: its account (null before one is set) and its two folders, oldest first. */
export interface EmailClientView {
readonly account: EmailClientAccount | null;
readonly inbox: readonly Mail[];
readonly sent: readonly Mail[];
}
/** The e-mail server: its button, its domain, and each account with the number of mails it holds. */
export interface EmailServerView {
readonly active: boolean;
readonly domain: string;
readonly accounts: readonly { readonly username: string; readonly mails: number }[];
}
/** posteingangAktualisieren: a received mail's row — its sender's name, else its address, nothing without a sender — and its subject. */
export function inboxRow(mail: Mail): readonly [string, string] {
const sender = mail.sender === null ? '' : (mail.sender.name ?? mail.sender.mailAddress ?? '');
return [sender, mail.subject ?? ''];
}
/** gesendeteAktualisieren: a sent mail's row — its recipients as Email.holeEmpfaengerListe writes them — and its subject. */
export function sentRow(mail: Mail): readonly [string, string] {
return [mail.to.map((each) => addressText(each) ?? 'null').join(', '), mail.subject ?? ''];
}
/**
* emailVerfassen with a mail to answer: to its sender, the subject after
* Java's "RE:", the text quoted below "<sender> wrote:" (replyLayout: each
* line after "> ").
*/
export function replyForm(mail: Mail, words: { readonly re: string; readonly wrote: string }): { readonly to: string; readonly subject: string; readonly text: string } {
const sender = mail.sender === null ? 'null' : (addressText(mail.sender) ?? 'null');
return {
to: sender,
subject: `${words.re} ${mail.subject ?? 'null'}`,
text: `\n\n${sender} ${words.wrote}\n> ${mail.text.replaceAll('\n', '\n> ')}`,
};
}