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