@octarq/plugin-mail 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,282 @@
1
+ import { Field, Input, GlassCard, Badge, Button, toast, confirmDialog, useTranslation, roleSatisfies, useCurrentRole } from "@octarq/plugin-sdk";
2
+ import { useEffect, useState } from "react";
3
+ import { mailApi, Attachment, Email } from "../api";
4
+ import { Paperclip, Trash2, Reply, Download, X, Sparkles, ExternalLink, ShieldAlert, ArchiveRestore, Edit3, Copy, KeyRound } from "lucide-react";
5
+ import { ReplyDraft } from "./types";
6
+ import { AuthBadges } from "./AuthBadges";
7
+
8
+ export { AuthBadges };
9
+
10
+ function parseAttachments(json: string): Attachment[] {
11
+ try {
12
+ const a = JSON.parse(json || "[]");
13
+ return Array.isArray(a) ? a : [];
14
+ } catch {
15
+ return [];
16
+ }
17
+ }
18
+
19
+ const CATEGORY_META: Record<string, { tone: "amber" | "cyan" | "red" | "neutral"; label: string }> = {
20
+ bill: { tone: "amber", label: "Bill" },
21
+ otp: { tone: "cyan", label: "OTP" },
22
+ marketing: { tone: "neutral", label: "Marketing" },
23
+ important: { tone: "red", label: "Important" },
24
+ };
25
+
26
+ function renderImportanceDots(n?: number) {
27
+ if (!n || n <= 0) return null;
28
+ const clamped = Math.max(1, Math.min(5, n));
29
+ return (
30
+ <span
31
+ className="text-xs tracking-wider text-warning-fg"
32
+ title={`Importance: ${clamped}/5`}
33
+ data-testid="email-view-importance"
34
+ >
35
+ {"●".repeat(clamped)}{"○".repeat(5 - clamped)}
36
+ </span>
37
+ );
38
+ }
39
+
40
+ export function EmailViewForm({
41
+ email,
42
+ onClose,
43
+ onReply,
44
+ onEditDraft,
45
+ onChanged,
46
+ }: {
47
+ email: Email;
48
+ onClose: () => void;
49
+ onReply: (draft: ReplyDraft) => void;
50
+ onEditDraft?: (draft: ReplyDraft) => void;
51
+ onChanged: () => void;
52
+ }) {
53
+ const [note, setNote] = useState(email.note ?? "");
54
+ const { t } = useTranslation();
55
+ const { role, isInstanceAdmin } = useCurrentRole();
56
+ const canDeleteEmail = roleSatisfies("admin", role, isInstanceAdmin);
57
+ const attachments = parseAttachments(email.attachments);
58
+ const realAttachments = attachments.filter((a) => !a.inline);
59
+ const [aiEnabled, setAiEnabled] = useState(false);
60
+ const [aiBusy, setAiBusy] = useState(false);
61
+ const [summary, setSummary] = useState("");
62
+
63
+ useEffect(() => {
64
+ mailApi.aiAssistStatus().then((s) => setAiEnabled(s.configured)).catch(() => {});
65
+ }, []);
66
+ useEffect(() => setSummary(""), [email.id]);
67
+
68
+ async function summarize() {
69
+ setAiBusy(true);
70
+ try {
71
+ const r = await mailApi.aiSummarizeEmail(email.id);
72
+ setSummary(r.summary);
73
+ } catch {
74
+ setSummary(t("mail.aiSummaryFailed"));
75
+ } finally {
76
+ setAiBusy(false);
77
+ }
78
+ }
79
+
80
+ async function moveToFolder(folder: string) {
81
+ try {
82
+ await mailApi.updateEmailFolder(email.id, folder);
83
+ toast.success(t("mail.movedToFolder", { folder }));
84
+ onChanged();
85
+ onClose();
86
+ } catch (e: any) {
87
+ toast.error(e.message || "Failed to move email");
88
+ }
89
+ }
90
+
91
+ return (
92
+ <GlassCard className="flex flex-col h-full max-h-full min-h-0">
93
+ <div className="p-5 border-b border-border flex justify-between items-start shrink-0 gap-4">
94
+ <div className="flex-1 min-w-0">
95
+ <h2 className="text-lg font-bold text-foreground mb-2 leading-snug">{email.subject || t("mail.noSubject")}</h2>
96
+ <div className="text-xs text-muted-foreground space-y-1.5">
97
+ <div><span className="text-muted-foreground">{t("mail.fromLabel")}</span> <span className="font-semibold text-foreground">{email.from}</span></div>
98
+ <div><span className="text-muted-foreground">{t("mail.toLabel")}</span> <span className="text-muted-foreground">{email.to}</span></div>
99
+ <div className="text-[11px] text-muted-foreground pt-0.5">{new Date(email.receivedAt).toLocaleString()}</div>
100
+ <div className="mt-2.5 flex flex-wrap items-center gap-2 pt-1">
101
+ <AuthBadges spf={email.authSpf} dkim={email.authDkim} dmarc={email.authDmarc} />
102
+ {email.category && CATEGORY_META[email.category] && (
103
+ <Badge tone={CATEGORY_META[email.category].tone} className="text-[10px] py-0 px-2 uppercase font-medium">
104
+ {t(`mail.cat_${email.category}`, CATEGORY_META[email.category].label)}
105
+ </Badge>
106
+ )}
107
+ {renderImportanceDots(email.importance)}
108
+ </div>
109
+ </div>
110
+ </div>
111
+ <Button variant="ghost" onClick={onClose} aria-label={t("common.close") || "Close"} className="p-2 shrink-0">
112
+ <X className="h-4 w-4" aria-hidden="true" />
113
+ </Button>
114
+ </div>
115
+
116
+ {(email.otp || (email.category === "otp" && email.subject.match(/\b([A-Z0-9]{4,8})\b/i)?.[1])) && (
117
+ <div
118
+ data-testid="otp-copy-bar"
119
+ className="mx-5 mt-3 flex items-center justify-between gap-3 px-4 py-2.5 bg-accent-soft border border-primary/20 rounded-xl text-xs shrink-0"
120
+ >
121
+ <div className="flex items-center gap-2.5">
122
+ <KeyRound className="h-4 w-4 text-accent-fg shrink-0" />
123
+ <span className="font-medium text-foreground">{t("mail.verificationCode", "Verification Code:")}</span>
124
+ <span className="font-mono text-sm font-bold text-accent-fg tracking-widest px-2.5 py-0.5 rounded bg-background border border-primary/30">
125
+ {email.otp || email.subject.match(/\b([A-Z0-9]{4,8})\b/i)?.[1]}
126
+ </span>
127
+ </div>
128
+ <Button
129
+ variant="primary"
130
+ size="sm"
131
+ className="text-xs py-1 px-3 gap-1.5 shrink-0"
132
+ onClick={() => {
133
+ const code = email.otp || email.subject.match(/\b([A-Z0-9]{4,8})\b/i)?.[1] || "";
134
+ navigator.clipboard.writeText(code);
135
+ toast.success(t("mail.otpCopied", "Verification code copied."));
136
+ }}
137
+ >
138
+ <Copy className="h-3.5 w-3.5" />
139
+ <span>{t("mail.copyCode", "Copy Code")}</span>
140
+ </Button>
141
+ </div>
142
+ )}
143
+
144
+ {email.unsubscribeUrl && (
145
+ <div className="mx-5 mt-3 flex items-center justify-between gap-3 px-3.5 py-2 bg-warning-bg border border-warning-border rounded-xl text-xs shrink-0">
146
+ <span className="text-warning-fg font-medium truncate">{t("mail.unsubscribe")}</span>
147
+ <Button
148
+ variant="outline"
149
+ className="text-xs py-1 px-2.5 gap-1 shrink-0 text-warning-fg border-warning-border hover:bg-warning-bg cursor-pointer"
150
+ onClick={() => {
151
+ window.open(email.unsubscribeUrl, "_blank", "noopener,noreferrer");
152
+ toast.success(t("mail.unsubscribeOpened"));
153
+ }}
154
+ >
155
+ <ExternalLink className="h-3 w-3" />
156
+ <span>{t("mail.unsubscribe")}</span>
157
+ </Button>
158
+ </div>
159
+ )}
160
+
161
+ {(summary || email.summary) && (
162
+ <div className="mx-5 mt-4 rounded-xl bg-info-bg border border-info-border p-3.5 shrink-0" data-testid="email-summary-box">
163
+ <div className="flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wider text-accent-fg mb-1.5">
164
+ <Sparkles className="h-3 w-3" />
165
+ {t("mail.aiSummaryTitle")}
166
+ </div>
167
+ <p className="text-sm text-foreground leading-relaxed whitespace-pre-wrap">{summary || email.summary}</p>
168
+ </div>
169
+ )}
170
+
171
+ <div className="flex-1 overflow-y-auto p-5 min-h-[400px] bg-well">
172
+ {email.html ? (
173
+ <iframe srcDoc={email.html} className="h-full min-h-[400px] w-full bg-white rounded-xl shadow-inner border-0" sandbox="" title={t("mail.iframeTitle")} />
174
+ ) : (
175
+ <pre className="whitespace-pre-wrap break-words font-sans text-sm text-foreground leading-relaxed">{email.text}</pre>
176
+ )}
177
+ </div>
178
+
179
+ <div className="p-5 border-t border-border shrink-0 bg-well">
180
+ {realAttachments.length > 0 && (
181
+ <div className="mb-4 flex flex-wrap gap-2">
182
+ {realAttachments.map((a, i) => (
183
+ <span key={i} className="inline-flex items-center gap-1.5 rounded-lg bg-well border border-border px-2.5 py-1 text-xs text-foreground" title={t("mail.attachmentTitle", { type: a.contentType, size: a.size })}>
184
+ <Paperclip className="h-3 w-3 text-accent-fg" />
185
+ {a.filename || t("mail.attachmentFallback")} <span className="font-mono tnum">({Math.max(1, Math.round(a.size / 1024))} KB)</span>
186
+ {a.truncated && (
187
+ <Badge tone="amber" className="font-mono text-[10px] uppercase tracking-wider ml-1">
188
+ {t("mail.truncated")}
189
+ </Badge>
190
+ )}
191
+ </span>
192
+ ))}
193
+ </div>
194
+ )}
195
+
196
+ <div className="flex flex-col sm:flex-row items-end gap-3 pt-2">
197
+ <div className="sm:flex-1">
198
+ <Field label={t("mail.noteMemo")}>
199
+ <Input value={note} onChange={(e) => setNote(e.target.value)} placeholder={t("mail.notePlaceholder")} />
200
+ </Field>
201
+ </div>
202
+ <div className="flex flex-wrap gap-2 w-full sm:w-auto shrink-0 pb-1">
203
+ {aiEnabled && (
204
+ <Button variant="subtle" onClick={summarize} disabled={aiBusy} className="text-xs py-1.5 px-3 gap-1">
205
+ <Sparkles className="h-3.5 w-3.5" />
206
+ {aiBusy ? t("mail.aiSummarizing") : t("mail.aiSummarize")}
207
+ </Button>
208
+ )}
209
+ <Button
210
+ variant="subtle"
211
+ onClick={async () => {
212
+ await mailApi.updateEmail(email.id, { note });
213
+ onChanged();
214
+ toast.success(t("mail.noteSaved"));
215
+ }}
216
+ className="text-xs py-1.5 px-3"
217
+ >
218
+ {t("mail.saveNote")}
219
+ </Button>
220
+ {email.folder === "drafts" ? (
221
+ <Button
222
+ variant="primary"
223
+ onClick={() => (onEditDraft || onReply)({ id: email.id, to: email.to, subject: email.subject, text: email.text })}
224
+ className="text-xs py-1.5 px-3 gap-1"
225
+ >
226
+ <Edit3 className="h-3.5 w-3.5" />
227
+ {t("mail.editDraft")}
228
+ </Button>
229
+ ) : (
230
+ <Button
231
+ variant="primary"
232
+ onClick={() =>
233
+ onReply({
234
+ to: email.from,
235
+ subject: email.subject.startsWith("Re:") ? email.subject : `Re: ${email.subject}`,
236
+ })
237
+ }
238
+ className="text-xs py-1.5 px-3 gap-1"
239
+ >
240
+ <Reply className="h-3.5 w-3.5" />
241
+ {t("mail.reply")}
242
+ </Button>
243
+ )}
244
+ {email.folder !== "trash" ? (
245
+ <Button variant="subtle" onClick={() => moveToFolder("trash")} title={t("mail.moveToTrash")} className="text-xs py-1.5 px-2">
246
+ <Trash2 className="h-3.5 w-3.5" />
247
+ </Button>
248
+ ) : (
249
+ <Button variant="subtle" onClick={() => moveToFolder("inbox")} title={t("mail.moveToInbox")} className="text-xs py-1.5 px-2">
250
+ <ArchiveRestore className="h-3.5 w-3.5" />
251
+ </Button>
252
+ )}
253
+ {email.folder !== "spam" && email.folder !== "trash" && (
254
+ <Button variant="subtle" onClick={() => moveToFolder("spam")} title={t("mail.moveToSpam")} className="text-xs py-1.5 px-2">
255
+ <ShieldAlert className="h-3.5 w-3.5" />
256
+ </Button>
257
+ )}
258
+ <Button variant="ghost" onClick={() => window.open(mailApi.rawEmailUrl(email.id))} className="text-xs py-1.5 px-3 font-mono">
259
+ <Download className="h-3.5 w-3.5 mr-1" />
260
+ .eml
261
+ </Button>
262
+ {canDeleteEmail && (
263
+ <Button
264
+ variant="danger"
265
+ onClick={async () => {
266
+ if (await confirmDialog(t("mail.deleteEmailConfirm"))) {
267
+ await mailApi.deleteEmail(email.id);
268
+ onChanged();
269
+ onClose();
270
+ }
271
+ }}
272
+ className="text-xs py-1.5 px-3 border-0"
273
+ >
274
+ <Trash2 className="h-3.5 w-3.5" />
275
+ </Button>
276
+ )}
277
+ </div>
278
+ </div>
279
+ </div>
280
+ </GlassCard>
281
+ );
282
+ }
@@ -0,0 +1,29 @@
1
+ import { Inbox, Send, FileText, Trash2, ShieldAlert } from "lucide-react";
2
+ import { TabBar, useTranslation } from "@octarq/plugin-sdk";
3
+ import { MailFolder } from "./types";
4
+
5
+ interface FolderNavProps {
6
+ currentFolder: MailFolder;
7
+ onSelectFolder: (folder: MailFolder) => void;
8
+ }
9
+
10
+ export function FolderNav({ currentFolder, onSelectFolder }: FolderNavProps) {
11
+ const { t } = useTranslation();
12
+
13
+ const folders = [
14
+ { value: "inbox", label: t("mail.folderInbox"), icon: <Inbox className="h-3.5 w-3.5" /> },
15
+ { value: "sent", label: t("mail.folderSent"), icon: <Send className="h-3.5 w-3.5" /> },
16
+ { value: "drafts", label: t("mail.folderDrafts"), icon: <FileText className="h-3.5 w-3.5" /> },
17
+ { value: "trash", label: t("mail.folderTrash"), icon: <Trash2 className="h-3.5 w-3.5" /> },
18
+ { value: "spam", label: t("mail.folderSpam"), icon: <ShieldAlert className="h-3.5 w-3.5" /> },
19
+ ];
20
+
21
+ return (
22
+ <TabBar
23
+ size="sm"
24
+ value={currentFolder}
25
+ onValueChange={(v) => onSelectFolder(v as MailFolder)}
26
+ items={folders}
27
+ />
28
+ );
29
+ }
@@ -0,0 +1,36 @@
1
+ import { Guide, useTranslation } from "@octarq/plugin-sdk";
2
+
3
+ export function MailGuide() {
4
+ const { t } = useTranslation();
5
+
6
+ return (
7
+ <Guide title={t("mail.guideTitle")} open>
8
+ <ol className="ml-4 list-decimal space-y-1.5 text-sm leading-relaxed text-muted-foreground">
9
+ <li>
10
+ {t("mail.guideStep1Pre")}
11
+ <b>{t("mail.guideStep1Domains")}</b>
12
+ {t("mail.guideStep1Mid")}
13
+ <b>{t("mail.guideStep1AcceptEmail")}</b>
14
+ {t("mail.guideStep1Post")}
15
+ </li>
16
+ <li>
17
+ {t("mail.guideStep2Pre")}
18
+ <b>{t("mail.guideStep2Routing")}</b>
19
+ {t("mail.guideStep2Post")}
20
+ </li>
21
+ <li>
22
+ {t("mail.guideStep3Pre")}
23
+ <code>deploy/cloudflare-email-worker.js</code>
24
+ {t("mail.guideStep3Mid1")}
25
+ <code>OCTARQ_ENDPOINT</code>
26
+ {t("mail.guideStep3Mid2")}
27
+ <b>{t("mail.guideStep3WebhookUrl")}</b>
28
+ {t("mail.guideStep3Mid3")}
29
+ <b>{t("mail.guideStep3SettingsMailboxes")}</b>
30
+ {t("mail.guideStep3Post")}
31
+ </li>
32
+ <li>{t("mail.guideStep4")}</li>
33
+ </ol>
34
+ </Guide>
35
+ );
36
+ }
@@ -0,0 +1,135 @@
1
+ import { Field, Input, Textarea, Switch, Button, Panel, toast, useTranslation } from "@octarq/plugin-sdk";
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import { mailApi, MailSettingsData } from "../api";
4
+
5
+ const MASK = "••••••••";
6
+
7
+ export function MailSettings() {
8
+ const { t } = useTranslation();
9
+ const [s, setS] = useState<MailSettingsData | null>(null);
10
+ const reload = useCallback(() => {
11
+ mailApi.settings().then(setS).catch(() => {});
12
+ }, []);
13
+ useEffect(() => { reload(); }, [reload]);
14
+
15
+ const [reservedMailboxes, setReservedMailboxes] = useState("");
16
+ const [inboundToken, setInboundToken] = useState("");
17
+ const [tokenLoaded, setTokenLoaded] = useState(false);
18
+ const [revealed, setRevealed] = useState(false);
19
+ const [copied, setCopied] = useState(false);
20
+ const [catchAll, setCatchAll] = useState(false);
21
+ const [autoWrap, setAutoWrap] = useState(false);
22
+ const [busy, setBusy] = useState(false);
23
+
24
+ const adminView = s?.inboundTokenSet !== undefined;
25
+
26
+ // The raw token is never part of the settings dump — it is fetched explicitly
27
+ // from the admin-only /api/settings/inbound-token endpoint and masked until
28
+ // the admin asks to see it.
29
+ const loadToken = useCallback(async () => {
30
+ if (tokenLoaded) return;
31
+ try {
32
+ const r = await mailApi.inboundToken();
33
+ setInboundToken(r.inboundToken);
34
+ setTokenLoaded(true);
35
+ } catch {
36
+ // First-run org or a transient failure — keep the mask.
37
+ }
38
+ }, [tokenLoaded]);
39
+
40
+ useEffect(() => { if (s) { setReservedMailboxes(s.reservedMailboxes || ""); setCatchAll(s.catchAll || false); setAutoWrap(s.autoWrapLinks || false); } }, [s]);
41
+
42
+ useEffect(() => { if (adminView) void loadToken(); }, [adminView, loadToken]);
43
+
44
+ async function save() {
45
+ setBusy(true);
46
+ try {
47
+ await mailApi.updateSettings({
48
+ reservedMailboxes,
49
+ ...(tokenLoaded ? { inboundToken } : {}),
50
+ catchAll,
51
+ autoWrapLinks: autoWrap,
52
+ });
53
+ toast.success(t("settings.saved"));
54
+ if (tokenLoaded) {
55
+ // A save may have rotated the token (clearing it mints a fresh one);
56
+ // refresh so the displayed value and URL stay accurate.
57
+ const r = await mailApi.inboundToken();
58
+ setInboundToken(r.inboundToken);
59
+ }
60
+ } catch (e: any) {
61
+ toast.error(e?.message || t("settings.saveFailed", "Failed to save settings"));
62
+ } finally { setBusy(false); }
63
+ }
64
+
65
+ async function reveal() {
66
+ await loadToken();
67
+ setRevealed((v) => !v);
68
+ }
69
+
70
+ async function copyToken() {
71
+ if (!tokenLoaded) await loadToken();
72
+ if (!inboundToken) return;
73
+ await navigator.clipboard.writeText(inboundToken);
74
+ setCopied(true);
75
+ setTimeout(() => setCopied(false), 1500);
76
+ }
77
+
78
+ if (!s) return <div className="text-sm text-muted-foreground">{t("settings.loadingLower")}</div>;
79
+
80
+ const displayed = tokenLoaded && revealed ? inboundToken : MASK;
81
+
82
+ return (
83
+ <Panel title={t("settings.inboundMailboxesSettings")} className="space-y-6">
84
+ <Field label={t("settings.reservedMailboxesLabel")} hint={t("settings.reservedMailboxesHint")}>
85
+ <Textarea className="font-mono text-xs" rows={2} value={reservedMailboxes} onChange={(e) => setReservedMailboxes(e.target.value)} placeholder="admin&#10;postmaster" />
86
+ </Field>
87
+ {adminView && (
88
+ <>
89
+ <Field label={t("settings.inboundWebhookUrlLabel")} hint={t("settings.inboundWebhookUrlHint")}>
90
+ <Input
91
+ readOnly
92
+ className="font-mono text-xs"
93
+ value={`${location.origin}/api/v1/webhook/${s?.orgSlug || ""}/email/inbound/${displayed}`}
94
+ onFocus={(e) => e.currentTarget.select()}
95
+ />
96
+ </Field>
97
+ <Field label={t("settings.inboundTokenLabel")} hint={t("settings.inboundTokenHint")}>
98
+ <div className="flex gap-2">
99
+ <Input
100
+ className="font-mono text-xs"
101
+ value={displayed}
102
+ readOnly={!revealed || !tokenLoaded}
103
+ onChange={(e) => setInboundToken(e.target.value)}
104
+ placeholder={t("settings.inboundTokenPlaceholder")}
105
+ />
106
+ <Button variant="outline" className="shrink-0 text-xs" onClick={reveal}>
107
+ {revealed ? t("settings.inboundTokenHide") : t("settings.inboundTokenReveal")}
108
+ </Button>
109
+ <Button variant="subtle" className="shrink-0 text-xs" onClick={copyToken}>
110
+ {copied ? t("uiCommon.copied") : t("settings.inboundTokenCopy")}
111
+ </Button>
112
+ </div>
113
+ </Field>
114
+ </>
115
+ )}
116
+ <div className="flex items-center gap-3 border-t border-border pt-4">
117
+ <Switch checked={catchAll} onCheckedChange={setCatchAll} aria-label={t("settings.enableCatchAll")} />
118
+ <div>
119
+ <span className="block select-none text-xs font-semibold text-muted-foreground">{t("settings.enableCatchAll")}</span>
120
+ <span className="select-none text-[10px] text-muted-foreground">{t("settings.enableCatchAllDesc")}</span>
121
+ </div>
122
+ </div>
123
+ <div className="flex items-center gap-3 border-t border-border pt-4">
124
+ <Switch checked={autoWrap} onCheckedChange={setAutoWrap} aria-label={t("settings.autoWrapLinks")} />
125
+ <div>
126
+ <span className="block select-none text-xs font-semibold text-muted-foreground">{t("settings.autoWrapLinks")}</span>
127
+ <span className="select-none text-[10px] text-muted-foreground">{t("settings.autoWrapLinksDesc")}</span>
128
+ </div>
129
+ </div>
130
+ <div className="border-t border-border pt-4 flex justify-end">
131
+ <Button variant="primary" className="text-xs" onClick={save} disabled={busy}>{busy ? t("settings.saving") : t("settings.saveSettings")}</Button>
132
+ </div>
133
+ </Panel>
134
+ );
135
+ }
@@ -0,0 +1,26 @@
1
+ import { TabBar, useTranslation } from "@octarq/plugin-sdk";
2
+
3
+ export type MailTab = "mail" | "inbound" | "smtp" | "suppressions";
4
+
5
+ interface MailTabsProps {
6
+ tab: MailTab;
7
+ onTabChange: (tab: MailTab) => void;
8
+ }
9
+
10
+ export function MailTabs({ tab, onTabChange }: MailTabsProps) {
11
+ const { t } = useTranslation();
12
+
13
+ return (
14
+ <TabBar
15
+ className="mb-6"
16
+ value={tab}
17
+ onValueChange={(v) => onTabChange(v as MailTab)}
18
+ items={[
19
+ { value: "mail", label: t("mail.tabMail") },
20
+ { value: "inbound", label: t("mail.tabInbound") },
21
+ { value: "smtp", label: t("mail.tabSmtp") },
22
+ { value: "suppressions", label: t("mail.tabSuppressions") },
23
+ ]}
24
+ />
25
+ );
26
+ }
@@ -0,0 +1,58 @@
1
+ import { Button, TabBar, useTranslation } from "@octarq/plugin-sdk";
2
+ import { Inbox, Settings } from "lucide-react";
3
+ import { Mailbox } from "../api";
4
+
5
+ interface MailboxBarProps {
6
+ boxes: Mailbox[];
7
+ active?: number;
8
+ totalUnread: number;
9
+ activeBox?: Mailbox;
10
+ onSelect: (id?: number) => void;
11
+ onEdit: (box: Mailbox) => void;
12
+ }
13
+
14
+ export function MailboxBar({
15
+ boxes,
16
+ active,
17
+ totalUnread,
18
+ activeBox,
19
+ onSelect,
20
+ onEdit,
21
+ }: MailboxBarProps) {
22
+ const { t } = useTranslation();
23
+
24
+ if (boxes.length === 0) return null;
25
+
26
+ const items = [
27
+ {
28
+ value: "all",
29
+ label: t("mail.allMailboxes"),
30
+ icon: <Inbox className="h-3.5 w-3.5" />,
31
+ count: totalUnread > 0 ? totalUnread : undefined,
32
+ },
33
+ ...boxes.map((b) => ({
34
+ value: String(b.id),
35
+ label: <span className="font-mono">{b.address}</span>,
36
+ count: b.unread > 0 ? b.unread : undefined,
37
+ })),
38
+ ];
39
+
40
+ return (
41
+ <div className="flex flex-wrap items-center justify-between gap-3">
42
+ <div className="min-w-0 flex-1">
43
+ <TabBar
44
+ size="sm"
45
+ value={active === undefined ? "all" : String(active)}
46
+ onValueChange={(v) => onSelect(v === "all" ? undefined : Number(v))}
47
+ items={items}
48
+ />
49
+ </div>
50
+ {activeBox && (
51
+ <Button variant="ghost" size="sm" onClick={() => onEdit(activeBox)} title={t("mail.editMailbox")}>
52
+ <Settings className="h-3.5 w-3.5" />
53
+ <span>{t("mail.editMailbox")}</span>
54
+ </Button>
55
+ )}
56
+ </div>
57
+ );
58
+ }