From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id gL53NYbeOV+ODwAAsNZ9tg (envelope-from ) for ; Mon, 17 Aug 2020 01:33:58 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id KDY5MYbeOV9EFgAA1q6Kng (envelope-from ) for ; Mon, 17 Aug 2020 01:33:58 +0000 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8A1169403C5 for ; Mon, 17 Aug 2020 01:33:58 +0000 (UTC) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id B436D683E3; Sun, 16 Aug 2020 21:33:57 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=TTdz0pWgGKAVg4V83PnY8MbQ5 Nk=; b=p976DmwSZLf2w9e6lnFQbuLz6pmXcxuIMQEe0UOF8h4BElLudYegw+l4p JfpTfbLqRh9vApuWQX72nyI3BvEB+HyPhKVeGVvcCPmpZZAJUHvDJB20SftlYHMe B+6q/Yxam/7SXKj0IYCFWwEtj2lMmzBBFHIE+9xUryZe+zcxbs= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id AA4EE683E0; Sun, 16 Aug 2020 21:33:57 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=ml+UewfiwyGaHkGsRV8MyL/4gG3Zn8ROAQpgOYKPxK0=; b=SGznQrNaKmy2mz0gPIf54dIV9fozuWAmah3cMfkRdOs5MO1z9+VL83GdKo6SNM1SS4BsBGokuSj4BSkhi19hQPa6MtucJQt1BXf+DKslnJCvo+SofxLqarCP2bB6rZoCsUyjOpnVyzcU6LJ2TWZgW91iSwKbgBgkIAqKcwaxpuo= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 2B38B683DF; Sun, 16 Aug 2020 21:33:57 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 5/5] b4: Try to download thread from piem-inboxes URL Date: Sun, 16 Aug 2020 21:33:43 -0400 Message-Id: <20200817013343.15615-6-kyle@kyleam.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817013343.15615-1-kyle@kyleam.com> References: <20200817013343.15615-1-kyle@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: B7E82CB0-E029-11EA-8B48-01D9BED8090B-24757444!pb-smtp1.pobox.com Content-Transfer-Encoding: quoted-printable X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=p976DmwS; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=SGznQrNa; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 64.147.108.70 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: 2.50 X-TUID: uPzQmxgslzcC If a call to piem-b4-am-from-mid fails to generate the thread for a message ID via piem-mid-to-thread-functions, b4 is called without a local mbox. In this case, b4 tries to download the thread from the URL specified by b4.midmask in the caller's Git configuration. That works, but it's inconvenient because the user needs to configure the URL in two places. If the current buffer is associated with an inbox in piem-inboxes, try to download the thread from its :url before falling back to b4's midmask. --- piem-b4.el | 19 +++++++++++++++---- piem.el | 15 +++++++++++++++ 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 @@ (defcustom piem-b4-b4-executable "b4" =0C ;;;; Internals =20 -;; 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 @@ (defun piem-b4--get-am-files (mid coderepo args) (funcall fn) (unless (=3D (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 94fa1ad..0fd1edc 100644 --- a/piem.el +++ b/piem.el @@ -382,6 +382,21 @@ (defun piem--url-decompress () (delete-region (point) (point-max)) (goto-char (point-min))) =20 +(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)) --=20 2.28.0