Subject: Re: bug#36266: 26.1; Problems with sieve-manage

From: Eric Abrahamsen <[email-masked]>
Date: Thu, 25 Jul 2019 11:28:08 -0700

[email-masked] writes:

> I asked for help with these on the `help-gnu-emacs` mailing list and
> Eric suggested that I also report them as bugs so that they don't get
> lost.  Here is the email thread:
>
> https://lists.gnu.org/archive/html/help-gnu-emacs/2019-06/msg00185.html
>
> g.
>
> ---
>
> I've been trying to use sieve-manage in GNU Emacs 26.1 on a Mac with
> dovecot-pigeonhole-0.5.6 on a FreeBSD 12 system.
>
> I've run into a few problems:
>
> 1. I can start sieve-manage, use the `f` key with the `<new script>`
>    line highlighted, edit a script, and use `C-c C-l` to upload it to
>    the server.
>
>    The problem is that the script, on the server, is named `<new
>    script>.sieve`, which is awkward.
>
>    But worse, if/when I restart sieve-manage it offers me two choices,
>    one labeled `<new script>` (which is the button to create a new
>    script) and one which is the existing script which was saved under
>    that same name.
>
>    I've tried renaming the buffer, but the code has a preference for
>    `sieve-buffer-script-name`.
>
>    Is there some way to rename the buffer?

I think it's a little weird that `sieve-new-script' (which defaults to
"<new script>" is a configurable option at all. IMO, there are two
separate concerns: some placeholder text for the button that's used to
create a new script (there's no reason to make this configurable), and
the default name for a newly-created script (the new name should be
prompted for on a script-by-script basis, and there's no reason to have
a default at all).

I've attached a simple diff which checks if your new script has the same
name as `sieve-new-script' and prompts you to rename it. But I think a
more sensible solution would be to remove the `sieve-new-script' option
altogether. Then hard-code the "new script" button text, and always
prompt for a name for a new script.

> 2. If I create a script directly on the server (e.g. `ape.sieve`) then
>    start sieve-manage, I'm offered the chance to edit it.  If I move
>    the highlighting to `ape.sieve` then use `f` to edit it, emacs
>    becomes unresponsive.  I can break out of it with C-g.
>
>    But, I've had it work once or twice.  I haven't figure out how to
>    repeat it.
>
>    If I look in `*sieve-manage-log*`, I can see that emacs has sent
>    `GETSCRIPT "ape"` and I can see the text of the script in the
>    response.
>
>    I'm not sure what it's waiting for.

I believe this is something to do with an infloop in
`accept-process-output' that was previously preventing me from logging
in to my sieve servers at all. This is just a guess, because it matches
pretty closely behavior that I saw discussed in another bug report here.
But this has since been cleared up for me in Emacs master, so maybe if
you build a new Emacs it will start working? We hope?

Eric

diff --git a/lisp/net/sieve.el b/lisp/net/sieve.el
index 3337998bed..4485b8c730 100644
--- a/lisp/net/sieve.el
+++ b/lisp/net/sieve.el
@@ -210,7 +210,11 @@ sieve-edit-script
 	      (set-buffer-modified-p nil)
 	    (error "Sieve download failed: %s" err)))
       (switch-to-buffer (get-buffer-create "template.siv"))
-      (insert sieve-template))
+      (insert sieve-template)
+      (setq name (read-string "Name for new script: "))
+      (when (string-match "\\.sieve\\'" name)
+        ;; The server will append .sieve to the script name.
+        (setq name (replace-match "" t t name))))
     (sieve-mode)
     (setq sieve-buffer-script-name name)
     (goto-char (point-min))