Ver V0.1.12
This commit is contained in:
+18
-1
@@ -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),
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user