1 ; This file holds functions that create and manipulate the cache of header
2 ; information for the various message files. It is explicitly loaded from
4 -------------------------------------------------------------------------
6 ; This function creates the header buffer that represents a message or
7 ; bboard directory. It associates several buffer-specific variables
8 ; with it: mh-buffer-filename, which is the actual Unix file name of the
9 ; directory; mh-folder-title, which is either the tail of the directory
10 ; name or the whole thing depending on whether it is in your mail path.
11 ; call: (&mh-read-folder "folder" "range" "pathname" "title")
13 (&mh-read-folder name rnge title
14 (setq name (arg 1)) (setq rnge (arg 2))
15 (pop-to-buffer (concat "+" mh-folder))
16 (if buffer-is-modified
19 (switch-to-buffer (concat "+" name))
20 (setq backup-before-writing 0)
21 (setq wrap-long-lines 0)
22 (use-local-map "&mh-keymap")
23 (setq mode-string "mh-folder")
24 (if (= (buffer-size) 0)
26 (if (!= 0 (length mh-flist))
27 (setq mh-flist (concat mh-flist ",")))
28 (setq mh-flist (concat mh-flist name))
29 (setq mh-buffer-filename (arg 3))
30 (setq mh-folder-title (arg 4))
31 (use-local-map "&mh-keymap")
33 (read-file (concat mh-buffer-filename "/"
34 (current-buffer-name))))
36 (message "Header file missing; regenerating it...")
38 (&mh-regenerate-headers)
44 (if (looking-at "scan: "); UCI
45 ;UCI (looking-at "No messages ")
48 (message "Folder +" name " is empty.")
49 (message "No messages in +" name " range " rnge)
56 (setq mode-line-format
58 "Cmds: n p d ^ ! u t e m f i r g b x ? Exit:^X^C %M")
60 (&mh-check-folder-full)
64 (setq buffer-is-modified 0)
69 (&mh-check-folder-full lastmsg
71 (temp-use-buffer (concat "+" mh-folder))
75 (while (= (following-char) ' ') (forward-character))
78 (goto-character (+ (dot) 3))
79 (setq lastmsg (region-to-string))
83 (get-response (concat "Folder +" mh-folder " is >90%% full. May I pack it for you? ")
85 "Please answer y or n"))
91 (message "OK, but you should use the 'x-p' command to pack it soon.")
101 (&mh-unmark-all-headers 0)
102 (&mh-position-to-current)
104 (beginning-of-window)
111 (scroll-one-line-down)
122 (&mh-regenerate-headers
123 (setq mode-line-format " please wait for header regeneration...")
124 (message "scan +" mh-folder-title)
126 (erase-buffer) (set-mark)
127 (fast-filter-region (concat mh-progs "/scan +" mh-folder-title))
128 (write-named-file (concat mh-buffer-filename "/"
129 (&mh-header-file-name)))
130 (unlink-file (concat mh-buffer-filename "/++"))
132 (&mh-header-file-name
133 (if (!= (substr (current-buffer-name) 2 1) "/")
134 (current-buffer-name)
136 (setq x (current-buffer-name))
137 (temp-use-buffer "scratch")
138 (erase-buffer) (insert-string x)
139 (beginning-of-file) (set-mark)
141 (replace-string "/" ".")
149 ; Read in the ++ file that was generated by an external "inc", then erase.
151 (&mh-update-headers uhf
152 (setq uhf (concat mh-buffer-filename "/++"))
153 (if (file-exists uhf)
156 (temp-use-buffer "++")
158 (temp-use-buffer (concat "+" mh-folder))
162 (temp-use-buffer "++")
170 ; This function removes all "+" flags from the headers, and if it is called
171 ; with an argument of 1, removes all "D" and "^" flags too.
173 (&mh-unmark-all-headers
174 (temp-use-buffer (concat "+" mh-folder))
176 (while (! (error-occured
178 (re-search-forward "^...\\+")
179 (re-search-forward "^...\\D\\|^...\\^\\|^...\\+")
183 (delete-previous-character)
184 (insert-character ' ')
188 ; position the cursor to the current message.
189 (&mh-position-to-current curmsg curbuf curfil
190 (setq curbuf (current-buffer-name))
191 (setq curfil mh-buffer-filename)
192 (temp-use-buffer "mh-temp") (erase-buffer)
194 (insert-file (concat curfil "/cur")))
200 (setq curmsg (region-to-string))
203 (temp-use-buffer curbuf)
205 (if (= curmsg 0) (previous-line)
207 (while (< (length curmsg) 3)
208 (setq curmsg (concat " " curmsg)))
210 (re-search-reverse (concat "^" curmsg)))
211 (progn (end-of-file) (previous-line))
218 (goto-character (+ (dot) 3))
219 (delete-next-character)
220 (insert-character '+')
225 ; This function sets the "current message" (+ sign) to equal the number of
226 ; the message that the cursor is pointing to. I.e. it writes cur to stable
229 (save-window-excursion
230 (temp-use-buffer (concat "+" mh-folder))
231 (setq cm (&mh-get-msgnum))
232 (setq cf (concat mh-buffer-filename "/cur"))
233 (temp-use-buffer "mh-temp")
236 (write-named-file cf)
237 (delete-buffer "mh-temp")
241 ; write out the header buffer as a file in the current folder
242 (&mh-make-headers-current
243 (temp-use-buffer (concat "+" mh-folder))
246 (while (! (error-occured
247 (re-search-forward "^...\\D\\|^...\\^")))
249 (kill-to-end-of-line) (delete-next-character)
256 ; This function closes a folder, i.e. processes all of the pending deletes and
257 ; moves for it and edits the header buffer accordingly.
259 (temp-use-buffer "cmd-buffer") (beginning-of-file)
261 (re-search-forward (concat "^rmm +" mh-folder))
262 (beginning-of-line) (insert-string mh-progs "/")
263 (beginning-of-line) (set-mark)
264 (end-of-line) (delete-next-character)
265 (setq ts (region-to-string)) (erase-region)
271 (re-search-forward (concat "^filem -src +" mh-folder))
273 (beginning-of-line) (insert-string mh-progs "/")
274 (beginning-of-line) (set-mark)
275 (end-of-line) (delete-next-character)
276 (setq ts (region-to-string)) (erase-region)
279 (pop-to-buffer (concat "+" mh-folder))
280 (&mh-make-headers-current)
281 (&mh-unmark-all-headers)
282 (&mh-position-to-current)
284 ; This function applies "folder -pack" to the current folder, after first
285 ; closing it (see above)
287 (setq sm mode-line-format)
288 (setq mode-line-format " closing folder first...") (sit-for 0)
290 (setq mode-line-format " please wait for pack...") (sit-for 0)
291 (send-to-shell (concat mh-progs "/folder +" mh-folder " -pack"))
292 (&mh-regenerate-headers)
293 (setq mode-line-format sm)