@octarq/plugin-mail 0.1.0 → 0.1.2
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/api.ts +18 -105
- package/i18n.ts +0 -1
- package/package.json +3 -3
- package/pages/AuthBadges.tsx +4 -4
- package/pages/Compose.tsx +16 -18
- package/pages/EmailListItem.tsx +5 -5
- package/pages/EmailListPane.tsx +35 -6
- package/pages/EmailView.tsx +16 -15
- package/pages/MailSettings.tsx +87 -54
- package/pages/MailboxEditor.tsx +1 -1
- package/pages/SMTPSenders.tsx +112 -75
- package/pages/SuppressionList.tsx +4 -2
- package/pages/emptyState.test.tsx +0 -3
- package/pages/forms.test.tsx +67 -36
- package/pages/index.tsx +23 -24
- package/pages/mailEnhancements.test.tsx +51 -4
- package/pages/mailSettings.test.tsx +105 -0
- package/widgets/MailSetupStepWidget.tsx +3 -5
package/api.ts
CHANGED
|
@@ -1,87 +1,6 @@
|
|
|
1
|
-
// Mail feature API surface — the slice of the JSON API owned by the mail plugin.
|
|
2
|
-
// Fully self-contained without relative host leaks.
|
|
3
1
|
|
|
4
|
-
|
|
5
|
-
status: number;
|
|
6
|
-
body?: any;
|
|
7
|
-
requestId?: string;
|
|
8
|
-
constructor(status: number, message: string, body?: any, requestId?: string) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.status = status;
|
|
11
|
-
this.body = body;
|
|
12
|
-
this.requestId = requestId;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getAppLang(): string {
|
|
17
|
-
try {
|
|
18
|
-
const saved = localStorage.getItem("lang");
|
|
19
|
-
if (saved) return saved;
|
|
20
|
-
} catch {
|
|
21
|
-
/* ignore */
|
|
22
|
-
}
|
|
23
|
-
return typeof navigator !== "undefined" ? navigator.language || "en" : "en";
|
|
24
|
-
}
|
|
2
|
+
import { req } from "@octarq/plugin-sdk";
|
|
25
3
|
|
|
26
|
-
interface ErrorEnvelope {
|
|
27
|
-
message?: string;
|
|
28
|
-
error?: string;
|
|
29
|
-
detail?: string;
|
|
30
|
-
details?: Array<string | { location?: string; message?: string }>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function req<T>(method: string, path: string, body?: unknown, lang?: string): Promise<T> {
|
|
34
|
-
const currentLang = lang || getAppLang();
|
|
35
|
-
const headers: Record<string, string> = {
|
|
36
|
-
"Accept-Language": currentLang,
|
|
37
|
-
};
|
|
38
|
-
if (body) {
|
|
39
|
-
headers["Content-Type"] = "application/json";
|
|
40
|
-
}
|
|
41
|
-
const res = await fetch(path, {
|
|
42
|
-
method,
|
|
43
|
-
headers,
|
|
44
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
45
|
-
});
|
|
46
|
-
if (!res.ok) {
|
|
47
|
-
let msg = res.statusText;
|
|
48
|
-
let parsed: ErrorEnvelope | null = null;
|
|
49
|
-
try {
|
|
50
|
-
parsed = (await res.json()) as ErrorEnvelope;
|
|
51
|
-
if (parsed?.message) {
|
|
52
|
-
msg = parsed.message;
|
|
53
|
-
if (parsed.details && Array.isArray(parsed.details) && parsed.details.length > 0) {
|
|
54
|
-
const detailMsgs = parsed.details
|
|
55
|
-
.map((d) => {
|
|
56
|
-
if (typeof d === "string") return d;
|
|
57
|
-
if (d?.message) {
|
|
58
|
-
const loc = d.location ? `${d.location.replace(/^body\./, "")}: ` : "";
|
|
59
|
-
return `${loc}${d.message}`;
|
|
60
|
-
}
|
|
61
|
-
return "";
|
|
62
|
-
})
|
|
63
|
-
.filter(Boolean)
|
|
64
|
-
.join("; ");
|
|
65
|
-
if (detailMsgs) msg = `${msg} (${detailMsgs})`;
|
|
66
|
-
}
|
|
67
|
-
} else if (parsed?.error) {
|
|
68
|
-
msg = parsed.error;
|
|
69
|
-
} else if (parsed?.detail) {
|
|
70
|
-
msg = parsed.detail;
|
|
71
|
-
}
|
|
72
|
-
} catch {
|
|
73
|
-
// Non-JSON error body: fall through to statusText.
|
|
74
|
-
}
|
|
75
|
-
const requestId = res.headers.get("x-request-id") || undefined;
|
|
76
|
-
throw new ApiError(res.status, msg || `HTTP ${res.status}`, parsed, requestId);
|
|
77
|
-
}
|
|
78
|
-
if (res.status === 204) return undefined as unknown as T;
|
|
79
|
-
const contentType = res.headers.get("content-type");
|
|
80
|
-
if (contentType && contentType.includes("application/json")) {
|
|
81
|
-
return (await res.json()) as T;
|
|
82
|
-
}
|
|
83
|
-
return (await res.text()) as unknown as T;
|
|
84
|
-
}
|
|
85
4
|
|
|
86
5
|
export interface HostEntry {
|
|
87
6
|
host: string;
|
|
@@ -170,10 +89,10 @@ export interface Email {
|
|
|
170
89
|
unsubscribeUrl?: string;
|
|
171
90
|
read: boolean;
|
|
172
91
|
note: string;
|
|
173
|
-
attachments: string;
|
|
174
|
-
authSpf: string;
|
|
175
|
-
authDkim: string;
|
|
176
|
-
authDmarc: string;
|
|
92
|
+
attachments: string;
|
|
93
|
+
authSpf: string;
|
|
94
|
+
authDkim: string;
|
|
95
|
+
authDmarc: string;
|
|
177
96
|
receivedAt: string;
|
|
178
97
|
category?: "bill" | "otp" | "marketing" | "important" | "general" | string;
|
|
179
98
|
summary?: string;
|
|
@@ -201,14 +120,20 @@ export interface MailSuppression {
|
|
|
201
120
|
updatedAt: string;
|
|
202
121
|
}
|
|
203
122
|
|
|
123
|
+
export const mailAiStatus = () => req<{ configured: boolean; provider: string }>("GET", "/api/mail/ai/status");
|
|
124
|
+
|
|
125
|
+
export const summarizeEmail = (id: number) =>
|
|
126
|
+
req<{ summary: string; category?: string; importance?: number; otp?: string }>(
|
|
127
|
+
"POST",
|
|
128
|
+
`/api/mail/assist/summarize-email/${id}`,
|
|
129
|
+
);
|
|
130
|
+
|
|
204
131
|
export const mailApi = {
|
|
205
|
-
// Mailbox CRUD
|
|
206
132
|
mailboxes: () => req<Mailbox[]>("GET", "/api/mailboxes"),
|
|
207
133
|
createMailbox: (m: Partial<Mailbox>) => req<Mailbox>("POST", "/api/mailboxes", m),
|
|
208
134
|
updateMailbox: (id: number, m: Partial<Mailbox>) => req<Mailbox>("PUT", `/api/mailboxes/${id}`, m),
|
|
209
135
|
deleteMailbox: (id: number) => req("DELETE", `/api/mailboxes/${id}`),
|
|
210
136
|
|
|
211
|
-
// Email read & mutation
|
|
212
137
|
emails: (mailboxId?: number, params?: { q?: string; folder?: string; limit?: number; offset?: number }) => {
|
|
213
138
|
const sp = new URLSearchParams();
|
|
214
139
|
if (mailboxId) sp.set("mailbox", mailboxId.toString());
|
|
@@ -242,7 +167,6 @@ export const mailApi = {
|
|
|
242
167
|
trackLinks?: boolean;
|
|
243
168
|
}) => req("POST", "/api/emails/send", m),
|
|
244
169
|
|
|
245
|
-
// Contacts
|
|
246
170
|
contacts: (params?: { query?: string; q?: string; limit?: number; offset?: number }) => {
|
|
247
171
|
const sp = new URLSearchParams();
|
|
248
172
|
const q = params?.query ?? params?.q;
|
|
@@ -253,17 +177,14 @@ export const mailApi = {
|
|
|
253
177
|
return req<MailContact[]>("GET", `/api/mail/contacts${qs ? "?" + qs : ""}`);
|
|
254
178
|
},
|
|
255
179
|
|
|
256
|
-
// Drafts
|
|
257
180
|
saveDraft: (d: { id?: number; mailboxId?: number; to: string; subject: string; text: string; html?: string }) =>
|
|
258
181
|
req<Email>("POST", "/api/mail/drafts", d),
|
|
259
182
|
deleteDraft: (id: number) => req<{ ok: boolean }>("DELETE", `/api/mail/drafts/${id}`),
|
|
260
183
|
|
|
261
|
-
// Suppressions
|
|
262
184
|
suppressions: () => req<MailSuppression[]>("GET", "/api/mail/suppressions"),
|
|
263
185
|
createSuppression: (address: string) => req<MailSuppression>("POST", "/api/mail/suppressions", { address }),
|
|
264
186
|
deleteSuppression: (id: number) => req("DELETE", `/api/mail/suppressions/${id}`),
|
|
265
187
|
|
|
266
|
-
// Domains (used for mailbox creation host selection)
|
|
267
188
|
domains: (params?: { q?: string; limit?: number; offset?: number }) => {
|
|
268
189
|
const sp = new URLSearchParams();
|
|
269
190
|
if (params?.q) sp.set("q", params.q);
|
|
@@ -273,7 +194,6 @@ export const mailApi = {
|
|
|
273
194
|
return req<Domain[]>("GET", `/api/domains${qs ? "?" + qs : ""}`);
|
|
274
195
|
},
|
|
275
196
|
|
|
276
|
-
// SMTP Senders
|
|
277
197
|
smtpSenders: () => req<SMTPSender[]>("GET", "/api/smtp-senders"),
|
|
278
198
|
createSMTPSender: (s: SMTPSenderInput) => req<SMTPSender>("POST", "/api/smtp-senders", s),
|
|
279
199
|
updateSMTPSender: (id: number, s: Partial<SMTPSenderInput>) =>
|
|
@@ -281,22 +201,15 @@ export const mailApi = {
|
|
|
281
201
|
deleteSMTPSender: (id: number) => req<void>("DELETE", `/api/smtp-senders/${id}`),
|
|
282
202
|
testSMTPSender: (id: number) => req<{ ok: boolean }>("POST", `/api/smtp-senders/${id}/test`),
|
|
283
203
|
|
|
284
|
-
|
|
285
|
-
settings: () => req<MailSettingsData>("GET", "/api/settings"),
|
|
204
|
+
settings: () => req<MailSettingsData>("GET", "/api/mail/settings"),
|
|
286
205
|
updateSettings: (s: Partial<MailSettingsData> & { inboundToken?: string }) =>
|
|
287
|
-
req<any>("PUT", "/api/settings", s),
|
|
206
|
+
req<any>("PUT", "/api/mail/settings", s),
|
|
288
207
|
inboundToken: () => req<{ inboundToken: string }>("GET", "/api/settings/inbound-token"),
|
|
289
208
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
aiSummarizeEmail: (id: number) =>
|
|
293
|
-
req<{ summary: string; category?: string; importance?: number; otp?: string }>(
|
|
294
|
-
"POST",
|
|
295
|
-
`/api/ai/assist/summarize-email/${id}`,
|
|
296
|
-
),
|
|
209
|
+
mailAiStatus,
|
|
210
|
+
summarizeEmail,
|
|
297
211
|
|
|
298
|
-
|
|
299
|
-
overview: (includeBot = false) => req<any>("GET", `/api/overview?include_bot=${includeBot}`),
|
|
212
|
+
overview: () => req<any>("GET", "/api/overview"),
|
|
300
213
|
};
|
|
301
214
|
|
|
302
215
|
export { mailApi as api };
|
package/i18n.ts
CHANGED
|
@@ -34,7 +34,6 @@ export const mailI18n = {
|
|
|
34
34
|
guideStep4: "To send replies, configure an SMTP relay via Settings.",
|
|
35
35
|
allMailboxes: "All mailboxes",
|
|
36
36
|
searchPlaceholder: "Search emails…",
|
|
37
|
-
// Empty inbox states: the address / query render beside these in mono.
|
|
38
37
|
emptyFilteredReason: "No messages match",
|
|
39
38
|
clearSearch: "Clear search",
|
|
40
39
|
emptyNoBoxesReason: "No mailbox configured yet.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octarq/plugin-mail",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Mailboxes, SMTP relay, and inbound webhook processing plugin for Octarq",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
".": "./index.ts"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@octarq/plugin-sdk": "^0.
|
|
12
|
+
"@octarq/plugin-sdk": "^0.25.0",
|
|
13
13
|
"react": "^18.3.1",
|
|
14
14
|
"react-dom": "^18.3.1",
|
|
15
15
|
"react-router-dom": "^6.28.0 || ^7.0.0"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"lucide-react": "^1.21.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@octarq/plugin-sdk": "^0.
|
|
21
|
+
"@octarq/plugin-sdk": "^0.25.0",
|
|
22
22
|
"@types/react": "^18.3.1",
|
|
23
23
|
"@types/react-dom": "^18.3.1",
|
|
24
24
|
"react": "^18.3.1",
|
package/pages/AuthBadges.tsx
CHANGED
|
@@ -15,11 +15,11 @@ export function AuthBadges({
|
|
|
15
15
|
if (!result || result === "none" || result === "") return null;
|
|
16
16
|
const pass = result === "pass";
|
|
17
17
|
const warn = result === "softfail" || result === "neutral";
|
|
18
|
-
if (compact && pass) return null;
|
|
18
|
+
if (compact && pass) return null;
|
|
19
19
|
|
|
20
|
-
let tone: "
|
|
21
|
-
if (pass) tone = "
|
|
22
|
-
else if (warn) tone = "
|
|
20
|
+
let tone: "success" | "warning" | "danger" = "danger";
|
|
21
|
+
if (pass) tone = "success";
|
|
22
|
+
else if (warn) tone = "warning";
|
|
23
23
|
|
|
24
24
|
return (
|
|
25
25
|
<Badge key={label} tone={tone} className="font-mono text-[10px] uppercase tracking-wider">
|
package/pages/Compose.tsx
CHANGED
|
@@ -20,8 +20,6 @@ export function Compose({
|
|
|
20
20
|
const [subject, setSubject] = useState(draft?.subject ?? "");
|
|
21
21
|
const [text, setText] = useState(draft?.text ?? "");
|
|
22
22
|
const [smtpSenderId, setSmtpSenderId] = useState<number>(0);
|
|
23
|
-
// Which registry owns smtpSenderId. The two registries number their rows
|
|
24
|
-
// independently, so the ID alone cannot identify a sender.
|
|
25
23
|
const [senderSource, setSenderSource] = useState<"local" | "integration" | null>(null);
|
|
26
24
|
const [senders, setSenders] = useState<any[]>([]);
|
|
27
25
|
const [loadingSenders, setLoadingSenders] = useState(true);
|
|
@@ -30,7 +28,6 @@ export function Compose({
|
|
|
30
28
|
const [autoWrapLinksEnabled, setAutoWrapLinksEnabled] = useState(false);
|
|
31
29
|
const [trackLinks, setTrackLinks] = useState(false);
|
|
32
30
|
|
|
33
|
-
// Contacts autocomplete
|
|
34
31
|
const [contacts, setContacts] = useState<MailContact[]>([]);
|
|
35
32
|
const [showSuggestions, setShowSuggestions] = useState(false);
|
|
36
33
|
const toContainerRef = useRef<HTMLDivElement>(null);
|
|
@@ -48,12 +45,10 @@ export function Compose({
|
|
|
48
45
|
setLoadingSenders(true);
|
|
49
46
|
(async () => {
|
|
50
47
|
try {
|
|
51
|
-
const res = await fetch("/api/
|
|
48
|
+
const res = await fetch("/api/vault/items?provider_type=communication", {
|
|
52
49
|
credentials: "same-origin",
|
|
53
50
|
});
|
|
54
51
|
if (res.status === 404) {
|
|
55
|
-
// No Integrations Hub on this instance: the local SMTP sender
|
|
56
|
-
// registry is the only source, so offer it instead of an empty list.
|
|
57
52
|
const list = await mailApi.smtpSenders();
|
|
58
53
|
if (cancelled) return;
|
|
59
54
|
setSenderSource("local");
|
|
@@ -63,7 +58,8 @@ export function Compose({
|
|
|
63
58
|
}
|
|
64
59
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
65
60
|
const data = await res.json();
|
|
66
|
-
const
|
|
61
|
+
const raw = Array.isArray(data) ? data : (data?.body ?? []);
|
|
62
|
+
const commSenders = (Array.isArray(raw) ? raw : []).filter(
|
|
67
63
|
(item: any) => item.provider === "smtp" || item.provider === "resend"
|
|
68
64
|
);
|
|
69
65
|
if (cancelled) return;
|
|
@@ -73,8 +69,6 @@ export function Compose({
|
|
|
73
69
|
setSmtpSenderId(preferred ? preferred.id : 0);
|
|
74
70
|
} catch {
|
|
75
71
|
if (cancelled) return;
|
|
76
|
-
// Do not guess at a sender when the lookup fails: sending through the
|
|
77
|
-
// wrong registry is worse than asking the user to retry.
|
|
78
72
|
setSenderSource(null);
|
|
79
73
|
setSenders([]);
|
|
80
74
|
setSmtpSenderId(0);
|
|
@@ -192,14 +186,18 @@ export function Compose({
|
|
|
192
186
|
className="text-sm"
|
|
193
187
|
value={String(smtpSenderId)}
|
|
194
188
|
onValueChange={(v) => setSmtpSenderId(Number(v))}
|
|
195
|
-
options={senders.map((s) =>
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
189
|
+
options={senders.map((s) => {
|
|
190
|
+
const detail =
|
|
191
|
+
s.metadata?.fromEmail ||
|
|
192
|
+
s.fromEmail ||
|
|
193
|
+
s.summary ||
|
|
194
|
+
s.metadata?.smtpHost ||
|
|
195
|
+
s.provider;
|
|
196
|
+
return {
|
|
197
|
+
value: String(s.id),
|
|
198
|
+
label: detail ? `${s.name} (${detail})` : s.name,
|
|
199
|
+
};
|
|
200
|
+
})}
|
|
203
201
|
/>
|
|
204
202
|
</Field>
|
|
205
203
|
)}
|
|
@@ -224,7 +222,7 @@ export function Compose({
|
|
|
224
222
|
/>
|
|
225
223
|
</Field>
|
|
226
224
|
{showSuggestions && contacts.length > 0 && (
|
|
227
|
-
<div className="absolute left-0 right-0 top-full mt-1 z-30 bg-card border border-border rounded-
|
|
225
|
+
<div className="absolute left-0 right-0 top-full mt-1 z-30 bg-card border border-border rounded-lg shadow-lg overflow-hidden divide-y divide-border">
|
|
228
226
|
{contacts.map((c) => (
|
|
229
227
|
<button
|
|
230
228
|
key={c.id}
|
package/pages/EmailListItem.tsx
CHANGED
|
@@ -10,11 +10,11 @@ interface EmailListItemProps {
|
|
|
10
10
|
onSelect: () => void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const CATEGORY_META: Record<string, { tone: "
|
|
14
|
-
bill: { tone: "
|
|
15
|
-
otp: { tone: "
|
|
16
|
-
marketing: { tone: "
|
|
17
|
-
important: { tone: "
|
|
13
|
+
const CATEGORY_META: Record<string, { tone: "warning" | "info" | "danger" | "default"; label: string }> = {
|
|
14
|
+
bill: { tone: "warning", label: "Bill" },
|
|
15
|
+
otp: { tone: "info", label: "OTP" },
|
|
16
|
+
marketing: { tone: "default", label: "Marketing" },
|
|
17
|
+
important: { tone: "danger", label: "Important" },
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
function renderImportanceDots(n?: number) {
|
package/pages/EmailListPane.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PageCard, Empty, Button, Input, Skeleton, useTranslation } from "@octarq/plugin-sdk";
|
|
2
2
|
import { Search, X, Mail as MailIcon, Inbox } from "lucide-react";
|
|
3
3
|
import { Email, Mailbox } from "../api";
|
|
4
4
|
import { MailFolder } from "./types";
|
|
@@ -56,15 +56,31 @@ export function EmailListPane({
|
|
|
56
56
|
)}
|
|
57
57
|
</div>
|
|
58
58
|
|
|
59
|
-
<
|
|
59
|
+
<PageCard className="mt-0 flex-1 overflow-hidden p-0">
|
|
60
60
|
{emails.length === 0 && loading ? (
|
|
61
|
-
<
|
|
61
|
+
<div
|
|
62
|
+
role="status"
|
|
63
|
+
aria-busy="true"
|
|
64
|
+
aria-label={t("mail.loading")}
|
|
65
|
+
className="divide-y divide-border"
|
|
66
|
+
>
|
|
67
|
+
{Array.from({ length: 7 }).map((_, i) => (
|
|
68
|
+
<div key={i} className="flex flex-col gap-1.5 p-3.5">
|
|
69
|
+
<div className="flex items-center justify-between gap-2">
|
|
70
|
+
<Skeleton className="h-3.5 w-36" />
|
|
71
|
+
<Skeleton className="h-3 w-12" />
|
|
72
|
+
</div>
|
|
73
|
+
<Skeleton className="h-3.5 w-4/5" />
|
|
74
|
+
<Skeleton className="h-3 w-3/5" />
|
|
75
|
+
</div>
|
|
76
|
+
))}
|
|
77
|
+
</div>
|
|
62
78
|
) : (
|
|
63
79
|
<div className="max-h-[650px] divide-y divide-border overflow-y-auto" onScroll={onScroll}>
|
|
64
80
|
{emails.length === 0 ? (
|
|
65
81
|
q ? (
|
|
66
82
|
<div className="flex flex-col items-center gap-2.5 px-6 py-10 text-center">
|
|
67
|
-
<div className="flex h-10 w-10 items-center justify-center rounded-
|
|
83
|
+
<div className="flex h-10 w-10 items-center justify-center rounded-lg bg-muted text-muted-foreground">
|
|
68
84
|
<Search className="h-4 w-4" />
|
|
69
85
|
</div>
|
|
70
86
|
<p className="text-[13px] text-muted-foreground">
|
|
@@ -112,12 +128,25 @@ export function EmailListPane({
|
|
|
112
128
|
onSelect={() => onOpenEmail(e)}
|
|
113
129
|
/>
|
|
114
130
|
))}
|
|
115
|
-
{loading &&
|
|
131
|
+
{loading && (
|
|
132
|
+
<div
|
|
133
|
+
role="status"
|
|
134
|
+
aria-busy="true"
|
|
135
|
+
aria-label={t("mail.loading")}
|
|
136
|
+
className="flex flex-col gap-1.5 p-3.5"
|
|
137
|
+
>
|
|
138
|
+
<div className="flex items-center justify-between gap-2">
|
|
139
|
+
<Skeleton className="h-3.5 w-32" />
|
|
140
|
+
<Skeleton className="h-3 w-12" />
|
|
141
|
+
</div>
|
|
142
|
+
<Skeleton className="h-3.5 w-3/4" />
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
116
145
|
</>
|
|
117
146
|
)}
|
|
118
147
|
</div>
|
|
119
148
|
)}
|
|
120
|
-
</
|
|
149
|
+
</PageCard>
|
|
121
150
|
</div>
|
|
122
151
|
);
|
|
123
152
|
}
|
package/pages/EmailView.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Field, Input,
|
|
1
|
+
import { Field, Input, PageCard, Badge, Button, toast, confirmDialog, useTranslation, roleSatisfies, useCurrentRole } from "@octarq/plugin-sdk";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
import { mailApi, Attachment, Email } from "../api";
|
|
4
4
|
import { Paperclip, Trash2, Reply, Download, X, Sparkles, ExternalLink, ShieldAlert, ArchiveRestore, Edit3, Copy, KeyRound } from "lucide-react";
|
|
@@ -16,11 +16,11 @@ function parseAttachments(json: string): Attachment[] {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const CATEGORY_META: Record<string, { tone: "
|
|
20
|
-
bill: { tone: "
|
|
21
|
-
otp: { tone: "
|
|
22
|
-
marketing: { tone: "
|
|
23
|
-
important: { tone: "
|
|
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
24
|
};
|
|
25
25
|
|
|
26
26
|
function renderImportanceDots(n?: number) {
|
|
@@ -61,14 +61,14 @@ export function EmailViewForm({
|
|
|
61
61
|
const [summary, setSummary] = useState("");
|
|
62
62
|
|
|
63
63
|
useEffect(() => {
|
|
64
|
-
mailApi.
|
|
64
|
+
mailApi.mailAiStatus().then((s) => setAiEnabled(s.configured)).catch(() => {});
|
|
65
65
|
}, []);
|
|
66
66
|
useEffect(() => setSummary(""), [email.id]);
|
|
67
67
|
|
|
68
68
|
async function summarize() {
|
|
69
69
|
setAiBusy(true);
|
|
70
70
|
try {
|
|
71
|
-
const r = await mailApi.
|
|
71
|
+
const r = await mailApi.summarizeEmail(email.id);
|
|
72
72
|
setSummary(r.summary);
|
|
73
73
|
} catch {
|
|
74
74
|
setSummary(t("mail.aiSummaryFailed"));
|
|
@@ -89,7 +89,7 @@ export function EmailViewForm({
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
return (
|
|
92
|
-
<
|
|
92
|
+
<PageCard className="mt-0 flex flex-col h-full max-h-full min-h-0 p-0">
|
|
93
93
|
<div className="p-5 border-b border-border flex justify-between items-start shrink-0 gap-4">
|
|
94
94
|
<div className="flex-1 min-w-0">
|
|
95
95
|
<h2 className="text-lg font-bold text-foreground mb-2 leading-snug">{email.subject || t("mail.noSubject")}</h2>
|
|
@@ -116,7 +116,7 @@ export function EmailViewForm({
|
|
|
116
116
|
{(email.otp || (email.category === "otp" && email.subject.match(/\b([A-Z0-9]{4,8})\b/i)?.[1])) && (
|
|
117
117
|
<div
|
|
118
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-
|
|
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
120
|
>
|
|
121
121
|
<div className="flex items-center gap-2.5">
|
|
122
122
|
<KeyRound className="h-4 w-4 text-accent-fg shrink-0" />
|
|
@@ -142,7 +142,7 @@ export function EmailViewForm({
|
|
|
142
142
|
)}
|
|
143
143
|
|
|
144
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-
|
|
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
146
|
<span className="text-warning-fg font-medium truncate">{t("mail.unsubscribe")}</span>
|
|
147
147
|
<Button
|
|
148
148
|
variant="outline"
|
|
@@ -159,7 +159,7 @@ export function EmailViewForm({
|
|
|
159
159
|
)}
|
|
160
160
|
|
|
161
161
|
{(summary || email.summary) && (
|
|
162
|
-
<div className="mx-5 mt-4 rounded-
|
|
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
163
|
<div className="flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wider text-accent-fg mb-1.5">
|
|
164
164
|
<Sparkles className="h-3 w-3" />
|
|
165
165
|
{t("mail.aiSummaryTitle")}
|
|
@@ -170,7 +170,8 @@ export function EmailViewForm({
|
|
|
170
170
|
|
|
171
171
|
<div className="flex-1 overflow-y-auto p-5 min-h-[400px] bg-well">
|
|
172
172
|
{email.html ? (
|
|
173
|
-
|
|
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")} />
|
|
174
175
|
) : (
|
|
175
176
|
<pre className="whitespace-pre-wrap break-words font-sans text-sm text-foreground leading-relaxed">{email.text}</pre>
|
|
176
177
|
)}
|
|
@@ -184,7 +185,7 @@ export function EmailViewForm({
|
|
|
184
185
|
<Paperclip className="h-3 w-3 text-accent-fg" />
|
|
185
186
|
{a.filename || t("mail.attachmentFallback")} <span className="font-mono tnum">({Math.max(1, Math.round(a.size / 1024))} KB)</span>
|
|
186
187
|
{a.truncated && (
|
|
187
|
-
<Badge tone="
|
|
188
|
+
<Badge tone="warning" className="font-mono text-[10px] uppercase tracking-wider ml-1">
|
|
188
189
|
{t("mail.truncated")}
|
|
189
190
|
</Badge>
|
|
190
191
|
)}
|
|
@@ -277,6 +278,6 @@ export function EmailViewForm({
|
|
|
277
278
|
</div>
|
|
278
279
|
</div>
|
|
279
280
|
</div>
|
|
280
|
-
</
|
|
281
|
+
</PageCard>
|
|
281
282
|
);
|
|
282
283
|
}
|