Reply-Mail: Zeilenumbrüche als <br> statt white-space:pre-wrap

Ausgehende Antwort-Mails (multipart/alternative) rendern den HTML-Teil
bisher über white-space:pre-wrap auf rohen Zeilenumbrüchen ohne <br>.
Beim ersten Empfang korrekt, aber sobald der Empfänger-Client (Outlook)
die Mail zitiert, wird der pre-wrap-Stil verworfen und die nackten
Newlines zu Leerzeichen kollabiert -> unser formatiertes Anschreiben wird
im Zitat zur zusammenhanglosen Textwand. Explizite <br> überleben diesen
Round-Trip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 09:18:44 +00:00
co-authored by Claude Opus 4.8
parent 4e1043897d
commit 17df46cb6c
+14 -4
View File
@@ -62,12 +62,22 @@ async function verify() {
}
// Minimal HTML rendering of a plain-text body: escape, then turn newlines into
// <br>. Sending multipart/alternative (text + html) reads as normal personal
// mail and avoids the "text-only, no html" heuristic some filters apply.
// explicit <br> tags. Sending multipart/alternative (text + html) reads as
// normal personal mail and avoids the "text-only, no html" heuristic some
// filters apply.
//
// The line breaks MUST be real <br> tags, not merely CSS white-space:pre-wrap
// on literal newlines: pre-wrap renders correctly on first receipt, but when
// the recipient's client (e.g. Outlook) quotes the message back to us it
// re-parses the HTML, drops the pre-wrap style and collapses the bare newlines
// into spaces — turning our carefully formatted reply into a run-on wall of
// text in the quoted thread. Explicit <br> survives that round-trip.
function textToHtml(text) {
const esc = String(text || '')
.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return `<div style="font-family:Arial,Helvetica,sans-serif;font-size:14px;line-height:1.5;color:#1a1a1a;white-space:pre-wrap">${esc}</div>`;
.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(/\r\n?/g, '\n')
.replace(/\n/g, '<br>\n');
return `<div style="font-family:Arial,Helvetica,sans-serif;font-size:14px;line-height:1.5;color:#1a1a1a">${esc}</div>`;
}
// Send one message via authenticated submission. Returns nodemailer info