Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id B3109431FAF for ; Fri, 26 Oct 2012 13:18:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EwTtc40udegB for ; Fri, 26 Oct 2012 13:18:19 -0700 (PDT) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id 366DF431FAE for ; Fri, 26 Oct 2012 13:18:19 -0700 (PDT) X-AuditID: 12074425-b7fcc6d00000091f-7a-508af00ae45d Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 56.D6.02335.A00FA805; Fri, 26 Oct 2012 16:18:18 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q9QKIIih006740; Fri, 26 Oct 2012 16:18:18 -0400 Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q9QKIFCn024591 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 26 Oct 2012 16:18:18 -0400 (EDT) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1TRqMB-0002zV-7G; Fri, 26 Oct 2012 16:18:15 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 1/3] emacs: Introduce generic boolean term escaping function Date: Fri, 26 Oct 2012 16:18:10 -0400 Message-Id: <1351282692-11455-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJIsWRmVeSWpSXmKPExsUixG6nrsv1oSvAYNFjLYvrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoErY9WcX6wFK3grnp98zd7AeIOri5GTQ0LARKJh+2R2CFtM4sK9 9WxdjFwcQgL7GCXmdtxkBEkICWxglPgzWwQicYpJonlJEyOEM5dRouvbDBaQKjYBDYlt+5eD dYgISEvsvDubtYuRg4NZQE3iT5cKiCks4CPxZ5Y+SAWLgKrExeu3wBbzCjhItP+exApxhLzE 0/t9bBMYeRcwMqxilE3JrdLNTczMKU5N1i1OTszLSy3StdDLzSzRS00p3cQIDgEX1R2MEw4p HWIU4GBU4uHd8aQrQIg1say4MvcQoyQHk5Io78LnQCG+pPyUyozE4oz4otKc1OJDjBIczEoi vEXHgHK8KYmVValF+TApaQ4WJXHeGyk3/YUE0hNLUrNTUwtSi2CyMhwcShK8r98BNQoWpaan VqRl5pQgpJk4OEGG8wANXwZSw1tckJhbnJkOkT/FqCglzjsfJCEAksgozYPrhcXoK0ZxoFeE ed3eA1XxAOMbrvsV0GAmoMFirJ0gg0sSEVJSDYzHJC3us04qcO3a0WzuP2WSXs3Xct70awy3 1l/JnDSh4/aC8MP79Zbd7S+x4H/6zXrNJP+CB5G+szOP2k4O2Nd+PGf7tcMydZarV+b0bPou uNvZWL5ovr74tV13m4VzZsvH5P9Yd6NHOFfsNNdepfIVHK1CJmv/iCn+uPAvTHFrzVXvzhtn mlcpsRRnJBpqMRcVJwIAlSGZQawCAAA= X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Oct 2012 20:18:20 -0000 Currently, we only properly escape stashed id queries, but there are other places where the Emacs UI constructs queries for boolean terms. Since this escaping function is meant to be used in other places, it avoids escaping strings that don't need escaping. --- emacs/notmuch-lib.el | 16 +++++++++++++++- test/emacs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 69867ad..eeb005f 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -161,9 +161,23 @@ the user hasn't set this variable with the old or new value." "[No Subject]" subject))) +(defun notmuch-escape-boolean-term (term) + "Escape a boolean term for use in a query. + +The caller is responsible for prepending the term prefix and a +colon. This performs minimal escaping in order to produce +user-friendly queries." + + (save-match-data + (if (or (equal term "") + (string-match "[ ()]\\|^\"" term)) + ;; Requires escaping + (concat "\"" (replace-regexp-in-string "\"" "\"\"" term t t) "\"") + term))) + (defun notmuch-id-to-query (id) "Return a query that matches the message with id ID." - (concat "id:\"" (replace-regexp-in-string "\"" "\"\"" id t t) "\"")) + (concat "id:" (notmuch-escape-boolean-term id))) ;; diff --git a/test/emacs b/test/emacs index 21f1d16..44f641e 100755 --- a/test/emacs +++ b/test/emacs @@ -667,7 +667,7 @@ Some One Some One Else Notmuch Stash my stashables -id:"bought" +id:bought bought inbox,stashtest ${gen_msg_filename} -- 1.7.10