Subject: bug#66885: 29.1; gnus search with mu always returns empty

From: Eric Abrahamsen <[email-masked]>
Date: Sun, 31 Dec 2023 18:53:28 -0800

Eric Abrahamsen <[email-masked]> writes:

> Britt Anderson <[email-masked]> writes:
>
>> Eric Abrahamsen <[email-masked]> writes:
>>
>>> Your configuration looks correct (your configuration also reveals an
>>> annoying redundancy in gnus-search, which is that most nnmail
>>> backends have a "directory" value that can and should be used as the
>>> value of remove-prefix).
>>>
>>> Basically, if you're seeing "a maildir "y2023" that lives in archives"
>>> as a Gnus group, then this is just a bug in gnus-search's mu handling,
>>> plain and simple.
>>
>> I think the bug starts on line 1952 of gnus-search.el.gz (when opened in
>> emacs). It is in the definition of the method for
>
> (Thank you for continuing to bug-hunt, this looks promising, I've just
> gotten back from traveling and will set this up to test soon...)

Hi Britt, I'm finally getting around to testing this. I set up mu with a
local maildir, and so far I'm not able to reproduce the problem. I mark
two maildir groups and search for unread messages with "mark:unread".

The search arguments constructed by gnus-search look like:

("find" "--nocolor" "--muhome=/home/eric/.cache/mu" "" "" "flag:unread"
"and" "(" "maildir:/mails" "or" "maildir:/Welcome" ")" "--format=plain"
"--fields=l")

Putting that on the command line and running it gives 17 results, and I
see the same 17 results within the Gnus search buffer. With the search
engine's `remove-prefix` set to the full system file path up to the main
directory of the nnmaildir backend (under which the groups appear as
top-level directories) the results are shown correctly within Gnus.

The group handling code you noticed is necessary, the
`(concat "maildir:/" x)` code is mu-specific.

I'm not sure what else to try! Even if mu is returning results from
other Gnus backends, that shouldn't cause a failure. Though mu has the
"path:" key we can use with remove-prefix...

The last things to try would be: setting `gnus-verbose' to 10, trying
the search, and telling me what you find in *Message*, and...

eval'ing this version of the mu command method, that includes the
"path:" key. Does this fix the problem?

(cl-defmethod gnus-search-indexed-search-command ((engine gnus-search-mu)
						  (qstring string)
						  query &optional groups)
  (let ((limit (alist-get 'limit query))
	(thread (alist-get 'thread query)))
    (with-slots (switches config-directory remove-prefix) engine
      `("find" 			; command must come first
	"--nocolor"		; mu will always give colored output otherwise
	,(format "--muhome=%s" config-directory)
	,@switches
	,(if thread "-r" "")
	,(if limit (format "--maxnum=%d" limit) "")
	,qstring
	,@(if groups
	      `("and" "("
		,@(nbutlast (mapcan (lambda (x)
				      (list (concat "maildir:/" x) "or"))
				    groups))
		")")
	    "")
	,(format "path:%s" (file-name-as-directory
                    (expand-file-name remove-prefix "/")))
	"--format=plain"
	"--fields=l"))))