[PATCH v2 2/3] emacs: Improve the regexp used to match id:'s in messages
authorAustin Clements <amdragon@MIT.EDU>
Sun, 11 Nov 2012 04:46:14 +0000 (23:46 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:30 +0000 (09:50 -0800)
fc/95f42235308019722c61968a0df55451a836a5 [new file with mode: 0644]

diff --git a/fc/95f42235308019722c61968a0df55451a836a5 b/fc/95f42235308019722c61968a0df55451a836a5
new file mode 100644 (file)
index 0000000..62b9411
--- /dev/null
@@ -0,0 +1,171 @@
+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 EB597431FBF\r
+       for <notmuch@notmuchmail.org>; Sat, 10 Nov 2012 20:46:49 -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 iuyUY+S+Cvfp for <notmuch@notmuchmail.org>;\r
+       Sat, 10 Nov 2012 20:46:47 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id EDA66431FC4\r
+       for <notmuch@notmuchmail.org>; Sat, 10 Nov 2012 20:46:35 -0800 (PST)\r
+X-AuditID: 12074423-b7fab6d0000008f9-3d-509f2dab8c2c\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 7E.10.02297.BAD2F905; Sat, 10 Nov 2012 23:46:35 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qAB4kObj008282; \r
+       Sat, 10 Nov 2012 23:46:24 -0500\r
+Received: from drake.dyndns.org\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (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 qAB4kJcE001918\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 10 Nov 2012 23:46:21 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TXPR5-0003a5-NI; Sat, 10 Nov 2012 23:46:19 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/3] emacs: Improve the regexp used to match id:'s in\r
+       messages\r
+Date: Sat, 10 Nov 2012 23:46:14 -0500\r
+Message-Id: <1352609175-12790-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1352609175-12790-1-git-send-email-amdragon@mit.edu>\r
+References: <1352609175-12790-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixCmqrLtad36AwflmBYum6c4W12/OZLZo\r
+       7XvK4sDscev+a3aPZ6tuMXts/PuDJYA5issmJTUnsyy1SN8ugStj5beHTAWHpSuW31jK2sB4\r
+       QKyLkZNDQsBEonP9GzYIW0ziwr31QDYXh5DAPkaJ81PXMkM4GxglHkyYxQjhPGKSWNL+nB2k\r
+       RUhgLqPEmscBIDabgIbEtv3LGUFsEQFpiZ13Z7OC2MwCqRKrd3Ywg9jCAoES/fu2gsVZBFQl\r
+       utoXsoDYvAIOEif/32aEOENRovvZBLCTOAUcJfpn/GGE2OUgcebHe+YJjPwLGBlWMcqm5Fbp\r
+       5iZm5hSnJusWJyfm5aUW6Zrp5WaW6KWmlG5iBAUXu4vyDsY/B5UOMQpwMCrx8N54My9AiDWx\r
+       rLgy9xCjJAeTkihvss78ACG+pPyUyozE4oz4otKc1OJDjBIczEoivLU7gMp5UxIrq1KL8mFS\r
+       0hwsSuK811Ju+gsJpCeWpGanphakFsFkZTg4lCR4Y0GGChalpqdWpGXmlCCkmTg4QYbzAA1/\r
+       pAVUw1tckJhbnJkOkT/FqCglzsuhDZQQAElklObB9cKi/xWjONArwrxBICt4gIkDrvsV0GAm\r
+       oMGNR+aADC5JREhJNTAKtit8N35XJb5X/vipWvMJOT8Vju6WWSXw9N/WH60Rn7eu9DnxNOjf\r
+       FaFLG2Z8C/bd2ljGKCTYviohNugRZ1VAdeGmhIrfizSWtxw18nu9JKXrEb9BQFPwu+X2sy9v\r
+       4PhaKWUv6HD4UejxJuk0qfm7jDLX1b6XD7//8I3kbT/WZ6tWf9suomSjxFKckWioxVxUnAgA\r
+       Q244VNkCAAA=\r
+Cc: sascha-ml-reply-to-2012-4@silbe.org\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, 11 Nov 2012 04:46:50 -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 9712633..8944e73 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 EXPECTED OUTPUT\r
+ \r
+-- \r
+1.7.10.4\r
+\r