annotate lisp/mh-e/mh-thread.el @ 104186:983634064cd2

Fix header.
author Glenn Morris <rgm@gnu.org>
date Sat, 08 Aug 2009 02:33:22 +0000
parents 6837adfb2772
children 00c0adbb54a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
1 ;;; mh-thread.el --- MH-E threading support
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
2
101484
ec23bb963b19 Follow Glenn's lead and update format of Copyright.
Bill Wohler <wohler@newt.com>
parents: 100908
diff changeset
3 ;; Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009
ec23bb963b19 Follow Glenn's lead and update format of Copyright.
Bill Wohler <wohler@newt.com>
parents: 100908
diff changeset
4 ;; Free Software Foundation, Inc.
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
5
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
6 ;; Author: Satyaki Das <satyaki@theforce.stanford.edu>
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
7 ;; Maintainer: Bill Wohler <wohler@newt.com>
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
8 ;; Keywords: mail
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
9 ;; See: mh-e.el
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
10
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
12
94663
90c9ebd43589 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79713
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94663
90c9ebd43589 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79713
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
90c9ebd43589 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79713
diff changeset
16 ;; (at your option) any later version.
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
17
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
21 ;; GNU General Public License for more details.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
22
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94663
90c9ebd43589 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79713
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
25
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
26 ;;; Commentary:
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
27
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
28 ;; The threading portion of this files tries to implement the
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
29 ;; algorithm described at:
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
30 ;; http://www.jwz.org/doc/threading.html
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
31 ;; It also begins to implement the IMAP Threading extension RFC. The
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
32 ;; implementation lacks the reference and subject canonicalization of
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
33 ;; the RFC.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
34
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
35 ;; In the presentation buffer, children messages are shown indented
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
36 ;; with either [ ] or < > around them. Square brackets ([ ]) denote
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
37 ;; that the algorithm can point out some headers which when taken
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
38 ;; together implies that the unindented message is an ancestor of the
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
39 ;; indented message. If no such proof exists then angles (< >) are
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
40 ;; used.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
41
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
42 ;; If threading is slow on your machine, compile this file. Of all the
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
43 ;; files in MH-E, this one really benefits from compilation.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
44
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
45 ;; Some issues and problems are as follows:
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
46
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
47 ;; (1) Scan truncates the fields at length 512. So longer
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
48 ;; references: headers get mutilated. The same kind of MH
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
49 ;; format string works when composing messages. Is there a way
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
50 ;; to avoid this? My scan command is as follows:
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
51 ;; scan +folder -width 10000 \
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
52 ;; -format "%(msg)\n%{message-id}\n%{references}\n%{subject}\n"
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
53 ;; I would really appreciate it if someone would help me with this.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
54
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
55 ;; (2) Implement heuristics to recognize message identifiers in
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
56 ;; In-Reply-To: header. Right now it just assumes that the last
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
57 ;; text between angles (< and >) is the message identifier.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
58 ;; There is the chance that this will incorrectly use an email
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
59 ;; address like a message identifier.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
60
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
61 ;; (3) Error checking of found message identifiers should be done.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
62
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
63 ;; (4) Since this breaks the assumption that message indices
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
64 ;; increase as one goes down the buffer, the binary search
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
65 ;; based mh-goto-msg doesn't work. I have a simpler replacement
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
66 ;; which may be less efficient.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
67
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
68 ;; (5) Better canonicalizing for message identifier and subject
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
69 ;; strings.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
70
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
71 ;;; Change Log:
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
72
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
73 ;;; Code:
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
74
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
75 (require 'mh-e)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
76 (require 'mh-scan)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
77
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
78 (mh-defstruct (mh-thread-message (:conc-name mh-message-)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
79 (:constructor mh-thread-make-message))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
80 (id nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
81 (references ())
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
82 (subject "")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
83 (subject-re-p nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
84
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
85 (mh-defstruct (mh-thread-container (:conc-name mh-container-)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
86 (:constructor mh-thread-make-container))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
87 message parent children
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
88 (real-child-p t))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
89
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
90 (defvar mh-thread-id-hash nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
91 "Hashtable used to canonicalize message identifiers.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
92 (make-variable-buffer-local 'mh-thread-id-hash)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
93
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
94 (defvar mh-thread-subject-hash nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
95 "Hashtable used to canonicalize subject strings.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
96 (make-variable-buffer-local 'mh-thread-subject-hash)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
97
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
98 (defvar mh-thread-id-table nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
99 "Thread ID table maps from message identifiers to message containers.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
100 (make-variable-buffer-local 'mh-thread-id-table)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
101
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
102 (defvar mh-thread-index-id-map nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
103 "Table to look up message identifier from message index.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
104 (make-variable-buffer-local 'mh-thread-index-id-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
105
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
106 (defvar mh-thread-id-index-map nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
107 "Table to look up message index number from message identifier.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
108 (make-variable-buffer-local 'mh-thread-id-index-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
109
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
110 (defvar mh-thread-subject-container-hash nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
111 "Hashtable used to group messages by subject.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
112 (make-variable-buffer-local 'mh-thread-subject-container-hash)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
113
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
114 (defvar mh-thread-duplicates nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
115 "Hashtable used to associate messages with the same message identifier.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
116 (make-variable-buffer-local 'mh-thread-duplicates)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
117
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
118 (defvar mh-thread-history ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
119 "Variable to remember the transformations to the thread tree.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
120 When new messages are added, these transformations are rewound,
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
121 then the links are added from the newly seen messages. Finally
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
122 the transformations are redone to get the new thread tree. This
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
123 makes incremental threading easier.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
124 (make-variable-buffer-local 'mh-thread-history)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
125
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
126 (defvar mh-thread-body-width nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
127 "Width of scan substring that contains subject and body of message.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
128
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
129
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
130
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
131 ;;; MH-Folder Commands
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
132
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
133 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
134 (defun mh-thread-ancestor (&optional thread-root-flag)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
135 "Display ancestor of current message.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
136
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
137 If you do not care for the way a particular thread has turned,
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
138 you can move up the chain of messages with this command. This
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
139 command can also take a prefix argument THREAD-ROOT-FLAG to jump
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
140 to the message that started everything."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
141 (interactive "P")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
142 (beginning-of-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
143 (cond ((not (memq 'unthread mh-view-ops))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
144 (error "Folder isn't threaded"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
145 ((eobp)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
146 (error "No message at point")))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
147 (let ((current-level (mh-thread-current-indentation-level)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
148 (cond (thread-root-flag
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
149 (while (mh-thread-immediate-ancestor))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
150 (mh-maybe-show))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
151 ((equal current-level 1)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
152 (message "Message has no ancestor"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
153 (t (mh-thread-immediate-ancestor)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
154 (mh-maybe-show)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
155
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
156 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
157 (defun mh-thread-delete ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
158 "Delete thread."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
159 (interactive)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
160 (cond ((not (memq 'unthread mh-view-ops))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
161 (error "Folder isn't threaded"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
162 ((eobp)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
163 (error "No message at point"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
164 (t (let ((region (mh-thread-find-children)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
165 (mh-iterate-on-messages-in-region () (car region) (cadr region)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
166 (mh-delete-a-msg nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
167 (mh-next-msg)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
168
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
169 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
170 (defun mh-thread-next-sibling (&optional previous-flag)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
171 "Display next sibling.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
172
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
173 With non-nil optional argument PREVIOUS-FLAG jump to the previous
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
174 sibling."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
175 (interactive)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
176 (cond ((not (memq 'unthread mh-view-ops))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
177 (error "Folder isn't threaded"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
178 ((eobp)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
179 (error "No message at point")))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
180 (beginning-of-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
181 (let ((point (point))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
182 (done nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
183 (my-level (mh-thread-current-indentation-level)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
184 (while (and (not done)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
185 (equal (forward-line (if previous-flag -1 1)) 0)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
186 (not (eobp)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
187 (let ((level (mh-thread-current-indentation-level)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
188 (cond ((equal level my-level)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
189 (setq done 'success))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
190 ((< level my-level)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
191 (message "No %s sibling" (if previous-flag "previous" "next"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
192 (setq done 'failure)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
193 (cond ((eq done 'success) (mh-maybe-show))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
194 ((eq done 'failure) (goto-char point))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
195 (t (message "No %s sibling" (if previous-flag "previous" "next"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
196 (goto-char point)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
197
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
198 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
199 (defun mh-thread-previous-sibling ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
200 "Display previous sibling."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
201 (interactive)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
202 (mh-thread-next-sibling t))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
203
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
204 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
205 (defun mh-thread-refile (folder)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
206 "Refile (output) thread into FOLDER."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
207 (interactive (list (intern (mh-prompt-for-refile-folder))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
208 (cond ((not (memq 'unthread mh-view-ops))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
209 (error "Folder isn't threaded"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
210 ((eobp)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
211 (error "No message at point"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
212 (t (let ((region (mh-thread-find-children)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
213 (mh-iterate-on-messages-in-region () (car region) (cadr region)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
214 (mh-refile-a-msg nil folder))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
215 (mh-next-msg)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
216
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
217 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
218 (defun mh-toggle-threads ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
219 "Toggle threaded view of folder."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
220 (interactive)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
221 (let ((msg-at-point (mh-get-msg-num nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
222 (old-buffer-modified-flag (buffer-modified-p))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
223 (buffer-read-only nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
224 (cond ((memq 'unthread mh-view-ops)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
225 (unless (mh-valid-view-change-operation-p 'unthread)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
226 (error "Can't unthread folder"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
227 (let ((msg-list ()))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
228 (goto-char (point-min))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
229 (while (not (eobp))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
230 (let ((index (mh-get-msg-num nil)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
231 (when index
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
232 (push index msg-list)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
233 (forward-line))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
234 (mh-scan-folder mh-current-folder
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
235 (mapcar #'(lambda (x) (format "%s" x))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
236 (mh-coalesce-msg-list msg-list))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
237 t))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
238 (when mh-index-data
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
239 (mh-index-insert-folder-headers)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
240 (mh-notate-cur)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
241 (t (mh-thread-folder)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
242 (push 'unthread mh-view-ops)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
243 (when msg-at-point (mh-goto-msg msg-at-point t t))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
244 (set-buffer-modified-p old-buffer-modified-flag)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
245 (mh-recenter nil)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
246
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
247
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
248
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
249 ;;; Support Routines
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
250
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
251 (defun mh-thread-current-indentation-level ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
252 "Find the number of spaces by which current message is indented."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
253 (save-excursion
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
254 (let ((address-start-offset (+ mh-cmd-note mh-scan-date-flag-width
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
255 mh-scan-date-width 1))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
256 (level 0))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
257 (beginning-of-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
258 (forward-char address-start-offset)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
259 (while (char-equal (char-after) ? )
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
260 (incf level)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
261 (forward-char))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
262 level)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
263
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
264 (defun mh-thread-immediate-ancestor ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
265 "Jump to immediate ancestor in thread tree."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
266 (beginning-of-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
267 (let ((point (point))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
268 (ancestor-level (- (mh-thread-current-indentation-level) 2))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
269 (done nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
270 (if (< ancestor-level 0)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
271 nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
272 (while (and (not done) (equal (forward-line -1) 0))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
273 (when (equal ancestor-level (mh-thread-current-indentation-level))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
274 (setq done t)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
275 (unless done
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
276 (goto-char point))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
277 done)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
278
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
279 (defun mh-thread-find-children ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
280 "Return a region containing the current message and its children.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
281 The result is returned as a list of two elements. The first is
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
282 the point at the start of the region and the second is the point
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
283 at the end."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
284 (beginning-of-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
285 (if (eobp)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
286 nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
287 (let ((address-start-offset (+ mh-cmd-note mh-scan-date-flag-width
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
288 mh-scan-date-width 1))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
289 (level (mh-thread-current-indentation-level))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
290 spaces begin)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
291 (setq begin (point))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
292 (setq spaces (format (format "%%%ss" (1+ level)) ""))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
293 (forward-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
294 (block nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
295 (while (not (eobp))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
296 (forward-char address-start-offset)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
297 (unless (equal (string-match spaces (buffer-substring-no-properties
68529
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
298 (point) (mh-line-end-position)))
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
299 0)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
300 (beginning-of-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
301 (backward-char)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
302 (return))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
303 (forward-line)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
304 (list begin (point)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
305
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
306
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
307
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
308 ;;; Thread Creation
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
309
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
310 (defun mh-thread-folder ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
311 "Generate thread view of folder."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
312 (message "Threading %s..." (buffer-name))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
313 (mh-thread-initialize)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
314 (goto-char (point-min))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
315 (mh-remove-all-notation)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
316 (let ((msg-list ()))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
317 (mh-iterate-on-range msg (cons (point-min) (point-max))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
318 (setf (gethash msg mh-thread-scan-line-map) (mh-thread-parse-scan-line))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
319 (push msg msg-list))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
320 (let* ((range (mh-coalesce-msg-list msg-list))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
321 (thread-tree (mh-thread-generate (buffer-name) range)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
322 (delete-region (point-min) (point-max))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
323 (mh-thread-print-scan-lines thread-tree)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
324 (mh-notate-user-sequences)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
325 (mh-notate-deleted-and-refiled)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
326 (mh-notate-cur)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
327 (message "Threading %s...done" (buffer-name)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
328
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
329 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
330 (defun mh-thread-inc (folder start-point)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
331 "Update thread tree for FOLDER.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
332 All messages after START-POINT are added to the thread tree."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
333 (mh-thread-rewind-pruning)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
334 (mh-remove-all-notation)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
335 (goto-char start-point)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
336 (let ((msg-list ()))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
337 (while (not (eobp))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
338 (let ((index (mh-get-msg-num nil)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
339 (when (numberp index)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
340 (push index msg-list)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
341 (setf (gethash index mh-thread-scan-line-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
342 (mh-thread-parse-scan-line)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
343 (forward-line)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
344 (let ((thread-tree (mh-thread-generate folder msg-list))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
345 (buffer-read-only nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
346 (old-buffer-modified-flag (buffer-modified-p)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
347 (delete-region (point-min) (point-max))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
348 (mh-thread-print-scan-lines thread-tree)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
349 (mh-notate-user-sequences)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
350 (mh-notate-deleted-and-refiled)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
351 (mh-notate-cur)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
352 (set-buffer-modified-p old-buffer-modified-flag))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
353
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
354 (defmacro mh-thread-initialize-hash (var test)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
355 "Initialize the hash table in VAR.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
356 TEST is the test to use when creating a new hash table."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
357 (unless (symbolp var) (error "Expected a symbol: %s" var))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
358 `(if ,var (clrhash ,var) (setq ,var (make-hash-table :test ,test))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
359
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
360 (defun mh-thread-initialize ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
361 "Make new hash tables, or clear them if already present."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
362 (mh-thread-initialize-hash mh-thread-id-hash #'equal)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
363 (mh-thread-initialize-hash mh-thread-subject-hash #'equal)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
364 (mh-thread-initialize-hash mh-thread-id-table #'eq)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
365 (mh-thread-initialize-hash mh-thread-id-index-map #'eq)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
366 (mh-thread-initialize-hash mh-thread-index-id-map #'eql)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
367 (mh-thread-initialize-hash mh-thread-scan-line-map #'eql)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
368 (mh-thread-initialize-hash mh-thread-subject-container-hash #'eq)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
369 (mh-thread-initialize-hash mh-thread-duplicates #'eq)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
370 (setq mh-thread-history ()))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
371
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
372 (defsubst mh-thread-id-container (id)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
373 "Given ID, return the corresponding container in `mh-thread-id-table'.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
374 If no container exists then a suitable container is created and
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
375 the id-table is updated."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
376 (when (not id)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
377 (error "1"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
378 (or (gethash id mh-thread-id-table)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
379 (setf (gethash id mh-thread-id-table)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
380 (let ((message (mh-thread-make-message :id id)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
381 (mh-thread-make-container :message message)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
382
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
383 (defsubst mh-thread-remove-parent-link (child)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
384 "Remove parent link of CHILD if it exists."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
385 (let* ((child-container (if (mh-thread-container-p child)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
386 child (mh-thread-id-container child)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
387 (parent-container (mh-container-parent child-container)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
388 (when parent-container
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
389 (setf (mh-container-children parent-container)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
390 (loop for elem in (mh-container-children parent-container)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
391 unless (eq child-container elem) collect elem))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
392 (setf (mh-container-parent child-container) nil))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
393
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
394 (defsubst mh-thread-add-link (parent child &optional at-end-p)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
395 "Add links so that PARENT becomes a parent of CHILD.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
396 Doesn't make any changes if CHILD is already an ancestor of
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
397 PARENT. If optional argument AT-END-P is non-nil, the CHILD is
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
398 added to the end of the children list of PARENT."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
399 (let ((parent-container (cond ((null parent) nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
400 ((mh-thread-container-p parent) parent)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
401 (t (mh-thread-id-container parent))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
402 (child-container (if (mh-thread-container-p child)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
403 child (mh-thread-id-container child))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
404 (when (and parent-container
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
405 (not (mh-thread-ancestor-p child-container parent-container))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
406 (not (mh-thread-ancestor-p parent-container child-container)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
407 (mh-thread-remove-parent-link child-container)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
408 (cond ((not at-end-p)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
409 (push child-container (mh-container-children parent-container)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
410 ((null (mh-container-children parent-container))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
411 (push child-container (mh-container-children parent-container)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
412 (t (let ((last-child (mh-container-children parent-container)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
413 (while (cdr last-child)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
414 (setq last-child (cdr last-child)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
415 (setcdr last-child (cons child-container nil)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
416 (setf (mh-container-parent child-container) parent-container))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
417 (unless parent-container
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
418 (mh-thread-remove-parent-link child-container))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
419
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
420 (defun mh-thread-rewind-pruning ()
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
421 "Restore the thread tree to its state before pruning."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
422 (while mh-thread-history
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
423 (let ((action (pop mh-thread-history)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
424 (cond ((eq (car action) 'DROP)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
425 (mh-thread-remove-parent-link (cadr action))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
426 (mh-thread-add-link (caddr action) (cadr action)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
427 ((eq (car action) 'PROMOTE)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
428 (let ((node (cadr action))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
429 (parent (caddr action))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
430 (children (cdddr action)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
431 (dolist (child children)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
432 (mh-thread-remove-parent-link child)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
433 (mh-thread-add-link node child))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
434 (mh-thread-add-link parent node)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
435 ((eq (car action) 'SUBJECT)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
436 (let ((node (cadr action)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
437 (mh-thread-remove-parent-link node)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
438 (setf (mh-container-real-child-p node) t)))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
439
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
440 (defun mh-thread-ancestor-p (ancestor successor)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
441 "Return t if ANCESTOR is really an ancestor of SUCCESSOR and nil otherwise.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
442 In the limit, the function returns t if ANCESTOR and SUCCESSOR
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
443 are the same containers."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
444 (block nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
445 (while successor
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
446 (when (eq ancestor successor) (return t))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
447 (setq successor (mh-container-parent successor)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
448 nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
449
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
450 ;; Another and may be better approach would be to generate all the info from
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
451 ;; the scan which generates the threading info. For now this will have to do.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
452 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
453 (defun mh-thread-parse-scan-line (&optional string)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
454 "Parse a scan line.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
455 If optional argument STRING is given then that is assumed to be
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
456 the scan line. Otherwise uses the line at point as the scan line
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
457 to parse."
68529
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
458 (let* ((string (or string (buffer-substring-no-properties
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
459 (mh-line-beginning-position)
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
460 (mh-line-end-position))))
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
461 (address-start (+ mh-cmd-note mh-scan-field-from-start-offset))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
462 (body-start (+ mh-cmd-note mh-scan-field-from-end-offset))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
463 (first-string (substring string 0 address-start)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
464 (list first-string
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
465 (substring string address-start (- body-start 2))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
466 (substring string body-start)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
467 string)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
468
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
469 (defsubst mh-thread-canonicalize-id (id)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
470 "Produce canonical string representation for ID.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
471 This allows cheap string comparison with EQ."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
472 (or (and (equal id "") (copy-sequence ""))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
473 (gethash id mh-thread-id-hash)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
474 (setf (gethash id mh-thread-id-hash) id)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
475
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
476 (defsubst mh-thread-prune-subject (subject)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
477 "Prune leading Re:'s, Fwd:'s etc. and trailing (fwd)'s from SUBJECT.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
478 If the result after pruning is not the empty string then it is
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
479 canonicalized so that subjects can be tested for equality with
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
480 eq. This is done so that all the messages without a subject are
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
481 not put into a single thread."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
482 (let ((case-fold-search t)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
483 (subject-pruned-flag nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
484 ;; Prune subject leader
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
485 (while (or (string-match "^[ \t]*\\(re\\|fwd?\\)\\(\\[[0-9]*\\]\\)?:[ \t]*"
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
486 subject)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
487 (string-match "^[ \t]*\\[[^\\]][ \t]*" subject))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
488 (setq subject-pruned-flag t)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
489 (setq subject (substring subject (match-end 0))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
490 ;; Prune subject trailer
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
491 (while (or (string-match "(fwd)$" subject)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
492 (string-match "[ \t]+$" subject))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
493 (setq subject-pruned-flag t)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
494 (setq subject (substring subject 0 (match-beginning 0))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
495 ;; Canonicalize subject only if it is non-empty
102537
6837adfb2772 m-v: use lists to pass things around rather than values.
Deepak Goel <deego@gnufans.org>
parents: 101484
diff changeset
496 (cond ((equal subject "") (list subject subject-pruned-flag))
6837adfb2772 m-v: use lists to pass things around rather than values.
Deepak Goel <deego@gnufans.org>
parents: 101484
diff changeset
497 (t (list
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
498 (or (gethash subject mh-thread-subject-hash)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
499 (setf (gethash subject mh-thread-subject-hash) subject))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
500 subject-pruned-flag)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
501
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
502 (defsubst mh-thread-group-by-subject (roots)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
503 "Group the set of message containers, ROOTS based on subject.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
504 Bug: Check for and make sure that something without Re: is made
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
505 the parent in preference to something that has it."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
506 (clrhash mh-thread-subject-container-hash)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
507 (let ((results ()))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
508 (dolist (root roots)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
509 (let* ((subject (mh-thread-container-subject root))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
510 (parent (gethash subject mh-thread-subject-container-hash)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
511 (cond (parent (mh-thread-remove-parent-link root)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
512 (mh-thread-add-link parent root t)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
513 (setf (mh-container-real-child-p root) nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
514 (push `(SUBJECT ,root) mh-thread-history))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
515 (t
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
516 (setf (gethash subject mh-thread-subject-container-hash) root)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
517 (push root results)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
518 (nreverse results)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
519
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
520 (defun mh-thread-container-subject (container)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
521 "Return the subject of CONTAINER.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
522 If CONTAINER is empty return the subject info of one of its
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
523 children."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
524 (cond ((and (mh-container-message container)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
525 (mh-message-id (mh-container-message container)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
526 (mh-message-subject (mh-container-message container)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
527 (t (block nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
528 (dolist (kid (mh-container-children container))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
529 (when (and (mh-container-message kid)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
530 (mh-message-id (mh-container-message kid)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
531 (let ((kid-message (mh-container-message kid)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
532 (return (mh-message-subject kid-message)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
533 (error "This can't happen")))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
534
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
535 (defsubst mh-thread-update-id-index-maps (id index)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
536 "Message with id, ID is the message in INDEX.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
537 The function also checks for duplicate messages (that is multiple
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
538 messages with the same ID). These messages are put in the
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
539 `mh-thread-duplicates' hash table."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
540 (let ((old-index (gethash id mh-thread-id-index-map)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
541 (when old-index (push old-index (gethash id mh-thread-duplicates)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
542 (setf (gethash id mh-thread-id-index-map) index)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
543 (setf (gethash index mh-thread-index-id-map) id)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
544
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
545 (defsubst mh-thread-get-message-container (message)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
546 "Return container which has MESSAGE in it.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
547 If there is no container present then a new container is
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
548 allocated."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
549 (let* ((id (mh-message-id message))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
550 (container (gethash id mh-thread-id-table)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
551 (cond (container (setf (mh-container-message container) message)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
552 container)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
553 (t (setf (gethash id mh-thread-id-table)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
554 (mh-thread-make-container :message message))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
555
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
556 (defsubst mh-thread-get-message (id subject-re-p subject refs)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
557 "Return appropriate message.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
558 Otherwise update message already present to have the proper ID,
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
559 SUBJECT-RE-P, SUBJECT and REFS fields."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
560 (let* ((container (gethash id mh-thread-id-table))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
561 (message (if container (mh-container-message container) nil)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
562 (cond (message
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
563 (setf (mh-message-subject-re-p message) subject-re-p)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
564 (setf (mh-message-subject message) subject)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
565 (setf (mh-message-id message) id)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
566 (setf (mh-message-references message) refs)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
567 message)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
568 (container
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
569 (setf (mh-container-message container)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
570 (mh-thread-make-message :id id :references refs
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
571 :subject subject
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
572 :subject-re-p subject-re-p)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
573 (t (let ((message (mh-thread-make-message :id id :references refs
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
574 :subject-re-p subject-re-p
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
575 :subject subject)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
576 (prog1 message
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
577 (mh-thread-get-message-container message)))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
578
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
579 (defvar mh-message-id-regexp "^<.*@.*>$"
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
580 "Regexp to recognize whether a string is a message identifier.")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
581
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
582 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
583 (defun mh-thread-generate (folder msg-list)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
584 "Scan FOLDER to get info for threading.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
585 Only information about messages in MSG-LIST are added to the tree."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
586 (with-temp-buffer
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
587 (mh-thread-set-tables folder)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
588 (when msg-list
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
589 (apply
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
590 #'call-process (expand-file-name mh-scan-prog mh-progs) nil '(t nil) nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
591 "-width" "10000" "-format"
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
592 "%(msg)\n%{message-id}\n%{references}\n%{in-reply-to}\n%{subject}\n"
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
593 folder (mapcar #'(lambda (x) (format "%s" x)) msg-list)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
594 (goto-char (point-min))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
595 (let ((roots ())
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
596 (case-fold-search t))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
597 (block nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
598 (while (not (eobp))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
599 (block process-message
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
600 (let* ((index-line
68529
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
601 (prog1 (buffer-substring (point) (mh-line-end-position))
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
602 (forward-line)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
603 (index (string-to-number index-line))
68529
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
604 (id (prog1 (buffer-substring (point) (mh-line-end-position))
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
605 (forward-line)))
68529
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
606 (refs (prog1
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
607 (buffer-substring (point) (mh-line-end-position))
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
608 (forward-line)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
609 (in-reply-to (prog1 (buffer-substring (point)
68529
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
610 (mh-line-end-position))
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
611 (forward-line)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
612 (subject (prog1
68529
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
613 (buffer-substring
7daec5f4a289 * mh-alias.el (mh-alias-gecos-name): Use mh-replace-regexp-in-string
Bill Wohler <wohler@newt.com>
parents: 68470
diff changeset
614 (point) (mh-line-end-position))
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
615 (forward-line)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
616 (subject-re-p nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
617 (unless (gethash index mh-thread-scan-line-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
618 (return-from process-message))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
619 (unless (integerp index) (return)) ;Error message here
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
620 (multiple-value-setq (subject subject-re-p)
102537
6837adfb2772 m-v: use lists to pass things around rather than values.
Deepak Goel <deego@gnufans.org>
parents: 101484
diff changeset
621 (values-list (mh-thread-prune-subject subject)))
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
622 (setq in-reply-to (mh-thread-process-in-reply-to in-reply-to))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
623 (setq refs (loop for x in (append (split-string refs) in-reply-to)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
624 when (string-match mh-message-id-regexp x)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
625 collect x))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
626 (setq id (mh-thread-canonicalize-id id))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
627 (mh-thread-update-id-index-maps id index)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
628 (setq refs (mapcar #'mh-thread-canonicalize-id refs))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
629 (mh-thread-get-message id subject-re-p subject refs)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
630 (do ((ancestors refs (cdr ancestors)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
631 ((null (cdr ancestors))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
632 (when (car ancestors)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
633 (mh-thread-remove-parent-link id)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
634 (mh-thread-add-link (car ancestors) id)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
635 (mh-thread-add-link (car ancestors) (cadr ancestors)))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
636 (maphash #'(lambda (k v)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
637 (declare (ignore k))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
638 (when (null (mh-container-parent v))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
639 (push v roots)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
640 mh-thread-id-table)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
641 (setq roots (mh-thread-prune-containers roots))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
642 (prog1 (setq roots (mh-thread-group-by-subject roots))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
643 (let ((history mh-thread-history))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
644 (set-buffer folder)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
645 (setq mh-thread-history history))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
646
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
647 (defun mh-thread-set-tables (folder)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
648 "Use the tables of FOLDER in current buffer."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
649 (flet ((mh-get-table (symbol)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
650 (save-excursion
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
651 (set-buffer folder)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
652 (symbol-value symbol))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
653 (setq mh-thread-id-hash (mh-get-table 'mh-thread-id-hash))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
654 (setq mh-thread-subject-hash (mh-get-table 'mh-thread-subject-hash))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
655 (setq mh-thread-id-table (mh-get-table 'mh-thread-id-table))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
656 (setq mh-thread-id-index-map (mh-get-table 'mh-thread-id-index-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
657 (setq mh-thread-index-id-map (mh-get-table 'mh-thread-index-id-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
658 (setq mh-thread-scan-line-map (mh-get-table 'mh-thread-scan-line-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
659 (setq mh-thread-subject-container-hash
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
660 (mh-get-table 'mh-thread-subject-container-hash))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
661 (setq mh-thread-duplicates (mh-get-table 'mh-thread-duplicates))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
662 (setq mh-thread-history (mh-get-table 'mh-thread-history))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
663
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
664 (defun mh-thread-process-in-reply-to (reply-to-header)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
665 "Extract message id's from REPLY-TO-HEADER.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
666 Ideally this should have some regexp which will try to guess if a
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
667 string between < and > is a message id and not an email address.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
668 For now it will take the last string inside angles."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
669 (let ((end (mh-search-from-end ?> reply-to-header)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
670 (when (numberp end)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
671 (let ((begin (mh-search-from-end ?< (substring reply-to-header 0 end))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
672 (when (numberp begin)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
673 (list (substring reply-to-header begin (1+ end))))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
674
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
675 (defun mh-thread-prune-containers (roots)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
676 "Prune empty containers in the containers ROOTS."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
677 (let ((dfs-ordered-nodes ())
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
678 (work-list roots))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
679 (while work-list
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
680 (let ((node (pop work-list)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
681 (dolist (child (mh-container-children node))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
682 (push child work-list))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
683 (push node dfs-ordered-nodes)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
684 (while dfs-ordered-nodes
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
685 (let ((node (pop dfs-ordered-nodes)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
686 (cond ((gethash (mh-message-id (mh-container-message node))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
687 mh-thread-id-index-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
688 ;; Keep it
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
689 (setf (mh-container-children node)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
690 (mh-thread-sort-containers (mh-container-children node))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
691 ((and (mh-container-children node)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
692 (or (null (cdr (mh-container-children node)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
693 (mh-container-parent node)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
694 ;; Promote kids
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
695 (let ((children ()))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
696 (dolist (kid (mh-container-children node))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
697 (mh-thread-remove-parent-link kid)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
698 (mh-thread-add-link (mh-container-parent node) kid)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
699 (push kid children))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
700 (push `(PROMOTE ,node ,(mh-container-parent node) ,@children)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
701 mh-thread-history)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
702 (mh-thread-remove-parent-link node)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
703 ((mh-container-children node)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
704 ;; Promote the first orphan to parent and add the other kids as
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
705 ;; his children
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
706 (setf (mh-container-children node)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
707 (mh-thread-sort-containers (mh-container-children node)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
708 (let ((new-parent (car (mh-container-children node)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
709 (other-kids (cdr (mh-container-children node))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
710 (mh-thread-remove-parent-link new-parent)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
711 (dolist (kid other-kids)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
712 (mh-thread-remove-parent-link kid)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
713 (setf (mh-container-real-child-p kid) nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
714 (mh-thread-add-link new-parent kid t))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
715 (push `(PROMOTE ,node ,(mh-container-parent node)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
716 ,new-parent ,@other-kids)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
717 mh-thread-history)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
718 (mh-thread-remove-parent-link node)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
719 (t
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
720 ;; Drop it
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
721 (push `(DROP ,node ,(mh-container-parent node))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
722 mh-thread-history)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
723 (mh-thread-remove-parent-link node)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
724 (let ((results ()))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
725 (maphash #'(lambda (k v)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
726 (declare (ignore k))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
727 (when (and (null (mh-container-parent v))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
728 (gethash (mh-message-id (mh-container-message v))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
729 mh-thread-id-index-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
730 (push v results)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
731 mh-thread-id-table)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
732 (mh-thread-sort-containers results))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
733
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
734 (defun mh-thread-sort-containers (containers)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
735 "Sort a list of message CONTAINERS to be in ascending order wrt index."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
736 (sort containers
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
737 #'(lambda (x y)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
738 (when (and (mh-container-message x) (mh-container-message y))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
739 (let* ((id-x (mh-message-id (mh-container-message x)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
740 (id-y (mh-message-id (mh-container-message y)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
741 (index-x (gethash id-x mh-thread-id-index-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
742 (index-y (gethash id-y mh-thread-id-index-map)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
743 (and (integerp index-x) (integerp index-y)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
744 (< index-x index-y)))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
745
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
746 (defvar mh-thread-last-ancestor)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
747
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
748 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
749 (defun mh-thread-print-scan-lines (thread-tree)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
750 "Print scan lines in THREAD-TREE in threaded mode."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
751 (let ((mh-thread-body-width (- (window-width) mh-cmd-note
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
752 (1- mh-scan-field-subject-start-offset)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
753 (mh-thread-last-ancestor nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
754 (if (null mh-index-data)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
755 (mh-thread-generate-scan-lines thread-tree -2)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
756 (loop for x in (mh-index-group-by-folder)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
757 do (let* ((old-map mh-thread-scan-line-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
758 (mh-thread-scan-line-map (make-hash-table)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
759 (setq mh-thread-last-ancestor nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
760 (loop for msg in (cdr x)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
761 do (let ((v (gethash msg old-map)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
762 (when v
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
763 (setf (gethash msg mh-thread-scan-line-map) v))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
764 (when (> (hash-table-count mh-thread-scan-line-map) 0)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
765 (insert (if (bobp) "" "\n") (car x) "\n")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
766 (mh-thread-generate-scan-lines thread-tree -2))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
767 (mh-index-create-imenu-index))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
768
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
769 (defun mh-thread-generate-scan-lines (tree level)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
770 "Generate scan lines.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
771 TREE is the hierarchical tree of messages, SCAN-LINE-MAP maps
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
772 message indices to the corresponding scan lines and LEVEL used to
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
773 determine indentation of the message."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
774 (cond ((null tree) nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
775 ((mh-thread-container-p tree)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
776 (let* ((message (mh-container-message tree))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
777 (id (mh-message-id message))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
778 (index (gethash id mh-thread-id-index-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
779 (duplicates (gethash id mh-thread-duplicates))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
780 (new-level (+ level 2))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
781 (dupl-flag t)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
782 (force-angle-flag nil)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
783 (increment-level-flag nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
784 (dolist (scan-line (mapcar (lambda (x)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
785 (gethash x mh-thread-scan-line-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
786 (reverse (cons index duplicates))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
787 (when scan-line
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
788 (when (and dupl-flag (equal level 0)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
789 (mh-thread-ancestor-p mh-thread-last-ancestor tree))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
790 (setq level (+ level 2)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
791 new-level (+ new-level 2)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
792 force-angle-flag t))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
793 (when (equal level 0)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
794 (setq mh-thread-last-ancestor tree)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
795 (while (mh-container-parent mh-thread-last-ancestor)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
796 (setq mh-thread-last-ancestor
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
797 (mh-container-parent mh-thread-last-ancestor))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
798 (let* ((lev (if dupl-flag level new-level))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
799 (square-flag (or (and (mh-container-real-child-p tree)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
800 (not force-angle-flag)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
801 dupl-flag)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
802 (equal lev 0))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
803 (insert (car scan-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
804 (format (format "%%%ss" lev) "")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
805 (if square-flag "[" "<")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
806 (cadr scan-line)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
807 (if square-flag "]" ">")
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
808 (truncate-string-to-width
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
809 (caddr scan-line) (- mh-thread-body-width lev))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
810 "\n"))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
811 (setq increment-level-flag t)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
812 (setq dupl-flag nil)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
813 (unless increment-level-flag (setq new-level level))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
814 (dolist (child (mh-container-children tree))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
815 (mh-thread-generate-scan-lines child new-level))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
816 (t (let ((nlevel (+ level 2)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
817 (dolist (ch tree)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
818 (mh-thread-generate-scan-lines ch nlevel))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
819
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
820
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
821
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
822 ;;; Additional Utilities
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
823
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
824 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
825 (defun mh-thread-update-scan-line-map (msg notation offset)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
826 "In threaded view update `mh-thread-scan-line-map'.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
827 MSG is the message being notated with NOTATION at OFFSET."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
828 (let* ((msg (or msg (mh-get-msg-num nil)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
829 (cur-scan-line (and mh-thread-scan-line-map
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
830 (gethash msg mh-thread-scan-line-map)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
831 (old-scan-lines (loop for map in mh-thread-scan-line-map-stack
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
832 collect (and map (gethash msg map)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
833 (when cur-scan-line
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
834 (setf (aref (car cur-scan-line) offset) notation))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
835 (dolist (line old-scan-lines)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
836 (when line (setf (aref (car line) offset) notation)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
837
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
838 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
839 (defun mh-thread-find-msg-subject (msg)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
840 "Find canonicalized subject of MSG.
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
841 This function can only be used the folder is threaded."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
842 (ignore-errors
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
843 (mh-message-subject
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
844 (mh-container-message (gethash (gethash msg mh-thread-index-id-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
845 mh-thread-id-table)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
846
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
847 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
848 (defun mh-thread-add-spaces (count)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
849 "Add COUNT spaces to each scan line in `mh-thread-scan-line-map'."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
850 (let ((spaces (format (format "%%%ss" count) "")))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
851 (while (not (eobp))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
852 (let* ((msg-num (mh-get-msg-num nil))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
853 (old-line (nth 3 (gethash msg-num mh-thread-scan-line-map))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
854 (when (numberp msg-num)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
855 (setf (gethash msg-num mh-thread-scan-line-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
856 (mh-thread-parse-scan-line (format "%s%s" spaces old-line)))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
857 (forward-line 1))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
858
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
859 ;;;###mh-autoload
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
860 (defun mh-thread-forget-message (index)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
861 "Forget the message INDEX from the threading tables."
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
862 (let* ((id (gethash index mh-thread-index-id-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
863 (id-index (gethash id mh-thread-id-index-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
864 (duplicates (gethash id mh-thread-duplicates)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
865 (remhash index mh-thread-index-id-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
866 (remhash index mh-thread-scan-line-map)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
867 (cond ((and (eql index id-index) (null duplicates))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
868 (remhash id mh-thread-id-index-map))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
869 ((eql index id-index)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
870 (setf (gethash id mh-thread-id-index-map) (car duplicates))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
871 (setf (gethash (car duplicates) mh-thread-index-id-map) id)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
872 (setf (gethash id mh-thread-duplicates) (cdr duplicates)))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
873 (t
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
874 (setf (gethash id mh-thread-duplicates)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
875 (remove index duplicates))))))
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
876
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
877 (provide 'mh-thread)
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
878
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
879 ;; Local Variables:
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
880 ;; indent-tabs-mode: nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
881 ;; sentence-end-double-space: nil
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
882 ;; End:
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
883
68470
4bd450a8dbe2 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 68465
diff changeset
884 ;; arch-tag: b10e62f5-f028-4e04-873e-89d0e069b3d5
68465
37d03b3298bf The Great Cleanup
Bill Wohler <wohler@newt.com>
parents:
diff changeset
885 ;;; mh-thread.el ends here