ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
refactor(email): relocate the Email page into the serverkit-email extension (plan 52 Phase 2 prep)
Juan Denisf6d9dea95479
diff --git a/backend/app/utils/sdk.py b/backend/app/utils/sdk.pyindex 262b5829..de402065 100644--- a/backend/app/utils/sdk.py+++ b/backend/app/utils/sdk.py@@ -40,7 +40,7 @@ from app.utils.version import compare_versions# 1.2.0 — plan 52 Phases 4-5: layout/feedback primitives, ui/* form kit,# common hooks, format utils, and the cross-feature embeds (git repo-connect,# backups ProtectionPanel) the WordPress runtime-ESM extraction needed.-SDK_VERSION = '1.3.0'+SDK_VERSION = '1.4.0'def _version_tuple(v):diff --git a/builtin-extensions/serverkit-email/frontend/index.jsx b/builtin-extensions/serverkit-email/frontend/index.jsxindex 2d8284d5..8d791800 100644--- a/builtin-extensions/serverkit-email/frontend/index.jsx+++ b/builtin-extensions/serverkit-email/frontend/index.jsx@@ -1,12 +1,17 @@-// Email Server, contributed through the extension system. The full mail-server-// backend (Postfix/Dovecot/DKIM/SpamAssassin/Roundcube orchestration + the-// /api/v1/email blueprint) lives in this extension's backend/; the page-// component stays in the host pages/ dir and is re-exported here (same pattern-// as serverkit-git/gpu/workflows) so its many relative imports keep resolving.+// Email Server, contributed through the extension system. Both halves live in+// this extension: the mail-server backend (Postfix/Dovecot/DKIM/SpamAssassin/+// Roundcube orchestration + the /api/v1/email blueprint) under backend/, and+// the full page here (pages/Email.jsx + styles/email.scss + its own API+// client in services/email.js). Imports go through 'serverkit-sdk' so the+// same source works baked in-tree (the panel's build-time glob) and as a+// runtime-ESM bundle once the extension leaves the tree (plan 52 Phase 2).//-// After sync this file lives at frontend/src/plugins/serverkit-email/ so the-// relative import resolves against the host's pages directory.-import Email from '../../pages/Email';+// The SCSS side-effect import compiles the page styles through this+// extension's own module graph — the host's main.scss no longer carries an+// _email partial.+import './styles/email.scss';++import Email from './pages/Email';export function EmailPage() {return <Email />;diff --git a/frontend/src/pages/Email.jsx b/builtin-extensions/serverkit-email/frontend/pages/Email.jsxsimilarity index 98%rename from frontend/src/pages/Email.jsxrename to builtin-extensions/serverkit-email/frontend/pages/Email.jsxindex dd8990f6..6ac631ef 100644--- a/frontend/src/pages/Email.jsx+++ b/builtin-extensions/serverkit-email/frontend/pages/Email.jsx@@ -12,22 +12,14 @@ import {RefreshCw, Plus, Trash2, ShieldCheck, Server, Globe, Users,Send, Filter, Inbox, ExternalLink, CheckCircle2, XCircle, HelpCircle, Search,} from 'lucide-react';-import api from '../services/api';-import useTabParam from '../hooks/useTabParam';-import { Pill, MetricCard, KpiBand, DataTable, DataTableFooter, ListToolbar, SearchField } from '@/components/ds';-import PageLayout from '../layouts/PageLayout';-import { Button } from '@/components/ui/button';-import { Input } from '@/components/ui/input';-import EmptyState from '../components/EmptyState';-import { useToast } from '../contexts/ToastContext';-import { useConfirm } from '../hooks/useConfirm';-import { useTableSort } from '../hooks/useTableSort';-import { useColumnVisibility } from '../hooks/useColumnVisibility';-import { useTranslation } from 'react-i18next';+import api from '../services/email';import {+ Pill, MetricCard, KpiBand, DataTable, DataTableFooter, ListToolbar,+ SearchField, PageLayout, Button, Input, EmptyState, useToast, useConfirm,+ useTabParam, useTableSort, useColumnVisibility, useTranslation,useTableChrome, GridViewPicker, GridChips, GridFilterButton,GridToolsMenu, GridFilterDrawer,-} from '@/components/ds/grid';+} from 'serverkit-sdk';const VALID_TABS = ['overview', 'domains', 'accounts', 'relay', 'spam', 'webmail', 'queue'];diff --git a/builtin-extensions/serverkit-email/frontend/services/email.js b/builtin-extensions/serverkit-email/frontend/services/email.jsnew file mode 100644index 00000000..78e811ab--- /dev/null+++ b/builtin-extensions/serverkit-email/frontend/services/email.js@@ -0,0 +1,69 @@+// The extension's own /api/v1/email client, built on the panel's ApiClient+// via the SDK singleton (JWT refresh, workspace headers, error normalization+// included) — moved out of the host's services/api/system.js with the page.+//+// Two email surfaces deliberately STAY core and are not duplicated here:+// the DNS-provider connections (/email/dns-providers — a core blueprint that+// keeps its historical prefix) and the Settings → Connections relay tile's+// calls. The relay methods below are this extension's own copies for the+// Relay tab; the page and the Settings tile hit the same endpoints.+import { api } from 'serverkit-sdk';++const emailApi = {+ // Server+ getEmailStatus: () => api.request('/email/status'),+ installEmailServer: (data = {}) => api.request('/email/install', { method: 'POST', body: JSON.stringify(data) }),+ controlEmailService: (component, action) => api.request(`/email/service/${component}/${action}`, { method: 'POST' }),++ // Domains+ getEmailDomains: () => api.request('/email/domains'),+ addEmailDomain: (data) => api.request('/email/domains', { method: 'POST', body: JSON.stringify(data) }),+ getEmailDomain: (domainId) => api.request(`/email/domains/${domainId}`),+ deleteEmailDomain: (domainId) => api.request(`/email/domains/${domainId}`, { method: 'DELETE' }),+ verifyEmailDNS: (domainId) => api.request(`/email/domains/${domainId}/verify-dns`, { method: 'POST' }),+ deployEmailDNS: (domainId) => api.request(`/email/domains/${domainId}/deploy-dns`, { method: 'POST' }),++ // Accounts+ getEmailAccounts: (domainId) => api.request(`/email/domains/${domainId}/accounts`),+ createEmailAccount: (domainId, data) => api.request(`/email/domains/${domainId}/accounts`, { method: 'POST', body: JSON.stringify(data) }),+ getEmailAccount: (accountId) => api.request(`/email/accounts/${accountId}`),+ updateEmailAccount: (accountId, data) => api.request(`/email/accounts/${accountId}`, { method: 'PUT', body: JSON.stringify(data) }),+ deleteEmailAccount: (accountId) => api.request(`/email/accounts/${accountId}`, { method: 'DELETE' }),+ changeEmailPassword: (accountId, password) => api.request(`/email/accounts/${accountId}/password`, { method: 'POST', body: JSON.stringify({ password }) }),++ // Aliases+ getEmailAliases: (domainId) => api.request(`/email/domains/${domainId}/aliases`),+ createEmailAlias: (domainId, data) => api.request(`/email/domains/${domainId}/aliases`, { method: 'POST', body: JSON.stringify(data) }),+ deleteEmailAlias: (aliasId) => api.request(`/email/aliases/${aliasId}`, { method: 'DELETE' }),++ // Forwarding+ getEmailForwarding: (accountId) => api.request(`/email/accounts/${accountId}/forwarding`),+ createEmailForwarding: (accountId, data) => api.request(`/email/accounts/${accountId}/forwarding`, { method: 'POST', body: JSON.stringify(data) }),+ updateEmailForwarding: (ruleId, data) => api.request(`/email/forwarding/${ruleId}`, { method: 'PUT', body: JSON.stringify(data) }),+ deleteEmailForwarding: (ruleId) => api.request(`/email/forwarding/${ruleId}`, { method: 'DELETE' }),++ // Outbound SMTP relay (smarthost)+ getEmailRelay: () => api.request('/email/relay'),+ updateEmailRelay: (data) => api.request('/email/relay', { method: 'PUT', body: JSON.stringify(data) }),+ testEmailRelay: (data) => api.request('/email/relay/test', { method: 'POST', body: JSON.stringify(data) }),+ disableEmailRelay: () => api.request('/email/relay', { method: 'DELETE' }),++ // SpamAssassin+ getSpamConfig: () => api.request('/email/spam/config'),+ updateSpamConfig: (data) => api.request('/email/spam/config', { method: 'PUT', body: JSON.stringify(data) }),+ updateSpamRules: () => api.request('/email/spam/update-rules', { method: 'POST' }),++ // Roundcube webmail+ getWebmailStatus: () => api.request('/email/webmail/status'),+ installWebmail: (data = {}) => api.request('/email/webmail/install', { method: 'POST', body: JSON.stringify(data) }),+ controlWebmail: (action) => api.request(`/email/webmail/service/${action}`, { method: 'POST' }),+ configureWebmailProxy: (domain) => api.request('/email/webmail/configure-proxy', { method: 'POST', body: JSON.stringify({ domain }) }),++ // Mail queue & logs+ getMailQueue: () => api.request('/email/queue'),+ flushMailQueue: () => api.request('/email/queue/flush', { method: 'POST' }),+ deleteMailQueueItem: (queueId) => api.request(`/email/queue/${queueId}`, { method: 'DELETE' }),+ getMailLogs: (lines = 100) => api.request(`/email/logs?lines=${lines}`),+};++export default emailApi;diff --git a/frontend/src/styles/pages/_email.scss b/builtin-extensions/serverkit-email/frontend/styles/email.scsssimilarity index 96%rename from frontend/src/styles/pages/_email.scssrename to builtin-extensions/serverkit-email/frontend/styles/email.scssindex 9ce278c4..299ecb8c 100644--- a/frontend/src/styles/pages/_email.scss+++ b/builtin-extensions/serverkit-email/frontend/styles/email.scss@@ -1,3 +1,9 @@+// Compiled through the extension's module graph (imported by index.jsx).+// The host's design-token partial is imported via a sync-safe relative+// path — the baked copy lives at frontend/src/plugins/serverkit-email/,+// so this resolves to frontend/src/styles/_variables.scss.+@import '../../../styles/variables';+// ============================================// EMAIL SERVER PAGE (redesign — infra console look, REDESIGN_MAP #18):// status Pills on the Services list, MetricCard KPI strip (Overview),diff --git a/frontend/public/serverkit-vendor/serverkit-sdk.mjs b/frontend/public/serverkit-vendor/serverkit-sdk.mjsindex 791fadd0..15051930 100644--- a/frontend/public/serverkit-vendor/serverkit-sdk.mjs+++ b/frontend/public/serverkit-vendor/serverkit-sdk.mjs@@ -90,3 +90,16 @@ export const GIT_PROVIDERS = m.GIT_PROVIDERS;export const detectProvider = m.detectProvider;export const RepoProviderStrip = m.RepoProviderStrip;export const ProtectionPanel = m.ProtectionPanel;+export const DataTableFooter = m.DataTableFooter;+export const ListToolbar = m.ListToolbar;+export const SearchField = m.SearchField;+export const SortChipBar = m.SortChipBar;+export const useTableChrome = m.useTableChrome;+export const GridViewPicker = m.GridViewPicker;+export const GridChips = m.GridChips;+export const GridFilterButton = m.GridFilterButton;+export const GridToolsMenu = m.GridToolsMenu;+export const GridFilterDrawer = m.GridFilterDrawer;+export const PageLayout = m.PageLayout;+export const useTableSort = m.useTableSort;+export const useColumnVisibility = m.useColumnVisibility;diff --git a/frontend/src/plugins/sdk/index.js b/frontend/src/plugins/sdk/index.jsindex 1ecd2675..349757ee 100644--- a/frontend/src/plugins/sdk/index.js+++ b/frontend/src/plugins/sdk/index.js@@ -38,7 +38,7 @@// GET /api/v1/plugins/contributions. The backend mirror lives in// backend/app/utils/sdk.py — keep the two in lock-step (asserted by// backend/tests/test_sdk_contract.py).-export const SDK_VERSION = '1.3.0';+export const SDK_VERSION = '1.4.0';export { api, default as defaultApi } from '../../services/api';@@ -174,3 +174,19 @@ export {GIT_PROVIDERS, detectProvider, RepoProviderStrip,} from '../../components/git/GitProviders';export { default as ProtectionPanel } from '../../components/backups/ProtectionPanel';++// List-page chrome (1.4.0, plan 52 Phase 2 — the email/cloudflare-ops frontend+// relocations proved these out). The full table kit a relocated list page+// needs: the DataTable footer/toolbar pieces, the saved-view chrome from+// ds/grid, the standalone-page layout, and the two table hooks. Same modules+// core pages use — generic re-exports, no extension special-casing.+export {+ DataTableFooter, ListToolbar, SearchField, SortChipBar,+} from '../../components/ds';+export {+ useTableChrome, GridViewPicker, GridChips, GridFilterButton,+ GridToolsMenu, GridFilterDrawer,+} from '../../components/ds/grid';+export { default as PageLayout } from '../../layouts/PageLayout';+export { useTableSort } from '../../hooks/useTableSort';+export { useColumnVisibility } from '../../hooks/useColumnVisibility';diff --git a/frontend/src/plugins/serverkit-email/index.jsx b/frontend/src/plugins/serverkit-email/index.jsxindex 2d8284d5..8d791800 100644--- a/frontend/src/plugins/serverkit-email/index.jsx+++ b/frontend/src/plugins/serverkit-email/index.jsx@@ -1,12 +1,17 @@-// Email Server, contributed through the extension system. The full mail-server-// backend (Postfix/Dovecot/DKIM/SpamAssassin/Roundcube orchestration + the-// /api/v1/email blueprint) lives in this extension's backend/; the page-// component stays in the host pages/ dir and is re-exported here (same pattern-// as serverkit-git/gpu/workflows) so its many relative imports keep resolving.+// Email Server, contributed through the extension system. Both halves live in+// this extension: the mail-server backend (Postfix/Dovecot/DKIM/SpamAssassin/+// Roundcube orchestration + the /api/v1/email blueprint) under backend/, and+// the full page here (pages/Email.jsx + styles/email.scss + its own API+// client in services/email.js). Imports go through 'serverkit-sdk' so the+// same source works baked in-tree (the panel's build-time glob) and as a+// runtime-ESM bundle once the extension leaves the tree (plan 52 Phase 2).//-// After sync this file lives at frontend/src/plugins/serverkit-email/ so the-// relative import resolves against the host's pages directory.-import Email from '../../pages/Email';+// The SCSS side-effect import compiles the page styles through this+// extension's own module graph — the host's main.scss no longer carries an+// _email partial.+import './styles/email.scss';++import Email from './pages/Email';export function EmailPage() {return <Email />;diff --git a/frontend/src/plugins/serverkit-email/pages/Email.jsx b/frontend/src/plugins/serverkit-email/pages/Email.jsxnew file mode 100644index 00000000..6ac631ef--- /dev/null+++ b/frontend/src/plugins/serverkit-email/pages/Email.jsx@@ -0,0 +1,1070 @@+// Email Server — management page for the serverkit-email extension.+//+// NOTE: This file was reconstructed after a data-loss corruption. The original+// was ~63KB; this is a coherent, functional, on-style rebuild — not a+// byte-for-byte restore. It is wired to the real ApiService email methods+// (see frontend/src/services/api/system.js, the `/email/*` endpoints) and+// covers the same surface area: server/service status, mail domains with+// SPF/DKIM/DMARC/PTR presence pills + DNS verify/deploy, accounts, aliases,+// outbound relay (smarthost), SpamAssassin, webmail, and the mail queue.+import { useState, useEffect, useCallback, useMemo } from 'react';+import {+ RefreshCw, Plus, Trash2, ShieldCheck, Server, Globe, Users,+ Send, Filter, Inbox, ExternalLink, CheckCircle2, XCircle, HelpCircle, Search,+} from 'lucide-react';+import api from '../services/email';+import {+ Pill, MetricCard, KpiBand, DataTable, DataTableFooter, ListToolbar,+ SearchField, PageLayout, Button, Input, EmptyState, useToast, useConfirm,+ useTabParam, useTableSort, useColumnVisibility, useTranslation,+ useTableChrome, GridViewPicker, GridChips, GridFilterButton,+ GridToolsMenu, GridFilterDrawer,+} from 'serverkit-sdk';++const VALID_TABS = ['overview', 'domains', 'accounts', 'relay', 'spam', 'webmail', 'queue'];++// A sort-only preset still has to say so: `apply` clears the live rules from+// whatever was selected before, and an absent `columnFilters` would leave the+// previous view's filters silently in place.+const NO_RULES = { match: 'all', rules: [] };++// DNS record checks surfaced as presence pills. `state` is one of+// 'ok' | 'missing' | 'unknown' and maps to a DS Pill colour + dot.+const DNS_RECORDS = [+ { key: 'spf', label: 'SPF' },+ { key: 'dkim', label: 'DKIM' },+ { key: 'dmarc', label: 'DMARC' },+ { key: 'ptr', label: 'PTR' },+ { key: 'mx', label: 'MX' },+];++function dnsPillKind(state) {+ if (state === 'ok') return 'green';+ if (state === 'missing') return 'red';+ return 'gray';+}++// Derive a per-record status map from a domain record and an optional live+// verify result. Falls back to "does the stored record string exist" when we+// have not run a live DNS check yet.+function deriveDnsStatus(domain, verify) {+ const out = {};+ for (const { key } of DNS_RECORDS) {+ if (verify && verify[key]) {+ out[key] = verify[key].valid || verify[key].present ? 'ok' : 'missing';+ } else if (key === 'spf') {+ out[key] = domain?.spf_record ? 'ok' : 'unknown';+ } else if (key === 'dkim') {+ out[key] = domain?.dkim_public_key ? 'ok' : 'unknown';+ } else if (key === 'dmarc') {+ out[key] = domain?.dmarc_record ? 'ok' : 'unknown';+ } else {+ out[key] = 'unknown';+ }+ }+ return out;+}++function DnsIcon({ state }) {+ if (state === 'ok') return <CheckCircle2 size={12} aria-hidden="true" />;+ if (state === 'missing') return <XCircle size={12} aria-hidden="true" />;+ return <HelpCircle size={12} aria-hidden="true" />;+}++export default function Email() {+ const { t } = useTranslation();+ const [activeTab] = useTabParam('/email', VALID_TABS);++ const [status, setStatus] = useState(null);+ const [domains, setDomains] = useState([]);+ const [loading, setLoading] = useState(true);++ const loadStatus = useCallback(async () => {+ try {+ const res = await api.getEmailStatus();+ setStatus(res?.status || res || null);+ } catch {+ setStatus(null);+ }+ }, []);++ const loadDomains = useCallback(async () => {+ try {+ const res = await api.getEmailDomains();+ setDomains(res?.domains || res || []);+ } catch {+ setDomains([]);+ }+ }, []);++ useEffect(() => {+ let alive = true;+ (async () => {+ await Promise.all([loadStatus(), loadDomains()]);+ if (alive) setLoading(false);+ })();+ return () => { alive = false; };+ }, [loadStatus, loadDomains]);++ const installed = status?.installed ?? status?.is_installed ?? (status != null && status.components != null);++ const tabs = VALID_TABS.map((t) => ({+ to: `/email/${t}`,+ label: t.charAt(0).toUpperCase() + t.slice(1),+ end: false,+ }));++ return (+ <PageLayout+ navLabel="Email Server"+ tabs={tabs}+ actions={(+ <Button variant="outline" size="sm" onClick={() => { loadStatus(); loadDomains(); }}>+ <RefreshCw size={14} /> {t('common.actions.refresh', 'Refresh')}+ </Button>+ )}+ >+ <div className="sk-email">+ {loading ? (+ <div className="sk-email__empty">{t('common.loading', 'Loading…')}</div>+ ) : (+ <>+ {activeTab === 'overview' && (+ <OverviewTab status={status} installed={installed} onChange={loadStatus} />+ )}+ {activeTab === 'domains' && (+ <DomainsTab domains={domains} onChange={loadDomains} />+ )}+ {activeTab === 'accounts' && (+ <AccountsTab domains={domains} />+ )}+ {activeTab === 'relay' && <RelayTab />}+ {activeTab === 'spam' && <SpamTab />}+ {activeTab === 'webmail' && <WebmailTab />}+ {activeTab === 'queue' && <QueueTab />}+ </>+ )}+ </div>+ </PageLayout>+ );+}++// ---------- Overview ----------+function OverviewTab({ status, installed, onChange }) {+ const { t } = useTranslation();+ const toast = useToast();+ const [installError, setInstallError] = useState(null);+ const components = status?.components || {};+ const names = Object.keys(components);++ // install_all answers {error, results: {postfix: {success, error}, ...}},+ // and the API client hangs that body off the thrown error as err.data. Dig+ // the failing components' stderr out of `results` so the user sees WHICH+ // component failed and why instead of a bare "Install failed". More than+ // one can fail in a single call: the installer only returns early on+ // postfix and dovecot, and lets dkim/spamassassin fall through.+ const installFailures = (err) => Object.entries(err?.data?.results || {})+ .filter(([, r]) => r && r.success === false)+ .map(([component, r]) => `${component}: ${r.error || 'unknown error'}`);++ const install = async () => {+ setInstallError(null);+ try {+ await api.installEmailServer();+ toast.success(t('app.email.emailServerInstallStarted', 'Email server install started'));+ onChange();+ } catch (err) {+ // err.message is the server's top-line reason ("Postfix+ // installation failed"); the failures carry the actual stderr.+ const summary = err?.message || 'Install failed';+ const failures = installFailures(err);+ // The toast stays one line — the inline block below keeps the full+ // detail on screen after the toast has gone.+ setInstallError([summary, ...failures].join('\n'));+ toast.error(failures.length ? `${summary} — ${failures[0]}` : summary);+ }+ };++ const control = async (component, action) => {+ try {+ await api.controlEmailService(component, action);+ toast.success(`${component}: ${action}`);+ onChange();+ } catch {+ toast.error(t('app.email.failedTo', 'Failed to {{action}} {{component}}', { action: action, component: component }));+ }+ };++ if (!installed) {+ return (+ <div className="sk-email__hero">+ <EmptyState+ icon={Server}+ title={t('app.email.mailServerNotInstalled', 'Mail server not installed')}+ description={t('app.email.mostPanelsNeverRunAMail', 'Most panels never run a mail server, install it when you need it.')}+ action={(+ <Button size="sm" onClick={install}>+ <Plus size={14} /> {t('app.email.installMailServer', 'Install mail server')}+ </Button>+ )}+ />+ <p className="sk-email__hero-note">+ {t('app.email.aDeliverabilityPreflightPtrPort25', 'A deliverability preflight (PTR, port 25, RBL) gates outbound sending before mail can leave this host.')}+ </p>+ {installError && (+ <p className="sk-email__hero-error" role="alert">{installError}</p>+ )}+ </div>+ );+ }++ const serviceRows = names.map((name) => {+ const running = components[name]?.running ?? components[name] === 'running';+ return { id: name, name, running };+ });++ const serviceColumns = [+ { key: 'component', headerKey: 'app.email.component', header: 'Component', sortable: true, hideable: false, sortValue: (r) => r.name, render: (r) => r.name },+ {+ key: 'state',+ headerKey: 'common.labels.state', header: 'State',+ sortable: true,+ sortValue: (r) => (r.running ? 1 : 0),+ render: (r) => <Pill kind={r.running ? 'green' : 'red'}>{r.running ? 'Running' : 'Stopped'}</Pill>,+ },+ {+ key: 'actions',+ header: '',+ hideable: false,+ className: 'sk-email__actions-col',+ cellClassName: 'sk-email__actions-cell',+ render: (r) => (+ <div className="sk-email__actions">+ <Button variant="ghost" size="sm" onClick={() => control(r.name, r.running ? 'restart' : 'start')}>+ {r.running ? 'Restart' : 'Start'}+ </Button>+ {r.running && (+ <Button variant="ghost" size="sm" onClick={() => control(r.name, 'stop')}>{t('common.actions.stop', 'Stop')}</Button>+ )}+ </div>+ ),+ },+ ];++ return (+ <section className="sk-email__section">+ <KpiBand>+ <MetricCard label={t('common.labels.domains', 'Domains')} value={status?.domains_count ?? 0} tone="accent" icon={<Globe size={16} />} />+ <MetricCard label={t('app.email.accounts', 'Accounts')} value={status?.accounts_count ?? 0} tone="cyan" icon={<Users size={16} />} />+ <MetricCard label={t('app.email.queue', 'Queue')} value={status?.queue_count ?? 0} tone="amber" icon={<Inbox size={16} />} />+ </KpiBand>++ <h2 className="sk-email__section-title"><Server size={16} /> {t('common.labels.services', 'Services')}</h2>+ <DataTable+ columns={serviceColumns}+ data={serviceRows}+ keyField="id"+ storageKey="serverkit-table-email-components"+ footer={<DataTableFooter shown={serviceRows.length} total={serviceRows.length} noun="service" />}+ emptyTitle="No service components reported."+ emptyMessage=""+ />+ </section>+ );+}++// ---------- Domains ----------+function DomainsTab({ domains, onChange }) {+ const { t } = useTranslation();+ const toast = useToast();+ const { confirm } = useConfirm();+ const [newDomain, setNewDomain] = useState('');+ const [verifying, setVerifying] = useState({});+ const [dnsResults, setDnsResults] = useState({});++ const add = async (e) => {+ e.preventDefault();+ if (!newDomain.trim()) return;+ try {+ await api.addEmailDomain({ name: newDomain.trim() });+ toast.success(t('app.email.domainAdded', 'Domain added'));+ setNewDomain('');+ onChange();+ } catch {+ toast.error(t('app.email.couldNotAddDomain', 'Could not add domain'));+ }+ };++ const remove = async (domain) => {+ const ok = await confirm({+ title: t('app.email.deleteDomain', 'Delete domain'),+ message: t('app.email.deleteAndAllOfItsAccounts', 'Delete {{name}} and all of its accounts and aliases?', { name: domain.name }),+ confirmLabel: t('common.actions.delete', 'Delete'),+ danger: true,+ });+ if (!ok) return;+ try {+ await api.deleteEmailDomain(domain.id);+ toast.success(t('app.email.domainDeleted', 'Domain deleted'));+ onChange();+ } catch {+ toast.error(t('app.email.deleteFailed', 'Delete failed'));+ }+ };++ const verify = async (domain) => {+ setVerifying((v) => ({ ...v, [domain.id]: true }));+ try {+ const res = await api.verifyEmailDNS(domain.id);+ setDnsResults((r) => ({ ...r, [domain.id]: res?.records || res || {} }));+ toast.success(t('app.email.dnsChecked', 'DNS checked'));+ } catch {+ toast.error(t('app.email.dnsCheckFailed', 'DNS check failed'));+ } finally {+ setVerifying((v) => ({ ...v, [domain.id]: false }));+ }+ };++ const deploy = async (domain) => {+ try {+ await api.deployEmailDNS(domain.id);+ toast.success(t('app.email.dnsRecordsDeployedToProvider', 'DNS records deployed to provider'));+ } catch {+ toast.error(t('app.email.deployFailedNoLinkedDnsProvider', 'Deploy failed (no linked DNS provider?)'));+ }+ };++ return (+ <section className="sk-email__section">+ <form className="sk-email__add" onSubmit={add}>+ <Input+ value={newDomain}+ onChange={(e) => setNewDomain(e.target.value)}+ placeholder="example.com"+ aria-label={t('app.email.newMailDomain', 'New mail domain')}+ />+ <Button type="submit" size="sm"><Plus size={14} /> {t('app.email.addDomain', 'Add domain')}</Button>+ </form>++ {domains.length === 0 ? (+ <div className="sk-email__empty">+ <Globe size={24} aria-hidden="true" />+ <p>{t('app.email.noMailDomainsYet', 'No mail domains yet.')}</p>+ </div>+ ) : (+ <ul className="sk-email__domains">+ {domains.map((domain) => {+ const dns = deriveDnsStatus(domain, dnsResults[domain.id]);+ return (+ <li key={domain.id} className="sk-email__domain">+ <div className="sk-email__domain-head">+ <span className="sk-email__domain-name">{domain.name}</span>+ <Pill kind={domain.is_active ? 'green' : 'gray'}>+ {domain.is_active ? 'Active' : 'Disabled'}+ </Pill>+ </div>++ <div className="sk-email__dns">+ {DNS_RECORDS.map(({ key, label }) => (+ <Pill key={key} kind={dnsPillKind(dns[key])} title={`${label}: ${dns[key]}`}>+ <DnsIcon state={dns[key]} /> {label}+ </Pill>+ ))}+ </div>++ <div className="sk-email__domain-meta">+ <span>{domain.accounts_count ?? 0} accounts</span>+ <span>{domain.aliases_count ?? 0} aliases</span>+ {domain.dkim_selector && <span>{t('app.email.dkimSelector', 'DKIM selector:')} {domain.dkim_selector}</span>}+ </div>++ <div className="sk-email__actions">+ <Button+ variant="outline"+ size="sm"+ onClick={() => verify(domain)}+ disabled={verifying[domain.id]}+ >+ <ShieldCheck size={14} /> {verifying[domain.id] ? 'Checking…' : 'Verify DNS'}+ </Button>+ <Button variant="outline" size="sm" onClick={() => deploy(domain)}>+ <ExternalLink size={14} /> {t('app.email.deployDns', 'Deploy DNS')}+ </Button>+ <Button variant="ghost" size="sm" onClick={() => remove(domain)}>+ <Trash2 size={14} /> {t('common.actions.delete', 'Delete')}+ </Button>+ </div>+ </li>+ );+ })}+ </ul>+ )}+ </section>+ );+}++// ---------- Accounts ----------++// Percent of an account's own quota in use, so a 200 MB mailbox on a 250 MB+// quota outranks a 2 GB one on 20 GB. null — not 0 — when no quota is set:+// an unlimited mailbox can never be "nearly full", and the rule engine drops+// nulls from every numeric comparison rather than reading them as empty.+function quotaPercent(account) {+ const total = account?.quota_mb ?? 0;+ if (!total) return null;+ return Math.round(((account.quota_used_mb ?? 0) / total) * 100);+}++// Built-in saved views for the accounts table.+//+// The rules match on what the State column's `value` accessor returns (the+// label the pill shows), NOT on the 1/0 its sortValue produces — filtering a+// string against a numeric rank is the one mistake that makes a preset match+// zero rows while looking perfectly correct.+const ACCOUNT_VIEWS = [+ { name: 'Active first', state: { search: '', sorts: [{ key: 'state', direction: 'desc' }], hiddenKeys: [], columnFilters: NO_RULES } },+ { name: 'Largest quota', state: { search: '', sorts: [{ key: 'quota', direction: 'desc' }], hiddenKeys: [], columnFilters: NO_RULES } },+ {+ // A disabled mailbox still exists and still holds its mail — it just+ // cannot authenticate. This is the list you audit after an offboarding.+ name: 'Disabled',+ state: {+ search: '', hiddenKeys: [],+ sorts: [{ key: 'email', direction: 'asc' }],+ columnFilters: {+ match: 'all',+ rules: [{ id: 'ac1', field: 'state', op: 'any', value: ['Disabled'] }],+ },+ },+ },+ {+ // Mailboxes about to start rejecting deliveries. Same 85% threshold the+ // fleet uses for disk pressure, and `gt` on a null keeps the unlimited+ // mailboxes out instead of ranking them as 0%.+ name: 'Nearly full',+ state: {+ search: '', hiddenKeys: [],+ sorts: [{ key: 'used', direction: 'desc' }],+ columnFilters: {+ match: 'all',+ rules: [{ id: 'ac2', field: 'used', op: 'gt', value: 85 }],+ },+ },+ },+];++function AccountsTab({ domains }) {+ const { t } = useTranslation();+ const toast = useToast();+ const { confirm } = useConfirm();+ const [domainId, setDomainId] = useState(domains[0]?.id ? String(domains[0].id) : '');+ const [accounts, setAccounts] = useState([]);+ const [loading, setLoading] = useState(false);+ const [search, setSearch] = useState('');+ const [form, setForm] = useState({ username: '', password: '', quota_mb: 1024 });+ const { sorts, setSorts } = useTableSort({ storageKey: 'serverkit-table-email-accounts-sort' });+ const { hiddenKeys, setHiddenKeys } = useColumnVisibility({ storageKey: 'serverkit-table-email-accounts-cols' });++ // The only view state this tab owns privately. Everything else — sorts,+ // hidden columns, column order, the column rules — is the shared envelope+ // useTableChrome captures for us. The selected domain deliberately stays+ // OUT of it: it is which list you are looking at, not how you are looking+ // at it, and a saved view that silently jumped domains would be a trap.+ const viewPageState = useMemo(() => ({ search }), [search]);+ const applyViewPageState = useCallback((saved) => {+ if (saved.search !== undefined) setSearch(saved.search);+ }, []);++ const load = useCallback(async () => {+ if (!domainId) { setAccounts([]); return; }+ setLoading(true);+ try {+ const res = await api.getEmailAccounts(domainId);+ setAccounts(res?.accounts || res || []);+ } catch {+ setAccounts([]);+ } finally {+ setLoading(false);+ }+ }, [domainId]);++ useEffect(() => { load(); }, [load]);++ const create = async (e) => {+ e.preventDefault();+ if (!form.username.trim() || !form.password) return;+ try {+ await api.createEmailAccount(domainId, form);+ toast.success(t('app.email.accountCreated', 'Account created'));+ setForm({ username: '', password: '', quota_mb: 1024 });+ load();+ } catch {+ toast.error(t('app.email.createFailed', 'Create failed'));+ }+ };++ const remove = async (account) => {+ const ok = await confirm({+ title: t('app.email.deleteAccount', 'Delete account'),+ message: t('app.email.delete3', 'Delete {{email}}?', { email: account.email }),+ confirmLabel: t('common.actions.delete', 'Delete'),+ danger: true,+ });+ if (!ok) return;+ try {+ await api.deleteEmailAccount(account.id);+ toast.success(t('app.email.accountDeleted', 'Account deleted'));+ load();+ } catch {+ toast.error(t('app.email.deleteFailed', 'Delete failed'));+ }+ };++ const filtered = useMemo(() => {+ const q = search.trim().toLowerCase();+ if (!q) return accounts;+ return accounts.filter((a) => (a.email || '').toLowerCase().includes(q));+ }, [accounts, search]);++ const accountColumns = [+ {+ key: 'email',+ headerKey: 'app.email.address', header: 'Address',+ sortable: true,+ hideable: false,+ sortValue: (a) => a.email || '',+ render: (a) => <span className="sk-email__mono">{a.email}</span>,+ },+ {+ key: 'quota',+ headerKey: 'app.email.quota', header: 'Quota',+ sortable: true,+ type: 'num',+ unit: ' MB',+ // The allocation, which is what "Largest quota" orders by. How full+ // it is lives in its own column below.+ value: (a) => a.quota_mb ?? 0,+ sortValue: (a) => a.quota_mb ?? 0,+ render: (a) => `${a.quota_used_mb ?? 0} / ${a.quota_mb ?? 0} MB`,+ },+ {+ key: 'used',+ headerKey: 'app.email.used', header: 'Used',+ sortable: true,+ type: 'num',+ unit: '%',+ value: quotaPercent,+ sortValue: quotaPercent,+ render: (a) => {+ const pct = quotaPercent(a);+ return pct == null ? '—' : `${pct}%`;+ },+ },+ {+ key: 'state',+ headerKey: 'common.labels.state', header: 'State',+ sortable: true,+ // Filter on the label the pill shows; keep the 1/0 sortValue so+ // "Active first" still puts active first when the column sorts desc.+ type: 'enum',+ value: (a) => (a.is_active ? 'Active' : 'Disabled'),+ sortValue: (a) => (a.is_active ? 1 : 0),+ render: (a) => <Pill kind={a.is_active ? 'green' : 'gray'}>{a.is_active ? 'Active' : 'Disabled'}</Pill>,+ },+ {+ key: 'actions',+ header: '',+ hideable: false,+ className: 'sk-email__actions-col',+ cellClassName: 'sk-email__actions-cell',+ render: (a) => (+ <div className="sk-email__actions">+ <Button variant="ghost" size="sm" onClick={() => remove(a)}>+ <Trash2 size={14} /> {t('common.actions.delete', 'Delete')}+ </Button>+ </div>+ ),+ },+ ];++ // Each tab is its own route, so only one picker is ever mounted — this+ // chrome is scoped to the accounts table alone and keeps its own page key.+ const chrome = useTableChrome({+ columns: accountColumns,+ rows: filtered,+ viewPageKey: 'email-accounts',+ builtinViews: ACCOUNT_VIEWS,+ noun: 'accounts',+ sorts,+ setSorts,+ hiddenKeys,+ setHiddenKeys,+ pageState: viewPageState,+ applyPage: applyViewPageState,+ });++ if (domains.length === 0) {+ return (+ <div className="sk-email__empty">+ <Users size={24} aria-hidden="true" />+ <p>{t('app.email.addAMailDomainFirst', 'Add a mail domain first.')}</p>+ </div>+ );+ }++ return (+ <section className="sk-email__section">+ {/* One row of chrome: the view name and the table's own controls.+ What stays in the toolbar below is not chrome — the domain+ select is WHICH list you are looking at. */}+ <GridViewPicker+ views={chrome.views}+ label="accounts"+ onCreate={chrome.createView}+ actions={(+ <>+ <GridFilterButton+ count={chrome.filterCount}+ onClick={() => chrome.setDrawerOpen(true)}+ />+ <GridToolsMenu {...chrome.toolsProps} onRefresh={load} />+ </>+ )}+ />+ <ListToolbar className="sk-email__filters">+ <label>+ {t('common.labels.domain', 'Domain')}+ <select value={domainId} onChange={(e) => setDomainId(e.target.value)}>+ {domains.map((d) => <option key={d.id} value={String(d.id)}>{d.name}</option>)}+ </select>+ </label>+ <label className="search-box">+ <Search size={16} />+ <Input+ type="text"+ value={search}+ onChange={(e) => setSearch(e.target.value)}+ placeholder={t('app.email.searchAccountsByAddress', 'Search accounts by address…')}+ aria-label={t('app.email.searchAccounts', 'Search accounts')}+ />+ </label>+ </ListToolbar>++ <GridChips {...chrome.chipProps} />++ <form className="sk-email__add" onSubmit={create}>+ <Input+ value={form.username}+ onChange={(e) => setForm({ ...form, username: e.target.value })}+ placeholder="username"+ aria-label={t('app.email.mailboxUsername', 'Mailbox username')}+ />+ <Input+ type="password"+ value={form.password}+ onChange={(e) => setForm({ ...form, password: e.target.value })}+ placeholder="password"+ aria-label={t('app.email.mailboxPassword', 'Mailbox password')}+ />+ <Input+ type="number"+ value={form.quota_mb}+ onChange={(e) => setForm({ ...form, quota_mb: Number(e.target.value) })}+ placeholder={t('app.email.quotaMb', 'Quota (MB)')}+ aria-label={t('app.email.quotaInMb', 'Quota in MB')}+ />+ <Button type="submit" size="sm"><Plus size={14} /> {t('common.actions.create', 'Create')}</Button>+ </form>++ <DataTable+ columns={chrome.columns}+ data={filtered}+ keyField="id"+ sorts={sorts}+ onSortsChange={setSorts}+ {...chrome.tableProps}+ loading={loading}+ footer={<DataTableFooter shown={filtered.length} total={accounts.length} noun="account" />}+ emptyTitle={accounts.length === 0 ? 'No accounts in this domain.' : 'No accounts match this search.'}+ emptyMessage=""+ />++ <GridFilterDrawer {...chrome.drawerProps} />+ </section>+ );+}++// ---------- Relay (smarthost) ----------+function RelayTab() {+ const { t } = useTranslation();+ const toast = useToast();+ const [relay, setRelay] = useState({ host: '', port: 587, username: '', password: '', enabled: false });+ const [loading, setLoading] = useState(true);++ useEffect(() => {+ let alive = true;+ api.getEmailRelay()+ .then((res) => { if (alive) setRelay((r) => ({ ...r, ...(res?.relay || res || {}) })); })+ .catch(() => { /* defaults */ })+ .finally(() => { if (alive) setLoading(false); });+ return () => { alive = false; };+ }, []);++ const save = async (e) => {+ e.preventDefault();+ try {+ await api.updateEmailRelay(relay);+ toast.success(t('app.email.relaySaved', 'Relay saved'));+ } catch {+ toast.error(t('app.email.saveFailed', 'Save failed'));+ }+ };++ const test = async () => {+ try {+ await api.testEmailRelay(relay);+ toast.success(t('app.email.relayReachable', 'Relay reachable'));+ } catch {+ toast.error(t('app.email.relayTestFailed', 'Relay test failed'));+ }+ };++ const disable = async () => {+ try {+ await api.disableEmailRelay();+ setRelay((r) => ({ ...r, enabled: false }));+ toast.success(t('app.email.relayDisabled', 'Relay disabled'));+ } catch {+ toast.error(t('app.email.failedToDisableRelay', 'Failed to disable relay'));+ }+ };++ if (loading) return <div className="sk-email__empty">{t('common.loading', 'Loading…')}</div>;++ return (+ <section className="sk-email__section">+ <h2 className="sk-email__section-title"><Send size={16} /> {t('app.email.outboundRelaySmarthost', 'Outbound relay (smarthost)')}</h2>+ <form className="sk-email__form" onSubmit={save}>+ <label>{t('app.email.host', 'Host')}<Input value={relay.host || ''} onChange={(e) => setRelay({ ...relay, host: e.target.value })} placeholder="smtp.provider.com" /></label>+ <label>{t('common.labels.port', 'Port')}<Input type="number" value={relay.port || 587} onChange={(e) => setRelay({ ...relay, port: Number(e.target.value) })} /></label>+ <label>{t('common.labels.username', 'Username')}<Input value={relay.username || ''} onChange={(e) => setRelay({ ...relay, username: e.target.value })} /></label>+ <label>{t('common.labels.password', 'Password')}<Input type="password" value={relay.password || ''} onChange={(e) => setRelay({ ...relay, password: e.target.value })} /></label>+ <label className="sk-email__check">+ <input type="checkbox" checked={!!relay.enabled} onChange={(e) => setRelay({ ...relay, enabled: e.target.checked })} />+ {t('app.email.enableRelay', 'Enable relay')}+ </label>+ <div className="sk-email__actions">+ <Button type="submit" size="sm">{t('common.actions.save', 'Save')}</Button>+ <Button type="button" variant="outline" size="sm" onClick={test}>{t('common.actions.test', 'Test')}</Button>+ <Button type="button" variant="ghost" size="sm" onClick={disable}>{t('common.actions.disable', 'Disable')}</Button>+ </div>+ </form>+ </section>+ );+}++// ---------- Spam ----------+function SpamTab() {+ const { t } = useTranslation();+ const toast = useToast();+ const [config, setConfig] = useState({ enabled: true, required_score: 5 });+ const [loading, setLoading] = useState(true);++ useEffect(() => {+ let alive = true;+ api.getSpamConfig()+ .then((res) => { if (alive) setConfig((c) => ({ ...c, ...(res?.config || res || {}) })); })+ .catch(() => { /* defaults */ })+ .finally(() => { if (alive) setLoading(false); });+ return () => { alive = false; };+ }, []);++ const save = async (e) => {+ e.preventDefault();+ try {+ await api.updateSpamConfig(config);+ toast.success(t('app.email.spamConfigSaved', 'Spam config saved'));+ } catch {+ toast.error(t('app.email.saveFailed', 'Save failed'));+ }+ };++ const updateRules = async () => {+ try {+ await api.updateSpamRules();+ toast.success(t('app.email.ruleUpdateStarted', 'Rule update started'));+ } catch {+ toast.error(t('app.email.ruleUpdateFailed', 'Rule update failed'));+ }+ };++ if (loading) return <div className="sk-email__empty">{t('common.loading', 'Loading…')}</div>;++ return (+ <section className="sk-email__section">+ <h2 className="sk-email__section-title"><Filter size={16} /> {t('app.email.spamassassin', 'SpamAssassin')}</h2>+ <form className="sk-email__form" onSubmit={save}>+ <label className="sk-email__check">+ <input type="checkbox" checked={!!config.enabled} onChange={(e) => setConfig({ ...config, enabled: e.target.checked })} />+ {t('app.email.enableSpamFiltering', 'Enable spam filtering')}+ </label>+ <label>{t('app.email.requiredScore', 'Required score')}<Input type="number" step="0.1" value={config.required_score ?? 5} onChange={(e) => setConfig({ ...config, required_score: Number(e.target.value) })} /></label>+ <div className="sk-email__actions">+ <Button type="submit" size="sm">{t('common.actions.save', 'Save')}</Button>+ <Button type="button" variant="outline" size="sm" onClick={updateRules}>{t('app.email.updateRules', 'Update rules')}</Button>+ </div>+ </form>+ </section>+ );+}++// ---------- Webmail ----------+function WebmailTab() {+ const { t } = useTranslation();+ const toast = useToast();+ const [state, setState] = useState(null);+ const [loading, setLoading] = useState(true);++ const load = useCallback(async () => {+ try {+ const res = await api.getWebmailStatus();+ setState(res?.status || res || null);+ } catch {+ setState(null);+ } finally {+ setLoading(false);+ }+ }, []);++ useEffect(() => { load(); }, [load]);++ const install = async () => {+ try {+ await api.installWebmail();+ toast.success(t('app.email.webmailInstallStarted', 'Webmail install started'));+ load();+ } catch {+ toast.error(t('app.email.installFailed', 'Install failed'));+ }+ };++ const control = async (action) => {+ try {+ await api.controlWebmail(action);+ toast.success(t('app.email.webmail', 'Webmail: {{action}}', { action: action }));+ load();+ } catch {+ toast.error(t('app.email.failedToWebmail', 'Failed to {{action}} webmail', { action: action }));+ }+ };++ if (loading) return <div className="sk-email__empty">{t('common.loading', 'Loading…')}</div>;++ const installed = state?.installed ?? state?.is_installed;+ const running = state?.running;++ return (+ <section className="sk-email__section">+ <h2 className="sk-email__section-title"><Inbox size={16} /> {t('app.email.roundcubeWebmail', 'Roundcube webmail')}</h2>+ {!installed ? (+ <div className="sk-email__empty">+ <p>{t('app.email.webmailIsNotInstalled', 'Webmail is not installed.')}</p>+ <Button size="sm" onClick={install}><Plus size={14} /> {t('app.email.installWebmail', 'Install webmail')}</Button>+ </div>+ ) : (+ <div className="sk-email__actions">+ <Pill kind={running ? 'green' : 'red'}>{running ? 'Running' : 'Stopped'}</Pill>+ <Button variant="outline" size="sm" onClick={() => control(running ? 'restart' : 'start')}>+ {running ? 'Restart' : 'Start'}+ </Button>+ {running && <Button variant="ghost" size="sm" onClick={() => control('stop')}>{t('common.actions.stop', 'Stop')}</Button>}+ </div>+ )}+ </section>+ );+}++// ---------- Mail queue ----------++// Built-in saved views for the queue.+//+// The queue payload is `mailq` output — a queue id, a byte size, a sender and+// its recipients. There is no status field, so nothing here pretends there is+// one: the only rule-based preset filters on `size`, which is a real integer on+// every row (see PostfixService.get_queue).+const QUEUE_VIEWS = [+ { name: 'Largest first', state: { search: '', sorts: [{ key: 'size', direction: 'desc' }], hiddenKeys: [], columnFilters: NO_RULES } },+ { name: 'By sender', state: { search: '', sorts: [{ key: 'sender', direction: 'asc' }], hiddenKeys: [], columnFilters: NO_RULES } },+ {+ // What a backed-up queue is usually full of. 100 KB is the line between+ // a plain message (a few KB) and one carrying an attachment; Postfix's+ // own message_size_limit is 25 MB, so this is well inside real traffic.+ name: 'Large messages',+ state: {+ search: '', hiddenKeys: [],+ sorts: [{ key: 'size', direction: 'desc' }],+ columnFilters: {+ match: 'all',+ rules: [{ id: 'q1', field: 'size', op: 'gt', value: 102400 }],+ },+ },+ },+];++function QueueTab() {+ const { t } = useTranslation();+ const toast = useToast();+ const [queue, setQueue] = useState([]);+ const [loading, setLoading] = useState(true);+ const [search, setSearch] = useState('');+ const { sorts, setSorts } = useTableSort({ storageKey: 'serverkit-table-email-queue-sort' });+ const { hiddenKeys, setHiddenKeys } = useColumnVisibility({ storageKey: 'serverkit-table-email-queue-cols' });++ // Search is all this tab owns privately; the rest of the view state is the+ // shared envelope useTableChrome captures.+ const viewPageState = useMemo(() => ({ search }), [search]);+ const applyViewPageState = useCallback((saved) => {+ if (saved.search !== undefined) setSearch(saved.search);+ }, []);++ const load = useCallback(async () => {+ setLoading(true);+ try {+ const res = await api.getMailQueue();+ setQueue(res?.queue || res || []);+ } catch {+ setQueue([]);+ } finally {+ setLoading(false);+ }+ }, []);++ useEffect(() => { load(); }, [load]);++ const flush = async () => {+ try {+ await api.flushMailQueue();+ toast.success(t('app.email.queueFlushed', 'Queue flushed'));+ load();+ } catch {+ toast.error(t('app.email.flushFailed', 'Flush failed'));+ }+ };++ const remove = async (id) => {+ try {+ await api.deleteMailQueueItem(id);+ load();+ } catch {+ toast.error(t('app.email.deleteFailed', 'Delete failed'));+ }+ };++ const filtered = queue.filter((item) => {+ const q = search.trim().toLowerCase();+ if (!q) return true;+ const id = String(item.id || item.queue_id || '').toLowerCase();+ const sender = String(item.sender || '').toLowerCase();+ const recipient = String(item.recipient || '').toLowerCase();+ return id.includes(q) || sender.includes(q) || recipient.includes(q);+ });++ const queueColumns = [+ {+ key: 'id',+ header: 'ID',+ sortable: true,+ hideable: false,+ sortValue: (item) => item.id || item.queue_id || '',+ render: (item) => <span className="sk-email__mono">{item.id || item.queue_id}</span>,+ },+ { key: 'sender', headerKey: 'app.email.sender', header: 'Sender', sortable: true, sortValue: (item) => item.sender || null, render: (item) => item.sender || '-' },+ { key: 'recipient', headerKey: 'app.email.recipient', header: 'Recipient', sortable: true, sortValue: (item) => item.recipient || null, render: (item) => item.recipient || '-' },+ {+ key: 'size',+ headerKey: 'common.labels.size', header: 'Size',+ sortable: true,+ // Bytes, straight off mailq. Typed explicitly because a preset+ // filters on it — inference would land on 'num' here anyway, but+ // only for as long as every loaded row happens to carry a size.+ type: 'num',+ unit: ' bytes',+ value: (item) => item.size ?? null,+ sortValue: (item) => item.size ?? null,+ render: (item) => item.size || '-',+ },+ {+ key: 'actions',+ header: '',+ hideable: false,+ className: 'sk-email__actions-col',+ cellClassName: 'sk-email__actions-cell',+ render: (item) => (+ <div className="sk-email__actions">+ <Button variant="ghost" size="sm" onClick={() => remove(item.id || item.queue_id)}>+ <Trash2 size={14} /> {t('common.actions.delete', 'Delete')}+ </Button>+ </div>+ ),+ },+ ];++ const chrome = useTableChrome({+ columns: queueColumns,+ rows: filtered,+ viewPageKey: 'email-queue',+ builtinViews: QUEUE_VIEWS,+ noun: 'messages',+ sorts,+ setSorts,+ hiddenKeys,+ setHiddenKeys,+ pageState: viewPageState,+ applyPage: applyViewPageState,+ });++ return (+ <section className="sk-email__section">+ {/* Everything that acts on the queue rides the view line, in the+ same order the topbar pages use: action, search, filter, "⋮".+ Refresh is not repeated as a button — it is in the "⋮". */}+ <GridViewPicker+ views={chrome.views}+ label="messages"+ onCreate={chrome.createView}+ actions={(+ <>+ <Button variant="outline" size="sm" onClick={flush}>{t('app.email.flushQueue', 'Flush queue')}</Button>+ <SearchField+ value={search}+ onSearch={setSearch}+ placeholder={t('app.email.searchQueueBySenderRecipientOr', 'Search queue by sender, recipient, or ID…')}+ />+ <GridFilterButton+ count={chrome.filterCount}+ onClick={() => chrome.setDrawerOpen(true)}+ />+ <GridToolsMenu {...chrome.toolsProps} onRefresh={load} />+ </>+ )}+ />++ <GridChips {...chrome.chipProps} />++ <DataTable+ columns={chrome.columns}+ data={filtered}+ keyField={(item) => item.id || item.queue_id}+ sorts={sorts}+ onSortsChange={setSorts}+ {...chrome.tableProps}+ loading={loading}+ footer={<DataTableFooter shown={filtered.length} total={queue.length} noun="message" />}+ emptyTitle={queue.length === 0 ? 'The mail queue is empty.' : 'No messages match this search.'}+ emptyMessage=""+ />++ <GridFilterDrawer {...chrome.drawerProps} />+ </section>+ );+}diff --git a/frontend/src/plugins/serverkit-email/services/email.js b/frontend/src/plugins/serverkit-email/services/email.jsnew file mode 100644index 00000000..78e811ab--- /dev/null+++ b/frontend/src/plugins/serverkit-email/services/email.js@@ -0,0 +1,69 @@+// The extension's own /api/v1/email client, built on the panel's ApiClient+// via the SDK singleton (JWT refresh, workspace headers, error normalization+// included) — moved out of the host's services/api/system.js with the page.+//+// Two email surfaces deliberately STAY core and are not duplicated here:+// the DNS-provider connections (/email/dns-providers — a core blueprint that+// keeps its historical prefix) and the Settings → Connections relay tile's+// calls. The relay methods below are this extension's own copies for the+// Relay tab; the page and the Settings tile hit the same endpoints.+import { api } from 'serverkit-sdk';++const emailApi = {+ // Server+ getEmailStatus: () => api.request('/email/status'),+ installEmailServer: (data = {}) => api.request('/email/install', { method: 'POST', body: JSON.stringify(data) }),+ controlEmailService: (component, action) => api.request(`/email/service/${component}/${action}`, { method: 'POST' }),++ // Domains+ getEmailDomains: () => api.request('/email/domains'),+ addEmailDomain: (data) => api.request('/email/domains', { method: 'POST', body: JSON.stringify(data) }),+ getEmailDomain: (domainId) => api.request(`/email/domains/${domainId}`),+ deleteEmailDomain: (domainId) => api.request(`/email/domains/${domainId}`, { method: 'DELETE' }),+ verifyEmailDNS: (domainId) => api.request(`/email/domains/${domainId}/verify-dns`, { method: 'POST' }),+ deployEmailDNS: (domainId) => api.request(`/email/domains/${domainId}/deploy-dns`, { method: 'POST' }),++ // Accounts+ getEmailAccounts: (domainId) => api.request(`/email/domains/${domainId}/accounts`),+ createEmailAccount: (domainId, data) => api.request(`/email/domains/${domainId}/accounts`, { method: 'POST', body: JSON.stringify(data) }),+ getEmailAccount: (accountId) => api.request(`/email/accounts/${accountId}`),+ updateEmailAccount: (accountId, data) => api.request(`/email/accounts/${accountId}`, { method: 'PUT', body: JSON.stringify(data) }),+ deleteEmailAccount: (accountId) => api.request(`/email/accounts/${accountId}`, { method: 'DELETE' }),+ changeEmailPassword: (accountId, password) => api.request(`/email/accounts/${accountId}/password`, { method: 'POST', body: JSON.stringify({ password }) }),++ // Aliases+ getEmailAliases: (domainId) => api.request(`/email/domains/${domainId}/aliases`),+ createEmailAlias: (domainId, data) => api.request(`/email/domains/${domainId}/aliases`, { method: 'POST', body: JSON.stringify(data) }),+ deleteEmailAlias: (aliasId) => api.request(`/email/aliases/${aliasId}`, { method: 'DELETE' }),++ // Forwarding+ getEmailForwarding: (accountId) => api.request(`/email/accounts/${accountId}/forwarding`),+ createEmailForwarding: (accountId, data) => api.request(`/email/accounts/${accountId}/forwarding`, { method: 'POST', body: JSON.stringify(data) }),+ updateEmailForwarding: (ruleId, data) => api.request(`/email/forwarding/${ruleId}`, { method: 'PUT', body: JSON.stringify(data) }),+ deleteEmailForwarding: (ruleId) => api.request(`/email/forwarding/${ruleId}`, { method: 'DELETE' }),++ // Outbound SMTP relay (smarthost)+ getEmailRelay: () => api.request('/email/relay'),+ updateEmailRelay: (data) => api.request('/email/relay', { method: 'PUT', body: JSON.stringify(data) }),+ testEmailRelay: (data) => api.request('/email/relay/test', { method: 'POST', body: JSON.stringify(data) }),+ disableEmailRelay: () => api.request('/email/relay', { method: 'DELETE' }),++ // SpamAssassin+ getSpamConfig: () => api.request('/email/spam/config'),+ updateSpamConfig: (data) => api.request('/email/spam/config', { method: 'PUT', body: JSON.stringify(data) }),+ updateSpamRules: () => api.request('/email/spam/update-rules', { method: 'POST' }),++ // Roundcube webmail+ getWebmailStatus: () => api.request('/email/webmail/status'),+ installWebmail: (data = {}) => api.request('/email/webmail/install', { method: 'POST', body: JSON.stringify(data) }),+ controlWebmail: (action) => api.request(`/email/webmail/service/${action}`, { method: 'POST' }),+ configureWebmailProxy: (domain) => api.request('/email/webmail/configure-proxy', { method: 'POST', body: JSON.stringify({ domain }) }),++ // Mail queue & logs+ getMailQueue: () => api.request('/email/queue'),+ flushMailQueue: () => api.request('/email/queue/flush', { method: 'POST' }),+ deleteMailQueueItem: (queueId) => api.request(`/email/queue/${queueId}`, { method: 'DELETE' }),+ getMailLogs: (lines = 100) => api.request(`/email/logs?lines=${lines}`),+};++export default emailApi;diff --git a/frontend/src/plugins/serverkit-email/styles/email.scss b/frontend/src/plugins/serverkit-email/styles/email.scssnew file mode 100644index 00000000..299ecb8c--- /dev/null+++ b/frontend/src/plugins/serverkit-email/styles/email.scss@@ -0,0 +1,277 @@+// Compiled through the extension's module graph (imported by index.jsx).+// The host's design-token partial is imported via a sync-safe relative+// path — the baked copy lives at frontend/src/plugins/serverkit-email/,+// so this resolves to frontend/src/styles/_variables.scss.+@import '../../../styles/variables';++// ============================================+// EMAIL SERVER PAGE (redesign — infra console look, REDESIGN_MAP #18):+// status Pills on the Services list, MetricCard KPI strip (Overview),+// dense .sk-dtable lists (services / accounts / queue), mono-uppercase+// eyebrow section headers, token surfaces. Domains stay as a designed+// card list. Class namespace = `sk-email` (the rebuilt Email.jsx emits it).+//+// Mail-volume chart, reputation/RBL ring, structured activity feed,+// per-mailbox storage gauges and per-message retry are intentionally+// absent — no backend yet (REDESIGN_MAP §5).+// ============================================++.sk-email {+ padding: $space-6;++ // ── Sections stack with breathing room ──────────────────+ &__section {+ display: flex;+ flex-direction: column;+ gap: $space-5;+ }++ // ── Mono-uppercase eyebrow section headers ──────────────+ &__section-title {+ display: flex;+ align-items: center;+ gap: $space-2;+ margin: 0;+ font-family: var(--mono);+ font-size: 10.5px;+ font-weight: $font-weight-semibold;+ letter-spacing: 0.08em;+ text-transform: uppercase;+ color: var(--text-faint);++ svg { color: var(--text-dim); }+ }++ // ── Empty / loading placeholders (shared look) ──────────+ &__empty {+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ gap: $space-2;+ padding: $space-6 $space-5;+ background: var(--surface);+ border: 1px solid var(--border-soft);+ border-radius: var(--radius-lg);+ text-align: center;+ color: var(--text-dim);+ font-size: $font-size-sm;++ svg { color: var(--text-faint); }++ p { margin: 0; }+ }++ // ── Not-installed hero (EmptyState + preflight note) ─────+ &__hero {+ max-width: 560px;+ margin: $space-6 auto 0;++ .empty-state {+ background: var(--surface);+ border: 1px solid var(--border-soft);+ border-radius: var(--radius-lg);+ padding: $space-8 $space-6;+ }+ }++ &__hero-note {+ margin: $space-4 0 0;+ padding: $space-3 $space-4;+ background: var(--accent-bg);+ border: 1px solid var(--border-soft);+ border-radius: var(--radius);+ font-family: var(--mono);+ font-size: 11.5px;+ line-height: 1.55;+ color: var(--text-dim);+ text-align: center;+ }++ // Inline install failure (component + stderr from the API) — same card+ // chrome as the hero note, in the danger tone. pre-line keeps one failing+ // component per line; anywhere stops a long unbroken stderr token from+ // widening the hero.+ &__hero-error {+ margin: $space-3 0 0;+ padding: $space-3 $space-4;+ background: var(--red-bg);+ border: 1px solid var(--red);+ border-radius: var(--radius);+ font-family: var(--mono);+ font-size: 11.5px;+ line-height: 1.55;+ color: var(--red);+ white-space: pre-line;+ overflow-wrap: anywhere;+ text-align: left;+ }++ // ── Action clusters (row actions, form buttons, toolbars) ─+ &__actions {+ display: flex;+ align-items: center;+ gap: $space-2;+ flex-wrap: wrap;+ }++ // Right-align the DataTable actions column+ &__actions-col { text-align: right; }++ &__actions-cell {+ text-align: right;++ .sk-email__actions { justify-content: flex-end; }+ }++ // ── Filters toolbar (domain select + search) ────────────+ // The row layout is the shared ListToolbar (.sk-listhead); this class+ // rides along on it to keep the eyebrow labels, select chrome and+ // search-box sizing below.+ &__filters {+ > label {+ display: flex;+ align-items: center;+ gap: $space-2;+ font-family: var(--mono);+ font-size: 10px;+ font-weight: $font-weight-semibold;+ letter-spacing: 0.08em;+ text-transform: uppercase;+ color: var(--text-faint);+ }++ select {+ padding: 6px 10px;+ background: var(--surface-2);+ border: 1px solid var(--border);+ border-radius: $radius-md;+ color: var(--text);+ font-family: $font-mono;+ font-size: $font-size-sm;+ cursor: pointer;++ &:focus {+ outline: none;+ border-color: var(--accent);+ }+ }++ // The global .search-box keeps its own chrome; just let it grow.+ .search-box {+ flex: 1;+ min-width: 220px;+ max-width: 360px;+ }+ }++ // ── Inline create/add forms (domain + account) ──────────+ &__add,+ &__form {+ display: flex;+ flex-wrap: wrap;+ align-items: flex-end;+ gap: $space-3;+ padding: $space-4 $space-5;+ background: var(--surface);+ border: 1px solid var(--border-soft);+ border-radius: var(--radius-lg);++ label {+ display: flex;+ flex-direction: column;+ gap: $space-1;+ font-family: var(--mono);+ font-size: 10px;+ font-weight: $font-weight-semibold;+ letter-spacing: 0.08em;+ text-transform: uppercase;+ color: var(--text-faint);+ }+ }++ &__form { flex-direction: column; align-items: stretch; }++ // Checkbox rows keep sentence case (not eyebrow uppercase)+ &__check {+ flex-direction: row;+ align-items: center;+ gap: $space-2;+ font-family: inherit;+ font-size: $font-size-sm;+ font-weight: $font-weight-normal;+ letter-spacing: normal;+ text-transform: none;+ color: var(--text-dim);+ cursor: pointer;++ input[type='checkbox'] {+ width: 15px;+ height: 15px;+ accent-color: var(--accent);+ }+ }++ // ── Domains card list (kept as designed cards) ──────────+ &__domains {+ list-style: none;+ margin: 0;+ padding: 0;+ display: grid;+ grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));+ gap: $space-4;+ }++ &__domain {+ display: flex;+ flex-direction: column;+ gap: $space-3;+ padding: 15px 16px;+ background: var(--surface);+ border: 1px solid var(--border-soft);+ border-radius: var(--radius-lg);+ transition: border-color $transition-fast;++ &:hover { border-color: var(--border-strong); }+ }++ &__domain-head {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: $space-3;+ }++ &__domain-name {+ font-family: var(--mono);+ font-size: 13.5px;+ font-weight: $font-weight-semibold;+ color: var(--text);+ overflow-wrap: anywhere;+ }++ &__dns {+ display: flex;+ flex-wrap: wrap;+ gap: 6px;+ }++ &__domain-meta {+ display: flex;+ flex-wrap: wrap;+ gap: $space-3;+ padding-top: $space-3;+ border-top: 1px solid var(--border-soft);+ font-family: var(--mono);+ font-size: 11.5px;+ color: var(--text-faint);+ }++ // ── Mono cell emphasis (queue ids, addresses) ───────────+ &__mono {+ font-family: var(--mono);+ font-size: 12.5px;+ color: var(--text);+ overflow-wrap: anywhere;+ }+}diff --git a/frontend/src/services/api/system.js b/frontend/src/services/api/system.jsindex b5afd322..ea18bca8 100644--- a/frontend/src/services/api/system.js+++ b/frontend/src/services/api/system.js@@ -778,37 +778,13 @@ export async function testUserNotification() {});}-// Email Server-export async function getEmailStatus() { return this.request('/email/status'); }-export async function installEmailServer(data = {}) { return this.request('/email/install', { method: 'POST', body: JSON.stringify(data) }); }-export async function controlEmailService(component, action) { return this.request(`/email/service/${component}/${action}`, { method: 'POST' }); }--// Email Domains-export async function getEmailDomains() { return this.request('/email/domains'); }-export async function addEmailDomain(data) { return this.request('/email/domains', { method: 'POST', body: JSON.stringify(data) }); }-export async function getEmailDomain(domainId) { return this.request(`/email/domains/${domainId}`); }-export async function deleteEmailDomain(domainId) { return this.request(`/email/domains/${domainId}`, { method: 'DELETE' }); }-export async function verifyEmailDNS(domainId) { return this.request(`/email/domains/${domainId}/verify-dns`, { method: 'POST' }); }-export async function deployEmailDNS(domainId) { return this.request(`/email/domains/${domainId}/deploy-dns`, { method: 'POST' }); }--// Email Accounts-export async function getEmailAccounts(domainId) { return this.request(`/email/domains/${domainId}/accounts`); }-export async function createEmailAccount(domainId, data) { return this.request(`/email/domains/${domainId}/accounts`, { method: 'POST', body: JSON.stringify(data) }); }-export async function getEmailAccount(accountId) { return this.request(`/email/accounts/${accountId}`); }-export async function updateEmailAccount(accountId, data) { return this.request(`/email/accounts/${accountId}`, { method: 'PUT', body: JSON.stringify(data) }); }-export async function deleteEmailAccount(accountId) { return this.request(`/email/accounts/${accountId}`, { method: 'DELETE' }); }-export async function changeEmailPassword(accountId, password) { return this.request(`/email/accounts/${accountId}/password`, { method: 'POST', body: JSON.stringify({ password }) }); }--// Email Aliases-export async function getEmailAliases(domainId) { return this.request(`/email/domains/${domainId}/aliases`); }-export async function createEmailAlias(domainId, data) { return this.request(`/email/domains/${domainId}/aliases`, { method: 'POST', body: JSON.stringify(data) }); }-export async function deleteEmailAlias(aliasId) { return this.request(`/email/aliases/${aliasId}`, { method: 'DELETE' }); }--// Email Forwarding-export async function getEmailForwarding(accountId) { return this.request(`/email/accounts/${accountId}/forwarding`); }-export async function createEmailForwarding(accountId, data) { return this.request(`/email/accounts/${accountId}/forwarding`, { method: 'POST', body: JSON.stringify(data) }); }-export async function updateEmailForwarding(ruleId, data) { return this.request(`/email/forwarding/${ruleId}`, { method: 'PUT', body: JSON.stringify(data) }); }-export async function deleteEmailForwarding(ruleId) { return this.request(`/email/forwarding/${ruleId}`, { method: 'DELETE' }); }+// Email Server management moved into the serverkit-email extension+// (builtin-extensions/serverkit-email/frontend/services/email.js) with the+// Email page — plan 52 Phase 2. Core keeps only the two email-adjacent+// surfaces that core Settings → Connections renders: the DNS-provider+// connections below (served by the core dns_providers blueprint, which owns+// the historical /email/dns-providers prefix) and the outbound relay tile+// (served by the extension's API; the tile degrades when it is absent).// DNS Providersexport async function getEmailDNSProviders() { return this.request('/email/dns-providers'); }@@ -823,23 +799,6 @@ export async function updateEmailRelay(data) { return this.request('/email/relayexport async function testEmailRelay(data) { return this.request('/email/relay/test', { method: 'POST', body: JSON.stringify(data) }); }export async function disableEmailRelay() { return this.request('/email/relay', { method: 'DELETE' }); }-// SpamAssassin-export async function getSpamConfig() { return this.request('/email/spam/config'); }-export async function updateSpamConfig(data) { return this.request('/email/spam/config', { method: 'PUT', body: JSON.stringify(data) }); }-export async function updateSpamRules() { return this.request('/email/spam/update-rules', { method: 'POST' }); }--// Roundcube Webmail-export async function getWebmailStatus() { return this.request('/email/webmail/status'); }-export async function installWebmail(data = {}) { return this.request('/email/webmail/install', { method: 'POST', body: JSON.stringify(data) }); }-export async function controlWebmail(action) { return this.request(`/email/webmail/service/${action}`, { method: 'POST' }); }-export async function configureWebmailProxy(domain) { return this.request('/email/webmail/configure-proxy', { method: 'POST', body: JSON.stringify({ domain }) }); }--// Mail Queue & Logs-export async function getMailQueue() { return this.request('/email/queue'); }-export async function flushMailQueue() { return this.request('/email/queue/flush', { method: 'POST' }); }-export async function deleteMailQueueItem(queueId) { return this.request(`/email/queue/${queueId}`, { method: 'DELETE' }); }-export async function getMailLogs(lines = 100) { return this.request(`/email/logs?lines=${lines}`); }-// Performance endpointsexport async function getCacheStats() {return this.request('/performance/cache/stats');diff --git a/frontend/src/styles/main.scss b/frontend/src/styles/main.scssindex f2c30a1d..eb03c662 100644--- a/frontend/src/styles/main.scss+++ b/frontend/src/styles/main.scss@@ -132,7 +132,6 @@@import 'pages/_ssl';// WordPress styles moved into the serverkit-wordpress extension (plan 52// Phase 4) — its synced bundle imports them through its own module graph.-@import 'pages/_email';@import 'pages/_setup-wizard';@import 'pages/_migration-wizard';@import 'pages/_import-wizard';