--- /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 CBFB2429E25\r
+ for <notmuch@notmuchmail.org>; Sat, 14 Apr 2012 14:27:54 -0700 (PDT)\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 jLhXEnOyG-Hn for <notmuch@notmuchmail.org>;\r
+ Sat, 14 Apr 2012 14:27:52 -0700 (PDT)\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 EBA8F431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 14 Apr 2012 14:27:51 -0700 (PDT)\r
+Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+ by earth-doxen-postvirus (Postfix) with ESMTP id BC32166E0123\r
+ for <notmuch@notmuchmail.org>; Sat, 14 Apr 2012 14:27:51 -0700 (PDT)\r
+X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
+Received: from finestructure.net (unknown [76.89.193.65])\r
+ (Authenticated sender: jrollins)\r
+ by earth-doxen-submit (Postfix) with ESMTP id 31E5866E0018\r
+ for <notmuch@notmuchmail.org>; Sat, 14 Apr 2012 14:27:49 -0700 (PDT)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+ id E17F445D; Sat, 14 Apr 2012 14:27:48 -0700 (PDT)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v2 2/2] emacs: new mua mailto: URI handler\r
+Date: Sat, 14 Apr 2012 14:27:48 -0700\r
+Message-Id: <1334438868-17168-1-git-send-email-jrollins@finestructure.net>\r
+X-Mailer: git-send-email 1.7.9.5\r
+In-Reply-To: <1327865624-7673-2-git-send-email-jrollins@finestructure.net>\r
+References: <1327865624-7673-2-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: Sat, 14 Apr 2012 21:27:55 -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
+Rebased against current master.\r
+\r
+ emacs/notmuch-mua.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 62 insertions(+)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index 87bd88d..59b4cf4 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -26,6 +26,10 @@\r
+ (require 'notmuch-lib)\r
+ (require 'notmuch-address)\r
+ \r
++(require 'rfc2368)\r
++(require 'rfc2047)\r
++(require 'mailheader)\r
++\r
+ (eval-when-compile (require 'cl))\r
+ \r
+ ;;\r
+@@ -198,6 +202,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.9.5\r
+\r