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 @@ <% } %> - -
+ +