--- /dev/null
+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 1F2BA431FBC\r
+ for <notmuch@notmuchmail.org>; Mon, 3 Feb 2014 13:21:17 -0800 (PST)\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 y2tYR9iD5gVM for <notmuch@notmuchmail.org>;\r
+ Mon, 3 Feb 2014 13:21:09 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 618DC431FAF\r
+ for <notmuch@notmuchmail.org>; Mon, 3 Feb 2014 13:21:09 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id DED2E100033;\r
+ Mon, 3 Feb 2014 23:21:03 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: sanitization of args notmuch-cli in notmuch-emacs\r
+In-Reply-To: <m2mwi8q6gh.fsf@guru.guru-group.fi>\r
+References: <87wqhcxb5j.fsf@maritornes.cs.unb.ca>\r
+ <m2mwi8q6gh.fsf@guru.guru-group.fi>\r
+User-Agent: Notmuch/0.17+55~g4397960 (http://notmuchmail.org) Emacs/24.3.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: Mon, 03 Feb 2014 23:21:03 +0200\r
+Message-ID: <m2sirzj3k0.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\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: Mon, 03 Feb 2014 21:21:17 -0000\r
+\r
+On Mon, Feb 03 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+\r
+> On Mon, Feb 03 2014, David Bremner <david@tethera.net> wrote:\r
+>\r
+>> Antoine Beaupr=C3=A9 found a bug when notmuch-saved-searches contains=20\r
+>> newlines:\r
+>>\r
+>> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D737496\r
+>>\r
+>> We can remove newlines with something like\r
+>>=20=20=20=20=20=20=20=20=20=20=20\r
+>> (mapcar (lambda (arg)=20\r
+>> (replace-regexp-in-string "\n" " " arg))\r
+>> args)\r
+>>\r
+>> I wonder if we should do some other sanitization at the same time?\r
+>\r
+> It took a while to reproduce...\r
+>\r
+> $ echo $'foo\nbar' | notmuch count --batch=20\r
+> 665\r
+> 631\r
+>\r
+> $ echo $'foo\n and bar' | notmuch count --batch\r
+> 665\r
+> A Xapian exception occurred: Syntax: <expression> AND <expression>\r
+> Query string was: and bar\r
+> 0\r
+>\r
+> Therefore: (wrong-type-argument number-or-marker-p A)\r
+>\r
+> (I run non-byte-compiled version of (one-) notmuch.el and\r
+> got this as a backtrace:\r
+>\r
+> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p A)\r
+> >(A 0)\r
+> (or (plist-get options :show-empty-searches) (> message-count 0))\r
+> ...\r
+> (notmuch-remove-if-not\r
+> ...\r
+> notmuch-hello-query-counts\r
+> ...\r
+>\r
+> simpler way to reproduce:\r
+>\r
+> $ notmuch count 'and bar'\r
+> A Xapian exception occurred: Syntax: <expression> AND <expression>\r
+> Query string was: and bar\r
+> 0\r
+>\r
+> Maybe the cli should be fixed ? (and/or make emacs MUA resilient to\r
+> this kind of result)\r
+\r
+of yes, the notmuch count --batch gets borken with \n -- from one\r
+query there are 2 new count queries (and counts should be all wrong\r
+from that point on (if there were no Xapian exception))\r
+\r
+We would not have noticed this (as easily) if the Xapian execption did not\r
+happen.\r
+\r
+So, whether (or not?) some fixing is done in CLI the batch query emacs\r
+sends needs to be sanitized exactly as David suggested above.\r
+\r
+>\r
+>>\r
+>> d\r
+>>\r
+>\r
+> Tomi\r
+\r
+Tomi\r
+\r