messages: Add update-mboxes!.
authorRicardo Wurmus <rekado@elephly.net>
Tue, 7 Apr 2020 12:23:08 +0000 (14:23 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Tue, 7 Apr 2020 12:23:08 +0000 (14:23 +0200)
mumi/messages.scm

index a93bd2b9e935147e5e924fcc5e43593378e903df..58a3335d1ff719861a4244d659f05882834b8df8 100644 (file)
@@ -25,6 +25,7 @@
   #:use-module (ice-9 match)
   #:use-module (ice-9 textual-ports)
   #:use-module (ice-9 binary-ports)
+  #:use-module (ice-9 threads)
   #:use-module (debbugs cache)
   #:use-module (debbugs soap)
   #:use-module (debbugs operations)
@@ -41,6 +42,7 @@
             wishlist-bugs
             bugs-by-severity
 
+            update-mboxes!
 
             multipart-message?
             extract-attachment))
@@ -219,6 +221,28 @@ the difference by providing the current file size as an offset."
               file-name)
             #f)))))
 
+(define (update-mboxes! bug-nums)
+  (par-for-each (lambda (bug-num i)
+                  (format (current-error-port)
+                          "[~a/~a] Refreshing mbox of bug ~a...~%"
+                          i (length bug-nums) bug-num)
+                  (force-output (current-error-port))
+                  (parameterize ((current-error-port (%make-void-port OPEN_WRITE)))
+                    (and=> (download-mbox bug-num)
+                           (lambda (mbox)
+                             ;; Split into several files for indexing with mumimu
+                             (let ((mails
+                                    (call-with-input-file mbox mbox->emails)))
+                               (map (lambda (mail index)
+                                      (with-output-to-file
+                                          (format #f "~a/cur/~a.~a"
+                                                  (%config 'mail-dir) bug-num index)
+                                        (lambda ()
+                                          (put-bytevector (current-output-port) mail))))
+                                    mails
+                                    (iota (length mails) 1)))))))
+                bug-nums
+                (iota (length bug-nums) 1)))
 
 ;; We would like to use get-bug-log here, but it often returns
 ;; truncated messages.  This is a known bug upstream.