Re: [PATCH 1/3] emacs: Introduce generic boolean term escaping function
authorTomi Ollila <tomi.ollila@iki.fi>
Fri, 26 Oct 2012 21:12:45 +0000 (00:12 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:04 +0000 (09:50 -0800)
4d/5e4312e8d57fefbe2a3682d705d123c95c11d0 [new file with mode: 0644]

diff --git a/4d/5e4312e8d57fefbe2a3682d705d123c95c11d0 b/4d/5e4312e8d57fefbe2a3682d705d123c95c11d0
new file mode 100644 (file)
index 0000000..25ab4c6
--- /dev/null
@@ -0,0 +1,117 @@
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 70DF6431FAF\r
+       for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 14:12:46 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id dXXVP8UIYBaN for <notmuch@notmuchmail.org>;\r
+       Fri, 26 Oct 2012 14:12:45 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 9FA4A431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 14:12:45 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id 5C7AD100045;\r
+       Sat, 27 Oct 2012 00:12:46 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/3] emacs: Introduce generic boolean term escaping\r
+       function\r
+In-Reply-To: <1351282692-11455-1-git-send-email-amdragon@mit.edu>\r
+References: <1351282692-11455-1-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.14+59~gf9031cd (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sat, 27 Oct 2012 00:12:45 +0300\r
+Message-ID: <m2k3uduecy.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 26 Oct 2012 21:12:46 -0000\r
+\r
+On Fri, Oct 26 2012, Austin Clements wrote:\r
+\r
+> Currently, we only properly escape stashed id queries, but there are\r
+> other places where the Emacs UI constructs queries for boolean terms.\r
+> Since this escaping function is meant to be used in other places, it\r
+> avoids escaping strings that don't need escaping.\r
+> ---\r
+\r
+These 3 patches LGTM.\r
+\r
+Tomi\r
+\r
+\r
+>  emacs/notmuch-lib.el |   16 +++++++++++++++-\r
+>  test/emacs           |    2 +-\r
+>  2 files changed, 16 insertions(+), 2 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+> index 69867ad..eeb005f 100644\r
+> --- a/emacs/notmuch-lib.el\r
+> +++ b/emacs/notmuch-lib.el\r
+> @@ -161,9 +161,23 @@ the user hasn't set this variable with the old or new value."\r
+>      "[No Subject]"\r
+>        subject)))\r
+>  \r
+> +(defun notmuch-escape-boolean-term (term)\r
+> +  "Escape a boolean term for use in a query.\r
+> +\r
+> +The caller is responsible for prepending the term prefix and a\r
+> +colon.  This performs minimal escaping in order to produce\r
+> +user-friendly queries."\r
+> +\r
+> +  (save-match-data\r
+> +    (if (or (equal term "")\r
+> +        (string-match "[ ()]\\|^\"" term))\r
+> +    ;; Requires escaping\r
+> +    (concat "\"" (replace-regexp-in-string "\"" "\"\"" term t t) "\"")\r
+> +      term)))\r
+> +\r
+>  (defun notmuch-id-to-query (id)\r
+>    "Return a query that matches the message with id ID."\r
+> -  (concat "id:\"" (replace-regexp-in-string "\"" "\"\"" id t t) "\""))\r
+> +  (concat "id:" (notmuch-escape-boolean-term id)))\r
+>  \r
+>  ;;\r
+>  \r
+> diff --git a/test/emacs b/test/emacs\r
+> index 21f1d16..44f641e 100755\r
+> --- a/test/emacs\r
+> +++ b/test/emacs\r
+> @@ -667,7 +667,7 @@ Some One <someone@somewhere.org>\r
+>  Some One Else <notsomeone@somewhere.org>\r
+>  Notmuch <notmuch@notmuchmail.org>\r
+>  Stash my stashables\r
+> -id:"bought"\r
+> +id:bought\r
+>  bought\r
+>  inbox,stashtest\r
+>  ${gen_msg_filename}\r
+> -- \r
+> 1.7.10\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r