Refractoring Stage 6.5 Migrated the snooze, attachment, and OpenPGP mail UI to the explicit mail feature API.

This commit is contained in:
2026-10-16 20:31:59 +03:00
parent f19573a337
commit 84a63441ef
14 changed files with 178 additions and 108 deletions
+14 -14
View File
@@ -1,4 +1,8 @@
// Reading and sending OpenPGP mail (desktop). Inert where there is no key store.
const mailUi = window.epMailFeatures.mail;
const $ = mailUi.select;
const $$ = mailUi.selectAll;
const toast = mailUi.toast;
const pgpApi = () => window.daybreakMail?.pgp;
function pgpAskPassphrase(title, detail) {
@@ -95,7 +99,7 @@ async function pgpUnlockMessage(message, interactive) {
body: result.body, html: result.html, links: result.links, attachments: result.attachments, attachment: result.attachment, size: result.size,
snippet: 'Encrypted message', pgpDecrypted: true, pgpResult: { signatures: result.signatures, attachedKeys: result.attachedKeys }
});
if (activeMessage === message.id) openMessage(message.id);
if (mailUi.state.activeMessage === message.id) mailUi.openMessage(message.id);
return;
}
if (result.code === 'PASSPHRASE_REQUIRED' || result.code === 'BAD_PASSPHRASE') {
@@ -111,24 +115,19 @@ async function pgpUnlockMessage(message, interactive) {
}
}
if (typeof openMessage === 'function') {
const baseOpenMessage = openMessage;
openMessage = function (id) {
mailUi.wrapOpenMessage(baseOpenMessage => function (id) {
baseOpenMessage(id);
const message = messages.find(item => item.id === id);
const message = mailUi.state.messages.find(item => item.id === id);
if (!message || !pgpApi()) return;
pgpRenderReaderState(message);
if (message.encrypted && !message.pgpDecrypted && !message.pgpAutoTried) {
message.pgpAutoTried = true;
void pgpUnlockMessage(message, false);
}
};
}
});
// Compose: encrypt/sign options.
if (typeof showCompose === 'function') {
const baseShowCompose = showCompose;
showCompose = function (reply, forward = false) {
mailUi.wrapShowCompose(baseShowCompose => function (reply, forward = false) {
baseShowCompose(reply, forward);
const footer = $('#modal-root .compose-footer');
if (!footer || !pgpApi()) return;
@@ -163,11 +162,10 @@ if (typeof showCompose === 'function') {
['#compose-to', '#compose-cc'].forEach(selector => $(selector)?.addEventListener('input', schedule));
sign.addEventListener('change', schedule);
schedule();
};
}
});
// Called by the send handler. Returns null (plain mail), false (cancelled) or send options.
window.pgpPrepareSend = async function pgpPrepareSend(to, cc) {
async function prepareSend(to, cc) {
if (!pgpApi()) return null;
let encrypt = Boolean($('#pgp-encrypt')?.checked);
const sign = Boolean($('#pgp-sign')?.checked);
@@ -195,4 +193,6 @@ window.pgpPrepareSend = async function pgpPrepareSend(to, cc) {
}
}
return { encrypt, sign, passphrase };
};
}
window.epMailFeatures.pgp = Object.freeze({ prepareSend });