From 8f81b7705afbec27264b0fe45e585619af3f9fd6 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 16 Aug 2020 21:33:41 -0400 Subject: 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> --- piem.el | 18 ++++++++++++------ 1 file 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)) -- cgit v1.2.3