Re: [PATCH] emacs: Function to query the list of labels from a thread-id
authorJani Nikula <jani@nikula.org>
Tue, 30 Oct 2012 20:48:25 +0000 (22:48 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:13 +0000 (09:50 -0800)
70/424ddd26df3a0a8344a6f25b15ab575b3a4d0d [new file with mode: 0644]

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