From 6f26d790bae2733a5bb77f2a7845f5a2534752cb Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 04:55:44 +1000 Subject: [PATCH] fix(email): stop dropping the first paragraph of plain-text bodies extractBody re-split the already-isolated body on the first blank line it found, intending to strip a stray content-header block some MTAs emit. That heuristic can't distinguish a header block from an ordinary blank line between paragraphs, so any multi-paragraph plain-text email silently lost everything before the first paragraph break. --- internal/channels/email/email.go | 5 ----- internal/channels/email/email_test.go | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/channels/email/email.go b/internal/channels/email/email.go index 16f707d27..eec0b5848 100644 --- a/internal/channels/email/email.go +++ b/internal/channels/email/email.go @@ -244,11 +244,6 @@ func extractBody(raw string) string { } // Non-multipart: strip trailing SMTP dots. - body = strings.TrimSpace(body) - // Remove any quoted-printable or base64 content headers. - if parts := strings.SplitN(body, "\r\n\r\n", 2); len(parts) == 2 { - body = parts[1] - } return strings.TrimSpace(body) } diff --git a/internal/channels/email/email_test.go b/internal/channels/email/email_test.go index 00d4be007..9e4b45ff5 100644 --- a/internal/channels/email/email_test.go +++ b/internal/channels/email/email_test.go @@ -45,6 +45,23 @@ func TestExtractBodyPlain(t *testing.T) { } } +// TestExtractBodyMultiParagraph pins that a non-multipart plain-text body +// keeps every paragraph. extractBody used to re-split the body on the +// first "\r\n\r\n" it found -- intended to strip a stray content-header +// block some MTAs emit -- but that heuristic can't tell a header block +// from an ordinary blank line between paragraphs, so it silently dropped +// the first paragraph of any multi-paragraph email. +func TestExtractBodyMultiParagraph(t *testing.T) { + raw := "From: test@example.com\r\nSubject: Hello\r\n\r\nFirst paragraph.\r\n\r\nSecond paragraph." + got := extractBody(raw) + if !strings.Contains(got, "First paragraph.") { + t.Errorf("extractBody = %q, want it to contain %q", got, "First paragraph.") + } + if !strings.Contains(got, "Second paragraph.") { + t.Errorf("extractBody = %q, want it to contain %q", got, "Second paragraph.") + } +} + func TestExtractBodyMultipart(t *testing.T) { raw := "From: test@example.com\r\nContent-Type: multipart/alternative; boundary=abc123\r\n\r\n--abc123\r\nContent-Type: text/plain\r\n\r\nplain text here\r\n--abc123\r\nContent-Type: text/html\r\n\r\n\r\n--abc123--" if got := extractBody(raw); got != "plain text here" {