1 #!@GUILE@ --no-auto-compile
3 -*- geiser-scheme-implementation: guile -*-
5 ;;; mumi -- Mediocre, uh, mail interface
6 ;;; Copyright © 2016, 2017, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
7 ;;; Copyright © 2018, 2021 Arun Isaac <arunisaac@systemreboot.net>
9 ;;; This file is part of mumi.
11 ;;; mumi is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or
14 ;;; (at your option) any later version.
16 ;;; mumi is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;;; General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with mumi. If not, see <http://www.gnu.org/licenses/>.
24 (use-modules (srfi srfi-1)
31 #:select (extract-bug-numbers))
33 #:select (worker-loop))
35 #:select (start-mumi-web-server))
39 (define %default-repl-server-port
40 ;; Default port to run REPL server on, if --listen-repl is provided
41 ;; but no port is mentioned
44 ;; Keep indexing the mail directory
45 (define %update-interval 30)
49 (lambda* (#:key loop?)
50 (set! count (remainder (1+ count) 10))
54 (display "Starting full indexing." (current-error-port))
55 (newline (current-error-port)))
56 (index! #:full? (zero? count))
59 (format (current-error-port)
60 "Sleeping for ~a seconds." %update-interval)
61 (sleep %update-interval)
64 (format (current-error-port) "worker error: ~a~%" args)
65 (sleep %update-interval)
69 ;; Specifications of the command-line options
70 (list (option '("address") #t #f
71 (lambda (opt name arg result)
74 (inet-pton AF_INET arg))
76 (error "invalid web server address" arg)))
77 (alist-cons 'address arg
78 (alist-delete 'address result))))
79 (option '("port") #t #f
80 (lambda (opt name arg result)
81 (let ((port (string->number arg)))
83 (alist-cons 'port port
84 (alist-delete 'port result))
85 (error "invalid web server port" arg)))))
86 (option '("listen-repl") #f #t
87 (lambda (opt name arg result)
88 (let ((port (cond (arg => string->number)
89 (else %default-repl-server-port))))
91 (alist-cons 'listen-repl port
92 (alist-delete 'listen-repl result))
93 (error "invalid REPL server port" arg)))))
94 (option '("disable-mailer") #f #f
95 (lambda (opt name arg result)
96 (alist-cons 'disable-mailer #t result)))
97 (option '("sender") #t #f
98 (lambda (opt name arg result)
99 (alist-cons 'sender arg result)))
100 (option '("smtp") #t #f
101 (lambda (opt name arg result)
102 (alist-cons 'smtp arg result)))))
104 (define %default-options
105 ;; Alist of default option values
109 (disable-mailer . #f)))
111 (define (parse-options args)
114 (lambda (opt name arg result)
115 (error "unrecognized option" name))
117 (error "extraneous argument" arg))
120 (define (show-mumi-usage)
121 (format (current-error-port)
123 `mumi web [--address=address] [--port=port] [--listen-repl[=port]] [--disable-mailer]':
124 start the application web server.
126 `mumi mailer --sender=SENDER --smtp=SMTP:
127 start a mailer process (requires Redis).
130 run an update loop to refresh issue information from Debbugs.
133 index all Debbugs bug logs and update bug statuses once.
138 (match (cdr (program-arguments))
140 (let* ((opts (parse-options rest))
141 (sender (assoc-ref opts 'sender))
142 (smtp (assoc-ref opts 'smtp)))
143 (if (and sender smtp)
145 (error "Both sender and smtp options must be provided!"))))
147 (update-state! #:loop? #f))
149 (update-state! #:loop? #t))
151 (let ((opts (parse-options rest)))
152 (parameterize ((mailer-enabled? (not (assoc-ref opts 'disable-mailer))))
153 (let ((repl-port (assoc-ref opts 'listen-repl)))
155 (format (current-error-port)
156 "REPL server listening on port ~a~%"
158 (spawn-server (make-tcp-server-socket #:port repl-port))))
159 (start-mumi-web-server (or (assoc-ref opts 'address)
161 (or (assoc-ref opts 'port)
163 (_ (show-mumi-usage)))