Gesendete Anhänge in Korrespondenz anzeigen (email_anhaenge verknüpfen)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-06 15:47:07 +02:00
co-authored by Claude Opus 4.8
parent 4003279453
commit 30f83d433a
+14 -1
View File
@@ -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'));