]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new defvoo nnimap-keepalive-intervals to Gnus nnimap servers
authorEric Abrahamsen <eric@ericabrahamsen.net>
Mon, 3 May 2021 16:14:24 +0000 (09:14 -0700)
committerEric Abrahamsen <eric@ericabrahamsen.net>
Tue, 4 May 2021 23:34:29 +0000 (16:34 -0700)
* lisp/gnus/nnimap.el (nnimap-keepalive-intervals): New per-server
config for customizing when keepalive commands are sent.
(nnimap-keepalive, nnimap-open-connection-1): Consult in these
places.  Additionally, use nnimap-streaming -> t when sending the
keepalive NOOP, so we don't wait for the response.
* doc/misc/gnus.texi (Customizing the IMAP Connection): Document.

doc/misc/gnus.texi
lisp/gnus/nnimap.el

index 869bb272664dadbbfee17157dc8a8cbf39b3394e..a31411ef8e89ce67ac603e015a9c90945991964e 100644 (file)
@@ -14515,6 +14515,17 @@ names.  If your IMAP mailboxes are called something like @samp{INBOX}
 and @samp{INBOX.Lists.emacs}, but you'd like the nnimap group names to
 be @samp{INBOX} and @samp{Lists.emacs}, you should enable this option.
 
+@item nnimap-keepalive-intervals
+By default, nnimap will send occasional @samp{NOOP} (keepalive)
+commands to the server, to keep the connection alive.  This option
+governs how often that happens.  It is a cons of two integers,
+representing seconds: first how often to run the keepalive check, and
+the second how many seconds of user inactivity are required to
+actually send the command.  The default, @code{(900 . 300)}, means run
+the check every fifteen minutes and, if the user has been inactive for
+five minutes, send the keepalive command.  Set to @code{nil} to
+disable keepalive commands altogether.
+
 @end table
 
 
index 8990b2bebeb95b7eebe378573bb9f7d47d9283e8..570be49094fcb0365635c2d6eb618ca739bdfde8 100644 (file)
@@ -136,6 +136,16 @@ will fetch all parts that have types that match that string.  A
 likely value would be \"text/\" to automatically fetch all
 textual parts.")
 
+(defvoo nnimap-keepalive-intervals (cons (* 60 15)
+                                         (* 60 5))
+  "Configuration for the nnimap keepalive timer.
+The value is a cons of two integers (each representing a number
+of seconds): the first is how often to run the keepalive
+function, the second is the seconds of inactivity required to
+send the actual keepalive command.
+
+Set to nil to disable keepalive commands altogether.")
+
 (defgroup nnimap nil
   "IMAP for Gnus."
   :group 'gnus)
@@ -405,15 +415,16 @@ during splitting, which may be slow."
       nil)))
 
 (defun nnimap-keepalive ()
-  (let ((now (current-time)))
+  (let ((now (current-time))
+        ;; Set this so we don't wait for a response.
+        (nnimap-streaming t))
     (dolist (buffer nnimap-process-buffers)
       (when (buffer-live-p buffer)
        (with-current-buffer buffer
          (when (and nnimap-object
                     (nnimap-last-command-time nnimap-object)
                     (time-less-p
-                     ;; More than five minutes since the last command.
-                     (* 5 60)
+                     (cdr nnimap-keepalive-intervals)
                      (time-subtract
                       now
                       (nnimap-last-command-time nnimap-object))))
@@ -448,9 +459,12 @@ during splitting, which may be slow."
     port))
 
 (defun nnimap-open-connection-1 (buffer)
-  (unless nnimap-keepalive-timer
-    (setq nnimap-keepalive-timer (run-at-time (* 60 15) (* 60 15)
-                                             #'nnimap-keepalive)))
+  (unless (or nnimap-keepalive-timer
+              (null nnimap-keepalive-intervals))
+    (setq nnimap-keepalive-timer (run-at-time
+                                  (car nnimap-keepalive-intervals)
+                                  (car nnimap-keepalive-intervals)
+                                 #'nnimap-keepalive)))
   (with-current-buffer (nnimap-make-process-buffer buffer)
     (let* ((coding-system-for-read 'binary)
           (coding-system-for-write 'binary)