[PATCH 2/2] emacs: Improve the regexp used to match id:'s in messages
authorAustin Clements <amdragon@MIT.EDU>
Wed, 31 Oct 2012 02:29:21 +0000 (22:29 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:13 +0000 (09:50 -0800)
2c/ee6ad5e4956a5c901469a4c651f9ee8ce36e2b [new file with mode: 0644]

diff --git a/2c/ee6ad5e4956a5c901469a4c651f9ee8ce36e2b b/2c/ee6ad5e4956a5c901469a4c651f9ee8ce36e2b
new file mode 100644 (file)
index 0000000..41ffc2f
--- /dev/null
@@ -0,0 +1,160 @@
+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 C658C431FC3\r
+       for <notmuch@notmuchmail.org>; Tue, 30 Oct 2012 19:29:42 -0700 (PDT)\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 qLaMTQ5aNXbI for <notmuch@notmuchmail.org>;\r
+       Tue, 30 Oct 2012 19:29:41 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
+       [18.9.25.13])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1ECB3431FC4\r
+       for <notmuch@notmuchmail.org>; Tue, 30 Oct 2012 19:29:37 -0700 (PDT)\r
+X-AuditID: 1209190d-b7f906d0000008de-a9-50908d101f56\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 6B.FE.02270.01D80905; Tue, 30 Oct 2012 22:29:36 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q9V2TZD0000788; \r
+       Tue, 30 Oct 2012 22:29:35 -0400\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 q9V2TUNu027171\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 30 Oct 2012 22:29:35 -0400 (EDT)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TTO3X-00021Q-TD; Tue, 30 Oct 2012 22:29:23 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] emacs: Improve the regexp used to match id:'s in messages\r
+Date: Tue, 30 Oct 2012 22:29:21 -0400\r
+Message-Id: <1351650561-7331-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1351650561-7331-1-git-send-email-amdragon@mit.edu>\r
+References: <1351650561-7331-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixG6nrivQOyHAYNlTNYum6c4W12/OZHZg\r
+       8rh1/zW7x7NVt5gDmKK4bFJSczLLUov07RK4Mi4tPcVUMEGy4v2+s0wNjEtFuhg5OSQETCQ2\r
+       fr/OCmGLSVy4t56ti5GLQ0hgH6PE4WMt7BDOBkaJP5PfQjmPmCTmzv/ICOHMZZR4svELG0g/\r
+       m4CGxLb9yxlBbBEBaYmdd2cDzeXgYBYwl7jZEgcSFhbwk1gy9y0TiM0ioCqxtPU1C4jNK2Av\r
+       0XtpKtQZ8hJP7/eBjeQUcJB4unUtI8gYIaCa2y8lJjDyL2BkWMUom5JbpZubmJlTnJqsW5yc\r
+       mJeXWqRrpJebWaKXmlK6iREURpySvDsY3x1UOsQowMGoxMOr8b0/QIg1say4MvcQoyQHk5Io\r
+       b1HXhAAhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIrwXM4ByvCmJlVWpRfkwKWkOFiVx3ispN/2F\r
+       BNITS1KzU1MLUotgsjIcHEoSvJo9QI2CRanpqRVpmTklCGkmDk6Q4TxAw6NAaniLCxJzizPT\r
+       IfKnGBWlxHnfdAMlBEASGaV5cL2wOH/FKA70ijCvC0g7DzBFwHW/AhrMBDRYh68XZHBJIkJK\r
+       qoFxyZLZckbJV8QXRN5ae+Z8xJXzZ1TV3nVfTP4o3Lg32ZrDt9ik1f61bce0y2KWJ3cwLy2s\r
+       Mt/fdE2+ZiIvx+ejze/eiN+QZr43m6P4z2yxCTeVvF6FPDld/uM1T3m6aqrDvgDbXKMJk7x4\r
+       Du2Ve3fslA1XtfeeRzKVf//vs80X/rE3/K3avhg2JZbijERDLeai4kQAlo70BM4CAAA=\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: Wed, 31 Oct 2012 02:29:43 -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       |   14 +++++++-------\r
+ 2 files changed, 26 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index f273eb4..e96e099 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -991,6 +991,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
+@@ -999,7 +1017,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 c4f3cf4..e16483c 100755\r
+--- a/test/emacs-show\r
++++ b/test/emacs-show\r
+@@ -131,18 +131,18 @@ 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;>>\r
+-<<id:abc)def>>\r
+-<<id:ab>>"c def\r
++<<id:abc.def>>. <<id:abc,def>>, <<id:abc;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\r
+\r