Subject: bug#49926: [PATCH] Fix NNIMAP search command in the gnus

From: Eric Abrahamsen <[email-masked]>
Date: Sat, 06 Nov 2021 07:55:29 -0700

On 11/06/21 03:39 AM, Lars Ingebrigtsen wrote:
> Eric Abrahamsen <[email-masked]> writes:
>
>> (Putting debbugs back in the cc)
>
> [...]
>
>>> New patch attached.
>
> The new version of the patch didn't make it to the bug tracker.  Could
> you re-send it, Jan?

He sent that directly to me, attached here. I guess I don't see any
problem with it.

>From 7f877856766b3e6b668ce4dc52130a3367f5dc6f Mon Sep 17 00:00:00 2001
From: Jan Stranik <[email-masked]>
Date: Sat, 7 Aug 2021 00:17:03 -0400
Subject: [PATCH] Fix NNIMAP search command in the gnus

In the version 27.2 of emacs, the nnimap search commands stopped
working in gnus.

Good example is a command AT to find a referred
thread in the summary buffer. The observed behaviour was that the
search command returned no error.

The problem turned out to be in the way how imap query is sent to the
server. The function nnimap-make-thread-query used a format function
with foramt specifier %S. For string values with formatting the string
returned is in the format #("string" ....). The result was tha the
query sent to the server looked like:
  23:52:00 [stranik.org] 1980 UID SEARCH (OR HEADER REFERENCES #("<[email-masked]>" 0 28 (ws-butler-chg chg)) HEADER Message-Id #("<[email-masked]>" 0 28 (ws-butler-chg chg)))

which is an invalid query.

The change formats the string with %s specifier which discards text
properties.
---
 lisp/gnus/nnimap.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 3cf65453f3..6e3c411bf2 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -2295,11 +2295,11 @@ Return the server's response to the SELECT or EXAMINE command."
 		    "")))
 	 (value
 	  (format
-	   "(OR HEADER REFERENCES %S HEADER Message-Id %S)"
+	   "(OR HEADER REFERENCES \"%s\" HEADER Message-Id \"%s\")"
 	   id id)))
     (dolist (refid refs value)
       (setq value (format
-		   "(OR (OR HEADER Message-Id %S HEADER REFERENCES %S) %s)"
+		   "(OR (OR HEADER Message-Id \"%s\" HEADER REFERENCES \"%s\") %s)"
 		   refid refid value)))))

-- 
2.31.1