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:
@@ -1433,13 +1433,26 @@ initializeDatabase().then(() => {
|
|||||||
});
|
});
|
||||||
const mid = String(info.messageId || '').replace(/[<>]/g, '');
|
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,
|
`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)
|
from_addr, to_addr, subject, body_text, attachments_json, seen, email_date)
|
||||||
VALUES (?, 'out', ?, ?, ?, ?, ?, ?, ?, ?, 1, ?)`,
|
VALUES (?, 'out', ?, ?, ?, ?, ?, ?, ?, ?, 1, ?)`,
|
||||||
[id, mid, inReplyTo ? inReplyTo.replace(/[<>]/g, '') : null, references ? references.replace(/[<>]/g, '') : null,
|
[id, mid, inReplyTo ? inReplyTo.replace(/[<>]/g, '') : null, references ? references.replace(/[<>]/g, '') : null,
|
||||||
mailer.fromAddress(), to, subject, body, JSON.stringify(attNames), new Date().toISOString()]
|
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]);
|
await dbRun('UPDATE bewerbungen SET email_empfaenger = ? WHERE id = ?', [to, id]);
|
||||||
|
|
||||||
res.redirect(back('?mailok=' + encodeURIComponent('E-Mail an ' + to + ' gesendet.') + '#korrespondenz'));
|
res.redirect(back('?mailok=' + encodeURIComponent('E-Mail an ' + to + ' gesendet.') + '#korrespondenz'));
|
||||||
|
|||||||
Reference in New Issue
Block a user