1 Return-Path: <bremner@pivot.cs.unb.ca>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 666B84196F4
\r
6 for <notmuch@notmuchmail.org>; Mon, 5 Apr 2010 09:46:54 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id VZWfZhs0CQY9 for <notmuch@notmuchmail.org>;
\r
16 Mon, 5 Apr 2010 09:46:53 -0700 (PDT)
\r
17 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])
\r
18 by olra.theworths.org (Postfix) with ESMTP id E52E04196F0
\r
19 for <notmuch@notmuchmail.org>; Mon, 5 Apr 2010 09:46:52 -0700 (PDT)
\r
21 fctnnbsc30w-142167190087.pppoe-dynamic.high-speed.nb.bellaliant.net
\r
22 ([142.167.190.87] helo=rocinante.cs.unb.ca)
\r
23 by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
\r
24 (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)
\r
25 id 1NypRr-0002h9-Ux; Mon, 05 Apr 2010 13:46:52 -0300
\r
26 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.71)
\r
27 (envelope-from <bremner@rocinante.cs.unb.ca>)
\r
28 id 1NypRm-0003N8-6A; Mon, 05 Apr 2010 13:46:46 -0300
\r
29 From: david@tethera.net
\r
30 To: notmuch@notmuchmail.org
\r
31 Date: Mon, 5 Apr 2010 13:46:16 -0300
\r
32 Message-Id: <1270485976-12776-1-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 1.7.0
\r
34 In-Reply-To: <1267015920-8999-1-git-send-email-david@tethera.net>
\r
35 References: <1267015920-8999-1-git-send-email-david@tethera.net>
\r
36 X-Sender-Verified: bremner@pivot.cs.unb.ca
\r
37 Cc: David Bremner <bremner@unb.ca>
\r
38 Subject: [notmuch] [PATCH v3] notmuch-query.el: new file to support access
\r
39 to the notmuch database.
\r
40 X-BeenThere: notmuch@notmuchmail.org
\r
41 X-Mailman-Version: 2.1.13
\r
43 List-Id: "Use and development of the notmuch mail system."
\r
44 <notmuch.notmuchmail.org>
\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
48 List-Post: <mailto:notmuch@notmuchmail.org>
\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
52 X-List-Received-Date: Mon, 05 Apr 2010 16:46:54 -0000
\r
54 From: David Bremner <bremner@unb.ca>
\r
56 Initially this file provides one main function
\r
57 notmuch-query-get-threads, which takes a set of search terms, and
\r
58 returns a parsed set of matching threads as a lisp data structure.
\r
60 A set of notmuch-query-map-* functions are provided to help map
\r
61 functions over the data structure.
\r
63 The function notmuch-query-get-message-ids uses this machinery to get
\r
64 the set of message-ids matching a query.
\r
67 Commentary on this revision of the patch.
\r
68 - Rebased to current master.
\r
69 - Last time I checked, used by dme's json rewrite of the emacs ui
\r
70 - Warnings eliminated by including the new notmuch-lib.el
\r
72 emacs/Makefile.local | 1 +
\r
73 emacs/notmuch-query.el | 90 ++++++++++++++++++++++++++++++++++++++++++++++++
\r
74 2 files changed, 91 insertions(+), 0 deletions(-)
\r
75 create mode 100644 emacs/notmuch-query.el
\r
77 diff --git a/emacs/Makefile.local b/emacs/Makefile.local
\r
78 index 95b6fa4..626a4e5 100644
\r
79 --- a/emacs/Makefile.local
\r
80 +++ b/emacs/Makefile.local
\r
81 @@ -4,6 +4,7 @@ dir := emacs
\r
83 $(dir)/notmuch-lib.el \
\r
85 + $(dir)/notmuch-query.el \
\r
86 $(dir)/notmuch-show.el
\r
88 emacs_bytecode := $(subst .el,.elc,$(emacs_sources))
\r
89 diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
\r
90 new file mode 100644
\r
91 index 0000000..3f1a7b3
\r
93 +++ b/emacs/notmuch-query.el
\r
95 +; notmuch-query.el --- provide an emacs api to query notmuch
\r
97 +; Copyright © David Bremner
\r
99 +; This file is part of Notmuch.
\r
101 +; Notmuch is free software: you can redistribute it and/or modify it
\r
102 +; under the terms of the GNU General Public License as published by
\r
103 +; the Free Software Foundation, either version 3 of the License, or
\r
104 +; (at your option) any later version.
\r
106 +; Notmuch is distributed in the hope that it will be useful, but
\r
107 +; WITHOUT ANY WARRANTY; without even the implied warranty of
\r
108 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
109 +; General Public License for more details.
\r
111 +; You should have received a copy of the GNU General Public License
\r
112 +; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
114 +; Authors: David Bremner <david@tethera.net>
\r
116 +(require 'notmuch-lib)
\r
119 +(defun notmuch-query-get-threads (search-terms &rest options)
\r
120 + "Return a list of threads of messages matching SEARCH-TERMS.
\r
122 +A thread is a forest or list of trees. A tree is a two element
\r
123 +list where the first element is a message, and the second element
\r
124 +is a possibly empty forest of replies.
\r
126 + (let ((args (append '("show" "--format=json") search-terms))
\r
127 + (json-object-type 'plist)
\r
128 + (json-array-type 'list)
\r
129 + (json-false 'nil))
\r
130 + (with-temp-buffer
\r
132 + (apply 'call-process (append (list notmuch-command nil t nil) args))
\r
133 + (goto-char (point-min))
\r
136 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
137 +;; Mapping functions across collections of messages.
\r
139 +(defun notmuch-query-map-aux (mapper function seq)
\r
140 + "private function to do the actual mapping and flattening"
\r
145 + (funcall mapper fn tree))
\r
149 +(defun notmuch-query-map-threads (fn threads)
\r
150 + "apply FN to every thread in THREADS. Flatten results to a list.
\r
152 +See the function notmuch-query-get-threads for more information."
\r
154 + (notmuch-query-map-aux 'notmuch-query-map-forest fn threads))
\r
157 +(defun notmuch-query-map-forest (fn forest)
\r
158 + "apply function to every message in a forest. Flatten results to a list.
\r
160 +See the function notmuch-query-get-threads for more information.
\r
163 + (notmuch-query-map-aux 'notmuch-query-map-tree fn forest))
\r
166 +(defun notmuch-query-map-tree (fn tree)
\r
167 + "Apply function FN to every message in TREE. Flatten results to a list
\r
169 +See the function notmuch-query-get-threads for more information."
\r
171 + (cons (funcall fn (car tree)) (notmuch-query-map-forest fn (cadr tree))))
\r
174 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
175 +;; Predefined queries
\r
177 +(defun notmuch-query-get-message-ids (&rest search-terms)
\r
178 + "Return a list of message-ids of messages that match SEARCH-TERMS"
\r
180 + (notmuch-query-map-threads
\r
181 + (lambda (msg) (plist-get msg :id))
\r
182 + (notmuch-query-get-threads search-terms)))
\r
184 +(provide 'notmuch-query)
\r