Refractoring Stage 6.24 Moved the HTML sanitizer and remote-image policy API into window.epMailFeatures.contentSecurity, removing the separate window.epMailMailContentSecurity global. Bumped to 0.4.36 (Android version code 436) and updated REFACTOR_PLAN.md.

This commit is contained in:
2026-10-16 23:14:31 +03:00
parent bc550cc929
commit cfb6ddc2bb
8 changed files with 22 additions and 8 deletions
+3 -1
View File
@@ -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.
+1 -1
View File
@@ -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=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[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=>`<div class="message ${m.unread?'unread':''} ${m.id===state.activeMessage?'selected':''}" data-id="${m.id}"><input class="row-check" type="checkbox" aria-label="Select message" ${state.selectedIds.has(m.id)?'checked':''}><div class="contact-avatar" style="background:${m.color}">${m.initials}</div><div class="message-body"><div class="sender">${esc(m.sender)}</div><div class="subject">${esc(m.subject)}</div><div class="snippet">${esc(m.snippet)}</div></div><div class="message-meta"><span class="time">${esc(m.time)}</span><button class="star ${m.star?'on':''}" aria-label="${m.star?'Unstar':'Star'}">${m.star?'★':'☆'}</button></div></div>`).join(''):`<div class="reader-empty"><div><div class="empty-icon">⌕</div><h3>No messages here</h3><p>Try another folder or search.</p></div></div>`;$$('.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;
+2 -1
View File
@@ -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
});
+2 -2
View File
@@ -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",
+1 -1
View File
@@ -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",
+10
View File
@@ -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', () => {
+1 -1
View File
@@ -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=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[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=>`<div class="message ${m.unread?'unread':''} ${m.id===state.activeMessage?'selected':''}" data-id="${m.id}"><input class="row-check" type="checkbox" aria-label="Select message" ${state.selectedIds.has(m.id)?'checked':''}><div class="contact-avatar" style="background:${m.color}">${m.initials}</div><div class="message-body"><div class="sender">${esc(m.sender)}</div><div class="subject">${esc(m.subject)}</div><div class="snippet">${esc(m.snippet)}</div></div><div class="message-meta"><span class="time">${esc(m.time)}</span><button class="star ${m.star?'on':''}" aria-label="${m.star?'Unstar':'Star'}">${m.star?'★':'☆'}</button></div></div>`).join(''):`<div class="reader-empty"><div><div class="empty-icon">⌕</div><h3>No messages here</h3><p>Try another folder or search.</p></div></div>`;$$('.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;
+2 -1
View File
@@ -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
});