[PATCH] emacs: Function to query the list of labels from a thread-id
authorDamien Cassou <damien.cassou@gmail.com>
Sun, 28 Oct 2012 19:11:18 +0000 (20:11 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:08 +0000 (09:50 -0800)
d0/e5aad9ddb9ed9d8156c741604c52710a55fe5f [new file with mode: 0644]

diff --git a/d0/e5aad9ddb9ed9d8156c741604c52710a55fe5f b/d0/e5aad9ddb9ed9d8156c741604c52710a55fe5f
new file mode 100644 (file)
index 0000000..e53f566
--- /dev/null
@@ -0,0 +1,132 @@
+Return-Path: <damien.cassou@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 BE591431FB6\r
+       for <notmuch@notmuchmail.org>; Sun, 28 Oct 2012 12:11:26 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, 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 QwEj20YBmlw8 for <notmuch@notmuchmail.org>;\r
+       Sun, 28 Oct 2012 12:11:26 -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 2097E431FAF\r
+       for <notmuch@notmuchmail.org>; Sun, 28 Oct 2012 12:11:25 -0700 (PDT)\r
+Received: by mail-wi0-f169.google.com with SMTP id hq4so1620521wib.2\r
+       for <notmuch@notmuchmail.org>; Sun, 28 Oct 2012 12:11:23 -0700 (PDT)\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;\r
+       bh=f/0dWmGrL1TR/3DwWEAj1Oo768CiBwmLGm998VRwXs8=;\r
+       b=lz/SHpvrSJ0cFgnKVLa2yE6/XhdwqLaSeRnJv6nWwsUiGVTlpnFaQu/eczdExXm07h\r
+       GBBWFZQuLudrlPv3V3iVvq7ypx6KZr+KLx1vCCYbO7ynF6LMiX7ZiWWg9x54xrfOppMv\r
+       Robopc5oXxCVycNfdes/Sw6cQucJr1YCD4SPngUG5dbbGzEM0yITApe9KmULIVrBN8hq\r
+       7z4u00d+bEpM5sB58LsD9c5nmJKX3booYZnrMXQP3oyQIVMpWWD1AAsW4f6YcmLbEmIh\r
+       SFgplxB4NNIc+16eDRhXOsVtiiSdSiw8BdjkzMuXRLjRZSZg0e11UGXeWVxkS9YL4x5k\r
+       SVyg==\r
+Received: by 10.180.84.202 with SMTP id b10mr12217017wiz.13.1351451483547;\r
+       Sun, 28 Oct 2012 12:11:23 -0700 (PDT)\r
+Received: from localhost.localdomain (ble59-4-82-228-190-150.fbx.proxad.net.\r
+       [82.228.190.150])\r
+       by mx.google.com with ESMTPS id az2sm6991606wib.10.2012.10.28.12.11.21\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sun, 28 Oct 2012 12:11:22 -0700 (PDT)\r
+From: Damien Cassou <damien.cassou@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: Function to query the list of labels from a thread-id\r
+Date: Sun, 28 Oct 2012 20:11:18 +0100\r
+Message-Id: <1351451478-11792-1-git-send-email-damien.cassou@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\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, 28 Oct 2012 19:11:26 -0000\r
+\r
+This patch adds `notmuch-query-thread-labels-from-id' and\r
+corresponding test. This function returns the labels of thread whose\r
+id is passed as argument. The thread labels are the union of the\r
+labels of emails in the thread. I need this function to integrate\r
+notmuch-labeler.\r
+\r
+Signed-off-by: Damien Cassou <damien.cassou@gmail.com>\r
+---\r
+ emacs/notmuch-query.el |   16 ++++++++++++++++\r
+ test/emacs             |   23 +++++++++++++++++++++++\r
+ 2 files changed, 39 insertions(+)\r
+\r
+diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el\r
+index d66baea..8b9a41d 100644\r
+--- a/emacs/notmuch-query.el\r
++++ b/emacs/notmuch-query.el\r
+@@ -81,4 +81,20 @@ See the function notmuch-query-get-threads for more information."\r
+    (lambda (msg) (plist-get msg :id))\r
+    (notmuch-query-get-threads search-terms)))\r
+\r
++(defun notmuch-query-thread-labels-from-id (thread-id)\r
++  "Return the labels of thread whose id is THREAD-ID.\r
++The thread labels are the union of the labels of emails in the\r
++thread."\r
++  (let ((label-lists\r
++       (notmuch-query-map-forest\r
++        (lambda (msg) (plist-get msg :tags))\r
++        (car (notmuch-query-get-threads\r
++              (list (concat "thread:" thread-id)))))))\r
++    (case (length label-lists)\r
++      (0 nil)\r
++      (1 (car label-lists))\r
++      (otherwise (reduce (lambda (l1 l2)\r
++                         (union l1 l2 :test 'string=))\r
++                       label-lists)))))\r
++\r
+ (provide 'notmuch-query)\r
+diff --git a/test/emacs b/test/emacs\r
+index 44f641e..3e8bdb8 100755\r
+--- a/test/emacs\r
++++ b/test/emacs\r
+@@ -820,5 +820,28 @@ Date: Fri, 05 Jan 2001 15:43:57 +0000\r
+ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+\r
++test_begin_subtest "Extracting all labels from a thread"\r
++add_message \\r
++    '[subject]="Extracting all labels from a thread"' \\r
++    '[body]="body 1"'\r
++first=${gen_msg_cnt}\r
++parent=${gen_msg_id}\r
++add_message \\r
++    '[subject]="Extracting all labels from a thread"' \\r
++    '[body]="body 2"' \\r
++    "[in-reply-to]=\<$parent\>"\r
++add_message \\r
++    '[subject]="Extracting all labels from a thread"' \\r
++    '[body]="body 3"' \\r
++    "[in-reply-to]=\<$parent\>"\r
++latest=${gen_msg_id}\r
++# Extract the thread-id from one of the emails\r
++thread_id=$(notmuch search id:${latest} | sed -e "s/thread:\([a-f0-9]*\).*/\1/")\r
++# Add tag "mytagfoo" to one of the emails\r
++notmuch tag +mytagfoo id:${latest}\r
++test_emacs_expect_t \\r
++    "(let ((output (notmuch-query-thread-labels-from-id \"${thread_id}\"))\r
++           (expected '(\"inbox\" \"mytagfoo\" \"unread\")))\r
++      (notmuch-test-expect-equal output expected))"\r
+\r
+ test_done\r
+--\r
+1.7.10.4\r