email compose

This commit is contained in:
debu-2 2026-10-05 21:57:22 +05:30
parent 2af0724938
commit f95901d596
6 changed files with 639 additions and 274 deletions

View file

@ -0,0 +1,44 @@
export const DRAFT_KEY_PREFIX = "agmail_draft_";
export function draftStorageKey(windowId) {
return `${DRAFT_KEY_PREFIX}${windowId}`;
}
export function readDraft(windowId) {
try {
const raw = localStorage.getItem(draftStorageKey(windowId));
return raw ? JSON.parse(raw) : null;
} catch {
return null;
}
}
export function isDraftEmpty(windowId) {
const draft = readDraft(windowId);
if (!draft) return true;
return (
!draft.subject
&& !draft.bodyHtml
&& !draft.to?.length
&& !draft.cc?.length
&& !draft.bcc?.length
);
}
export function draftHasContent(windowId) {
return !isDraftEmpty(windowId);
}
export function draftTitle(windowId) {
const draft = readDraft(windowId);
if (!draft) return "New message";
if (draft.subject?.trim()) return draft.subject.trim();
const first = draft.to?.[0];
if (first?.name) return first.name;
if (first?.email) return first.email.split("@")[0];
return "New message";
}
export function clearDraft(windowId) {
localStorage.removeItem(draftStorageKey(windowId));
}