X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=emacs%2Fnotmuch-lib.el;h=eeb005ffed21806294970ceeb76c593eeaee610d;hp=69867ada9a6a68ff7cb7851e25cbb7b232c1d10c;hb=1a4cb8fd29c52445fc3de70e92de377f00cdc4a7;hpb=05c87b5d18794290f4746218d1ea93c2990ba43d diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 69867ada..eeb005ff 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))) ;;