From: Tomi Ollila Date: Fri, 26 Oct 2012 21:12:45 +0000 (+0300) Subject: Re: [PATCH 1/3] emacs: Introduce generic boolean term escaping function X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=df2d163ccb43ac248f6b4507b2ce9ae8307c1fc3;p=notmuch-archives.git Re: [PATCH 1/3] emacs: Introduce generic boolean term escaping function --- diff --git a/4d/5e4312e8d57fefbe2a3682d705d123c95c11d0 b/4d/5e4312e8d57fefbe2a3682d705d123c95c11d0 new file mode 100644 index 000000000..25ab4c69c --- /dev/null +++ b/4d/5e4312e8d57fefbe2a3682d705d123c95c11d0 @@ -0,0 +1,117 @@ +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 70DF6431FAF + for ; Fri, 26 Oct 2012 14:12:46 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 dXXVP8UIYBaN for ; + Fri, 26 Oct 2012 14:12:45 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 9FA4A431FAE + for ; Fri, 26 Oct 2012 14:12:45 -0700 (PDT) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 5C7AD100045; + Sat, 27 Oct 2012 00:12:46 +0300 (EEST) +From: Tomi Ollila +To: Austin Clements , notmuch@notmuchmail.org +Subject: Re: [PATCH 1/3] emacs: Introduce generic boolean term escaping + function +In-Reply-To: <1351282692-11455-1-git-send-email-amdragon@mit.edu> +References: <1351282692-11455-1-git-send-email-amdragon@mit.edu> +User-Agent: Notmuch/0.14+59~gf9031cd (http://notmuchmail.org) Emacs/24.2.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +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 21:12:46 -0000 + +On Fri, Oct 26 2012, Austin Clements wrote: + +> 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. +> --- + +These 3 patches LGTM. + +Tomi + + +> 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 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch