Subject: bug#18156: Thread sorting before loose threads are gathered

From: Michael Welsh Duggan <[email-masked]>
Date: Wed, 30 Jul 2014 20:00:59 -0400

Thread sorting happens before loose threads are gathered.  See the
definition of `gnus-summary-prepare'.  Threads are made, then cut, then
sorted, and then gathered.  I believe they should be made, cut,
gathered, and then sorted.  A consequence of the current order is that
using `gnus-thread-sort-by-most-recent-{number,date}' in the
`gnus-thread-sort-functions' will not pay attention to all messages in a
gathered thread.

I have verified that changing the order does the right thing, but some
functions that may be used in sorting do not know how to handle gathered
threads.  An example is `gnus-thread-latest-date' which will choke on
the string at the car of a gathered thread.  I made a change to
`gnus-thread-latest-date' so it understands gathered threads, but it may
make more sense to do this in the function(s) that call the sort
functions rather than testing that all sorting functions know how to
handle gathered threads.

I include the patch I was testing with.  It is only valid with respect
to the sorting functions I was working with, and as such isn't suitable
to commit in its current state.

diff --git a/lisp/gnus-sum.el b/lisp/gnus-sum.el
index 61cf7ec..8295227 100644
--- a/lisp/gnus-sum.el
+++ b/lisp/gnus-sum.el
@@ -4146,9 +4146,9 @@ If SELECT-ARTICLES, only select those articles from GROUP."
     (when gnus-newsgroup-headers
       (gnus-summary-prepare-threads
        (if gnus-show-threads
-	   (gnus-sort-gathered-threads
-	    (funcall gnus-summary-thread-gathering-function
-		     (gnus-sort-threads
+           (gnus-sort-threads
+            (gnus-sort-gathered-threads
+             (funcall gnus-summary-thread-gathering-function
 		      (gnus-cut-threads (gnus-make-threads)))))
 	 ;; Unthreaded display.
 	 (gnus-sort-articles gnus-newsgroup-headers))))
@@ -5109,7 +5109,8 @@ Unscored articles will be counted as having a score of zero."
 	 (mapcar (lambda (header) (gnus-float-time
 				   (gnus-date-get-time
 				    (mail-header-date header))))
-		 (message-flatten-list thread))))
+		 (let ((x (message-flatten-list thread)))
+                   (if (stringp (car x)) (cdr x) x)))))
 
 (defun gnus-thread-total-score-1 (root)
   ;; This function find the total score of the thread below ROOT.

Ma Gnus v0.8
GNU Emacs 24.4.50.1 (x86_64-unknown-linux-gnu, X toolkit)
 of 2014-07-13 on maru2
200 news.gmane.org InterNetNews NNRP server INN 2.5.1 ready (posting ok)
100 Legal commands
  ARTICLE [message-ID|number]
  AUTHINFO USER name|PASS password|GENERIC program [argument ...]
  BODY [message-ID|number]
  CAPABILITIES [keyword]
  DATE
  GROUP newsgroup
  HDR header [message-ID|range]
  HEAD [message-ID|number]
  HELP
  IHAVE message-ID
  LAST
  LIST [ACTIVE [wildmat]|ACTIVE.TIMES [wildmat]|DISTRIB.PATS|DISTRIBUTIONS|HEADERS [MSGID|RANGE]|MODERATORS|MOTD|NEWSGROUPS [wildmat]|OVERVIEW.FMT|SUBSCRIPTIONS]
  LISTGROUP [newsgroup [range]]
  MODE READER
  NEWGROUPS [yy]yymmdd hhmmss [GMT]
  NEWNEWS wildmat [yy]yymmdd hhmmss [GMT]
  NEXT
  OVER [range]
  POST
  QUIT
  STARTTLS
  STAT [message-ID|number]
  XGTITLE [wildmat]
  XHDR header [message-ID|range]
  XOVER [range]
  XPAT header message-ID|range pattern [pattern ...]
Report problems to <[email-masked]>.
.
382 Begin TLS negotiation now
100 Legal commands
  ARTICLE [message-ID|number]
  AUTHINFO USER name|PASS password|GENERIC program [argument ...]
  BODY [message-ID|number]
  CAPABILITIES [keyword]
  DATE
  GROUP newsgroup
  HDR header [message-ID|range]
  HEAD [message-ID|number]
  HELP
  IHAVE message-ID
  LAST
  LIST [ACTIVE [wildmat]|ACTIVE.TIMES [wildmat]|DISTRIB.PATS|DISTRIBUTIONS|HEADERS [MSGID|RANGE]|MODERATORS|MOTD|NEWSGROUPS [wildmat]|OVERVIEW.FMT|SUBSCRIPTIONS]
  LISTGROUP [newsgroup [range]]
  MODE READER
  NEWGROUPS [yy]yymmdd hhmmss [GMT]
  NEWNEWS wildmat [yy]yymmdd hhmmss [GMT]
  NEXT
  OVER [range]
  POST
  QUIT
  STARTTLS
  STAT [message-ID|number]
  XGTITLE [wildmat]
  XHDR header [message-ID|range]
  XOVER [range]
  XPAT header message-ID|range pattern [pattern ...]
Report problems to <[email-masked]>.
.

-- 
Michael Welsh Duggan
([email-masked])