(gnus-summary-refer-thread): Implement a version that uses *-request-thread.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Thu, 14 Oct 2010 19:02:21 +0000 (21:02 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Thu, 14 Oct 2010 19:02:21 +0000 (21:02 +0200)
From Andrew Cohen  <cohen@andy.bu.edu>.

lisp/ChangeLog
lisp/gnus-int.el
lisp/gnus-sum.el
lisp/nnimap.el

index 2285baf..58c2c58 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-14  Andrew Cohen  <cohen@andy.bu.edu>
+
+       * gnus-sum.el (gnus-summary-refer-thread): Implement a version that
+       uses *-request-thread.
+
 2010-10-14  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * nnimap.el (nnimap-open-connection): Remove %s from openssl
index b210df4..19bcffe 100644 (file)
@@ -504,6 +504,12 @@ If BUFFER, insert the article in that group."
             article (gnus-group-real-name group)
             (nth 1 gnus-command-method) buffer)))
 
+(defun gnus-request-thread (id)
+  "Request the thread containing the article specified by Message-ID id."
+  (let ((gnus-command-method (gnus-find-method-for-group gnus-newsgroup-name)))
+    (funcall (gnus-get-function gnus-command-method 'request-thread)
+            id)))
+
 (defun gnus-request-head (article group)
   "Request the head of ARTICLE in GROUP."
   (let* ((gnus-command-method (gnus-find-method-for-group group))
index 1086e28..568e297 100644 (file)
@@ -8824,31 +8824,35 @@ Return the number of articles fetched."
 
 (defun gnus-summary-refer-thread (&optional limit)
   "Fetch all articles in the current thread.
-If LIMIT (the numerical prefix), fetch that many old headers instead
-of what's specified by the `gnus-refer-thread-limit' variable."
+If no backend-specific 'request-thread function is available
+fetch LIMIT (the numerical prefix) old headers. If LIMIT is nil
+fetch what's specified by the `gnus-refer-thread-limit'
+variable."
   (interactive "P")
   (let ((id (mail-header-id (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))
+    (if  (gnus-check-backend-function 'request-thread gnus-newsgroup-name)
+       (gnus-request-thread id)
+      (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 (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)
+         (gnus-message 5 "Fetching headers for %s...done"
+                       gnus-newsgroup-name))))
+    (when (eq gnus-headers-retrieved-by 'nov)
+      (gnus-build-all-threads))
     (gnus-summary-limit-include-thread id)))
 
 (defun gnus-summary-refer-article (message-id)
index af26a1f..2c3a38a 100644 (file)
@@ -1311,6 +1311,25 @@ textual parts.")
   (setq nnimap-status-string "Read-only server")
   nil)
 
+(deffoo nnimap-request-thread (id)
+    (let* ((refs (split-string
+              (or (mail-header-references (gnus-summary-article-header))
+                  "")))
+          (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))))
+      (gnus-fetch-headers (and (car result)
+          (delete 0 (mapcar #'string-to-number
+                            (cdr (assoc "SEARCH" (cdr result)))))))))
+
 (defun nnimap-possibly-change-group (group server)
   (let ((open-result t))
     (when (and server