--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 CEE7A431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 15 Nov 2012 11:50:03 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 YP-eYlCKTEjB for <notmuch@notmuchmail.org>;\r
+ Thu, 15 Nov 2012 11:50:03 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
+ [18.7.68.36])\r
+ by olra.theworths.org (Postfix) with ESMTP id F2033431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 15 Nov 2012 11:50:02 -0800 (PST)\r
+X-AuditID: 12074424-b7fce6d000000925-91-50a5476a705f\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id CA.1A.02341.A6745A05; Thu, 15 Nov 2012 14:50:02 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qAFJo12w000887; \r
+ Thu, 15 Nov 2012 14:50:01 -0500\r
+Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qAFJnuZj018788\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Thu, 15 Nov 2012 14:49:59 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1TZ5Rk-0004YG-Og; Thu, 15 Nov 2012 14:49:56 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 3/3] emacs: Buttonize mid: links\r
+Date: Thu, 15 Nov 2012 14:49:54 -0500\r
+Message-Id: <1353008994-17305-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1353008994-17305-1-git-send-email-amdragon@mit.edu>\r
+References: <1353008994-17305-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsUixG6nopvlvjTA4OtZbovrN2cyW7xZOY/V\r
+ gcnj8NeFLB7PVt1iDmCK4rJJSc3JLEst0rdL4Mpo2b6esWCfVEX34mmsDYyrRbsYOTkkBEwk\r
+ Jvy+ywRhi0lcuLeerYuRi0NIYB+jxJpJC9ghnA2MEn1TLjFCOKeYJPZtvg1VNpdRYmXXQrB+\r
+ NgENiW37lzOC2CIC0hI7785mBbGZBawkDl/dBGYLCxhLnNy9DayeRUBV4vi7V+wgNq+Ag8Sp\r
+ j51sEHcoSnQ/mwBmcwo4Shy5NBPMFgKquffxLtsERv4FjAyrGGVTcqt0cxMzc4pTk3WLkxPz\r
+ 8lKLdM31cjNL9FJTSjcxgoPJRWUHY/MhpUOMAhyMSjy8J24uDhBiTSwrrsw9xCjJwaQkypto\r
+ szRAiC8pP6UyI7E4I76oNCe1+BCjBAezkgivpxxQjjclsbIqtSgfJiXNwaIkzns95aa/kEB6\r
+ YklqdmpqQWoRTFaGg0NJgrfWDahRsCg1PbUiLTOnBCHNxMEJMpwHaDhYDW9xQWJucWY6RP4U\r
+ o6KUOK8nSEIAJJFRmgfXC4v2V4ziQK8I88aCVPEAEwVc9yugwUxAg7fILAEZXJKIkJJqYBRc\r
+ +TB7/zU+jcuJZd6Jt+59Y97h9y5EepVf+8ILC+pyzwZOMTof3L1nofsbRZZtDx+qSrhp7m3V\r
+ W+G/Tr/qjPDnODcH8c4G18r7301Z7obZXy6p5bT7demRXd9ls5OnazY03dp5VbhteptJ+C81\r
+ j26T9TxLfOSWrp0+aYqTgJBu8vcOx+kcF5RYijMSDbWYi4oTAcI0ABzRAgAA\r
+Cc: tomi.ollila@iki.fi\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: Thu, 15 Nov 2012 19:50:04 -0000\r
+\r
+This adds support for RFC 2392 mid: message ID links.\r
+---\r
+ emacs/notmuch-show.el | 45 +++++++++++++++++++++++++++++++++------------\r
+ test/emacs-show | 8 +++++++-\r
+ 2 files changed, 40 insertions(+), 13 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 49961fb..5b3e70e 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -1014,23 +1014,44 @@ message at DEPTH in the current thread."\r
+ "\\)")\r
+ "The regexp used to match id: links in messages.")\r
+ \r
++(defvar notmuch-mid-regexp\r
++ ;; goto-address-url-regexp matched cid: links, which have the same\r
++ ;; grammar as the message ID part of a mid: link. Construct the\r
++ ;; regexp using the same technique as goto-address-url-regexp.\r
++ (concat "\\<mid:\\(" thing-at-point-url-path-regexp "\\)")\r
++ "The regexp used to match mid: links in messages.\r
++\r
++See RFC 2392.")\r
++\r
+ (defun notmuch-show-buttonise-links (start end)\r
+ "Buttonise URLs and mail addresses between START and END.\r
+ \r
+-This also turns id:\"<message id>\"-parts into buttons for\r
+-a corresponding notmuch search."\r
++This also turns id:\"<message id>\"-parts and mid: links into\r
++buttons for a corresponding notmuch search."\r
+ (goto-address-fontify-region start end)\r
+ (save-excursion\r
+- (goto-char start)\r
+- (while (re-search-forward notmuch-id-regexp end t)\r
+- ;; remove the overlay created by goto-address-mode\r
+- (remove-overlays (match-beginning 0) (match-end 0) 'goto-address t)\r
+- (make-text-button (match-beginning 0) (match-end 0)\r
+- 'action `(lambda (arg)\r
+- (notmuch-show ,(match-string-no-properties 0)))\r
+- 'follow-link t\r
+- 'help-echo "Mouse-1, RET: search for this message"\r
+- 'face goto-address-mail-face))))\r
++ (let (links)\r
++ (goto-char start)\r
++ (while (re-search-forward notmuch-id-regexp end t)\r
++ (push (list (match-beginning 0) (match-end 0)\r
++ (match-string-no-properties 0)) links))\r
++ (goto-char start)\r
++ (while (re-search-forward notmuch-mid-regexp end t)\r
++ (let* ((mid-cid (match-string-no-properties 1))\r
++ (mid (save-match-data\r
++ (string-match "^[^/]*" mid-cid)\r
++ (url-unhex-string (match-string 0 mid-cid)))))\r
++ (push (list (match-beginning 0) (match-end 0)\r
++ (notmuch-id-to-query mid)) links)))\r
++ (dolist (link links)\r
++ ;; Remove the overlay created by goto-address-mode\r
++ (remove-overlays (first link) (second link) 'goto-address t)\r
++ (make-text-button (first link) (second link)\r
++ 'action `(lambda (arg)\r
++ (notmuch-show ,(third link)))\r
++ 'follow-link t\r
++ 'help-echo "Mouse-1, RET: search for this message"\r
++ 'face goto-address-mail-face)))))\r
+ \r
+ ;;;###autoload\r
+ (defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name)\r
+diff --git a/test/emacs-show b/test/emacs-show\r
+index e2d7c70..ec3be8b 100755\r
+--- a/test/emacs-show\r
++++ b/test/emacs-show\r
+@@ -125,7 +125,10 @@ id:\"abc\r
+ \"\r
+ id:)\r
+ id:\r
+-cid:xxx"'\r
++cid:xxx\r
++mid:abc mid:abc/def\r
++mid:abc%20def\r
++mid:abc. mid:abc, mid:abc;"'\r
+ test_emacs '(notmuch-show "id:'$gen_msg_id'")\r
+ (notmuch-test-mark-links)\r
+ (test-visible-output)'\r
+@@ -153,6 +156,9 @@ id:"abc\r
+ id:)\r
+ id:\r
+ cid:xxx\r
++<<mid:abc>> <<mid:abc/def>>\r
++<<mid:abc%20def>>\r
++<<mid:abc>>. <<mid:abc>>, <<mid:abc>>;\r
+ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+-- \r
+1.7.10.4\r
+\r