summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--piem-b4.el19
-rw-r--r--piem.el15
2 files changed, 30 insertions, 4 deletions
diff --git a/piem-b4.el b/piem-b4.el
index 537abed..39d32be 100644
--- a/piem-b4.el
+++ b/piem-b4.el
@@ -47,10 +47,6 @@
;;;; Internals
-;; In many cases, we don't really need b4 to download the mbox for us,
-;; as we already have our own mbox to URL mapping. Perhaps we should
-;; default to using that, but it should still be an option to use b4
-;; so that we honor its customization/URL resolution.
(defun piem-b4--get-am-files (mid coderepo args)
(let* ((outdir (file-name-as-directory
(make-temp-file "piem-b4-" t)))
@@ -63,6 +59,21 @@
(funcall fn)
(unless (= (point-max) 1)
(setq local-mbox-p t))))
+ ;; `piem-mid-to-thread-functions' didn't generate an mbox. Next
+ ;; try to download it from a URL at `piem-inboxes'. Finally, fall
+ ;; back to b4's configuration.
+ (unless local-mbox-p
+ (when-let ((url (piem-inbox-url))
+ (mid (piem-mid))
+ (buffer (condition-case nil
+ (piem-download-and-decompress
+ (concat url mid "/t.mbox.gz"))
+ (user-error nil))))
+ (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (write-region nil nil mbox-thread))
+ (kill-buffer buffer)
+ (setq local-mbox-p t))))
;; Move to the coderepo so that we pick up any b4 configuration
;; from there.
(apply #'piem-process-call coderepo piem-b4-b4-executable "am"
diff --git a/piem.el b/piem.el
index 029b647..3669cfe 100644
--- a/piem.el
+++ b/piem.el
@@ -390,6 +390,21 @@ buffer."
(delete-region (point) (point-max))
(goto-char (point-min)))
+(defun piem--decompress-callback (status)
+ (if (plist-get status :error)
+ (kill-buffer (current-buffer))
+ (piem--url-remove-header)
+ (piem--url-decompress)))
+
+(defun piem-download-and-decompress (url)
+ "Retrieve gzipped content at URL and decompress it.
+A buffer with the decompressed content is returned. A live
+buffer indicates that the request did not result in an error."
+ (unless (piem-check-gunzip)
+ (user-error "gunzip executable not found"))
+ (let ((url-asynchronous nil))
+ (url-retrieve url #'piem--decompress-callback)))
+
(defun piem--write-mbox-to-maildir ()
(let ((n-messages 0))
(while (and (not (eobp))