From 7cd9c16ff9efc53246dd8b0e43fc6d3900ca7561 Mon Sep 17 00:00:00 2001 From: drew Date: Tue, 29 Jul 2025 14:00:38 +0400 Subject: [PATCH 1/4] fix: no more than 2 whitespaces (#17) --- view/html.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/view/html.go b/view/html.go index 37487482377f91d08d33b6c63bcb64f8e924593f..fd1de9237447a1a2043b6f861c696fbca7fb7811 100644 --- a/view/html.go +++ b/view/html.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "mime/quotedprintable" + "regexp" "strings" "github.com/PuerkitoBio/goquery" @@ -62,6 +63,12 @@ func ProcessBody(rawBody string) (string, error) { s.ReplaceWithHtml(hyperlink(href, s.Text())) }) - // Return the document's text content, which now includes our formatting - return doc.Text(), nil + // Get the text content, which now includes our formatting + text := doc.Text() + + // Collapse more than 2 consecutive newlines into 2 + re := regexp.MustCompile(`\n{3,}`) + text = re.ReplaceAllString(text, "\n\n") + + return text, nil } \ No newline at end of file From b138fc2dcbe6eec80141a3785167664d841609d9 Mon Sep 17 00:00:00 2001 From: drew Date: Tue, 29 Jul 2025 14:06:12 +0400 Subject: [PATCH 2/4] fix: download emails in filter (#19) --- tui/inbox.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tui/inbox.go b/tui/inbox.go index 5abfee614e3362a5370271213fceb4dc659cdf36..f470a6eb818c00d8ea85c6fc2fe603312419ea2e 100644 --- a/tui/inbox.go +++ b/tui/inbox.go @@ -136,6 +136,15 @@ func (m *Inbox) Update(msg tea.Msg) (tea.Model, tea.Cmd) { }) } + // New logic to fetch more emails when filtering is active + if m.list.FilterState() == list.Filtering && !m.isFetching { + m.isFetching = true + m.list.Title = "Fetching more emails..." + cmds = append(cmds, func() tea.Msg { + return FetchMoreEmailsMsg{Offset: uint32(m.emailsCount)} + }) + } + var cmd tea.Cmd var newModel list.Model newModel, cmd = m.list.Update(msg) From d3e30de1a93b299494238e2de91ba2e430f1bfae Mon Sep 17 00:00:00 2001 From: drew Date: Tue, 29 Jul 2025 14:09:19 +0400 Subject: [PATCH 3/4] fix: hyperlinks in md (#20) --- view/html.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/view/html.go b/view/html.go index fd1de9237447a1a2043b6f861c696fbca7fb7811..491b6c883a916b5f13dea963d07e184580695223 100644 --- a/view/html.go +++ b/view/html.go @@ -1,6 +1,7 @@ package view import ( + "bytes" "fmt" "io" "mime/quotedprintable" @@ -8,6 +9,8 @@ import ( "strings" "github.com/PuerkitoBio/goquery" + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/renderer/html" ) // hyperlink formats a string as a terminal-clickable hyperlink. @@ -27,6 +30,20 @@ func decodeQuotedPrintable(s string) (string, error) { return string(body), nil } +// markdownToHTML converts a Markdown string to an HTML string. +func markdownToHTML(md []byte) []byte { + var buf bytes.Buffer + p := goldmark.New( + goldmark.WithRendererOptions( + html.WithUnsafe(), // Allow raw HTML in email. + ), + ) + if err := p.Convert(md, &buf); err != nil { + return md // Fallback to original markdown. + } + return buf.Bytes() +} + // ProcessBody takes a raw email body, decodes it, and formats it as plain // text with terminal hyperlinks. func ProcessBody(rawBody string) (string, error) { @@ -36,7 +53,10 @@ func ProcessBody(rawBody string) (string, error) { decodedBody = rawBody } - doc, err := goquery.NewDocumentFromReader(strings.NewReader(decodedBody)) + // Convert markdown to HTML before processing + htmlBody := markdownToHTML([]byte(decodedBody)) + + doc, err := goquery.NewDocumentFromReader(bytes.NewReader(htmlBody)) if err != nil { return "", fmt.Errorf("could not parse email body: %w", err) } @@ -63,7 +83,7 @@ func ProcessBody(rawBody string) (string, error) { s.ReplaceWithHtml(hyperlink(href, s.Text())) }) - // Get the text content, which now includes our formatting + // Get the document's text content, which now includes our formatting text := doc.Text() // Collapse more than 2 consecutive newlines into 2 From b4e16cdf43076fe753c6b4b4eaf658925dc45d73 Mon Sep 17 00:00:00 2001 From: drew Date: Tue, 29 Jul 2025 14:16:17 +0400 Subject: [PATCH 4/4] fix: image as hyperlink (#4) --- view/html.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/view/html.go b/view/html.go index 491b6c883a916b5f13dea963d07e184580695223..76ff2157ab30131ad6605ee06986c8f1cfaea483 100644 --- a/view/html.go +++ b/view/html.go @@ -83,6 +83,20 @@ func ProcessBody(rawBody string) (string, error) { s.ReplaceWithHtml(hyperlink(href, s.Text())) }) + // Format images into terminal hyperlinks + doc.Find("img").Each(func(i int, s *goquery.Selection) { + src, exists := s.Attr("src") + if !exists { + return + } + alt, _ := s.Attr("alt") + + if alt == "" { + alt = "Does not contain alt text" + } + s.ReplaceWithHtml(hyperlink(src, fmt.Sprintf("\n [Click here to view image: %s] \n", alt))) + }) + // Get the document's text content, which now includes our formatting text := doc.Text()