--- /dev/null
+Return-Path: <dme@dme.org>\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 DB1D3431FCB\r
+ for <notmuch@notmuchmail.org>; Wed, 21 May 2014 03:47:36 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 Tfyz5r-Saq7U for <notmuch@notmuchmail.org>;\r
+ Wed, 21 May 2014 03:47:32 -0700 (PDT)\r
+Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com\r
+ [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id E0CC8431FC7\r
+ for <notmuch@notmuchmail.org>; Wed, 21 May 2014 03:47:31 -0700 (PDT)\r
+Received: by mail-wi0-f169.google.com with SMTP id hi2so8232030wib.4\r
+ for <notmuch@notmuchmail.org>; Wed, 21 May 2014 03:47:29 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:to:cc:subject:in-reply-to:references:user-agent\r
+ :from:date:message-id:mime-version:content-type;\r
+ bh=wsw89nD/+Xn1rzy3UkihdIVKMNw7TRbtvzH9343IWIY=;\r
+ b=FFVYwZfk61wBAP6CGd4uPKDFC5iZCAmxzLmhuCcKGPIfuC5+ChvBdHdZOQ8vqbz8/R\r
+ 6Hb3aC6C8MPGqr5AcT/JdPjArya7cs8iqyhcnX6xc+4Fo8B+lkVItHdd/TosVxZ3uaGf\r
+ gg2O+lUFPztdYM8d+LHBo01NHXXO2r9quxlGRMrmHj9oI9liilqV7FSa0r5bTEWxoy7z\r
+ fjNnMHzgr4zd0fBUBPjiGjYcO7I3xBth6MMSXOkm8nVT+Asnm6EjymsJPw+XHmpVKd2I\r
+ Z5PqG28SWAGA6vL+mitWsUa+dkfc8yRmEyHCcMmlPHj8P0HsU5Yv6sZRGNUukPEN0gqp\r
+ m4LQ==\r
+X-Gm-Message-State:\r
+ ALoCoQkfoA+Sqoanex8SVUYxQpv86/URsjfxfQlWfayGBj5Gw+wGZeYxUQ7Ts5jgR9Ppnab+5QAG\r
+X-Received: by 10.194.187.107 with SMTP id fr11mr1552816wjc.70.1400669249358; \r
+ Wed, 21 May 2014 03:47:29 -0700 (PDT)\r
+Received: from localhost ([2a01:348:1a2:1:a288:b4ff:fe8a:77d8])\r
+ by mx.google.com with ESMTPSA id l4sm22093993wjf.14.2014.05.21.03.47.27\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Wed, 21 May 2014 03:47:28 -0700 (PDT)\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] emacs: make sure tagging on an empty query is harmless\r
+In-Reply-To: <1400666330-4363-1-git-send-email-markwalters1009@gmail.com>\r
+References: <87iop0ynl2.fsf@qmul.ac.uk>\r
+ <1400666330-4363-1-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Notmuch/0.18 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-pc-linux-gnu)\r
+From: David Edmondson <dme@dme.org>\r
+Date: Wed, 21 May 2014 11:47:23 +0100\r
+Message-ID: <cuny4xvtnlw.fsf@hotblack-desiato.hh.sledj.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+ micalg=pgp-sha1; protocol="application/pgp-signature"\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: Wed, 21 May 2014 10:47:37 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Wed, May 21 2014, Mark Walters wrote:\r
+> Currently notmuch-tag throws a "wrong-type-argument stringp nil" if\r
+> passed a nil query-string. Catch this and provide a more useful error\r
+> message. This fixes a case in notmuch-tree (if you try to tag when at\r
+> the end of the buffer).\r
+>\r
+> Secondly, as pointed out by David (dme)\r
+> `notmuch-search-find-stable-query-region' can return the query string\r
+> () if there are no messages in the region. This gets passed to notmuch\r
+> tag, and due to interactions in the optimize_query code in\r
+> notmuch-tag.c becomes, in the case tag-change is -inbox, "( () ) and\r
+> (tag:inbox)". This query matches some strange collection of messages\r
+> which then get archived. This should probably be fixed, but in any\r
+> case make `notmuch-search-find-stable-query-region' return a nil\r
+> query-string in this case.\r
+>\r
+> This avoids data-loss (random tag removal) in this case.\r
+> ---\r
+>\r
+> This is my attempt to solve the same problem as the parent. I prefer\r
+> not throwing an error in n.s.f.s.q.r as it is difficult for the caller\r
+> to catch cleanly. Throwing it in notmuch-tag is fine as the caller can\r
+> trivially check for query-string being nil before calling notmuch-tag\r
+> if it wants to deal with it gracefully.\r
+>\r
+> If people do prefer an error in n.s.f.s.q.r as in the parent patch\r
+> then I think we should update the error message. The first hunk of\r
+> this should also be applied to catch nil queries to notmuch-tag gracefull=\r
+y.\r
+\r
+I'm fine with this approach.\r
+\r
+> Although this has been present for a while I think it is a dataloss\r
+> issue so a fix should go in for 0.18.1\r
+\r
+As someone who has had to reconstruct a couple of times after being\r
+bitten by this, I would agree.\r
+\r
+> Best wishes\r
+>\r
+> Mark\r
+>\r
+>\r
+>\r
+>\r
+> emacs/notmuch-tag.el | 2 ++\r
+> emacs/notmuch.el | 6 ++++--\r
+> 2 files changed, 6 insertions(+), 2 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el\r
+> index 07c260e..f54aa9d 100644\r
+> --- a/emacs/notmuch-tag.el\r
+> +++ b/emacs/notmuch-tag.el\r
+> @@ -387,6 +387,8 @@ (defun notmuch-tag (query tag-changes)\r
+> (unless (string-match-p "^[-+]\\S-+$" tag-change)\r
+> (error "Tag must be of the form `+this_tag' or `-that_tag'")))\r
+> tag-changes)\r
+> + (unless query\r
+> + (error "Nothing to tag!"))\r
+> (unless (null tag-changes)\r
+> (run-hooks 'notmuch-before-tag-hook)\r
+> (if (<=3D (length query) notmuch-tag-argument-limit)\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index 6c0bc1b..1adea9c 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -428,14 +428,16 @@ (defun notmuch-search-find-stable-query-region (beg=\r
+ end &optional only-matched)\r
+> "Return the stable query for the current region.\r
+>=20=20\r
+> If ONLY-MATCHED is non-nil, include only matched messages. If it\r
+> -is nil, include both matched and unmatched messages."\r
+> +is nil, include both matched and unmatched messages. If there are\r
+> +no messages in the region then return nil."\r
+> (let ((query-list nil) (all (not only-matched)))\r
+> (dolist (queries (notmuch-search-properties-in-region :query beg end=\r
+))\r
+> (when (first queries)\r
+> (push (first queries) query-list))\r
+> (when (and all (second queries))\r
+> (push (second queries) query-list)))\r
+> - (concat "(" (mapconcat 'identity query-list ") or (") ")")))\r
+> + (when query-list\r
+> + (concat "(" (mapconcat 'identity query-list ") or (") ")"))))\r
+>=20=20\r
+> (defun notmuch-search-find-authors ()\r
+> "Return the authors for the current thread"\r
+> --=20\r
+> 1.7.10.4\r
+\r
+--=-=-=\r
+Content-Type: application/pgp-signature; name="signature.asc"\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1\r
+\r
+iKYEARECAGYFAlN8hDtfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl\r
+bnBncC5maWZ0aGhvcnNlbWFuLm5ldDc1M0Y5NDJDMEExNjc3MDE4OURGMUYyMDY5\r
+RUNEMEFCRjA0OTY1MTYACgkQaezQq/BJZRbTSgCfTWVy50oKivVSuv+yxAEbssCh\r
+wZgAn3Gy1ONB1wkLpN+xBZLKLHXwJdog\r
+=JHTn\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r