diff --git a/REFACTOR_PLAN.md b/REFACTOR_PLAN.md
index c76843c..3790cad 100644
--- a/REFACTOR_PLAN.md
+++ b/REFACTOR_PLAN.md
@@ -110,6 +110,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC
- [x] Migrate Calendar/Contacts navigation and DAV UI to the productivity feature API (`app.js`, `dav-ui.js`).
- [x] Migrate OpenPGP key UI to the mail feature API for active-account access (`pgp-ui.js`).
- [x] Make the core app shell consume the namespaced renderer state instead of compatibility aliases.
+- [x] Expose core shell behavior through an explicit renderer API and migrate mail UI selectors, notifications, rendering, and compose hooks to that API (`app.js`, `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.
@@ -138,7 +139,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.21`; Android derives `versionName 0.4.21` and `versionCode 421`. The checked-in `release/` directory contains Windows artifacts through `0.4.20`; the user confirms the current artifact works.
+- Latest version check: `package.json` and both lockfile version fields are `0.4.22`; Android derives `versionName 0.4.22` and `versionCode 422`. The user confirms the current artifact works.
## Progress log
@@ -157,9 +158,11 @@ 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. Package/lockfile are `0.4.21`, with Android build number `421`; the user confirms the current artifact works.
+- Added a build-version consistency check; the initial verification was at package version `0.4.21` / Android build number `421`.
- 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`, extracted the mail HTML security API, and introduced `renderer-mail-api.js`; `account-ui.js` now uses that explicit API instead of several mail globals. Transitional aliases remain for other classic scripts.
- Step 6 migrated snooze, attachment, OpenPGP mail/key, shortcut, productivity state/render, and DAV UI integrations to feature APIs; compatibility globals remain in the core shell and some cross-feature hooks. The core app now reads shared state through `renderer-state.js`; the suite passes 123 tests.
+- Step 6 added an explicit `epMailShell` interface for mail UI selectors, notifications, views, and renderer wrappers. `mail-ui.js` now uses it rather than directly replacing core renderer functions; search resets use namespaced state, and preferences remain owned by the productivity feature.
+- Step 6 verification at version `0.4.22` / Android build number `422`: all 123 tests pass, including generated `www/` parity and combined classic-script parsing.
- 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 23f2156..8c99203 100644
--- a/app.js
+++ b/app.js
@@ -35,3 +35,21 @@ function toast(s){const el=$('#toast');el.textContent=s;el.classList.add('visibl
function showCompose(reply,forward=false){const root=$('#modal-root');root.innerHTML=`
${reply?(forward?'Forward message':'Reply to message'):'New message'}
Your password is encrypted with this computer's credential storage. Connections require TLS.
MAIL RULES
Rules match the sender or subject of incoming mail. The first matching rule runs.
${ruleMarkup}
Signatures are appended to outgoing messages. Sync interval controls periodic checks when IMAP IDLE is unavailable; Android may apply its 15-minute minimum background interval.${editing ? ' Leave the password empty to keep the saved password.' : ''}
`;
+ root.innerHTML = `
${editing ? 'Edit mailbox' : 'Add a mailbox'}
Your password is encrypted with this computer's credential storage. Connections require TLS.
MAIL RULES
Rules match the sender or subject of incoming mail. The first matching rule runs.
${ruleMarkup}
Signatures are appended to outgoing messages. Sync interval controls periodic checks when IMAP IDLE is unavailable; Android may apply its 15-minute minimum background interval.${editing ? ' Leave the password empty to keep the saved password.' : ''}
`;
const close = () => { root.innerHTML = ''; };
- $$('.modal-close').forEach(button => button.onclick = close);
- $('.modal-overlay').addEventListener('click', event => { if (event.target.classList.contains('modal-overlay')) close(); });
- $('#disconnect-mail').onclick = close;
+ selectAllMailUi('.modal-close').forEach(button => button.onclick = close);
+ selectMailUi('.modal-overlay').addEventListener('click', event => { if (event.target.classList.contains('modal-overlay')) close(); });
+ selectMailUi('#disconnect-mail').onclick = close;
const addRuleRow = rule => {
const row = document.createElement('div');
row.className = 'mail-rule-row';
- row.innerHTML = ``;
+ row.innerHTML = ``;
row.querySelector('.mail-rule-action').value = rule?.action || 'archive';
- $('#mail-rule-list').append(row);
+ selectMailUi('#mail-rule-list').append(row);
};
- $('#add-mail-rule').onclick = () => addRuleRow();
- $('#mail-rule-list').onclick = event => {
+ selectMailUi('#add-mail-rule').onclick = () => addRuleRow();
+ selectMailUi('#mail-rule-list').onclick = event => {
if (event.target.closest('.remove-mail-rule')) event.target.closest('.mail-rule-row').remove();
};
- $('#mail-rule-list').onchange = event => {
+ selectMailUi('#mail-rule-list').onchange = event => {
if (!event.target.matches('.mail-rule-action')) return;
const row = event.target.closest('.mail-rule-row');
const value = row.querySelector('.mail-rule-value');
@@ -251,27 +255,27 @@ function openMailAccount(existingAccount = null) {
}
row.querySelector('.mail-rule-value').disabled = event.target.value === 'flag';
};
- $('#connect-mail').onclick = async () => {
- const button = $('#connect-mail');
- const status = $('#mail-account-status');
- const password = $('#mail-account-password').value;
- const name = $('#mail-account-display-name').value.trim();
- if (!name) { status.textContent = 'Enter a display name for this mail account.'; $('#mail-account-display-name').focus(); return; }
- if (!editing && !password) { status.textContent = 'Enter the mailbox password to connect.'; $('#mail-account-password').focus(); return; }
+ selectMailUi('#connect-mail').onclick = async () => {
+ const button = selectMailUi('#connect-mail');
+ const status = selectMailUi('#mail-account-status');
+ const password = selectMailUi('#mail-account-password').value;
+ const name = selectMailUi('#mail-account-display-name').value.trim();
+ if (!name) { status.textContent = 'Enter a display name for this mail account.'; selectMailUi('#mail-account-display-name').focus(); return; }
+ if (!editing && !password) { status.textContent = 'Enter the mailbox password to connect.'; selectMailUi('#mail-account-password').focus(); return; }
button.disabled = true;
button.textContent = editing ? 'Checking updated settings…' : 'Checking secure connections…';
status.textContent = editing ? 'Testing the updated mailbox settings before saving.' : 'Checking IMAP and SMTP sign-in. This may take a moment.';
try {
const details = {
- email: $('#mail-account-email').value,
+ email: selectMailUi('#mail-account-email').value,
password,
displayName: name,
- imapHost: $('#mail-account-imap').value,
- smtpHost: $('#mail-account-smtp').value,
- signature: $('#mail-account-signature').value,
- notificationsEnabled: $('#mail-account-notifications').checked,
- syncIntervalMinutes: Number($('#mail-account-sync-interval').value),
- rules: [...$('#mail-rule-list').querySelectorAll('.mail-rule-row')].map(row => ({
+ imapHost: selectMailUi('#mail-account-imap').value,
+ smtpHost: selectMailUi('#mail-account-smtp').value,
+ signature: selectMailUi('#mail-account-signature').value,
+ notificationsEnabled: selectMailUi('#mail-account-notifications').checked,
+ syncIntervalMinutes: Number(selectMailUi('#mail-account-sync-interval').value),
+ rules: [...selectMailUi('#mail-rule-list').querySelectorAll('.mail-rule-row')].map(row => ({
senderContains: row.querySelector('.mail-rule-sender').value,
subjectContains: row.querySelector('.mail-rule-subject').value,
action: row.querySelector('.mail-rule-action').value,
@@ -292,12 +296,12 @@ function openMailAccount(existingAccount = null) {
} else {
close();
}
- toast('Mailbox settings updated');
+ toastMailUi('Mailbox settings updated');
} else {
mailFeatureState.connectedAccount = account;
updateAccountCard(account);
close();
- toast('Mailbox connected securely');
+ toastMailUi('Mailbox connected securely');
await syncMailbox(true);
}
} catch (error) {
@@ -306,30 +310,30 @@ function openMailAccount(existingAccount = null) {
button.textContent = editing ? 'Save & reconnect' : 'Test & connect';
}
};
- $('#mail-account-email').focus();
+ selectMailUi('#mail-account-email').focus();
}
function mailSearchFilters() {
return {
- query: $('#search').value.trim(),
- sender: $('#filter-sender').value.trim(),
- subject: $('#filter-subject').value.trim(),
- after: $('#filter-after').value,
- before: $('#filter-before').value,
- hasAttachments: $('#filter-attachments').checked,
- folder: $('#filter-folder').value
+ query: selectMailUi('#search').value.trim(),
+ sender: selectMailUi('#filter-sender').value.trim(),
+ subject: selectMailUi('#filter-subject').value.trim(),
+ after: selectMailUi('#filter-after').value,
+ before: selectMailUi('#filter-before').value,
+ hasAttachments: selectMailUi('#filter-attachments').checked,
+ folder: selectMailUi('#filter-folder').value
};
}
async function deleteSelectedDrafts() {
const ids = rendererState.messages.map(message => String(message.id)).filter(id => mailFeatureState.selectedDraftIds.has(id));
- if (!ids.length) { toast('Select one or more drafts first'); return; }
+ if (!ids.length) { toastMailUi('Select one or more drafts first'); return; }
if (!confirm(`Delete ${ids.length} selected draft${ids.length === 1 ? '' : 's'}?`)) return;
try {
for (const id of ids) await window.daybreakMail.deleteDraft(id);
mailFeatureState.selectedDraftIds.clear();
- toast(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`);
+ toastMailUi(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`);
await syncMailbox(false);
- } catch (error) { toast(error.message || 'Could not delete the drafts'); }
+ } catch (error) { toastMailUi(error.message || 'Could not delete the drafts'); }
}
// In the Drafts folder the shared toolbar acts on drafts, which use string ids.
@@ -361,14 +365,14 @@ function renderDrafts(drafts) {
color: '#dce6df',
draft
})));
- $('#message-list').innerHTML = rendererState.messages.length ? rendererState.messages.map(message => `
-
OpenPGP keys are protected by a passphrase and stored encrypted by your operating system. Back up your private key and revocation certificate: without them, encrypted mail cannot be recovered. Contact keys below are used to encrypt mail to your correspondents and to check signatures.
@@ -18,7 +23,7 @@ function openEncryptionKeys() {
Public key servers
Servers are disabled by default. Enable the servers you want to use; searching checks every enabled server, which can learn which email address you searched for. Discovered keys remain unverified until you check their fingerprints independently.
Loading key servers…
-
+
@@ -33,8 +38,8 @@ function openEncryptionKeys() {
Unlocked passphrases are kept in memory only, for this many minutes (0 asks every time). Opening encrypted attachments needs the passphrase to be remembered.
Create a key
-
-
+
+
@@ -42,13 +47,13 @@ function openEncryptionKeys() {
const close = () => { root.innerHTML = ''; };
root.querySelector('.modal-close').onclick = close;
root.querySelector('.modal-overlay').onclick = event => { if (event.target.classList.contains('modal-overlay')) close(); };
- const status = message => { $('#pgp-status').textContent = message; };
- const passphraseField = () => $('#pgp-passphrase');
+ const status = message => { selectPgpKeyUi('#pgp-status').textContent = message; };
+ const passphraseField = () => selectPgpKeyUi('#pgp-passphrase');
let keyServers = [];
- const selectedPublishServer = () => keyServers.find(server => server.id === $('#pgp-publish-server').value && server.enabled);
+ const selectedPublishServer = () => keyServers.find(server => server.id === selectPgpKeyUi('#pgp-publish-server').value && server.enabled);
const updatePublishButtons = () => {
const server = selectedPublishServer();
- $$('.pgp-publish').forEach(button => {
+ selectAllPgpKeyUi('.pgp-publish').forEach(button => {
button.disabled = !server;
button.textContent = server ? `Publish to ${server.name}…` : 'Enable a server to publish…';
});
@@ -60,7 +65,7 @@ function openEncryptionKeys() {
};
async function render() {
- const list = $('#pgp-key-list');
+ const list = selectPgpKeyUi('#pgp-key-list');
let keys = [];
try { keys = await window.daybreakMail.pgp.list(); } catch (error) { list.textContent = error.message || 'Could not load keys.'; return; }
list.replaceChildren();
@@ -86,21 +91,21 @@ function openEncryptionKeys() {
changePassphrase.className = 'discard';
changePassphrase.textContent = 'Change passphrase…';
changePassphrase.onclick = async () => {
- const currentPassphrase = $('#pgp-change-current-passphrase').value;
+ const currentPassphrase = selectPgpKeyUi('#pgp-change-current-passphrase').value;
if (!currentPassphrase) {
status('Enter the current passphrase for this key.');
- $('#pgp-change-current-passphrase').focus();
+ selectPgpKeyUi('#pgp-change-current-passphrase').focus();
return;
}
- const newPassphrase = $('#pgp-new-passphrase').value;
+ const newPassphrase = selectPgpKeyUi('#pgp-new-passphrase').value;
if (newPassphrase.length < 8) {
status('Use a new passphrase of at least 8 characters.');
- $('#pgp-new-passphrase').focus();
+ selectPgpKeyUi('#pgp-new-passphrase').focus();
return;
}
- if (newPassphrase !== $('#pgp-confirm-passphrase').value) {
+ if (newPassphrase !== selectPgpKeyUi('#pgp-confirm-passphrase').value) {
status('The new passphrases do not match.');
- $('#pgp-confirm-passphrase').focus();
+ selectPgpKeyUi('#pgp-confirm-passphrase').focus();
return;
}
changePassphrase.disabled = true;
@@ -110,12 +115,12 @@ function openEncryptionKeys() {
currentPassphrase,
newPassphrase
});
- $('#pgp-change-current-passphrase').value = '';
+ selectPgpKeyUi('#pgp-change-current-passphrase').value = '';
status(`Passphrase changed for ${key.email || key.fingerprint}.`);
} catch (error) { status(error.message || 'Could not change the key passphrase.'); }
finally {
- $('#pgp-new-passphrase').value = '';
- $('#pgp-confirm-passphrase').value = '';
+ selectPgpKeyUi('#pgp-new-passphrase').value = '';
+ selectPgpKeyUi('#pgp-confirm-passphrase').value = '';
changePassphrase.disabled = false;
}
};
@@ -164,20 +169,20 @@ function openEncryptionKeys() {
updatePublishButtons();
}
- $('#pgp-generate').onclick = async () => {
- const button = $('#pgp-generate');
+ selectPgpKeyUi('#pgp-generate').onclick = async () => {
+ const button = selectPgpKeyUi('#pgp-generate');
button.disabled = true;
status('Creating key…');
try {
await window.daybreakMail.pgp.generate({
- name: $('#pgp-name').value, email: $('#pgp-email').value, passphrase: passphraseField().value, accountId: account.id || null
+ name: selectPgpKeyUi('#pgp-name').value, email: selectPgpKeyUi('#pgp-email').value, passphrase: passphraseField().value, accountId: account.id || null
});
status('Key created. Export your private key and revocation certificate now and keep them safe.');
await render();
} catch (error) { status(error.message || 'Could not create the key.'); }
button.disabled = false;
};
- $('#pgp-import').onclick = async () => {
+ selectPgpKeyUi('#pgp-import').onclick = async () => {
const passphrase = needPassphrase();
if (!passphrase) return;
try {
@@ -187,7 +192,7 @@ function openEncryptionKeys() {
} catch (error) { status(error.message || 'Could not import the key.'); }
};
async function renderContacts() {
- const list = $('#pgp-contact-list');
+ const list = selectPgpKeyUi('#pgp-contact-list');
let contacts = [];
try { contacts = await window.daybreakMail.pgp.contacts(); } catch (error) { list.textContent = error.message || 'Could not load contacts.'; return; }
list.replaceChildren();
@@ -244,7 +249,7 @@ function openEncryptionKeys() {
});
}
- $('#pgp-add-contact').onclick = async () => {
+ selectPgpKeyUi('#pgp-add-contact').onclick = async () => {
try {
const result = await window.daybreakMail.pgp.addContact({});
if (!result.canceled) status(result.keyChangedFrom?.length ? 'Key added. Warning: you already had a different key for this address. Verify the new fingerprint.' : 'Public key added. Verify its fingerprint with the owner, then mark it as verified.');
@@ -252,8 +257,8 @@ function openEncryptionKeys() {
} catch (error) { status(error.message || 'Could not import the key.'); }
};
async function renderKeyServers() {
- const list = $('#pgp-server-list');
- const selector = $('#pgp-publish-server');
+ const list = selectPgpKeyUi('#pgp-server-list');
+ const selector = selectPgpKeyUi('#pgp-publish-server');
const selectedId = selector.value;
try { keyServers = await window.daybreakMail.pgp.keyServers(); }
catch (error) { list.textContent = error.message || 'Could not load key servers.'; return; }
@@ -321,14 +326,14 @@ function openEncryptionKeys() {
list.append(row);
});
}
- $('#pgp-find-key').onclick = async () => {
- const button = $('#pgp-find-key');
- const results = $('#pgp-found-keys');
+ selectPgpKeyUi('#pgp-find-key').onclick = async () => {
+ const button = selectPgpKeyUi('#pgp-find-key');
+ const results = selectPgpKeyUi('#pgp-found-keys');
button.disabled = true;
results.textContent = 'Searching…';
try {
const found = await window.daybreakMail.pgp.findKey({
- email: $('#pgp-search-email').value
+ email: selectPgpKeyUi('#pgp-search-email').value
});
results.replaceChildren();
found.keys.forEach(key => {
@@ -374,39 +379,37 @@ function openEncryptionKeys() {
status(error.message || 'Could not search the key server.');
} finally { button.disabled = false; }
};
- $('#pgp-add-server').onclick = async () => {
- const button = $('#pgp-add-server');
+ selectPgpKeyUi('#pgp-add-server').onclick = async () => {
+ const button = selectPgpKeyUi('#pgp-add-server');
button.disabled = true;
try {
const result = await window.daybreakMail.pgp.addKeyServer({
- name: $('#pgp-server-name').value,
- url: $('#pgp-server-url').value,
- protocol: $('#pgp-server-protocol').value
+ name: selectPgpKeyUi('#pgp-server-name').value,
+ url: selectPgpKeyUi('#pgp-server-url').value,
+ protocol: selectPgpKeyUi('#pgp-server-protocol').value
});
if (result.canceled) return;
- $('#pgp-server-name').value = '';
- $('#pgp-server-url').value = '';
+ selectPgpKeyUi('#pgp-server-name').value = '';
+ selectPgpKeyUi('#pgp-server-url').value = '';
await renderKeyServers();
status('Custom key server added.');
} catch (error) { status(error.message || 'Could not add the key server.'); }
finally { button.disabled = false; }
};
- window.daybreakMail.pgp.getSettings().then(settings => { $('#pgp-cache-minutes').value = settings.cacheMinutes; }).catch(() => {});
- $('#pgp-save-cache').onclick = async () => {
- try { const settings = await window.daybreakMail.pgp.setSettings({ cacheMinutes: Number($('#pgp-cache-minutes').value) }); status(`Passphrases are remembered for ${settings.cacheMinutes} minute(s).`); }
+ window.daybreakMail.pgp.getSettings().then(settings => { selectPgpKeyUi('#pgp-cache-minutes').value = settings.cacheMinutes; }).catch(() => {});
+ selectPgpKeyUi('#pgp-save-cache').onclick = async () => {
+ try { const settings = await window.daybreakMail.pgp.setSettings({ cacheMinutes: Number(selectPgpKeyUi('#pgp-cache-minutes').value) }); status(`Passphrases are remembered for ${settings.cacheMinutes} minute(s).`); }
catch (error) { status(error.message || 'Could not save the setting.'); }
};
- $('#pgp-forget').onclick = async () => { await window.daybreakMail.pgp.forgetPassphrases(); status('Remembered passphrases were cleared.'); };
+ selectPgpKeyUi('#pgp-forget').onclick = async () => { await window.daybreakMail.pgp.forgetPassphrases(); status('Remembered passphrases were cleared.'); };
void renderKeyServers();
void renderContacts();
void render();
}
-if (typeof openPreferences === 'function') {
- const baseOpenPreferences = openPreferences;
- openPreferences = function () {
+window.epMailFeatures.productivity.wrapOpenPreferences(baseOpenPreferences => function () {
baseOpenPreferences();
- const fields = $('#modal-root .compose-fields');
+ const fields = selectPgpKeyUi('#modal-root .compose-fields');
if (!fields || !pgpAvailable()) return;
const button = document.createElement('button');
button.type = 'button';
@@ -415,5 +418,4 @@ if (typeof openPreferences === 'function') {
button.textContent = 'Encryption keys…';
button.onclick = openEncryptionKeys;
fields.append(button);
- };
-}
+ });
diff --git a/tests/renderer-mail-api.test.cjs b/tests/renderer-mail-api.test.cjs
index be192e5..9d01450 100644
--- a/tests/renderer-mail-api.test.cjs
+++ b/tests/renderer-mail-api.test.cjs
@@ -63,6 +63,8 @@ test('account and snooze UI consume the explicit mail API instead of selected le
const attachmentUi = fs.readFileSync(path.join(root, 'attachments.js'), 'utf8');
const pgpMailUi = fs.readFileSync(path.join(root, 'pgp-mail-ui.js'), 'utf8');
const pgpUi = fs.readFileSync(path.join(root, 'pgp-ui.js'), 'utf8');
+ const appShell = fs.readFileSync(path.join(root, 'app.js'), 'utf8');
+ const mailUi = fs.readFileSync(path.join(root, 'mail-ui.js'), 'utf8');
const shortcutsUi = fs.readFileSync(path.join(root, 'shortcuts.js'), 'utf8');
const productivityUi = fs.readFileSync(path.join(root, 'productivity.js'), 'utf8');
assert.match(accountUi, /window\.epMailFeatures\.mail/);
@@ -70,6 +72,10 @@ test('account and snooze UI consume the explicit mail API instead of selected le
assert.match(attachmentUi, /window\.epMailFeatures\.mail/);
assert.match(pgpMailUi, /window\.epMailFeatures\.mail/);
assert.match(pgpUi, /window\.epMailFeatures\.mail\.connectedAccount/);
+ assert.match(appShell, /window\.epMailShell = Object\.freeze/);
+ assert.match(mailUi, /appShell\.wrapOpenMessage/);
+ assert.match(mailUi, /appShell\.wrapShowCompose/);
+ assert.doesNotMatch(mailUi, /(?
${reply?(forward?'Forward message':'Reply to message'):'New message'}
Your password is encrypted with this computer's credential storage. Connections require TLS.
MAIL RULES
Rules match the sender or subject of incoming mail. The first matching rule runs.
${ruleMarkup}
Signatures are appended to outgoing messages. Sync interval controls periodic checks when IMAP IDLE is unavailable; Android may apply its 15-minute minimum background interval.${editing ? ' Leave the password empty to keep the saved password.' : ''}
`;
+ root.innerHTML = `
${editing ? 'Edit mailbox' : 'Add a mailbox'}
Your password is encrypted with this computer's credential storage. Connections require TLS.
MAIL RULES
Rules match the sender or subject of incoming mail. The first matching rule runs.
${ruleMarkup}
Signatures are appended to outgoing messages. Sync interval controls periodic checks when IMAP IDLE is unavailable; Android may apply its 15-minute minimum background interval.${editing ? ' Leave the password empty to keep the saved password.' : ''}
`;
const close = () => { root.innerHTML = ''; };
- $$('.modal-close').forEach(button => button.onclick = close);
- $('.modal-overlay').addEventListener('click', event => { if (event.target.classList.contains('modal-overlay')) close(); });
- $('#disconnect-mail').onclick = close;
+ selectAllMailUi('.modal-close').forEach(button => button.onclick = close);
+ selectMailUi('.modal-overlay').addEventListener('click', event => { if (event.target.classList.contains('modal-overlay')) close(); });
+ selectMailUi('#disconnect-mail').onclick = close;
const addRuleRow = rule => {
const row = document.createElement('div');
row.className = 'mail-rule-row';
- row.innerHTML = ``;
+ row.innerHTML = ``;
row.querySelector('.mail-rule-action').value = rule?.action || 'archive';
- $('#mail-rule-list').append(row);
+ selectMailUi('#mail-rule-list').append(row);
};
- $('#add-mail-rule').onclick = () => addRuleRow();
- $('#mail-rule-list').onclick = event => {
+ selectMailUi('#add-mail-rule').onclick = () => addRuleRow();
+ selectMailUi('#mail-rule-list').onclick = event => {
if (event.target.closest('.remove-mail-rule')) event.target.closest('.mail-rule-row').remove();
};
- $('#mail-rule-list').onchange = event => {
+ selectMailUi('#mail-rule-list').onchange = event => {
if (!event.target.matches('.mail-rule-action')) return;
const row = event.target.closest('.mail-rule-row');
const value = row.querySelector('.mail-rule-value');
@@ -251,27 +255,27 @@ function openMailAccount(existingAccount = null) {
}
row.querySelector('.mail-rule-value').disabled = event.target.value === 'flag';
};
- $('#connect-mail').onclick = async () => {
- const button = $('#connect-mail');
- const status = $('#mail-account-status');
- const password = $('#mail-account-password').value;
- const name = $('#mail-account-display-name').value.trim();
- if (!name) { status.textContent = 'Enter a display name for this mail account.'; $('#mail-account-display-name').focus(); return; }
- if (!editing && !password) { status.textContent = 'Enter the mailbox password to connect.'; $('#mail-account-password').focus(); return; }
+ selectMailUi('#connect-mail').onclick = async () => {
+ const button = selectMailUi('#connect-mail');
+ const status = selectMailUi('#mail-account-status');
+ const password = selectMailUi('#mail-account-password').value;
+ const name = selectMailUi('#mail-account-display-name').value.trim();
+ if (!name) { status.textContent = 'Enter a display name for this mail account.'; selectMailUi('#mail-account-display-name').focus(); return; }
+ if (!editing && !password) { status.textContent = 'Enter the mailbox password to connect.'; selectMailUi('#mail-account-password').focus(); return; }
button.disabled = true;
button.textContent = editing ? 'Checking updated settings…' : 'Checking secure connections…';
status.textContent = editing ? 'Testing the updated mailbox settings before saving.' : 'Checking IMAP and SMTP sign-in. This may take a moment.';
try {
const details = {
- email: $('#mail-account-email').value,
+ email: selectMailUi('#mail-account-email').value,
password,
displayName: name,
- imapHost: $('#mail-account-imap').value,
- smtpHost: $('#mail-account-smtp').value,
- signature: $('#mail-account-signature').value,
- notificationsEnabled: $('#mail-account-notifications').checked,
- syncIntervalMinutes: Number($('#mail-account-sync-interval').value),
- rules: [...$('#mail-rule-list').querySelectorAll('.mail-rule-row')].map(row => ({
+ imapHost: selectMailUi('#mail-account-imap').value,
+ smtpHost: selectMailUi('#mail-account-smtp').value,
+ signature: selectMailUi('#mail-account-signature').value,
+ notificationsEnabled: selectMailUi('#mail-account-notifications').checked,
+ syncIntervalMinutes: Number(selectMailUi('#mail-account-sync-interval').value),
+ rules: [...selectMailUi('#mail-rule-list').querySelectorAll('.mail-rule-row')].map(row => ({
senderContains: row.querySelector('.mail-rule-sender').value,
subjectContains: row.querySelector('.mail-rule-subject').value,
action: row.querySelector('.mail-rule-action').value,
@@ -292,12 +296,12 @@ function openMailAccount(existingAccount = null) {
} else {
close();
}
- toast('Mailbox settings updated');
+ toastMailUi('Mailbox settings updated');
} else {
mailFeatureState.connectedAccount = account;
updateAccountCard(account);
close();
- toast('Mailbox connected securely');
+ toastMailUi('Mailbox connected securely');
await syncMailbox(true);
}
} catch (error) {
@@ -306,30 +310,30 @@ function openMailAccount(existingAccount = null) {
button.textContent = editing ? 'Save & reconnect' : 'Test & connect';
}
};
- $('#mail-account-email').focus();
+ selectMailUi('#mail-account-email').focus();
}
function mailSearchFilters() {
return {
- query: $('#search').value.trim(),
- sender: $('#filter-sender').value.trim(),
- subject: $('#filter-subject').value.trim(),
- after: $('#filter-after').value,
- before: $('#filter-before').value,
- hasAttachments: $('#filter-attachments').checked,
- folder: $('#filter-folder').value
+ query: selectMailUi('#search').value.trim(),
+ sender: selectMailUi('#filter-sender').value.trim(),
+ subject: selectMailUi('#filter-subject').value.trim(),
+ after: selectMailUi('#filter-after').value,
+ before: selectMailUi('#filter-before').value,
+ hasAttachments: selectMailUi('#filter-attachments').checked,
+ folder: selectMailUi('#filter-folder').value
};
}
async function deleteSelectedDrafts() {
const ids = rendererState.messages.map(message => String(message.id)).filter(id => mailFeatureState.selectedDraftIds.has(id));
- if (!ids.length) { toast('Select one or more drafts first'); return; }
+ if (!ids.length) { toastMailUi('Select one or more drafts first'); return; }
if (!confirm(`Delete ${ids.length} selected draft${ids.length === 1 ? '' : 's'}?`)) return;
try {
for (const id of ids) await window.daybreakMail.deleteDraft(id);
mailFeatureState.selectedDraftIds.clear();
- toast(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`);
+ toastMailUi(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`);
await syncMailbox(false);
- } catch (error) { toast(error.message || 'Could not delete the drafts'); }
+ } catch (error) { toastMailUi(error.message || 'Could not delete the drafts'); }
}
// In the Drafts folder the shared toolbar acts on drafts, which use string ids.
@@ -361,14 +365,14 @@ function renderDrafts(drafts) {
color: '#dce6df',
draft
})));
- $('#message-list').innerHTML = rendererState.messages.length ? rendererState.messages.map(message => `
-
OpenPGP keys are protected by a passphrase and stored encrypted by your operating system. Back up your private key and revocation certificate: without them, encrypted mail cannot be recovered. Contact keys below are used to encrypt mail to your correspondents and to check signatures.
@@ -18,7 +23,7 @@ function openEncryptionKeys() {
Public key servers
Servers are disabled by default. Enable the servers you want to use; searching checks every enabled server, which can learn which email address you searched for. Discovered keys remain unverified until you check their fingerprints independently.
Loading key servers…
-
+
@@ -33,8 +38,8 @@ function openEncryptionKeys() {
Unlocked passphrases are kept in memory only, for this many minutes (0 asks every time). Opening encrypted attachments needs the passphrase to be remembered.
Create a key
-
-
+
+
@@ -42,13 +47,13 @@ function openEncryptionKeys() {
const close = () => { root.innerHTML = ''; };
root.querySelector('.modal-close').onclick = close;
root.querySelector('.modal-overlay').onclick = event => { if (event.target.classList.contains('modal-overlay')) close(); };
- const status = message => { $('#pgp-status').textContent = message; };
- const passphraseField = () => $('#pgp-passphrase');
+ const status = message => { selectPgpKeyUi('#pgp-status').textContent = message; };
+ const passphraseField = () => selectPgpKeyUi('#pgp-passphrase');
let keyServers = [];
- const selectedPublishServer = () => keyServers.find(server => server.id === $('#pgp-publish-server').value && server.enabled);
+ const selectedPublishServer = () => keyServers.find(server => server.id === selectPgpKeyUi('#pgp-publish-server').value && server.enabled);
const updatePublishButtons = () => {
const server = selectedPublishServer();
- $$('.pgp-publish').forEach(button => {
+ selectAllPgpKeyUi('.pgp-publish').forEach(button => {
button.disabled = !server;
button.textContent = server ? `Publish to ${server.name}…` : 'Enable a server to publish…';
});
@@ -60,7 +65,7 @@ function openEncryptionKeys() {
};
async function render() {
- const list = $('#pgp-key-list');
+ const list = selectPgpKeyUi('#pgp-key-list');
let keys = [];
try { keys = await window.daybreakMail.pgp.list(); } catch (error) { list.textContent = error.message || 'Could not load keys.'; return; }
list.replaceChildren();
@@ -86,21 +91,21 @@ function openEncryptionKeys() {
changePassphrase.className = 'discard';
changePassphrase.textContent = 'Change passphrase…';
changePassphrase.onclick = async () => {
- const currentPassphrase = $('#pgp-change-current-passphrase').value;
+ const currentPassphrase = selectPgpKeyUi('#pgp-change-current-passphrase').value;
if (!currentPassphrase) {
status('Enter the current passphrase for this key.');
- $('#pgp-change-current-passphrase').focus();
+ selectPgpKeyUi('#pgp-change-current-passphrase').focus();
return;
}
- const newPassphrase = $('#pgp-new-passphrase').value;
+ const newPassphrase = selectPgpKeyUi('#pgp-new-passphrase').value;
if (newPassphrase.length < 8) {
status('Use a new passphrase of at least 8 characters.');
- $('#pgp-new-passphrase').focus();
+ selectPgpKeyUi('#pgp-new-passphrase').focus();
return;
}
- if (newPassphrase !== $('#pgp-confirm-passphrase').value) {
+ if (newPassphrase !== selectPgpKeyUi('#pgp-confirm-passphrase').value) {
status('The new passphrases do not match.');
- $('#pgp-confirm-passphrase').focus();
+ selectPgpKeyUi('#pgp-confirm-passphrase').focus();
return;
}
changePassphrase.disabled = true;
@@ -110,12 +115,12 @@ function openEncryptionKeys() {
currentPassphrase,
newPassphrase
});
- $('#pgp-change-current-passphrase').value = '';
+ selectPgpKeyUi('#pgp-change-current-passphrase').value = '';
status(`Passphrase changed for ${key.email || key.fingerprint}.`);
} catch (error) { status(error.message || 'Could not change the key passphrase.'); }
finally {
- $('#pgp-new-passphrase').value = '';
- $('#pgp-confirm-passphrase').value = '';
+ selectPgpKeyUi('#pgp-new-passphrase').value = '';
+ selectPgpKeyUi('#pgp-confirm-passphrase').value = '';
changePassphrase.disabled = false;
}
};
@@ -164,20 +169,20 @@ function openEncryptionKeys() {
updatePublishButtons();
}
- $('#pgp-generate').onclick = async () => {
- const button = $('#pgp-generate');
+ selectPgpKeyUi('#pgp-generate').onclick = async () => {
+ const button = selectPgpKeyUi('#pgp-generate');
button.disabled = true;
status('Creating key…');
try {
await window.daybreakMail.pgp.generate({
- name: $('#pgp-name').value, email: $('#pgp-email').value, passphrase: passphraseField().value, accountId: account.id || null
+ name: selectPgpKeyUi('#pgp-name').value, email: selectPgpKeyUi('#pgp-email').value, passphrase: passphraseField().value, accountId: account.id || null
});
status('Key created. Export your private key and revocation certificate now and keep them safe.');
await render();
} catch (error) { status(error.message || 'Could not create the key.'); }
button.disabled = false;
};
- $('#pgp-import').onclick = async () => {
+ selectPgpKeyUi('#pgp-import').onclick = async () => {
const passphrase = needPassphrase();
if (!passphrase) return;
try {
@@ -187,7 +192,7 @@ function openEncryptionKeys() {
} catch (error) { status(error.message || 'Could not import the key.'); }
};
async function renderContacts() {
- const list = $('#pgp-contact-list');
+ const list = selectPgpKeyUi('#pgp-contact-list');
let contacts = [];
try { contacts = await window.daybreakMail.pgp.contacts(); } catch (error) { list.textContent = error.message || 'Could not load contacts.'; return; }
list.replaceChildren();
@@ -244,7 +249,7 @@ function openEncryptionKeys() {
});
}
- $('#pgp-add-contact').onclick = async () => {
+ selectPgpKeyUi('#pgp-add-contact').onclick = async () => {
try {
const result = await window.daybreakMail.pgp.addContact({});
if (!result.canceled) status(result.keyChangedFrom?.length ? 'Key added. Warning: you already had a different key for this address. Verify the new fingerprint.' : 'Public key added. Verify its fingerprint with the owner, then mark it as verified.');
@@ -252,8 +257,8 @@ function openEncryptionKeys() {
} catch (error) { status(error.message || 'Could not import the key.'); }
};
async function renderKeyServers() {
- const list = $('#pgp-server-list');
- const selector = $('#pgp-publish-server');
+ const list = selectPgpKeyUi('#pgp-server-list');
+ const selector = selectPgpKeyUi('#pgp-publish-server');
const selectedId = selector.value;
try { keyServers = await window.daybreakMail.pgp.keyServers(); }
catch (error) { list.textContent = error.message || 'Could not load key servers.'; return; }
@@ -321,14 +326,14 @@ function openEncryptionKeys() {
list.append(row);
});
}
- $('#pgp-find-key').onclick = async () => {
- const button = $('#pgp-find-key');
- const results = $('#pgp-found-keys');
+ selectPgpKeyUi('#pgp-find-key').onclick = async () => {
+ const button = selectPgpKeyUi('#pgp-find-key');
+ const results = selectPgpKeyUi('#pgp-found-keys');
button.disabled = true;
results.textContent = 'Searching…';
try {
const found = await window.daybreakMail.pgp.findKey({
- email: $('#pgp-search-email').value
+ email: selectPgpKeyUi('#pgp-search-email').value
});
results.replaceChildren();
found.keys.forEach(key => {
@@ -374,39 +379,37 @@ function openEncryptionKeys() {
status(error.message || 'Could not search the key server.');
} finally { button.disabled = false; }
};
- $('#pgp-add-server').onclick = async () => {
- const button = $('#pgp-add-server');
+ selectPgpKeyUi('#pgp-add-server').onclick = async () => {
+ const button = selectPgpKeyUi('#pgp-add-server');
button.disabled = true;
try {
const result = await window.daybreakMail.pgp.addKeyServer({
- name: $('#pgp-server-name').value,
- url: $('#pgp-server-url').value,
- protocol: $('#pgp-server-protocol').value
+ name: selectPgpKeyUi('#pgp-server-name').value,
+ url: selectPgpKeyUi('#pgp-server-url').value,
+ protocol: selectPgpKeyUi('#pgp-server-protocol').value
});
if (result.canceled) return;
- $('#pgp-server-name').value = '';
- $('#pgp-server-url').value = '';
+ selectPgpKeyUi('#pgp-server-name').value = '';
+ selectPgpKeyUi('#pgp-server-url').value = '';
await renderKeyServers();
status('Custom key server added.');
} catch (error) { status(error.message || 'Could not add the key server.'); }
finally { button.disabled = false; }
};
- window.daybreakMail.pgp.getSettings().then(settings => { $('#pgp-cache-minutes').value = settings.cacheMinutes; }).catch(() => {});
- $('#pgp-save-cache').onclick = async () => {
- try { const settings = await window.daybreakMail.pgp.setSettings({ cacheMinutes: Number($('#pgp-cache-minutes').value) }); status(`Passphrases are remembered for ${settings.cacheMinutes} minute(s).`); }
+ window.daybreakMail.pgp.getSettings().then(settings => { selectPgpKeyUi('#pgp-cache-minutes').value = settings.cacheMinutes; }).catch(() => {});
+ selectPgpKeyUi('#pgp-save-cache').onclick = async () => {
+ try { const settings = await window.daybreakMail.pgp.setSettings({ cacheMinutes: Number(selectPgpKeyUi('#pgp-cache-minutes').value) }); status(`Passphrases are remembered for ${settings.cacheMinutes} minute(s).`); }
catch (error) { status(error.message || 'Could not save the setting.'); }
};
- $('#pgp-forget').onclick = async () => { await window.daybreakMail.pgp.forgetPassphrases(); status('Remembered passphrases were cleared.'); };
+ selectPgpKeyUi('#pgp-forget').onclick = async () => { await window.daybreakMail.pgp.forgetPassphrases(); status('Remembered passphrases were cleared.'); };
void renderKeyServers();
void renderContacts();
void render();
}
-if (typeof openPreferences === 'function') {
- const baseOpenPreferences = openPreferences;
- openPreferences = function () {
+window.epMailFeatures.productivity.wrapOpenPreferences(baseOpenPreferences => function () {
baseOpenPreferences();
- const fields = $('#modal-root .compose-fields');
+ const fields = selectPgpKeyUi('#modal-root .compose-fields');
if (!fields || !pgpAvailable()) return;
const button = document.createElement('button');
button.type = 'button';
@@ -415,5 +418,4 @@ if (typeof openPreferences === 'function') {
button.textContent = 'Encryption keys…';
button.onclick = openEncryptionKeys;
fields.append(button);
- };
-}
+ });