--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 ECDF2431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 16:38:20 -0800 (PST)\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 jlzzWHYHZOAj for <notmuch@notmuchmail.org>;\r
+ Sat, 24 Nov 2012 16:38:18 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+ [18.7.68.35])\r
+ by olra.theworths.org (Postfix) with ESMTP id A220F431FAE\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 16:38:18 -0800 (PST)\r
+X-AuditID: 12074423-b7fab6d0000008f9-65-50b1687a3def\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 9E.BA.02297.A7861B05; Sat, 24 Nov 2012 19:38:18 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qAP0cHF3007359; \r
+ Sat, 24 Nov 2012 19:38:18 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qAP0cFHe007027\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+ Sat, 24 Nov 2012 19:38:16 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1TcQEh-0006c6-Ki; Sat, 24 Nov 2012 19:38:15 -0500\r
+Date: Sat, 24 Nov 2012 19:38:15 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: markwalters1009 <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH v2 7/7] emacs: make emacs use message-ids for tagging\r
+Message-ID: <20121125003815.GK4562@mit.edu>\r
+References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com>\r
+ <1353763256-32336-8-git-send-email-markwalters1009@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1353763256-32336-8-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT0a3K2Bhg0P+Q22L1XB6L6zdnMjsw\r
+ eeycdZfd49mqW8wBTFFcNimpOZllqUX6dglcGUveLGIueKZZsba3uoHxrmIXIyeHhICJxPWD\r
+ L1kgbDGJC/fWs3UxcnEICexjlLjePIEJwtnAKLHuzC8mkCohgYtMEguaJCASSxgl9q7+zQyS\r
+ YBFQlTi89i2YzSagIbFt/3JGEFtEQF9iz4rbbCA2s4C0xLffzWCDhAU8Jdp/vwVbzSugLbHw\r
+ Wx8zxNBORolzLTtZIRKCEidnPmGBaNaSuPHvJVAzB9ig5f84QMKcAl4Se453g+0VFVCRmHJy\r
+ G9sERqFZSLpnIemehdC9gJF5FaNsSm6Vbm5iZk5xarJucXJiXl5qka6ZXm5miV5qSukmRnBQ\r
+ uyjvYPxzUOkQowAHoxIP743EjQFCrIllxZW5hxglOZiURHlz0oBCfEn5KZUZicUZ8UWlOanF\r
+ hxglOJiVRHitVYFyvCmJlVWpRfkwKWkOFiVx3mspN/2FBNITS1KzU1MLUotgsjIcHEoSvLHp\r
+ QI2CRanpqRVpmTklCGkmDk6Q4TxAw51BaniLCxJzizPTIfKnGBWlxHk9QBICIImM0jy4XljS\r
+ ecUoDvSKMO9ZkCoeYMKC634FNJgJaPDT2etABpckIqSkGhgbTC73HlZpmn/yZnnRix0iIqoL\r
+ 41rLPh7ZsO/0d9amDRoKxfaBM2RlTRZyh5WIau/85Ky+VXJatrtfiplEcDeLYGm1w9XgZe4M\r
+ 7QyTV3jMdRdnmS6sqG+0fWWtlciEYA/7owptLc8fyN0ua71ep7qKq+1L78RdZW/OV2aF/a69\r
+ onHi81aJNUosxRmJhlrMRcWJAHH+5CYVAwAA\r
+Cc: notmuch@notmuchmail.org\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: Sun, 25 Nov 2012 00:38:21 -0000\r
+\r
+Quoth markwalters1009 on Nov 24 at 1:20 pm:\r
+> From: Mark Walters <markwalters1009@gmail.com>\r
+> \r
+> This makes emacs use the new --queries=true in search mode and use\r
+> this for tagging. This fixes the race condition in tagging from\r
+> search mode so mark the tests fixed.\r
+> ---\r
+> emacs/notmuch.el | 28 +++++++++++++++++++++++++---\r
+> test/emacs | 2 --\r
+> 2 files changed, 25 insertions(+), 5 deletions(-)\r
+> \r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index 64b9474..6e8ef83 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -473,7 +473,8 @@ BEG."\r
+> (let (output)\r
+> (notmuch-search-foreach-result beg end\r
+> (lambda (pos)\r
+> - (push (plist-get (notmuch-search-get-result pos) property) output)))\r
+> + (let ((value (plist-get (notmuch-search-get-result pos) property)))\r
+> + (when value (push value output)))))\r
+\r
+Why is this necessary? (Assuming it is, it could use a comment, and\r
+probably an update to the docstring.)\r
+\r
+> output))\r
+> \r
+> (defun notmuch-search-find-thread-id (&optional bare)\r
+> @@ -483,6 +484,7 @@ If BARE is set then do not prefix with \"thread:\""\r
+> (let ((thread (plist-get (notmuch-search-get-result) :thread)))\r
+> (when thread (concat (unless bare "thread:") thread))))\r
+> \r
+> +\r
+\r
+Unintentional?\r
+\r
+> (defun notmuch-search-find-thread-id-region (beg end)\r
+> "Return a list of threads for the current region"\r
+> (mapcar (lambda (thread) (concat "thread:" thread))\r
+> @@ -492,6 +494,23 @@ If BARE is set then do not prefix with \"thread:\""\r
+> "Return a search string for threads for the current region"\r
+> (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))\r
+> \r
+> +;; The following two functions are similar to the previous two but\r
+> +;; they only match messages that were in the the thread when the\r
+> +;; initial search was run. This means that they can be used where it\r
+> +;; is important to avoid races: e.g. when tagging.\r
+> +(defun notmuch-search-find-queries-region (beg end &optional only-matching)\r
+> + (interactive)\r
+> + "Return a list of queries for the current region"\r
+> + (append (notmuch-search-properties-in-region :matching_msg_query beg end)\r
+> + (unless only-matching\r
+> + (notmuch-search-properties-in-region :nonmatching_msg_query beg end))))\r
+\r
+Two minor performance nits: Using nconc instead of append will avoid\r
+copying the first list and swapping the two arguments will avoid\r
+needlessly traversing the non-matching list when only-matching is nil.\r
+\r
+> +\r
+> +(defun notmuch-search-find-queries-region-search (beg end &optional only-matching)\r
+> + "Return a search string for messages in threads in the current region"\r
+> + (mapconcat 'identity\r
+\r
+#'identity\r
+\r
+> + (notmuch-search-find-queries-region beg end only-matching)\r
+> + " or "))\r
+> +\r
+> (defun notmuch-search-find-authors ()\r
+> "Return the authors for the current thread"\r
+> (plist-get (notmuch-search-get-result) :authors))\r
+> @@ -575,7 +594,7 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
+> \r
+> (defun notmuch-search-tag-region (beg end &optional tag-changes)\r
+> "Change tags for threads in the given region."\r
+> - (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
+> + (let ((search-string (notmuch-search-find-queries-region-search beg end)))\r
+> (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))\r
+> (notmuch-search-foreach-result beg end\r
+> (lambda (pos)\r
+> @@ -851,7 +870,9 @@ non-authors is found, assume that all of the authors match."\r
+> \r
+> See `notmuch-tag' for information on the format of TAG-CHANGES."\r
+> (interactive)\r
+> - (apply 'notmuch-tag notmuch-search-query-string tag-changes))\r
+> + (apply 'notmuch-tag (notmuch-search-find-queries-region-search\r
+> + (point-min) (point-max) t)\r
+> + tag-changes))\r
+> \r
+> (defun notmuch-search-buffer-title (query)\r
+> "Returns the title for a buffer with notmuch search results."\r
+> @@ -948,6 +969,7 @@ Other optional parameters are used as follows:\r
+> "notmuch-search" buffer\r
+> notmuch-command "search"\r
+> "--format=json"\r
+> + "--output=with-queries"\r
+\r
+--output=with-queries or --queries=true?\r
+\r
+> (if oldest-first\r
+> "--sort=oldest-first"\r
+> "--sort=newest-first")\r
+> diff --git a/test/emacs b/test/emacs\r
+> index 3788439..132768f 100755\r
+> --- a/test/emacs\r
+> +++ b/test/emacs\r
+> @@ -123,7 +123,6 @@ output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)\r
+> test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"\r
+> \r
+> test_begin_subtest "Tag all matching messages from search view"\r
+> -test_subtest_known_broken\r
+> notmuch tag +test-tag-race from:cworth\r
+> test_emacs "(notmuch-search \"tag:test-tag-race\")\r
+> (notmuch-test-wait)"\r
+> @@ -135,7 +134,6 @@ notmuch tag -test-tag-race '*'\r
+> notmuch tag -test-tag-race-2 '*'\r
+> \r
+> test_begin_subtest "Change tags from search view: another message arriving after thread lookup"\r
+> -test_subtest_known_broken\r
+> typsos_id="878we4qdqf.fsf@yoom.home.cworth.org"\r
+> typsos_thread=$(notmuch search --output=threads id:$typsos_id)\r
+> test_emacs "(notmuch-search \"$typsos_thread\")\r