+ (let (msg)
+ (save-excursion
+ (set-buffer rmail-buffer)
+ (rmail-previous-labeled-message n labels)
+ (setq msg rmail-current-message))
+ (rmail-summary-goto-msg msg)))
+
+(defun rmail-summary-next-same-subject (n)
+ "Go to the next message in the summary having the same subject.
+With prefix argument N, do this N times.
+If N is negative, go backwards."
+ (interactive "p")
+ (let (subject search-regexp i found
+ (forward (> n 0)))
+ (save-excursion
+ (set-buffer rmail-buffer)
+ (setq subject (mail-fetch-field "Subject"))
+ (setq i rmail-current-message))
+ (if (string-match "Re:[ \t]*" subject)
+ (setq subject (substring subject (match-end 0))))
+ (setq search-regexp (concat "^Subject: *\\(Re: *\\)?"
+ (regexp-quote subject)
+ "\n"))
+ (save-excursion
+ (while (and (/= n 0)
+ (if forward
+ (not (eobp))
+ (not (bobp))))
+ (let (done)
+ (while (and (not done)
+ (if forward
+ (not (eobp))
+ (not (bobp))))
+ ;; Advance thru summary.
+ (forward-line (if forward 1 -1))
+ ;; Get msg number of this line.
+ (setq i (string-to-int
+ (buffer-substring (point)
+ (min (point-max) (+ 5 (point))))))
+ ;; See if that msg has desired subject.
+ (save-excursion
+ (set-buffer rmail-buffer)
+ (save-restriction
+ (widen)
+ (goto-char (rmail-msgbeg i))
+ (search-forward "\n*** EOOH ***\n")
+ (let ((beg (point)) end)
+ (search-forward "\n\n")
+ (setq end (point))
+ (goto-char beg)
+ (setq done (re-search-forward search-regexp end t))))))
+ (if done (setq found i)))
+ (setq n (if forward (1- n) (1+ n)))))
+ (if found
+ (rmail-summary-goto-msg found)
+ (error "No %s message with same subject"
+ (if forward "following" "previous")))))
+
+(defun rmail-summary-previous-same-subject (n)
+ "Go to the previous message in the summary having the same subject.
+With prefix argument N, do this N times.
+If N is negative, go forwards instead."
+ (interactive "p")
+ (rmail-summary-next-same-subject (- n)))