[PATCH v2 7/7] emacs: make emacs use message-ids for tagging
authormarkwalters1009 <markwalters1009@gmail.com>
Sat, 24 Nov 2012 13:20:56 +0000 (13:20 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:50 +0000 (09:50 -0800)
d8/b356c36751ee06274c0648738634b950d28df1 [new file with mode: 0644]

diff --git a/d8/b356c36751ee06274c0648738634b950d28df1 b/d8/b356c36751ee06274c0648738634b950d28df1
new file mode 100644 (file)
index 0000000..d16c4c3
--- /dev/null
@@ -0,0 +1,169 @@
+Return-Path: <markwalters1009@gmail.com>\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 C03A4431FBD\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 05:21:20 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       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 xpsO+ECaZSBh for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Nov 2012 05:21:19 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 7B44E431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 05:21:19 -0800 (PST)\r
+Received: by mail-we0-f181.google.com with SMTP id t11so3934097wey.26\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 05:21:18 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=x21H9sO0YJw+KzZLVr8jpQuzQBEggwvFWQGE5F7gVNs=;\r
+       b=qGRw7/RMtr2kjob00isFhYYC/fBngnVE9BTj1n2KG5BTuHFzjG9wHOUctpqK3lnWaC\r
+       zP8rcjpSCN7ufeV2TL/OdpUoZTsZdbWx6MRyXvbJdxf3swNJK/cU2310e6Q+md5IOqL5\r
+       qSubQWzwHb6znkRFtslSIG4NDwnzQwQhP354GugVcquAnbuwuvo0htGLd4cByCCLXZRF\r
+       Xt5s5rwYvJNomjmwLoH1eUzm1XWU7cko6z4KxGbORxbHXlwuGN66QLp0XfN1Axn04HOK\r
+       sfqFrGijn3fna6yDNg2EpNG7MWH2dRrcSegbPTDQWFuzl50lWVXcLq49Ofh2TZj3OIc1\r
+       Pb8w==\r
+Received: by 10.180.81.170 with SMTP id b10mr9835809wiy.16.1353763278256;\r
+       Sat, 24 Nov 2012 05:21:18 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPS id b1sm14246472wix.11.2012.11.24.05.21.16\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 24 Nov 2012 05:21:17 -0800 (PST)\r
+From: markwalters1009 <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 7/7] emacs: make emacs use message-ids for tagging\r
+Date: Sat, 24 Nov 2012 13:20:56 +0000\r
+Message-Id: <1353763256-32336-8-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com>\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: Sat, 24 Nov 2012 13:21:21 -0000\r
+\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
+     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
+ (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
++(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
++           (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
+                    (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
+-- \r
+1.7.9.1\r
+\r