From 634083d3ae1185a9b442fd8600097f357aa13f2b Mon Sep 17 00:00:00 2001 From: Ray Andrew Date: Thu, 4 Dec 2025 14:41:19 -0600 Subject: [PATCH] view email html improvement --- bin/view-email-html | 83 +++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/bin/view-email-html b/bin/view-email-html index 33a8502..403ed74 100755 --- a/bin/view-email-html +++ b/bin/view-email-html @@ -29,27 +29,36 @@ else echo '' echo "" echo "" echo '' echo "" # Extract and display headers (handles multi-line headers) @@ -108,13 +117,15 @@ else # Only split To, CC, Bcc addresses (not Date, Subject, From) if (tolower(header) ~ /^(to|cc|bcc)$/) { n = split_addresses(value, addrs) + printf "

" header ": " if (n > 1) { - print "

" header ":

" + for (i=1; i<=n; i++) printf "" addrs[i] "" } else { - print "

" header ": " value "

" + printf "" value "" } + print "

" + } else if (tolower(header) == "subject") { + print "

" header ": " value "

" } else { print "

" header ": " value "

" } @@ -150,15 +161,40 @@ else else body_content=$(sed '1,/^$/d' "$emlfile") fi - # Process body: escape HTML, handle code blocks and inline code + # Process body: escape HTML, handle code blocks, inline code, and quoted text + # First pass: detect quote blocks (lines starting with > followed by more > lines) echo "$body_content" | awk ' - BEGIN { incode=0 } + BEGIN { incode=0; inquote=0; quotebuf=""; quotecount=0 } + function flush_quote() { + if (quotebuf != "") { + # Only make collapsible if we have 3+ quoted lines + n = split(quotebuf, lines, "\n") + if (n >= 3) { + print "
▶ Show quoted text (" n " lines)
"
+                        print quotebuf
+                        print "
" + } else { + print "" quotebuf "" + } + quotebuf = "" + } + } /^```/ { + flush_quote() if (incode) { print ""; incode=0 } else { print "
"; incode=1 }
                 next
             }
+            /^>/ {
+                if (incode) { gsub(//, "\\>"); print; next }
+                gsub(//, "\\>")
+                if (quotebuf != "") quotebuf = quotebuf "\n"
+                quotebuf = quotebuf $0
+                next
+            }
             {
+                flush_quote()
                 gsub(//, "\\>")
                 if (!incode) {
@@ -172,7 +208,10 @@ else
                 }
                 print
             }
-            END { if (incode) print "
" } + END { + flush_quote() + if (incode) print "" + } ' echo ""