Subject: Re: bug#54154: Emacs commit ae963e80a79f5a9184daabfc8197f211a39b136d (sieve-manage)

From: "Herbert J. Skuhra" <[email-masked]>
Date: Thu, 19 Jan 2023 00:22:44 +0100

On Wed, Jan 18, 2023 at 09:17:59PM +0200, Eli Zaretskii wrote:
> > Cc: larsi <[email-masked]>, [email-masked]
> > Date: Wed, 18 Jan 2023 19:28:40 +0100
> > From: "Herbert J. Skuhra" <[email-masked]>
> > 
> > On Wed, Jan 18, 2023 at 10:09:33AM +0100, Kai Tetzlaff wrote:
> > > Hello Herbert,
> > > 
> > > it seems that I'm responsible for this issue. Unfortunately, I cannot
> > > reproduce it with my imap/sieve server setup. However, if you're willing
> > > to provide some additional info, we should hopefully be able to find the
> > > bug.
> > 
> > Hello, 
> > 
> > this is strange because I can reproduce it easily on different systems:
> > 
> > - master on FreeBSD 13.1-STABLE 
> > - emacs-29 and master on macOS 12.6.2
> > - master on WLS2/Windows11 (Ubuntu)
> 
> Is this problem still relevant?  I thought that Lars closed the bug
> report back in September?
> 
> > > Could you re-run the steps above with the following additional steps
> > > before 3.:
> > > 
> > > 2a) M-x find-library sieve-manage
> > > 2b) M-x eval-buffer
> > > 2c) M-x find-library sieve
> > > 2d) M-x eval-buffer
> > > 2e) M-x toggle-debug-on-error
> > > 
> > > to get a full backtrace and send it to me?
> > 
> > Backtrace attached.
> 
> Thanks.  The error is here:
> 
> (defun sieve-manage--append-to-log (&rest args)
>   "Append ARGS to sieve-manage log buffer.
> 
> ARGS can be a string or a list of strings.
> The buffer to use for logging is specifified via
> `sieve-manage-log'. If it is nil, logging is disabled."
>   (when sieve-manage-log
>     (with-current-buffer (or (get-buffer sieve-manage-log)
>                              (with-current-buffer  <<<<<<<<<<<<<<<<<<<<<<
>                                  (get-buffer-create sieve-manage-log)
>                                (set-buffer-multibyte nil)
>                                (buffer-disable-undo)))
> 
> And I admit that I don't understand this code.  What is it trying to
> do?  Shouldn't it be just
> 
>   (when sieve-manage-log
>     (with-current-buffer (get-buffer-create sieve-manage-log)
>       (set-buffer-multibyte nil)
>       (buffer-disable-undo)))
> 
> Kai, am I missing something?
> 
> Herbert, if you make the change above, does the problem go away?

Yes, this change resolves the issue:

diff --git a/lisp/net/sieve-manage.el b/lisp/net/sieve-manage.el
index 5bee4f4c4a..636c7cbc5b 100644
--- a/lisp/net/sieve-manage.el
+++ b/lisp/net/sieve-manage.el
@@ -174,11 +174,9 @@ sieve-manage--append-to-log
 The buffer to use for logging is specifified via
 `sieve-manage-log'. If it is nil, logging is disabled."
   (when sieve-manage-log
-    (with-current-buffer (or (get-buffer sieve-manage-log)
-                             (with-current-buffer
-                                 (get-buffer-create sieve-manage-log)
+    (with-current-buffer (get-buffer-create sieve-manage-log)
                                (set-buffer-multibyte nil)
-                               (buffer-disable-undo)))
+                               (buffer-disable-undo)
       (goto-char (point-max))
       (apply #'insert args))))

Thanks.

-- 
Herbert