@octarq/plugin-mail 0.0.0-stage → 0.1.1
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.
- package/LICENSE +21 -0
- package/api.ts +223 -0
- package/i18n.ts +699 -0
- package/index.ts +17 -0
- package/package.json +26 -3
- package/pages/AuthBadges.tsx +33 -0
- package/pages/Compose.tsx +291 -0
- package/pages/EmailListItem.tsx +85 -0
- package/pages/EmailListPane.tsx +152 -0
- package/pages/EmailView.tsx +283 -0
- package/pages/FolderNav.tsx +30 -0
- package/pages/MailGuide.tsx +36 -0
- package/pages/MailSettings.tsx +174 -0
- package/pages/MailTabs.tsx +26 -0
- package/pages/MailboxBar.tsx +59 -0
- package/pages/MailboxEditor.tsx +116 -0
- package/pages/SMTPSenders.tsx +323 -0
- package/pages/SuppressionList.tsx +148 -0
- package/pages/emptyState.test.tsx +58 -0
- package/pages/forms.test.tsx +694 -0
- package/pages/index.tsx +213 -0
- package/pages/mailEnhancements.test.tsx +254 -0
- package/pages/types.ts +10 -0
- package/tsconfig.json +15 -0
- package/widgets/MailSetupStepWidget.tsx +55 -0
- package/widgets/MailStatCardWidget.tsx +22 -0
- package/widgets/RecentMailPanelWidget.tsx +37 -0
- package/README.md +0 -3
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { Field, Input, PageCard, 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: "warning" | "info" | "danger" | "default"; label: string }> = {
|
|
20
|
+
bill: { tone: "warning", label: "Bill" },
|
|
21
|
+
otp: { tone: "info", label: "OTP" },
|
|
22
|
+
marketing: { tone: "default", label: "Marketing" },
|
|
23
|
+
important: { tone: "danger", 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
|
+
<PageCard className="mt-0 flex flex-col h-full max-h-full min-h-0 p-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-lg 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-lg 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-lg 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
|
+
/* ui-color-ok: HTML emails assume a light paper viewport */
|
|
174
|
+
<iframe srcDoc={email.html} className="h-full min-h-[400px] w-full rounded-lg border border-border bg-white" sandbox="" title={t("mail.iframeTitle")} />
|
|
175
|
+
) : (
|
|
176
|
+
<pre className="whitespace-pre-wrap break-words font-sans text-sm text-foreground leading-relaxed">{email.text}</pre>
|
|
177
|
+
)}
|
|
178
|
+
</div>
|
|
179
|
+
|
|
180
|
+
<div className="p-5 border-t border-border shrink-0 bg-well">
|
|
181
|
+
{realAttachments.length > 0 && (
|
|
182
|
+
<div className="mb-4 flex flex-wrap gap-2">
|
|
183
|
+
{realAttachments.map((a, i) => (
|
|
184
|
+
<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 })}>
|
|
185
|
+
<Paperclip className="h-3 w-3 text-accent-fg" />
|
|
186
|
+
{a.filename || t("mail.attachmentFallback")} <span className="font-mono tnum">({Math.max(1, Math.round(a.size / 1024))} KB)</span>
|
|
187
|
+
{a.truncated && (
|
|
188
|
+
<Badge tone="warning" className="font-mono text-[10px] uppercase tracking-wider ml-1">
|
|
189
|
+
{t("mail.truncated")}
|
|
190
|
+
</Badge>
|
|
191
|
+
)}
|
|
192
|
+
</span>
|
|
193
|
+
))}
|
|
194
|
+
</div>
|
|
195
|
+
)}
|
|
196
|
+
|
|
197
|
+
<div className="flex flex-col sm:flex-row items-end gap-3 pt-2">
|
|
198
|
+
<div className="sm:flex-1">
|
|
199
|
+
<Field label={t("mail.noteMemo")}>
|
|
200
|
+
<Input value={note} onChange={(e) => setNote(e.target.value)} placeholder={t("mail.notePlaceholder")} />
|
|
201
|
+
</Field>
|
|
202
|
+
</div>
|
|
203
|
+
<div className="flex flex-wrap gap-2 w-full sm:w-auto shrink-0 pb-1">
|
|
204
|
+
{aiEnabled && (
|
|
205
|
+
<Button variant="subtle" onClick={summarize} disabled={aiBusy} className="text-xs py-1.5 px-3 gap-1">
|
|
206
|
+
<Sparkles className="h-3.5 w-3.5" />
|
|
207
|
+
{aiBusy ? t("mail.aiSummarizing") : t("mail.aiSummarize")}
|
|
208
|
+
</Button>
|
|
209
|
+
)}
|
|
210
|
+
<Button
|
|
211
|
+
variant="subtle"
|
|
212
|
+
onClick={async () => {
|
|
213
|
+
await mailApi.updateEmail(email.id, { note });
|
|
214
|
+
onChanged();
|
|
215
|
+
toast.success(t("mail.noteSaved"));
|
|
216
|
+
}}
|
|
217
|
+
className="text-xs py-1.5 px-3"
|
|
218
|
+
>
|
|
219
|
+
{t("mail.saveNote")}
|
|
220
|
+
</Button>
|
|
221
|
+
{email.folder === "drafts" ? (
|
|
222
|
+
<Button
|
|
223
|
+
variant="primary"
|
|
224
|
+
onClick={() => (onEditDraft || onReply)({ id: email.id, to: email.to, subject: email.subject, text: email.text })}
|
|
225
|
+
className="text-xs py-1.5 px-3 gap-1"
|
|
226
|
+
>
|
|
227
|
+
<Edit3 className="h-3.5 w-3.5" />
|
|
228
|
+
{t("mail.editDraft")}
|
|
229
|
+
</Button>
|
|
230
|
+
) : (
|
|
231
|
+
<Button
|
|
232
|
+
variant="primary"
|
|
233
|
+
onClick={() =>
|
|
234
|
+
onReply({
|
|
235
|
+
to: email.from,
|
|
236
|
+
subject: email.subject.startsWith("Re:") ? email.subject : `Re: ${email.subject}`,
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
className="text-xs py-1.5 px-3 gap-1"
|
|
240
|
+
>
|
|
241
|
+
<Reply className="h-3.5 w-3.5" />
|
|
242
|
+
{t("mail.reply")}
|
|
243
|
+
</Button>
|
|
244
|
+
)}
|
|
245
|
+
{email.folder !== "trash" ? (
|
|
246
|
+
<Button variant="subtle" onClick={() => moveToFolder("trash")} title={t("mail.moveToTrash")} className="text-xs py-1.5 px-2">
|
|
247
|
+
<Trash2 className="h-3.5 w-3.5" />
|
|
248
|
+
</Button>
|
|
249
|
+
) : (
|
|
250
|
+
<Button variant="subtle" onClick={() => moveToFolder("inbox")} title={t("mail.moveToInbox")} className="text-xs py-1.5 px-2">
|
|
251
|
+
<ArchiveRestore className="h-3.5 w-3.5" />
|
|
252
|
+
</Button>
|
|
253
|
+
)}
|
|
254
|
+
{email.folder !== "spam" && email.folder !== "trash" && (
|
|
255
|
+
<Button variant="subtle" onClick={() => moveToFolder("spam")} title={t("mail.moveToSpam")} className="text-xs py-1.5 px-2">
|
|
256
|
+
<ShieldAlert className="h-3.5 w-3.5" />
|
|
257
|
+
</Button>
|
|
258
|
+
)}
|
|
259
|
+
<Button variant="ghost" onClick={() => window.open(mailApi.rawEmailUrl(email.id))} className="text-xs py-1.5 px-3 font-mono">
|
|
260
|
+
<Download className="h-3.5 w-3.5 mr-1" />
|
|
261
|
+
.eml
|
|
262
|
+
</Button>
|
|
263
|
+
{canDeleteEmail && (
|
|
264
|
+
<Button
|
|
265
|
+
variant="danger"
|
|
266
|
+
onClick={async () => {
|
|
267
|
+
if (await confirmDialog(t("mail.deleteEmailConfirm"))) {
|
|
268
|
+
await mailApi.deleteEmail(email.id);
|
|
269
|
+
onChanged();
|
|
270
|
+
onClose();
|
|
271
|
+
}
|
|
272
|
+
}}
|
|
273
|
+
className="text-xs py-1.5 px-3 border-0"
|
|
274
|
+
>
|
|
275
|
+
<Trash2 className="h-3.5 w-3.5" />
|
|
276
|
+
</Button>
|
|
277
|
+
)}
|
|
278
|
+
</div>
|
|
279
|
+
</div>
|
|
280
|
+
</div>
|
|
281
|
+
</PageCard>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
className="flex-wrap"
|
|
24
|
+
size="sm"
|
|
25
|
+
value={currentFolder}
|
|
26
|
+
onValueChange={(v) => onSelectFolder(v as MailFolder)}
|
|
27
|
+
items={folders}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -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,174 @@
|
|
|
1
|
+
import { Field, Input, Textarea, Switch, Button, PageSection, PageCard, PageRows, PageRow, Separator, Skeleton, 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) {
|
|
79
|
+
return (
|
|
80
|
+
<div role="status" aria-busy="true" aria-label={t("settings.loadingLower")}>
|
|
81
|
+
<PageSection className="mt-0" title={t("settings.inboundMailboxesSettings")}>
|
|
82
|
+
<PageCard className="space-y-5">
|
|
83
|
+
<div className="space-y-2">
|
|
84
|
+
<Skeleton className="h-3.5 w-36" />
|
|
85
|
+
<Skeleton className="h-16 w-full rounded-lg" />
|
|
86
|
+
</div>
|
|
87
|
+
<div className="space-y-2">
|
|
88
|
+
<Skeleton className="h-3.5 w-40" />
|
|
89
|
+
<Skeleton className="h-9 w-full rounded-lg" />
|
|
90
|
+
</div>
|
|
91
|
+
<div className="space-y-2">
|
|
92
|
+
<Skeleton className="h-3.5 w-32" />
|
|
93
|
+
<Skeleton className="h-9 w-full rounded-lg" />
|
|
94
|
+
</div>
|
|
95
|
+
</PageCard>
|
|
96
|
+
<PageRows>
|
|
97
|
+
<div data-slot="page-row" className="flex min-h-[var(--row-height,3.5rem)] items-center justify-between gap-4 px-4 py-3">
|
|
98
|
+
<div className="flex-1 space-y-1.5">
|
|
99
|
+
<Skeleton className="h-4 w-36" />
|
|
100
|
+
<Skeleton className="h-3 w-64" />
|
|
101
|
+
</div>
|
|
102
|
+
<Skeleton className="h-6 w-11 shrink-0 rounded-full" />
|
|
103
|
+
</div>
|
|
104
|
+
<Separator />
|
|
105
|
+
<div data-slot="page-row" className="flex min-h-[var(--row-height,3.5rem)] items-center justify-between gap-4 px-4 py-3">
|
|
106
|
+
<div className="flex-1 space-y-1.5">
|
|
107
|
+
<Skeleton className="h-4 w-40" />
|
|
108
|
+
<Skeleton className="h-3 w-56" />
|
|
109
|
+
</div>
|
|
110
|
+
<Skeleton className="h-6 w-11 shrink-0 rounded-full" />
|
|
111
|
+
</div>
|
|
112
|
+
</PageRows>
|
|
113
|
+
</PageSection>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const displayed = tokenLoaded && revealed ? inboundToken : MASK;
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<PageSection className="mt-0" title={t("settings.inboundMailboxesSettings")}>
|
|
122
|
+
<PageCard className="space-y-5">
|
|
123
|
+
<Field label={t("settings.reservedMailboxesLabel")} hint={t("settings.reservedMailboxesHint")}>
|
|
124
|
+
<Textarea className="font-mono text-xs" rows={2} value={reservedMailboxes} onChange={(e) => setReservedMailboxes(e.target.value)} placeholder="admin postmaster" />
|
|
125
|
+
</Field>
|
|
126
|
+
{adminView && (
|
|
127
|
+
<>
|
|
128
|
+
<Field label={t("settings.inboundWebhookUrlLabel")} hint={t("settings.inboundWebhookUrlHint")}>
|
|
129
|
+
<Input
|
|
130
|
+
readOnly
|
|
131
|
+
className="font-mono text-xs"
|
|
132
|
+
value={`${location.origin}/api/v1/webhook/${s?.orgSlug || ""}/email/inbound/${displayed}`}
|
|
133
|
+
onFocus={(e) => e.currentTarget.select()}
|
|
134
|
+
/>
|
|
135
|
+
</Field>
|
|
136
|
+
<Field label={t("settings.inboundTokenLabel")} hint={t("settings.inboundTokenHint")}>
|
|
137
|
+
<div className="flex gap-2">
|
|
138
|
+
<Input
|
|
139
|
+
className="font-mono text-xs"
|
|
140
|
+
value={displayed}
|
|
141
|
+
readOnly={!revealed || !tokenLoaded}
|
|
142
|
+
onChange={(e) => setInboundToken(e.target.value)}
|
|
143
|
+
placeholder={t("settings.inboundTokenPlaceholder")}
|
|
144
|
+
/>
|
|
145
|
+
<Button variant="outline" className="shrink-0 text-xs" onClick={reveal}>
|
|
146
|
+
{revealed ? t("settings.inboundTokenHide") : t("settings.inboundTokenReveal")}
|
|
147
|
+
</Button>
|
|
148
|
+
<Button variant="subtle" className="shrink-0 text-xs" onClick={copyToken}>
|
|
149
|
+
{copied ? t("uiCommon.copied") : t("settings.inboundTokenCopy")}
|
|
150
|
+
</Button>
|
|
151
|
+
</div>
|
|
152
|
+
</Field>
|
|
153
|
+
</>
|
|
154
|
+
)}
|
|
155
|
+
</PageCard>
|
|
156
|
+
<PageRows>
|
|
157
|
+
<PageRow
|
|
158
|
+
title={t("settings.enableCatchAll")}
|
|
159
|
+
description={t("settings.enableCatchAllDesc")}
|
|
160
|
+
control={<Switch checked={catchAll} onCheckedChange={setCatchAll} aria-label={t("settings.enableCatchAll")} />}
|
|
161
|
+
/>
|
|
162
|
+
<Separator />
|
|
163
|
+
<PageRow
|
|
164
|
+
title={t("settings.autoWrapLinks")}
|
|
165
|
+
description={t("settings.autoWrapLinksDesc")}
|
|
166
|
+
control={<Switch checked={autoWrap} onCheckedChange={setAutoWrap} aria-label={t("settings.autoWrapLinks")} />}
|
|
167
|
+
/>
|
|
168
|
+
</PageRows>
|
|
169
|
+
<div className="mt-4 flex justify-end">
|
|
170
|
+
<Button variant="primary" className="text-xs" onClick={save} disabled={busy}>{busy ? t("settings.saving") : t("settings.saveSettings")}</Button>
|
|
171
|
+
</div>
|
|
172
|
+
</PageSection>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
@@ -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 flex-wrap"
|
|
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,59 @@
|
|
|
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
|
+
className="flex-wrap"
|
|
45
|
+
size="sm"
|
|
46
|
+
value={active === undefined ? "all" : String(active)}
|
|
47
|
+
onValueChange={(v) => onSelect(v === "all" ? undefined : Number(v))}
|
|
48
|
+
items={items}
|
|
49
|
+
/>
|
|
50
|
+
</div>
|
|
51
|
+
{activeBox && (
|
|
52
|
+
<Button variant="ghost" size="sm" onClick={() => onEdit(activeBox)} title={t("mail.editMailbox")}>
|
|
53
|
+
<Settings className="h-3.5 w-3.5" />
|
|
54
|
+
<span>{t("mail.editMailbox")}</span>
|
|
55
|
+
</Button>
|
|
56
|
+
)}
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|