This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

mutt: add H keybinding to view HTML emails in browser

Converts embedded images to base64 data URIs so they display correctly.

+45
+45
tools/mutt/flake-module.nix
··· 18 18 text/html; ${pkgs.elinks}/bin/elinks -dump ; copiousoutput; 19 19 ''; 20 20 21 + # Script to view HTML emails in browser with embedded images 22 + viewHtmlBrowser = pkgs.writeShellScriptBin "view-html-browser" '' 23 + set -euo pipefail 24 + tmpfile=$(mktemp --suffix=.html) 25 + trap 'rm -f "$tmpfile"' EXIT 26 + 27 + ${pkgs.python3}/bin/python3 -c ' 28 + import email, sys, base64 29 + 30 + msg = email.message_from_file(sys.stdin) 31 + 32 + # Build map of Content-ID -> base64 data URI 33 + cid_map = {} 34 + for part in msg.walk(): 35 + cid = part.get("Content-ID", "").strip("<>") 36 + if cid and part.get_content_maintype() == "image": 37 + data = part.get_payload(decode=True) 38 + if data: 39 + mime = part.get_content_type() 40 + cid_map[cid] = f"data:{mime};base64,{base64.b64encode(data).decode()}" 41 + 42 + # Find HTML part 43 + html = None 44 + for part in msg.walk(): 45 + if part.get_content_type() == "text/html": 46 + payload = part.get_payload(decode=True) 47 + charset = part.get_content_charset() or "utf-8" 48 + html = payload.decode(charset, errors="replace") 49 + break 50 + 51 + if html: 52 + for cid, data_uri in cid_map.items(): 53 + html = html.replace(f"cid:{cid}", data_uri) 54 + print(html) 55 + else: 56 + print("<html><body><p>No HTML content found.</p></body></html>") 57 + ' > "$tmpfile" 58 + 59 + ${if pkgs.stdenv.isDarwin then "open" else "xdg-open"} "$tmpfile" 60 + sleep 2 61 + ''; 62 + 21 63 msmtprc = pkgs.writeText "msmtprc" '' 22 64 defaults 23 65 logfile ~/.msmtp.log ··· 170 212 # scan urls from emails 171 213 macro index,pager \cb "<pipe-message> ${lib.getExe pkgs.urlscan}<Enter>" 172 214 macro attach,compose \cb "<pipe-entry> ${lib.getExe pkgs.urlscan}<Enter>" 215 + 216 + # view HTML in graphical browser 217 + macro index,pager H "<pipe-message>${viewHtmlBrowser}/bin/view-html-browser<Enter>" "View HTML in browser" 173 218 174 219 # sidebar 175 220 set sidebar_divider_char = '│'