From 30f83d433a1b31eebcfa2e6f11f7912e71c310f7 Mon Sep 17 00:00:00 2001 From: Thomas Hackner Date: Mon, 6 Jul 2026 15:47:07 +0200 Subject: [PATCH] =?UTF-8?q?Gesendete=20Anh=C3=A4nge=20in=20Korrespondenz?= =?UTF-8?q?=20anzeigen=20(email=5Fanhaenge=20verkn=C3=BCpfen)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- server.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index f45e3e0..fd0a30b 100644 --- a/server.js +++ b/server.js @@ -1433,13 +1433,26 @@ initializeDatabase().then(() => { }); const mid = String(info.messageId || '').replace(/[<>]/g, ''); - await dbRun( + const emailRow = await dbRun( `INSERT INTO emails (bewerbung_id, direction, message_id, in_reply_to, email_references, from_addr, to_addr, subject, body_text, attachments_json, seen, email_date) VALUES (?, 'out', ?, ?, ?, ?, ?, ?, ?, ?, 1, ?)`, [id, mid, inReplyTo ? inReplyTo.replace(/[<>]/g, '') : null, references ? references.replace(/[<>]/g, '') : null, mailer.fromAddress(), to, subject, body, JSON.stringify(attNames), new Date().toISOString()] ); + + // Keep a copy of each sent attachment linked to the outgoing message so it + // is shown (and can be reopened) in the correspondence view afterwards. + for (const att of attachments) { + const safe = String(att.filename || 'anhang').replace(/[^a-zA-Z0-9äöüÄÖÜß._ -]/g, '_').slice(0, 80); + const storedName = `${emailRow.lastID}_${Date.now()}_${safe}`; + try { + fs.copyFileSync(att.path, path.join(emailAnhaengeDir, storedName)); + await dbRun('INSERT INTO email_anhaenge (email_id, name, mime, pfad) VALUES (?, ?, ?, ?)', + [emailRow.lastID, att.filename, att.contentType || null, storedName]); + } catch (e) { /* ignore a single bad attachment */ } + } + await dbRun('UPDATE bewerbungen SET email_empfaenger = ? WHERE id = ?', [to, id]); res.redirect(back('?mailok=' + encodeURIComponent('E-Mail an ' + to + ' gesendet.') + '#korrespondenz'));