+(defmacro wl-summary-put-alike (alike)
+ (` (elmo-set-hash-val (format "#%d" (wl-count-lines))
+ (, alike)
+ wl-summary-alike-hashtb)))
+
+(defmacro wl-summary-get-alike ()
+ (` (elmo-get-hash-val (format "#%d" (wl-count-lines))
+ wl-summary-alike-hashtb)))
+
+(defun wl-summary-insert-headers (overview func mime-decode)
+ (let (ov this last alike)
+ (buffer-disable-undo (current-buffer))
+ (make-local-variable 'wl-summary-alike-hashtb)
+ (setq wl-summary-alike-hashtb (elmo-make-hash (* (length overview) 2)))
+ (when mime-decode
+ (elmo-set-buffer-multibyte default-enable-multibyte-characters))
+ (while (setq ov (pop overview))
+ (setq this (funcall func ov))
+ (and this (setq this (std11-unfold-string this)))
+ (if (equal last this)
+ (wl-append alike (list ov))
+ (when last
+ (wl-summary-put-alike alike)
+ (insert last ?\n))
+ (setq alike (list ov)
+ last this)))
+ (when last
+ (wl-summary-put-alike alike)
+ (insert last ?\n))
+ (when mime-decode
+ (decode-mime-charset-region (point-min) (point-max)
+ elmo-mime-charset)
+ (when (eq mime-decode 'mime)
+ (eword-decode-region (point-min) (point-max))))
+ (run-hooks 'wl-summary-insert-headers-hook)))
+
+(defun wl-summary-search-by-subject (entity overview)
+ (let ((buf (get-buffer-create wl-summary-search-buf-name))
+ (folder-name wl-summary-buffer-folder-name)
+ match founds found-entity)
+ (save-excursion
+ (set-buffer buf)
+ (let ((case-fold-search t))
+ (when (or (not (string= wl-summary-buffer-folder-name folder-name))
+ (zerop (buffer-size)))
+ (setq wl-summary-buffer-folder-name folder-name)
+ (wl-summary-insert-headers
+ overview
+ (function
+ (lambda (x)
+ (wl-summary-subject-filter-func-internal
+ (elmo-msgdb-overview-entity-get-subject-no-decode x))))
+ t))
+ (setq match (wl-summary-subject-filter-func-internal
+ (elmo-msgdb-overview-entity-get-subject entity)))
+ (if (string= match "")
+ (setq match "\n"))
+ (goto-char (point-max))
+ (while (and (not founds)
+ (not (= (point) (point-min)))
+ (search-backward match nil t))
+ ;; check exactly match
+ (when (and (bolp)
+ (= (point-at-eol)
+ (match-end 0)))
+ (setq found-entity (wl-summary-get-alike))
+ (if (and found-entity
+ ;; Is founded entity myself or children?
+ (not (string=
+ (elmo-msgdb-overview-entity-get-id entity)
+ (elmo-msgdb-overview-entity-get-id (car found-entity))))
+ (not (wl-thread-descendant-p
+ (elmo-msgdb-overview-entity-get-number entity)
+ (elmo-msgdb-overview-entity-get-number (car found-entity)))))
+ ;; return matching entity
+ (setq founds found-entity))))
+ (if founds
+ (car founds))))))
+
+(defun wl-summary-insert-thread-entity (entity overview mark-alist update
+ &optional force-insert)
+ (let (update-list entity-stack)
+ (while entity
+ (let* ((this-id (elmo-msgdb-overview-entity-get-id entity))
+ (parent-entity
+ (elmo-msgdb-overview-get-parent-entity entity overview));; temp
+;;; (parent-id (elmo-msgdb-overview-entity-get-id parent-entity))
+ (parent-number (elmo-msgdb-overview-entity-get-number parent-entity))
+ (case-fold-search t)
+ msg overview2 cur-entity linked retval delayed-entity)
+ (setq msg (elmo-msgdb-overview-entity-get-number entity))
+ (if (and parent-number
+ (not (wl-thread-get-entity parent-number))
+ (not force-insert))
+ ;; parent is exists in overview, but not exists in wl-thread-entities
+ (progn
+ (wl-append wl-summary-delayed-update
+ (list (cons parent-number entity)))
+ (setq entity nil)) ;; exit loop
+ ;; Search parent by subject.
+ (when (and (null parent-number)
+ wl-summary-search-parent-by-subject-regexp
+ (string-match wl-summary-search-parent-by-subject-regexp
+ (elmo-msgdb-overview-entity-get-subject entity)))
+ (let ((found (wl-summary-search-by-subject entity overview)))
+ (when (and found
+ (not (member found wl-summary-delayed-update)))
+ (setq parent-entity found)
+ (setq parent-number
+ (elmo-msgdb-overview-entity-get-number parent-entity))
+ (setq linked t))))
+ ;; If subject is change, divide thread.
+ (if (and parent-number
+ wl-summary-divide-thread-when-subject-changed
+ (not (wl-summary-subject-equal
+ (or (elmo-msgdb-overview-entity-get-subject
+ entity) "")
+ (or (elmo-msgdb-overview-entity-get-subject
+ parent-entity) ""))))
+ (setq parent-number nil))
+ ;;
+ (setq retval
+ (wl-thread-insert-message entity overview mark-alist
+ msg parent-number update linked))
+ (and retval
+ (wl-append update-list (list retval)))
+ (setq entity nil) ; exit loop
+ (while (setq delayed-entity (assq msg wl-summary-delayed-update))
+ (setq wl-summary-delayed-update
+ (delete delayed-entity wl-summary-delayed-update))
+ ;; update delayed message
+ (wl-append entity-stack (list (cdr delayed-entity)))))
+ (if (and (not entity)
+ entity-stack)
+ (setq entity (pop entity-stack)))))
+ update-list))
+
+(defun wl-summary-update-thread (entity
+ overview
+ mark-alist