Refractoring Stage 6.9 Moved the OpenPGP key UI’s active-account lookup to the mail feature API. The renderer now uses explicit APIs for account, snooze, attachment, OpenPGP mail/key, shortcuts, and DAV integrations; remaining transitional globals are mainly in the core shell and cross-feature hooks.
This commit is contained in:
+4
-3
@@ -108,6 +108,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC
|
|||||||
- [x] Migrate OpenPGP mail UI reader/compose hooks to the mail feature API (`pgp-mail-ui.js`).
|
- [x] Migrate OpenPGP mail UI reader/compose hooks to the mail feature API (`pgp-mail-ui.js`).
|
||||||
- [x] Migrate shortcut mail-state access and preferences extension to feature APIs (`shortcuts.js`, `productivity.js`).
|
- [x] Migrate shortcut mail-state access and preferences extension to feature APIs (`shortcuts.js`, `productivity.js`).
|
||||||
- [x] Migrate Calendar/Contacts navigation and DAV UI to the productivity feature API (`app.js`, `dav-ui.js`).
|
- [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] Make the core app shell consume the namespaced renderer state instead of compatibility aliases.
|
||||||
- [x] Migrate additional mail-related consumers to unique local aliases to avoid classic-script lexical redeclarations.
|
- [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.
|
- [x] Add a combined-script parse test to prevent duplicate top-level lexical declarations from stopping later UI scripts.
|
||||||
@@ -137,7 +138,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`.
|
- 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.
|
- 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.
|
- `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.19`; Android derives `versionName 0.4.19` and `versionCode 419`. `release/` contains the user-verified Windows artifact `0.4.19`.
|
- 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.
|
||||||
|
|
||||||
## Progress log
|
## Progress log
|
||||||
|
|
||||||
@@ -156,9 +157,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 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 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.
|
- 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.19`, with Android build number `419`; the user-verified artifact is `0.4.18`.
|
- Added a build-version consistency check. Package/lockfile are `0.4.21`, with Android build number `421`; the user confirms the current artifact works.
|
||||||
- Step 5 grouped mail/account handlers and added a release-version consistency test; current package/lockfile/Android version alignment was checked and documented.
|
- 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 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, 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 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.
|
||||||
- The current IPC/DAV validation changes pass the full suite: 108 tests.
|
- 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.
|
- While work continued, `package.json` and `package-lock.json` reflected a version bump to `0.4.6`; those changes were preserved.
|
||||||
|
|||||||
+108
-107
@@ -1,10 +1,15 @@
|
|||||||
let connectedMailAccount = null;
|
const rendererState = window.epMailState;
|
||||||
let mailPageOffset = 0;
|
const mailFeatureState = {
|
||||||
let mailTotal = 0;
|
connectedAccount: null,
|
||||||
let mailboxSyncPromise = null;
|
pageOffset: 0,
|
||||||
let mailboxSyncQueued = false;
|
total: 0,
|
||||||
let mailboxRefreshPending = false;
|
syncPromise: null,
|
||||||
let folderBeforeSearch = null;
|
syncQueued: false,
|
||||||
|
refreshPending: false,
|
||||||
|
folderBeforeSearch: null,
|
||||||
|
customFolders: [],
|
||||||
|
selectedDraftIds: new Set()
|
||||||
|
};
|
||||||
|
|
||||||
const senderBrandDomains = {
|
const senderBrandDomains = {
|
||||||
amazon: ['amazon.com', 'amazon.co.uk'],
|
amazon: ['amazon.com', 'amazon.co.uk'],
|
||||||
@@ -65,7 +70,7 @@ function messageLinks(message) {
|
|||||||
const originalOpenMessage = openMessage;
|
const originalOpenMessage = openMessage;
|
||||||
openMessage = function (id) {
|
openMessage = function (id) {
|
||||||
originalOpenMessage(id);
|
originalOpenMessage(id);
|
||||||
const message = messages.find(item => item.id === id);
|
const message = rendererState.messages.find(item => item.id === id);
|
||||||
if (!message) return;
|
if (!message) return;
|
||||||
const senderReasons = suspiciousSenderReasons(message);
|
const senderReasons = suspiciousSenderReasons(message);
|
||||||
const links = messageLinks(message);
|
const links = messageLinks(message);
|
||||||
@@ -102,16 +107,14 @@ openMessage = function (id) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let customFolders = [];
|
|
||||||
|
|
||||||
function renderCustomFolders() {
|
function renderCustomFolders() {
|
||||||
const box = $('#custom-folders');
|
const box = $('#custom-folders');
|
||||||
if (!box) return;
|
if (!box) return;
|
||||||
box.replaceChildren(...customFolders.map(folder => {
|
box.replaceChildren(...mailFeatureState.customFolders.map(folder => {
|
||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
button.className = 'folder custom-folder';
|
button.className = 'folder custom-folder';
|
||||||
button.dataset.folder = folder.id;
|
button.dataset.folder = folder.id;
|
||||||
button.classList.toggle('active', activeFolder === folder.id);
|
button.classList.toggle('active', rendererState.activeFolder === folder.id);
|
||||||
const glyph = document.createElement('span');
|
const glyph = document.createElement('span');
|
||||||
glyph.className = 'nav-glyph';
|
glyph.className = 'nav-glyph';
|
||||||
glyph.textContent = '▭';
|
glyph.textContent = '▭';
|
||||||
@@ -120,12 +123,12 @@ function renderCustomFolders() {
|
|||||||
button.title = folder.path;
|
button.title = folder.path;
|
||||||
button.append(glyph, label);
|
button.append(glyph, label);
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
if ($('#filter-folder').value) { $('#filter-folder').value = ''; folderBeforeSearch = null; }
|
if ($('#filter-folder').value) { $('#filter-folder').value = ''; mailFeatureState.folderBeforeSearch = null; }
|
||||||
activeFolder = folder.id;
|
rendererState.activeFolder = folder.id;
|
||||||
$$('.folder').forEach(item => item.classList.toggle('active', item === button));
|
$$('.folder').forEach(item => item.classList.toggle('active', item === button));
|
||||||
$('#sidebar-title').textContent = folder.name;
|
$('#sidebar-title').textContent = folder.name;
|
||||||
$('#crumb-current').textContent = folder.name;
|
$('#crumb-current').textContent = folder.name;
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
void syncMailbox(false, { offset: 0 });
|
void syncMailbox(false, { offset: 0 });
|
||||||
});
|
});
|
||||||
return button;
|
return button;
|
||||||
@@ -133,16 +136,16 @@ function renderCustomFolders() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadCustomFolders() {
|
async function loadCustomFolders() {
|
||||||
if (!connectedMailAccount || !window.daybreakMail?.listFolders) return;
|
if (!mailFeatureState.connectedAccount || !window.daybreakMail?.listFolders) return;
|
||||||
try {
|
try {
|
||||||
customFolders = (await window.daybreakMail.listFolders()).folders || [];
|
mailFeatureState.customFolders = (await window.daybreakMail.listFolders()).folders || [];
|
||||||
renderCustomFolders();
|
renderCustomFolders();
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destination options for the mail-rule folder picker: built-in folders plus the account's IMAP folders.
|
// Destination options for the mail-rule folder picker: built-in folders plus the account's IMAP folders.
|
||||||
function ruleFolderSelect(selected = 'Inbox') {
|
function ruleFolderSelect(selected = 'Inbox') {
|
||||||
const options = [['Inbox', 'Inbox'], ['Archive', 'Archive'], ['Trash', 'Trash'], ...customFolders.map(folder => [folder.id, folder.name])];
|
const options = [['Inbox', 'Inbox'], ['Archive', 'Archive'], ['Trash', 'Trash'], ...mailFeatureState.customFolders.map(folder => [folder.id, folder.name])];
|
||||||
if (!options.some(([value]) => value === selected)) {
|
if (!options.some(([value]) => value === selected)) {
|
||||||
options.push([selected, String(selected).replace(/^[^:]*:/, '') || selected]);
|
options.push([selected, String(selected).replace(/^[^:]*:/, '') || selected]);
|
||||||
}
|
}
|
||||||
@@ -170,12 +173,12 @@ function askText(title, label, placeholder = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createMailFolder() {
|
async function createMailFolder() {
|
||||||
if (!connectedMailAccount || !window.daybreakMail?.createFolder) { openMailAccount(); return; }
|
if (!mailFeatureState.connectedAccount || !window.daybreakMail?.createFolder) { openMailAccount(); return; }
|
||||||
const name = await askText('New mail folder', 'Name');
|
const name = await askText('New mail folder', 'Name');
|
||||||
if (!name) return;
|
if (!name) return;
|
||||||
try {
|
try {
|
||||||
const result = await window.daybreakMail.createFolder(name);
|
const result = await window.daybreakMail.createFolder(name);
|
||||||
customFolders = result.folders || customFolders;
|
mailFeatureState.customFolders = result.folders || mailFeatureState.customFolders;
|
||||||
renderCustomFolders();
|
renderCustomFolders();
|
||||||
toast(`Folder “${result.folder?.name || name}” created`);
|
toast(`Folder “${result.folder?.name || name}” created`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -281,9 +284,9 @@ function openMailAccount(existingAccount = null) {
|
|||||||
if (editing) {
|
if (editing) {
|
||||||
const accountList = await window.daybreakMail.listAccounts();
|
const accountList = await window.daybreakMail.listAccounts();
|
||||||
if (accountList.activeId === account.id) {
|
if (accountList.activeId === account.id) {
|
||||||
connectedMailAccount = account;
|
mailFeatureState.connectedAccount = account;
|
||||||
updateAccountCard(account);
|
updateAccountCard(account);
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
close();
|
close();
|
||||||
await syncMailbox(false, { offset: 0 });
|
await syncMailbox(false, { offset: 0 });
|
||||||
} else {
|
} else {
|
||||||
@@ -291,7 +294,7 @@ function openMailAccount(existingAccount = null) {
|
|||||||
}
|
}
|
||||||
toast('Mailbox settings updated');
|
toast('Mailbox settings updated');
|
||||||
} else {
|
} else {
|
||||||
connectedMailAccount = account;
|
mailFeatureState.connectedAccount = account;
|
||||||
updateAccountCard(account);
|
updateAccountCard(account);
|
||||||
close();
|
close();
|
||||||
toast('Mailbox connected securely');
|
toast('Mailbox connected securely');
|
||||||
@@ -317,15 +320,13 @@ function mailSearchFilters() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedDraftIds = new Set();
|
|
||||||
|
|
||||||
async function deleteSelectedDrafts() {
|
async function deleteSelectedDrafts() {
|
||||||
const ids = messages.map(message => String(message.id)).filter(id => selectedDraftIds.has(id));
|
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) { toast('Select one or more drafts first'); return; }
|
||||||
if (!confirm(`Delete ${ids.length} selected draft${ids.length === 1 ? '' : 's'}?`)) return;
|
if (!confirm(`Delete ${ids.length} selected draft${ids.length === 1 ? '' : 's'}?`)) return;
|
||||||
try {
|
try {
|
||||||
for (const id of ids) await window.daybreakMail.deleteDraft(id);
|
for (const id of ids) await window.daybreakMail.deleteDraft(id);
|
||||||
selectedDraftIds.clear();
|
mailFeatureState.selectedDraftIds.clear();
|
||||||
toast(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`);
|
toast(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`);
|
||||||
await syncMailbox(false);
|
await syncMailbox(false);
|
||||||
} catch (error) { toast(error.message || 'Could not delete the drafts'); }
|
} catch (error) { toast(error.message || 'Could not delete the drafts'); }
|
||||||
@@ -333,22 +334,22 @@ async function deleteSelectedDrafts() {
|
|||||||
|
|
||||||
// In the Drafts folder the shared toolbar acts on drafts, which use string ids.
|
// In the Drafts folder the shared toolbar acts on drafts, which use string ids.
|
||||||
document.addEventListener('click', event => {
|
document.addEventListener('click', event => {
|
||||||
if (activeFolder !== 'Drafts') return;
|
if (rendererState.activeFolder !== 'Drafts') return;
|
||||||
const button = event.target.closest('#select-all, #delete-selected, #archive-selected, #mark-unread');
|
const button = event.target.closest('#select-all, #delete-selected, #archive-selected, #mark-unread');
|
||||||
if (!button) return;
|
if (!button) return;
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
if (button.id === 'select-all') {
|
if (button.id === 'select-all') {
|
||||||
const ids = messages.map(message => String(message.id));
|
const ids = rendererState.messages.map(message => String(message.id));
|
||||||
const all = ids.length && ids.every(id => selectedDraftIds.has(id));
|
const all = ids.length && ids.every(id => mailFeatureState.selectedDraftIds.has(id));
|
||||||
ids.forEach(id => all ? selectedDraftIds.delete(id) : selectedDraftIds.add(id));
|
ids.forEach(id => all ? mailFeatureState.selectedDraftIds.delete(id) : mailFeatureState.selectedDraftIds.add(id));
|
||||||
renderDrafts(messages.map(message => message.draft));
|
renderDrafts(rendererState.messages.map(message => message.draft));
|
||||||
} else if (button.id === 'delete-selected') void deleteSelectedDrafts();
|
} else if (button.id === 'delete-selected') void deleteSelectedDrafts();
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
function renderDrafts(drafts) {
|
function renderDrafts(drafts) {
|
||||||
const present = new Set(drafts.map(draft => String(draft.id)));
|
const present = new Set(drafts.map(draft => String(draft.id)));
|
||||||
[...selectedDraftIds].forEach(id => { if (!present.has(id)) selectedDraftIds.delete(id); });
|
[...mailFeatureState.selectedDraftIds].forEach(id => { if (!present.has(id)) mailFeatureState.selectedDraftIds.delete(id); });
|
||||||
messages.splice(0, messages.length, ...drafts.map(draft => ({
|
rendererState.messages.splice(0, rendererState.messages.length, ...drafts.map(draft => ({
|
||||||
id: draft.id,
|
id: draft.id,
|
||||||
sender: 'Draft',
|
sender: 'Draft',
|
||||||
email: draft.to || 'No recipient',
|
email: draft.to || 'No recipient',
|
||||||
@@ -360,19 +361,19 @@ function renderDrafts(drafts) {
|
|||||||
color: '#dce6df',
|
color: '#dce6df',
|
||||||
draft
|
draft
|
||||||
})));
|
})));
|
||||||
$('#message-list').innerHTML = messages.length ? messages.map(message => `
|
$('#message-list').innerHTML = rendererState.messages.length ? rendererState.messages.map(message => `
|
||||||
<div class="message" data-id="${esc(message.id)}"><input class="row-check" type="checkbox" aria-label="Select draft"${selectedDraftIds.has(String(message.id)) ? ' checked' : ''}><div class="contact-avatar" style="background:${message.color}">${message.initials}</div>
|
<div class="message" data-id="${esc(message.id)}"><input class="row-check" type="checkbox" aria-label="Select draft"${mailFeatureState.selectedDraftIds.has(String(message.id)) ? ' checked' : ''}><div class="contact-avatar" style="background:${message.color}">${message.initials}</div>
|
||||||
<div class="message-body"><div class="sender">${esc(message.email)}</div><div class="subject">${esc(message.subject)}</div><div class="snippet">${esc(message.snippet)}</div></div>
|
<div class="message-body"><div class="sender">${esc(message.email)}</div><div class="subject">${esc(message.subject)}</div><div class="snippet">${esc(message.snippet)}</div></div>
|
||||||
<div class="message-meta"><span class="time">${esc(message.date)}</span><button type="button" class="icon-button draft-delete" title="Delete draft" aria-label="Delete draft">⌫</button></div></div>`).join('') :
|
<div class="message-meta"><span class="time">${esc(message.date)}</span><button type="button" class="icon-button draft-delete" title="Delete draft" aria-label="Delete draft">⌫</button></div></div>`).join('') :
|
||||||
'<div class="reader-empty"><div><div class="empty-icon">✎</div><h3>No saved drafts</h3><p>Drafts are saved on this device and available offline.</p><button class="text-button" id="start-draft">Compose a draft</button></div></div>';
|
'<div class="reader-empty"><div><div class="empty-icon">✎</div><h3>No saved drafts</h3><p>Drafts are saved on this device and available offline.</p><button class="text-button" id="start-draft">Compose a draft</button></div></div>';
|
||||||
const start = $('#start-draft');
|
const start = $('#start-draft');
|
||||||
if (start) start.onclick = () => showCompose();
|
if (start) start.onclick = () => showCompose();
|
||||||
$$('.message').forEach(row => row.onclick = event => {
|
$$('.message').forEach(row => row.onclick = event => {
|
||||||
const draft = messages.find(message => String(message.id) === row.dataset.id)?.draft;
|
const draft = rendererState.messages.find(message => String(message.id) === row.dataset.id)?.draft;
|
||||||
if (event.target.closest('.row-check')) {
|
if (event.target.closest('.row-check')) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const id = row.dataset.id;
|
const id = row.dataset.id;
|
||||||
selectedDraftIds.has(id) ? selectedDraftIds.delete(id) : selectedDraftIds.add(id);
|
mailFeatureState.selectedDraftIds.has(id) ? mailFeatureState.selectedDraftIds.delete(id) : mailFeatureState.selectedDraftIds.add(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.target.closest('.draft-delete')) {
|
if (event.target.closest('.draft-delete')) {
|
||||||
@@ -386,7 +387,7 @@ function renderDrafts(drafts) {
|
|||||||
if (draft) showCompose(null, false, draft);
|
if (draft) showCompose(null, false, draft);
|
||||||
});
|
});
|
||||||
$('#reader-pane').innerHTML = emptyReader();
|
$('#reader-pane').innerHTML = emptyReader();
|
||||||
$('#pagination').textContent = `${messages.length} drafts`;
|
$('#pagination').textContent = `${rendererState.messages.length} drafts`;
|
||||||
$('#load-more').classList.add('hidden');
|
$('#load-more').classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,7 +510,7 @@ function setupDraftComposer() {
|
|||||||
try {
|
try {
|
||||||
await persist();
|
await persist();
|
||||||
toast('Draft saved on this device');
|
toast('Draft saved on this device');
|
||||||
if (activeFolder === 'Drafts') void syncMailbox(false);
|
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||||
} catch (error) { toast(error.message || 'Could not save draft'); }
|
} catch (error) { toast(error.message || 'Could not save draft'); }
|
||||||
};
|
};
|
||||||
modal.addEventListener('input', () => {
|
modal.addEventListener('input', () => {
|
||||||
@@ -519,13 +520,13 @@ function setupDraftComposer() {
|
|||||||
modal.querySelector('.modal-overlay')?.addEventListener('click', event => {
|
modal.querySelector('.modal-overlay')?.addEventListener('click', event => {
|
||||||
if (!event.target.classList.contains('modal-overlay')) return;
|
if (!event.target.classList.contains('modal-overlay')) return;
|
||||||
clearTimeout(saveTimer);
|
clearTimeout(saveTimer);
|
||||||
persist().then(() => { if (activeFolder === 'Drafts') void syncMailbox(false); })
|
persist().then(() => { if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); })
|
||||||
.catch(error => toast(error.message || 'Could not save draft'));
|
.catch(error => toast(error.message || 'Could not save draft'));
|
||||||
closed = true;
|
closed = true;
|
||||||
}, true);
|
}, true);
|
||||||
root.querySelector('.modal-close')?.addEventListener('click', () => {
|
root.querySelector('.modal-close')?.addEventListener('click', () => {
|
||||||
clearTimeout(saveTimer);
|
clearTimeout(saveTimer);
|
||||||
persist().then(() => { if (activeFolder === 'Drafts') void syncMailbox(false); })
|
persist().then(() => { if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); })
|
||||||
.catch(error => toast(error.message || 'Could not save draft'));
|
.catch(error => toast(error.message || 'Could not save draft'));
|
||||||
closed = true;
|
closed = true;
|
||||||
}, true);
|
}, true);
|
||||||
@@ -535,7 +536,7 @@ function setupDraftComposer() {
|
|||||||
try {
|
try {
|
||||||
if (modal.dataset.draftId) await window.daybreakMail.deleteDraft(modal.dataset.draftId);
|
if (modal.dataset.draftId) await window.daybreakMail.deleteDraft(modal.dataset.draftId);
|
||||||
root.innerHTML = '';
|
root.innerHTML = '';
|
||||||
if (activeFolder === 'Drafts') void syncMailbox(false);
|
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||||
} catch (error) { toast(error.message || 'Could not delete draft'); }
|
} catch (error) { toast(error.message || 'Could not delete draft'); }
|
||||||
};
|
};
|
||||||
$('#send').addEventListener('click', () => {
|
$('#send').addEventListener('click', () => {
|
||||||
@@ -546,11 +547,11 @@ function setupDraftComposer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function syncMailbox(showToast, options = {}) {
|
async function syncMailbox(showToast, options = {}) {
|
||||||
if (mailboxSyncPromise) {
|
if (mailFeatureState.syncPromise) {
|
||||||
mailboxSyncQueued = true;
|
mailFeatureState.syncQueued = true;
|
||||||
return mailboxSyncPromise;
|
return mailFeatureState.syncPromise;
|
||||||
}
|
}
|
||||||
if (!connectedMailAccount || !window.daybreakMail) {
|
if (!mailFeatureState.connectedAccount || !window.daybreakMail) {
|
||||||
openMailAccount();
|
openMailAccount();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -558,48 +559,48 @@ async function syncMailbox(showToast, options = {}) {
|
|||||||
if (refresh) refresh.disabled = true;
|
if (refresh) refresh.disabled = true;
|
||||||
const sync = (async () => {
|
const sync = (async () => {
|
||||||
try {
|
try {
|
||||||
if (activeFolder === 'Drafts') {
|
if (rendererState.activeFolder === 'Drafts') {
|
||||||
const result = await window.daybreakMail.listDrafts();
|
const result = await window.daybreakMail.listDrafts();
|
||||||
renderDrafts(result.drafts || []);
|
renderDrafts(result.drafts || []);
|
||||||
if (showToast) toast(`${result.drafts.length} saved drafts`);
|
if (showToast) toast(`${result.drafts.length} saved drafts`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const previouslyActiveMessage = activeMessage;
|
const previouslyActiveMessage = rendererState.activeMessage;
|
||||||
const offset = options.offset ?? (options.append ? mailPageOffset + messages.length : mailPageOffset);
|
const offset = options.offset ?? (options.append ? mailFeatureState.pageOffset + rendererState.messages.length : mailFeatureState.pageOffset);
|
||||||
const result = await window.daybreakMail.syncFolder(activeFolder, offset, mailSearchFilters());
|
const result = await window.daybreakMail.syncFolder(rendererState.activeFolder, offset, mailSearchFilters());
|
||||||
if (options.append) messages.push(...result.messages);
|
if (options.append) rendererState.messages.push(...result.messages);
|
||||||
else messages.splice(0, messages.length, ...result.messages);
|
else rendererState.messages.splice(0, rendererState.messages.length, ...result.messages);
|
||||||
messages.forEach(message => {
|
rendererState.messages.forEach(message => {
|
||||||
try {
|
try {
|
||||||
const localTags = JSON.parse(localStorage.getItem(`daybreak-message-labels-${message.id}`) || '[]');
|
const localTags = JSON.parse(localStorage.getItem(`daybreak-message-labels-${message.id}`) || '[]');
|
||||||
message.tags = [...new Set([...(message.tags || []), ...localTags])];
|
message.tags = [...new Set([...(message.tags || []), ...localTags])];
|
||||||
} catch {}
|
} catch {}
|
||||||
});
|
});
|
||||||
if (!options.append) mailPageOffset = offset;
|
if (!options.append) mailFeatureState.pageOffset = offset;
|
||||||
mailTotal = result.total;
|
mailFeatureState.total = result.total;
|
||||||
activeMessage = messages.some(message => message.id === previouslyActiveMessage)
|
rendererState.activeMessage = rendererState.messages.some(message => message.id === previouslyActiveMessage)
|
||||||
? previouslyActiveMessage
|
? previouslyActiveMessage
|
||||||
: messages[0]?.id;
|
: rendererState.messages[0]?.id;
|
||||||
selectedIds.clear();
|
rendererState.selectedIds.clear();
|
||||||
const unread = messages.filter(message => message.unread).length;
|
const unread = rendererState.messages.filter(message => message.unread).length;
|
||||||
const inboxCount = $('.folder[data-folder="Inbox"] .count');
|
const inboxCount = $('.folder[data-folder="Inbox"] .count');
|
||||||
if (inboxCount) inboxCount.textContent = String(unread);
|
if (inboxCount) inboxCount.textContent = String(unread);
|
||||||
const pagination = $('#pagination');
|
const pagination = $('#pagination');
|
||||||
if (pagination) pagination.textContent = result.total ? `${options.append ? 1 : result.start}–${options.append ? Math.min(offset + result.messages.length, result.total) : result.end} of ${result.total}` : '0 messages';
|
if (pagination) pagination.textContent = result.total ? `${options.append ? 1 : result.start}–${options.append ? Math.min(offset + result.messages.length, result.total) : result.end} of ${result.total}` : '0 messages';
|
||||||
const loadMore = $('#load-more');
|
const loadMore = $('#load-more');
|
||||||
if (loadMore) loadMore.classList.toggle('hidden', mailPageOffset + messages.length >= result.total);
|
if (loadMore) loadMore.classList.toggle('hidden', mailFeatureState.pageOffset + rendererState.messages.length >= result.total);
|
||||||
query = '';
|
query = '';
|
||||||
renderList();
|
renderList();
|
||||||
if (activeMessage) {
|
if (rendererState.activeMessage) {
|
||||||
openMessage(activeMessage);
|
openMessage(rendererState.activeMessage);
|
||||||
const current = messages.find(message => message.id === activeMessage);
|
const current = rendererState.messages.find(message => message.id === rendererState.activeMessage);
|
||||||
if (current?.uid) window.daybreakMail.updateMessage({ uid: current.uid, folder: current.sourceFolder || activeFolder, action: 'unread', enabled: false }).catch(() => {});
|
if (current?.uid) window.daybreakMail.updateMessage({ uid: current.uid, folder: current.sourceFolder || rendererState.activeFolder, action: 'unread', enabled: false }).catch(() => {});
|
||||||
}
|
}
|
||||||
else $('#reader-pane').innerHTML = emptyReader();
|
else $('#reader-pane').innerHTML = emptyReader();
|
||||||
updateAccountCard(connectedMailAccount);
|
updateAccountCard(mailFeatureState.connectedAccount);
|
||||||
const status = $('#mail-status');
|
const status = $('#mail-status');
|
||||||
if (status) status.textContent = result.offline ? 'Offline — showing saved messages' : 'All caught up with your mail';
|
if (status) status.textContent = result.offline ? 'Offline — showing saved messages' : 'All caught up with your mail';
|
||||||
if (showToast) toast(`Synced ${messages.length} messages`);
|
if (showToast) toast(`Synced ${rendererState.messages.length} messages`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast(error.message || 'Could not sync the inbox');
|
toast(error.message || 'Could not sync the inbox');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -607,13 +608,13 @@ async function syncMailbox(showToast, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
mailboxSyncPromise = sync;
|
mailFeatureState.syncPromise = sync;
|
||||||
try {
|
try {
|
||||||
await sync;
|
await sync;
|
||||||
} finally {
|
} finally {
|
||||||
mailboxSyncPromise = null;
|
mailFeatureState.syncPromise = null;
|
||||||
if (mailboxSyncQueued) {
|
if (mailFeatureState.syncQueued) {
|
||||||
mailboxSyncQueued = false;
|
mailFeatureState.syncQueued = false;
|
||||||
void syncMailbox(false);
|
void syncMailbox(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -636,28 +637,28 @@ if (window.daybreakMail) {
|
|||||||
$('#filter-before').value = '';
|
$('#filter-before').value = '';
|
||||||
$('#filter-attachments').checked = false;
|
$('#filter-attachments').checked = false;
|
||||||
$('#search').value = '';
|
$('#search').value = '';
|
||||||
activeFolder = folderBeforeSearch || activeFolder;
|
rendererState.activeFolder = mailFeatureState.folderBeforeSearch || rendererState.activeFolder;
|
||||||
folderBeforeSearch = null;
|
mailFeatureState.folderBeforeSearch = null;
|
||||||
$$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === activeFolder));
|
$$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === rendererState.activeFolder));
|
||||||
$('#sidebar-title').textContent = activeFolder;
|
$('#sidebar-title').textContent = rendererState.activeFolder;
|
||||||
$('#crumb-current').textContent = activeFolder;
|
$('#crumb-current').textContent = rendererState.activeFolder;
|
||||||
query = '';
|
query = '';
|
||||||
renderList();
|
renderList();
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
void syncMailbox(false, { offset: 0 });
|
void syncMailbox(false, { offset: 0 });
|
||||||
};
|
};
|
||||||
for (const selector of searchControls) {
|
for (const selector of searchControls) {
|
||||||
$(selector).addEventListener(selector === '#search' ? 'input' : 'change', () => {
|
$(selector).addEventListener(selector === '#search' ? 'input' : 'change', () => {
|
||||||
if (selector === '#filter-folder' && $('#filter-folder').value) {
|
if (selector === '#filter-folder' && $('#filter-folder').value) {
|
||||||
if (!folderBeforeSearch) folderBeforeSearch = activeFolder;
|
if (!mailFeatureState.folderBeforeSearch) mailFeatureState.folderBeforeSearch = rendererState.activeFolder;
|
||||||
activeFolder = $('#filter-folder').value;
|
rendererState.activeFolder = $('#filter-folder').value;
|
||||||
$$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === activeFolder));
|
$$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === rendererState.activeFolder));
|
||||||
$('#sidebar-title').textContent = activeFolder;
|
$('#sidebar-title').textContent = rendererState.activeFolder;
|
||||||
$('#crumb-current').textContent = activeFolder;
|
$('#crumb-current').textContent = rendererState.activeFolder;
|
||||||
}
|
}
|
||||||
clearTimeout(searchTimer);
|
clearTimeout(searchTimer);
|
||||||
searchTimer = setTimeout(() => {
|
searchTimer = setTimeout(() => {
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
void syncMailbox(false, { offset: 0 });
|
void syncMailbox(false, { offset: 0 });
|
||||||
}, selector === '#search' ? 350 : 0);
|
}, selector === '#search' ? 350 : 0);
|
||||||
});
|
});
|
||||||
@@ -668,7 +669,7 @@ if (window.daybreakMail) {
|
|||||||
console.error('Could not read app version:', error);
|
console.error('Could not read app version:', error);
|
||||||
});
|
});
|
||||||
window.daybreakMail.onSyncUpdate(update => {
|
window.daybreakMail.onSyncUpdate(update => {
|
||||||
if (update.accountId !== connectedMailAccount?.id) return;
|
if (update.accountId !== mailFeatureState.connectedAccount?.id) return;
|
||||||
if (update.error) {
|
if (update.error) {
|
||||||
toast(update.error);
|
toast(update.error);
|
||||||
return;
|
return;
|
||||||
@@ -677,23 +678,23 @@ if (window.daybreakMail) {
|
|||||||
if (document.visibilityState === 'visible') {
|
if (document.visibilityState === 'visible') {
|
||||||
syncMailbox(false, update.newCount ? { offset: 0 } : {});
|
syncMailbox(false, update.newCount ? { offset: 0 } : {});
|
||||||
}
|
}
|
||||||
else mailboxRefreshPending = true;
|
else mailFeatureState.refreshPending = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.addEventListener('visibilitychange', () => {
|
document.addEventListener('visibilitychange', () => {
|
||||||
if (document.visibilityState === 'visible' && mailboxRefreshPending) {
|
if (document.visibilityState === 'visible' && mailFeatureState.refreshPending) {
|
||||||
mailboxRefreshPending = false;
|
mailFeatureState.refreshPending = false;
|
||||||
syncMailbox(false, { offset: 0 });
|
syncMailbox(false, { offset: 0 });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.addEventListener('focus', () => {
|
window.addEventListener('focus', () => {
|
||||||
if (connectedMailAccount) syncMailbox(false);
|
if (mailFeatureState.connectedAccount) syncMailbox(false);
|
||||||
});
|
});
|
||||||
window.addEventListener('online', () => {
|
window.addEventListener('online', () => {
|
||||||
if (connectedMailAccount) syncMailbox(false, { offset: 0 });
|
if (mailFeatureState.connectedAccount) syncMailbox(false, { offset: 0 });
|
||||||
});
|
});
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (connectedMailAccount && document.visibilityState === 'visible' && activeView === 'mail') {
|
if (mailFeatureState.connectedAccount && document.visibilityState === 'visible' && rendererState.activeView === 'mail') {
|
||||||
syncMailbox(false);
|
syncMailbox(false);
|
||||||
}
|
}
|
||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
@@ -707,27 +708,27 @@ if (window.daybreakMail) {
|
|||||||
$$('.folder').forEach(button => button.addEventListener('click', () => {
|
$$('.folder').forEach(button => button.addEventListener('click', () => {
|
||||||
if ($('#filter-folder').value) {
|
if ($('#filter-folder').value) {
|
||||||
$('#filter-folder').value = '';
|
$('#filter-folder').value = '';
|
||||||
folderBeforeSearch = null;
|
mailFeatureState.folderBeforeSearch = null;
|
||||||
}
|
}
|
||||||
if (['Inbox', 'Sent', 'Archive', 'Trash', 'Starred', 'Drafts'].includes(button.dataset.folder)) {
|
if (['Inbox', 'Sent', 'Archive', 'Trash', 'Starred', 'Drafts'].includes(button.dataset.folder)) {
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
syncMailbox(false, { offset: 0 });
|
syncMailbox(false, { offset: 0 });
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
$('#previous-page').onclick = () => {
|
$('#previous-page').onclick = () => {
|
||||||
if (mailPageOffset <= 0) return;
|
if (mailFeatureState.pageOffset <= 0) return;
|
||||||
mailPageOffset = Math.max(0, mailPageOffset - 20);
|
mailFeatureState.pageOffset = Math.max(0, mailFeatureState.pageOffset - 20);
|
||||||
syncMailbox(false, { offset: mailPageOffset });
|
syncMailbox(false, { offset: mailFeatureState.pageOffset });
|
||||||
};
|
};
|
||||||
$('#next-page').onclick = () => {
|
$('#next-page').onclick = () => {
|
||||||
if (mailPageOffset + 20 >= mailTotal) return;
|
if (mailFeatureState.pageOffset + 20 >= mailFeatureState.total) return;
|
||||||
mailPageOffset += 20;
|
mailFeatureState.pageOffset += 20;
|
||||||
syncMailbox(false, { offset: mailPageOffset });
|
syncMailbox(false, { offset: mailFeatureState.pageOffset });
|
||||||
};
|
};
|
||||||
$('#load-more').onclick = () => syncMailbox(false, { append: true });
|
$('#load-more').onclick = () => syncMailbox(false, { append: true });
|
||||||
document.addEventListener('click', async event => {
|
document.addEventListener('click', async event => {
|
||||||
const sendButton = event.target.closest('#send');
|
const sendButton = event.target.closest('#send');
|
||||||
if (!sendButton || !connectedMailAccount) return;
|
if (!sendButton || !mailFeatureState.connectedAccount) return;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
const recipient = $('#compose-to').value.trim();
|
const recipient = $('#compose-to').value.trim();
|
||||||
@@ -749,7 +750,7 @@ if (window.daybreakMail) {
|
|||||||
subject: $('#compose-subject').value.trim(),
|
subject: $('#compose-subject').value.trim(),
|
||||||
text: $('#compose-body').value,
|
text: $('#compose-body').value,
|
||||||
attachments: $('#modal-root .compose-modal')?._composeAttachments || [],
|
attachments: $('#modal-root .compose-modal')?._composeAttachments || [],
|
||||||
displayName: connectedMailAccount.displayName || window.epMailFeatures.productivity?.profileName || '',
|
displayName: mailFeatureState.connectedAccount.displayName || window.epMailFeatures.productivity?.profileName || '',
|
||||||
...(pgp ? { pgp } : {})
|
...(pgp ? { pgp } : {})
|
||||||
});
|
});
|
||||||
if (result.failed) {
|
if (result.failed) {
|
||||||
@@ -763,15 +764,15 @@ if (window.daybreakMail) {
|
|||||||
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
||||||
$('#modal-root').innerHTML = '';
|
$('#modal-root').innerHTML = '';
|
||||||
toast('Offline: message queued and will send when connected');
|
toast('Offline: message queued and will send when connected');
|
||||||
if (activeFolder === 'Drafts') void syncMailbox(false);
|
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const draftId = $('#modal-root .compose-modal')?.dataset.draftId;
|
const draftId = $('#modal-root .compose-modal')?.dataset.draftId;
|
||||||
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
||||||
$('#modal-root').innerHTML = '';
|
$('#modal-root').innerHTML = '';
|
||||||
toast(result.savedToSent ? 'Message sent and saved in Sent' : 'Message sent, but its Sent copy could not be saved');
|
toast(result.savedToSent ? 'Message sent and saved in Sent' : 'Message sent, but its Sent copy could not be saved');
|
||||||
if (activeFolder === 'Sent') syncMailbox(false, { offset: 0 });
|
if (rendererState.activeFolder === 'Sent') syncMailbox(false, { offset: 0 });
|
||||||
if (activeFolder === 'Drafts') void syncMailbox(false);
|
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
sendButton.disabled = false;
|
sendButton.disabled = false;
|
||||||
sendButton.textContent = 'Send ↗';
|
sendButton.textContent = 'Send ↗';
|
||||||
@@ -781,7 +782,7 @@ if (window.daybreakMail) {
|
|||||||
|
|
||||||
window.daybreakMail.getAccount().then(account => {
|
window.daybreakMail.getAccount().then(account => {
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
connectedMailAccount = account;
|
mailFeatureState.connectedAccount = account;
|
||||||
updateAccountCard(account);
|
updateAccountCard(account);
|
||||||
syncMailbox(false);
|
syncMailbox(false);
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
@@ -789,9 +790,9 @@ if (window.daybreakMail) {
|
|||||||
|
|
||||||
const mailUiApi = window.epMailUiModules.createMailUiApi({
|
const mailUiApi = window.epMailUiModules.createMailUiApi({
|
||||||
state: window.epMailState,
|
state: window.epMailState,
|
||||||
getConnectedAccount: () => connectedMailAccount,
|
getConnectedAccount: () => mailFeatureState.connectedAccount,
|
||||||
setConnectedAccount: account => { connectedMailAccount = account; },
|
setConnectedAccount: account => { mailFeatureState.connectedAccount = account; },
|
||||||
setPageOffset: offset => { mailPageOffset = offset; },
|
setPageOffset: offset => { mailFeatureState.pageOffset = offset; },
|
||||||
syncMailbox,
|
syncMailbox,
|
||||||
updateAccountCard,
|
updateAccountCard,
|
||||||
getRenderList: () => renderList,
|
getRenderList: () => renderList,
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.4.20",
|
"version": "0.4.21",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.4.20",
|
"version": "0.4.21",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@capacitor/android": "^8.5.2",
|
"@capacitor/android": "^8.5.2",
|
||||||
"@capacitor/core": "^8.5.2",
|
"@capacitor/core": "^8.5.2",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.4.20",
|
"version": "0.4.21",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Eternity Project mail client",
|
"description": "Eternity Project mail client",
|
||||||
"homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client",
|
"homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ function pgpAvailable() { return Boolean(window.daybreakMail?.pgp); }
|
|||||||
|
|
||||||
function openEncryptionKeys() {
|
function openEncryptionKeys() {
|
||||||
const root = $('#modal-root');
|
const root = $('#modal-root');
|
||||||
const account = connectedMailAccount || {};
|
const account = window.epMailFeatures.mail.connectedAccount || {};
|
||||||
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal attachments-modal"><div class="modal-head"><span>Encryption keys</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields">
|
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal attachments-modal"><div class="modal-head"><span>Encryption keys</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields">
|
||||||
<p class="account-note">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.</p>
|
<p class="account-note">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.</p>
|
||||||
<div id="pgp-key-list" class="attachment-list">Loading keys…</div>
|
<div id="pgp-key-list" class="attachment-list">Loading keys…</div>
|
||||||
|
|||||||
@@ -62,18 +62,21 @@ test('account and snooze UI consume the explicit mail API instead of selected le
|
|||||||
const snoozeUi = fs.readFileSync(path.join(root, 'snooze-ui.js'), 'utf8');
|
const snoozeUi = fs.readFileSync(path.join(root, 'snooze-ui.js'), 'utf8');
|
||||||
const attachmentUi = fs.readFileSync(path.join(root, 'attachments.js'), 'utf8');
|
const attachmentUi = fs.readFileSync(path.join(root, 'attachments.js'), 'utf8');
|
||||||
const pgpMailUi = fs.readFileSync(path.join(root, 'pgp-mail-ui.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 shortcutsUi = fs.readFileSync(path.join(root, 'shortcuts.js'), 'utf8');
|
const shortcutsUi = fs.readFileSync(path.join(root, 'shortcuts.js'), 'utf8');
|
||||||
const productivityUi = fs.readFileSync(path.join(root, 'productivity.js'), 'utf8');
|
const productivityUi = fs.readFileSync(path.join(root, 'productivity.js'), 'utf8');
|
||||||
assert.match(accountUi, /window\.epMailFeatures\.mail/);
|
assert.match(accountUi, /window\.epMailFeatures\.mail/);
|
||||||
assert.match(snoozeUi, /window\.epMailFeatures\.mail/);
|
assert.match(snoozeUi, /window\.epMailFeatures\.mail/);
|
||||||
assert.match(attachmentUi, /window\.epMailFeatures\.mail/);
|
assert.match(attachmentUi, /window\.epMailFeatures\.mail/);
|
||||||
assert.match(pgpMailUi, /window\.epMailFeatures\.mail/);
|
assert.match(pgpMailUi, /window\.epMailFeatures\.mail/);
|
||||||
|
assert.match(pgpUi, /window\.epMailFeatures\.mail\.connectedAccount/);
|
||||||
assert.match(shortcutsUi, /window\.epMailFeatures\.mail/);
|
assert.match(shortcutsUi, /window\.epMailFeatures\.mail/);
|
||||||
assert.match(shortcutsUi, /window\.epMailFeatures\.productivity/);
|
assert.match(shortcutsUi, /window\.epMailFeatures\.productivity/);
|
||||||
assert.doesNotMatch(accountUi, /\bconnectedMailAccount\b|\bmailPageOffset\b|(?<!\.)\bsyncMailbox\s*\(/);
|
assert.doesNotMatch(accountUi, /\bconnectedMailAccount\b|\bmailPageOffset\b|(?<!\.)\bsyncMailbox\s*\(/);
|
||||||
assert.doesNotMatch(snoozeUi, /\bconnectedMailAccount\b|(?<!\.)\bactiveFolder\b|(?<!\.)\bselectedIds\b|(?<!\.)\bsyncMailbox\s*\(/);
|
assert.doesNotMatch(snoozeUi, /\bconnectedMailAccount\b|(?<!\.)\bactiveFolder\b|(?<!\.)\bselectedIds\b|(?<!\.)\bsyncMailbox\s*\(/);
|
||||||
assert.doesNotMatch(attachmentUi, /\bconnectedMailAccount\b|(?<!\.)\bactiveFolder\b|(?<!\.)\bmessages\.find/);
|
assert.doesNotMatch(attachmentUi, /\bconnectedMailAccount\b|(?<!\.)\bactiveFolder\b|(?<!\.)\bmessages\.find/);
|
||||||
assert.doesNotMatch(pgpMailUi, /(?<!\.)\bmessages\.find|(?<!\.)\bactiveMessage\b|window\.pgpPrepareSend/);
|
assert.doesNotMatch(pgpMailUi, /(?<!\.)\bmessages\.find|(?<!\.)\bactiveMessage\b|window\.pgpPrepareSend/);
|
||||||
|
assert.doesNotMatch(pgpUi, /\bconnectedMailAccount\b/);
|
||||||
assert.match(productivityUi, /window\.epMailFeatures\.productivity/);
|
assert.match(productivityUi, /window\.epMailFeatures\.productivity/);
|
||||||
assert.doesNotMatch(shortcutsUi, /(?<!\.)\bactiveMessage\b|(?<!\.)\bopenMessage\s*\(/);
|
assert.doesNotMatch(shortcutsUi, /(?<!\.)\bactiveMessage\b|(?<!\.)\bopenMessage\s*\(/);
|
||||||
});
|
});
|
||||||
|
|||||||
+108
-107
@@ -1,10 +1,15 @@
|
|||||||
let connectedMailAccount = null;
|
const rendererState = window.epMailState;
|
||||||
let mailPageOffset = 0;
|
const mailFeatureState = {
|
||||||
let mailTotal = 0;
|
connectedAccount: null,
|
||||||
let mailboxSyncPromise = null;
|
pageOffset: 0,
|
||||||
let mailboxSyncQueued = false;
|
total: 0,
|
||||||
let mailboxRefreshPending = false;
|
syncPromise: null,
|
||||||
let folderBeforeSearch = null;
|
syncQueued: false,
|
||||||
|
refreshPending: false,
|
||||||
|
folderBeforeSearch: null,
|
||||||
|
customFolders: [],
|
||||||
|
selectedDraftIds: new Set()
|
||||||
|
};
|
||||||
|
|
||||||
const senderBrandDomains = {
|
const senderBrandDomains = {
|
||||||
amazon: ['amazon.com', 'amazon.co.uk'],
|
amazon: ['amazon.com', 'amazon.co.uk'],
|
||||||
@@ -65,7 +70,7 @@ function messageLinks(message) {
|
|||||||
const originalOpenMessage = openMessage;
|
const originalOpenMessage = openMessage;
|
||||||
openMessage = function (id) {
|
openMessage = function (id) {
|
||||||
originalOpenMessage(id);
|
originalOpenMessage(id);
|
||||||
const message = messages.find(item => item.id === id);
|
const message = rendererState.messages.find(item => item.id === id);
|
||||||
if (!message) return;
|
if (!message) return;
|
||||||
const senderReasons = suspiciousSenderReasons(message);
|
const senderReasons = suspiciousSenderReasons(message);
|
||||||
const links = messageLinks(message);
|
const links = messageLinks(message);
|
||||||
@@ -102,16 +107,14 @@ openMessage = function (id) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let customFolders = [];
|
|
||||||
|
|
||||||
function renderCustomFolders() {
|
function renderCustomFolders() {
|
||||||
const box = $('#custom-folders');
|
const box = $('#custom-folders');
|
||||||
if (!box) return;
|
if (!box) return;
|
||||||
box.replaceChildren(...customFolders.map(folder => {
|
box.replaceChildren(...mailFeatureState.customFolders.map(folder => {
|
||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
button.className = 'folder custom-folder';
|
button.className = 'folder custom-folder';
|
||||||
button.dataset.folder = folder.id;
|
button.dataset.folder = folder.id;
|
||||||
button.classList.toggle('active', activeFolder === folder.id);
|
button.classList.toggle('active', rendererState.activeFolder === folder.id);
|
||||||
const glyph = document.createElement('span');
|
const glyph = document.createElement('span');
|
||||||
glyph.className = 'nav-glyph';
|
glyph.className = 'nav-glyph';
|
||||||
glyph.textContent = '▭';
|
glyph.textContent = '▭';
|
||||||
@@ -120,12 +123,12 @@ function renderCustomFolders() {
|
|||||||
button.title = folder.path;
|
button.title = folder.path;
|
||||||
button.append(glyph, label);
|
button.append(glyph, label);
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
if ($('#filter-folder').value) { $('#filter-folder').value = ''; folderBeforeSearch = null; }
|
if ($('#filter-folder').value) { $('#filter-folder').value = ''; mailFeatureState.folderBeforeSearch = null; }
|
||||||
activeFolder = folder.id;
|
rendererState.activeFolder = folder.id;
|
||||||
$$('.folder').forEach(item => item.classList.toggle('active', item === button));
|
$$('.folder').forEach(item => item.classList.toggle('active', item === button));
|
||||||
$('#sidebar-title').textContent = folder.name;
|
$('#sidebar-title').textContent = folder.name;
|
||||||
$('#crumb-current').textContent = folder.name;
|
$('#crumb-current').textContent = folder.name;
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
void syncMailbox(false, { offset: 0 });
|
void syncMailbox(false, { offset: 0 });
|
||||||
});
|
});
|
||||||
return button;
|
return button;
|
||||||
@@ -133,16 +136,16 @@ function renderCustomFolders() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadCustomFolders() {
|
async function loadCustomFolders() {
|
||||||
if (!connectedMailAccount || !window.daybreakMail?.listFolders) return;
|
if (!mailFeatureState.connectedAccount || !window.daybreakMail?.listFolders) return;
|
||||||
try {
|
try {
|
||||||
customFolders = (await window.daybreakMail.listFolders()).folders || [];
|
mailFeatureState.customFolders = (await window.daybreakMail.listFolders()).folders || [];
|
||||||
renderCustomFolders();
|
renderCustomFolders();
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destination options for the mail-rule folder picker: built-in folders plus the account's IMAP folders.
|
// Destination options for the mail-rule folder picker: built-in folders plus the account's IMAP folders.
|
||||||
function ruleFolderSelect(selected = 'Inbox') {
|
function ruleFolderSelect(selected = 'Inbox') {
|
||||||
const options = [['Inbox', 'Inbox'], ['Archive', 'Archive'], ['Trash', 'Trash'], ...customFolders.map(folder => [folder.id, folder.name])];
|
const options = [['Inbox', 'Inbox'], ['Archive', 'Archive'], ['Trash', 'Trash'], ...mailFeatureState.customFolders.map(folder => [folder.id, folder.name])];
|
||||||
if (!options.some(([value]) => value === selected)) {
|
if (!options.some(([value]) => value === selected)) {
|
||||||
options.push([selected, String(selected).replace(/^[^:]*:/, '') || selected]);
|
options.push([selected, String(selected).replace(/^[^:]*:/, '') || selected]);
|
||||||
}
|
}
|
||||||
@@ -170,12 +173,12 @@ function askText(title, label, placeholder = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createMailFolder() {
|
async function createMailFolder() {
|
||||||
if (!connectedMailAccount || !window.daybreakMail?.createFolder) { openMailAccount(); return; }
|
if (!mailFeatureState.connectedAccount || !window.daybreakMail?.createFolder) { openMailAccount(); return; }
|
||||||
const name = await askText('New mail folder', 'Name');
|
const name = await askText('New mail folder', 'Name');
|
||||||
if (!name) return;
|
if (!name) return;
|
||||||
try {
|
try {
|
||||||
const result = await window.daybreakMail.createFolder(name);
|
const result = await window.daybreakMail.createFolder(name);
|
||||||
customFolders = result.folders || customFolders;
|
mailFeatureState.customFolders = result.folders || mailFeatureState.customFolders;
|
||||||
renderCustomFolders();
|
renderCustomFolders();
|
||||||
toast(`Folder “${result.folder?.name || name}” created`);
|
toast(`Folder “${result.folder?.name || name}” created`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -281,9 +284,9 @@ function openMailAccount(existingAccount = null) {
|
|||||||
if (editing) {
|
if (editing) {
|
||||||
const accountList = await window.daybreakMail.listAccounts();
|
const accountList = await window.daybreakMail.listAccounts();
|
||||||
if (accountList.activeId === account.id) {
|
if (accountList.activeId === account.id) {
|
||||||
connectedMailAccount = account;
|
mailFeatureState.connectedAccount = account;
|
||||||
updateAccountCard(account);
|
updateAccountCard(account);
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
close();
|
close();
|
||||||
await syncMailbox(false, { offset: 0 });
|
await syncMailbox(false, { offset: 0 });
|
||||||
} else {
|
} else {
|
||||||
@@ -291,7 +294,7 @@ function openMailAccount(existingAccount = null) {
|
|||||||
}
|
}
|
||||||
toast('Mailbox settings updated');
|
toast('Mailbox settings updated');
|
||||||
} else {
|
} else {
|
||||||
connectedMailAccount = account;
|
mailFeatureState.connectedAccount = account;
|
||||||
updateAccountCard(account);
|
updateAccountCard(account);
|
||||||
close();
|
close();
|
||||||
toast('Mailbox connected securely');
|
toast('Mailbox connected securely');
|
||||||
@@ -317,15 +320,13 @@ function mailSearchFilters() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedDraftIds = new Set();
|
|
||||||
|
|
||||||
async function deleteSelectedDrafts() {
|
async function deleteSelectedDrafts() {
|
||||||
const ids = messages.map(message => String(message.id)).filter(id => selectedDraftIds.has(id));
|
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) { toast('Select one or more drafts first'); return; }
|
||||||
if (!confirm(`Delete ${ids.length} selected draft${ids.length === 1 ? '' : 's'}?`)) return;
|
if (!confirm(`Delete ${ids.length} selected draft${ids.length === 1 ? '' : 's'}?`)) return;
|
||||||
try {
|
try {
|
||||||
for (const id of ids) await window.daybreakMail.deleteDraft(id);
|
for (const id of ids) await window.daybreakMail.deleteDraft(id);
|
||||||
selectedDraftIds.clear();
|
mailFeatureState.selectedDraftIds.clear();
|
||||||
toast(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`);
|
toast(`${ids.length} draft${ids.length === 1 ? '' : 's'} deleted`);
|
||||||
await syncMailbox(false);
|
await syncMailbox(false);
|
||||||
} catch (error) { toast(error.message || 'Could not delete the drafts'); }
|
} catch (error) { toast(error.message || 'Could not delete the drafts'); }
|
||||||
@@ -333,22 +334,22 @@ async function deleteSelectedDrafts() {
|
|||||||
|
|
||||||
// In the Drafts folder the shared toolbar acts on drafts, which use string ids.
|
// In the Drafts folder the shared toolbar acts on drafts, which use string ids.
|
||||||
document.addEventListener('click', event => {
|
document.addEventListener('click', event => {
|
||||||
if (activeFolder !== 'Drafts') return;
|
if (rendererState.activeFolder !== 'Drafts') return;
|
||||||
const button = event.target.closest('#select-all, #delete-selected, #archive-selected, #mark-unread');
|
const button = event.target.closest('#select-all, #delete-selected, #archive-selected, #mark-unread');
|
||||||
if (!button) return;
|
if (!button) return;
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
if (button.id === 'select-all') {
|
if (button.id === 'select-all') {
|
||||||
const ids = messages.map(message => String(message.id));
|
const ids = rendererState.messages.map(message => String(message.id));
|
||||||
const all = ids.length && ids.every(id => selectedDraftIds.has(id));
|
const all = ids.length && ids.every(id => mailFeatureState.selectedDraftIds.has(id));
|
||||||
ids.forEach(id => all ? selectedDraftIds.delete(id) : selectedDraftIds.add(id));
|
ids.forEach(id => all ? mailFeatureState.selectedDraftIds.delete(id) : mailFeatureState.selectedDraftIds.add(id));
|
||||||
renderDrafts(messages.map(message => message.draft));
|
renderDrafts(rendererState.messages.map(message => message.draft));
|
||||||
} else if (button.id === 'delete-selected') void deleteSelectedDrafts();
|
} else if (button.id === 'delete-selected') void deleteSelectedDrafts();
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
function renderDrafts(drafts) {
|
function renderDrafts(drafts) {
|
||||||
const present = new Set(drafts.map(draft => String(draft.id)));
|
const present = new Set(drafts.map(draft => String(draft.id)));
|
||||||
[...selectedDraftIds].forEach(id => { if (!present.has(id)) selectedDraftIds.delete(id); });
|
[...mailFeatureState.selectedDraftIds].forEach(id => { if (!present.has(id)) mailFeatureState.selectedDraftIds.delete(id); });
|
||||||
messages.splice(0, messages.length, ...drafts.map(draft => ({
|
rendererState.messages.splice(0, rendererState.messages.length, ...drafts.map(draft => ({
|
||||||
id: draft.id,
|
id: draft.id,
|
||||||
sender: 'Draft',
|
sender: 'Draft',
|
||||||
email: draft.to || 'No recipient',
|
email: draft.to || 'No recipient',
|
||||||
@@ -360,19 +361,19 @@ function renderDrafts(drafts) {
|
|||||||
color: '#dce6df',
|
color: '#dce6df',
|
||||||
draft
|
draft
|
||||||
})));
|
})));
|
||||||
$('#message-list').innerHTML = messages.length ? messages.map(message => `
|
$('#message-list').innerHTML = rendererState.messages.length ? rendererState.messages.map(message => `
|
||||||
<div class="message" data-id="${esc(message.id)}"><input class="row-check" type="checkbox" aria-label="Select draft"${selectedDraftIds.has(String(message.id)) ? ' checked' : ''}><div class="contact-avatar" style="background:${message.color}">${message.initials}</div>
|
<div class="message" data-id="${esc(message.id)}"><input class="row-check" type="checkbox" aria-label="Select draft"${mailFeatureState.selectedDraftIds.has(String(message.id)) ? ' checked' : ''}><div class="contact-avatar" style="background:${message.color}">${message.initials}</div>
|
||||||
<div class="message-body"><div class="sender">${esc(message.email)}</div><div class="subject">${esc(message.subject)}</div><div class="snippet">${esc(message.snippet)}</div></div>
|
<div class="message-body"><div class="sender">${esc(message.email)}</div><div class="subject">${esc(message.subject)}</div><div class="snippet">${esc(message.snippet)}</div></div>
|
||||||
<div class="message-meta"><span class="time">${esc(message.date)}</span><button type="button" class="icon-button draft-delete" title="Delete draft" aria-label="Delete draft">⌫</button></div></div>`).join('') :
|
<div class="message-meta"><span class="time">${esc(message.date)}</span><button type="button" class="icon-button draft-delete" title="Delete draft" aria-label="Delete draft">⌫</button></div></div>`).join('') :
|
||||||
'<div class="reader-empty"><div><div class="empty-icon">✎</div><h3>No saved drafts</h3><p>Drafts are saved on this device and available offline.</p><button class="text-button" id="start-draft">Compose a draft</button></div></div>';
|
'<div class="reader-empty"><div><div class="empty-icon">✎</div><h3>No saved drafts</h3><p>Drafts are saved on this device and available offline.</p><button class="text-button" id="start-draft">Compose a draft</button></div></div>';
|
||||||
const start = $('#start-draft');
|
const start = $('#start-draft');
|
||||||
if (start) start.onclick = () => showCompose();
|
if (start) start.onclick = () => showCompose();
|
||||||
$$('.message').forEach(row => row.onclick = event => {
|
$$('.message').forEach(row => row.onclick = event => {
|
||||||
const draft = messages.find(message => String(message.id) === row.dataset.id)?.draft;
|
const draft = rendererState.messages.find(message => String(message.id) === row.dataset.id)?.draft;
|
||||||
if (event.target.closest('.row-check')) {
|
if (event.target.closest('.row-check')) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const id = row.dataset.id;
|
const id = row.dataset.id;
|
||||||
selectedDraftIds.has(id) ? selectedDraftIds.delete(id) : selectedDraftIds.add(id);
|
mailFeatureState.selectedDraftIds.has(id) ? mailFeatureState.selectedDraftIds.delete(id) : mailFeatureState.selectedDraftIds.add(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.target.closest('.draft-delete')) {
|
if (event.target.closest('.draft-delete')) {
|
||||||
@@ -386,7 +387,7 @@ function renderDrafts(drafts) {
|
|||||||
if (draft) showCompose(null, false, draft);
|
if (draft) showCompose(null, false, draft);
|
||||||
});
|
});
|
||||||
$('#reader-pane').innerHTML = emptyReader();
|
$('#reader-pane').innerHTML = emptyReader();
|
||||||
$('#pagination').textContent = `${messages.length} drafts`;
|
$('#pagination').textContent = `${rendererState.messages.length} drafts`;
|
||||||
$('#load-more').classList.add('hidden');
|
$('#load-more').classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,7 +510,7 @@ function setupDraftComposer() {
|
|||||||
try {
|
try {
|
||||||
await persist();
|
await persist();
|
||||||
toast('Draft saved on this device');
|
toast('Draft saved on this device');
|
||||||
if (activeFolder === 'Drafts') void syncMailbox(false);
|
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||||
} catch (error) { toast(error.message || 'Could not save draft'); }
|
} catch (error) { toast(error.message || 'Could not save draft'); }
|
||||||
};
|
};
|
||||||
modal.addEventListener('input', () => {
|
modal.addEventListener('input', () => {
|
||||||
@@ -519,13 +520,13 @@ function setupDraftComposer() {
|
|||||||
modal.querySelector('.modal-overlay')?.addEventListener('click', event => {
|
modal.querySelector('.modal-overlay')?.addEventListener('click', event => {
|
||||||
if (!event.target.classList.contains('modal-overlay')) return;
|
if (!event.target.classList.contains('modal-overlay')) return;
|
||||||
clearTimeout(saveTimer);
|
clearTimeout(saveTimer);
|
||||||
persist().then(() => { if (activeFolder === 'Drafts') void syncMailbox(false); })
|
persist().then(() => { if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); })
|
||||||
.catch(error => toast(error.message || 'Could not save draft'));
|
.catch(error => toast(error.message || 'Could not save draft'));
|
||||||
closed = true;
|
closed = true;
|
||||||
}, true);
|
}, true);
|
||||||
root.querySelector('.modal-close')?.addEventListener('click', () => {
|
root.querySelector('.modal-close')?.addEventListener('click', () => {
|
||||||
clearTimeout(saveTimer);
|
clearTimeout(saveTimer);
|
||||||
persist().then(() => { if (activeFolder === 'Drafts') void syncMailbox(false); })
|
persist().then(() => { if (rendererState.activeFolder === 'Drafts') void syncMailbox(false); })
|
||||||
.catch(error => toast(error.message || 'Could not save draft'));
|
.catch(error => toast(error.message || 'Could not save draft'));
|
||||||
closed = true;
|
closed = true;
|
||||||
}, true);
|
}, true);
|
||||||
@@ -535,7 +536,7 @@ function setupDraftComposer() {
|
|||||||
try {
|
try {
|
||||||
if (modal.dataset.draftId) await window.daybreakMail.deleteDraft(modal.dataset.draftId);
|
if (modal.dataset.draftId) await window.daybreakMail.deleteDraft(modal.dataset.draftId);
|
||||||
root.innerHTML = '';
|
root.innerHTML = '';
|
||||||
if (activeFolder === 'Drafts') void syncMailbox(false);
|
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||||
} catch (error) { toast(error.message || 'Could not delete draft'); }
|
} catch (error) { toast(error.message || 'Could not delete draft'); }
|
||||||
};
|
};
|
||||||
$('#send').addEventListener('click', () => {
|
$('#send').addEventListener('click', () => {
|
||||||
@@ -546,11 +547,11 @@ function setupDraftComposer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function syncMailbox(showToast, options = {}) {
|
async function syncMailbox(showToast, options = {}) {
|
||||||
if (mailboxSyncPromise) {
|
if (mailFeatureState.syncPromise) {
|
||||||
mailboxSyncQueued = true;
|
mailFeatureState.syncQueued = true;
|
||||||
return mailboxSyncPromise;
|
return mailFeatureState.syncPromise;
|
||||||
}
|
}
|
||||||
if (!connectedMailAccount || !window.daybreakMail) {
|
if (!mailFeatureState.connectedAccount || !window.daybreakMail) {
|
||||||
openMailAccount();
|
openMailAccount();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -558,48 +559,48 @@ async function syncMailbox(showToast, options = {}) {
|
|||||||
if (refresh) refresh.disabled = true;
|
if (refresh) refresh.disabled = true;
|
||||||
const sync = (async () => {
|
const sync = (async () => {
|
||||||
try {
|
try {
|
||||||
if (activeFolder === 'Drafts') {
|
if (rendererState.activeFolder === 'Drafts') {
|
||||||
const result = await window.daybreakMail.listDrafts();
|
const result = await window.daybreakMail.listDrafts();
|
||||||
renderDrafts(result.drafts || []);
|
renderDrafts(result.drafts || []);
|
||||||
if (showToast) toast(`${result.drafts.length} saved drafts`);
|
if (showToast) toast(`${result.drafts.length} saved drafts`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const previouslyActiveMessage = activeMessage;
|
const previouslyActiveMessage = rendererState.activeMessage;
|
||||||
const offset = options.offset ?? (options.append ? mailPageOffset + messages.length : mailPageOffset);
|
const offset = options.offset ?? (options.append ? mailFeatureState.pageOffset + rendererState.messages.length : mailFeatureState.pageOffset);
|
||||||
const result = await window.daybreakMail.syncFolder(activeFolder, offset, mailSearchFilters());
|
const result = await window.daybreakMail.syncFolder(rendererState.activeFolder, offset, mailSearchFilters());
|
||||||
if (options.append) messages.push(...result.messages);
|
if (options.append) rendererState.messages.push(...result.messages);
|
||||||
else messages.splice(0, messages.length, ...result.messages);
|
else rendererState.messages.splice(0, rendererState.messages.length, ...result.messages);
|
||||||
messages.forEach(message => {
|
rendererState.messages.forEach(message => {
|
||||||
try {
|
try {
|
||||||
const localTags = JSON.parse(localStorage.getItem(`daybreak-message-labels-${message.id}`) || '[]');
|
const localTags = JSON.parse(localStorage.getItem(`daybreak-message-labels-${message.id}`) || '[]');
|
||||||
message.tags = [...new Set([...(message.tags || []), ...localTags])];
|
message.tags = [...new Set([...(message.tags || []), ...localTags])];
|
||||||
} catch {}
|
} catch {}
|
||||||
});
|
});
|
||||||
if (!options.append) mailPageOffset = offset;
|
if (!options.append) mailFeatureState.pageOffset = offset;
|
||||||
mailTotal = result.total;
|
mailFeatureState.total = result.total;
|
||||||
activeMessage = messages.some(message => message.id === previouslyActiveMessage)
|
rendererState.activeMessage = rendererState.messages.some(message => message.id === previouslyActiveMessage)
|
||||||
? previouslyActiveMessage
|
? previouslyActiveMessage
|
||||||
: messages[0]?.id;
|
: rendererState.messages[0]?.id;
|
||||||
selectedIds.clear();
|
rendererState.selectedIds.clear();
|
||||||
const unread = messages.filter(message => message.unread).length;
|
const unread = rendererState.messages.filter(message => message.unread).length;
|
||||||
const inboxCount = $('.folder[data-folder="Inbox"] .count');
|
const inboxCount = $('.folder[data-folder="Inbox"] .count');
|
||||||
if (inboxCount) inboxCount.textContent = String(unread);
|
if (inboxCount) inboxCount.textContent = String(unread);
|
||||||
const pagination = $('#pagination');
|
const pagination = $('#pagination');
|
||||||
if (pagination) pagination.textContent = result.total ? `${options.append ? 1 : result.start}–${options.append ? Math.min(offset + result.messages.length, result.total) : result.end} of ${result.total}` : '0 messages';
|
if (pagination) pagination.textContent = result.total ? `${options.append ? 1 : result.start}–${options.append ? Math.min(offset + result.messages.length, result.total) : result.end} of ${result.total}` : '0 messages';
|
||||||
const loadMore = $('#load-more');
|
const loadMore = $('#load-more');
|
||||||
if (loadMore) loadMore.classList.toggle('hidden', mailPageOffset + messages.length >= result.total);
|
if (loadMore) loadMore.classList.toggle('hidden', mailFeatureState.pageOffset + rendererState.messages.length >= result.total);
|
||||||
query = '';
|
query = '';
|
||||||
renderList();
|
renderList();
|
||||||
if (activeMessage) {
|
if (rendererState.activeMessage) {
|
||||||
openMessage(activeMessage);
|
openMessage(rendererState.activeMessage);
|
||||||
const current = messages.find(message => message.id === activeMessage);
|
const current = rendererState.messages.find(message => message.id === rendererState.activeMessage);
|
||||||
if (current?.uid) window.daybreakMail.updateMessage({ uid: current.uid, folder: current.sourceFolder || activeFolder, action: 'unread', enabled: false }).catch(() => {});
|
if (current?.uid) window.daybreakMail.updateMessage({ uid: current.uid, folder: current.sourceFolder || rendererState.activeFolder, action: 'unread', enabled: false }).catch(() => {});
|
||||||
}
|
}
|
||||||
else $('#reader-pane').innerHTML = emptyReader();
|
else $('#reader-pane').innerHTML = emptyReader();
|
||||||
updateAccountCard(connectedMailAccount);
|
updateAccountCard(mailFeatureState.connectedAccount);
|
||||||
const status = $('#mail-status');
|
const status = $('#mail-status');
|
||||||
if (status) status.textContent = result.offline ? 'Offline — showing saved messages' : 'All caught up with your mail';
|
if (status) status.textContent = result.offline ? 'Offline — showing saved messages' : 'All caught up with your mail';
|
||||||
if (showToast) toast(`Synced ${messages.length} messages`);
|
if (showToast) toast(`Synced ${rendererState.messages.length} messages`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast(error.message || 'Could not sync the inbox');
|
toast(error.message || 'Could not sync the inbox');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -607,13 +608,13 @@ async function syncMailbox(showToast, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
mailboxSyncPromise = sync;
|
mailFeatureState.syncPromise = sync;
|
||||||
try {
|
try {
|
||||||
await sync;
|
await sync;
|
||||||
} finally {
|
} finally {
|
||||||
mailboxSyncPromise = null;
|
mailFeatureState.syncPromise = null;
|
||||||
if (mailboxSyncQueued) {
|
if (mailFeatureState.syncQueued) {
|
||||||
mailboxSyncQueued = false;
|
mailFeatureState.syncQueued = false;
|
||||||
void syncMailbox(false);
|
void syncMailbox(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -636,28 +637,28 @@ if (window.daybreakMail) {
|
|||||||
$('#filter-before').value = '';
|
$('#filter-before').value = '';
|
||||||
$('#filter-attachments').checked = false;
|
$('#filter-attachments').checked = false;
|
||||||
$('#search').value = '';
|
$('#search').value = '';
|
||||||
activeFolder = folderBeforeSearch || activeFolder;
|
rendererState.activeFolder = mailFeatureState.folderBeforeSearch || rendererState.activeFolder;
|
||||||
folderBeforeSearch = null;
|
mailFeatureState.folderBeforeSearch = null;
|
||||||
$$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === activeFolder));
|
$$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === rendererState.activeFolder));
|
||||||
$('#sidebar-title').textContent = activeFolder;
|
$('#sidebar-title').textContent = rendererState.activeFolder;
|
||||||
$('#crumb-current').textContent = activeFolder;
|
$('#crumb-current').textContent = rendererState.activeFolder;
|
||||||
query = '';
|
query = '';
|
||||||
renderList();
|
renderList();
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
void syncMailbox(false, { offset: 0 });
|
void syncMailbox(false, { offset: 0 });
|
||||||
};
|
};
|
||||||
for (const selector of searchControls) {
|
for (const selector of searchControls) {
|
||||||
$(selector).addEventListener(selector === '#search' ? 'input' : 'change', () => {
|
$(selector).addEventListener(selector === '#search' ? 'input' : 'change', () => {
|
||||||
if (selector === '#filter-folder' && $('#filter-folder').value) {
|
if (selector === '#filter-folder' && $('#filter-folder').value) {
|
||||||
if (!folderBeforeSearch) folderBeforeSearch = activeFolder;
|
if (!mailFeatureState.folderBeforeSearch) mailFeatureState.folderBeforeSearch = rendererState.activeFolder;
|
||||||
activeFolder = $('#filter-folder').value;
|
rendererState.activeFolder = $('#filter-folder').value;
|
||||||
$$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === activeFolder));
|
$$('.folder').forEach(button => button.classList.toggle('active', button.dataset.folder === rendererState.activeFolder));
|
||||||
$('#sidebar-title').textContent = activeFolder;
|
$('#sidebar-title').textContent = rendererState.activeFolder;
|
||||||
$('#crumb-current').textContent = activeFolder;
|
$('#crumb-current').textContent = rendererState.activeFolder;
|
||||||
}
|
}
|
||||||
clearTimeout(searchTimer);
|
clearTimeout(searchTimer);
|
||||||
searchTimer = setTimeout(() => {
|
searchTimer = setTimeout(() => {
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
void syncMailbox(false, { offset: 0 });
|
void syncMailbox(false, { offset: 0 });
|
||||||
}, selector === '#search' ? 350 : 0);
|
}, selector === '#search' ? 350 : 0);
|
||||||
});
|
});
|
||||||
@@ -668,7 +669,7 @@ if (window.daybreakMail) {
|
|||||||
console.error('Could not read app version:', error);
|
console.error('Could not read app version:', error);
|
||||||
});
|
});
|
||||||
window.daybreakMail.onSyncUpdate(update => {
|
window.daybreakMail.onSyncUpdate(update => {
|
||||||
if (update.accountId !== connectedMailAccount?.id) return;
|
if (update.accountId !== mailFeatureState.connectedAccount?.id) return;
|
||||||
if (update.error) {
|
if (update.error) {
|
||||||
toast(update.error);
|
toast(update.error);
|
||||||
return;
|
return;
|
||||||
@@ -677,23 +678,23 @@ if (window.daybreakMail) {
|
|||||||
if (document.visibilityState === 'visible') {
|
if (document.visibilityState === 'visible') {
|
||||||
syncMailbox(false, update.newCount ? { offset: 0 } : {});
|
syncMailbox(false, update.newCount ? { offset: 0 } : {});
|
||||||
}
|
}
|
||||||
else mailboxRefreshPending = true;
|
else mailFeatureState.refreshPending = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.addEventListener('visibilitychange', () => {
|
document.addEventListener('visibilitychange', () => {
|
||||||
if (document.visibilityState === 'visible' && mailboxRefreshPending) {
|
if (document.visibilityState === 'visible' && mailFeatureState.refreshPending) {
|
||||||
mailboxRefreshPending = false;
|
mailFeatureState.refreshPending = false;
|
||||||
syncMailbox(false, { offset: 0 });
|
syncMailbox(false, { offset: 0 });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.addEventListener('focus', () => {
|
window.addEventListener('focus', () => {
|
||||||
if (connectedMailAccount) syncMailbox(false);
|
if (mailFeatureState.connectedAccount) syncMailbox(false);
|
||||||
});
|
});
|
||||||
window.addEventListener('online', () => {
|
window.addEventListener('online', () => {
|
||||||
if (connectedMailAccount) syncMailbox(false, { offset: 0 });
|
if (mailFeatureState.connectedAccount) syncMailbox(false, { offset: 0 });
|
||||||
});
|
});
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (connectedMailAccount && document.visibilityState === 'visible' && activeView === 'mail') {
|
if (mailFeatureState.connectedAccount && document.visibilityState === 'visible' && rendererState.activeView === 'mail') {
|
||||||
syncMailbox(false);
|
syncMailbox(false);
|
||||||
}
|
}
|
||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
@@ -707,27 +708,27 @@ if (window.daybreakMail) {
|
|||||||
$$('.folder').forEach(button => button.addEventListener('click', () => {
|
$$('.folder').forEach(button => button.addEventListener('click', () => {
|
||||||
if ($('#filter-folder').value) {
|
if ($('#filter-folder').value) {
|
||||||
$('#filter-folder').value = '';
|
$('#filter-folder').value = '';
|
||||||
folderBeforeSearch = null;
|
mailFeatureState.folderBeforeSearch = null;
|
||||||
}
|
}
|
||||||
if (['Inbox', 'Sent', 'Archive', 'Trash', 'Starred', 'Drafts'].includes(button.dataset.folder)) {
|
if (['Inbox', 'Sent', 'Archive', 'Trash', 'Starred', 'Drafts'].includes(button.dataset.folder)) {
|
||||||
mailPageOffset = 0;
|
mailFeatureState.pageOffset = 0;
|
||||||
syncMailbox(false, { offset: 0 });
|
syncMailbox(false, { offset: 0 });
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
$('#previous-page').onclick = () => {
|
$('#previous-page').onclick = () => {
|
||||||
if (mailPageOffset <= 0) return;
|
if (mailFeatureState.pageOffset <= 0) return;
|
||||||
mailPageOffset = Math.max(0, mailPageOffset - 20);
|
mailFeatureState.pageOffset = Math.max(0, mailFeatureState.pageOffset - 20);
|
||||||
syncMailbox(false, { offset: mailPageOffset });
|
syncMailbox(false, { offset: mailFeatureState.pageOffset });
|
||||||
};
|
};
|
||||||
$('#next-page').onclick = () => {
|
$('#next-page').onclick = () => {
|
||||||
if (mailPageOffset + 20 >= mailTotal) return;
|
if (mailFeatureState.pageOffset + 20 >= mailFeatureState.total) return;
|
||||||
mailPageOffset += 20;
|
mailFeatureState.pageOffset += 20;
|
||||||
syncMailbox(false, { offset: mailPageOffset });
|
syncMailbox(false, { offset: mailFeatureState.pageOffset });
|
||||||
};
|
};
|
||||||
$('#load-more').onclick = () => syncMailbox(false, { append: true });
|
$('#load-more').onclick = () => syncMailbox(false, { append: true });
|
||||||
document.addEventListener('click', async event => {
|
document.addEventListener('click', async event => {
|
||||||
const sendButton = event.target.closest('#send');
|
const sendButton = event.target.closest('#send');
|
||||||
if (!sendButton || !connectedMailAccount) return;
|
if (!sendButton || !mailFeatureState.connectedAccount) return;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
const recipient = $('#compose-to').value.trim();
|
const recipient = $('#compose-to').value.trim();
|
||||||
@@ -749,7 +750,7 @@ if (window.daybreakMail) {
|
|||||||
subject: $('#compose-subject').value.trim(),
|
subject: $('#compose-subject').value.trim(),
|
||||||
text: $('#compose-body').value,
|
text: $('#compose-body').value,
|
||||||
attachments: $('#modal-root .compose-modal')?._composeAttachments || [],
|
attachments: $('#modal-root .compose-modal')?._composeAttachments || [],
|
||||||
displayName: connectedMailAccount.displayName || window.epMailFeatures.productivity?.profileName || '',
|
displayName: mailFeatureState.connectedAccount.displayName || window.epMailFeatures.productivity?.profileName || '',
|
||||||
...(pgp ? { pgp } : {})
|
...(pgp ? { pgp } : {})
|
||||||
});
|
});
|
||||||
if (result.failed) {
|
if (result.failed) {
|
||||||
@@ -763,15 +764,15 @@ if (window.daybreakMail) {
|
|||||||
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
||||||
$('#modal-root').innerHTML = '';
|
$('#modal-root').innerHTML = '';
|
||||||
toast('Offline: message queued and will send when connected');
|
toast('Offline: message queued and will send when connected');
|
||||||
if (activeFolder === 'Drafts') void syncMailbox(false);
|
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const draftId = $('#modal-root .compose-modal')?.dataset.draftId;
|
const draftId = $('#modal-root .compose-modal')?.dataset.draftId;
|
||||||
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
if (draftId) await window.daybreakMail.deleteDraft(draftId);
|
||||||
$('#modal-root').innerHTML = '';
|
$('#modal-root').innerHTML = '';
|
||||||
toast(result.savedToSent ? 'Message sent and saved in Sent' : 'Message sent, but its Sent copy could not be saved');
|
toast(result.savedToSent ? 'Message sent and saved in Sent' : 'Message sent, but its Sent copy could not be saved');
|
||||||
if (activeFolder === 'Sent') syncMailbox(false, { offset: 0 });
|
if (rendererState.activeFolder === 'Sent') syncMailbox(false, { offset: 0 });
|
||||||
if (activeFolder === 'Drafts') void syncMailbox(false);
|
if (rendererState.activeFolder === 'Drafts') void syncMailbox(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
sendButton.disabled = false;
|
sendButton.disabled = false;
|
||||||
sendButton.textContent = 'Send ↗';
|
sendButton.textContent = 'Send ↗';
|
||||||
@@ -781,7 +782,7 @@ if (window.daybreakMail) {
|
|||||||
|
|
||||||
window.daybreakMail.getAccount().then(account => {
|
window.daybreakMail.getAccount().then(account => {
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
connectedMailAccount = account;
|
mailFeatureState.connectedAccount = account;
|
||||||
updateAccountCard(account);
|
updateAccountCard(account);
|
||||||
syncMailbox(false);
|
syncMailbox(false);
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
@@ -789,9 +790,9 @@ if (window.daybreakMail) {
|
|||||||
|
|
||||||
const mailUiApi = window.epMailUiModules.createMailUiApi({
|
const mailUiApi = window.epMailUiModules.createMailUiApi({
|
||||||
state: window.epMailState,
|
state: window.epMailState,
|
||||||
getConnectedAccount: () => connectedMailAccount,
|
getConnectedAccount: () => mailFeatureState.connectedAccount,
|
||||||
setConnectedAccount: account => { connectedMailAccount = account; },
|
setConnectedAccount: account => { mailFeatureState.connectedAccount = account; },
|
||||||
setPageOffset: offset => { mailPageOffset = offset; },
|
setPageOffset: offset => { mailFeatureState.pageOffset = offset; },
|
||||||
syncMailbox,
|
syncMailbox,
|
||||||
updateAccountCard,
|
updateAccountCard,
|
||||||
getRenderList: () => renderList,
|
getRenderList: () => renderList,
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ function pgpAvailable() { return Boolean(window.daybreakMail?.pgp); }
|
|||||||
|
|
||||||
function openEncryptionKeys() {
|
function openEncryptionKeys() {
|
||||||
const root = $('#modal-root');
|
const root = $('#modal-root');
|
||||||
const account = connectedMailAccount || {};
|
const account = window.epMailFeatures.mail.connectedAccount || {};
|
||||||
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal attachments-modal"><div class="modal-head"><span>Encryption keys</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields">
|
root.innerHTML = `<div class="modal-overlay"><div class="compose-modal attachments-modal"><div class="modal-head"><span>Encryption keys</span><button class="modal-close" aria-label="Close">×</button></div><div class="compose-fields">
|
||||||
<p class="account-note">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.</p>
|
<p class="account-note">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.</p>
|
||||||
<div id="pgp-key-list" class="attachment-list">Loading keys…</div>
|
<div id="pgp-key-list" class="attachment-list">Loading keys…</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user