open messages in browser in new window

80 views
Skip to first unread message

Ken Mankoff

unread,
Dec 19, 2016, 9:30:03 AM12/19/16
to mu-discuss
Hi,

Sometimes I have to view HTML messages in a web browser in order to be able to parse the contents (e.g. airline reservations). I have two functions to help with this. I'd like to view messages in a new window.

1) View in browser, from http://www.djcbsoftware.nl/code/mu/mu4e/Reading-messages.html

which is implemented with:

(add-to-list 'mu4e-view-actions '("ViewInBrowser" . mu4e-action-view-in-browser) t)

2) View in GMail, from https://github.com/danieroux/emacs/blob/master/mine/djr-mu4e.el

which is implemented with:

(defun kdm/mu4e-open-message-in-google (msg)
(let* ((msgid (mu4e-message-field msg :message-id))
(url (concat "https://mail.google.com/mail/u/0/?shva=1#search/rfc822msgid%3A"
(url-encode-url msgid))))
(start-process "" nil "open" url)))
(add-to-list 'mu4e-view-actions '("gopen in gmail" . kdm/mu4e-open-message-in-google) t)
(add-to-list 'mu4e-headers-actions '("gopen in gmail" . kdm/mu4e-open-message-in-google) t)


However, neither of these open the message in a new browser window. Does anyone know how to achieve that? I would hope a generic solution might only involve:

(setq browse-url-new-window-flag t)

But that does not have any noticible effect. If it matters, I'm on OS X and use Google Chrome as my primary browser.

Thanks,

-k.

Steffen Fuerst

unread,
Jan 2, 2017, 11:41:52 AM1/2/17
to mu-discuss
I'm using a solution from this reddit thread:

(defun mu4e-msgv-action-view-in-browser (msg)
      "View the body of the message in a web browser."
      (interactive)
      (let ((html (mu4e-msg-field (mu4e-message-at-point t) :body-html))
            (tmpfile (format "%s/%d.html" temporary-file-directory (random))))
        (unless html (error "No html part for this message"))
        (with-temp-file tmpfile
          (insert
           "<html>"
           "<head><meta http-equiv=\"content-type\""
           "content=\"text/html;charset=UTF-8\">"
           html))
        (browse-url (concat "file://" tmpfile))))

 (add-to-list 'mu4e-view-actions '("View in browser" . mu4e-msgv-action-view-in-browser) t)



Stig Brautaset

unread,
Jan 2, 2017, 11:56:08 AM1/2/17
to mu-di...@googlegroups.com

Steffen Fuerst <steffen...@web.de> writes:

> I'm using a solution from this reddit thread
> <https://www.reddit.com/r/emacs/comments/4rl0a9/email_in_emacs_i_want_to_but_wow_its_overwhelming/>
> :

mu4e already supports opening messages in external browser, so no need
for a custom function:

,----
| (add-to-list 'mu4e-headers-actions
| '("in browser" . mu4e-action-view-in-browser) t)
| (add-to-list 'mu4e-view-actions
| '("in browser" . mu4e-action-view-in-browser) t)
`----

Stig

Ken Mankoff

unread,
Jan 2, 2017, 12:15:04 PM1/2/17
to mu-di...@googlegroups.com
Hi Steffen,

That opens the message in a browser, but on my system, not in a new window.

I think that function is built into mu4e already and all you need to do is have:

(add-to-list 'mu4e-view-actions '("ViewInBrowser" . mu4e-action-view-in-browser) t)

But your email made me review the existing functions, and on my OS X system w/ Chrome (running usually on another virtual desktop), I can now get a new browser window on my current desktop with the following code:

(defun kdm/mu4e-msg-view-action-view-in-browser (msg)
(start-process "~/path/to/Google Chrome.app/Contents/MacOS/Google Chrome --new" nil "~/path/to/Google Chrome.app/Contents/MacOS/Google Chrome" "--new")
(sleep-for 1) ; may need to increase this
(browse-url (concat "file://" (mu4e~write-body-to-html msg))))

(add-to-list 'mu4e-view-actions
'("View in browser" . kdm/mu4e-msg-view-action-view-in-browser) t)
Reply all
Reply to author
Forward
0 new messages