From: Eli Zaretskii <eliz@gnu.org>
To: Kai Tetzlaff <emacs+bug@tetzco.de>
Cc: herbert@gojira.at, 54154@debbugs.gnu.org, larsi@gnus.org
Subject: bug#54154: Emacs commit ae963e80a79f5a9184daabfc8197f211a39b136d (sieve-manage)
Date: Thu, 19 Jan 2023 19:41:13 +0200 [thread overview]
Message-ID: <83v8l2o212.fsf@gnu.org> (raw)
In-Reply-To: <87bkmua51z.fsf@tetzco.de> (message from Kai Tetzlaff on Thu, 19 Jan 2023 16:59:36 +0100)
> From: Kai Tetzlaff <emacs+bug@tetzco.de>
> Cc: herbert@gojira.at, larsi@gnus.org, 54154@debbugs.gnu.org
> Date: Thu, 19 Jan 2023 16:59:36 +0100
>
> >> Yes, true. But since `sieve-manage--set-internal-buffer-properties' is
> >> used in two different places, the more elegant solution you suggested
> >> above would require duplicating the body of the function in those
> >> places. I just didn't see a better way.
> >
> > I'm not sure why you need to force the encoding of the process buffer,
> > when you already set the coding-system to be used for decoding stuff
> > from the process. Is that really needed?
>
> Not sure if it is really needed. But I wanted to make sure that both,
> the process buffer and the log buffer use identical settings. Otherwise,
> the content of the log buffer might be misleading.
I don't think it could mislead, but OK.
> > But if you really need this, then just make the insertion of the text
> > into the buffer you create optional: then for the process-buffer pass
> > nil as the text to insert, and you can do the with-current-buffer
> > dance only inside that function.
>
> Sorry, you lost me there. I don't understand what you want to tell me.
> Which (optional) text in which buffer?
I meant this:
(defun sieve-manage--set-buffer-and-append-text (buffer-name &rest args)
(let ((existing-buffer (get-buffer buffer-name))
new-buffer)
(if existing-buffer
(setq new-buffer existing-buffer)
(setq new-buffer (get-buffer-create buffer-name)))
(with-current-buffer new-buffer
(when (not existing-buffer)
(set-buffer-file-coding-system sieve-manage--coding-system)
(setq-local after-change-functions nil)
(buffer-disable-undo)
; What happened to set-buffer-multibyte?
)
(goto-char (point-max))
(apply #'insert args))))
Then you can call it from sieve-manage-make-process-buffer like this:
(sieve-manage--set-buffer-and-append-text
(format " *sieve %s:%s*" sieve-manage-server sieve-manage-port)
"")
i.e. with an empty string, so nothing gets inserted into the process
buffer. Or you could instead change the signature to accept a single
&optional argument that is a list, and then you could make the last
two lines in the function above conditional on that argument being
non-nil.
> > Since you seem to be encoding and decoding to/from UTF-8 by hand in
> > sieve-manage-encode/decode, you should use 'binary' as the
> > process-codings-system for the network connection to the server, and
> > that's it.
>
> That works. Done.
>
> > What you should do is call sieve-manage-encode inside
> > sieve-manage-send, and count the bytes there after encoding the
> > payload.
>
> Unfortunately, that is too late since the sent data - in case that the
> sent text may contain CRLF sequences - contains its own length. So in
> order to insert the correct length, I need to encode before sending.
> See:
>
> (defun sieve-manage-putscript (name content &optional buffer)
> (with-current-buffer (or buffer (current-buffer))
> (sieve-manage-send (format "PUTSCRIPT \"%s\" {%d+}%s%s" name
> (length (sieve-manage-encode content))
> sieve-manage-client-eol content))
> (sieve-manage-parse-oknobye)))
This is because you pass both the text and the number to 'format'.
But that is not carved in stone: the "%d" part can never produce any
non-ASCII characters, so there's no need to encode it together with
CONTENT. You could do this instead:
(defun sieve-manage-send (command &optional payload)
(let ((encoded (if payload (encode-coding-string payload 'utf-8-unix)))
size cmdstr)
(if encoded
(setq size (format " {%d+}%s"
(length encoded) sieve-manage-client-eol)))
(setq cmdstr (concat command size encoded))
(sieve-manage--append-to-log cmdstr)
(process-send-string sieve-manage-process cmdstr)))
And then you call this like below:
(sieve-manage-send (format "PUTSCRIPT \"%s\"" name) content)
(sieve-manage-send (format "HAVESPACE \"%s\" %s" name size))
I hope this clarifies my proposal.
next prev parent reply other threads:[~2023-01-19 17:41 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-25 9:04 bug#54154: 29.0.50; [PATCH] `sieve-manage-getscript' fails if script contains multibyte characters Kai Tetzlaff
2022-02-25 12:19 ` Lars Ingebrigtsen
2022-02-25 13:10 ` Lars Ingebrigtsen
2022-02-25 16:00 ` Kai Tetzlaff
2022-02-26 15:07 ` Lars Ingebrigtsen
2022-02-28 12:27 ` Kai Tetzlaff
2022-09-06 11:34 ` Lars Ingebrigtsen
2022-02-28 12:35 ` Kai Tetzlaff
2022-02-28 13:06 ` Lars Ingebrigtsen
2022-02-28 13:08 ` Lars Ingebrigtsen
2022-02-28 13:03 ` Kai Tetzlaff
[not found] ` <87bkmwi0ut.fsf@tetzco.de>
[not found] ` <87fsc8i2c5.fsf@tetzco.de>
[not found] ` <87bkmw8b02.fsf@tetzco.de>
2023-01-18 18:28 ` bug#54154: Emacs commit ae963e80a79f5a9184daabfc8197f211a39b136d (sieve-manage) Herbert J. Skuhra
2023-01-18 19:17 ` Eli Zaretskii
2023-01-18 23:22 ` Herbert J. Skuhra
2023-01-19 4:06 ` Kai Tetzlaff
2023-01-19 7:45 ` Eli Zaretskii
2023-01-19 12:38 ` Kai Tetzlaff
2023-01-19 14:08 ` Eli Zaretskii
2023-01-19 15:59 ` Kai Tetzlaff
2023-01-19 17:41 ` Eli Zaretskii [this message]
2023-01-19 21:33 ` Kai Tetzlaff
2023-01-20 6:54 ` Kai Tetzlaff
2023-01-22 2:12 ` Kai Tetzlaff
2023-01-23 0:59 ` Kai Tetzlaff
2023-01-23 12:47 ` Herbert J. Skuhra
2023-01-23 13:01 ` Kai Tetzlaff
2023-01-23 13:36 ` Herbert J. Skuhra
2023-01-23 13:57 ` Kai Tetzlaff
2023-01-23 14:27 ` Andreas Schwab
2023-01-23 17:07 ` Kai Tetzlaff
2023-01-23 17:53 ` Andreas Schwab
2023-01-23 13:40 ` Eli Zaretskii
2023-01-23 16:22 ` Kai Tetzlaff
2023-01-23 16:49 ` Eli Zaretskii
2023-01-23 17:12 ` Kai Tetzlaff
2023-01-19 13:22 ` Kai Tetzlaff
2023-01-19 14:16 ` Kai Tetzlaff
2023-01-19 4:50 ` bug#54154: [update] " Kai Tetzlaff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83v8l2o212.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=54154@debbugs.gnu.org \
--cc=emacs+bug@tetzco.de \
--cc=herbert@gojira.at \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).