From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id MJ1YDNzqCGDBXQAAsNZ9tg (envelope-from ) for ; Thu, 21 Jan 2021 02:45:48 +0000 Received: from out2.migadu.com ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id kFUeM9rqCGDPUQAA1q6Kng (envelope-from ) for ; Thu, 21 Jan 2021 02:45:46 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1611197146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ueXagLhjbQoreRs0vDElrsgOD0saZyT2F9TlwCVxiUE=; b=NZwLxM2PQm4TnFY9ZffcSCLPAlIYPOTZ0IOmJWG/5CIKKPIrtOQniEGuaVAuMZ3mhxd1bD 4HFHxVrA50DmdzdqmlwfEgWMpkDPNB0L7g1B64FFHrViKYPTb2EliFIykp7VYVjmOi4C4G bm/znEDbsasCczmSYXNTi7V27JYq14WF6j86PtJusPdo5Om+F2SKO6IDI2KlQ//q1uGlpw RW4E0yVg1m3FaJKERNejC1cmR/DVomOKT5Medjh6uPkzKbVNx22imeg48klQXQvsO6vJMY AF5FoF0J5l9vyFYnaQK2K9JPdUKDEzmTYoyY2HuLB4URe1q1Jj/DXWuKnz4u1g== From: Kyle Meyer To: Xinglu Chen Cc: piem@inbox.kyleam.com Subject: Re: [RFC PATCH v2] gnus: Add piem-gnus-mid-to-thread In-Reply-To: <796fb84d852f2a5adea1502db144dae1bdc4fe0c.1611132172.git.public@yoctocell.xyz> References: <796fb84d852f2a5adea1502db144dae1bdc4fe0c.1611132172.git.public@yoctocell.xyz> Date: Wed, 20 Jan 2021 21:45:39 -0500 Message-ID: <87im7rt3cc.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com X-TUID: vbAJiTUZn005 Xinglu Chen writes: > Inserts a string of the whole thread in mbox format. > --- > Changes from v1 > > - Add safety check for major mode and message id before trying to generate > the mbox file > - Escape "^From" in the body to prevent ambiguity I played around with this a bit, and all series seemed to get applied without issues. I think interface-wise it'd be a bit nicer if we could do this work behind the scenes without the user seeing any changes in the layout/rendering of Gnus buffers, but I'm not sure that's really feasible. > diff --git a/piem-gnus.el b/piem-gnus.el > index 5f10be8..828ce1f 100644 > --- a/piem-gnus.el > +++ b/piem-gnus.el > @@ -55,8 +55,38 @@ > (match-string 1 mid) > mid))))) >=20=20 > -;; If there is an easy way to generate an mbox for a thread in Gnus, a > -;; function for `piem-mid-to-thread-functions' should be defined. > +(defun piem-gnus-mid-to-thread (mid) > + (when (and (derived-mode-p 'gnus-summary-mode) > + (string-equal (substring > + (mail-header-id (gnus-summary-article-header)) > + 1 -1) ; Remove "<" and ">" > + mid)) Great, thanks for adding those guards. > + (save-excursion > + ;; Cursor has to be at the root of the thread > + (gnus-summary-refer-parent-article most-positive-fixnum) > + (let ((articles (gnus-summary-articles-in-thread)) > + message I'm going to s/message/&s/ on apply. It's a cosmetic nit, but I'll trip over this whenever I need to revisit this code if I don't make that change. > + ;; Just show raw message > + (gnus-have-all-headers t) > + gnus-article-prepare-hook > + gnus-article-decode-hook > + gnus-display-mime-function > + gnus-break-pages) When compiling, this gives the following warnings: In toplevel form: piem-gnus.el:58:1:Warning: Unused lexical variable =E2=80=98gnus-display-mime-function=E2=80=99 piem-gnus.el:58:1:Warning: Unused lexical variable =E2=80=98gnus-article-= decode-hook=E2=80=99 piem-gnus.el:58:1:Warning: Unused lexical variable =E2=80=98gnus-article-= prepare-hook=E2=80=99 I'll silence those by adding (require 'gnus-art) > + (mapc (lambda (article) > + (gnus-summary-display-article article) > + (push (format > + "From mboxrd@z Thu Jan 1 00:00:00 1970\n%s\n" > + (replace-regexp-in-string ; From-munge > + "^From " > + "^>From " There's a spurious "^" making it into the replacement. Also this doesn't handle mboxrd's ">From " escaping. I'll squash the following in. diff --git a/piem-gnus.el b/piem-gnus.el index 4293049..d81c086 100644 --- a/piem-gnus.el +++ b/piem-gnus.el @@ -77,8 +77,8 @@ (defun piem-gnus-mid-to-thread (mid) (push (format "From mboxrd@z Thu Jan 1 00:00:00 1970\n%s\n" (replace-regexp-in-string ; From-munge - "^From " - "^>From " + "^>*From " + ">\\&" (with-current-buffer gnus-article-buffer (buffer-substring-no-properties (point-min) > + (with-current-buffer gnus-article-buffer > + (buffer-substring-no-properties > + (point-min) > + (point-max))))) > + message)) > + articles) > + (lambda () > + (insert (apply #'concat (nreverse message)))))))) Mostly just thinking aloud: this could be rewritten without concat by using (dolist ... (insert ...)), and it might eventually be worth considering building the mbox up in a temporary buffer rather than as a list of strings. But I think it's fine as is. Also, I've replaced the tabs with spaces. Sorry for not having set indent-tabs-mode for the project. I've now done that in 9d60b3e. Pushed (c9228b9). Thank you!