Clickable Email address in Chrome => mu4e opens (?)

294 views
Skip to first unread message

Marius Hofert

unread,
May 5, 2013, 7:51:25 PM5/5/13
to mu-discuss
Hi,

Is there a simple way to have mu4e open if an email address has been
clicked on in the browser (Chrome)?

The following (see http://lists.gnu.org/archive/html/info-gnus-english/2013-01/msg00048.html)
is for Gnus:

#v+
#!/bin/sh

ARG="$1"

if [ -z "$ARG" ]; then exit 0; fi

RECIPIENT=$(echo $ARG |sed -r -n -e '/^mailto:/s/^mailto:([^@]
+@[[:alnum:].-]+).*$/\1/gp')
SUBJECT="$(echo $ARG |sed -r -n -e '/^mailto:/s/^mailto:[^@]
+@[[:alnum:].-]+[?].*&?subject=([^&]+).*$/\1/gp')"

emacsclient -e '(progn (gnus-group-mail) (message-goto-to) (insert
"'$RECIPIENT'") (message-goto-subject) (insert "'"$SUBJECT"'")
(message-goto-body))'
#v-

Cheers,

Marius

D. LoBraico

unread,
May 5, 2013, 9:58:37 PM5/5/13
to mu-di...@googlegroups.com
What operating system do you use? I have written a simple Cocoa app for
OS X that opens mu4e for mailto links.

Marius Hofert

unread,
May 6, 2013, 2:08:35 AM5/6/13
to mu-discuss
Hi,

I'm using Ubuntu 13.04.

Cheers,

Marius

Steve Dowe

unread,
May 7, 2013, 5:37:41 AM5/7/13
to mu-di...@googlegroups.com
Hey Marius,

I don't know about Chrome, but I set up a mailto handler in Firefox. I
got this code from elsewhere so I don't assume any authorship, and I'm
afraid I can't really now where I got it from - but it works ;)

The first trick is running Emacs in server mode, whereby it can accept
incoming messages from other apps. This helps avoid another instance of
Emacs starting separately.

There's more info on all that here:

.. but effectively all you need to do is put this at the top of your
.emacs:

;; start the server to allow emacsclient
(server-start)


The next thing is to use this bash script as your mailto shell script:


#!/bin/sh
# emacs-mailto-handler

mailto=$1
mailto="mailto:${mailto#mailto:}"
mailto=$(printf '%s\n' "$mailto" | sed -e 's/[\"]/\\&/g')
elisp_expr="(mailto-compose-mail \"$mailto\")"

# replace mu4e-compose-new/browse-url with mailto-compose-mail if problems

emacsclient -a "" -c -n --eval "$elisp_expr" \
'(set-window-dedicated-p (selected-window) t)'


You can put this somewhere in your $PATH if you want
(e.g. /usr/local/bin) or keep it locally in your ~, say in ~/bin.


Now, revisit your .emacs and put this in:

;; enable mailto: link handling
(load-file "~/.emacs.d/mailto-handler.el")


.. and finally, create that file in Emacs and paste this in:

;;;; mailto-compose-mail.el (2010-08-15)

;;;###autoload
(defun mailto-compose-mail (mailto-url)
"Parse MAILTO-URL and start composing mail."
(if (and (stringp mailto-url)
(string-match "\\`mailto:" mailto-url))
(progn
(require 'rfc2368)
(require 'rfc2047)
(require 'mailheader)

(let ((hdr-alist (rfc2368-parse-mailto-url mailto-url))
(body "")
to subject
;; In addition to To, Subject and Body these headers are
;; allowed:
(allowed-xtra-hdrs '(cc bcc in-reply-to)))

(with-temp-buffer
;; Extract body if it's defined
(when (assoc "Body" hdr-alist)
(dolist (hdr hdr-alist)
(when (equal "Body" (car hdr))
(insert (format "%s\n" (cdr hdr)))))
(rfc2047-decode-region (point-min) (point-max))
(setq body (buffer-substring-no-properties
(point-min) (point-max)))
(erase-buffer))

;; Extract headers
(dolist (hdr hdr-alist)
(unless (equal "Body" (car hdr))
(insert (format "%s: %s\n" (car hdr) (cdr hdr)))))
(rfc2047-decode-region (point-min) (point-max))
(goto-char (point-min))
(setq hdr-alist (mail-header-extract-no-properties)))

(setq to (or (cdr (assq 'to hdr-alist)) "")
subject (or (cdr (assq 'subject hdr-alist)) "")
hdr-alist
(remove nil (mapcar
#'(lambda (item)
(when (memq (car item) allowed-xtra-hdrs)
(cons (capitalize (symbol-name (car item)))
(cdr item))))
hdr-alist)))

(compose-mail to subject hdr-alist nil nil
(list (lambda (string)
(insert string))
body))))
(compose-mail)))




I think that's "all" there is to it, but I'm a bit wary that I may not
be specifying the link between mu4e's compose and Emacs' standard mail
compose window - but see how you get on.

In Chrome, see if you can edit the mailto handler and change it to point
to your ~/bin/mailto_emacs.sh script. And make sure that script is
executable, with:

# chmod 750 ~/bin/mailto_emacs.sh


When clicking on a mailto: link in Firefox, the effect for me is that a
small, separate emacsclient window opens with the message composer
waiting for my input. When I am ready to send and hit C-c C-c, the
message gets sent and the window closes.

Hope this helps.

Steve

Steve Dowe

unread,
May 7, 2013, 5:40:51 AM5/7/13
to mu-di...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages