Subject: [PATCH links] Strips, if present, the mbox From line when piping emails to the links-email binary.

From: Peter Sanchez <[email-masked]>
Date: Wed, 7 Jan 2026 18:16:31 -0600

Addresses failed header parsing when piped via Postfix.

References: https://todo.code.netlandish.com/~netlandish/links/132
---
 cmd/email/main.go | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/cmd/email/main.go b/cmd/email/main.go
index f1879fb..9461058 100644
--- a/cmd/email/main.go
+++ b/cmd/email/main.go
@@ -2,6 +2,7 @@ package main
 
 import (
 	"bufio"
+	"bytes"
 	"context"
 	"flag"
 	"fmt"
@@ -157,7 +158,20 @@ func run(logger *log.Logger) error {
 }
 
 func parseEmail(r io.Reader) (*parsedEmail, error) {
-	mr, err := mail.CreateReader(r)
+	data, err := io.ReadAll(r)
+	if err != nil {
+		return nil, err
+	}
+
+	// strip mbox "From " envelope line if present
+	// (Postfix adds this when piping to programs)
+	if bytes.HasPrefix(data, []byte("From ")) {
+		if idx := bytes.IndexByte(data, '\n'); idx != -1 {
+			data = data[idx+1:]
+		}
+	}
+
+	mr, err := mail.CreateReader(bytes.NewReader(data))
 	if err != nil {
 		return nil, err
 	}
-- 
2.52.0