Re: A systematic way of handling Xapian lock errors?
[notmuch-archives.git] / 18 / 8e7fdf6354762d9bff466aed8b245ee8240b91
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 B3109431FAF\r
6         for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 13:18:20 -0700 (PDT)\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 EwTtc40udegB for <notmuch@notmuchmail.org>;\r
16         Fri, 26 Oct 2012 13:18:19 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
18         [18.7.68.37])\r
19         by olra.theworths.org (Postfix) with ESMTP id 366DF431FAE\r
20         for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 13:18:19 -0700 (PDT)\r
21 X-AuditID: 12074425-b7fcc6d00000091f-7a-508af00ae45d\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 56.D6.02335.A00FA805; Fri, 26 Oct 2012 16:18:18 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q9QKIIih006740; \r
27         Fri, 26 Oct 2012 16:18:18 -0400\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 q9QKIFCn024591\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 26 Oct 2012 16:18:18 -0400 (EDT)\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1TRqMB-0002zV-7G; Fri, 26 Oct 2012 16:18:15 -0400\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 1/3] emacs: Introduce generic boolean term escaping function\r
40 Date: Fri, 26 Oct 2012 16:18:10 -0400\r
41 Message-Id: <1351282692-11455-1-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10\r
43 X-Brightmail-Tracker:\r
44  H4sIAAAAAAAAA+NgFprJIsWRmVeSWpSXmKPExsUixG6nrsv1oSvAYNFjLYvrN2cyOzB6PFt1\r
45         izmAMYrLJiU1J7MstUjfLoErY9WcX6wFK3grnp98zd7AeIOri5GTQ0LARKJh+2R2CFtM4sK9\r
46         9WxdjFwcQgL7GCXmdtxkBEkICWxglPgzWwQicYpJonlJEyOEM5dRouvbDBaQKjYBDYlt+5eD\r
47         dYgISEvsvDubtYuRg4NZQE3iT5cKiCks4CPxZ5Y+SAWLgKrExeu3wBbzCjhItP+exApxhLzE\r
48         0/t9bBMYeRcwMqxilE3JrdLNTczMKU5N1i1OTszLSy3StdDLzSzRS00p3cQIDgEX1R2MEw4p\r
49         HWIU4GBU4uHd8aQrQIg1say4MvcQoyQHk5Io78LnQCG+pPyUyozE4oz4otKc1OJDjBIczEoi\r
50         vEXHgHK8KYmVValF+TApaQ4WJXHeGyk3/YUE0hNLUrNTUwtSi2CyMhwcShK8r98BNQoWpaan\r
51         VqRl5pQgpJk4OEGG8wANXwZSw1tckJhbnJkOkT/FqCglzjsfJCEAksgozYPrhcXoK0ZxoFeE\r
52         ed3eA1XxAOMbrvsV0GAmoMFirJ0gg0sSEVJSDYzHJC3us04qcO3a0WzuP2WSXs3Xct70awy3\r
53         1l/JnDSh4/aC8MP79Zbd7S+x4H/6zXrNJP+CB5G+szOP2k4O2Nd+PGf7tcMydZarV+b0bPou\r
54         uNvZWL5ovr74tV13m4VzZsvH5P9Yd6NHOFfsNNdepfIVHK1CJmv/iCn+uPAvTHFrzVXvzhtn\r
55         mlcpsRRnJBpqMRcVJwIAlSGZQawCAAA=\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Fri, 26 Oct 2012 20:18:20 -0000\r
69 \r
70 Currently, we only properly escape stashed id queries, but there are\r
71 other places where the Emacs UI constructs queries for boolean terms.\r
72 Since this escaping function is meant to be used in other places, it\r
73 avoids escaping strings that don't need escaping.\r
74 ---\r
75  emacs/notmuch-lib.el |   16 +++++++++++++++-\r
76  test/emacs           |    2 +-\r
77  2 files changed, 16 insertions(+), 2 deletions(-)\r
78 \r
79 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
80 index 69867ad..eeb005f 100644\r
81 --- a/emacs/notmuch-lib.el\r
82 +++ b/emacs/notmuch-lib.el\r
83 @@ -161,9 +161,23 @@ the user hasn't set this variable with the old or new value."\r
84         "[No Subject]"\r
85        subject)))\r
86  \r
87 +(defun notmuch-escape-boolean-term (term)\r
88 +  "Escape a boolean term for use in a query.\r
89 +\r
90 +The caller is responsible for prepending the term prefix and a\r
91 +colon.  This performs minimal escaping in order to produce\r
92 +user-friendly queries."\r
93 +\r
94 +  (save-match-data\r
95 +    (if (or (equal term "")\r
96 +           (string-match "[ ()]\\|^\"" term))\r
97 +       ;; Requires escaping\r
98 +       (concat "\"" (replace-regexp-in-string "\"" "\"\"" term t t) "\"")\r
99 +      term)))\r
100 +\r
101  (defun notmuch-id-to-query (id)\r
102    "Return a query that matches the message with id ID."\r
103 -  (concat "id:\"" (replace-regexp-in-string "\"" "\"\"" id t t) "\""))\r
104 +  (concat "id:" (notmuch-escape-boolean-term id)))\r
105  \r
106  ;;\r
107  \r
108 diff --git a/test/emacs b/test/emacs\r
109 index 21f1d16..44f641e 100755\r
110 --- a/test/emacs\r
111 +++ b/test/emacs\r
112 @@ -667,7 +667,7 @@ Some One <someone@somewhere.org>\r
113  Some One Else <notsomeone@somewhere.org>\r
114  Notmuch <notmuch@notmuchmail.org>\r
115  Stash my stashables\r
116 -id:"bought"\r
117 +id:bought\r
118  bought\r
119  inbox,stashtest\r
120  ${gen_msg_filename}\r
121 -- \r
122 1.7.10\r
123 \r