Stefan Kangas <stefankangas@HIDDEN>
to control <at> debbugs.gnu.org.
Full text available.Received: (at 76783) by debbugs.gnu.org; 7 Mar 2025 16:40:02 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 07 11:40:01 2025 Received: from localhost ([127.0.0.1]:49761 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tqajx-0006Lw-9B for submit <at> debbugs.gnu.org; Fri, 07 Mar 2025 11:40:01 -0500 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]:52309) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>) id 1tqajv-0006Lj-CY for 76783 <at> debbugs.gnu.org; Fri, 07 Mar 2025 11:39:59 -0500 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-abfe7b5fbe8so274844466b.0 for <76783 <at> debbugs.gnu.org>; Fri, 07 Mar 2025 08:39:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741365593; x=1741970393; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=zMFEc55ZhZAz1uMqawtLKqmsmi5/GMiQ5BVJPue6XOM=; b=YUnIylo9s7woBh6fzvqrGcL05ho3o9LIF4CYM2nthDpqqgJZlT2NFNF2T09b3vYK1q i1SRlQmBH/HhdHZ7ieSe0bcR443z0mevscOOqj8dyeGc0R11asnAsHIA57E11mulWC03 06XYkf17p7T3hPYD0ESHnXTVOqM+uIVdwJ7kat1XmtPhJa/WRRaOZHQ5Pg/eTU6oMU75 O60U9rOrfrOLnGjkE69MnNgm16R7oWnUdme0Oo2M3ZLgnbPBd4NIUAhKKpNQAPs2tnak 4z5OWzFGLApzMOmdU/4jBvFxlSb6ye1AN+FGIwvAi69gdSY6QfSgF/TVt8p0zIsi3gYQ SXZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741365593; x=1741970393; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zMFEc55ZhZAz1uMqawtLKqmsmi5/GMiQ5BVJPue6XOM=; b=ESlYKkfxnzzCp/O8Fl9/518XL0kjOAeH1AuY3mCx1rBbh4AhtjdAvxMYJ63FQ48gb8 ADCZ+whQ8Bq/ZFJsYmG+Yn5YJ5eCPaL+uLLUNk1T6eJ9RU74z1uL8NL16j4UBW050MTp Ybcn8CIGZIjgavzQ2Yh7HMjqRhibVl6wmxwn3b1EfoiGVfhgwK8DCXQPHjYInV1Y1s+x 5jytK2HERhJtV7npZdyuIE2g12FPD3spv3JhYyoD1Oyx2Ym+HvWX65eZf7UcqpB6d0nY BG8Tca9ySU8pGoa0N8zap9P9KqqaowbTIHWBtEnFith0Cvw8XjN7NNVWnen2UVa8CtP4 FIwA== X-Forwarded-Encrypted: i=1; AJvYcCW0jPeLA5+ft87fFSclncZCn72FRMIgxKveC7JhqHW+mVtKC+9hIgrAlBTrSjex1qtWpuO8wg==@debbugs.gnu.org X-Gm-Message-State: AOJu0Yx7jU6NxGx+FIRF2ikHmwLwH5pdOZ+B/qwNIjSYvFHed+sVpuk7 /hEX47UsGwOOmUzMLL4tdtposzSqBb7DHz+kj/7iE9YMWECMtVx5UR8WbSJA53vgN4kyyY23TUO 2MBIbZ4uyLRADo/cx8IPOGxcKFgs= X-Gm-Gg: ASbGnct4HJxmnM6pLjBq+HxXN1/pcEbhXjdTLMCvCVeRwbNWErB1ZdGW3R0bv4Lefe4 JJGnAiYPLYGkJHpJYrKbIaMx5nxcEbQWK2KM8z4ze8SLtcf5CZmOgGcPCyoSTgWNt8hg3i7q6o1 MtIwcZFDxixnXEB0ujamFrV7jIlw== X-Google-Smtp-Source: AGHT+IFdRASL5jaPbav7U7D2AKZw6t9kq7O/AMVGBdoTD6K3DMkQmu9sIF98C6bhBaGp20Py/MIbyRiJuqSIBdSHB6E= X-Received: by 2002:a05:6402:2353:b0:5e5:c0e7:f428 with SMTP id 4fb4d7f45d1cf-5e5e210296emr10163802a12.0.1741365592961; Fri, 07 Mar 2025 08:39:52 -0800 (PST) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Fri, 7 Mar 2025 16:39:51 +0000 From: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <87plitmaz2.fsf@HIDDEN> References: <87a59y3zr6.fsf@HIDDEN> <87plitmaz2.fsf@HIDDEN> MIME-Version: 1.0 Date: Fri, 7 Mar 2025 16:39:51 +0000 X-Gm-Features: AQ5f1JoUl7EIrMYJBPSJpQR-fL6lAWY7LZKGk16zBUNEGbxGRCRDpF_3326WvP8 Message-ID: <CADwFkm=KQ=+oniOErb0RcTBYAqEpsv=DRwAAZoYon0dkdC201g@HIDDEN> Subject: Re: bug#76783: [PATCH] Keep IMAP connection opened with nnml To: Manuel Giraud <manuel@HIDDEN>, 76783 <at> debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 76783 Cc: Andrew Cohen <acohen@HIDDEN>, Eric Abrahamsen <eric@HIDDEN>, Lars Magne Ingebrigtsen <larsi@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) Manuel Giraud <manuel@HIDDEN> writes: > From 426b31e1fc6b5a098445779084424c07bbc8282d Mon Sep 17 00:00:00 2001 > From: Manuel Giraud <manuel@HIDDEN> > Date: Thu, 6 Mar 2025 15:40:48 +0100 > Subject: [PATCH] Keep IMAP connection opened with nnml > > * lisp/gnus/mail-source.el (mail-source-fetch-imap): Keep > connection opened when user provide a buffer name. > * lisp/gnus/nnml.el (nnml-connected-buffer-list): New variable > of connected buffers. > (nnml-request-close): New function that closes connected buffers > when quitting Gnus. > * doc/misc/gnus.texi (Mail Source Specifiers): Document the > feature. Andrew, Eric, could you please take a look at this patch?
bug-gnu-emacs@HIDDEN:bug#76783; Package emacs.
Full text available.
Received: (at 76783) by debbugs.gnu.org; 7 Mar 2025 09:44:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 07 04:44:29 2025
Received: from localhost ([127.0.0.1]:47037 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1tqUFp-0002bs-1o
for submit <at> debbugs.gnu.org; Fri, 07 Mar 2025 04:44:29 -0500
Received: from ledu-giraud.fr ([51.159.28.247]:2660)
by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.84_2) (envelope-from <manuel@HIDDEN>)
id 1tqUFm-0002bi-CY
for 76783 <at> debbugs.gnu.org; Fri, 07 Mar 2025 04:44:27 -0500
DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=WA/7YTxL
Zfpw1FirEB9Y9oKva45z5LqjyoTJ3YWjMf4=;
h=date:references:in-reply-to:
subject:cc:to:from; d=ledu-giraud.fr; b=qnZxxNz4yFyup71Tnya2tq2yQHpJ9b
WxfUa/RYeTCBUlt1q18+wTFCr+6WifTIR+L5x+VgxtONPslLfSN6ZMDQ==
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=WA/7YTxLZfpw1Fir
EB9Y9oKva45z5LqjyoTJ3YWjMf4=;
h=date:references:in-reply-to:subject:
cc:to:from; d=ledu-giraud.fr; b=C2zsPlQLyL+w6rNj0XnB8wi9SCZH/iAvoAQexF
kLxWPk0oFgDNLtNAEd/jYFSgKmIUPlbDLB8hRHUDEuFk4nUHhmmKKBaWqdGftX8A5kqi1s
Unntt+gQi8xq4muV3ApiU6JJ8MCSdr2yFmEJhKOH+MwMsJxaIk5FuNmfp3tTQCCfLvUH5M
GEFsmJxKx5eb+GEiOgJmFMQLMaBmY4JOt89IqHuVTgR1Mf6f+p6gFqqqejFgdHq4tr9stP
WFkrTFKoQlgB+6M9V9UgULprl/POBB2gjb/c1j9zgC0lxBkZtemouM5TaKJppIURcuTuCp
rpun9ZVrB+I/Vm403HqShn0Q==
Received: from computer (2630.fr [82.65.148.221])
by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id b466fd96
(TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO);
Fri, 7 Mar 2025 10:44:19 +0100 (CET)
From: Manuel Giraud <manuel@HIDDEN>
To: 76783 <at> debbugs.gnu.org
Subject: Re: bug#76783: [PATCH] Keep IMAP connection opened with nnml
In-Reply-To: <87a59y3zr6.fsf@HIDDEN>
References: <87a59y3zr6.fsf@HIDDEN>
Date: Fri, 07 Mar 2025 10:44:17 +0100
Message-ID: <87plitmaz2.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76783
Cc: Lars Magne Ingebrigtsen <larsi@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)
--=-=-=
Content-Type: text/plain
Hi,
Please consider this new version instead in which I simplified
`nnml-request-close' a bit.
--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
filename=0001-Keep-IMAP-connection-opened-with-nnml.patch
From 426b31e1fc6b5a098445779084424c07bbc8282d Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@HIDDEN>
Date: Thu, 6 Mar 2025 15:40:48 +0100
Subject: [PATCH] Keep IMAP connection opened with nnml
* lisp/gnus/mail-source.el (mail-source-fetch-imap): Keep
connection opened when user provide a buffer name.
* lisp/gnus/nnml.el (nnml-connected-buffer-list): New variable
of connected buffers.
(nnml-request-close): New function that closes connected buffers
when quitting Gnus.
* doc/misc/gnus.texi (Mail Source Specifiers): Document the
feature.
---
doc/misc/gnus.texi | 8 ++++++++
lisp/gnus/mail-source.el | 28 ++++++++++++++++++++--------
lisp/gnus/nnml.el | 14 ++++++++++++++
3 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index a239a8a628b..9a003d0c3a6 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -15408,6 +15408,14 @@ Mail Source Specifiers
If non-@code{nil}, don't remove all articles marked as deleted in the
mailbox after finishing the fetch.
+@item :buffer
+The name of the buffer used to communicate with the @acronym{IMAP}
+server. By default, Gnus creates such a buffer on the fly and kills it
+after having retrieved some mails. By setting this option, the
+connection with the server is kept open for the entire Gnus session.
+Preferably, you would use a buffer name starting with the space
+character to avoid it being list in @code{list-buffers} for instance.
+
@end table
An example @acronym{IMAP} mail source:
diff --git a/lisp/gnus/mail-source.el b/lisp/gnus/mail-source.el
index 954dce92e84..f4685af0f72 100644
--- a/lisp/gnus/mail-source.el
+++ b/lisp/gnus/mail-source.el
@@ -349,6 +349,7 @@ mail-source-new-mail-available
(:mailbox "INBOX")
(:predicate "UNSEEN UNDELETED")
(:fetchflag "\\Deleted")
+ (:buffer)
(:prescript)
(:prescript-delay)
(:postscript)
@@ -1034,6 +1035,7 @@ mail-source-fetch-maildir
found)))
(autoload 'imap-open "imap")
+(autoload 'imap-opened "imap")
(autoload 'imap-authenticate "imap")
(autoload 'imap-mailbox-select "imap")
(autoload 'imap-mailbox-unselect "imap")
@@ -1046,6 +1048,7 @@ mail-source-fetch-maildir
(autoload 'imap-list-to-message-set "imap")
(autoload 'imap-range-to-message-set "imap")
(autoload 'nnheader-ms-strip-cr "nnheader")
+(autoload 'nnml-connected-buffer-list "nnml")
(defvar mail-source-imap-file-coding-system 'binary
"Coding system for the crashbox made by `mail-source-fetch-imap'.")
@@ -1063,14 +1066,21 @@ mail-source-fetch-imap
prescript-delay)
(let ((from (format "%s:%s:%s" server user port))
(found 0)
- (buf (generate-new-buffer " *imap source*"))
+ (buf (if buffer
+ (get-buffer-create buffer)
+ (generate-new-buffer " *imap source*")))
(imap-shell-program (or (list program) imap-shell-program)))
- (if (and (imap-open server port stream authentication buf)
- (imap-authenticate
- user (or (cdr (assoc from mail-source-password-cache))
- password)
- buf))
+ (if (or (and buffer (imap-opened buf))
+ (and (imap-open server port stream authentication buf)
+ (imap-authenticate
+ user (or (cdr (assoc from mail-source-password-cache))
+ password)
+ buf)))
(let ((mailbox-list (if (listp mailbox) mailbox (list mailbox))))
+ ;; Remember communication buffer if needed.
+ (when (and buffer
+ (not (member buf nnml-connected-buffer-list)))
+ (push buf nnml-connected-buffer-list))
(dolist (mailbox mailbox-list)
(when (imap-mailbox-select mailbox nil buf)
(let ((coding-system-for-write
@@ -1114,7 +1124,9 @@ mail-source-fetch-imap
(if dontexpunge
(imap-mailbox-unselect buf)
(imap-mailbox-close nil buf)))))
- (imap-close buf))
+ ;; If the user has provided a buffer name keep the
+ ;; connection opened.
+ (unless buffer (imap-close buf)))
(imap-close buf)
;; We nix out the password in case the error
;; was because of a wrong password being given.
@@ -1122,7 +1134,7 @@ mail-source-fetch-imap
(delq (assoc from mail-source-password-cache)
mail-source-password-cache))
(error "IMAP error: %s" (imap-error-text buf)))
- (kill-buffer buf)
+ (unless buffer (kill-buffer buf))
(mail-source-run-script
postscript
`((?p . ,password) (?t . ,mail-source-crash-box)
diff --git a/lisp/gnus/nnml.el b/lisp/gnus/nnml.el
index 4366391a66d..6db5031d181 100644
--- a/lisp/gnus/nnml.el
+++ b/lisp/gnus/nnml.el
@@ -541,6 +541,20 @@ nnml-set-status
(nnmail-replace-status name value))
t))))
+;;;###autoload
+(defvar nnml-connected-buffer-list nil)
+
+(deffoo nnml-request-close ()
+ (let (buf)
+ (while (setq buf (pop nnml-connected-buffer-list))
+ (when (buffer-live-p buf)
+ (imap-close buf)
+ ;; On the safe side: kill any leftover process.
+ (let ((proc (get-buffer-process buf)))
+ (when proc
+ (delete-process proc)))
+ (kill-buffer buf)))))
+
;;; Internal functions.
--
2.48.1
--=-=-=
Content-Type: text/plain
--
Manuel Giraud
--=-=-=--
bug-gnu-emacs@HIDDEN:bug#76783; Package emacs.
Full text available.
Received: (at submit) by debbugs.gnu.org; 6 Mar 2025 16:12:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Mar 06 11:12:10 2025
Received: from localhost ([127.0.0.1]:44903 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1tqDpS-0003Sm-1p
for submit <at> debbugs.gnu.org; Thu, 06 Mar 2025 11:12:10 -0500
Received: from lists.gnu.org ([2001:470:142::17]:38980)
by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.84_2) (envelope-from <manuel@HIDDEN>)
id 1tqDpO-0003Qf-JH
for submit <at> debbugs.gnu.org; Thu, 06 Mar 2025 11:12:07 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1) (envelope-from <manuel@HIDDEN>)
id 1tqDp5-00071u-Jb
for bug-gnu-emacs@HIDDEN; Thu, 06 Mar 2025 11:11:47 -0500
Received: from ledu-giraud.fr ([51.159.28.247])
by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
(Exim 4.90_1) (envelope-from <manuel@HIDDEN>)
id 1tqDp3-00018S-BS
for bug-gnu-emacs@HIDDEN; Thu, 06 Mar 2025 11:11:47 -0500
DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=f8/BDhTI
2SQpem0TNR5VVVaxpZF8FonyAwtaxNLSJ98=; h=date:subject:to:from;
d=ledu-giraud.fr;
b=WeNESyWAC7dK9lAXpH/CowbZV/EQVJ2VefWj0Qxu4SdoNSD+H0
zASm+r2AVAVAYvYnJ6/aQhWRW/Y+HIBYkiDw==
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=f8/BDhTI2SQpem0T
NR5VVVaxpZF8FonyAwtaxNLSJ98=; h=date:subject:to:from;
d=ledu-giraud.fr; b=fxZtZMFTV9RM0p9fc/L52wX4Bd4Ix1KLQpmj7q8cBNZ4O3QKzK
9jaHjqAZ/j/D6jAlAPXSzwEAGzwSiWgYpKlaGBGhEM6M/jsDhJlkTuSxKdZB+cZiopijlY
BHY7zwHF9+R5Y34UQoE9lag4+Sq2dXNtDx3ECyveAYBEupvKGphKPksOt8gH18ursExfsP
GrULM06nKJXn9eNrT/gV1R32iqWn/r/H+2YTDAl1V8VD1+96XRwDPjgqlCJYXydH6PVNL6
WKzZ4yfXXfyScTcCo4ubGm0GPCUu2SbtFCyhz/aWFhlNllXs5o+L0+5IXjkEVAnjDrb06J
Oz8iYsI4lNIw==
Received: from computer (<unknown> [10.1.1.1])
by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id d4e51acc
(TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <bug-gnu-emacs@HIDDEN>;
Thu, 6 Mar 2025 17:11:42 +0100 (CET)
From: Manuel Giraud <manuel@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] Keep IMAP connection opened with nnml
X-Debbugs-Cc: Lars Magne Ingebrigtsen <larsi@HIDDEN>
Date: Thu, 06 Mar 2025 17:11:41 +0100
Message-ID: <87a59y3zr6.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=51.159.28.247; envelope-from=manuel@HIDDEN;
helo=ledu-giraud.fr
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,
SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.1 (/)
--=-=-=
Content-Type: text/plain
Tags: patch
Hi,
Here is a patch that permits a Gnus/nnml user to define the name of the
buffer for IMAP communication. Like this, for instance:
(setq mail-sources '((imap :server "example.com"
:stream tls
:buffer " *imap example.com*")))
Doing so, said buffer will be kept connected for the entire Gnus
session. FWIW, I'm using it right now and it seems like a quite
effective way to speed up mail retrieving (even better with multiple
IMAP servers).
I have no use for this myself but I guess that this feature could also
be extended to POP servers.
In GNU Emacs 31.0.50 (build 22, x86_64-unknown-openbsd7.6, X toolkit) of
2025-03-06 built on computer
Repository revision: fe7a8c92be6269f8fc7933eb6c190178839d0f8a
Repository branch: mgi/mail-source-keep-connect
Windowing system distributor 'The X.Org Foundation', version 11.0.12101015
System Description: OpenBSD computer 7.6 GENERIC.MP#567 amd64
Configured using:
'configure CC=egcc CPPFLAGS=-I/usr/local/include
LDFLAGS=-L/usr/local/lib MAKEINFO=gmakeinfo --prefix=/home/manuel/emacs
--bindir=/home/manuel/bin --with-x-toolkit=lucid
--with-toolkit-scroll-bars=no --without-cairo
--without-compress-install'
--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
filename=0001-Keep-IMAP-connection-opened-with-nnml.patch
From 75f85630179d09ccc058c6771415c6bff59f618c Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@HIDDEN>
Date: Thu, 6 Mar 2025 15:40:48 +0100
Subject: [PATCH] Keep IMAP connection opened with nnml
* lisp/gnus/mail-source.el (mail-source-fetch-imap): Keep
connection opened when user provide a buffer name.
* lisp/gnus/nnml.el (nnml-connected-buffer-list): New variable
of connected buffers.
(nnml-request-close): New function that closes connected buffers
when quitting Gnus.
* doc/misc/gnus.texi (Mail Source Specifiers): Document the
feature.
---
doc/misc/gnus.texi | 8 ++++++++
lisp/gnus/mail-source.el | 28 ++++++++++++++++++++--------
lisp/gnus/nnml.el | 12 ++++++++++++
3 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index a239a8a628b..9a003d0c3a6 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -15408,6 +15408,14 @@ Mail Source Specifiers
If non-@code{nil}, don't remove all articles marked as deleted in the
mailbox after finishing the fetch.
+@item :buffer
+The name of the buffer used to communicate with the @acronym{IMAP}
+server. By default, Gnus creates such a buffer on the fly and kills it
+after having retrieved some mails. By setting this option, the
+connection with the server is kept open for the entire Gnus session.
+Preferably, you would use a buffer name starting with the space
+character to avoid it being list in @code{list-buffers} for instance.
+
@end table
An example @acronym{IMAP} mail source:
diff --git a/lisp/gnus/mail-source.el b/lisp/gnus/mail-source.el
index 954dce92e84..f4685af0f72 100644
--- a/lisp/gnus/mail-source.el
+++ b/lisp/gnus/mail-source.el
@@ -349,6 +349,7 @@ mail-source-new-mail-available
(:mailbox "INBOX")
(:predicate "UNSEEN UNDELETED")
(:fetchflag "\\Deleted")
+ (:buffer)
(:prescript)
(:prescript-delay)
(:postscript)
@@ -1034,6 +1035,7 @@ mail-source-fetch-maildir
found)))
(autoload 'imap-open "imap")
+(autoload 'imap-opened "imap")
(autoload 'imap-authenticate "imap")
(autoload 'imap-mailbox-select "imap")
(autoload 'imap-mailbox-unselect "imap")
@@ -1046,6 +1048,7 @@ mail-source-fetch-maildir
(autoload 'imap-list-to-message-set "imap")
(autoload 'imap-range-to-message-set "imap")
(autoload 'nnheader-ms-strip-cr "nnheader")
+(autoload 'nnml-connected-buffer-list "nnml")
(defvar mail-source-imap-file-coding-system 'binary
"Coding system for the crashbox made by `mail-source-fetch-imap'.")
@@ -1063,14 +1066,21 @@ mail-source-fetch-imap
prescript-delay)
(let ((from (format "%s:%s:%s" server user port))
(found 0)
- (buf (generate-new-buffer " *imap source*"))
+ (buf (if buffer
+ (get-buffer-create buffer)
+ (generate-new-buffer " *imap source*")))
(imap-shell-program (or (list program) imap-shell-program)))
- (if (and (imap-open server port stream authentication buf)
- (imap-authenticate
- user (or (cdr (assoc from mail-source-password-cache))
- password)
- buf))
+ (if (or (and buffer (imap-opened buf))
+ (and (imap-open server port stream authentication buf)
+ (imap-authenticate
+ user (or (cdr (assoc from mail-source-password-cache))
+ password)
+ buf)))
(let ((mailbox-list (if (listp mailbox) mailbox (list mailbox))))
+ ;; Remember communication buffer if needed.
+ (when (and buffer
+ (not (member buf nnml-connected-buffer-list)))
+ (push buf nnml-connected-buffer-list))
(dolist (mailbox mailbox-list)
(when (imap-mailbox-select mailbox nil buf)
(let ((coding-system-for-write
@@ -1114,7 +1124,9 @@ mail-source-fetch-imap
(if dontexpunge
(imap-mailbox-unselect buf)
(imap-mailbox-close nil buf)))))
- (imap-close buf))
+ ;; If the user has provided a buffer name keep the
+ ;; connection opened.
+ (unless buffer (imap-close buf)))
(imap-close buf)
;; We nix out the password in case the error
;; was because of a wrong password being given.
@@ -1122,7 +1134,7 @@ mail-source-fetch-imap
(delq (assoc from mail-source-password-cache)
mail-source-password-cache))
(error "IMAP error: %s" (imap-error-text buf)))
- (kill-buffer buf)
+ (unless buffer (kill-buffer buf))
(mail-source-run-script
postscript
`((?p . ,password) (?t . ,mail-source-crash-box)
diff --git a/lisp/gnus/nnml.el b/lisp/gnus/nnml.el
index 4366391a66d..0e4546cd7bb 100644
--- a/lisp/gnus/nnml.el
+++ b/lisp/gnus/nnml.el
@@ -541,6 +541,18 @@ nnml-set-status
(nnmail-replace-status name value))
t))))
+;;;###autoload
+(defvar nnml-connected-buffer-list nil)
+
+(deffoo nnml-request-close ()
+ (let (buf)
+ (while (setq buf (pop nnml-connected-buffer-list))
+ (when (buffer-live-p buf)
+ (with-current-buffer buf
+ (when (imap-opened)
+ (imap-close)))
+ (kill-buffer buf)))))
+
;;; Internal functions.
--
2.48.1
--=-=-=
Content-Type: text/plain
--
Manuel Giraud
--=-=-=--
Manuel Giraud <manuel@HIDDEN>:larsi@HIDDEN, bug-gnu-emacs@HIDDEN.
Full text available.larsi@HIDDEN, bug-gnu-emacs@HIDDEN:bug#76783; Package emacs.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.