Initial commit.
[software/mumi.git] / mumi / queries.scm
1 ;;; mumi -- Mediocre, uh, mail interface
2 ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
3 ;;;
4 ;;; This program is free software: you can redistribute it and/or
5 ;;; modify it under the terms of the GNU Affero General Public License
6 ;;; as published by the Free Software Foundation, either version 3 of
7 ;;; the License, or (at your option) any later version.
8 ;;;
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;; Affero General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU Affero General Public
15 ;;; License along with this program. If not, see
16 ;;; <http://www.gnu.org/licenses/>.
17
18 (define-module (mumi queries)
19 #:use-module (mumi config)
20 #:use-module (mu)
21 #:use-module (srfi srfi-1)
22 #:use-module (srfi srfi-26)
23 #:export (query-and
24 query-or))
25
26 (define-public (group s)
27 (string-append "(" s ")"))
28
29 (define-syntax-rule (query-and e ...)
30 (group (string-join (list e ...) " ")))
31
32 (define-syntax-rule (query-or e ...)
33 (group (string-join (list e ...) " OR ")))
34
35 (define-public (msgid id)
36 (string-append "msgid:" id))
37
38 (define-public (messages-in-thread id)
39 (append
40 (mu:message-list (msgid id))
41 (filter (lambda (msg)
42 (member id (mu:references msg)))
43 (mu:message-list (assoc-ref %config 'list)))))