mailcap on Windows WSL

Jan Eden via Mutt-users <[email protected]>
Newsgroups gmane.mail.mutt.user
Message-ID <[email protected]>
Good morning,

I need to use mutt within the WSL of MS Windows. To display HTML
mails via mailcap, I created a small script which reads from STDIN,
writes a temporary file and opens it with the Edge browser:

# ~/.mutt/mailcap
text/html; ~/.mutt/htmlviewer html

# ~/.mutt/htmlviewer
with open('/var/tmp/htmlfile', 'w') as tmp_file:
	for line in sys.stdin:
		tmp_file.write(line)

This works for some messages, but for others, a UnicodeEncodeError is
returned:

'utf-8' can't encode character '...' in position ...: surrogates not
allowed

Since all of the messages affected were encoded in iso-8859-1, I tried
this (temporarily, with the intention of reading %{charset} from mutt
into the script later):

with open('/var/tmp/htmlfile', 'w', encoding='iso-8859-1') as tmp_file:
	...

but this only changed the error message to:

'latin-1' can't encode character '...' in position ...: ordinal not in
range(256)

How can I reliably write the input provided by mutt to a temporary file?

- Jan
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQQg9//YDsLBcpRDSgIg03s851X+OgUCZwTXaQAKCRAg03s851X+
OrlWAP96BbHsYkHTyVlFJa8LUazQhhfIGWeihstketT0KJoP+wD+OHjw/fj/yo2N
qIcZ8mRUA8UYNlGxwyQZzgaOGw9H6QE=
=4pI5
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.