summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2020-04-07 14:22:18 +0200
committerRicardo Wurmus <rekado@elephly.net>2020-04-07 14:22:18 +0200
commit2549353d92c9e86115d4b970da9b757977452890 (patch)
tree6a948e5fb33d0d857617773b0468b8ef9088e757
parent01ed2c8ee5a7c4facce6b15fdd01fbdafd28a5ea (diff)
messages: Add fetch-mbox*.
-rw-r--r--mumi/messages.scm30
1 files changed, 30 insertions, 0 deletions
diff --git a/mumi/messages.scm b/mumi/messages.scm
index beb9f1a..a1b8805 100644
--- a/mumi/messages.scm
+++ b/mumi/messages.scm
@@ -33,6 +33,7 @@
#:use-module (mumi config)
#:use-module ((mumi bugs) #:prefix db:)
#:use-module (mumimu)
+ #:use-module (web client)
#:export (search-bugs
fetch-bug
recent-bugs
@@ -154,6 +155,35 @@ we have to do this in a very convoluted way."
(format #f "~a/mbox/~a"
(%config 'mail-dir) bug-id))
+;; This is a modified version of fetch-mbox from guile-debbugs: it
+;; supports downloading with an offset. It also only supports
+;; streaming and doesn't bother with msg-num.
+(define* (fetch-mbox* instance bug-number #:optional mbox-type
+ #:key offset mdate)
+ "Download the mbox containing messages of bug BUG-NUMBER from the
+Debbugs server INSTANCE (a procedure returning a string when given the
+symbol 'email)."
+ (let* ((options
+ `((bug . ,(number->string bug-number))
+ ,@(cond
+ ((member mbox-type '(mboxmaint mboxstat mboxstatus))
+ `((mbox-type . "yes")))
+ (else '()))
+ (mbox . "yes")))
+ (uri (string-append (instance 'email) "?"
+ (string-join (map (match-lambda
+ ((key . value)
+ (format #f "~a=~a" key value)))
+ options)
+ ";")))
+ (headers `(,@(if offset
+ `((range . (bytes (,offset . #f))))
+ '())
+ ,@(if mdate
+ `((if-modified-since . ,mdate))
+ '()))))
+ (http-get uri #:streaming? #t #:headers headers)))
+
;; We would like to use get-bug-log here, but it often returns
;; truncated messages. This is a known bug upstream.