From 9203dbb0c57df0ba1c30d27b4ad7434e25c505e2 Mon Sep 17 00:00:00 2001 From: ryneeverett Date: Wed, 4 Mar 2020 02:25:13 +0000 Subject: [PATCH] Enable piping html to browser without scripts. Many browsers (including chromium) require that files end in the '.html' extension in order to render them. See . When using `pipeto --format=mimepart --as_file`, on an html mime part, let's automatically set the file extension. This eliminates the need for additional user scripts referenced in issues such as #789 and #1153. --- alot/commands/thread.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/alot/commands/thread.py b/alot/commands/thread.py index bb8c9228c..d7c85eba8 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -769,7 +769,9 @@ async def apply(self, ui): # Pass mail as temporary file rather than piping through stdin. if self.as_file: - with tempfile.NamedTemporaryFile(delete=False) as tmpfile: + suffix = {'html': '.html'}.get(mimepart.get_content_subtype()) + with tempfile.NamedTemporaryFile( + delete=False, suffix=suffix) as tmpfile: tmpfile.write(mail.encode(urwid.util.detected_encoding)) tempfile_name = tmpfile.name mail = None