diff --git a/TODO.md b/TODO.md index f6e1d08..460bb34 100644 --- a/TODO.md +++ b/TODO.md @@ -13,10 +13,12 @@ - [x] Make **EP Wasteland** the default theme for new users. - [x] Move theme selection into Settings and save the selection so the chosen theme is applied every time the program starts. -- [x] Move the display name field from general Settings into Account Settings. +- [x] Keep the display name in Account Settings and make it available while adding a mailbox. ## Account settings -- [ ] Add an **Edit** button for each connected mail account so its account settings can be changed after setup. +- [x] Add an **Edit** button for each connected mail account so its account settings can be changed after setup. - [ ] Move CalDAV and CardDAV server configuration into Account Settings, removing the server settings controls from the Calendar and Contacts views. - [x] Keep general Settings focused on appearance and other app-wide preferences rather than the display name. +- [ ] Display name must be set per account. +- [ ] Remove the display name initials from the bottom-left corner. diff --git a/account-ui.js b/account-ui.js index fe24b16..c91c731 100644 --- a/account-ui.js +++ b/account-ui.js @@ -3,7 +3,7 @@ async function openAccountManager(){ try{ const data=await window.daybreakMail.listAccounts(); const accounts=data.accounts||[]; - const rows=accounts.map(account=>`
${esc(account.email)}${esc(account.imapHost)} · ${esc(account.smtpHost)}
${account.id===data.activeId?'':``}
`).join(''); + const rows=accounts.map(account=>`
${esc(account.email)}${esc(account.imapHost)} · ${esc(account.smtpHost)}
${account.id===data.activeId?'':``}
`).join(''); root.innerHTML=``; const close=()=>root.innerHTML=''; root.querySelectorAll('.modal-close').forEach(button=>button.onclick=close); @@ -12,6 +12,8 @@ async function openAccountManager(){ root.onclick=async event=>{ const switchButton=event.target.closest('[data-switch-account]'); if(switchButton){switchButton.disabled=true;try{connectedMailAccount=await window.daybreakMail.selectAccount(switchButton.dataset.switchAccount);activeFolder='Inbox';mailPageOffset=0;document.querySelectorAll('.folder').forEach(button=>button.classList.toggle('active',button.dataset.folder==='Inbox'));$('#sidebar-title').textContent='Inbox';$('#crumb-current').textContent='Inbox';updateAccountCard(connectedMailAccount);close();await syncMailbox(true,{offset:0})}catch(error){toast(error.message||'Could not switch accounts');switchButton.disabled=false}return} + const editButton=event.target.closest('[data-edit-account]'); + if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)openMailAccount(account);return} const removeButton=event.target.closest('[data-remove-account]'); if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;connectedMailAccount=active;if(active){updateAccountCard(active);close();activeFolder='Inbox';mailPageOffset=0;await syncMailbox(false,{offset:0})}else{updateAccountCard({email:'Connect a mailbox',imapHost:''});messages.splice(0,messages.length);renderList();$('#reader-pane').innerHTML=emptyReader();toast('Mail account removed');openAccountManager()}}catch(error){toast(error.message||'Could not remove the account');removeButton.disabled=false}return} }; diff --git a/desktop/main.cjs b/desktop/main.cjs index f55aae9..a3bf510 100644 --- a/desktop/main.cjs +++ b/desktop/main.cjs @@ -274,6 +274,22 @@ ipcMain.handle('mail:remove-account', async (_event, accountId) => { return { accounts: store.accounts.map(publicAccount), activeId: store.activeId }; }); +ipcMain.handle('mail:update-account', async (_event, accountId, input) => { + const store = await readAccountStore(); + const existing = store?.accounts.find(account => account.id === accountId); + if (!existing) throw new Error('That mail account is no longer available.'); + const account = normalizeAccount({ ...existing, ...input, password: String(input?.password || '') || existing.password }); + account.id = existing.id; + try { + const status = await connectMail(account); + store.accounts = store.accounts.map(item => item.id === existing.id ? account : item); + await saveAccountStore(store); + return { ...publicAccount(account), ...status }; + } catch (error) { + throw new Error(`Could not update the mailbox: ${error.message}`); + } +}); + ipcMain.handle('mail:connect', async (_event, input) => { const account = normalizeAccount(input); try { @@ -375,8 +391,9 @@ ipcMain.handle('mail:send', async (_event, message) => { if (!to) throw new Error('Add at least one recipient.'); const transport = smtpTransport(account); const sentMessageId = `<${require('node:crypto').randomUUID()}@ep-mail.local>`; + const fromName = String(message.displayName || account.email).replace(/[\r\n]+/g, ' ').trim().slice(0, 80) || account.email; const messageOptions = { - from: { name: account.email, address: account.email }, + from: { name: fromName, address: account.email }, to, cc: String(message.cc || '').trim() || undefined, subject: String(message.subject || '(no subject)').slice(0, 998), diff --git a/desktop/preload.cjs b/desktop/preload.cjs index 9ead33d..389e564 100644 --- a/desktop/preload.cjs +++ b/desktop/preload.cjs @@ -6,6 +6,7 @@ contextBridge.exposeInMainWorld('daybreakMail', { selectAccount: id => ipcRenderer.invoke('mail:select-account', id), removeAccount: id => ipcRenderer.invoke('mail:remove-account', id), connect: details => ipcRenderer.invoke('mail:connect', details), + updateAccount: (id, details) => ipcRenderer.invoke('mail:update-account', id, details), syncFolder: (folder, offset) => ipcRenderer.invoke('mail:sync-folder', folder, offset), syncInbox: () => ipcRenderer.invoke('mail:sync-folder', 'INBOX'), updateMessage: details => ipcRenderer.invoke('mail:update-message', details), diff --git a/mail-ui.js b/mail-ui.js index bf7e4a6..15acb0e 100644 --- a/mail-ui.js +++ b/mail-ui.js @@ -16,45 +16,62 @@ function updateAccountCard(account) { card.querySelector('.online-dot').style.background = '#70ad7b'; } -function openMailAccount() { +function openMailAccount(existingAccount = null) { const root = $('#modal-root'); - const current = {}; - root.innerHTML = ``; + const editing = Boolean(existingAccount); + const displayName = profileSettings.name || ''; + root.innerHTML = ``; 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 = async () => { - close(); - }; + $('#disconnect-mail').onclick = close; $('#connect-mail').onclick = async () => { const button = $('#connect-mail'); const status = $('#mail-account-status'); const password = $('#mail-account-password').value; - if (!password) { status.textContent = 'Enter the mailbox password to connect.'; $('#mail-account-password').focus(); return; } + const name = $('#mail-account-display-name').value.trim(); + if (!editing && !password) { status.textContent = 'Enter the mailbox password to connect.'; $('#mail-account-password').focus(); return; } button.disabled = true; - button.textContent = 'Checking secure connections…'; - status.textContent = 'Checking IMAP and SMTP sign-in. This may take a moment.'; + 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 account = await window.daybreakMail.connect({ + const details = { email: $('#mail-account-email').value, password, imapHost: $('#mail-account-imap').value, smtpHost: $('#mail-account-smtp').value - }); - connectedMailAccount = account; - updateAccountCard(account); - close(); - toast('Mailbox connected securely'); - await syncMailbox(true); + }; + const account = editing + ? await window.daybreakMail.updateAccount(existingAccount.id, details) + : await window.daybreakMail.connect(details); + if (name) setProfileName(name); + if (editing) { + const accountList = await window.daybreakMail.listAccounts(); + if (accountList.activeId === account.id) { + connectedMailAccount = account; + updateAccountCard(account); + mailPageOffset = 0; + close(); + await syncMailbox(false, { offset: 0 }); + } else { + close(); + } + toast('Mailbox settings updated'); + } else { + connectedMailAccount = account; + updateAccountCard(account); + close(); + toast('Mailbox connected securely'); + await syncMailbox(true); + } } catch (error) { status.textContent = error.message || 'Could not connect. Check the account details and try again.'; button.disabled = false; - button.textContent = 'Test & connect'; + button.textContent = editing ? 'Save & reconnect' : 'Test & connect'; } }; $('#mail-account-email').focus(); } - async function syncMailbox(showToast, options = {}) { if (!connectedMailAccount || !window.daybreakMail) { openMailAccount(); @@ -138,7 +155,8 @@ if (window.daybreakMail) { to: recipient, cc: $('#compose-cc').value, subject: $('#compose-subject').value.trim(), - text: $('#compose-body').value + text: $('#compose-body').value, + displayName: profileSettings.name }); $('#modal-root').innerHTML = ''; toast(result.savedToSent ? 'Message sent and saved in Sent' : 'Message sent, but its Sent copy could not be saved');