--- /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 C79C5431FBC\r
+ for <notmuch@notmuchmail.org>; Thu, 15 Nov 2012 11:50:05 -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 Z6Y79Dsek1jo for <notmuch@notmuchmail.org>;\r
+ Thu, 15 Nov 2012 11:50:03 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+ [18.9.25.15])\r
+ by olra.theworths.org (Postfix) with ESMTP id 8311D431FBD\r
+ for <notmuch@notmuchmail.org>; Thu, 15 Nov 2012 11:50:03 -0800 (PST)\r
+X-AuditID: 1209190f-b7f636d00000095b-48-50a5476b8577\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id CF.04.02395.B6745A05; Thu, 15 Nov 2012 14:50:03 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qAFJo1Y4005194; \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 qAFJnuf5018787\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-0004YD-Nm; Thu, 15 Nov 2012 14:49:56 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 2/3] emacs: Improve the regexp used to match id:'s in\r
+ messages\r
+Date: Thu, 15 Nov 2012 14:49:53 -0500\r
+Message-Id: <1353008994-17305-3-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+NgFtrHIsWRmVeSWpSXmKPExsUixCmqrZvtvjTAYPMuNovrN2cyW7xZOY/V\r
+ gcnj8NeFLB7PVt1iDmCK4rJJSc3JLEst0rdL4Mp4MekwU8Fh6YqXLc2sDYwHxLoYOTkkBEwk\r
+ vm06xAxhi0lcuLeerYuRi0NIYB+jxOJ/U6CcDYwSb2bNZ4JwTjFJnNx6jwXCmcso8fX8DrB+\r
+ NgENiW37lzOC2CIC0hI7785mBbGZBawkDl/dBGYLCwRKNN84ywZiswioStye8xMszivgIDHp\r
+ 4USoOxQlup9NAKvhFHCUOHJpJpgtBFRz7+NdtgmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+bl\r
+ pRbpmujlZpbopaaUbmIEB5Mk/w7GbweVDjEKcDAq8fCeuLk4QIg1say4MvcQoyQHk5Iob6LN\r
+ 0gAhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIryeckA53pTEyqrUonyYlDQHi5I479WUm/5CAumJ\r
+ JanZqakFqUUwWRkODiUJ3m1uQI2CRanpqRVpmTklCGkmDk6Q4TxAw7eC1PAWFyTmFmemQ+RP\r
+ MSpKifNuAEkIgCQySvPgemHR/opRHOgVYd6rIFU8wEQB1/0KaDAT0OAtMktABpckIqSkGhin\r
+ d6ytcLy55UxFYsDpqHN/WbcZd4mmWLXunfNcT/qb70XhXpszDBoPrjpnCRzxW/SFmXdyYM6p\r
+ k76CdUsffZpaOy0h64n0yoZjwS+uZKU2922quu1z8fO9ORMijqpdOb1d7/Xzd9qKv5tk+uIu\r
+ 1Sfc2310e6i13+PPfQZnvkxpOJK3a8FPH5e3SizFGYmGWsxFxYkAxALfINECAAA=\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:06 -0000\r
+\r
+This regexp agrees with Xapian query syntax much more closely, though\r
+we specifically disallow various cases that would be confusing in the\r
+context of an email body (e.g., punctuation at the end of an id: link\r
+is not considered part of the id: link because it's probably part of\r
+the surrounding text).\r
+\r
+In particular, this handles id: links that are not surrounded by\r
+quotes much better, which stash is much more likely to generate now\r
+that we don't quote id's that don't need to be quoted. It also\r
+handles quoted id: links better.\r
+\r
+We update the buttonization test to reflect the new pattern.\r
+---\r
+ emacs/notmuch-show.el | 20 +++++++++++++++++++-\r
+ test/emacs-show | 20 ++++++++++----------\r
+ 2 files changed, 29 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index d061367..49961fb 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -996,6 +996,24 @@ message at DEPTH in the current thread."\r
+ "Insert the forest of threads FOREST."\r
+ (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))\r
+ \r
++(defvar notmuch-id-regexp\r
++ (concat\r
++ ;; Match the id: prefix only if it begins a word (to disallow, for\r
++ ;; example, matching cid:).\r
++ "\\<id:\\("\r
++ ;; If the term starts with a ", then parse Xapian's quoted boolean\r
++ ;; term syntax, which allows for anything as long as embedded\r
++ ;; double quotes escaped by doubling them. We also disallow\r
++ ;; newlines (which Xapian allows) to prevent runaway terms.\r
++ "\"\\([^\"\n]\\|\"\"\\)*\""\r
++ ;; Otherwise, parse Xapian's unquoted syntax, which goes up to the\r
++ ;; next space or ). We disallow [.,;] as the last character\r
++ ;; because these are probably part of the surrounding text, and not\r
++ ;; part of the id. This doesn't match single character ids; meh.\r
++ "\\|[^\"[:space:])][^[:space:])]*[^])[:space:].,:;?!]"\r
++ "\\)")\r
++ "The regexp used to match id: links in messages.")\r
++\r
+ (defun notmuch-show-buttonise-links (start end)\r
+ "Buttonise URLs and mail addresses between START and END.\r
+ \r
+@@ -1004,7 +1022,7 @@ a corresponding notmuch search."\r
+ (goto-address-fontify-region start end)\r
+ (save-excursion\r
+ (goto-char start)\r
+- (while (re-search-forward "id:\\(\"?\\)[^[:space:]\"]+\\1" end t)\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
+diff --git a/test/emacs-show b/test/emacs-show\r
+index 5d7151b..e2d7c70 100755\r
+--- a/test/emacs-show\r
++++ b/test/emacs-show\r
+@@ -136,23 +136,23 @@ To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
+ Date: Fri, 05 Jan 2001 15:43:57 +0000\r
+ \r
+ <<id:abc>>\r
+-<<id:abc.def.>> <<id:abc,def,>> <<id:abc;def;>> <<id:abc:def:>>\r
+-<<id:foo@bar.?baz?>> <<id:foo@bar!.baz!>>\r
+-(<<id:foo@bar.baz)>> [<<id:foo@bar.baz]>>\r
+-<<id:foo@bar.baz...>>\r
++<<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:\r
++<<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!\r
++(<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]\r
++<<id:foo@bar.baz>>...\r
+ <<id:2+2=5>>\r
+ <<id:=_-:/.[]@$%+>>\r
+-<<id:abc)def>>\r
+-<<id:ab>>"c def\r
++<<id:abc>>)def\r
++<<id:ab"c>> def\r
+ <<id:"abc">>def\r
+-<<id:"ab">>"c"def\r
+-id:"ab c"def\r
++<<id:"ab""c">>def\r
++<<id:"ab c">>def\r
+ <<id:"abc">>.def\r
+ id:"abc\r
+ "\r
+-<<id:)>>\r
++id:)\r
+ id:\r
+-c<<id:xxx>>\r
++cid:xxx\r
+ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+-- \r
+1.7.10.4\r
+\r