Commit | Line | Data |
---|---|---|
dda00b2c BW |
1 | ;;; mh-folder.el --- MH-Folder mode |
2 | ||
3 | ;; Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Author: Bill Wohler <wohler@newt.com> | |
6 | ;; Maintainer: Bill Wohler <wohler@newt.com> | |
7 | ;; Keywords: mail | |
8 | ;; See: mh-e.el | |
9 | ||
10 | ;; This file is part of GNU Emacs. | |
11 | ||
12 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 | ;; it under the terms of the GNU General Public License as published by | |
14 | ;; the Free Software Foundation; either version 2, or (at your option) | |
15 | ;; any later version. | |
16 | ||
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
23 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
25 | ;; Boston, MA 02110-1301, USA. | |
26 | ||
27 | ;;; Commentary: | |
28 | ||
29 | ;; Mode for browsing folders | |
30 | ||
31 | ;;; Change Log: | |
32 | ||
33 | ;;; Code: | |
34 | ||
35 | (require 'mh-e) | |
36 | (require 'mh-scan) | |
37 | (mh-require-cl) | |
38 | ||
efc27af6 | 39 | ;; Dynamically-created functions not found in mh-loaddefs.el. |
dda00b2c | 40 | (autoload 'mh-tool-bar-folder-buttons-init "mh-tool-bar") |
efc27af6 | 41 | (autoload 'mh-tool-bar-init "mh-tool-bar") |
dda00b2c BW |
42 | |
43 | (require 'gnus-util) | |
44 | (autoload 'message-fetch-field "message") | |
45 | ||
46 | \f | |
47 | ||
48 | ;;; MH-E Entry Points | |
49 | ||
50 | ;;;###autoload | |
51 | (defun mh-rmail (&optional arg) | |
52 | "Incorporate new mail with MH. | |
53 | Scan an MH folder if ARG is non-nil. | |
54 | ||
55 | This function is an entry point to MH-E, the Emacs interface to | |
56 | the MH mail system." | |
57 | (interactive "P") | |
58 | (mh-find-path) | |
59 | (if arg | |
60 | (call-interactively 'mh-visit-folder) | |
61 | (unless (get-buffer mh-inbox) | |
62 | (mh-visit-folder mh-inbox (symbol-name mh-unseen-seq))) | |
63 | (mh-inc-folder))) | |
64 | ||
65 | ;;;###autoload | |
66 | (defun mh-nmail (&optional arg) | |
67 | "Check for new mail in inbox folder. | |
68 | Scan an MH folder if ARG is non-nil. | |
69 | ||
70 | This function is an entry point to MH-E, the Emacs interface to | |
71 | the MH mail system." | |
72 | (interactive "P") | |
73 | (mh-find-path) ; init mh-inbox | |
74 | (if arg | |
75 | (call-interactively 'mh-visit-folder) | |
76 | (mh-visit-folder mh-inbox))) | |
77 | \f | |
78 | ||
79 | ;;; Desktop Integration | |
80 | ||
81 | ;; desktop-buffer-mode-handlers appeared in Emacs 22. | |
82 | (if (fboundp 'desktop-buffer-mode-handlers) | |
83 | (add-to-list 'desktop-buffer-mode-handlers | |
84 | '(mh-folder-mode . mh-restore-desktop-buffer))) | |
85 | ||
86 | (defun mh-restore-desktop-buffer (desktop-buffer-file-name | |
87 | desktop-buffer-name | |
88 | desktop-buffer-misc) | |
89 | "Restore an MH folder buffer specified in a desktop file. | |
90 | When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the | |
91 | file name to visit, DESKTOP-BUFFER-NAME holds the desired buffer | |
92 | name, and DESKTOP-BUFFER-MISC holds a list of miscellaneous info | |
93 | used by the `desktop-buffer-handlers' functions." | |
94 | (mh-find-path) | |
95 | (mh-visit-folder desktop-buffer-name) | |
96 | (current-buffer)) | |
97 | ||
98 | \f | |
99 | ||
100 | ;;; Variables | |
101 | ||
102 | (defvar mh-folder-filename nil | |
103 | "Full path of directory for this folder.") | |
104 | ||
105 | (defvar mh-partial-folder-mode-line-annotation "select" | |
106 | "Annotation when displaying part of a folder. | |
107 | The string is displayed after the folder's name. nil for no | |
108 | annotation.") | |
109 | ||
110 | (defvar mh-last-destination nil | |
111 | "Destination of last refile or write command.") | |
112 | ||
113 | (defvar mh-last-destination-folder nil | |
114 | "Destination of last refile command.") | |
115 | ||
116 | (defvar mh-last-destination-write nil | |
117 | "Destination of last write command.") | |
118 | ||
119 | (defvar mh-first-msg-num nil | |
120 | "Number of first message in buffer.") | |
121 | ||
122 | (defvar mh-last-msg-num nil | |
123 | "Number of last msg in buffer.") | |
124 | ||
125 | (defvar mh-msg-count nil | |
126 | "Number of msgs in buffer.") | |
127 | ||
128 | \f | |
129 | ||
130 | ;;; Sequence Menu | |
131 | ||
132 | (easy-menu-define | |
133 | mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence." | |
134 | '("Sequence" | |
135 | ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)] | |
136 | ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)] | |
137 | ["Delete Message from Sequence..." mh-delete-msg-from-seq | |
138 | (mh-get-msg-num nil)] | |
139 | ["List Sequences in Folder..." mh-list-sequences t] | |
140 | ["Delete Sequence..." mh-delete-seq t] | |
141 | ["Narrow to Sequence..." mh-narrow-to-seq t] | |
142 | ["Widen from Sequence" mh-widen mh-folder-view-stack] | |
143 | "--" | |
144 | ["Narrow to Subject Sequence" mh-narrow-to-subject t] | |
145 | ["Narrow to Tick Sequence" mh-narrow-to-tick | |
146 | (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))] | |
147 | ["Delete Rest of Same Subject" mh-delete-subject t] | |
148 | ["Toggle Tick Mark" mh-toggle-tick t] | |
149 | "--" | |
150 | ["Push State Out to MH" mh-update-sequences t])) | |
151 | ||
152 | ;;; Message Menu | |
153 | ||
154 | (easy-menu-define | |
155 | mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message." | |
156 | '("Message" | |
157 | ["Show Message" mh-show (mh-get-msg-num nil)] | |
158 | ["Show Message with Header" mh-header-display (mh-get-msg-num nil)] | |
159 | ["Next Message" mh-next-undeleted-msg t] | |
160 | ["Previous Message" mh-previous-undeleted-msg t] | |
161 | ["Go to First Message" mh-first-msg t] | |
162 | ["Go to Last Message" mh-last-msg t] | |
163 | ["Go to Message by Number..." mh-goto-msg t] | |
164 | ["Modify Message" mh-modify t] | |
165 | ["Delete Message" mh-delete-msg (mh-get-msg-num nil)] | |
166 | ["Refile Message" mh-refile-msg (mh-get-msg-num nil)] | |
167 | ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)] | |
168 | ["Execute Delete/Refile" mh-execute-commands | |
169 | (mh-outstanding-commands-p)] | |
170 | "--" | |
171 | ["Compose a New Message" mh-send t] | |
172 | ["Reply to Message..." mh-reply (mh-get-msg-num nil)] | |
173 | ["Forward Message..." mh-forward (mh-get-msg-num nil)] | |
174 | ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)] | |
175 | ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)] | |
176 | ["Re-edit a Bounced Message" mh-extract-rejected-mail t] | |
177 | "--" | |
178 | ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)] | |
179 | ["Print Message" mh-print-msg (mh-get-msg-num nil)] | |
180 | ["Write Message to File..." mh-write-msg-to-file | |
181 | (mh-get-msg-num nil)] | |
182 | ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)] | |
183 | ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)] | |
184 | ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)])) | |
185 | ||
186 | ;;; Folder Menu | |
187 | ||
188 | (easy-menu-define | |
189 | mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder." | |
190 | '("Folder" | |
191 | ["Incorporate New Mail" mh-inc-folder t] | |
192 | ["Toggle Show/Folder" mh-toggle-showing t] | |
193 | ["Execute Delete/Refile" mh-execute-commands | |
194 | (mh-outstanding-commands-p)] | |
195 | ["Rescan Folder" mh-rescan-folder t] | |
196 | ["Thread Folder" mh-toggle-threads | |
197 | (not (memq 'unthread mh-view-ops))] | |
198 | ["Pack Folder" mh-pack-folder t] | |
199 | ["Sort Folder" mh-sort-folder t] | |
200 | "--" | |
201 | ["List Folders" mh-list-folders t] | |
202 | ["Visit a Folder..." mh-visit-folder t] | |
203 | ["View New Messages" mh-index-new-messages t] | |
204 | ["Search..." mh-search t] | |
205 | "--" | |
206 | ["Quit MH-E" mh-quit t])) | |
207 | ||
208 | \f | |
209 | ||
210 | ;;; MH-Folder Keys | |
211 | ||
212 | (suppress-keymap mh-folder-mode-map) | |
213 | ||
214 | ;; Use defalias to make sure the documented primary key bindings | |
215 | ;; appear in menu lists. | |
216 | (defalias 'mh-alt-show 'mh-show) | |
217 | (defalias 'mh-alt-refile-msg 'mh-refile-msg) | |
218 | (defalias 'mh-alt-send 'mh-send) | |
219 | (defalias 'mh-alt-visit-folder 'mh-visit-folder) | |
220 | ||
221 | ;; Save the "b" binding for a future `back'. Maybe? | |
222 | (gnus-define-keys mh-folder-mode-map | |
223 | " " mh-page-msg | |
224 | "!" mh-refile-or-write-again | |
225 | "'" mh-toggle-tick | |
226 | "," mh-header-display | |
227 | "." mh-alt-show | |
228 | ";" mh-toggle-mh-decode-mime-flag | |
229 | ">" mh-write-msg-to-file | |
230 | "?" mh-help | |
231 | "E" mh-extract-rejected-mail | |
232 | "M" mh-modify | |
233 | "\177" mh-previous-page | |
234 | "\C-d" mh-delete-msg-no-motion | |
235 | "\t" mh-index-next-folder | |
236 | [backtab] mh-index-previous-folder | |
237 | "\M-\t" mh-index-previous-folder | |
238 | "\e<" mh-first-msg | |
239 | "\e>" mh-last-msg | |
240 | "\ed" mh-redistribute | |
241 | "\r" mh-show | |
242 | "^" mh-alt-refile-msg | |
243 | "c" mh-copy-msg | |
244 | "d" mh-delete-msg | |
245 | "e" mh-edit-again | |
246 | "f" mh-forward | |
247 | "g" mh-goto-msg | |
248 | "i" mh-inc-folder | |
249 | "k" mh-delete-subject-or-thread | |
250 | "m" mh-alt-send | |
251 | "n" mh-next-undeleted-msg | |
252 | "\M-n" mh-next-unread-msg | |
253 | "o" mh-refile-msg | |
254 | "p" mh-previous-undeleted-msg | |
255 | "\M-p" mh-previous-unread-msg | |
256 | "q" mh-quit | |
257 | "r" mh-reply | |
258 | "s" mh-send | |
259 | "t" mh-toggle-showing | |
260 | "u" mh-undo | |
261 | "v" mh-index-visit-folder | |
262 | "x" mh-execute-commands | |
263 | "|" mh-pipe-msg) | |
264 | ||
265 | (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map) | |
266 | "?" mh-prefix-help | |
267 | "'" mh-index-ticked-messages | |
268 | "S" mh-sort-folder | |
269 | "c" mh-catchup | |
270 | "f" mh-alt-visit-folder | |
271 | "k" mh-kill-folder | |
272 | "l" mh-list-folders | |
273 | "n" mh-index-new-messages | |
274 | "o" mh-alt-visit-folder | |
275 | "p" mh-pack-folder | |
276 | "q" mh-index-sequenced-messages | |
277 | "r" mh-rescan-folder | |
278 | "s" mh-search | |
279 | "u" mh-undo-folder | |
280 | "v" mh-visit-folder) | |
281 | ||
282 | (define-key mh-folder-mode-map "I" mh-inc-spool-map) | |
283 | ||
284 | (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map) | |
285 | "?" mh-prefix-help | |
286 | "b" mh-junk-blacklist | |
287 | "w" mh-junk-whitelist) | |
288 | ||
289 | (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map) | |
290 | "?" mh-prefix-help | |
291 | "C" mh-ps-print-toggle-color | |
292 | "F" mh-ps-print-toggle-faces | |
293 | "f" mh-ps-print-msg-file | |
294 | "l" mh-print-msg | |
295 | "p" mh-ps-print-msg) | |
296 | ||
297 | (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map) | |
298 | "'" mh-narrow-to-tick | |
299 | "?" mh-prefix-help | |
300 | "d" mh-delete-msg-from-seq | |
301 | "k" mh-delete-seq | |
302 | "l" mh-list-sequences | |
303 | "n" mh-narrow-to-seq | |
304 | "p" mh-put-msg-in-seq | |
305 | "s" mh-msg-is-in-seq | |
306 | "w" mh-widen) | |
307 | ||
308 | (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map) | |
309 | "?" mh-prefix-help | |
310 | "u" mh-thread-ancestor | |
311 | "p" mh-thread-previous-sibling | |
312 | "n" mh-thread-next-sibling | |
313 | "t" mh-toggle-threads | |
314 | "d" mh-thread-delete | |
315 | "o" mh-thread-refile) | |
316 | ||
317 | (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map) | |
318 | "'" mh-narrow-to-tick | |
319 | "?" mh-prefix-help | |
320 | "c" mh-narrow-to-cc | |
321 | "g" mh-narrow-to-range | |
322 | "m" mh-narrow-to-from | |
323 | "s" mh-narrow-to-subject | |
324 | "t" mh-narrow-to-to | |
325 | "w" mh-widen) | |
326 | ||
327 | (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map) | |
328 | "?" mh-prefix-help | |
329 | "s" mh-store-msg ;shar | |
330 | "u" mh-store-msg) ;uuencode | |
331 | ||
332 | (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map) | |
333 | " " mh-page-digest | |
334 | "?" mh-prefix-help | |
335 | "\177" mh-page-digest-backwards | |
336 | "b" mh-burst-digest) | |
337 | ||
338 | (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map) | |
339 | "?" mh-prefix-help | |
340 | "a" mh-mime-save-parts | |
341 | "e" mh-display-with-external-viewer | |
342 | "i" mh-folder-inline-mime-part | |
343 | "o" mh-folder-save-mime-part | |
344 | "t" mh-toggle-mime-buttons | |
345 | "v" mh-folder-toggle-mime-part | |
346 | "\t" mh-next-button | |
347 | [backtab] mh-prev-button | |
348 | "\M-\t" mh-prev-button) | |
349 | ||
350 | (cond | |
351 | (mh-xemacs-flag | |
352 | (define-key mh-folder-mode-map [button2] 'mh-show-mouse)) | |
353 | (t | |
354 | (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse))) | |
355 | ||
356 | ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt | |
357 | ||
358 | \f | |
359 | ||
360 | ;;; MH-Folder Help Messages | |
361 | ||
362 | ;; If you add a new prefix, add appropriate text to the nil key. | |
363 | ||
364 | ;; In general, messages are grouped logically. Taking the main commands for | |
365 | ;; example, the first line is "ways to view messages," the second line is | |
366 | ;; "things you can do with messages", and the third is "composing" messages. | |
367 | ||
368 | ;; When adding a new prefix, ensure that the help message contains "what" the | |
369 | ;; prefix is for. For example, if the word "folder" were not present in the | |
370 | ;; "F" entry, it would not be clear what these commands operated upon. | |
371 | (defvar mh-folder-mode-help-messages | |
372 | '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n" | |
373 | "[d]elete, [o]refile, e[x]ecute,\n" | |
374 | "[s]end, [r]eply,\n" | |
375 | "[;]toggle MIME decoding.\n" | |
376 | "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys," | |
377 | "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.") | |
378 | ||
379 | (?F "[l]ist; [v]isit folder;\n" | |
380 | "[n]ew messages; [']ticked messages; [s]earch;\n" | |
381 | "[p]ack; [S]ort; [r]escan; [k]ill") | |
382 | (?P "[p]rint message to [f]ile; old-style [l]pr printing;\n" | |
383 | "Toggle printing of [C]olors, [F]aces") | |
384 | (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n" | |
385 | "[s]equences, [l]ist,\n" | |
386 | "[d]elete message from sequence, [k]ill sequence") | |
387 | (?T "[t]oggle, [d]elete, [o]refile thread") | |
388 | (?/ "Limit to [c]c, ran[g]e, fro[m], [s]ubject, [t]o; [w]iden") | |
389 | (?X "un[s]har, [u]udecode message") | |
390 | (?D "[b]urst digest") | |
391 | (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n" | |
392 | "[TAB] next; [SHIFT-TAB] previous") | |
393 | (?J "[b]lacklist, [w]hitelist message")) | |
394 | "Key binding cheat sheet. | |
395 | See `mh-set-help'.") | |
396 | ||
397 | \f | |
398 | ||
399 | ;;; MH-Folder Font Lock | |
400 | ||
401 | (defvar mh-folder-font-lock-keywords | |
402 | (list | |
403 | ;; Folders when displaying index buffer | |
404 | (list "^\\+.*" | |
405 | '(0 'mh-search-folder)) | |
406 | ;; Marked for deletion | |
407 | (list (concat mh-scan-deleted-msg-regexp ".*") | |
408 | '(0 'mh-folder-deleted)) | |
409 | ;; Marked for refile | |
410 | (list (concat mh-scan-refiled-msg-regexp ".*") | |
411 | '(0 'mh-folder-refiled)) | |
412 | ;; After subject | |
413 | (list mh-scan-body-regexp | |
414 | '(1 'mh-folder-body nil t)) | |
415 | ;; Subject | |
416 | '(mh-folder-font-lock-subject | |
417 | (1 'mh-folder-followup append t) | |
418 | (2 'mh-folder-subject append t)) | |
419 | ;; Current message number | |
420 | (list mh-scan-cur-msg-number-regexp | |
421 | '(1 'mh-folder-cur-msg-number)) | |
422 | ;; Message number | |
423 | (list mh-scan-good-msg-regexp | |
424 | '(1 'mh-folder-msg-number)) | |
425 | ;; Date | |
426 | (list mh-scan-date-regexp | |
427 | '(1 'mh-folder-date)) | |
428 | ;; Messages from me (To:) | |
429 | (list mh-scan-rcpt-regexp | |
430 | '(1 'mh-folder-to) | |
431 | '(2 'mh-folder-address)) | |
432 | ;; Messages to me | |
433 | (list mh-scan-sent-to-me-sender-regexp | |
434 | '(1 'mh-folder-sent-to-me-hint) | |
435 | '(2 'mh-folder-sent-to-me-sender))) | |
436 | "Keywords (regular expressions) used to fontify the MH-Folder buffer.") | |
437 | ||
438 | (defun mh-folder-font-lock-subject (limit) | |
439 | "Return MH-E scan subject strings to font-lock between point and LIMIT." | |
440 | (if (not (re-search-forward mh-scan-subject-regexp limit t)) | |
441 | nil | |
442 | (if (match-beginning 1) | |
443 | (set-match-data (list (match-beginning 1) (match-end 3) | |
444 | (match-beginning 1) (match-end 3) nil nil)) | |
445 | (set-match-data (list (match-beginning 3) (match-end 3) | |
446 | nil nil (match-beginning 3) (match-end 3)))) | |
447 | t)) | |
448 | ||
449 | ;; Fontify unseen messages in bold. | |
450 | ||
451 | (defmacro mh-generate-sequence-font-lock (seq prefix face) | |
452 | "Generate the appropriate code to fontify messages in SEQ. | |
453 | PREFIX is used to generate unique names for the variables and | |
454 | functions defined by the macro. So a different prefix should be | |
455 | provided for every invocation. | |
456 | FACE is the font-lock face used to display the matching scan lines." | |
457 | (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix))) | |
458 | (func (intern (format "mh-folder-font-lock-%s" prefix)))) | |
459 | `(progn | |
460 | (defvar ,cache nil | |
461 | "Internal cache variable used for font-lock in MH-E. | |
462 | Should only be non-nil through font-lock stepping, and nil once | |
463 | font-lock is done highlighting.") | |
464 | (make-variable-buffer-local ',cache) | |
465 | ||
466 | (defun ,func (limit) | |
467 | "Return unseen message lines to font-lock between point and LIMIT." | |
468 | (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq)))) | |
469 | (let ((cur-msg (mh-get-msg-num nil))) | |
470 | (cond ((not ,cache) | |
471 | nil) | |
472 | ((>= (point) limit) ;Presumably at end of buffer | |
473 | (setq ,cache nil) | |
474 | nil) | |
475 | ((member cur-msg ,cache) | |
476 | (let ((bpoint (progn (beginning-of-line)(point))) | |
477 | (epoint (progn (forward-line 1)(point)))) | |
478 | (if (<= limit (point)) (setq ,cache nil)) | |
479 | (set-match-data (list bpoint epoint bpoint epoint)) | |
480 | t)) | |
481 | (t | |
482 | ;; move forward one line at a time, checking each message | |
483 | (while (and (= 0 (forward-line 1)) | |
484 | (> limit (point)) | |
485 | (not (member (mh-get-msg-num nil) ,cache)))) | |
486 | ;; Examine how we must have exited the loop... | |
487 | (let ((cur-msg (mh-get-msg-num nil))) | |
488 | (cond ((or (<= limit (point)) | |
489 | (not (member cur-msg ,cache))) | |
490 | (setq ,cache nil) | |
491 | nil) | |
492 | ((member cur-msg ,cache) | |
493 | (let ((bpoint (progn (beginning-of-line) (point))) | |
494 | (epoint (progn (forward-line 1) (point)))) | |
495 | (if (<= limit (point)) (setq ,cache nil)) | |
496 | (set-match-data | |
497 | (list bpoint epoint bpoint epoint)) | |
498 | t)))))))) | |
499 | ||
500 | (setq mh-folder-font-lock-keywords | |
501 | (append mh-folder-font-lock-keywords | |
502 | (list (list ',func (list 1 '',face 'prepend t)))))))) | |
503 | ||
504 | (mh-generate-sequence-font-lock mh-unseen-seq unseen bold) | |
505 | (mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick) | |
506 | ||
507 | \f | |
508 | ||
509 | ;;; MH-Folder Mode | |
510 | ||
511 | (defmacro mh-remove-xemacs-horizontal-scrollbar () | |
512 | "Get rid of the horizontal scrollbar that XEmacs insists on putting in." | |
513 | (when mh-xemacs-flag | |
514 | `(if (and (featurep 'scrollbar) | |
515 | (fboundp 'set-specifier)) | |
516 | (set-specifier horizontal-scrollbar-visible-p nil | |
517 | (cons (current-buffer) nil))))) | |
518 | ||
dda00b2c | 519 | ;; Register mh-folder-mode as supporting which-function-mode... |
d5dc8c56 | 520 | (mh-require 'which-func nil t) |
dda00b2c BW |
521 | (when (boundp 'which-func-modes) |
522 | (add-to-list 'which-func-modes 'mh-folder-mode)) | |
523 | ||
524 | ;; Shush compiler. | |
525 | (eval-when-compile | |
526 | (defvar desktop-save-buffer) | |
527 | (defvar font-lock-auto-fontify) | |
f875b154 | 528 | (defvar image-load-path) |
dda00b2c BW |
529 | (mh-do-in-xemacs (defvar font-lock-defaults))) |
530 | ||
531 | (defvar mh-folder-buttons-init-flag nil) | |
532 | ||
533 | ;; Ensure new buffers won't get this mode if default-major-mode is nil. | |
534 | (put 'mh-folder-mode 'mode-class 'special) | |
535 | ||
536 | ;; Autoload cookie needed by desktop.el | |
537 | ;;;###autoload | |
538 | (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder" | |
539 | "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map> | |
540 | ||
541 | You can show the message the cursor is pointing to, and step through | |
542 | the messages. Messages can be marked for deletion or refiling into | |
543 | another folder; these commands are executed all at once with a | |
544 | separate command. | |
545 | ||
546 | Options that control this mode can be changed with | |
547 | \\[customize-group]; specify the \"mh\" group. In particular, please | |
548 | see the `mh-scan-format-file' option if you wish to modify scan's | |
549 | format. | |
550 | ||
551 | When a folder is visited, the hook `mh-folder-mode-hook' is run. | |
552 | ||
553 | Ranges | |
554 | ====== | |
555 | Many commands that operate on individual messages, such as | |
556 | `mh-forward' or `mh-refile-msg' take a RANGE argument. This argument | |
557 | can be used in several ways. | |
558 | ||
559 | If you provide the prefix argument (\\[universal-argument]) to | |
560 | these commands, then you will be prompted for the message range. | |
561 | This can be any valid MH range which can include messages, | |
562 | sequences, and the abbreviations (described in the mh(1) man | |
563 | page): | |
564 | ||
565 | <num1>-<num2> | |
566 | Indicates all messages in the range <num1> to <num2>, inclusive. | |
567 | The range must be nonempty. | |
568 | ||
569 | <num>:N | |
570 | <num>:+N | |
571 | <num>:-N | |
572 | Up to N messages beginning with (or ending with) message num. Num | |
573 | may be any of the predefined symbols: first, prev, cur, next or | |
574 | last. | |
575 | ||
576 | first:N | |
577 | prev:N | |
578 | next:N | |
579 | last:N | |
580 | The first, previous, next or last messages, if they exist. | |
581 | ||
582 | all | |
583 | All of the messages. | |
584 | ||
585 | For example, a range that shows all of these things is `1 2 3 | |
586 | 5-10 last:5 unseen'. | |
587 | ||
588 | If the option `transient-mark-mode' is set to t and you set a | |
589 | region in the MH-Folder buffer, then the MH-E command will | |
590 | perform the operation on all messages in that region. | |
591 | ||
592 | \\{mh-folder-mode-map}" | |
593 | (mh-do-in-gnu-emacs | |
efc27af6 | 594 | (unless mh-folder-buttons-init-flag |
44e3f440 | 595 | (let* ((load-path (mh-image-load-path-for-library "mh-e" "mh-logo.xpm")) |
f875b154 BW |
596 | (image-load-path (cons (car load-path) |
597 | (when (boundp 'image-load-path) | |
598 | image-load-path)))) | |
efc27af6 BW |
599 | (mh-tool-bar-folder-buttons-init) |
600 | (setq mh-folder-buttons-init-flag t))) | |
601 | (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)) | |
602 | (mh-do-in-xemacs | |
603 | (mh-tool-bar-init :folder)) | |
dda00b2c BW |
604 | (make-local-variable 'font-lock-defaults) |
605 | (setq font-lock-defaults '(mh-folder-font-lock-keywords t)) | |
606 | (make-local-variable 'desktop-save-buffer) | |
607 | (setq desktop-save-buffer t) | |
608 | (mh-make-local-vars | |
609 | 'mh-colors-available-flag (mh-colors-available-p) | |
610 | ; Do we have colors available | |
611 | 'mh-current-folder (buffer-name) ; Name of folder, a string | |
612 | 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs | |
613 | 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/" | |
614 | (file-name-as-directory (mh-expand-file-name (buffer-name))) | |
615 | 'mh-display-buttons-for-inline-parts-flag | |
616 | mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to | |
617 | ; be toggled. | |
618 | 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed | |
619 | 'overlay-arrow-position nil ; Allow for simultaneous display in | |
620 | 'overlay-arrow-string ">" ; different MH-E buffers. | |
621 | 'mh-showing-mode nil ; Show message also? | |
622 | 'mh-delete-list nil ; List of msgs nums to delete | |
623 | 'mh-refile-list nil ; List of folder names in mh-seq-list | |
624 | 'mh-seq-list nil ; Alist of (seq . msgs) nums | |
625 | 'mh-seen-list nil ; List of displayed messages | |
626 | 'mh-next-direction 'forward ; Direction to move to next message | |
627 | 'mh-view-ops () ; Stack that keeps track of the order | |
628 | ; in which narrowing/threading has been | |
629 | ; carried out. | |
630 | 'mh-folder-view-stack () ; Stack of previous views of the | |
631 | ; folder. | |
632 | 'mh-index-data nil ; If the folder was created by a call | |
633 | ; to mh-search, this contains info | |
634 | ; about the search results. | |
635 | 'mh-index-previous-search nil ; folder, indexer, search-regexp | |
636 | 'mh-index-msg-checksum-map nil ; msg -> checksum map | |
637 | 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg ) | |
638 | 'mh-index-sequence-search-flag nil ; folder resulted from sequence search | |
639 | 'mh-first-msg-num nil ; Number of first msg in buffer | |
640 | 'mh-last-msg-num nil ; Number of last msg in buffer | |
641 | 'mh-msg-count nil ; Number of msgs in buffer | |
642 | 'mh-mode-line-annotation nil ; Indicates message range | |
643 | 'mh-sequence-notation-history (make-hash-table) | |
644 | ; Remember what is overwritten by | |
645 | ; mh-note-seq. | |
646 | 'imenu-create-index-function 'mh-index-create-imenu-index | |
647 | ; Setup imenu support | |
648 | 'mh-previous-window-config nil) ; Previous window configuration | |
649 | (mh-remove-xemacs-horizontal-scrollbar) | |
650 | (setq truncate-lines t) | |
651 | (auto-save-mode -1) | |
652 | (setq buffer-offer-save t) | |
06e7028b BW |
653 | (mh-make-local-hook (mh-write-file-functions)) |
654 | (add-hook (mh-write-file-functions) 'mh-execute-commands nil t) | |
dda00b2c BW |
655 | (make-local-variable 'revert-buffer-function) |
656 | (make-local-variable 'hl-line-mode) ; avoid pollution | |
657 | (mh-funcall-if-exists hl-line-mode 1) | |
658 | (setq revert-buffer-function 'mh-undo-folder) | |
4f3a7d02 | 659 | (add-to-list 'minor-mode-alist '(mh-showing-mode " Show")) |
dda00b2c BW |
660 | (easy-menu-add mh-folder-sequence-menu) |
661 | (easy-menu-add mh-folder-message-menu) | |
662 | (easy-menu-add mh-folder-folder-menu) | |
663 | (mh-inc-spool-make) | |
dda00b2c BW |
664 | (mh-set-help mh-folder-mode-help-messages) |
665 | (if (and mh-xemacs-flag | |
666 | font-lock-auto-fontify) | |
667 | (turn-on-font-lock))) ; Force font-lock in XEmacs. | |
668 | ||
669 | \f | |
670 | ||
671 | ;;; MH-Folder Commands | |
672 | ||
673 | ;; Alphabetical. | |
674 | ;; See also mh-comp.el, mh-junk.el, mh-mime.el, mh-print.el, | |
675 | ;; mh-search.el, and mh-seq.el. | |
676 | ||
677 | ;;;###mh-autoload | |
678 | (defun mh-delete-msg (range) | |
679 | "Delete RANGE\\<mh-folder-mode-map>. | |
680 | ||
681 | To mark a message for deletion, use this command. A \"D\" is | |
682 | placed by the message in the scan window, and the next undeleted | |
683 | message is displayed. If the previous command had been | |
684 | \\[mh-previous-undeleted-msg], then the next message displayed is | |
685 | the first undeleted message previous to the message just deleted. | |
686 | Use \\[mh-next-undeleted-msg] to force subsequent | |
687 | \\[mh-delete-msg] commands to move forward to the next undeleted | |
688 | message after deleting the message under the cursor. | |
689 | ||
690 | The hook `mh-delete-msg-hook' is called after you mark a message | |
691 | for deletion. For example, a past maintainer of MH-E used this | |
692 | once when he kept statistics on his mail usage. | |
693 | ||
694 | Check the documentation of `mh-interactive-range' to see how | |
695 | RANGE is read in interactive use." | |
696 | (interactive (list (mh-interactive-range "Delete"))) | |
697 | (mh-delete-msg-no-motion range) | |
698 | (if (looking-at mh-scan-deleted-msg-regexp) | |
699 | (mh-next-msg))) | |
700 | ||
701 | ;;;###mh-autoload | |
702 | (defun mh-delete-msg-no-motion (range) | |
703 | "Delete RANGE, don't move to next message. | |
704 | ||
705 | This command marks the RANGE for deletion but leaves the cursor | |
706 | at the current message in case you wish to perform other | |
707 | operations on the message. | |
708 | ||
709 | Check the documentation of `mh-interactive-range' to see how | |
710 | RANGE is read in interactive use." | |
711 | (interactive (list (mh-interactive-range "Delete"))) | |
712 | (mh-iterate-on-range () range | |
713 | (mh-delete-a-msg nil))) | |
714 | ||
715 | ;;;###mh-autoload | |
716 | (defun mh-execute-commands () | |
717 | "Process outstanding delete and refile requests\\<mh-folder-mode-map>. | |
718 | ||
719 | If you've marked messages to be deleted or refiled and you want | |
720 | to go ahead and delete or refile the messages, use this command. | |
721 | Many MH-E commands that may affect the numbering of the | |
722 | messages (such as \\[mh-rescan-folder] or \\[mh-pack-folder]) | |
723 | will ask if you want to process refiles or deletes first and then | |
724 | either run this command for you or undo the pending refiles and | |
798b73dd | 725 | deletes. |
dda00b2c BW |
726 | |
727 | This function runs `mh-before-commands-processed-hook' before the | |
728 | commands are processed and `mh-after-commands-processed-hook' | |
729 | after the commands are processed." | |
730 | (interactive) | |
731 | (if mh-folder-view-stack (mh-widen t)) | |
732 | (mh-process-commands mh-current-folder) | |
733 | (mh-set-scan-mode) | |
734 | (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency | |
735 | (mh-make-folder-mode-line) | |
736 | t) ; return t for write-file-functions | |
737 | ||
738 | ;;;###mh-autoload | |
739 | (defun mh-first-msg () | |
740 | "Display first message." | |
741 | (interactive) | |
742 | (goto-char (point-min)) | |
743 | (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp))) | |
744 | (forward-line 1))) | |
745 | ||
746 | ;;;###mh-autoload | |
747 | (defun mh-goto-msg (number &optional no-error-if-no-message dont-show) | |
748 | "Go to a message\\<mh-folder-mode-map>. | |
749 | ||
750 | You can enter the message NUMBER either before or after typing | |
751 | \\[mh-goto-msg]. In the latter case, Emacs prompts you. | |
752 | ||
753 | In a program, optional non-nil second argument NO-ERROR-IF-NO-MESSAGE | |
754 | means return nil instead of signaling an error if message does not | |
755 | exist\; in this case, the cursor is positioned near where the message | |
756 | would have been. Non-nil third argument DONT-SHOW means not to show | |
757 | the message." | |
758 | (interactive "NGo to message: ") | |
759 | (setq number (prefix-numeric-value number)) | |
760 | (let ((point (point)) | |
761 | (return-value t)) | |
762 | (goto-char (point-min)) | |
763 | (unless (re-search-forward (format (mh-scan-msg-search-regexp) number) | |
764 | nil t) | |
765 | (goto-char point) | |
766 | (unless no-error-if-no-message | |
767 | (error "No message %d" number)) | |
768 | (setq return-value nil)) | |
769 | (beginning-of-line) | |
770 | (or dont-show (not return-value) (mh-maybe-show number)) | |
771 | return-value)) | |
772 | ||
773 | ;;;###mh-autoload | |
774 | (defun mh-inc-folder (&optional file folder) | |
775 | "Incorporate new mail into a folder. | |
776 | ||
777 | You can incorporate mail from any file into the current folder by | |
778 | specifying a prefix argument; you'll be prompted for the name of | |
779 | the FILE to use as well as the destination FOLDER | |
780 | ||
781 | The hook `mh-inc-folder-hook' is run after incorporating new | |
782 | mail. | |
783 | ||
784 | Do not call this function from outside MH-E; use \\[mh-rmail] | |
785 | instead." | |
786 | (interactive (list (if current-prefix-arg | |
787 | (expand-file-name | |
788 | (read-file-name "inc mail from file: " | |
789 | mh-user-path))) | |
790 | (if current-prefix-arg | |
791 | (mh-prompt-for-folder "inc mail into" mh-inbox t)))) | |
792 | (if (not folder) | |
793 | (setq folder mh-inbox)) | |
794 | (let ((threading-needed-flag nil)) | |
795 | (let ((config (current-window-configuration))) | |
796 | (when (and mh-show-buffer (get-buffer mh-show-buffer)) | |
797 | (delete-windows-on mh-show-buffer)) | |
798 | (cond ((not (get-buffer folder)) | |
799 | (mh-make-folder folder) | |
800 | (setq threading-needed-flag mh-show-threads-flag) | |
801 | (setq mh-previous-window-config config)) | |
802 | ((not (eq (current-buffer) (get-buffer folder))) | |
803 | (switch-to-buffer folder) | |
804 | (setq mh-previous-window-config config)))) | |
805 | (mh-get-new-mail file) | |
806 | (when (and threading-needed-flag | |
807 | (save-excursion | |
808 | (goto-char (point-min)) | |
809 | (or (null mh-large-folder) | |
810 | (not (equal (forward-line (1+ mh-large-folder)) 0)) | |
811 | (and (message "Not threading since the number of messages exceeds `mh-large-folder'") | |
812 | nil)))) | |
813 | (mh-toggle-threads)) | |
814 | (beginning-of-line) | |
815 | (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show)) | |
816 | (run-hooks 'mh-inc-folder-hook))) | |
817 | ||
818 | ;;;###mh-autoload | |
819 | (defun mh-last-msg () | |
820 | "Display last message." | |
821 | (interactive) | |
822 | (goto-char (point-max)) | |
823 | (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp))) | |
824 | (forward-line -1)) | |
825 | (mh-recenter nil)) | |
826 | ||
827 | ;;;###mh-autoload | |
828 | (defun mh-modify (&optional message) | |
829 | "Edit message. | |
830 | ||
831 | There are times when you need to edit a message. For example, you | |
832 | may need to fix a broken Content-Type header field. You can do | |
833 | this with this command. It displays the raw message in an | |
834 | editable buffer. When you are done editing, save and kill the | |
835 | buffer as you would any other. | |
836 | ||
837 | From a program, edit MESSAGE; nil means edit current message." | |
838 | (interactive) | |
839 | (let* ((message (or message (mh-get-msg-num t))) | |
840 | (msg-filename (mh-msg-filename message)) | |
841 | edit-buffer) | |
842 | (when (not (file-exists-p msg-filename)) | |
843 | (error "Message %d does not exist" message)) | |
844 | ||
845 | ;; Invalidate the show buffer if it is showing the same message that is | |
846 | ;; to be edited. | |
847 | (when (and (buffer-live-p (get-buffer mh-show-buffer)) | |
848 | (equal (save-excursion (set-buffer mh-show-buffer) | |
849 | buffer-file-name) | |
850 | msg-filename)) | |
851 | (mh-invalidate-show-buffer)) | |
852 | ||
853 | ;; Edit message | |
854 | (find-file msg-filename) | |
855 | (setq edit-buffer (current-buffer)) | |
856 | ||
857 | ;; Set buffer properties | |
858 | (mh-letter-mode) | |
859 | (use-local-map text-mode-map) | |
860 | ||
861 | ;; Just show the edit buffer... | |
862 | (delete-other-windows) | |
863 | (switch-to-buffer edit-buffer))) | |
864 | ||
865 | ;;;###mh-autoload | |
866 | (defun mh-next-button (&optional backward-flag) | |
867 | "Go to the next button. | |
868 | ||
869 | If the end of the buffer is reached then the search wraps over to | |
870 | the start of the buffer. | |
871 | ||
872 | If an optional prefix argument BACKWARD-FLAG is given, the cursor | |
873 | will move to the previous button." | |
874 | (interactive (list current-prefix-arg)) | |
875 | (unless mh-showing-mode | |
876 | (mh-show)) | |
877 | (mh-in-show-buffer (mh-show-buffer) | |
878 | (mh-goto-next-button backward-flag))) | |
879 | ||
880 | ;;;###mh-autoload | |
881 | (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag) | |
882 | "Display next message. | |
883 | ||
884 | This command can be given a prefix argument COUNT to specify how | |
885 | many unread messages to skip. | |
886 | ||
887 | In a program, pause for a second after printing message if we are | |
888 | at the last undeleted message and optional argument | |
889 | WAIT-AFTER-COMPLAINING-FLAG is non-nil." | |
890 | (interactive "p") | |
891 | (setq mh-next-direction 'forward) | |
892 | (forward-line 1) | |
893 | (cond ((re-search-forward mh-scan-good-msg-regexp nil t count) | |
894 | (beginning-of-line) | |
895 | (mh-maybe-show)) | |
896 | (t (forward-line -1) | |
897 | (message "No more undeleted messages") | |
898 | (if wait-after-complaining-flag (sit-for 1))))) | |
899 | ||
900 | ;;;###mh-autoload | |
901 | (defun mh-next-unread-msg (&optional count) | |
902 | "Display next unread message. | |
903 | ||
904 | This command can be given a prefix argument COUNT to specify how | |
905 | many unread messages to skip." | |
906 | (interactive "p") | |
907 | (unless (> count 0) | |
908 | (error "The function `mh-next-unread-msg' expects positive argument")) | |
909 | (setq count (1- count)) | |
910 | (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list)))) | |
911 | (cur-msg (mh-get-msg-num nil))) | |
912 | (cond ((and (not cur-msg) (not (bobp)) | |
913 | ;; If we are at the end of the buffer back up one line and go | |
914 | ;; to unread message after that. | |
915 | (progn | |
916 | (forward-line -1) | |
917 | (setq cur-msg (mh-get-msg-num nil))) | |
918 | nil)) | |
919 | ((or (null unread-sequence) (not cur-msg)) | |
920 | ;; No unread message or there aren't any messages in buffer... | |
921 | (message "No more unread messages")) | |
922 | ((progn | |
923 | ;; Skip messages | |
924 | (while (and unread-sequence (>= cur-msg (car unread-sequence))) | |
925 | (setq unread-sequence (cdr unread-sequence))) | |
926 | (while (> count 0) | |
927 | (setq unread-sequence (cdr unread-sequence)) | |
928 | (setq count (1- count))) | |
929 | (not (car unread-sequence))) | |
930 | (message "No more unread messages")) | |
931 | (t (loop for msg in unread-sequence | |
932 | when (mh-goto-msg msg t) return nil | |
933 | finally (message "No more unread messages")))))) | |
934 | ||
935 | ;;;###mh-autoload | |
936 | (defun mh-page-msg (&optional lines) | |
937 | "Display next page in message. | |
938 | ||
939 | You can give this command a prefix argument that specifies the | |
940 | number of LINES to scroll. This command will also show the next | |
941 | undeleted message if it is used at the bottom of a message." | |
942 | (interactive "P") | |
943 | (if mh-showing-mode | |
944 | (if mh-page-to-next-msg-flag | |
945 | (if (equal mh-next-direction 'backward) | |
946 | (mh-previous-undeleted-msg) | |
947 | (mh-next-undeleted-msg)) | |
948 | (if (mh-in-show-buffer (mh-show-buffer) | |
949 | (pos-visible-in-window-p (point-max))) | |
950 | (progn | |
951 | (message | |
952 | "End of message (Type %s to read %s undeleted message)" | |
953 | (single-key-description last-input-event) | |
954 | (if (equal mh-next-direction 'backward) | |
955 | "previous" | |
956 | "next")) | |
957 | (setq mh-page-to-next-msg-flag t)) | |
958 | (scroll-other-window lines))) | |
959 | (mh-show))) | |
960 | ||
961 | ;;;###mh-autoload | |
962 | (defun mh-prev-button () | |
963 | "Go to the previous button. | |
964 | ||
965 | If the beginning of the buffer is reached then the search wraps | |
966 | over to the end of the buffer." | |
967 | (interactive) | |
968 | (mh-next-button t)) | |
969 | ||
970 | ;;;###mh-autoload | |
971 | (defun mh-previous-page (&optional lines) | |
972 | "Display next page in message. | |
973 | ||
974 | You can give this command a prefix argument that specifies the | |
975 | number of LINES to scroll." | |
976 | (interactive "P") | |
977 | (mh-in-show-buffer (mh-show-buffer) | |
978 | (scroll-down lines))) | |
979 | ||
980 | ;;;###mh-autoload | |
981 | (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag) | |
982 | "Display previous message. | |
983 | ||
984 | This command can be given a prefix argument COUNT to specify how | |
985 | many unread messages to skip. | |
986 | ||
987 | In a program, pause for a second after printing message if we are | |
988 | at the last undeleted message and optional argument | |
989 | WAIT-AFTER-COMPLAINING-FLAG is non-nil." | |
990 | (interactive "p") | |
991 | (setq mh-next-direction 'backward) | |
992 | (beginning-of-line) | |
993 | (cond ((re-search-backward mh-scan-good-msg-regexp nil t count) | |
994 | (mh-maybe-show)) | |
995 | (t (message "No previous undeleted message") | |
996 | (if wait-after-complaining-flag (sit-for 1))))) | |
997 | ||
998 | ;;;###mh-autoload | |
999 | (defun mh-previous-unread-msg (&optional count) | |
1000 | "Display previous unread message. | |
1001 | ||
1002 | This command can be given a prefix argument COUNT to specify how | |
1003 | many unread messages to skip." | |
1004 | (interactive "p") | |
1005 | (unless (> count 0) | |
1006 | (error "The function `mh-previous-unread-msg' expects positive argument")) | |
1007 | (setq count (1- count)) | |
1008 | (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list))) | |
1009 | (cur-msg (mh-get-msg-num nil))) | |
1010 | (cond ((and (not cur-msg) (not (bobp)) | |
1011 | ;; If we are at the end of the buffer back up one line and go | |
1012 | ;; to unread message after that. | |
1013 | (progn | |
1014 | (forward-line -1) | |
1015 | (setq cur-msg (mh-get-msg-num nil))) | |
1016 | nil)) | |
1017 | ((or (null unread-sequence) (not cur-msg)) | |
1018 | ;; No unread message or there aren't any messages in buffer... | |
1019 | (message "No more unread messages")) | |
1020 | ((progn | |
1021 | ;; Skip count messages... | |
1022 | (while (and unread-sequence (>= (car unread-sequence) cur-msg)) | |
1023 | (setq unread-sequence (cdr unread-sequence))) | |
1024 | (while (> count 0) | |
1025 | (setq unread-sequence (cdr unread-sequence)) | |
1026 | (setq count (1- count))) | |
1027 | (not (car unread-sequence))) | |
1028 | (message "No more unread messages")) | |
1029 | (t (loop for msg in unread-sequence | |
1030 | when (mh-goto-msg msg t) return nil | |
1031 | finally (message "No more unread messages")))))) | |
1032 | ||
1033 | ;;;###mh-autoload | |
1034 | (defun mh-quit () | |
1035 | "Quit the current MH-E folder. | |
1036 | ||
1037 | When you want to quit using MH-E and go back to editing, you can use | |
1038 | this command. This buries the buffers of the current MH-E folder and | |
1039 | restores the buffers that were present when you first ran | |
1040 | \\[mh-rmail]. It also removes any MH-E working buffers whose name | |
1041 | begins with \" *mh-\" or \"*MH-E \". You can later restore your MH-E | |
1042 | session by selecting the \"+inbox\" buffer or by running \\[mh-rmail] | |
1043 | again. | |
1044 | ||
1045 | The two hooks `mh-before-quit-hook' and `mh-quit-hook' are called by | |
1046 | this function. The former one is called before the quit occurs, so you | |
1047 | might use it to perform any MH-E operations; you could perform some | |
1048 | query and abort the quit or call `mh-execute-commands', for example. | |
1049 | The latter is not run in an MH-E context, so you might use it to | |
1050 | modify the window setup." | |
1051 | (interactive) | |
1052 | (run-hooks 'mh-before-quit-hook) | |
1053 | (let ((show-buffer (get-buffer mh-show-buffer))) | |
1054 | (when show-buffer | |
1055 | (kill-buffer show-buffer))) | |
1056 | (mh-update-sequences) | |
1057 | (mh-destroy-postponed-handles) | |
1058 | (bury-buffer (current-buffer)) | |
1059 | ||
1060 | ;; Delete all MH-E temporary and working buffers. | |
1061 | (dolist (buffer (buffer-list)) | |
1062 | (when (or (string-match "^ \\*mh-" (buffer-name buffer)) | |
1063 | (string-match "^\\*MH-E " (buffer-name buffer))) | |
1064 | (kill-buffer buffer))) | |
1065 | ||
1066 | (if mh-previous-window-config | |
1067 | (set-window-configuration mh-previous-window-config)) | |
1068 | (run-hooks 'mh-quit-hook)) | |
1069 | ||
1070 | ;;;###mh-autoload | |
1071 | (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag) | |
1072 | "Refile (output) RANGE into FOLDER. | |
1073 | ||
1074 | You are prompted for the folder name. Note that this command can also | |
1075 | be used to create folders. If you specify a folder that does not | |
1076 | exist, you will be prompted to create it. | |
1077 | ||
1078 | The hook `mh-refile-msg-hook' is called after a message is marked to | |
1079 | be refiled. | |
1080 | ||
1081 | Check the documentation of `mh-interactive-range' to see how RANGE is | |
1082 | read in interactive use. | |
1083 | ||
1084 | In a program, the variables `mh-last-destination' and | |
1085 | `mh-last-destination-folder' are not updated if | |
1086 | DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil." | |
1087 | (interactive (list (mh-interactive-range "Refile") | |
1088 | (intern (mh-prompt-for-refile-folder)))) | |
1089 | (unless dont-update-last-destination-flag | |
1090 | (setq mh-last-destination (cons 'refile folder) | |
1091 | mh-last-destination-folder mh-last-destination)) | |
1092 | (mh-iterate-on-range () range | |
1093 | (mh-refile-a-msg nil folder)) | |
1094 | (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg))) | |
1095 | ||
1096 | ;;;###mh-autoload | |
1097 | (defun mh-refile-or-write-again (range &optional interactive-flag) | |
1098 | "Repeat last output command. | |
1099 | ||
1100 | If you are refiling several messages into the same folder, you | |
1101 | can use this command to repeat the last | |
1102 | refile (\\[mh-refile-msg]) or write (\\[mh-write-msg-to-file]). | |
1103 | You can use a range. | |
1104 | ||
1105 | Check the documentation of `mh-interactive-range' to see how RANGE is | |
1106 | read in interactive use. | |
1107 | ||
1108 | In a program, a non-nil INTERACTIVE-FLAG means that the function was | |
1109 | called interactively." | |
1110 | (interactive (list (mh-interactive-range "Redo") t)) | |
1111 | (if (null mh-last-destination) | |
1112 | (error "No previous refile or write")) | |
1113 | (cond ((eq (car mh-last-destination) 'refile) | |
1114 | (mh-refile-msg range (cdr mh-last-destination)) | |
1115 | (message "Destination folder: %s" (cdr mh-last-destination))) | |
1116 | (t | |
1117 | (mh-iterate-on-range msg range | |
1118 | (apply 'mh-write-msg-to-file msg (cdr mh-last-destination))) | |
1119 | (mh-next-msg interactive-flag)))) | |
1120 | ||
1121 | ;;;###mh-autoload | |
1122 | (defun mh-rescan-folder (&optional range dont-exec-pending) | |
1123 | "Rescan folder\\<mh-folder-mode-map>. | |
1124 | ||
1125 | This command is useful to grab all messages in your \"+inbox\" after | |
1126 | processing your new mail for the first time. If you don't want to | |
1127 | rescan the entire folder, this command will accept a RANGE. Check the | |
1128 | documentation of `mh-interactive-range' to see how RANGE is read in | |
1129 | interactive use. | |
1130 | ||
1131 | This command will ask if you want to process refiles or deletes first | |
1132 | and then either run \\[mh-execute-commands] for you or undo the | |
798b73dd | 1133 | pending refiles and deletes. |
dda00b2c BW |
1134 | |
1135 | In a program, the processing of outstanding commands is not performed | |
1136 | if DONT-EXEC-PENDING is non-nil." | |
1137 | (interactive (list (if current-prefix-arg | |
1138 | (mh-read-range "Rescan" mh-current-folder t nil t | |
1139 | mh-interpret-number-as-range-flag) | |
1140 | nil))) | |
1141 | (setq mh-next-direction 'forward) | |
1142 | (let ((threaded-flag (memq 'unthread mh-view-ops)) | |
1143 | (msg-num (mh-get-msg-num nil))) | |
1144 | (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending) | |
1145 | ;; If there isn't a cur sequence, mh-scan-folder goes to the first message. | |
1146 | ;; Try to stay where we were. | |
1147 | (if (null (car (mh-seq-to-msgs 'cur))) | |
1148 | (mh-goto-msg msg-num t t)) | |
1149 | (cond (threaded-flag (mh-toggle-threads)) | |
1150 | (mh-index-data (mh-index-insert-folder-headers))))) | |
1151 | ||
1152 | (defun mh-show-mouse (event) | |
1153 | "Move point to mouse EVENT and show message." | |
1154 | (interactive "e") | |
1155 | (mouse-set-point event) | |
1156 | (mh-show)) | |
1157 | ||
1158 | ;;;###mh-autoload | |
1159 | (defun mh-toggle-showing () | |
1160 | "Toggle between MH-Folder and MH-Folder Show modes. | |
1161 | ||
1162 | This command switches between MH-Folder mode and MH-Folder Show | |
1163 | mode. MH-Folder mode turns off the associated show buffer so that | |
1164 | you can perform operations on the messages quickly without | |
1165 | reading them. This is an excellent way to prune out your junk | |
1166 | mail or to refile a group of messages to another folder for later | |
1167 | examination." | |
1168 | (interactive) | |
1169 | (if mh-showing-mode | |
1170 | (mh-set-scan-mode) | |
1171 | (mh-show))) | |
1172 | ||
1173 | ;;;###mh-autoload | |
1174 | (defun mh-undo (range) | |
1175 | "Undo pending deletes or refiles in RANGE. | |
1176 | ||
1177 | If you've deleted a message or refiled it, but changed your mind, | |
1178 | you can cancel the action before you've executed it. Use this | |
1179 | command to undo a refile on or deletion of a single message. You | |
1180 | can also undo refiles and deletes for messages that are found in | |
1181 | a given RANGE. | |
1182 | ||
1183 | Check the documentation of `mh-interactive-range' to see how | |
1184 | RANGE is read in interactive use." | |
1185 | (interactive (list (mh-interactive-range "Undo"))) | |
1186 | (cond ((numberp range) | |
1187 | (let ((original-position (point))) | |
1188 | (beginning-of-line) | |
1189 | (while (not (or (looking-at mh-scan-deleted-msg-regexp) | |
1190 | (looking-at mh-scan-refiled-msg-regexp) | |
1191 | (and (eq mh-next-direction 'forward) (bobp)) | |
1192 | (and (eq mh-next-direction 'backward) | |
1193 | (save-excursion (forward-line) (eobp))))) | |
1194 | (forward-line (if (eq mh-next-direction 'forward) -1 1))) | |
1195 | (if (or (looking-at mh-scan-deleted-msg-regexp) | |
1196 | (looking-at mh-scan-refiled-msg-regexp)) | |
1197 | (progn | |
1198 | (mh-undo-msg (mh-get-msg-num t)) | |
1199 | (mh-maybe-show)) | |
1200 | (goto-char original-position) | |
1201 | (error "Nothing to undo")))) | |
1202 | (t (mh-iterate-on-range () range | |
1203 | (mh-undo-msg nil)))) | |
1204 | (if (not (mh-outstanding-commands-p)) | |
1205 | (mh-set-folder-modified-p nil))) | |
1206 | ||
1207 | ;;;###mh-autoload | |
1208 | (defun mh-visit-folder (folder &optional range index-data) | |
1209 | "Visit FOLDER. | |
1210 | ||
1211 | When you want to read the messages that you have refiled into folders, | |
1212 | use this command to visit the folder. You are prompted for the folder | |
1213 | name. | |
1214 | ||
1215 | The folder buffer will show just unseen messages if there are any; | |
1216 | otherwise, it will show all the messages in the buffer as long there | |
1217 | are fewer than `mh-large-folder' messages. If there are more, then you | |
1218 | are prompted for a range of messages to scan. | |
1219 | ||
1220 | You can provide a prefix argument in order to specify a RANGE of | |
1221 | messages to show when you visit the folder. In this case, regions are | |
1222 | not used to specify the range and `mh-large-folder' is ignored. Check | |
1223 | the documentation of `mh-interactive-range' to see how RANGE is read | |
1224 | in interactive use. | |
1225 | ||
1226 | Note that this command can also be used to create folders. If you | |
1227 | specify a folder that does not exist, you will be prompted to create | |
1228 | it. | |
1229 | ||
1230 | Do not call this function from outside MH-E; use \\[mh-rmail] instead. | |
1231 | ||
1232 | If, in a program, RANGE is nil (the default), then all messages in | |
1233 | FOLDER are displayed. If an index buffer is being created then | |
1234 | INDEX-DATA is used to initialize the index buffer specific data | |
1235 | structures." | |
1236 | (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t))) | |
1237 | (list folder-name | |
1238 | (mh-read-range "Scan" folder-name t nil | |
1239 | current-prefix-arg | |
1240 | mh-interpret-number-as-range-flag)))) | |
1241 | (let ((config (current-window-configuration)) | |
1242 | (current-buffer (current-buffer)) | |
1243 | (threaded-view-flag mh-show-threads-flag)) | |
1244 | (delete-other-windows) | |
1245 | (save-excursion | |
1246 | (when (get-buffer folder) | |
1247 | (set-buffer folder) | |
1248 | (setq threaded-view-flag (memq 'unthread mh-view-ops)))) | |
1249 | (when index-data | |
1250 | (mh-make-folder folder) | |
1251 | (setq mh-index-data (car index-data) | |
1252 | mh-index-msg-checksum-map (make-hash-table :test #'equal) | |
1253 | mh-index-checksum-origin-map (make-hash-table :test #'equal)) | |
1254 | (mh-index-update-maps folder (cadr index-data)) | |
1255 | (mh-index-create-sequences)) | |
1256 | (mh-scan-folder folder (or range "all")) | |
1257 | (cond ((and threaded-view-flag | |
1258 | (save-excursion | |
1259 | (goto-char (point-min)) | |
1260 | (or (null mh-large-folder) | |
1261 | (not (equal (forward-line (1+ mh-large-folder)) 0)) | |
1262 | (and (message "Not threading since the number of messages exceeds `mh-large-folder'") | |
1263 | nil)))) | |
1264 | (mh-toggle-threads)) | |
1265 | (mh-index-data | |
1266 | (mh-index-insert-folder-headers))) | |
1267 | (unless (eq current-buffer (current-buffer)) | |
1268 | (setq mh-previous-window-config config))) | |
1269 | nil) | |
1270 | ||
1271 | ;;;###mh-autoload | |
1272 | (defun mh-write-msg-to-file (message file no-header) | |
1273 | "Append MESSAGE to end of FILE\\<mh-folder-mode-map>. | |
1274 | ||
1275 | You are prompted for the filename. If the file already exists, | |
1276 | the message is appended to it. You can also write the message to | |
1277 | the file without the header by specifying a prefix argument | |
1278 | NO-HEADER. Subsequent writes to the same file can be made with | |
1279 | the command \\[mh-refile-or-write-again]." | |
1280 | (interactive | |
1281 | (list (mh-get-msg-num t) | |
1282 | (let ((default-dir (if (eq 'write (car mh-last-destination-write)) | |
1283 | (file-name-directory | |
1284 | (car (cdr mh-last-destination-write))) | |
1285 | default-directory))) | |
1286 | (read-file-name (format "Save message%s in file: " | |
1287 | (if current-prefix-arg " body" "")) | |
1288 | default-dir | |
1289 | (if (eq 'write (car mh-last-destination-write)) | |
1290 | (car (cdr mh-last-destination-write)) | |
1291 | (expand-file-name "mail.out" default-dir)))) | |
1292 | current-prefix-arg)) | |
1293 | (let ((msg-file-to-output (mh-msg-filename message)) | |
1294 | (output-file (mh-expand-file-name file))) | |
1295 | (setq mh-last-destination (list 'write file (if no-header 'no-header)) | |
1296 | mh-last-destination-write mh-last-destination) | |
1297 | (save-excursion | |
1298 | (set-buffer (get-buffer-create mh-temp-buffer)) | |
1299 | (erase-buffer) | |
1300 | (insert-file-contents msg-file-to-output) | |
1301 | (goto-char (point-min)) | |
1302 | (if no-header (search-forward "\n\n")) | |
1303 | (append-to-file (point) (point-max) output-file)))) | |
1304 | ||
1305 | ;;;###mh-autoload | |
1306 | (defun mh-update-sequences () | |
1307 | "Flush MH-E's state out to MH. | |
1308 | ||
1309 | This function updates the sequence specified by your | |
1310 | \"Unseen-Sequence:\" profile component, \"cur\", and the sequence | |
1311 | listed by the `mh-tick-seq' option which is \"tick\" by default. | |
1312 | The message at the cursor is used for \"cur\"." | |
1313 | (interactive) | |
1314 | ;; mh-update-sequences is the opposite of mh-read-folder-sequences, | |
1315 | ;; which updates MH-E's state from MH. | |
1316 | (let ((folder-set (mh-update-unseen)) | |
1317 | (new-cur (mh-get-msg-num nil))) | |
1318 | (if new-cur | |
1319 | (let ((seq-entry (mh-find-seq 'cur))) | |
1320 | (mh-remove-cur-notation) | |
1321 | (setcdr seq-entry | |
1322 | (list new-cur)) ;delete-seq-locally, add-msgs-to-seq | |
1323 | (mh-define-sequence 'cur (list new-cur)) | |
1324 | (beginning-of-line) | |
1325 | (if (looking-at mh-scan-good-msg-regexp) | |
1326 | (mh-notate-cur))) | |
1327 | (or folder-set | |
1328 | (save-excursion | |
1329 | ;; psg - mh-current-folder is nil if mh-summary-height < 4 ! | |
1330 | ;; So I added this sanity check. | |
1331 | (if (stringp mh-current-folder) | |
1332 | (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast") | |
1333 | (mh-exec-cmd-quiet t "folder" "-fast"))))))) | |
1334 | ||
1335 | \f | |
1336 | ||
1337 | ;;; Support Routines | |
1338 | ||
1339 | (defun mh-get-new-mail (maildrop-name) | |
1340 | "Read new mail from MAILDROP-NAME into the current buffer. | |
1341 | Return in the current buffer." | |
1342 | (let ((point-before-inc (point)) | |
1343 | (folder mh-current-folder) | |
1344 | (new-mail-flag nil)) | |
1345 | (with-mh-folder-updating (t) | |
1346 | (if maildrop-name | |
1347 | (message "inc %s -file %s..." folder maildrop-name) | |
1348 | (message "inc %s..." folder)) | |
1349 | (setq mh-next-direction 'forward) | |
1350 | (goto-char (point-max)) | |
1351 | (mh-remove-cur-notation) | |
1352 | (let ((start-of-inc (point))) | |
1353 | (if maildrop-name | |
1354 | ;; I think MH 5 used "-ms-file" instead of "-file", | |
1355 | ;; which would make inc'ing from maildrops fail. | |
1356 | (mh-exec-cmd-output mh-inc-prog nil folder | |
1357 | (mh-scan-format) | |
1358 | "-file" (expand-file-name maildrop-name) | |
1359 | "-width" (window-width) | |
1360 | "-truncate") | |
1361 | (mh-exec-cmd-output mh-inc-prog nil | |
1362 | (mh-scan-format) | |
1363 | "-width" (window-width))) | |
1364 | (if maildrop-name | |
1365 | (message "inc %s -file %s...done" folder maildrop-name) | |
1366 | (message "inc %s...done" folder)) | |
1367 | (goto-char start-of-inc) | |
1368 | (cond ((save-excursion | |
1369 | (re-search-forward "^inc: no mail" nil t)) | |
1370 | (message "No new mail%s%s" (if maildrop-name " in " "") | |
1371 | (if maildrop-name maildrop-name ""))) | |
1372 | ((and (when mh-folder-view-stack | |
1373 | (let ((saved-text (buffer-substring-no-properties | |
1374 | start-of-inc (point-max)))) | |
1375 | (delete-region start-of-inc (point-max)) | |
1376 | (unwind-protect (mh-widen t) | |
1377 | (mh-remove-cur-notation) | |
1378 | (goto-char (point-max)) | |
1379 | (setq start-of-inc (point)) | |
1380 | (insert saved-text) | |
1381 | (goto-char start-of-inc)))) | |
1382 | nil)) | |
1383 | ((re-search-forward "^inc:" nil t) ; Error messages | |
1384 | (error "Error incorporating mail")) | |
1385 | ((and | |
1386 | (equal mh-scan-format-file t) | |
1387 | mh-adaptive-cmd-note-flag | |
1388 | ;; Have we reached an edge condition? | |
1389 | (save-excursion | |
1390 | (re-search-forward mh-scan-msg-overflow-regexp nil 0 1)) | |
1391 | (setq start-of-inc (mh-generate-new-cmd-note folder)) | |
1392 | nil)) | |
1393 | (t | |
1394 | (setq new-mail-flag t))) | |
1395 | (keep-lines mh-scan-valid-regexp) ; Flush random scan lines | |
1396 | (let* ((sequences (mh-read-folder-sequences folder t)) | |
1397 | (new-cur (assoc 'cur sequences)) | |
1398 | (new-unseen (assoc mh-unseen-seq sequences))) | |
1399 | (unless (assoc 'cur mh-seq-list) | |
1400 | (push (list 'cur) mh-seq-list)) | |
1401 | (unless (assoc mh-unseen-seq mh-seq-list) | |
1402 | (push (list mh-unseen-seq) mh-seq-list)) | |
1403 | (setcdr (assoc 'cur mh-seq-list) (cdr new-cur)) | |
1404 | (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen))) | |
1405 | (when (equal (point-max) start-of-inc) | |
1406 | (mh-notate-cur)) | |
1407 | (if new-mail-flag | |
1408 | (progn | |
1409 | (mh-make-folder-mode-line) | |
1410 | (when (mh-speed-flists-active-p) | |
1411 | (mh-speed-flists t mh-current-folder)) | |
1412 | (when (memq 'unthread mh-view-ops) | |
1413 | (mh-thread-inc folder start-of-inc)) | |
1414 | (mh-goto-cur-msg)) | |
1415 | (goto-char point-before-inc)) | |
1416 | (mh-notate-user-sequences (cons start-of-inc (point-max))))))) | |
1417 | ||
1418 | (defun mh-generate-new-cmd-note (folder) | |
1419 | "Fix the `mh-cmd-note' value for this FOLDER. | |
1420 | ||
1421 | After doing an `mh-get-new-mail' operation in this FOLDER, at least | |
1422 | one line that looks like a truncated message number was found. | |
1423 | ||
1424 | Remove the text added by the last `mh-inc' command. It should be the | |
1425 | messages cur-last. Call `mh-set-cmd-note', adjusting the notation | |
1426 | column with the width of the largest message number in FOLDER. | |
1427 | ||
1428 | Reformat the message number width on each line in the buffer and trim | |
1429 | the line length to fit in the window. | |
1430 | ||
1431 | Rescan the FOLDER in the range cur-last in order to display the | |
1432 | messages that were removed earlier. They should all fit in the scan | |
1433 | line now with no message truncation." | |
1434 | (save-excursion | |
1435 | (let ((maxcol (1- (window-width))) | |
1436 | (old-cmd-note mh-cmd-note) | |
1437 | mh-cmd-note-fmt | |
1438 | msgnum) | |
1439 | ;; Nuke all of the lines just added by the last inc | |
1440 | (delete-char (- (point-max) (point))) | |
1441 | ;; Update the current buffer to reflect the new mh-cmd-note | |
1442 | ;; value needed to display messages. | |
1443 | (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder))) | |
1444 | (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d")) | |
1445 | ;; Cleanup the messages that are in the buffer right now | |
1446 | (goto-char (point-min)) | |
1447 | (cond ((memq 'unthread mh-view-ops) | |
1448 | (mh-thread-add-spaces (- mh-cmd-note old-cmd-note))) | |
1449 | (t (while (re-search-forward (mh-scan-msg-number-regexp) nil 0 1) | |
1450 | ;; reformat the number to fix in mh-cmd-note columns | |
1451 | (setq msgnum (string-to-number | |
1452 | (buffer-substring | |
1453 | (match-beginning 1) (match-end 1)))) | |
1454 | (replace-match (format mh-cmd-note-fmt msgnum)) | |
1455 | ;; trim the line to fix in the window | |
1456 | (end-of-line) | |
1457 | (let ((eol (point))) | |
1458 | (move-to-column maxcol) | |
1459 | (if (<= (point) eol) | |
1460 | (delete-char (- eol (point)))))))) | |
1461 | ;; now re-read the lost messages | |
1462 | (goto-char (point-max)) | |
1463 | (prog1 (point) | |
1464 | (mh-regenerate-headers "cur-last" t))))) | |
1465 | ||
1466 | ;;;###mh-autoload | |
1467 | (defun mh-goto-cur-msg (&optional minimal-changes-flag) | |
1468 | "Position the cursor at the current message. | |
1469 | When optional argument MINIMAL-CHANGES-FLAG is non-nil, the | |
1470 | function doesn't recenter the folder buffer." | |
1471 | (let ((cur-msg (car (mh-seq-to-msgs 'cur)))) | |
1472 | (cond ((and cur-msg | |
1473 | (mh-goto-msg cur-msg t t)) | |
1474 | (unless minimal-changes-flag | |
1475 | (mh-notate-cur) | |
1476 | (mh-recenter 0) | |
1477 | (mh-maybe-show cur-msg))) | |
1478 | (t | |
1479 | (setq overlay-arrow-position nil) | |
1480 | (message "No current message"))))) | |
1481 | ||
1482 | ;;;###mh-autoload | |
1483 | (defun mh-recenter (arg) | |
1484 | "Like recenter but with three improvements: | |
1485 | ||
1486 | - At the end of the buffer it tries to show fewer empty lines. | |
1487 | ||
1488 | - operates only if the current buffer is in the selected window. | |
1489 | (Commands like `save-some-buffers' can make this false.) | |
1490 | ||
1491 | - nil ARG means recenter as if prefix argument had been given." | |
1492 | (cond ((not (eq (get-buffer-window (current-buffer)) (selected-window))) | |
1493 | nil) | |
1494 | ((= (point-max) (save-excursion | |
1495 | (forward-line (- (/ (window-height) 2) 2)) | |
1496 | (point))) | |
1497 | (let ((lines-from-end 2)) | |
1498 | (save-excursion | |
1499 | (while (> (point-max) (progn (forward-line) (point))) | |
1500 | (incf lines-from-end))) | |
1501 | (recenter (- lines-from-end)))) | |
1502 | ;; '(4) is the same as C-u prefix argument. | |
1503 | (t (recenter (or arg '(4)))))) | |
1504 | ||
1505 | (defun mh-update-unseen () | |
1506 | "Synchronize the unseen sequence with MH. | |
1507 | Return non-nil iff the MH folder was set. | |
1508 | The hook `mh-unseen-updated-hook' is called after the unseen sequence | |
1509 | is updated." | |
1510 | (if mh-seen-list | |
1511 | (let* ((unseen-seq (mh-find-seq mh-unseen-seq)) | |
1512 | (unseen-msgs (mh-seq-msgs unseen-seq))) | |
1513 | (if unseen-msgs | |
1514 | (progn | |
1515 | (mh-undefine-sequence mh-unseen-seq mh-seen-list) | |
1516 | (run-hooks 'mh-unseen-updated-hook) | |
1517 | (while mh-seen-list | |
1518 | (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs)) | |
1519 | (setq mh-seen-list (cdr mh-seen-list))) | |
1520 | (setcdr unseen-seq unseen-msgs) | |
1521 | t) ;since we set the folder | |
1522 | (setq mh-seen-list nil))))) | |
1523 | ||
1524 | ;;;###mh-autoload | |
1525 | (defun mh-outstanding-commands-p () | |
1526 | "Return non-nil if there are outstanding deletes or refiles." | |
1527 | (save-excursion | |
1528 | (when (eq major-mode 'mh-show-mode) | |
1529 | (set-buffer mh-show-folder-buffer)) | |
1530 | (or mh-delete-list mh-refile-list))) | |
1531 | ||
1532 | ;;;###mh-autoload | |
1533 | (defun mh-set-folder-modified-p (flag) | |
1534 | "Mark current folder as modified or unmodified according to FLAG." | |
1535 | (set-buffer-modified-p flag)) | |
1536 | ||
1537 | (defun mh-process-commands (folder) | |
1538 | "Process outstanding commands for FOLDER. | |
1539 | ||
1540 | This function runs `mh-before-commands-processed-hook' before the | |
1541 | commands are processed and `mh-after-commands-processed-hook' | |
1542 | after the commands are processed." | |
1543 | (message "Processing deletes and refiles for %s..." folder) | |
1544 | (set-buffer folder) | |
1545 | (with-mh-folder-updating (nil) | |
1546 | ;; Run the before hook -- the refile and delete lists are still valid | |
1547 | (run-hooks 'mh-before-commands-processed-hook) | |
1548 | ||
1549 | ;; Update the unseen sequence if it exists | |
1550 | (mh-update-unseen) | |
1551 | ||
1552 | (let ((redraw-needed-flag mh-index-data) | |
1553 | (folders-changed (list mh-current-folder)) | |
1554 | (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag | |
1555 | (mh-create-sequence-map mh-seq-list))) | |
1556 | (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag | |
1557 | (make-hash-table)))) | |
1558 | ;; Remove invalid scan lines if we are in an index folder and then remove | |
1559 | ;; the real messages | |
1560 | (when mh-index-data | |
1561 | (mh-index-delete-folder-headers) | |
1562 | (setq folders-changed | |
1563 | (append folders-changed (mh-index-execute-commands)))) | |
1564 | ||
1565 | ;; Then refile messages | |
1566 | (mh-mapc #'(lambda (folder-msg-list) | |
1567 | (let* ((dest-folder (symbol-name (car folder-msg-list))) | |
1568 | (last (car (mh-translate-range dest-folder "last"))) | |
1569 | (msgs (cdr folder-msg-list))) | |
1570 | (push dest-folder folders-changed) | |
1571 | (setq redraw-needed-flag t) | |
1572 | (apply #'mh-exec-cmd | |
1573 | "refile" "-src" folder dest-folder | |
1574 | (mh-coalesce-msg-list msgs)) | |
1575 | (mh-delete-scan-msgs msgs) | |
1576 | ;; Preserve sequences in destination folder... | |
1577 | (when mh-refile-preserves-sequences-flag | |
1578 | (clrhash dest-map) | |
1579 | (loop for i from (1+ (or last 0)) | |
1580 | for msg in (sort (copy-sequence msgs) #'<) | |
1581 | do (loop for seq-name in (gethash msg seq-map) | |
1582 | do (push i (gethash seq-name dest-map)))) | |
1583 | (maphash | |
1584 | #'(lambda (seq msgs) | |
1585 | ;; Can't be run in the background, since the | |
1586 | ;; current folder is changed by mark this could | |
1587 | ;; lead to a race condition with the next refile. | |
1588 | (apply #'mh-exec-cmd "mark" | |
1589 | "-sequence" (symbol-name seq) dest-folder | |
1590 | "-add" (mapcar #'(lambda (x) (format "%s" x)) | |
1591 | (mh-coalesce-msg-list msgs)))) | |
1592 | dest-map)))) | |
1593 | mh-refile-list) | |
1594 | (setq mh-refile-list ()) | |
1595 | ||
1596 | ;; Now delete messages | |
1597 | (cond (mh-delete-list | |
1598 | (setq redraw-needed-flag t) | |
1599 | (apply 'mh-exec-cmd "rmm" folder | |
1600 | (mh-coalesce-msg-list mh-delete-list)) | |
1601 | (mh-delete-scan-msgs mh-delete-list) | |
1602 | (setq mh-delete-list nil))) | |
1603 | ||
1604 | ;; Don't need to remove sequences since delete and refile do so. | |
1605 | ;; Mark cur message | |
1606 | (if (> (buffer-size) 0) | |
1607 | (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last")))) | |
1608 | ||
1609 | ;; Redraw folder buffer if needed | |
1610 | (when (and redraw-needed-flag) | |
1611 | (when (mh-speed-flists-active-p) | |
1612 | (apply #'mh-speed-flists t folders-changed)) | |
1613 | (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max))) | |
1614 | (mh-index-data (mh-index-insert-folder-headers)))) | |
1615 | ||
1616 | (and (buffer-file-name (get-buffer mh-show-buffer)) | |
1617 | (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer)))) | |
1618 | ;; If "inc" were to put a new msg in this file, | |
1619 | ;; we would not notice, so mark it invalid now. | |
1620 | (mh-invalidate-show-buffer)) | |
1621 | ||
1622 | (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil)) | |
1623 | (mh-remove-all-notation) | |
1624 | (mh-notate-user-sequences) | |
1625 | ||
1626 | ;; Run the after hook -- now folders-changed is valid, | |
1627 | ;; but not the lists of specific messages. | |
1628 | (let ((mh-folders-changed folders-changed)) | |
1629 | (run-hooks 'mh-after-commands-processed-hook))) | |
1630 | ||
1631 | (message "Processing deletes and refiles for %s...done" folder))) | |
1632 | ||
1633 | (defun mh-delete-scan-msgs (msgs) | |
1634 | "Delete the scan listing lines for MSGS." | |
1635 | (save-excursion | |
1636 | (while msgs | |
1637 | (when (mh-goto-msg (car msgs) t t) | |
1638 | (when (memq 'unthread mh-view-ops) | |
1639 | (mh-thread-forget-message (car msgs))) | |
1640 | (mh-delete-line 1)) | |
1641 | (setq msgs (cdr msgs))))) | |
1642 | ||
1643 | (defun mh-set-scan-mode () | |
1644 | "Display the scan listing buffer, but do not show a message." | |
1645 | (if (get-buffer mh-show-buffer) | |
1646 | (delete-windows-on mh-show-buffer)) | |
1647 | (mh-showing-mode 0) | |
1648 | (force-mode-line-update) | |
1649 | (if mh-recenter-summary-flag | |
1650 | (mh-recenter nil))) | |
1651 | ||
1652 | ;;;###mh-autoload | |
1653 | (defun mh-make-folder-mode-line (&optional ignored) | |
1654 | "Set the fields of the mode line for a folder buffer. | |
1655 | The optional argument is now obsolete and IGNORED. It used to be | |
1656 | used to pass in what is now stored in the buffer-local variable | |
1657 | `mh-mode-line-annotation'." | |
1658 | (save-excursion | |
1659 | (save-window-excursion | |
1660 | (mh-first-msg) | |
1661 | (let ((new-first-msg-num (mh-get-msg-num nil))) | |
1662 | (when (or (not (memq 'unthread mh-view-ops)) | |
1663 | (null mh-first-msg-num) | |
1664 | (null new-first-msg-num) | |
1665 | (< new-first-msg-num mh-first-msg-num)) | |
1666 | (setq mh-first-msg-num new-first-msg-num))) | |
1667 | (mh-last-msg) | |
1668 | (let ((new-last-msg-num (mh-get-msg-num nil))) | |
1669 | (when (or (not (memq 'unthread mh-view-ops)) | |
1670 | (null mh-last-msg-num) | |
1671 | (null new-last-msg-num) | |
1672 | (> new-last-msg-num mh-last-msg-num)) | |
1673 | (setq mh-last-msg-num new-last-msg-num))) | |
1674 | (setq mh-msg-count (if mh-first-msg-num | |
1675 | (count-lines (point-min) (point-max)) | |
1676 | 0)) | |
1677 | (setq mode-line-buffer-identification | |
1678 | (list (format " {%%b%s} %s msg%s" | |
1679 | (if mh-mode-line-annotation | |
1680 | (format "/%s" mh-mode-line-annotation) | |
1681 | "") | |
1682 | (if (zerop mh-msg-count) | |
1683 | "no" | |
1684 | (format "%d" mh-msg-count)) | |
1685 | (if (zerop mh-msg-count) | |
1686 | "s" | |
1687 | (cond ((> mh-msg-count 1) | |
1688 | (format "s (%d-%d)" mh-first-msg-num | |
1689 | mh-last-msg-num)) | |
1690 | (mh-first-msg-num | |
1691 | (format " (%d)" mh-first-msg-num)) | |
1692 | ("")))))) | |
1693 | (mh-logo-display)))) | |
1694 | ||
1695 | ;;;###mh-autoload | |
1696 | (defun mh-scan-folder (folder range &optional dont-exec-pending) | |
1697 | "Scan FOLDER over RANGE. | |
1698 | ||
1699 | After the scan is performed, switch to the buffer associated with | |
1700 | FOLDER. | |
1701 | ||
1702 | Check the documentation of `mh-interactive-range' to see how RANGE is | |
1703 | read in interactive use. | |
1704 | ||
1705 | The processing of outstanding commands is not performed if | |
1706 | DONT-EXEC-PENDING is non-nil." | |
1707 | (when (stringp range) | |
1708 | (setq range (delete "" (split-string range "[ \t\n]")))) | |
1709 | (cond ((null (get-buffer folder)) | |
1710 | (mh-make-folder folder)) | |
1711 | (t | |
1712 | (unless dont-exec-pending | |
1713 | (mh-process-or-undo-commands folder) | |
1714 | (mh-reset-threads-and-narrowing)) | |
1715 | (switch-to-buffer folder))) | |
1716 | (mh-regenerate-headers range) | |
1717 | (if (zerop (buffer-size)) | |
1718 | (if (equal range "all") | |
1719 | (message "Folder %s is empty" folder) | |
1720 | (message "No messages in %s, range %s" folder range)) | |
1721 | (mh-goto-cur-msg)) | |
1722 | (when (mh-outstanding-commands-p) | |
1723 | (mh-notate-deleted-and-refiled))) | |
1724 | ||
1725 | ;;;###mh-autoload | |
1726 | (defun mh-process-or-undo-commands (folder) | |
1727 | "If FOLDER has outstanding commands, then either process or discard them. | |
1728 | Called by functions like `mh-sort-folder', so also invalidate | |
1729 | show buffer." | |
1730 | (set-buffer folder) | |
1731 | (if (mh-outstanding-commands-p) | |
1732 | (if (or mh-do-not-confirm-flag | |
1733 | (y-or-n-p | |
1734 | "Process outstanding deletes and refiles? ")) | |
1735 | (mh-process-commands folder) | |
1736 | (set-buffer folder) | |
1737 | (mh-undo-folder))) | |
1738 | (mh-update-unseen) | |
1739 | (mh-invalidate-show-buffer)) | |
1740 | ||
1741 | ;;;###mh-autoload | |
1742 | (defun mh-regenerate-headers (range &optional update) | |
1743 | "Scan folder over RANGE. | |
1744 | If UPDATE, append the scan lines, otherwise replace." | |
1745 | (let ((folder mh-current-folder) | |
1746 | (range (if (and range (atom range)) (list range) range)) | |
1747 | scan-start) | |
1748 | (message "Scanning %s..." folder) | |
1749 | (mh-remove-all-notation) | |
1750 | (with-mh-folder-updating (nil) | |
1751 | (if update | |
1752 | (goto-char (point-max)) | |
1753 | (delete-region (point-min) (point-max)) | |
1754 | (if mh-adaptive-cmd-note-flag | |
1755 | (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width | |
1756 | folder))))) | |
1757 | (setq scan-start (point)) | |
1758 | (apply #'mh-exec-cmd-output | |
1759 | mh-scan-prog nil | |
1760 | (mh-scan-format) | |
1761 | "-noclear" "-noheader" | |
1762 | "-width" (window-width) | |
1763 | folder range) | |
1764 | (goto-char scan-start) | |
1765 | (cond ((looking-at "scan: no messages in") | |
1766 | (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines | |
1767 | ((looking-at (if (mh-variant-p 'mu-mh) | |
1768 | "scan: message set .* does not exist" | |
1769 | "scan: bad message list ")) | |
1770 | (keep-lines mh-scan-valid-regexp)) | |
1771 | ((looking-at "scan: ")) ; Keep error messages | |
1772 | (t | |
1773 | (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines | |
1774 | (setq mh-seq-list (mh-read-folder-sequences folder nil)) | |
1775 | (mh-notate-user-sequences) | |
1776 | (or update | |
1777 | (setq mh-mode-line-annotation | |
1778 | (if (equal range '("all")) | |
1779 | nil | |
1780 | mh-partial-folder-mode-line-annotation))) | |
1781 | (mh-make-folder-mode-line)) | |
1782 | (message "Scanning %s...done" folder))) | |
1783 | ||
1784 | ;;;###mh-autoload | |
1785 | (defun mh-reset-threads-and-narrowing () | |
1786 | "Reset all variables pertaining to threads and narrowing. | |
1787 | Also removes all content from the folder buffer." | |
1788 | (setq mh-view-ops ()) | |
1789 | (setq mh-folder-view-stack ()) | |
1790 | (setq mh-thread-scan-line-map-stack ()) | |
1791 | (let ((buffer-read-only nil)) (erase-buffer))) | |
1792 | ||
1793 | (defun mh-make-folder (name) | |
1794 | "Create a new mail folder called NAME. | |
1795 | Make it the current folder." | |
1796 | (switch-to-buffer name) | |
1797 | (setq buffer-read-only nil) | |
1798 | (erase-buffer) | |
1799 | (if mh-adaptive-cmd-note-flag | |
1800 | (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name)))) | |
1801 | (setq buffer-read-only t) | |
1802 | (mh-folder-mode) | |
1803 | (mh-set-folder-modified-p nil) | |
1804 | (setq buffer-file-name mh-folder-filename) | |
1805 | (when (and (not mh-index-data) | |
1806 | (file-exists-p (concat buffer-file-name mh-index-data-file))) | |
1807 | (mh-index-read-data)) | |
1808 | (mh-make-folder-mode-line)) | |
1809 | ||
1810 | ;;;###mh-autoload | |
1811 | (defun mh-next-msg (&optional wait-after-complaining-flag) | |
1812 | "Move backward or forward to the next undeleted message in the buffer. | |
1813 | If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and | |
1814 | we are at the last message, then wait for a second after telling | |
1815 | the user that there aren't any more unread messages." | |
1816 | (if (eq mh-next-direction 'forward) | |
1817 | (mh-next-undeleted-msg 1 wait-after-complaining-flag) | |
1818 | (mh-previous-undeleted-msg 1 wait-after-complaining-flag))) | |
1819 | ||
1820 | ;;;###mh-autoload | |
1821 | (defun mh-prompt-for-refile-folder () | |
1822 | "Prompt the user for a folder in which the message should be filed. | |
1823 | The folder is returned as a string. | |
1824 | ||
1825 | The default folder name is generated by the option | |
1826 | `mh-default-folder-for-message-function' if it is non-nil or | |
1827 | `mh-folder-from-address'." | |
1828 | (mh-prompt-for-folder | |
1829 | "Destination" | |
1830 | (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t))))) | |
1831 | (if (null refile-file) "" | |
1832 | (save-excursion | |
1833 | (set-buffer (get-buffer-create mh-temp-buffer)) | |
1834 | (erase-buffer) | |
1835 | (insert-file-contents refile-file) | |
1836 | (or (and mh-default-folder-for-message-function | |
1837 | (let ((buffer-file-name refile-file)) | |
1838 | (funcall mh-default-folder-for-message-function))) | |
1839 | (mh-folder-from-address) | |
1840 | (and (eq 'refile (car mh-last-destination-folder)) | |
1841 | (symbol-name (cdr mh-last-destination-folder))) | |
1842 | "")))) | |
1843 | t)) | |
1844 | ||
1845 | ;;;###mh-autoload | |
1846 | (defun mh-folder-from-address () | |
1847 | "Derive folder name from sender. | |
1848 | ||
1849 | The name of the folder is derived as follows: | |
1850 | ||
1851 | a) The folder name associated with the first address found in | |
1852 | the list `mh-default-folder-list' is used. Each element in | |
1853 | this list contains a \"Check Recipient\" item. If this item is | |
1854 | turned on, then the address is checked against the recipient | |
1855 | instead of the sender. This is useful for mailing lists. | |
1856 | ||
1857 | b) An alias prefixed by `mh-default-folder-prefix' | |
1858 | corresponding to the address is used. The prefix is used to | |
1859 | prevent clutter in your mail directory. | |
1860 | ||
1861 | Return nil if a folder name was not derived, or if the variable | |
1862 | `mh-default-folder-must-exist-flag' is t and the folder does not | |
1863 | exist." | |
1864 | ;; Loop for all entries in mh-default-folder-list | |
1865 | (save-restriction | |
1866 | (goto-char (point-min)) | |
1867 | (re-search-forward "\n\n" nil 'limit) | |
1868 | (narrow-to-region (point-min) (point)) | |
1869 | (let ((to/cc (concat (or (message-fetch-field "to") "") ", " | |
1870 | (or (message-fetch-field "cc") ""))) | |
1871 | (from (or (message-fetch-field "from") "")) | |
1872 | folder-name) | |
1873 | (setq folder-name | |
1874 | (loop for list in mh-default-folder-list | |
1875 | when (string-match (nth 0 list) (if (nth 2 list) to/cc from)) | |
1876 | return (nth 1 list) | |
1877 | finally return nil)) | |
1878 | ||
1879 | ;; Make sure a result from `mh-default-folder-list' begins with "+" | |
1880 | ;; since 'mh-expand-file-name below depends on it | |
1881 | (when (and folder-name (not (eq (aref folder-name 0) ?+))) | |
1882 | (setq folder-name (concat "+" folder-name))) | |
1883 | ||
1884 | ;; If not, is there an alias for the address? | |
1885 | (when (not folder-name) | |
1886 | (let* ((from-header (mh-extract-from-header-value)) | |
1887 | (address (and from-header | |
1888 | (nth 1 (mail-extract-address-components | |
1889 | from-header)))) | |
1890 | (alias (and address (mh-alias-address-to-alias address)))) | |
1891 | (when alias | |
1892 | (setq folder-name | |
1893 | (and alias (concat "+" mh-default-folder-prefix alias)))))) | |
1894 | ||
1895 | ;; If mh-default-folder-must-exist-flag set, check that folder exists. | |
1896 | (if (and folder-name | |
1897 | (or (not mh-default-folder-must-exist-flag) | |
1898 | (file-exists-p (mh-expand-file-name folder-name)))) | |
1899 | folder-name)))) | |
1900 | ||
1901 | ;;;###mh-autoload | |
1902 | (defun mh-delete-a-msg (message) | |
1903 | "Delete MESSAGE. | |
1904 | If MESSAGE is nil then the message at point is deleted. | |
1905 | The hook `mh-delete-msg-hook' is called after you mark a message | |
1906 | for deletion. For example, a past maintainer of MH-E used this | |
1907 | once when he kept statistics on his mail usage." | |
1908 | (save-excursion | |
1909 | (if (numberp message) | |
1910 | (mh-goto-msg message nil t) | |
1911 | (beginning-of-line) | |
1912 | (setq message (mh-get-msg-num t))) | |
1913 | (if (looking-at mh-scan-refiled-msg-regexp) | |
1914 | (error "Message %d is refiled; undo refile before deleting" message)) | |
1915 | (if (looking-at mh-scan-deleted-msg-regexp) | |
1916 | nil | |
1917 | (mh-set-folder-modified-p t) | |
1918 | (setq mh-delete-list (cons message mh-delete-list)) | |
1919 | (mh-notate nil mh-note-deleted mh-cmd-note) | |
1920 | (run-hooks 'mh-delete-msg-hook)))) | |
1921 | ||
1922 | ;;;###mh-autoload | |
1923 | (defun mh-refile-a-msg (message folder) | |
1924 | "Refile MESSAGE in FOLDER. | |
1925 | If MESSAGE is nil then the message at point is refiled. | |
1926 | Folder is a symbol, not a string. | |
1927 | The hook `mh-refile-msg-hook' is called after a message is marked to | |
1928 | be refiled." | |
1929 | (save-excursion | |
1930 | (if (numberp message) | |
1931 | (mh-goto-msg message nil t) | |
1932 | (beginning-of-line) | |
1933 | (setq message (mh-get-msg-num t))) | |
1934 | (cond ((looking-at mh-scan-deleted-msg-regexp) | |
1935 | (error "Message %d is deleted; undo delete before moving" message)) | |
1936 | ((looking-at mh-scan-refiled-msg-regexp) | |
1937 | (if (y-or-n-p | |
1938 | (format "Message %d already refiled; copy to %s as well? " | |
1939 | message folder)) | |
1940 | (mh-exec-cmd "refile" (mh-get-msg-num t) "-link" | |
1941 | "-src" mh-current-folder | |
1942 | (symbol-name folder)) | |
1943 | (message "Message not copied"))) | |
1944 | (t | |
1945 | (mh-set-folder-modified-p t) | |
1946 | (cond ((null (assoc folder mh-refile-list)) | |
1947 | (push (list folder message) mh-refile-list)) | |
1948 | ((not (member message (cdr (assoc folder mh-refile-list)))) | |
1949 | (push message (cdr (assoc folder mh-refile-list))))) | |
1950 | (mh-notate nil mh-note-refiled mh-cmd-note) | |
1951 | (run-hooks 'mh-refile-msg-hook))))) | |
1952 | ||
1953 | (defun mh-undo-msg (msg) | |
1954 | "Undo the deletion or refile of one MSG. | |
1955 | If MSG is nil then act on the message at point" | |
1956 | (save-excursion | |
1957 | (if (numberp msg) | |
1958 | (mh-goto-msg msg t t) | |
1959 | (beginning-of-line) | |
1960 | (setq msg (mh-get-msg-num t))) | |
1961 | (cond ((memq msg mh-delete-list) | |
1962 | (setq mh-delete-list (delq msg mh-delete-list))) | |
1963 | (t | |
1964 | (dolist (folder-msg-list mh-refile-list) | |
1965 | (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list)))) | |
1966 | (setq mh-refile-list (loop for x in mh-refile-list | |
1967 | unless (null (cdr x)) collect x)))) | |
1968 | (mh-notate nil ? mh-cmd-note))) | |
1969 | ||
1970 | ;;;###mh-autoload | |
1971 | (defun mh-msg-filename (msg &optional folder) | |
1972 | "Return the file name of MSG in FOLDER (default current folder)." | |
1973 | (expand-file-name (int-to-string msg) | |
1974 | (if folder | |
1975 | (mh-expand-file-name folder) | |
1976 | mh-folder-filename))) | |
1977 | ||
1978 | (provide 'mh-folder) | |
1979 | ||
1980 | ;; Local Variables: | |
1981 | ;; indent-tabs-mode: nil | |
1982 | ;; sentence-end-double-space: nil | |
1983 | ;; End: | |
1984 | ||
a1ab640d | 1985 | ;; arch-tag: aa97b758-d4f6-4c86-bc5a-1950921da1e7 |
dda00b2c | 1986 | ;;; mh-folder.el ends here |