Refractoring Stage 6.18 Scoped pgp-mail-ui.js behind its existing window.epMailFeatures.pgp API and replaced its leftover global esc dependency with the mail API’s escapeHtml. Bumped to 0.4.30 (Android version code 430) and updated REFACTOR_PLAN.md.
This commit is contained in:
+6
-3
@@ -1,8 +1,10 @@
|
||||
(() => {
|
||||
// Reading and sending OpenPGP mail (desktop). Inert where there is no key store.
|
||||
const pgpMailUi = window.epMailFeatures.mail;
|
||||
const selectPgpMailUi = pgpMailUi.select;
|
||||
const selectAllPgpMailUi = pgpMailUi.selectAll;
|
||||
const toastPgpMailUi = pgpMailUi.toast;
|
||||
const escapePgpMailUi = pgpMailUi.escapeHtml;
|
||||
const pgpApi = () => window.daybreakMail?.pgp;
|
||||
|
||||
function pgpAskPassphrase(title, detail) {
|
||||
@@ -42,10 +44,10 @@ function pgpSignatureHtml(signatures, encrypted) {
|
||||
if (signature.mismatch) notes.push('The signing key does not belong to the sender address.');
|
||||
if (signature.status === 'valid') {
|
||||
const level = signature.keyChanged || signature.mismatch ? 'bad' : signature.trust === 'unknown' ? 'warn' : 'ok';
|
||||
return `<section class="pgp-status pgp-${level}" role="status"><strong>${lock}Valid signature from ${esc(signature.email || 'a known key')}</strong><span>${esc(trust)} · ${esc(pgpFormatFingerprint(signature.fingerprint))}</span>${notes.map(note => `<small>${esc(note)}</small>`).join('')}</section>`;
|
||||
return `<section class="pgp-status pgp-${level}" role="status"><strong>${lock}Valid signature from ${escapePgpMailUi(signature.email || 'a known key')}</strong><span>${escapePgpMailUi(trust)} · ${escapePgpMailUi(pgpFormatFingerprint(signature.fingerprint))}</span>${notes.map(note => `<small>${escapePgpMailUi(note)}</small>`).join('')}</section>`;
|
||||
}
|
||||
if (signature.status === 'unknown-key') {
|
||||
return `<section class="pgp-status pgp-warn" role="status"><strong>${lock}Signed with an unknown key</strong><span>Key ID ${esc(signature.keyId)} is not in your contacts, so the signature cannot be checked.</span>${notes.map(note => `<small>${esc(note)}</small>`).join('')}</section>`;
|
||||
return `<section class="pgp-status pgp-warn" role="status"><strong>${lock}Signed with an unknown key</strong><span>Key ID ${escapePgpMailUi(signature.keyId)} is not in your contacts, so the signature cannot be checked.</span>${notes.map(note => `<small>${escapePgpMailUi(note)}</small>`).join('')}</section>`;
|
||||
}
|
||||
return `<section class="pgp-status pgp-bad" role="alert"><strong>${lock}Invalid signature</strong><span>This message may have been altered or forged. Do not trust it.</span></section>`;
|
||||
}).join('');
|
||||
@@ -76,7 +78,7 @@ function pgpRenderReaderState(message) {
|
||||
html = pgpSignatureHtml(message.pgpSignatures, false);
|
||||
}
|
||||
const keys = message.pgpResult?.attachedKeys || [];
|
||||
header.insertAdjacentHTML('afterend', html + keys.map((key, index) => `<section class="pgp-status pgp-warn"><strong>Public key attached</strong><span>${esc(key.emails.join(', ') || 'unknown address')} · ${esc(pgpFormatFingerprint(key.fingerprint))}</span><button type="button" class="discard" data-pgp-key="${index}">Add to contacts…</button></section>`).join(''));
|
||||
header.insertAdjacentHTML('afterend', html + keys.map((key, index) => `<section class="pgp-status pgp-warn"><strong>Public key attached</strong><span>${escapePgpMailUi(key.emails.join(', ') || 'unknown address')} · ${escapePgpMailUi(pgpFormatFingerprint(key.fingerprint))}</span><button type="button" class="discard" data-pgp-key="${index}">Add to contacts…</button></section>`).join(''));
|
||||
reader.querySelectorAll('[data-pgp-key]').forEach(button => {
|
||||
button.onclick = () => pgpAddAttachedKey(keys[Number(button.dataset.pgpKey)]);
|
||||
});
|
||||
@@ -196,3 +198,4 @@ async function prepareSend(to, cc) {
|
||||
}
|
||||
|
||||
window.epMailFeatures.pgp = Object.freeze({ prepareSend });
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user