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 GFJgOuta5F51VgAAsNZ9tg (envelope-from ) for ; Sat, 13 Jun 2020 04:49:47 +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 YPtFNuta5F5HbQAA1q6Kng (envelope-from ) for ; Sat, 13 Jun 2020 04:49:47 +0000 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) (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 3DACD94060B for ; Sat, 13 Jun 2020 04:49:47 +0000 (UTC) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 562B36790E; Sat, 13 Jun 2020 00:49:45 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=UHeG6Gk5LLEZOrL6HWWOWFZ9q Aw=; b=lovFWA6LpivfEB8SrmrEpcRQLuLvNeWGgwTfWenyWFXZfaL1oOrGTKAGk 7+jxmBeuyWh2JTl3CE3E7rHrAr4bG2fSzOO1A2czaFkwILm6iWzSjZPCjbU2yvHc Ptg9elPZShm0ZFZv8k6Z7Q0dEXr7KhZkhlwiSM0AO6UgzN/y6w= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 4EDC76790D; Sat, 13 Jun 2020 00:49:45 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=Rhm2Lt3trg0SHBkujKbgm3HcVcL5zw3g+TotsPHKtOo=; b=nAL8wTXet0gDNyNLftP6vLnvoKQLMXgx6y2oVvoDdhQArRDL5pnqJOwtxE06jCB/QN24emp/yBUrw0xPUaHUpp8BK0c6tZMD6GeutAtoix3/AjvgD8WL8kpjlo0r3C7EKjwI6TKvRPmiA7be7Fqimc5H2OT/SRBnEVUO7XFREkg= 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-smtp2.pobox.com (Postfix) with ESMTPSA id 475B86790C; Sat, 13 Jun 2020 00:49:44 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Cc: Kyle Meyer Subject: [PATCH v2] Support adding Message-Id to attached patches Date: Sat, 13 Jun 2020 00:49:33 -0400 Message-Id: <20200613044933.4046-1-kyle@kyleam.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <87wo4bps58.fsf@kyleam.com> References: <87wo4bps58.fsf@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 4CE15CFA-AD31-11EA-A8C4-D1361DBA3BAF-24757444!pb-smtp2.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=lovFWA6L; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=nAL8wTXe; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 64.147.108.71 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: 2.50 X-TUID: QAthXmd1K5l9 With an inline patch that has a Message-Id, this information can be linked up to the patch when applied (e.g., with git-am's --message-id flag or using a post-applypatch hook [1]). Unfortunately, this method fails for projects where it is common to attach patches, as there is no Message-Id within the patch. Teach piem-am-ready-mbox how to insert the Message-Id that piem-mid reports, which should always correspond to the message that contains the patch attachments. [1] Here's an example that used to keep the commit->Message-Id mapping in git.git: https://lore.kernel.org/git/xmqq7e5ag4g5.fsf@gitster-ct.c.googlers.co= m/ --- piem.el | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/piem.el b/piem.el index a757092..6e13cc9 100644 --- a/piem.el +++ b/piem.el @@ -101,6 +101,14 @@ (defcustom piem-am-ready-mbox-functions nil arguments and inserts the mbox's contents in the current buffer." :type 'hook) =20 +(defcustom piem-add-message-id-header nil + "Whether to add Message-Id header to non-mail patches. +If this value is non-nil and a patch returned by a function in +`piem-am-ready-mbox-functions' looks like a patch that was +attached rather than sent inline, add a Message-Id header with +the return value of `piem-mid'." + :type 'boolean) + (defcustom piem-git-executable (or (and (boundp 'magit-git-executable) magit-git-executable) "git") @@ -294,16 +302,49 @@ (defun piem-mid () "Return the current buffer's message ID." (run-hook-with-args-until-success 'piem-get-mid-functions)) =20 +(defun piem--insert-message-id-header (mid) + ;; Be strict about case because this is coming from + ;; git-format-patch. + (let ((case-fold-search nil)) + (while (re-search-forward + (rx line-start + "From " (>=3D 40 hex-digit) " Mon Sep 17 00:00:00 2001" + line-end) + nil t) + (catch 'has-message-id + (let ((header-count 0)) + (while (and (=3D (forward-line) 0) + (not (looking-at-p + (rx line-start (zero-or-one space) line-end)= ))) + (cond + ((looking-at-p + (rx line-start + "Message-Id: <" (one-or-more not-newline) ">" + line-end)) + (throw 'has-message-id nil)) + ((looking-at-p + (rx line-start (or "From" "Date" "Subject") ": " + not-newline)) + (cl-incf header-count)))) + (when (=3D header-count 3) + ;; Found all the expected headers before hitting a + ;; blank line. Assume we're in a header. + (insert (format "Message-Id: <%s>\n" mid)))))))) + (defun piem-am-ready-mbox () "Return buffer containing an am-ready mbox. Callers are responsible for killing the buffer." (when-let ((fn (run-hook-with-args-until-success 'piem-am-ready-mbox-functions))) (let ((buffer (generate-new-buffer " *piem am-ready mbox*")) + (mid (and piem-add-message-id-header (piem-mid))) has-content) (with-current-buffer buffer (funcall fn) - (setq has-content (< 1 (point-max)))) + (setq has-content (< 1 (point-max))) + (when (and has-content mid) + (goto-char (point-min)) + (piem--insert-message-id-header mid))) (if has-content buffer (kill-buffer buffer) --=20 2.26.2