From 89c8c6db975b1d539925157f0c8ef22f03a88d3d Mon Sep 17 00:00:00 2001 From: Thomas Hackner Date: Sat, 4 Jul 2026 18:55:23 +0200 Subject: [PATCH] Delete e-mails from the Postfach; searchable assignment picker Each Postfach e-mail gets a Delete button (POST /postfach/:id/delete), which also removes stored attachment files. The plain assignment dropdown is replaced by a searchable combobox that filters applications by company, position and city, with keyboard navigation. Co-Authored-By: Claude Opus 4.8 --- server.js | 17 ++++++ views/postfach.ejs | 131 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 130 insertions(+), 18 deletions(-) diff --git a/server.js b/server.js index fd9854f..0faae73 100644 --- a/server.js +++ b/server.js @@ -1341,6 +1341,23 @@ initializeDatabase().then(() => { } }); + // Delete an e-mail from the Postfach (removes its stored attachment files too). + app.post('/postfach/:emailId/delete', async (req, res) => { + try { + const emailId = req.params.emailId; + const atts = await dbAll('SELECT pfad FROM email_anhaenge WHERE email_id = ?', [emailId]); + for (const a of atts) { + fs.promises.unlink(path.join(emailAnhaengeDir, a.pfad)).catch(() => {}); + } + await dbRun('DELETE FROM email_anhaenge WHERE email_id = ?', [emailId]); + await dbRun('DELETE FROM emails WHERE id = ?', [emailId]); + res.redirect('/postfach?mailok=' + encodeURIComponent('E-Mail wurde gelöscht.')); + } catch (error) { + console.error('Error deleting e-mail:', error); + res.redirect('/postfach?mailerror=' + encodeURIComponent('Löschen fehlgeschlagen: ' + (error.message || 'Unbekannter Fehler'))); + } + }); + // Count of unlinked e-mails — drives the header badge on every page. app.get('/api/emails/unassigned-count', async (req, res) => { try { diff --git a/views/postfach.ejs b/views/postfach.ejs index 4117e11..efac268 100644 --- a/views/postfach.ejs +++ b/views/postfach.ejs @@ -77,24 +77,32 @@ <% } %> - -
-
- - -
- -
+ +
+
+
+ + + + +
+ +
+
+ +
+
<% }); %> @@ -111,6 +119,9 @@ <%- include('partials/footer') %> +