share
Unix & LinuxHow do I troubleshoot Mutt html preview choking?
[+7] [2] Amanda
[2018-05-22 17:29:57]
[ mutt ]
[ https://unix.stackexchange.com/questions/445390/how-do-i-troubleshoot-mutt-html-preview-choking ]

For a while now I've found that when I try to view an HTML file in my browser (from Mutt, v to see all attachments, select the text/html attachment and enter) my browser opens a new tab at file:///tmp/mutt.html but consistently says

File not found

Firefox can’t find the file at /tmp/mutt.html.

Check the file name for capitalization or other typing errors. Check to see if the file was moved, renamed or deleted.

I'm not quite sure how to troubleshoot this. It worked fine until it didn't. And then just to keep me on my toes every 10th or 12th time it randomly does show the HTML mail.

For instance, just now, I ...

So ... where should I be looking for some indication of why mutt html messages sometimes open just fine in a browser and sometimes /tmp/mutt.html can't be found?

[+8] [2018-05-23 12:52:18] ploth [ACCEPTED]

I had some trouble with that too. The mailcap entry for text/html is the point to look at. With chromium it was indeed the needsterminal flag. For firefox the copiousoutput [1] flag did the trick.

#text/html; chromium %s; needsterminal
text/html; firefox %s;copiousoutput 

If you don't already have a custom mailcap, you can create a file at ~/.mailcap for example and add the firefox line to it. Don't forget to specify the path in your .muttrc

set mailcap_path  = ~/.mailcap
[1] https://linux.die.net/man/4/mailcap

/etc/mailcap has multiple entries for text/html; -- is there a best practice for me to follow here? Should I be editing /etc/mailcap/ or creating my own ~/.mailcap file with custom entries? - Amanda
Don't edit /etc/mailcap and create your own ~/.mailcap instead. - ploth
1
[+6] [2018-05-22 18:59:31] Juancho

Maybe it is a race condition between Firefox command line returning to mutt, and mutt deleting the temporary file before the Firefox process actually reads the file.

Try, in your mailcap entry, adding the needsterminal flag.

Or even better, instead of calling Firefox directly, call a simple shell script of yours that copies the html file with another name and then calls Firefox on that new file, before returning command to mutt (which will delete the original file).

Some people add a sleep command after calling firefox. See here [1] or here [2] for example (search for sleep).

[1] https://gist.github.com/fwolf/f5bf675c80b818bd1941971853ae2422
[2] https://gitlab.com/muttmua/mutt/wikis/MuttFaq/Attachment

(1) text/html; /usr/bin/firefox %s & sleep 10 ; copiousoutput was the working solution for me. - Martin T.
2