The additional changes I mentioned above solve the problem in a different way by introducing a helper function. The also add some other improvements including a new test for handling multibyte characters in sieve server responses. I'm attaching the additional patches below. They might be too large for the current emacs-29 branch. But maybe they can be applied to master?