Re: Flat search and threaded views
[notmuch-archives.git] / 91 / e25004be319ed05717da3fef1dea25c783f1b7
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id C79C5431FBC\r
6         for <notmuch@notmuchmail.org>; Thu, 15 Nov 2012 11:50:05 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id Z6Y79Dsek1jo for <notmuch@notmuchmail.org>;\r
16         Thu, 15 Nov 2012 11:50:03 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id 8311D431FBD\r
20         for <notmuch@notmuchmail.org>; Thu, 15 Nov 2012 11:50:03 -0800 (PST)\r
21 X-AuditID: 1209190f-b7f636d00000095b-48-50a5476b8577\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id CF.04.02395.B6745A05; Thu, 15 Nov 2012 14:50:03 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qAFJo1Y4005194; \r
27         Thu, 15 Nov 2012 14:50:01 -0500\r
28 Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qAFJnuf5018787\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 15 Nov 2012 14:49:59 -0500 (EST)\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1TZ5Rk-0004YD-Nm; Thu, 15 Nov 2012 14:49:56 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v3 2/3] emacs: Improve the regexp used to match id:'s in\r
40         messages\r
41 Date: Thu, 15 Nov 2012 14:49:53 -0500\r
42 Message-Id: <1353008994-17305-3-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.10.4\r
44 In-Reply-To: <1353008994-17305-1-git-send-email-amdragon@mit.edu>\r
45 References: <1353008994-17305-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsUixCmqrZvtvjTAYPMuNovrN2cyW7xZOY/V\r
48         gcnj8NeFLB7PVt1iDmCK4rJJSc3JLEst0rdL4Mp4MekwU8Fh6YqXLc2sDYwHxLoYOTkkBEwk\r
49         vm06xAxhi0lcuLeerYuRi0NIYB+jxOJ/U6CcDYwSb2bNZ4JwTjFJnNx6jwXCmcso8fX8DrB+\r
50         NgENiW37lzOC2CIC0hI7785mBbGZBawkDl/dBGYLCwRKNN84ywZiswioStye8xMszivgIDHp\r
51         4USoOxQlup9NAKvhFHCUOHJpJpgtBFRz7+NdtgmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+bl\r
52         pRbpmujlZpbopaaUbmIEB5Mk/w7GbweVDjEKcDAq8fCeuLk4QIg1say4MvcQoyQHk5Iob6LN\r
53         0gAhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIryeckA53pTEyqrUonyYlDQHi5I479WUm/5CAumJ\r
54         JanZqakFqUUwWRkODiUJ3m1uQI2CRanpqRVpmTklCGkmDk6Q4TxAw7eC1PAWFyTmFmemQ+RP\r
55         MSpKifNuAEkIgCQySvPgemHR/opRHOgVYd6rIFU8wEQB1/0KaDAT0OAtMktABpckIqSkGhin\r
56         d6ytcLy55UxFYsDpqHN/WbcZd4mmWLXunfNcT/qb70XhXpszDBoPrjpnCRzxW/SFmXdyYM6p\r
57         k76CdUsffZpaOy0h64n0yoZjwS+uZKU2922quu1z8fO9ORMijqpdOb1d7/Xzd9qKv5tk+uIu\r
58         1Sfc2310e6i13+PPfQZnvkxpOJK3a8FPH5e3SizFGYmGWsxFxYkAxALfINECAAA=\r
59 Cc: tomi.ollila@iki.fi\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Thu, 15 Nov 2012 19:50:06 -0000\r
73 \r
74 This regexp agrees with Xapian query syntax much more closely, though\r
75 we specifically disallow various cases that would be confusing in the\r
76 context of an email body (e.g., punctuation at the end of an id: link\r
77 is not considered part of the id: link because it's probably part of\r
78 the surrounding text).\r
79 \r
80 In particular, this handles id: links that are not surrounded by\r
81 quotes much better, which stash is much more likely to generate now\r
82 that we don't quote id's that don't need to be quoted.  It also\r
83 handles quoted id: links better.\r
84 \r
85 We update the buttonization test to reflect the new pattern.\r
86 ---\r
87  emacs/notmuch-show.el |   20 +++++++++++++++++++-\r
88  test/emacs-show       |   20 ++++++++++----------\r
89  2 files changed, 29 insertions(+), 11 deletions(-)\r
90 \r
91 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
92 index d061367..49961fb 100644\r
93 --- a/emacs/notmuch-show.el\r
94 +++ b/emacs/notmuch-show.el\r
95 @@ -996,6 +996,24 @@ message at DEPTH in the current thread."\r
96    "Insert the forest of threads FOREST."\r
97    (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))\r
98  \r
99 +(defvar notmuch-id-regexp\r
100 +  (concat\r
101 +   ;; Match the id: prefix only if it begins a word (to disallow, for\r
102 +   ;; example, matching cid:).\r
103 +   "\\<id:\\("\r
104 +   ;; If the term starts with a ", then parse Xapian's quoted boolean\r
105 +   ;; term syntax, which allows for anything as long as embedded\r
106 +   ;; double quotes escaped by doubling them.  We also disallow\r
107 +   ;; newlines (which Xapian allows) to prevent runaway terms.\r
108 +   "\"\\([^\"\n]\\|\"\"\\)*\""\r
109 +   ;; Otherwise, parse Xapian's unquoted syntax, which goes up to the\r
110 +   ;; next space or ).  We disallow [.,;] as the last character\r
111 +   ;; because these are probably part of the surrounding text, and not\r
112 +   ;; part of the id.  This doesn't match single character ids; meh.\r
113 +   "\\|[^\"[:space:])][^[:space:])]*[^])[:space:].,:;?!]"\r
114 +   "\\)")\r
115 +  "The regexp used to match id: links in messages.")\r
116 +\r
117  (defun notmuch-show-buttonise-links (start end)\r
118    "Buttonise URLs and mail addresses between START and END.\r
119  \r
120 @@ -1004,7 +1022,7 @@ a corresponding notmuch search."\r
121    (goto-address-fontify-region start end)\r
122    (save-excursion\r
123      (goto-char start)\r
124 -    (while (re-search-forward "id:\\(\"?\\)[^[:space:]\"]+\\1" end t)\r
125 +    (while (re-search-forward notmuch-id-regexp end t)\r
126        ;; remove the overlay created by goto-address-mode\r
127        (remove-overlays (match-beginning 0) (match-end 0) 'goto-address t)\r
128        (make-text-button (match-beginning 0) (match-end 0)\r
129 diff --git a/test/emacs-show b/test/emacs-show\r
130 index 5d7151b..e2d7c70 100755\r
131 --- a/test/emacs-show\r
132 +++ b/test/emacs-show\r
133 @@ -136,23 +136,23 @@ To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
134  Date: Fri, 05 Jan 2001 15:43:57 +0000\r
135  \r
136  <<id:abc>>\r
137 -<<id:abc.def.>> <<id:abc,def,>> <<id:abc;def;>> <<id:abc:def:>>\r
138 -<<id:foo@bar.?baz?>> <<id:foo@bar!.baz!>>\r
139 -(<<id:foo@bar.baz)>> [<<id:foo@bar.baz]>>\r
140 -<<id:foo@bar.baz...>>\r
141 +<<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:\r
142 +<<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!\r
143 +(<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]\r
144 +<<id:foo@bar.baz>>...\r
145  <<id:2+2=5>>\r
146  <<id:=_-:/.[]@$%+>>\r
147 -<<id:abc)def>>\r
148 -<<id:ab>>"c def\r
149 +<<id:abc>>)def\r
150 +<<id:ab"c>> def\r
151  <<id:"abc">>def\r
152 -<<id:"ab">>"c"def\r
153 -id:"ab c"def\r
154 +<<id:"ab""c">>def\r
155 +<<id:"ab c">>def\r
156  <<id:"abc">>.def\r
157  id:"abc\r
158  "\r
159 -<<id:)>>\r
160 +id:)\r
161  id:\r
162 -c<<id:xxx>>\r
163 +cid:xxx\r
164  EOF\r
165  test_expect_equal_file OUTPUT EXPECTED\r
166  \r
167 -- \r
168 1.7.10.4\r
169 \r