| johnsu01 ( @ 2007-02-04 02:45:00 |
| Current music: | Brad Mehldau -- All The Things You Are |
| Entry tags: | emacs, emacs lisp, gnus, iceweasel, lisp |
mailto links with IceWeasel and Gnus
Today I finally got around to making mailto: links and the Send Link command in
IceWeasel work with Gnus and Emacs the way I want.
Now when I click on a mailto: link or select Send Link, I'm prompted in my
running Emacs session for a Gnus posting style, and a new message is started
with the headers and body populated according to that style and any parameters
in the link.
There are three steps to doing this.
First, put this function in your ~/.emacs file:
(defun johnsu01/mailto (url) "Follow a mailto URL as passed from Iceweasel, prompting for a posting style." (let ((gnus-newsgroup-name (completing-read "Use posting style of group: " gnus-active-hashtb nil (gnus-read-active-file-p)))) (setq url (url-unhex-string url)) (browse-url-mail url)) ;; message-mail does not do anything with the body argument, so we have to. (if (string-match (regexp-quote "?") url) (let* ((start (match-end 0)) (args (url-parse-query-string (substring url start nil))) (body (cadr (assoc-string "body" args t)))) (when body (switch-to-buffer (car (message-buffers))) (save-excursion (message-goto-body) (insert body))))))
I suspect that for the posting styles to work properly (along with other Gnus
goodness), you want to have this in your ~/.gnus if you don't already:
(setq mail-user-agent 'gnus-user-agent)
Second, write a tiny shell script to launch emacsclient with the needed
arguments, and make it executable. This is what I use:
#!/bin/bash # $Id: mailto.sh,v 1.5 2007/02/04 07:03:32 johnsu01 Exp $ /usr/bin/emacsclient -e "(johnsu01/mailto \"$1\")"
Third, configure IceWeasel to use this script to handle mailto: links. Browse
to about:config. Search for "mailto:", to see if the parameter
network.protocol-handler.app.mailto is already defined. If it's not there
already, create it by right-clicking to New/String. The value should be the
path to your shell script. So, mine is /home/johnsu01/bin/mailto.sh.
mailto: links should now be working (assuming you have a running Emacs server).
I was off on a wild goose chase for a while writing my own function to do what
browse-url-mail does, and then I was experimenting with url-mail and
url-mailto, but I think in the end this way is the best. I'm not sure what's
going on with the body parameter (which is used when you click Send Link, to
mail a URL to someone). Things would be much simpler if it were handled
properly, but it's not. The body is passed as a an argument to the message
composition command, but none of the commands that fill that role that I
checked do anything with it. That's not surprising, given this note in
message-mail:
;; FIXME: message-mail should do something if YANK-ACTION is not
;; insert-buffer.
Well, when there is a body, YANK-ACTION is insert, not insert-buffer. I thought
for a bit about what the right way to fix this would be, but I shelved it and
went with the the homegrown function above.
(I've since been pointed to gnus-url-mailto, which does seem to do the right
thing with the body, but doesn't give me the posting styles option and doesn't
leave point where I would like.)