--- /dev/null
+Return-Path: <jrollins@finestructure.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id C2E42429E3F\r
+ for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 11:33:51 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id qwJXBfCHQyFy for <notmuch@notmuchmail.org>;\r
+ Sun, 29 Jan 2012 11:33:47 -0800 (PST)\r
+Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
+ [131.215.239.19])\r
+ by olra.theworths.org (Postfix) with ESMTP id AC1D5431E64\r
+ for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 11:33:47 -0800 (PST)\r
+Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+ by earth-doxen-postvirus (Postfix) with ESMTP id 22BF766E013B\r
+ for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 11:33:47 -0800 (PST)\r
+X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
+Received: from finestructure.net (cpe-76-174-137-84.socal.res.rr.com\r
+ [76.174.137.84]) (Authenticated sender: jrollins)\r
+ by earth-doxen-submit (Postfix) with ESMTP id C0D0366E00CF\r
+ for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 11:33:44 -0800 (PST)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+ id 3F46C159; Sun, 29 Jan 2012 11:33:44 -0800 (PST)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH 2/2] emacs: new mua mailto: URI handler\r
+Date: Sun, 29 Jan 2012 11:33:44 -0800\r
+Message-Id: <1327865624-7673-2-git-send-email-jrollins@finestructure.net>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1327865624-7673-1-git-send-email-jrollins@finestructure.net>\r
+References: <1327865624-7673-1-git-send-email-jrollins@finestructure.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 29 Jan 2012 19:33:52 -0000\r
+\r
+The new function 'notmuch-mua-mailto' provides an interactive handler\r
+for rfc6068 "mailto:" URIs. It attempts to implement the rfc6068\r
+specification: http://tools.ietf.org/html/rfc6068\r
+\r
+More decoding of the mailto string needs to be done, as is evident by\r
+the fact that the mailto test remains broken.\r
+---\r
+Unfortunately I'm not sure how best to do the URI decoding, so I've\r
+left a FIXME in the code, and the test as known_broken. I'm hoping an\r
+elisp/encodings expert out there will pick this up.\r
+\r
+ emacs/notmuch-mua.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 files changed, 62 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index 023645e..750e8d6 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -24,6 +24,10 @@\r
+ (require 'notmuch-lib)\r
+ (require 'notmuch-address)\r
+ \r
++(require 'rfc2368)\r
++(require 'rfc2047)\r
++(require 'mailheader)\r
++\r
+ ;;\r
+ \r
+ (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)\r
+@@ -131,6 +135,64 @@ list."\r
+ \r
+ (message-goto-to))\r
+ \r
++(defun notmuch-mua-mailto (mailto)\r
++ "Invoke the notmuch mail composition window for a `mailto:' URI."\r
++ ;; this should implement implement rfc6068: http://tools.ietf.org/html/rfc6068\r
++ ;; which obsoleted: http://tools.ietf.org/html/rfc2368\r
++ ;; this function is based on previous work: http://www.emacswiki.org/emacs/MailtoHandler\r
++ (interactive)\r
++ (when (and (stringp mailto)\r
++ (string-match "\\`mailto:" mailto))\r
++ (let* (\r
++ ;; FIXME: need to decode all html encodings in uri.\r
++ (mailto (replace-regexp-in-string "&" "&" mailto))\r
++ (hdr-alist (rfc2368-parse-mailto-url mailto))\r
++ to subject other-headers body\r
++ (allowed-xtra-hdrs '(cc bcc in-reply-to)))\r
++\r
++ (with-temp-buffer\r
++ ;; extract body if it's defined\r
++ (when (assoc "Body" hdr-alist)\r
++ (dolist (hdr hdr-alist)\r
++ (when (equal "Body" (car hdr))\r
++ (insert (format "%s\n" (cdr hdr)))))\r
++ (rfc2047-decode-region (point-min) (point-max))\r
++ (setq body (buffer-substring-no-properties\r
++ (point-min) (point-max)))\r
++ (erase-buffer))\r
++\r
++ ;; extract headers\r
++ (dolist (hdr hdr-alist)\r
++ (unless (equal "Body" (car hdr))\r
++ (insert (format "%s: %s\n" (car hdr) (cdr hdr)))))\r
++ (rfc2047-decode-region (point-min) (point-max))\r
++ (goto-char (point-min))\r
++ (setq hdr-alist (mail-header-extract-no-properties)))\r
++\r
++ (setq to (cdr (assoc 'to hdr-alist)))\r
++ (setq subject (cdr (assoc 'subject hdr-alist)))\r
++\r
++ ;; extract allowed other headers, taking only first defined\r
++ ;; value\r
++ (dolist (hdr hdr-alist)\r
++ (if (and (member (car hdr) allowed-xtra-hdrs)\r
++ (not (assoc (car hdr) other-headers)))\r
++ (add-to-list 'other-headers hdr)))\r
++\r
++ (notmuch-mua-mail to subject other-headers)\r
++\r
++ ;; insert the message body - but put it in front of the signature\r
++ ;; if one is present\r
++ (goto-char (point-max))\r
++ (if (re-search-backward message-signature-separator nil t)\r
++ (forward-line -1)\r
++ (goto-char (point-max)))\r
++ (insert body)\r
++ (push-mark))\r
++ (set-buffer-modified-p nil)\r
++\r
++ (message-goto-body)))\r
++\r
+ (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args)\r
+ "Invoke the notmuch mail composition window.\r
+ \r
+-- \r
+1.7.8.3\r
+\r