From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id SOkfNmddBmDWYwAAsNZ9tg (envelope-from ) for ; Tue, 19 Jan 2021 04:17:43 +0000 Received: from out1.migadu.com ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id EOjzImZdBmDBPwAAbx9fmQ (envelope-from ) for ; Tue, 19 Jan 2021 04:17:42 +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=1611029862; 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: in-reply-to:in-reply-to:references:references; bh=xYR2nnewnEW5kaQAcJnzp6THkVA6umDI6rFoMzKEFow=; b=BSo7qR1zuTSCMx+5jujh+my255DR5T+Cbh2SZGPZJbz54K2+QhtO28Yi1ZSKxO3tlYwPGc bG1LW4+XTWkD+O2BPTkVo93JUvQ5aBeegOYYtcdZ070HDtgspeJ59bqf3MqCq6J/yIPQfk xmf1xJcZ/YoN87XuZ6PAzG78oKecvVNq5qUFIjCWMKlXAruoNEvKS6N98uD+zZGM/h6kKu Fk9qwe/jq9HIkquJWfJcsza4a0+dawq4//eK3eDs14JT8vl+AAHvjDfWjfU9/wsmmD6hew Aqq7Zgu8MfAm4L/J9CC3Wo6Ok4VVXZFk0HAh5o4pPZFx/o73AfEwC6pHCzlt9g== From: Kyle Meyer To: Xinglu Chen Cc: piem@inbox.kyleam.com Subject: Re: [RFC PATCH] gnus: Add piem-gnus-mid-to-thread In-Reply-To: References: Date: Mon, 18 Jan 2021 23:17:40 -0500 Message-ID: <874kjdlfvf.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com X-TUID: 49XrNhcz4rFs Xinglu Chen writes: > Inserts a string of the whole thread in mbox format. Great, thanks for looking into this. > --- > The function works as expected when running > 'M-: (funcall (piem-gnus-mid-thread t))', but when running > piem-b4-am-from-mid interactively, it just inserts an empty string. > > Any ideas of why this happens? Sorry, my elisp skills are not that great. Yes, I think you just need to move the lambda deeper so that the messages are collected outside of the returned function. > diff --git a/piem-gnus.el b/piem-gnus.el > index 5f10be8..f91f91c 100644 > --- a/piem-gnus.el > +++ b/piem-gnus.el > @@ -58,6 +58,30 @@ > ;; 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) Hmm, yeah, I don't think we can convince Gnus to do much useful with the message ID here. However, perhaps there should at least be a check that the given message ID matches the one for the article at point before returning a function (i.e. claiming piem-gnus-mid-to-thread can generate a thread for the given MID). Also, I think this would need to be guarded by (derived-mode-p 'gnus-summary-mode) or perhaps (derived-mode-p 'gnus-article-mode 'gnus-summary-mode) to make sure we don't start doing this collection in buffers where it won't work. > + (lambda () This is the lambda I was referring to in the beginning of the message. It should be moved to deeper so that it contains only (insert ...). > + (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 > + ;; Just show raw message > + (gnus-have-all-headers t) > + gnus-article-prepare-hook > + gnus-article-decode-hook > + gnus-display-mime-function > + gnus-break-pages) Is the above set of variables (or this approach in general) based off of an example from the Gnus source code? If so, I should probably read through it to orient myself. I am mostly clueless when it comes to writing Gnus-related elisp and pretty much stumble around its source code looking for something that seems close to what I want. > + (mapc (lambda (article) > + (gnus-summary-display-article article) > + (push (format "From mboxrd@z Thu Jan 1 00:00:00 1970\n%s\n" > + (with-current-buffer gnus-article-buffer > + (buffer-substring-no-properties > + (point-min) > + (point-max)))) > + message)) > + articles) For mboxrd, I suppose there needs to be some From-munging. > + (insert (apply #'concat (nreverse message)))))))