From cbb47203533c840ec7e7a3582f44a53a20cfaef6 Mon Sep 17 00:00:00 2001 From: Tero Date: Fri, 16 Oct 2026 22:47:41 +0300 Subject: [PATCH] =?UTF-8?q?=20Refractoring=20Stage=206.18=20Scoped=20pgp-m?= =?UTF-8?q?ail-ui.js=20behind=20its=20existing=20window.epMailFeatures.pgp?= =?UTF-8?q?=20API=20and=20replaced=20its=20leftover=20global=20esc=20depen?= =?UTF-8?q?dency=20with=20the=20mail=20API=E2=80=99s=20escapeHtml.=20Bumpe?= =?UTF-8?q?d=20to=200.4.30=20(Android=20version=20code=20430)=20and=20upda?= =?UTF-8?q?ted=20REFACTOR=5FPLAN.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- REFACTOR_PLAN.md | 4 +++- package-lock.json | 4 ++-- package.json | 2 +- pgp-mail-ui.js | 9 ++++++--- tests/renderer-mail-api.test.cjs | 3 +++ www/pgp-mail-ui.js | 9 ++++++--- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/REFACTOR_PLAN.md b/REFACTOR_PLAN.md index c650d4d..b37d01a 100644 --- a/REFACTOR_PLAN.md +++ b/REFACTOR_PLAN.md @@ -118,6 +118,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC - [x] Encapsulate core renderer implementation behind `window.epMailShell` (`app.js`). - [x] Encapsulate mail UI implementation behind `window.epMailFeatures.mail` (`mail-ui.js`). - [x] Encapsulate OpenPGP key-management UI helpers locally; it contributes to Preferences through the productivity API (`pgp-ui.js`). +- [x] Encapsulate OpenPGP mail helpers behind `window.epMailFeatures.pgp` and use the mail API's HTML escaping helper (`pgp-mail-ui.js`). - [x] Migrate additional mail-related consumers to unique local aliases to avoid classic-script lexical redeclarations. - [x] Add a combined-script parse test to prevent duplicate top-level lexical declarations from stopping later UI scripts. - [ ] Migrate remaining mail-related consumers and remove transitional global dependencies. @@ -146,7 +147,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC - Electron Builder and the desktop Actions artifact name derive from `package.json`. - Android `versionName` derives from the same package version. Its current `versionCode` mapping is `major * 10000 + minor * 100 + patch`; keep minor and patch below 100, and revise the mapping before reaching that boundary to avoid collisions. - `scripts/build-all.ps1` uses the package version for APK naming. Before a release, bump once with `npm run bump:build`, verify the lockfile and computed Android version code, and build every target without another bump. -- Latest version check: `package.json` and both lockfile version fields are `0.4.29`; Android derives `versionName 0.4.29` and `versionCode 429`. The user confirms the previous artifact works; this bump is for the next build. +- Latest version check: `package.json` and both lockfile version fields are `0.4.30`; Android derives `versionName 0.4.30` and `versionCode 430`. The user confirms the previous artifact works; this bump is for the next build. ## Progress log @@ -178,5 +179,6 @@ This is a gradual destination, not a requirement to move everything at once. IPC - Step 6 at version `0.4.27` scopes core renderer functions and state in `app.js`; other scripts continue through the explicit `epMailShell` interface. - Step 6 at version `0.4.28` scopes mail UI implementation details while retaining its explicit mail feature API. - Step 6 at version `0.4.29` scopes OpenPGP key UI implementation helpers without changing its Preferences integration. +- Step 6 at version `0.4.30` scopes PGP mail helpers, preserving the `prepareSend` API and removing its dependency on the core shell's former global HTML escape helper. - The current IPC/DAV validation changes pass the full suite: 108 tests. - While work continued, `package.json` and `package-lock.json` reflected a version bump to `0.4.6`; those changes were preserved. diff --git a/package-lock.json b/package-lock.json index efb53d4..0412320 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ep-mail", - "version": "0.4.29", + "version": "0.4.30", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ep-mail", - "version": "0.4.29", + "version": "0.4.30", "dependencies": { "@capacitor/android": "^8.5.2", "@capacitor/core": "^8.5.2", diff --git a/package.json b/package.json index 2523aa9..03c9005 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ep-mail", - "version": "0.4.29", + "version": "0.4.30", "private": true, "description": "Eternity Project mail client", "homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client", diff --git a/pgp-mail-ui.js b/pgp-mail-ui.js index 0914207..e0e7544 100644 --- a/pgp-mail-ui.js +++ b/pgp-mail-ui.js @@ -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 `
${lock}Valid signature from ${esc(signature.email || 'a known key')}${esc(trust)} · ${esc(pgpFormatFingerprint(signature.fingerprint))}${notes.map(note => `${esc(note)}`).join('')}
`; + return `
${lock}Valid signature from ${escapePgpMailUi(signature.email || 'a known key')}${escapePgpMailUi(trust)} · ${escapePgpMailUi(pgpFormatFingerprint(signature.fingerprint))}${notes.map(note => `${escapePgpMailUi(note)}`).join('')}
`; } if (signature.status === 'unknown-key') { - return `
${lock}Signed with an unknown keyKey ID ${esc(signature.keyId)} is not in your contacts, so the signature cannot be checked.${notes.map(note => `${esc(note)}`).join('')}
`; + return `
${lock}Signed with an unknown keyKey ID ${escapePgpMailUi(signature.keyId)} is not in your contacts, so the signature cannot be checked.${notes.map(note => `${escapePgpMailUi(note)}`).join('')}
`; } return ``; }).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) => `
Public key attached${esc(key.emails.join(', ') || 'unknown address')} · ${esc(pgpFormatFingerprint(key.fingerprint))}
`).join('')); + header.insertAdjacentHTML('afterend', html + keys.map((key, index) => `
Public key attached${escapePgpMailUi(key.emails.join(', ') || 'unknown address')} · ${escapePgpMailUi(pgpFormatFingerprint(key.fingerprint))}
`).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 }); +})(); diff --git a/tests/renderer-mail-api.test.cjs b/tests/renderer-mail-api.test.cjs index 351defe..4d0f593 100644 --- a/tests/renderer-mail-api.test.cjs +++ b/tests/renderer-mail-api.test.cjs @@ -72,6 +72,9 @@ test('account and snooze UI consume the explicit mail API instead of selected le assert.match(snoozeUi, /window\.epMailFeatures\.mail/); assert.match(attachmentUi, /window\.epMailFeatures\.mail/); assert.match(pgpMailUi, /window\.epMailFeatures\.mail/); + assert.match(pgpMailUi, /^\(\(\) => \{/); + assert.match(pgpMailUi, /window\.epMailFeatures\.pgp = Object\.freeze/); + assert.doesNotMatch(pgpMailUi, /(? \{/); assert.match(accountUi, /const accountDavUi = window\.epMailFeatures\.dav/); diff --git a/www/pgp-mail-ui.js b/www/pgp-mail-ui.js index 0914207..e0e7544 100644 --- a/www/pgp-mail-ui.js +++ b/www/pgp-mail-ui.js @@ -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 `
${lock}Valid signature from ${esc(signature.email || 'a known key')}${esc(trust)} · ${esc(pgpFormatFingerprint(signature.fingerprint))}${notes.map(note => `${esc(note)}`).join('')}
`; + return `
${lock}Valid signature from ${escapePgpMailUi(signature.email || 'a known key')}${escapePgpMailUi(trust)} · ${escapePgpMailUi(pgpFormatFingerprint(signature.fingerprint))}${notes.map(note => `${escapePgpMailUi(note)}`).join('')}
`; } if (signature.status === 'unknown-key') { - return `
${lock}Signed with an unknown keyKey ID ${esc(signature.keyId)} is not in your contacts, so the signature cannot be checked.${notes.map(note => `${esc(note)}`).join('')}
`; + return `
${lock}Signed with an unknown keyKey ID ${escapePgpMailUi(signature.keyId)} is not in your contacts, so the signature cannot be checked.${notes.map(note => `${escapePgpMailUi(note)}`).join('')}
`; } return ``; }).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) => `
Public key attached${esc(key.emails.join(', ') || 'unknown address')} · ${esc(pgpFormatFingerprint(key.fingerprint))}
`).join('')); + header.insertAdjacentHTML('afterend', html + keys.map((key, index) => `
Public key attached${escapePgpMailUi(key.emails.join(', ') || 'unknown address')} · ${escapePgpMailUi(pgpFormatFingerprint(key.fingerprint))}
`).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 }); +})();