Files
reactive-mail-server/frontend/src/app/core/models.ts
T
Liosha84andClaude Opus 5.5 fc3fe3970d
continuous-integration/drone/pr Build is passing
Ловушка у ящика (TRAP): что ящик отправляет — в его же INBOX, наружу ничего
Для staging@: staging-стенд шлёт через настоящий mail.jambocheck.com,
но тестовые письма не доходят до живых людей.
- V5: users.is_trap
- MailRouter: отправитель-ловушка → все получатели LOCAL, одна копия в INBOX отправителя
- PUT /api/admin/mailboxes/{id}/trap, MailboxView.trap
- MAILBOXES: кнопка outbox/move_to_inbox, метка TRAP
- тесты: router + admin (77 тестов)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 10:45:20 +01:00

129 lines
3.5 KiB
TypeScript

export interface Folder {
id: number;
name: string;
system: boolean;
messageCount: number;
unreadCount: number;
}
export interface Message {
id: number;
folderId: number;
senderEmail: string;
senderName?: string | null;
recipientEmail: string;
ccEmail?: string | null;
subject: string;
body: string;
html: boolean;
read: boolean;
flagged: boolean;
spam: boolean;
messageSize?: number | null;
receivedAt: string;
hasAttachments: boolean;
attachmentCount: number;
}
export interface Attachment {
id: number;
filename: string;
contentType: string;
sizeBytes: number;
}
export interface Contact {
id?: number;
name: string;
email: string;
phone?: string;
company?: string;
}
export interface BlacklistEntry {
id: number;
senderEmail: string;
reason?: string | null;
createdAt?: string;
}
export interface Profile {
email: string;
displayName: string;
usedBytes: number;
quotaBytes: number;
createdAt: string;
admin?: boolean; // may manage mailboxes (Settings → Mailboxes)
}
/** MailboxAdminController.MailboxView */
export interface Mailbox {
id: number;
email: string;
displayName: string;
active: boolean;
admin: boolean;
trap: boolean; // what it sends stays in its own INBOX, nothing leaves the server (staging@)
usedBytes: number;
quotaBytes: number;
createdAt: string;
}
/** password — generated by the server, shown once; null when the administrator chose it */
export interface MailboxCreated {
mailbox: Mailbox;
password: string | null;
}
export interface ServerConfig {
registrationEnabled: boolean;
domains: string[];
}
export interface Draft {
to: string;
cc: string;
subject: string;
body: string;
html: boolean;
}
/** System folders: label and icon in the web client. */
export const FOLDER_VIEW: Record<string, { label: string; icon: string }> = {
INBOX: { label: 'Inbox', icon: 'inbox' },
Drafts: { label: 'Drafts', icon: 'edit_note' },
Sent: { label: 'Sent', icon: 'send' },
Spam: { label: 'Spam', icon: 'report' },
Trash: { label: 'Trash', icon: 'delete' }
};
export function folderLabel(folder: Folder): string {
return folder.system ? (FOLDER_VIEW[folder.name]?.label ?? folder.name) : folder.name;
}
export function folderIcon(folder: Folder): string {
return folder.system ? (FOLDER_VIEW[folder.name]?.icon ?? 'folder') : 'folder';
}
export function formatBytes(bytes: number | null | undefined): string {
const value = bytes ?? 0;
if (value < 1024) return `${value} B`;
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`;
if (value < 1024 * 1024 * 1024) return `${(value / 1024 / 1024).toFixed(1)} MB`;
return `${(value / 1024 / 1024 / 1024).toFixed(2)} GB`;
}
/** Text of an API error: our {error}, Spring's {message}, or the status. */
export function errorText(error: unknown): string {
const e = error as { error?: { error?: string; message?: string; status?: number } | string; status?: number; message?: string };
if (e?.error && typeof e.error === 'object') {
// Spring's error body: {status, error: "Bad Request", message: "No such mailbox: …"} — the reason is in message
const body = e.error;
const springBody = typeof body.status === 'number';
return (springBody ? body.message || body.error : body.error || body.message) || `Error ${e.status ?? ''}`.trim();
}
if (typeof e?.error === 'string' && e.error) return e.error;
if (e?.status === 0) return 'Server is not reachable';
return e?.message || 'Something went wrong';
}