]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: Introduce generic boolean term escaping function
authorAustin Clements <amdragon@MIT.EDU>
Fri, 26 Oct 2012 20:18:10 +0000 (16:18 -0400)
committerDavid Bremner <bremner@debian.org>
Sat, 27 Oct 2012 12:33:55 +0000 (09:33 -0300)
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
test/emacs

index 69867ada9a6a68ff7cb7851e25cbb7b232c1d10c..eeb005ffed21806294970ceeb76c593eeaee610d 100644 (file)
@@ -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)))
 
 ;;
 
index 21f1d163d4215379b283fac3cc9908450b7d4bb8..44f641ebf25192e6b3fdc1b2c23c8e0e9d36bce2 100755 (executable)
@@ -667,7 +667,7 @@ Some One <someone@somewhere.org>
 Some One Else <notsomeone@somewhere.org>
 Notmuch <notmuch@notmuchmail.org>
 Stash my stashables
-id:"bought"
+id:bought
 bought
 inbox,stashtest
 ${gen_msg_filename}