Warn about suspicious mail senders and links
Bump version to 0.1.21 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+33
-2
@@ -513,6 +513,11 @@ async function toUiMessage(item, folder) {
|
||||
const bodyText = String(parsed.text || '').replace(/\r/g, '').trim().slice(0, 20000);
|
||||
const body = bodyText ? bodyText.split(/\n\s*\n/).map(part => part.trim()).filter(Boolean).slice(0, 40) : ['This message has no plain-text body.'];
|
||||
const date = parsed.date || item.internalDate || new Date();
|
||||
const html = Array.isArray(parsed.html) ? parsed.html.join('') : String(parsed.html || '');
|
||||
const links = [...html.matchAll(/<a\b[^>]*\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi)]
|
||||
.map(match => (match[1] || match[2] || match[3] || '').replace(/&/gi, '&').replace(///gi, '/'))
|
||||
.filter(Boolean)
|
||||
.slice(0, 30);
|
||||
return {
|
||||
id: Number(item.uid),
|
||||
initials: (sender?.name || sender?.address || '?').split(/[\s@]+/).filter(Boolean).map(word => word[0]).join('').slice(0, 2).toUpperCase(),
|
||||
@@ -532,6 +537,7 @@ async function toUiMessage(item, folder) {
|
||||
deleted: folder === 'Trash',
|
||||
sourceFolder: folder,
|
||||
body,
|
||||
links,
|
||||
uid: Number(item.uid),
|
||||
attachments: (parsed.attachments || []).map(file => ({ filename: file.filename || 'attachment', size: file.size || 0 })),
|
||||
attachment: parsed.attachments?.[0]?.filename || null,
|
||||
@@ -1097,6 +1103,32 @@ ipcMain.handle('mail:save-attachment', async (event, input) => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('mail:open-external', async (event, rawUrl) => {
|
||||
let target;
|
||||
try {
|
||||
target = new URL(String(rawUrl || ''));
|
||||
} catch {
|
||||
throw new Error('This link is not a valid web address.');
|
||||
}
|
||||
if (!['http:', 'https:'].includes(target.protocol) || target.username || target.password) {
|
||||
throw new Error('Only standard web links can be opened from mail.');
|
||||
}
|
||||
const parent = BrowserWindow.fromWebContents(event.sender);
|
||||
const confirmation = await dialog.showMessageBox(parent, {
|
||||
type: 'warning',
|
||||
title: 'Open external link?',
|
||||
message: 'Email links can lead to fake sign-in pages or harmful content.',
|
||||
detail: `Check the full address before continuing:\n${target.href}`,
|
||||
buttons: ['Cancel', 'Open link'],
|
||||
defaultId: 0,
|
||||
cancelId: 0,
|
||||
noLink: true
|
||||
});
|
||||
if (confirmation.response !== 1) return { opened: false };
|
||||
await shell.openExternal(target.href);
|
||||
return { opened: true };
|
||||
});
|
||||
|
||||
ipcMain.handle('mail:sync-inbox', async () => {
|
||||
const account = await readAccount();
|
||||
if (!account) throw new Error('Add a mail account before syncing.');
|
||||
@@ -1356,8 +1388,7 @@ function createWindow() {
|
||||
window.once('ready-to-show', () => window.show());
|
||||
|
||||
window.loadFile(path.join(__dirname, '..', 'index.html'));
|
||||
window.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (url.startsWith('https://') || url.startsWith('mailto:')) shell.openExternal(url);
|
||||
window.webContents.setWindowOpenHandler(() => {
|
||||
return { action: 'deny' };
|
||||
});
|
||||
window.webContents.on('will-navigate', (event, url) => {
|
||||
|
||||
Reference in New Issue
Block a user