summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2019-07-19 23:18:31 +0200
committerRicardo Wurmus <rekado@elephly.net>2019-07-19 23:18:53 +0200
commit0412808399454e3c07d0d44361c7cc5962fe2b3a (patch)
tree730d68117bc1e4e462f291b57b6b3aafce6be81c
parent72e8f6b70c814c47090ba2dd5cf618602e917d09 (diff)
operations: Add fetch-mbox.
* debbugs/operations.scm (fetch-mbox): New procedure.
-rw-r--r--debbugs/operations.scm43
1 files changed, 42 insertions, 1 deletions
diff --git a/debbugs/operations.scm b/debbugs/operations.scm
index 5d1eb19..ebf86b4 100644
--- a/debbugs/operations.scm
+++ b/debbugs/operations.scm
@@ -34,7 +34,9 @@
get-bugs
get-bug-log
get-usertag
- search-est))
+ search-est
+
+ fetch-mbox))
(define (soap-email->email email-item)
"Convert an SXML expression representing an email item from a SOAP
@@ -251,3 +253,42 @@ an operator."
(match (soap->scheme item)
(('item (pair) ...) pair)))
items)))))
+
+;; This is not a normal operation. Call it directly, not via
+;; soap-invoke.
+(define* (fetch-mbox instance bug-number #:optional msg-num mbox-type
+ #:key streaming?)
+ "Download the mbox containing messages of bug BUG-NUMBER from the
+Debbugs server INSTANCE (a procedure returning a string when given the
+symbol 'email). If MSG-NUM is not provided, all emails relating to
+this BUG-NUMBER are fetched."
+ (let* ((options
+ `((bug . ,(number->string bug-number))
+ ,@(cond
+ ((member mbox-type '(mboxmaint mboxstat mboxstatus))
+ `((mbox-type . "yes")))
+ (else '()))
+ ,@(if msg-num
+ `((msg . ,msg-num))
+ '())
+ (mbox . "yes")))
+ (uri (string-append (instance 'email) "?"
+ (string-join (map (match-lambda
+ ((key . value)
+ (format #f "~a=~a" key value)))
+ options)
+ ";"))))
+ (if streaming?
+ (http-get uri #:streaming? #t)
+ (call-with-values
+ (lambda () (http-get uri #:streaming? #t))
+ (lambda (response port)
+ (with-input-from-port port
+ (lambda ()
+ (let loop ((bv (get-bytevector-some (current-input-port))))
+ (match bv
+ ((? eof-object?) #t)
+ (bv
+ (put-bytevector (current-output-port) bv)
+ (loop (get-bytevector-some (current-input-port))))))))
+ response)))))