Something went wrong. Try again.
Kagi Mail CLI client
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374package render
import ( "bytes" "strings" "testing" "time"
"tangled.org/matilde.at/km/internal/mail")
func testThread() []mail.Email { t0 := time.Date(2026, 11, 10, 9, 0, 0, 0, time.UTC) body := func(s string) map[string]mail.BodyValue { return map[string]mail.BodyValue{"1": {Value: s}} } text := []mail.BodyPart{{PartID: "1", Type: "text/plain"}} return []mail.Email{ {ID: "e1", Subject: "Hello", ReceivedAt: t0, Keywords: map[string]bool{"$seen": true}, From: []mail.Address{{Name: "Ann", Email: "ann@example.org"}}, Preview: "first body", BodyValues: body("first body"), TextBody: text}, {ID: "e2", Subject: "Re: Hello", ReceivedAt: t0.Add(time.Hour), From: []mail.Address{{Email: "bo@example.org"}}, To: []mail.Address{{Name: "Ann", Email: "ann@example.org"}}, Cc: []mail.Address{{Email: "cy@example.org"}}, BodyValues: body("second body\r\n"), TextBody: text, Attachments: []mail.BodyPart{ {Name: "a.pdf", Type: "application/pdf", Size: 2048, Disposition: "attachment"}, {Name: "i.png", Type: "image/png", Size: 100, Disposition: "inline", CID: "x"}, }}, {ID: "e3", Subject: "Re: Hello", ReceivedAt: t0.Add(2 * time.Hour), Keywords: map[string]bool{"$seen": true}, From: []mail.Address{{Email: "ann@example.org"}}, BodyValues: body("third body"), TextBody: text}, }}
func TestThreadCollapsesOldReadMessages(t *testing.T) { var b bytes.Buffer p := &Printer{Out: &b} p.Thread(&b, "Hello", testThread()) out := b.String() if strings.Contains(out, "first body") && !strings.Contains(out, "first body\n\n") { t.Errorf("unexpected:\n%s", out) } for _, want := range []string{ "Hello\n3 messages\n", "Ann 2026-11-10T09:00:00Z e1 first body\n", // collapsed, whitespace squeezed "Cc: cy@example.org\n", "ID: e2\n", "Flags: unread\n", " a.pdf application/pdf 2K\n", " i.png image/png 100B (inline)\n", "second body\n", "ID: e3\n", "third body\n", } { if !strings.Contains(out, want) { t.Errorf("missing %q in:\n%s", want, out) } } if strings.Contains(out, "ID: e1") { t.Errorf("read message e1 not collapsed:\n%s", out) }}
func TestAttachmentsInline(t *testing.T) { e := testThread()[1] atts := Attachments(&e) if len(atts) != 2 || atts[0].Inline || !atts[1].Inline { t.Errorf("%+v", atts) }}
func TestHTMLBody(t *testing.T) { e := mail.Email{ BodyValues: map[string]mail.BodyValue{"1": {Value: "<p>x</p>"}}, HTMLBody: []mail.BodyPart{{PartID: "1", Type: "text/html"}}, } if got := HTMLBody(&e); got != "<p>x</p>" { t.Errorf("%q", got) }}