diff --git a/lisp/nnir.el b/lisp/nnir.el index 2a264d1..2dcebe6 100644 --- a/lisp/nnir.el +++ b/lisp/nnir.el @@ -343,7 +343,8 @@ (eval-when-compile (autoload 'nnimap-buffer "nnimap") (autoload 'nnimap-command "nnimap") - (autoload 'nnimap-possibly-change-group "nnimap")) + (autoload 'nnimap-possibly-change-group "nnimap") + (autoload 'nnimap-find-thread "nnimap")) (nnoo-declare nnir) (nnoo-define-basics nnir) @@ -717,21 +718,8 @@ and show thread that contains this article." (refs (split-string (mail-header-references (gnus-summary-article-header))))) (if (string= (car (gnus-group-method group)) "nnimap") - (with-current-buffer (nnimap-buffer) - (let* ((cmd (let ((value - (format - "(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)" - refid refid value))))) - (result (nnimap-command - "UID SEARCH %s" cmd))) - (gnus-summary-read-group-1 group t t gnus-summary-buffer nil - (and (car result) - (delete 0 (mapcar #'string-to-number - (cdr (assoc "SEARCH" (cdr result))))))))) + (gnus-summary-read-group-1 group t t gnus-summary-buffer nil + (nnimap-find-thread id refs)) (gnus-summary-read-group-1 group t t gnus-summary-buffer nil (list backend-number)) (gnus-summary-limit (list backend-number)) diff --git a/lisp/nnimap.el b/lisp/nnimap.el index c6c8787..5de8518 100644 --- a/lisp/nnimap.el +++ b/lisp/nnimap.el @@ -1659,6 +1659,22 @@ textual parts.") group-art)) nnimap-incoming-split-list))) +(defun nnimap-find-thread (id refs) + (let* ((cmd (let ((value + (format + "(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)" + refid refid value))))) + (result (with-current-buffer (nnimap-buffer) + (nnimap-command + "UID SEARCH %s" cmd)))) + (and (car result) + (delete 0 (mapcar #'string-to-number + (cdr (assoc "SEARCH" (cdr result)))))))) + (provide 'nnimap) ;;; nnimap.el ends here diff --git a/lisp/gnus-sum.el b/lisp/gnus-sum.el index 1086e28..a2f7a90 100644 --- a/lisp/gnus-sum.el +++ b/lisp/gnus-sum.el @@ -60,6 +60,7 @@ (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t) (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t) (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t) +(autoload 'nnimap-find-thread "nnimap") (defcustom gnus-kill-summary-on-exit t "*If non-nil, kill the summary buffer when you exit from it. @@ -8828,28 +8829,35 @@ If LIMIT (the numerical prefix), fetch that many old headers instead of what's specified by the `gnus-refer-thread-limit' variable." (interactive "P") (let ((id (mail-header-id (gnus-summary-article-header))) + (refs (split-string (or + (mail-header-references (gnus-summary-article-header)) ""))) (limit (if limit (prefix-numeric-value limit) gnus-refer-thread-limit))) - (unless (eq gnus-fetch-old-headers 'invisible) - (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name) - ;; Retrieve the headers and read them in. - (if (eq (if (numberp limit) - (gnus-retrieve-headers - (list (min - (+ (mail-header-number - (gnus-summary-article-header)) - limit) - gnus-newsgroup-end)) - gnus-newsgroup-name (* limit 2)) - ;; gnus-refer-thread-limit is t, i.e. fetch _all_ - ;; headers. - (gnus-retrieve-headers (list gnus-newsgroup-end) - gnus-newsgroup-name limit)) - 'nov) - (gnus-build-all-threads) - (error "Can't fetch thread from back ends that don't support NOV")) - (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)) - (gnus-summary-limit-include-thread id))) + (if (string= (car (gnus-group-method gnus-newsgroup-name)) "nnimap") + (progn (gnus-select-newsgroup gnus-newsgroup-name nil + (nnimap-find-thread id refs)) + (when gnus-build-sparse-threads + (gnus-build-sparse-threads))) + (unless (eq gnus-fetch-old-headers 'invisible) + (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name) + ;; Retrieve the headers and read them in. + (if (eq (if (numberp limit) + (gnus-retrieve-headers + (list (min + (+ (mail-header-number + (gnus-summary-article-header)) + limit) + gnus-newsgroup-end)) + gnus-newsgroup-name (* limit 2)) + ;; gnus-refer-thread-limit is t, i.e. fetch _all_ + ;; headers. + (gnus-retrieve-headers (list gnus-newsgroup-end) + gnus-newsgroup-name limit)) + 'nov) + (gnus-build-all-threads) + (error "Can't fetch thread from back ends that don't support NOV")) + (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))) + (gnus-summary-limit-include-thread id))) (defun gnus-summary-refer-article (message-id) "Fetch an article specified by MESSAGE-ID."