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 E7075431FC0 for ; Tue, 30 Oct 2012 13:48:31 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 DtSMGwX0k+TE for ; Tue, 30 Oct 2012 13:48:30 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 24CC2431FBC for ; Tue, 30 Oct 2012 13:48:29 -0700 (PDT) Received: by mail-lb0-f181.google.com with SMTP id gg6so578724lbb.26 for ; Tue, 30 Oct 2012 13:48:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type:x-gm-message-state; bh=HIFcLJ8fZkLnfIMextv1ZQXHjejlECMj/2+Pp+YEyZk=; b=EABNZlSCGyq41trSFoEnIsJSPqt88FV/7Ojakcuncz3rlEI4ET/o+3cqYoEifxuzKH t+e8dPmoFGen31dDBszv3FwSY+JHNfOEFQYe8mvOQyPbnJcPzwLIrREogAm94yi4x6Iz sZvnGhkRFz7XeIbDp3Ytkdionr00hM27Oz+eaNVCZV6lZoV0R27zzj6m56RWoeG6Scbr 2yseBLugUA9YPti1x3suiprbCWpCWNvG3itXC2zPj0RPmV46hLRREG3SDI3URhOz3Ojw y1BjQ00qPda7JrrJKWsEwx7kP0fkTBHaMs4LkmsG5I3UawCNTLakck0ixh33IFpCwcX9 xABw== Received: by 10.152.114.100 with SMTP id jf4mr31945100lab.47.1351630108413; Tue, 30 Oct 2012 13:48:28 -0700 (PDT) Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id fp7sm678078lab.4.2012.10.30.13.48.26 (version=SSLv3 cipher=OTHER); Tue, 30 Oct 2012 13:48:27 -0700 (PDT) From: Jani Nikula To: Damien Cassou , notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: Function to query the list of labels from a thread-id In-Reply-To: <1351451478-11792-1-git-send-email-damien.cassou@gmail.com> References: <1351451478-11792-1-git-send-email-damien.cassou@gmail.com> User-Agent: Notmuch/0.14+76~gef5e8d1 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Tue, 30 Oct 2012 22:48:25 +0200 Message-ID: <87390v8z52.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQmBCaaU+UvUnTcOCixckmYTUo5AdMAUoHy1SpNVUzRkaZ+tgY+N37jHvIUoiX97uFI4CyGp 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: Tue, 30 Oct 2012 20:48:32 -0000 On Sun, 28 Oct 2012, Damien Cassou wrote: > 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. Hi Damien, please send this patch as part of the series adding notmuch-labeler. Out of context, without adding any users of the function, it's a bit difficult to evaluate. Also note that notmuch uses "tags", not "labels", universally. If what you're referring to is tags, please use that, and if there's a distinction between tags and labels, please describe what it is. BR, Jani. > > 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 > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch