Source

vm / vm-thread.el

Diff from to

vm-thread.el

 	    thread-list (list id-sym))
       (set (intern (symbol-name id-sym) vm-thread-loop-obarray) t)
       (while (not done)
+	;; save the date of the oldest message in this thread
+	(setq root-date (get id-sym 'oldest-date))
+	(if (or (null root-date)
+		(string< (vm-so-sortable-datestring message) root-date))
+	    (put id-sym 'oldest-date (vm-so-sortable-datestring message)))
 	(if (and (boundp id-sym) (symbol-value id-sym))
 	    (progn
 	      (setq id-sym (symbol-value id-sym)
 	  (if (null m)
 	      (setq done t)
 	    (if (null vm-thread-using-subject)
-		nil
+		(setq done t)
 	      (setq subject-sym
 		    (intern (vm-so-sortable-subject m)
 			    vm-thread-subject-obarray))
 		      (eq (aref (symbol-value subject-sym) 0) id-sym))
 		  (setq done t)
 		(setq id-sym (aref (symbol-value subject-sym) 0)
-		      loop-recovery-point (or loop-recovery-point
-					      thread-list)
+;; seems to cause more trouble than it fixes
+;; revisit this later.
+;;		      loop-recovery-point (or loop-recovery-point
+;;					      thread-list)
 		      loop-sym (intern (symbol-name id-sym)
 				       vm-thread-loop-obarray))
 		(if (boundp loop-sym)
 		  (set loop-sym t)
 		  (setq thread-list (cons id-sym thread-list)
 			m (car (get id-sym 'messages)))))))))
-      ;; save the date of the oldest message in this thread
-      (setq root-date (get id-sym 'oldest-date))
-      (if (or (null root-date)
-	      (string< (vm-so-sortable-datestring message) root-date))
-	  (put id-sym 'oldest-date (vm-so-sortable-datestring message)))
       thread-list )))
 
 ;; remove message struct from thread data.
       (vm-set-parent-of
        m
        (or (car (vm-last (vm-th-references m)))
-	   (let (in-reply-to)
-	     (setq in-reply-to (vm-get-header-contents m "In-Reply-To:" " "))
-	     (and in-reply-to
-		  (car (vm-parse in-reply-to "[^<]*\\(<[^>]+>\\)"))))))))
+	   (let (in-reply-to ids id)
+	     (setq in-reply-to (vm-get-header-contents m "In-Reply-To:" " ")
+		   ids (and in-reply-to (vm-parse in-reply-to
+						  "[^<]*\\(<[^>]+>\\)")))
+	     (while ids
+	       (if (< (length id) (length (car ids)))
+		   (setq id (car ids)))
+	       (setq ids (cdr ids)))
+	     (and id (vm-set-references-of m (list id)))
+	     id )))))
 
 (defun vm-th-thread-indentation (m)
   (or (vm-thread-indentation-of m)