diff --git a/REFACTOR_PLAN.md b/REFACTOR_PLAN.md index 9ea4a03..30b3315 100644 --- a/REFACTOR_PLAN.md +++ b/REFACTOR_PLAN.md @@ -124,6 +124,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC - [x] Encapsulate keyboard shortcut settings and handlers locally; integrations remain through the mail/productivity feature APIs (`shortcuts.js`). - [x] Remove transitional renderer-state globals after all consumers migrated to the namespaced state API (`renderer-state.js`). - [x] Register the mail API factory under the shared feature namespace instead of a standalone renderer global (`renderer-mail-api.js`, `mail-ui.js`). +- [x] Register content security helpers under the shared feature namespace instead of a standalone global (`mail-content-security.js`, `app.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. @@ -152,7 +153,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.35`; Android derives `versionName 0.4.35` and `versionCode 435`. 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.36`; Android derives `versionName 0.4.36` and `versionCode 436`. The user confirms the previous artifact works; this bump is for the next build. ## Progress log @@ -190,5 +191,6 @@ This is a gradual destination, not a requirement to move everything at once. IPC - Step 6 at version `0.4.33` scopes keyboard shortcut helpers and event handlers without changing their Preferences integration. - Step 6 at version `0.4.34` removes legacy global renderer-state accessors; the state module now exposes only `window.epMailState` to the renderer. - Step 6 at version `0.4.35` consolidates the mail API factory under `window.epMailFeatures.modules`, removing the separate `window.epMailUiModules` global. +- Step 6 at version `0.4.36` consolidates the HTML sanitization and remote-image policy API under `window.epMailFeatures.contentSecurity`. - 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/app.js b/app.js index a0762b7..425ab65 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,7 @@ if('serviceWorker'in navigator)window.addEventListener('load',()=>navigator.serv const state = window.epMailState; const $=s=>document.querySelector(s), $$=s=>[...document.querySelectorAll(s)]; function esc(x){return String(x).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))} -const { safeRemoteImageUrl, sanitizeMailHtml } = window.epMailMailContentSecurity; +const { safeRemoteImageUrl, sanitizeMailHtml } = window.epMailFeatures.contentSecurity; function renderList(){let rows=state.messages.filter(m=>{if(state.activeFolder==='Starred'&&!m.star)return false;if(state.activeFolder==='Inbox'&&m.archived)return false;if(state.activeFolder==='Archive'&&!m.archived)return false;if(state.activeFolder==='Trash'&&!m.deleted)return false;if(state.activeFolder==='Sent'&&!m.sent)return false;if(state.activeFolder==='Drafts')return false;if(state.activeFolder==='Snoozed')return false;if(m.deleted&&state.activeFolder!=='Trash')return false;return !state.query||`${m.sender} ${m.email} ${m.subject} ${m.snippet}`.toLowerCase().includes(state.query.toLowerCase())});$('#message-list').innerHTML=rows.length?rows.map(m=>`
${m.initials}
${esc(m.sender)}
${esc(m.subject)}
${esc(m.snippet)}
${esc(m.time)}
`).join(''):`
⌕

No messages here

Try another folder or search.

`;$$('.message').forEach(row=>{row.addEventListener('click',e=>{if(e.target.closest('.row-check')){const id=+row.dataset.id;state.selectedIds.has(id)?state.selectedIds.delete(id):state.selectedIds.add(id);return}if(e.target.closest('.star')){const m=state.messages.find(x=>x.id===+row.dataset.id);m.star=!m.star;renderList();return}openMessage(+row.dataset.id)});});if(!rows.length)$('#reader-pane').innerHTML=emptyReader()} function openMessage(id){ state.activeMessage=id; diff --git a/mail-content-security.js b/mail-content-security.js index fc4d16f..f724612 100644 --- a/mail-content-security.js +++ b/mail-content-security.js @@ -3,7 +3,8 @@ module.exports = { createMailContentSecurity }; return; } - Object.defineProperty(root, 'epMailMailContentSecurity', { + root.epMailFeatures = root.epMailFeatures || {}; + Object.defineProperty(root.epMailFeatures, 'contentSecurity', { value: createMailContentSecurity(root), enumerable: false }); diff --git a/package-lock.json b/package-lock.json index 176ccfc..5e7933c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ep-mail", - "version": "0.4.35", + "version": "0.4.36", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ep-mail", - "version": "0.4.35", + "version": "0.4.36", "dependencies": { "@capacitor/android": "^8.5.2", "@capacitor/core": "^8.5.2", diff --git a/package.json b/package.json index f00d708..446daa7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ep-mail", - "version": "0.4.35", + "version": "0.4.36", "private": true, "description": "Eternity Project mail client", "homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client", diff --git a/tests/renderer-bootstrap.test.cjs b/tests/renderer-bootstrap.test.cjs index 9a5fd45..029a0d8 100644 --- a/tests/renderer-bootstrap.test.cjs +++ b/tests/renderer-bootstrap.test.cjs @@ -28,6 +28,16 @@ test('core app shell uses the namespaced renderer state', () => { assert.match(app, /window\.epMailShell = Object\.freeze/); assert.match(app, /const state = window\.epMailState/); assert.doesNotMatch(app, /^\s*(?:const|let|var)\s+(?:messages|contacts|activeMessage|activeFolder|activeView|query|toastTimer|selectedIds)\b/m); + assert.match(app, /window\.epMailFeatures\.contentSecurity/); + assert.doesNotMatch(app, /epMailMailContentSecurity/); +}); + +test('mail content security API is registered in the shared feature namespace', () => { + const window = {}; + vm.runInNewContext(read('mail-content-security.js'), { window }); + assert.equal(typeof window.epMailFeatures.contentSecurity.safeRemoteImageUrl, 'function'); + assert.equal(typeof window.epMailFeatures.contentSecurity.sanitizeMailHtml, 'function'); + assert.equal(Object.hasOwn(window, 'epMailMailContentSecurity'), false); }); test('desktop, Android web generation, and offline cache include renderer support modules', () => { diff --git a/www/app.js b/www/app.js index a0762b7..425ab65 100644 --- a/www/app.js +++ b/www/app.js @@ -3,7 +3,7 @@ if('serviceWorker'in navigator)window.addEventListener('load',()=>navigator.serv const state = window.epMailState; const $=s=>document.querySelector(s), $$=s=>[...document.querySelectorAll(s)]; function esc(x){return String(x).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))} -const { safeRemoteImageUrl, sanitizeMailHtml } = window.epMailMailContentSecurity; +const { safeRemoteImageUrl, sanitizeMailHtml } = window.epMailFeatures.contentSecurity; function renderList(){let rows=state.messages.filter(m=>{if(state.activeFolder==='Starred'&&!m.star)return false;if(state.activeFolder==='Inbox'&&m.archived)return false;if(state.activeFolder==='Archive'&&!m.archived)return false;if(state.activeFolder==='Trash'&&!m.deleted)return false;if(state.activeFolder==='Sent'&&!m.sent)return false;if(state.activeFolder==='Drafts')return false;if(state.activeFolder==='Snoozed')return false;if(m.deleted&&state.activeFolder!=='Trash')return false;return !state.query||`${m.sender} ${m.email} ${m.subject} ${m.snippet}`.toLowerCase().includes(state.query.toLowerCase())});$('#message-list').innerHTML=rows.length?rows.map(m=>`
${m.initials}
${esc(m.sender)}
${esc(m.subject)}
${esc(m.snippet)}
${esc(m.time)}
`).join(''):`
⌕

No messages here

Try another folder or search.

`;$$('.message').forEach(row=>{row.addEventListener('click',e=>{if(e.target.closest('.row-check')){const id=+row.dataset.id;state.selectedIds.has(id)?state.selectedIds.delete(id):state.selectedIds.add(id);return}if(e.target.closest('.star')){const m=state.messages.find(x=>x.id===+row.dataset.id);m.star=!m.star;renderList();return}openMessage(+row.dataset.id)});});if(!rows.length)$('#reader-pane').innerHTML=emptyReader()} function openMessage(id){ state.activeMessage=id; diff --git a/www/mail-content-security.js b/www/mail-content-security.js index fc4d16f..f724612 100644 --- a/www/mail-content-security.js +++ b/www/mail-content-security.js @@ -3,7 +3,8 @@ module.exports = { createMailContentSecurity }; return; } - Object.defineProperty(root, 'epMailMailContentSecurity', { + root.epMailFeatures = root.epMailFeatures || {}; + Object.defineProperty(root.epMailFeatures, 'contentSecurity', { value: createMailContentSecurity(root), enumerable: false });