pazz / alot

Terminal-based Mail User Agent
GNU General Public License v3.0
697 stars 165 forks source link

Html render with w3m #789

Open GuillaumeSeren opened 8 years ago

GuillaumeSeren commented 8 years ago

Hello there, I am a new user of alot, and already a big fan !

I search to display a bit better, some of the html mail that I may get (some people/company), didn't like plain text :( so I need a descent display for html and images.

I use is w3m because it can also render image in my terminal (rxvt), but when I read a mail in alot my html render is very simple, just the text is displayed with no color or images.

Here what I used in ~/.mailcap file: text/html; w3m -dump -o document_charset=%{charset} '%s'; nametemplate=%s.html; copiousoutput

Maybe w3m is not the better in alot, did someone manage to get it to work ?

andresmrm commented 8 years ago

Salut! =)

This is a problem I'm still wondering how to solve. For now I have two ways to view HTML:

  1. Inside Alot using a mailcap similar to yours
  2. Piping (pipeto) the HTML content to be rendered by a real browser (I set a hotkey for this).

I tried many HTML to text renders, but none seems a good option. w3m is good at keeping text formatting, but sometimes it hides links. And that can be very bad. E.g.:

Hi! Don't forget to check my report.

And I would reply:

Sure! But where is your report?

This happened a few times to me, so I started using Pandoc (pandoc --wrap=preserve --normalize --reference-links -i %s -f html -t plain). It breaks formatting, but marks links in text, so I know there is a link there.

The second path, piping to a browser, is good when you open a message an you realize it's not displaying right. The problem is when you don't realize that, like in the problem described above.

But it would be great to have better console display of messages: bold, italic, colors. Pandoc turns bold to CAPS, but... it's not the same thing. Colors could be used to mark links in HTML, and it would also help alot with quoted text. Sometimes quoted and new text get mixed, and it gets really hard to read.

lucc commented 8 years ago

Did any of you try elinks? I am using elinks and did not yet have any problems besides bad formatting (aliment, colors, bold, underline etc) but until now I attributed this to the terminal not being a good place to render html in general :) .

From my .mailcap:

text/html; elinks        %s; nametemplate=%s.html;
text/html; elinks -dump  %s; nametemplate=%s.html; copiousoutput;

I have no technical insight on this but I assume that it is not possible to get w3m to display the images if you -dump / use mailcap's copiosoutput. I assume that w3m can display them only if it has direct access to the terminal device (running in the terminal directly). But when you use the copiousoutput in the mailcap file (what alot does and should do) w3m will see a file or pipe at its output.

GuillaumeSeren commented 8 years ago

@andresmrm Yes I noticed the 'links problem' before, so when I have some doubt I use a better render (ie: browser), to check but it is not a convenient solution.

Originaly I was searching a way of displaying images (as in w3m) in alot, but didn't find a way, I think there could be a way using the framebuffer and python.

@lucc Maybe elinks do a better job I will try, thanks for the advice

GuillaumeSeren commented 8 years ago

@lucc After trying your mailcap config with elinks, I only get an output with the (-dump) version, with the other version I get no output at all, and the links are displayed in the bottom which is convenient.

But I try to display a webpage with both w3m and elinks, and it work well with w3m, but I did not get any form of format with elinks, and no image at all, did you manage to display image with elinks ?

lucc commented 8 years ago

No I did not get images and I also think it is not possible via mimecap file entries (see speculation above).

As far as I understand mailcap the only entry that is relevant for email readers (and other programs that use mailcap to get a rendered version of some data to display themselves) is the copiousoutput one. Sorry for posting the other one as well.

andresmrm commented 8 years ago

Thanks for the tip, Lucas. I had used elinks before and changed for a reason that I didn't remember. I tested it again these days and now I remember: it doesn't quote well previous messages. The line width it imposes break them.

guillaumecherel commented 7 years ago

Hi everyone, You mention using piping the HTML part of a message to a browser. How do you do that? The command pipeto sends the whole email file which is not HTML. How do you extract the relevant html part?

andresmrm commented 7 years ago

Hi, @guillaumecherel!

I pipe it to a script. =) And add a hotkey for it in alot:

    v = pipeto /myscripts/input_to_browser.py
GuillaumeSeren commented 7 years ago

Hey some life on this issue ! @andresmrm Thank you ! This script is really useful, I'd just try it it works well.

@lucc Sorry for the big delay but I didn't see your reply, I still not find a way of doing text/html rendering in w3m and pull it back into alot, but emacs seems to be able to change its default internal renderer to w3m (I didn't try it), so it could be a way.

lucc commented 7 years ago

@guillaumecherel about sending only the html part: I started a PR to add a mime tree view to alot it might be useful for this use case. The mime tree view in mutt that is serving as my example can be used to pipe a single mime part to an external command.

The PR is here: #894 (sadly I have little time to work on this right now, hopfuly later in December)

guillaumecherel commented 7 years ago

@lucc I saw that, and indeed I think it'd be perfect for this use case!

ersinakinci commented 4 years ago

I implemented a little script to open HTML and other multimedia types on macOS: https://github.com/earksiinni/pipe-mime-to-qlmanage. Instructions are available at the link.

I use this script to read HTML emails in Safari on my Mac while using alot on my remote text-only computer, thanks to SSH forwarding.

pazz commented 4 years ago

cute. Thanks for sharing @earksiinni !

ryneeverett commented 4 years ago

I'd like to note that the "link hiding" issue can be fixed by implementing terminal hyperlinks in a terminal web browser. @lypanov has a solution that works fairly well, but it's limited by the fact that terminal web browsers currently clobber the information about what is the anchor text for a link. See https://github.com/tats/w3m/issues/116.

robert-winkler commented 3 years ago

Hi, @guillaumecherel!

I pipe it to a script. =) And add a hotkey for it in alot:

  v = pipeto /myscripts/input_to_browser.py

great stuff! this script solved my problem with HTML mails. I only modified it slightly to add the .html extension:

fileending = ".html"
htmlfilename = "".join([f.name,fileending])
os.rename(f.name, htmlfilename)
webbrowser.open(htmlfilename)
#webbrowser.open(f.name)
lypanov commented 1 year ago

I'd like to note that the "link hiding" issue can be fixed by implementing terminal hyperlinks in a terminal web browser. @lypanov has a solution that works fairly well, but it's limited by the fact that terminal web browsers currently clobber the information about what is the anchor text for a link. See tats/w3m#116.

I somehow missed this mention sorry. My work around for this issue is to manually parse the References output from elinks and embed it back into the output. Working for pretty much every email I've recieved since 2020 ;)

The script in question: https://gist.github.com/lypanov/7a71793568fc1175ce5122cac3015cd3

I'll try to get my latest patch set working against current alot sometime this year.

lypanov commented 10 months ago

I'll try to look into this shortly as I'd like to get my alot fork on python 3.13 to benefit from some of the speed ups.