Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mhtml: Simple script to view HTML emails in browser #166

Open
Anachron opened this issue Aug 27, 2019 · 3 comments
Open

mhtml: Simple script to view HTML emails in browser #166

Anachron opened this issue Aug 27, 2019 · 3 comments

Comments

@Anachron
Copy link

Anachron commented Aug 27, 2019

#!/bin/sh

msg="${1:-$(mseq)}"
tf=$(mktemp '/tmp/mhtml.XXXXXX.html')
hp=$(mshow -t "${msg}" | grep 'text/html' | cut -d ':' -f 1 | xargs)
mshow -O "${msg}" "${hp}" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//' | sed '/^$/d' > "${tf}"
"${BROWSER:-xdg-open}" "${tf}"
sleep 1
rm "${tf}"
@Duncaen
Copy link
Collaborator

Duncaen commented Aug 27, 2019

This breaks if there are multiple html parts.

You could use something like the following to use the alternative choosing thing instead of all attachments, but I think this would still create wrong html files if there are multiple parts with text/html alternatives and they all contain the doctype and head nodes.

#!/bin/sh
tmp=$(mktemp '/tmp/mhtml.XXXXXX.html')
mshow -NA text/html -h "" ${1} | tail -n +2 >"$tmp" 

@Anachron
Copy link
Author

Anachron commented Aug 27, 2019

Yeah I'm aware of that, the script I posted above works for at least 9/10 html-only emails I receive so that was fair enough for such a short script I thought.

I'll think of a good way how to handle multi-html-parts.

@anjandev
Copy link

anjandev commented Aug 25, 2020

Hi @Anachron, thank you for sharing your approach for opening html emails. I built upon your example for an approach that works for me:

ATTACH="$(mshow -t . | dmenu)"
MIME="$(echo "$ATTACH" | cut -f 2 -d ":" | cut -f 2 -d " ")"
ATTACHNUM="$(echo "$ATTACH" | cut -f1 -d':')"

tmp="$(mktemp '/tmp/mblaze.XXXXXX')"
mshow -O . "$ATTACHNUM" > "$tmp"
# replace this with xdg?
case "$MIME" in
	"application/pdf")
		zathura "$tmp"
		;;
	"text/html")
		firefox "$tmp" 
		;;
# More stuff for pngs and stuff?
esac

You can change dmenu to fzf or any other fuzzy finder. I use this snippet as a general tool for extracting all attachments in emails in my email script I made for my pinephone:

https://git.sr.ht/~anjan/sxmo-userscripts/tree/master/mail.sh#L79

I dont know if my approach is the best but it works for emails with multi html and works as a general attachment extractor. It would be cool to have an attachment extractor included in mblaze.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants