The new function 'notmuch-mua-mailto' provides an interactive handler for rfc6068 "mailto:" URIs. It attempts to implement the rfc6068 specification: http://tools.ietf.org/html/rfc6068 More decoding of the mailto string needs to be done, as is evident by the fact that the mailto test remains broken. --- Rebased against current master. emacs/notmuch-mua.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index 87bd88d..59b4cf4 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -26,6 +26,10 @@ (require 'notmuch-lib) (require 'notmuch-address) +(require 'rfc2368) +(require 'rfc2047) +(require 'mailheader) + (eval-when-compile (require 'cl)) ;; @@ -198,6 +202,64 @@ list." (message-goto-to)) +(defun notmuch-mua-mailto (mailto) + "Invoke the notmuch mail composition window for a `mailto:' URI." + ;; this should implement implement rfc6068: http://tools.ietf.org/html/rfc6068 + ;; which obsoleted: http://tools.ietf.org/html/rfc2368 + ;; this function is based on previous work: http://www.emacswiki.org/emacs/MailtoHandler + (interactive) + (when (and (stringp mailto) + (string-match "\\`mailto:" mailto)) + (let* ( + ;; FIXME: need to decode all html encodings in uri. + (mailto (replace-regexp-in-string "&" "&" mailto)) + (hdr-alist (rfc2368-parse-mailto-url mailto)) + to subject other-headers body + (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 (cdr (assoc 'to hdr-alist))) + (setq subject (cdr (assoc 'subject hdr-alist))) + + ;; extract allowed other headers, taking only first defined + ;; value + (dolist (hdr hdr-alist) + (if (and (member (car hdr) allowed-xtra-hdrs) + (not (assoc (car hdr) other-headers))) + (add-to-list 'other-headers hdr))) + + (notmuch-mua-mail to subject other-headers) + + ;; insert the message body - but put it in front of the signature + ;; if one is present + (goto-char (point-max)) + (if (re-search-backward message-signature-separator nil t) + (forward-line -1) + (goto-char (point-max))) + (insert body) + (push-mark)) + (set-buffer-modified-p nil) + + (message-goto-body))) + (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args) "Invoke the notmuch mail composition window. -- 1.7.9.5