aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2020-08-16 21:33:41 -0400
committerKyle Meyer <kyle@kyleam.com>2020-08-17 20:23:21 -0400
commit8f81b7705afbec27264b0fe45e585619af3f9fd6 (patch)
tree0b11b1d4a2118b612b9a885450c3a3352708f247
parente37abb4e89952a919722237b5786102cf956a84e (diff)
downloadpiem-8f81b7705afbec27264b0fe45e585619af3f9fd6.tar.gz
Extract logic from inject-thread-callback
An upcoming commit will use this same logic in another callback. Message-Id: <20200817013343.15615-4-kyle@kyleam.com>
-rw-r--r--piem.el18
1 files changed, 12 insertions, 6 deletions
diff --git a/piem.el b/piem.el
index 693c951..029b647 100644
--- a/piem.el
+++ b/piem.el
@@ -380,6 +380,16 @@ buffer."
(setq piem--has-gunzip (executable-find "gunzip")))
piem--has-gunzip)
+(defun piem--url-remove-header ()
+ (goto-char (1+ url-http-end-of-headers))
+ (delete-region (point-min) (point)))
+
+(defun piem--url-decompress ()
+ (unless (= 0 (call-process-region nil nil "gunzip" nil t))
+ (error "Decompressing t.mbox.gz failed"))
+ (delete-region (point) (point-max))
+ (goto-char (point-min)))
+
(defun piem--write-mbox-to-maildir ()
(let ((n-messages 0))
(while (and (not (eobp))
@@ -414,13 +424,9 @@ buffer."
(let ((error-status (plist-get status :error)))
(if error-status
(signal (car error-status) (cdr error-status))
- (goto-char (1+ url-http-end-of-headers))
- (delete-region (point-min) (point))
+ (piem--url-remove-header)
(unless message-only
- (unless (= 0 (call-process-region nil nil "gunzip" nil t))
- (error "Decompressing t.mbox.gz failed"))
- (delete-region (point) (point-max)))
- (goto-char (point-min))
+ (piem--url-decompress))
(let ((message-count (piem--write-mbox-to-maildir)))
(message "%d message(s) for %s moved to %s"
message-count mid piem-maildir-directory))