diff --git a/REFACTOR_PLAN.md b/REFACTOR_PLAN.md
index 5cf2bcf..89a1bba 100644
--- a/REFACTOR_PLAN.md
+++ b/REFACTOR_PLAN.md
@@ -101,6 +101,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC
### 6. Modularize renderer incrementally — in progress
- [x] Introduce a namespaced shared renderer-state module with transitional classic-script accessors (`renderer-state.js`).
+- [x] Extract mail HTML sanitization and remote-image approval checks into a dedicated renderer API (`mail-content-security.js`).
- [ ] Convert mail UI to explicit feature APIs and remove legacy global dependencies.
- Replace hidden globals and script-order dependencies with imports or passed dependencies.
- Keep root web assets canonical and generated copies out of hand-edited workflows.
@@ -127,7 +128,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.13`; Android derives `versionName 0.4.13` and `versionCode 413`. The user confirmed the `0.4.12` artifact was built and tested; `release/` contains its Windows executable. The `0.4.13` artifact has not yet been built.
+- Latest version check: `package.json` and both lockfile version fields are `0.4.14`; Android derives `versionName 0.4.14` and `versionCode 414`. `release/` currently contains Windows artifacts through `0.4.13`; no `0.4.14` artifact has been built yet.
## Progress log
@@ -146,8 +147,9 @@ This is a gradual destination, not a requirement to move everything at once. IPC
- Step 5 moved OpenPGP handler registration and message-source fetching into a feature module and added registration/schema coverage.
- Step 5 moved DAV handler registration into a feature module and added registration/schema coverage; the full suite passes 110 tests.
- Step 5 grouped mail/account handlers in `desktop/ipc/mail.cjs`; all 114 tests pass and the remaining app-version handler stays in the Electron shell.
-- Added a build-version consistency check. The user bumped to `0.4.13`; package and lockfile match, and Android's derived build number is `413`. The verified release artifact remains `0.4.12`.
+- Added a build-version consistency check. The user bumped to `0.4.14`; package and lockfile match, and Android's derived build number is `414`. The latest artifact observed is Windows `0.4.13`.
- Step 5 grouped mail/account handlers and added a release-version consistency test; current package/lockfile/Android version alignment was checked and documented.
-- Step 6 added `renderer-state.js` as the namespaced owner of shared mail/view state, retaining temporary classic-script accessors. It is included in desktop, Android-web, and service-worker asset lists and covered by state/parity tests.
+- Step 6 added `renderer-state.js` as the namespaced owner of shared mail/view state and `mail-content-security.js` as a dedicated sanitizer/remote-image API. Transitional classic-script accessors remain; bootstrap order and desktop/Android/offline asset inclusion are tested.
+- Step 6's first renderer slice passes 119 tests. The `0.4.14` artifact has not been built as part of this renderer change.
- 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 e27e70a..8e05e68 100644
--- a/app.js
+++ b/app.js
@@ -1,48 +1,7 @@
if('serviceWorker'in navigator)window.addEventListener('load',()=>navigator.serviceWorker.register('./service-worker.js').catch(()=>{}));
const $=s=>document.querySelector(s), $$=s=>[...document.querySelectorAll(s)];
function esc(x){return String(x).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}
-function safeRemoteImageUrl(value){if(typeof value!=='string'||value.length>2048)return null;try{const url=new URL(value);return url.protocol==='https:'&&url.hostname&&!url.username&&!url.password?url.href:null}catch{return null}}
-function sanitizeMailHtml(value){
- const html=String(value||'').slice(0,100000);
- const inertImages=html
- .replace(/<(script|style|iframe|frame|object|embed|svg|math|form|noscript|template|video|audio|source|picture|track)\b[\s\S]*?<\/\1\s*>/gi,'')
- .replace(/<(?:script|style|iframe|frame|object|embed|svg|math|form|noscript|template|video|audio|source|picture|track|link|base|meta)\b[^>]*>/gi,'')
- .replace(//g,'')
- .replace(/]*>/gi,tag=>{
- const source=tag.match(/\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s/>]+))/i);
- const alt=tag.match(/\balt\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s/>]+))/i);
- const remote=source&&(source[1]||source[2]||source[3]||'').trim();
- const alternative=alt&&(alt[1]||alt[2]||alt[3]||'');
- return ``;
- })
- .replace(/\s(?:src|srcset|background|poster|action|formaction|href|xlink:href|srcdoc|dynsrc|lowsrc|style)\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi,'');
- const document=new DOMParser().parseFromString(inertImages,'text/html');
- const allowed=new Set(['a','p','div','span','br','hr','h1','h2','h3','h4','h5','h6','b','strong','i','em','u','s','del','blockquote','pre','code','ul','ol','li','table','thead','tbody','tfoot','tr','th','td','img']);
- const discard=new Set(['script','style','iframe','frame','object','embed','svg','math','form','input','button','textarea','select','option','link','base','meta','video','audio','source','picture','track']);
- let remoteImageCount=0;
- const clean=parent=>{
- for(const node of [...parent.childNodes]){
- if(node.nodeType!==Node.ELEMENT_NODE){if(node.nodeType!==Node.TEXT_NODE)node.remove();continue}
- const name=node.localName.toLowerCase();
- if(discard.has(name)){node.remove();continue}
- if(!allowed.has(name)){node.replaceWith(...node.childNodes);continue}
- for(const attribute of [...node.attributes]){
- const key=attribute.name.toLowerCase();
- const keep=(name==='img'&&(key==='alt'||key==='data-remote-src'))||
- (name==='td'||name==='th')&&['colspan','rowspan'].includes(key)&&/^\d{1,2}$/.test(attribute.value);
- if(!keep)node.removeAttribute(attribute.name);
- }
- if(name==='img'){
- const url=safeRemoteImageUrl(node.getAttribute('data-remote-src'));
- if(url){node.setAttribute('data-remote-src',url);remoteImageCount+=1}
- else node.removeAttribute('data-remote-src');
- }
- clean(node);
- }
- };
- clean(document.body);
- return {html:document.body.innerHTML,remoteImageCount};
-}
+const { safeRemoteImageUrl, sanitizeMailHtml } = window.epMailMailContentSecurity;
function renderList(){let rows=messages.filter(m=>{if(activeFolder==='Starred'&&!m.star)return false;if(activeFolder==='Inbox'&&m.archived)return false;if(activeFolder==='Archive'&&!m.archived)return false;if(activeFolder==='Trash'&&!m.deleted)return false;if(activeFolder==='Sent'&&!m.sent)return false;if(activeFolder==='Drafts')return false;if(activeFolder==='Snoozed')return false;if(m.deleted&&activeFolder!=='Trash')return false;return !query||`${m.sender} ${m.email} ${m.subject} ${m.snippet}`.toLowerCase().includes(query.toLowerCase())});$('#message-list').innerHTML=rows.length?rows.map(m=>`