Function: gnus-search-thread

gnus-search-thread is an autoloaded and byte-compiled function defined in gnus-search.el.gz.

Signature

(gnus-search-thread HEADER &optional GROUP SERVER)

Documentation

Find articles in the thread containing HEADER from GROUP on SERVER.

If gnus-refer-thread-use-search is nil only the current group is checked for articles; if t all groups on the server containing the article's group will be searched; if a list then all servers in this list will be searched. If possible the newly found articles are added to the summary buffer; otherwise the full thread along with the original articles are displayed in a new ephemeral nnselect buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-search.el.gz
(defun gnus-search-thread (header &optional group server)
  "Find articles in the thread containing HEADER from GROUP on SERVER.
If `gnus-refer-thread-use-search' is nil only the current group is
checked for articles; if t all groups on the server containing
the article's group will be searched; if a list then all servers
in this list will be searched.  If possible the newly found
articles are added to the summary buffer; otherwise the full
thread along with the original articles are displayed in a new
ephemeral nnselect buffer."
  (let* ((group (or group gnus-newsgroup-name))
         (server (or server (gnus-group-server group)))
         (query
          (list
           (cons 'query
                 (mapconcat (lambda (i) (format "id:%s" i))
                            (cons (mail-header-id header)
                                  (split-string
                                   (or (mail-header-references header) "")))
                            " or "))
           (cons 'thread t)))
         (gnus-search-use-parsed-queries t))
    (if (not gnus-refer-thread-use-search)
        ;; Search only the current group and send the headers back to
        ;; the caller to add to the summary buffer.
        (gnus-fetch-headers
         (sort
          (mapcar (lambda (x) (elt x 1))
                  (gnus-search-run-query
                   (list (cons 'search-query-spec query)
                         (cons 'search-group-spec
                               (list (list server group))))))
          #'<) nil t)
      ;; Otherwise create an ephemeral search group: record the
      ;; current summary contents; exit the current group (so that
      ;; changes are saved); then create a new ephemeral group with
      ;; the original articles plus those of the thread.
      (let ((selection (seq-map (lambda (x) (vector group x 100))
                                gnus-newsgroup-articles))
            (thread  (gnus-search-run-query
                      (list (cons 'search-query-spec query)
                            (cons 'search-group-spec
                                  (if (listp gnus-refer-thread-use-search)
                                      gnus-refer-thread-use-search
                                    (list (list server))))))))
        (if (< (nnselect-artlist-length thread) 2)
            (message "No other articles in thread")
          (setq selection
                (seq-into
                 (seq-union selection thread
                            (lambda (x y)
                              (and (equal (nnselect-artitem-group x)
                                          (nnselect-artitem-group y))
                                   (eql (nnselect-artitem-number x)
                                        (nnselect-artitem-number y)))))
                 'vector))
          (gnus-summary-exit)
          (gnus-group-read-ephemeral-group
           (concat "nnselect-" (message-unique-id))
           (list 'nnselect "nnselect")
           nil
           (cons (current-buffer) gnus-current-window-configuration)
           nil nil
           (list
            (cons 'nnselect-specs
                  (list
                   (cons 'nnselect-function 'identity)
                   (cons 'nnselect-args
                         selection)))
            (cons 'nnselect-artlist nil))
           (nnselect-artlist-length selection))
          (if (gnus-id-to-article (mail-header-id header))
              (gnus-summary-goto-subject
               (gnus-id-to-article (mail-header-id header)))
            (message "Thread search failed")))))))