6365
|
1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system
|
|
2
|
|
3 ;;; Copyright 1985,86,87,88,90,92,93 Free Software Foundation
|
|
4
|
|
5 (defconst mh-e-time-stamp "Time-stamp: <94/03/14 18:34:22 gildea>")
|
|
6 (defconst mh-e-version "4.0"
|
|
7 "Version numbers of this version of mh-e.")
|
|
8
|
|
9 ;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
|
|
10 ;; Version: 4.0
|
|
11 ;; Keywords: mail
|
|
12
|
|
13 ;; mh-e is free software; you can redistribute it and/or modify
|
|
14 ;; it under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; mh-e is distributed in the hope that it will be useful,
|
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with mh-e; see the file COPYING. If not, write to
|
|
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;;; HOW TO USE:
|
|
30 ;;; M-x mh-rmail to read mail. Type C-h m there for a list of commands.
|
|
31 ;;; C-u M-x mh-rmail to visit any folder.
|
|
32 ;;; M-x mh-smail to send mail. From within the mail reader, "m" works, too.
|
|
33 ;;; Your .emacs might benefit from these bindings:
|
|
34 ;;; (global-set-key "\C-cr" 'mh-rmail)
|
|
35 ;;; (global-set-key "\C-xm" 'mh-smail)
|
|
36 ;;; (global-set-key "\C-x4m" 'mh-smail-other-window)
|
|
37
|
|
38 ;;; MH (Message Handler) is a powerful mail reader. The MH newsgroup
|
|
39 ;;; is comp.mail.mh; the mailing list is mh-users@ics.uci.edu (send to
|
|
40 ;;; mh-users-request to be added). See the monthly Frequently Asked
|
|
41 ;;; Questions posting there for information on getting MH.
|
|
42
|
|
43 ;;; mh-e works with Emacs 18 or 19, and MH 5 or 6.
|
|
44
|
|
45 ;;; NB. MH must have been compiled with the MHE compiler flag or several
|
|
46 ;;; features necessary mh-e will be missing from MH commands, specifically
|
|
47 ;;; the -build switch to repl and forw.
|
|
48
|
|
49 ;;; Change Log:
|
|
50
|
|
51 ;;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
|
|
52 ;;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
|
|
53 ;;; Rewritten for GNU Emacs, James Larus 1985. larus@ginger.berkeley.edu
|
|
54 ;;; Modified by Stephen Gildea 1988. gildea@lcs.mit.edu
|
|
55 (defconst mh-e-RCS-id "$Header: mh-e.el,v 3.14 94/03/14 18:34:49 gildea Exp $")
|
|
56
|
|
57 ;;; Code:
|
|
58
|
|
59 (provide 'mh-e)
|
|
60 (require 'mh-utils)
|
|
61
|
|
62
|
|
63 ;;; Site customization:
|
|
64
|
|
65 ;;; Set for local environment:
|
|
66 ;;; mh-progs and mh-lib used to be set in paths.el, which tried to
|
|
67 ;;; figure out at build time which of several possible directories MH
|
|
68 ;;; was installed into. But if you installed MH after building Emacs,
|
|
69 ;;; this would almost certainly be wrong, so now we do it at run time.
|
|
70
|
|
71 (defvar mh-progs nil
|
|
72 "Directory containing MH commands, such as inc, repl, and rmm.")
|
|
73
|
|
74 (defvar mh-lib nil
|
|
75 "Directory containing the MH library.
|
|
76 This directory contains, among other things,
|
|
77 the mhl program and the components file.")
|
|
78
|
|
79 (defvar mh-redist-full-contents nil
|
|
80 "Non-nil if the `dist' command needs whole letter for redistribution.
|
|
81 This is the case when `send' is compiled with the BERK option.
|
|
82 If MH will not allow you to redist a previously redist'd msg, set to nil.")
|
|
83
|
|
84 ;;; Hooks:
|
|
85
|
|
86 (defvar mh-folder-mode-hook nil
|
|
87 "Invoked in `mh-folder mode' on a new folder.")
|
|
88
|
|
89 (defvar mh-inc-folder-hook nil
|
|
90 "Invoked by \\<mh-folder-mode-map>`\\[mh-inc-folder]' after incorporating mail into a folder.")
|
|
91
|
|
92 (defvar mh-show-hook nil
|
|
93 "Invoked after \\<mh-folder-mode-map>`\\[mh-show]' shows a message.")
|
|
94
|
|
95 (defvar mh-show-mode-hook nil
|
|
96 "Invoked in mh-show mode in each message.")
|
|
97
|
|
98 (defvar mh-delete-msg-hook nil
|
|
99 "Invoked after marking each message for deletion.")
|
|
100
|
|
101 (defvar mh-refile-msg-hook nil
|
|
102 "Invoked after marking each message for refiling.")
|
|
103
|
|
104 (defvar mh-before-quit-hook nil
|
|
105 "Invoked by \\<mh-folder-mode-map>`\\[mh-quit]' before quitting mh-e. See also mh-quit-hook.")
|
|
106
|
|
107 (defvar mh-quit-hook nil
|
|
108 "Invoked after \\<mh-folder-mode-map>`\\[mh-quit]' quits mh-e. See also mh-before-quit-hook.")
|
|
109
|
|
110
|
|
111
|
|
112 ;;; Personal preferences:
|
|
113
|
|
114 (defvar mh-lpr-command-format "lpr -p -J '%s'"
|
|
115 "*Format for Unix command that prints a message.
|
|
116 The string should be a Unix command line, with the string '%s' where
|
|
117 the job's name (folder and message number) should appear. The formatted
|
|
118 message text is piped to this command when you type \\<mh-folder-mode-map>`\\[mh-print-msg]'.")
|
|
119
|
|
120 (defvar mh-scan-prog "scan"
|
|
121 "*Program to run to generate one-line-per-message listing of a folder.
|
|
122 Normally \"scan\" or a file name linked to scan. This file is searched
|
|
123 for relative to the mh-progs directory unless it is an absolute pathname.
|
|
124 Automatically becomes buffer-local when set in any fashion.")
|
|
125 (make-variable-buffer-local 'mh-scan-prog)
|
|
126
|
|
127 (defvar mh-inc-prog "inc"
|
|
128 "*Program to run to incorporate new mail into a folder.
|
|
129 Normally \"inc\". This file is searched for relative to
|
|
130 the mh-progs directory unless it is an absolute pathname.")
|
|
131
|
|
132 (defvar mh-print-background nil
|
|
133 "*Print messages in the background if non-nil.
|
|
134 WARNING: do not delete the messages until printing is finished;
|
|
135 otherwise, your output may be truncated.")
|
|
136
|
|
137 (defvar mh-recenter-summary-p nil
|
|
138 "*Recenter summary window when the show window is toggled off if non-nil.")
|
|
139
|
|
140 (defvar mh-ins-buf-prefix "> "
|
|
141 "*String to put before each non-blank line of a yanked or inserted message.
|
|
142 \\<mh-letter-mode-map>Used when the message is inserted into an outgoing letter
|
|
143 by \\[mh-insert-letter] or \\[mh-yank-cur-msg].")
|
|
144
|
|
145 (defvar mh-do-not-confirm nil
|
|
146 "*Non-nil means do not prompt for confirmation before some mh-e commands.
|
|
147 Affects non-recoverable commands such as mh-kill-folder and mh-undo-folder.")
|
|
148
|
|
149 (defvar mh-store-default-directory nil
|
|
150 "*Last directory used by \\[mh-store-msg]; default for next store.
|
|
151 A directory name string, or nil to use current directory.")
|
|
152
|
|
153 ;;; Parameterize mh-e to work with different scan formats. The defaults work
|
|
154 ;;; with the standard MH scan listings, in which the first 4 characters on
|
|
155 ;;; the line are the message number, followed by two places for notations.
|
|
156
|
|
157 (defvar mh-good-msg-regexp "^....[^D^]"
|
|
158 "Regexp specifiying the scan lines that are 'good' messages.")
|
|
159
|
|
160 (defvar mh-deleted-msg-regexp "^....D"
|
|
161 "Regexp matching scan lines of deleted messages.")
|
|
162
|
|
163 (defvar mh-refiled-msg-regexp "^....\\^"
|
|
164 "Regexp matching scan lines of refiled messages.")
|
|
165
|
|
166 (defvar mh-valid-scan-line "^ *[0-9]"
|
|
167 "Regexp matching scan lines for messages (not error messages).")
|
|
168
|
|
169 (defvar mh-flagged-scan-msg-regexp "^....\\D\\|^....\\^\\|^....\\+\\|^.....%"
|
|
170 "Regexp matching flagged scan lines.
|
|
171 Matches lines marked as deleted, refiled, in a sequence, or the cur message.")
|
|
172
|
|
173 (defvar mh-cur-scan-msg-regexp "^....\\+"
|
|
174 "Regexp matching scan line for the cur message.")
|
|
175
|
|
176 (defvar mh-show-buffer-mode-line-buffer-id "{show-%s} %d"
|
|
177 "Format string to produce `mode-line-buffer-identification' for show buffers.
|
|
178 First argument is folder name. Second is message number.")
|
|
179
|
|
180 (defvar mh-partial-folder-mode-line-annotation "select"
|
|
181 "Annotation when displaying part of a folder.
|
|
182 The string is displayed after the folder's name. NIL for no annotation.")
|
|
183
|
|
184
|
|
185 ;;; Internal variables:
|
|
186
|
|
187 (defvar mh-last-destination nil
|
|
188 "Destination of last refile or write command.")
|
|
189
|
|
190 (defvar mh-folder-mode-map (make-keymap)
|
|
191 "Keymap for MH folders.")
|
|
192
|
|
193 (defvar mh-next-seq-num nil
|
|
194 "Index of free sequence id.")
|
|
195
|
|
196 (defvar mh-delete-list nil
|
|
197 "List of msg numbers to delete.")
|
|
198
|
|
199 (defvar mh-refile-list nil
|
|
200 "List of folder names in mh-seq-list.")
|
|
201
|
|
202 (defvar mh-next-direction 'forward
|
|
203 "Direction to move to next message.")
|
|
204
|
|
205 (defvar mh-narrowed-to-seq nil
|
|
206 "Sequence display is narrowed to.")
|
|
207
|
|
208 (defvar mh-first-msg-num nil
|
|
209 "Number of first msg in buffer.")
|
|
210
|
|
211 (defvar mh-last-msg-num nil
|
|
212 "Number of last msg in buffer.")
|
|
213
|
|
214
|
|
215 ;;; Macros and generic functions:
|
|
216
|
|
217 (defun mh-mapc (func list)
|
|
218 (while list
|
|
219 (funcall func (car list))
|
|
220 (setq list (cdr list))))
|
|
221
|
|
222
|
|
223
|
|
224 ;;; Entry points:
|
|
225
|
|
226 ;;;###autoload
|
|
227 (defun mh-rmail (&optional arg)
|
|
228 "Inc(orporate) new mail with MH, or, with arg, scan an MH mail folder.
|
|
229 This function is an entry point to mh-e, the Emacs front end
|
|
230 to the MH mail system."
|
|
231 (interactive "P")
|
|
232 (mh-find-path)
|
|
233 (if arg
|
|
234 (call-interactively 'mh-visit-folder)
|
|
235 (mh-inc-folder)))
|
|
236
|
|
237
|
|
238 ;;; mh-smail and mh-smail-other-window have been moved to the new file
|
|
239 ;;; mh-comp.el, but Emacs 18 still looks for them here, so provide a
|
|
240 ;;; definition here, too, for a while.
|
|
241
|
|
242 (defun mh-smail ()
|
|
243 "Compose and send mail with the MH mail system.
|
|
244 This function is an entry point to mh-e, the Emacs front end
|
|
245 to the MH mail system."
|
|
246 (interactive)
|
|
247 (mh-find-path)
|
|
248 (require 'mh-comp)
|
|
249 (call-interactively 'mh-send))
|
|
250
|
|
251
|
|
252 (defun mh-smail-other-window ()
|
|
253 "Compose and send mail in other window with the MH mail system.
|
|
254 This function is an entry point to mh-e, the Emacs front end
|
|
255 to the MH mail system."
|
|
256 (interactive)
|
|
257 (mh-find-path)
|
|
258 (require 'mh-comp)
|
|
259 (call-interactively 'mh-send-other-window))
|
|
260
|
|
261
|
|
262
|
|
263 ;;; User executable mh-e commands:
|
|
264
|
|
265
|
|
266 (defun mh-delete-msg (msg-or-seq)
|
|
267 "Mark the specified MESSAGE(s) for subsequent deletion and move to the next.
|
|
268 Default is the displayed message. If optional prefix argument is
|
|
269 given then prompt for the message sequence."
|
|
270 (interactive (list (if current-prefix-arg
|
|
271 (mh-read-seq-default "Delete" t)
|
|
272 (mh-get-msg-num t))))
|
|
273 (mh-delete-msg-no-motion msg-or-seq)
|
|
274 (mh-next-msg))
|
|
275
|
|
276
|
|
277 (defun mh-delete-msg-no-motion (msg-or-seq)
|
|
278 "Mark the specified MESSAGE(s) for subsequent deletion.
|
|
279 Default is the displayed message. If optional prefix argument is
|
|
280 provided, then prompt for the message sequence."
|
|
281 (interactive (list (if current-prefix-arg
|
|
282 (mh-read-seq-default "Delete" t)
|
|
283 (mh-get-msg-num t))))
|
|
284 (if (numberp msg-or-seq)
|
|
285 (mh-delete-a-msg msg-or-seq)
|
|
286 (mh-map-to-seq-msgs 'mh-delete-a-msg msg-or-seq)))
|
|
287
|
|
288
|
|
289 (defun mh-execute-commands ()
|
|
290 "Process outstanding delete and refile requests."
|
|
291 (interactive)
|
|
292 (if mh-narrowed-to-seq (mh-widen))
|
|
293 (mh-process-commands mh-current-folder)
|
|
294 (mh-set-scan-mode)
|
|
295 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
|
|
296 (mh-make-folder-mode-line)
|
|
297 t) ; return t for write-file-hooks
|
|
298
|
|
299
|
|
300 (defun mh-first-msg ()
|
|
301 "Move to the first message."
|
|
302 (interactive)
|
|
303 (goto-char (point-min)))
|
|
304
|
|
305
|
|
306 (defun mh-header-display ()
|
|
307 "Show the current message with all its headers.
|
|
308 Displays headers that might have been suppressed by mh-clean-message-header,
|
|
309 mhl-formfile, or the fallback behavior of scrolling uninteresting headers
|
|
310 off the top of the window. Type \"\\[mh-show]\" to show the message
|
|
311 normally again."
|
|
312 (interactive)
|
|
313 (and (not mh-showing-with-headers)
|
|
314 (or mhl-formfile mh-clean-message-header)
|
|
315 (mh-invalidate-show-buffer))
|
|
316 (let ((mhl-formfile nil)
|
|
317 (mh-clean-message-header nil))
|
|
318 (mh-show-msg nil)
|
|
319 (mh-in-show-buffer (mh-show-buffer)
|
|
320 (goto-char (point-min))
|
|
321 (mh-recenter 0))
|
|
322 (setq mh-showing-with-headers t)))
|
|
323
|
|
324
|
|
325 (defun mh-inc-folder (&optional maildrop-name)
|
|
326 "Inc(orporate)s new mail into +inbox.
|
|
327 Optional prefix argument specifies an alternate maildrop from the default.
|
|
328 If this is given, incorporates mail into the current folder, rather
|
|
329 than +inbox. Runs `mh-inc-folder-hook' after incorporating new mail.
|
|
330 Do not call this function from outside mh-e; use \\[mh-rmail] instead."
|
|
331 (interactive (list (if current-prefix-arg
|
|
332 (expand-file-name
|
|
333 (read-file-name "inc mail from file: "
|
|
334 mh-user-path)))))
|
|
335 (let ((config (current-window-configuration)))
|
|
336 (if (not maildrop-name)
|
|
337 (cond ((not (get-buffer "+inbox"))
|
|
338 (mh-make-folder "+inbox")
|
|
339 (setq mh-previous-window-config config))
|
|
340 ((not (eq (current-buffer) (get-buffer "+inbox")))
|
|
341 (switch-to-buffer "+inbox")
|
|
342 (setq mh-previous-window-config config)))))
|
|
343 (mh-get-new-mail maildrop-name)
|
|
344 (run-hooks 'mh-inc-folder-hook))
|
|
345
|
|
346
|
|
347 (defun mh-last-msg ()
|
|
348 "Move to the last message."
|
|
349 (interactive)
|
|
350 (goto-char (point-max))
|
|
351 (while (and (not (bobp)) (looking-at "^$"))
|
|
352 (forward-line -1)))
|
|
353
|
|
354
|
|
355 (defun mh-next-undeleted-msg (&optional arg)
|
|
356 "Move to next undeleted message in window."
|
|
357 (interactive "P")
|
|
358 (forward-line (prefix-numeric-value arg))
|
|
359 (setq mh-next-direction 'forward)
|
|
360 (cond ((re-search-forward mh-good-msg-regexp nil 0 arg)
|
|
361 (beginning-of-line)
|
|
362 (mh-maybe-show))
|
|
363 (t
|
|
364 (forward-line -1)
|
|
365 (if (get-buffer mh-show-buffer)
|
|
366 (delete-windows-on mh-show-buffer)))))
|
|
367
|
|
368
|
|
369 (defun mh-refile-msg (msg-or-seq dest)
|
|
370 "Refile MESSAGE(s) (default: displayed message) in FOLDER.
|
|
371 If optional prefix argument provided, then prompt for message sequence."
|
|
372 (interactive
|
|
373 (list (if current-prefix-arg
|
|
374 (mh-read-seq-default "Refile" t)
|
|
375 (mh-get-msg-num t))
|
|
376 (intern
|
|
377 (mh-prompt-for-folder
|
|
378 "Destination"
|
|
379 (or (and mh-msg-folder-hook
|
|
380 (let ((file-name (mh-msg-filename (mh-get-msg-num t))))
|
|
381 (save-excursion
|
|
382 (set-buffer (get-buffer-create " *mh-temp*"))
|
|
383 (erase-buffer)
|
|
384 (insert-file-contents file-name)
|
|
385 (let ((buffer-file-name file-name))
|
|
386 (funcall mh-msg-folder-hook)))))
|
|
387 (and (eq 'refile (car mh-last-destination))
|
|
388 (symbol-name (cdr mh-last-destination)))
|
|
389 "")
|
|
390 t))))
|
|
391 (setq mh-last-destination (cons 'refile dest))
|
|
392 (if (numberp msg-or-seq)
|
|
393 (mh-refile-a-msg msg-or-seq dest)
|
|
394 (mh-map-to-seq-msgs 'mh-refile-a-msg msg-or-seq dest))
|
|
395 (mh-next-msg))
|
|
396
|
|
397
|
|
398 (defun mh-refile-or-write-again (msg)
|
|
399 "Re-execute the last refile or write command on the given MESSAGE.
|
|
400 Default is the displayed message. Use the same folder or file as the
|
|
401 previous refile or write command."
|
|
402 (interactive (list (mh-get-msg-num t)))
|
|
403 (if (null mh-last-destination)
|
|
404 (error "No previous refile or write"))
|
|
405 (cond ((eq (car mh-last-destination) 'refile)
|
|
406 (mh-refile-a-msg msg (cdr mh-last-destination))
|
|
407 (message "Destination folder: %s" (cdr mh-last-destination)))
|
|
408 (t
|
|
409 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination))
|
|
410 (message "Destination: %s" (cdr mh-last-destination))))
|
|
411 (mh-next-msg))
|
|
412
|
|
413
|
|
414 (defun mh-quit ()
|
|
415 "Quit mh-e.
|
|
416 Start by running mh-before-quit-hook. Restore the previous window
|
|
417 configuration, if one exists. Finish by running mh-quit-hook."
|
|
418 (interactive)
|
|
419 (run-hooks 'mh-before-quit-hook)
|
|
420 (mh-update-unseen)
|
|
421 (mh-invalidate-show-buffer)
|
|
422 (bury-buffer (current-buffer))
|
|
423 (if (get-buffer mh-show-buffer)
|
|
424 (bury-buffer mh-show-buffer))
|
|
425 (if mh-previous-window-config
|
|
426 (set-window-configuration mh-previous-window-config))
|
|
427 (run-hooks 'mh-quit-hook))
|
|
428
|
|
429 (defun mh-page-msg (&optional arg)
|
|
430 "Page the displayed message forwards.
|
|
431 Scrolls ARG lines or a full screen if no argument is supplied."
|
|
432 (interactive "P")
|
|
433 (scroll-other-window arg))
|
|
434
|
|
435
|
|
436 (defun mh-previous-page (&optional arg)
|
|
437 "Page the displayed message backwards.
|
|
438 Scrolls ARG lines or a full screen if no argument is supplied."
|
|
439 (interactive "P")
|
|
440 (mh-in-show-buffer (mh-show-buffer)
|
|
441 (scroll-down arg)))
|
|
442
|
|
443
|
|
444 (defun mh-previous-undeleted-msg (&optional arg)
|
|
445 "Move to previous undeleted message in window."
|
|
446 (interactive "p")
|
|
447 (setq mh-next-direction 'backward)
|
|
448 (beginning-of-line)
|
|
449 (cond ((re-search-backward mh-good-msg-regexp nil 0 arg)
|
|
450 (mh-maybe-show))
|
|
451 (t
|
|
452 (if (get-buffer mh-show-buffer)
|
|
453 (delete-windows-on mh-show-buffer)))))
|
|
454
|
|
455
|
|
456 (defun mh-rescan-folder (&optional range)
|
|
457 "Rescan a folder after optionally processing the outstanding commands.
|
|
458 If optional prefix argument is provided, prompt for the range of
|
|
459 messages to display. Otherwise show the entire folder."
|
|
460 (interactive (list (if current-prefix-arg
|
|
461 (mh-read-msg-range "Range to scan [all]? ")
|
|
462 nil)))
|
|
463 (setq mh-next-direction 'forward)
|
|
464 (mh-scan-folder mh-current-folder (or range "all")))
|
|
465
|
|
466
|
|
467 (defun mh-write-msg-to-file (msg file no-headers)
|
|
468 "Append MESSAGE to the end of a FILE.
|
|
469 If NO-HEADERS (prefix argument) is provided, write only the message body.
|
|
470 Otherwise send the entire message including the headers."
|
|
471 (interactive
|
|
472 (list (mh-get-msg-num t)
|
|
473 (let ((default-dir (if (eq 'write (car mh-last-destination))
|
|
474 (file-name-directory (car (cdr mh-last-destination)))
|
|
475 default-directory)))
|
|
476 (read-file-name "Save message in file: " default-dir
|
|
477 (expand-file-name "mail.out" default-dir)))
|
|
478 current-prefix-arg))
|
|
479 (let ((file-name (mh-msg-filename msg))
|
|
480 (output-file (mh-expand-file-name file)))
|
|
481 (setq mh-last-destination (list 'write file no-headers))
|
|
482 (save-excursion
|
|
483 (set-buffer (get-buffer-create " *mh-temp*"))
|
|
484 (erase-buffer)
|
|
485 (insert-file-contents file-name)
|
|
486 (goto-char (point-min))
|
|
487 (if no-headers (search-forward "\n\n"))
|
|
488 (append-to-file (point) (point-max) output-file))))
|
|
489
|
|
490
|
|
491 (defun mh-toggle-showing ()
|
|
492 "Toggle the scanning mode/showing mode of displaying messages."
|
|
493 (interactive)
|
|
494 (if mh-showing
|
|
495 (mh-set-scan-mode)
|
|
496 (mh-show)))
|
|
497
|
|
498
|
|
499 (defun mh-undo (msg-or-seq)
|
|
500 "Undo the deletion or refile of the specified MESSAGE(s).
|
|
501 Default is the displayed message. If optional prefix argument is
|
|
502 provided, then prompt for the message sequence."
|
|
503 (interactive (list (if current-prefix-arg
|
|
504 (mh-read-seq-default "Undo" t)
|
|
505 (mh-get-msg-num t))))
|
|
506 (cond ((numberp msg-or-seq)
|
|
507 (let ((original-position (point)))
|
|
508 (beginning-of-line)
|
|
509 (while (not (or (looking-at mh-deleted-msg-regexp)
|
|
510 (looking-at mh-refiled-msg-regexp)
|
|
511 (and (eq mh-next-direction 'forward) (bobp))
|
|
512 (and (eq mh-next-direction 'backward)
|
|
513 (save-excursion (forward-line) (eobp)))))
|
|
514 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
|
|
515 (if (or (looking-at mh-deleted-msg-regexp)
|
|
516 (looking-at mh-refiled-msg-regexp))
|
|
517 (progn
|
|
518 (mh-undo-msg (mh-get-msg-num t))
|
|
519 (mh-maybe-show))
|
|
520 (goto-char original-position)
|
|
521 (error "Nothing to undo"))))
|
|
522 (t
|
|
523 (mh-mapc (function mh-undo-msg) (mh-seq-to-msgs msg-or-seq))))
|
|
524 ;; update the mh-refile-list so mh-outstanding-commands-p will work
|
|
525 (mh-mapc (function
|
|
526 (lambda (elt)
|
|
527 (if (not (mh-seq-to-msgs elt))
|
|
528 (setq mh-refile-list (delq elt mh-refile-list)))))
|
|
529 mh-refile-list)
|
|
530 (if (not (mh-outstanding-commands-p))
|
|
531 (mh-set-folder-modified-p nil)))
|
|
532
|
|
533
|
|
534 (defun mh-version ()
|
|
535 "Display version information about mh-e and MH."
|
|
536 (interactive)
|
|
537 (mh-find-progs)
|
|
538 (set-buffer (get-buffer-create " *mh-temp*"))
|
|
539 (erase-buffer)
|
|
540 (insert " mh-e info:\n\nversion: " mh-e-version "\n" mh-e-time-stamp
|
|
541 "\nEmacs: " emacs-version " on " (symbol-name system-type) " ")
|
|
542 (condition-case ()
|
|
543 (call-process "uname" nil t nil "-a")
|
|
544 (file-error))
|
|
545 (insert "\n\n MH info:\n\n" (expand-file-name "inc" mh-progs) ":\n")
|
|
546 (let ((help-start (point)))
|
|
547 (condition-case err-data
|
|
548 (mh-exec-cmd-output "inc" nil "-help")
|
|
549 (file-error (insert (mapconcat 'concat (cdr err-data) ": "))))
|
|
550 (goto-char help-start)
|
|
551 (search-forward "version: " nil t)
|
|
552 (beginning-of-line)
|
|
553 (delete-region help-start (point))
|
|
554 (goto-char (point-min)))
|
|
555 (display-buffer " *mh-temp*"))
|
|
556
|
|
557
|
|
558 (defun mh-visit-folder (folder &optional range)
|
|
559 "Visits FOLDER and displays RANGE of messages.
|
|
560 Assumes mh-e has already been initialized.
|
|
561 Do not call this function from outside mh-e; see \\[mh-rmail] instead."
|
|
562 (interactive (list (mh-prompt-for-folder "Visit" "+inbox" t)
|
|
563 (mh-read-msg-range "Range [all]? ")))
|
|
564 (let ((config (current-window-configuration)))
|
|
565 (mh-scan-folder folder (or range "all"))
|
|
566 (setq mh-previous-window-config config))
|
|
567 nil)
|
|
568
|
|
569
|
|
570 (defun mh-compat-quit ()
|
|
571 "\"b\" reserved for future use as mh-burst-digest; will assume you want \"\\[mh-quit]\" ..."
|
|
572 ;; This is a temporary compatibility function
|
|
573 (interactive)
|
|
574 (message "%s" (documentation this-command))
|
|
575 (sit-for 1)
|
|
576 (call-interactively 'mh-quit))
|
|
577
|
|
578
|
|
579
|
|
580 ;;; Support routines.
|
|
581
|
|
582 (defun mh-delete-a-msg (msg)
|
|
583 ;; Delete the MESSAGE.
|
|
584 (save-excursion
|
|
585 (mh-goto-msg msg nil t)
|
|
586 (if (looking-at mh-refiled-msg-regexp)
|
|
587 (error "Message %d is refiled. Undo refile before deleting." msg))
|
|
588 (if (looking-at mh-deleted-msg-regexp)
|
|
589 nil
|
|
590 (mh-set-folder-modified-p t)
|
|
591 (setq mh-delete-list (cons msg mh-delete-list))
|
|
592 (mh-add-msgs-to-seq msg 'deleted t)
|
|
593 (mh-notate msg ?D mh-cmd-note)
|
|
594 (run-hooks 'mh-delete-msg-hook))))
|
|
595
|
|
596 (defun mh-refile-a-msg (msg destination)
|
|
597 ;; Refile MESSAGE in FOLDER. FOLDER is a symbol, not a string.
|
|
598 (save-excursion
|
|
599 (mh-goto-msg msg nil t)
|
|
600 (cond ((looking-at mh-deleted-msg-regexp)
|
|
601 (error "Message %d is deleted. Undo delete before moving." msg))
|
|
602 ((looking-at mh-refiled-msg-regexp)
|
|
603 (if (y-or-n-p
|
|
604 (format "Message %d already refiled. Copy to %s as well? "
|
|
605 msg destination))
|
|
606 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
|
|
607 "-src" mh-current-folder
|
|
608 (symbol-name destination))
|
|
609 (message "Message not copied.")))
|
|
610 (t
|
|
611 (mh-set-folder-modified-p t)
|
|
612 (if (not (memq destination mh-refile-list))
|
|
613 (setq mh-refile-list (cons destination mh-refile-list)))
|
|
614 (if (not (memq msg (mh-seq-to-msgs destination)))
|
|
615 (mh-add-msgs-to-seq msg destination t))
|
|
616 (mh-notate msg ?^ mh-cmd-note)
|
|
617 (run-hooks 'mh-refile-msg-hook)))))
|
|
618
|
|
619
|
|
620 (defun mh-next-msg ()
|
|
621 ;; Move backward or forward to the next undeleted message in the buffer.
|
|
622 (if (eq mh-next-direction 'forward)
|
|
623 (mh-next-undeleted-msg 1)
|
|
624 (mh-previous-undeleted-msg 1)))
|
|
625
|
|
626
|
|
627 (defun mh-set-scan-mode ()
|
|
628 ;; Display the scan listing buffer, but do not show a message.
|
|
629 (if (get-buffer mh-show-buffer)
|
|
630 (delete-windows-on mh-show-buffer))
|
|
631 (setq mh-showing nil)
|
|
632 (set-buffer-modified-p (buffer-modified-p)) ;force mode line update
|
|
633 (if mh-recenter-summary-p
|
|
634 (mh-recenter nil)))
|
|
635
|
|
636
|
|
637 (defun mh-undo-msg (msg)
|
|
638 ;; Undo the deletion or refile of one MESSAGE.
|
|
639 (cond ((memq msg mh-delete-list)
|
|
640 (setq mh-delete-list (delq msg mh-delete-list))
|
|
641 (mh-delete-msg-from-seq msg 'deleted t))
|
|
642 (t
|
|
643 (mh-mapc (function (lambda (dest)
|
|
644 (mh-delete-msg-from-seq msg dest t)))
|
|
645 mh-refile-list)))
|
|
646 (mh-notate msg ? mh-cmd-note))
|
|
647
|
|
648
|
|
649
|
|
650
|
|
651 ;;; The folder data abstraction.
|
|
652
|
|
653 (defun mh-make-folder (name)
|
|
654 ;; Create and initialize a new mail folder called NAME and make it the
|
|
655 ;; current folder.
|
|
656 (switch-to-buffer name)
|
|
657 (setq buffer-read-only nil)
|
|
658 (erase-buffer)
|
|
659 (setq buffer-read-only t)
|
|
660 (mh-folder-mode)
|
|
661 (mh-set-folder-modified-p nil)
|
|
662 (setq buffer-file-name mh-folder-filename))
|
|
663
|
|
664
|
|
665 ;;; Ensure new buffers won't get this mode if default-major-mode is nil.
|
|
666 (put 'mh-folder-mode 'mode-class 'special)
|
|
667
|
|
668 (defun mh-folder-mode ()
|
|
669 "Major mh-e mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
|
|
670 You can show the message the cursor is pointing to, and step through the
|
|
671 messages. Messages can be marked for deletion or refiling into another
|
|
672 folder; these commands are executed all at once with a separate command.
|
|
673
|
|
674 A prefix argument (\\[universal-argument]) to delete, refile, list, or undo
|
|
675 applies the action to a message sequence.
|
|
676
|
|
677 Here is a list of the standard keys for mh-e commands, grouped by function.
|
|
678 This list is purposefully not customized; mh-e has a long history, and many
|
|
679 alternate key bindings as a result. This list is to encourage users to use
|
|
680 standard keys so the other keys can perhaps someday be put to new uses.
|
|
681
|
|
682 t toggle show or scan-only mode
|
|
683 . show message, or back to top if already showing
|
|
684
|
|
685 SPC page forward
|
|
686 DEL page back
|
|
687
|
|
688 n next message
|
|
689 p previous message
|
|
690 j jump to message by number
|
|
691
|
|
692 d mark for deletion
|
|
693 o, ^ mark for output (refile) to another folder
|
|
694 ? show folder of pending refile
|
|
695 u undo delete or refile marking
|
|
696
|
|
697 x execute marked deletes and refiles
|
|
698 i incorporate new mail
|
|
699
|
|
700 m mail a new message
|
|
701 r reply to a message
|
|
702 f forward a message
|
|
703
|
|
704 q quit mh-e
|
|
705
|
|
706 M-f visit new folder
|
|
707 M-r rescan this folder
|
|
708
|
|
709 Here are all the commands with their current binding, listed in key order:
|
|
710 \\{mh-folder-mode-map}
|
|
711
|
|
712 Variables controlling mh-e operation are (defaults in parentheses):
|
|
713
|
|
714 mh-recursive-folders (nil)
|
|
715 Non-nil means commands which operate on folders do so recursively.
|
|
716
|
|
717 mh-bury-show-buffer (t)
|
|
718 Non-nil means that the buffer used to display message is buried.
|
|
719 It will never be offered as the default other buffer.
|
|
720
|
|
721 mh-clean-message-header (nil)
|
|
722 Non-nil means remove header lines matching the regular expression
|
|
723 specified in mh-invisible-headers from messages.
|
|
724
|
|
725 mh-visible-headers (nil)
|
|
726 If non-nil, it contains a regexp specifying the headers that are shown in
|
|
727 a message if mh-clean-message-header is non-nil. Setting this variable
|
|
728 overrides mh-invisible-headers.
|
|
729
|
|
730 mh-do-not-confirm (nil)
|
|
731 Non-nil means do not prompt for confirmation before executing some
|
|
732 non-recoverable commands such as mh-kill-folder and mh-undo-folder.
|
|
733
|
|
734 mhl-formfile (nil)
|
|
735 Name of format file to be used by mhl to show messages.
|
|
736 A value of T means use the default format file.
|
|
737 Nil means don't use mhl to format messages.
|
|
738
|
|
739 mh-lpr-command-format (\"lpr -p -J '%s'\")
|
|
740 Format for command used to print a message on a system printer.
|
|
741
|
|
742 mh-scan-prog (\"scan\")
|
|
743 Program to run to generate one-line-per-message listing of a folder.
|
|
744 Normally \"scan\" or a file name linked to scan. This file is searched
|
|
745 for relative to the mh-progs directory unless it is an absolute pathname.
|
|
746 Automatically becomes buffer-local when set in any fashion.
|
|
747
|
|
748 mh-print-background (nil)
|
|
749 Print messages in the background if non-nil.
|
|
750 WARNING: do not delete the messages until printing is finished;
|
|
751 otherwise, your output may be truncated.
|
|
752
|
|
753 mh-recenter-summary-p (nil)
|
|
754 If non-nil, then the scan listing is recentered when the window displaying
|
|
755 a messages is toggled off.
|
|
756
|
|
757 mh-summary-height (4)
|
|
758 Number of lines in the summary window including the mode line.
|
|
759
|
|
760 mh-ins-buf-prefix (\"> \")
|
|
761 String to insert before each non-blank line of a message as it is
|
|
762 inserted in a draft letter.
|
|
763
|
|
764 The value of mh-folder-mode-hook is called when a new folder is set up."
|
|
765
|
|
766 (kill-all-local-variables)
|
|
767 (use-local-map mh-folder-mode-map)
|
|
768 (setq major-mode 'mh-folder-mode)
|
|
769 (mh-set-mode-name "MH-Folder")
|
|
770 (make-local-vars
|
|
771 'mh-current-folder (buffer-name) ; Name of folder, a string
|
|
772 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
|
|
773 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
|
|
774 (file-name-as-directory (mh-expand-file-name (buffer-name)))
|
|
775 'mh-showing nil ; Show message also?
|
|
776 'mh-next-seq-num 0 ; Index of free sequence id
|
|
777 'mh-delete-list nil ; List of msgs nums to delete
|
|
778 'mh-refile-list nil ; List of folder names in mh-seq-list
|
|
779 'mh-seq-list nil ; Alist of (seq . msgs) nums
|
|
780 'mh-seen-list nil ; List of displayed messages
|
|
781 'mh-next-direction 'forward ; Direction to move to next message
|
|
782 'mh-narrowed-to-seq nil ; Sequence display is narrowed to
|
|
783 'mh-first-msg-num nil ; Number of first msg in buffer
|
|
784 'mh-last-msg-num nil ; Number of last msg in buffer
|
|
785 'mh-previous-window-config nil) ; Previous window configuration
|
|
786 (setq truncate-lines t)
|
|
787 (auto-save-mode -1)
|
|
788 (setq buffer-offer-save t)
|
|
789 (make-local-variable 'write-file-hooks)
|
|
790 (setq write-file-hooks '(mh-execute-commands))
|
|
791 (make-local-variable 'revert-buffer-function)
|
|
792 (setq revert-buffer-function 'mh-undo-folder)
|
|
793 (or (assq 'mh-showing minor-mode-alist)
|
|
794 (setq minor-mode-alist
|
|
795 (cons '(mh-showing " Show") minor-mode-alist)))
|
|
796 (run-hooks 'mh-folder-mode-hook))
|
|
797
|
|
798
|
|
799 (defun make-local-vars (&rest pairs)
|
|
800 ;; Take VARIABLE-VALUE pairs and makes local variables initialized to the
|
|
801 ;; value.
|
|
802 (while pairs
|
|
803 (make-variable-buffer-local (car pairs))
|
|
804 (set (car pairs) (car (cdr pairs)))
|
|
805 (setq pairs (cdr (cdr pairs)))))
|
|
806
|
|
807
|
|
808 (defun mh-scan-folder (folder range)
|
|
809 ;; Scan the FOLDER over the RANGE. Return in the folder's buffer.
|
|
810 (cond ((null (get-buffer folder))
|
|
811 (mh-make-folder folder))
|
|
812 (t
|
|
813 (mh-process-or-undo-commands folder)
|
|
814 (switch-to-buffer folder)))
|
|
815 (mh-regenerate-headers range)
|
|
816 (cond ((zerop (buffer-size))
|
|
817 (if (equal range "all")
|
|
818 (message "Folder %s is empty" folder)
|
|
819 (message "No messages in %s, range %s" folder range))
|
|
820 (sit-for 5)))
|
|
821 (mh-goto-cur-msg))
|
|
822
|
|
823
|
|
824 (defun mh-regenerate-headers (range)
|
|
825 ;; Replace buffer with scan of its contents over range RANGE.
|
|
826 (let ((folder mh-current-folder))
|
|
827 (message "Scanning %s..." folder)
|
|
828 (with-mh-folder-updating (nil)
|
|
829 (erase-buffer)
|
|
830 (mh-exec-cmd-output mh-scan-prog nil
|
|
831 "-noclear" "-noheader"
|
|
832 "-width" (window-width)
|
|
833 folder range)
|
|
834 (goto-char (point-min))
|
|
835 (cond ((looking-at "scan: no messages in")
|
|
836 (keep-lines mh-valid-scan-line)) ; Flush random scan lines
|
|
837 ((looking-at "scan: ")) ; Keep error messages
|
|
838 (t
|
|
839 (keep-lines mh-valid-scan-line))) ; Flush random scan lines
|
|
840 (mh-delete-seq-locally 'cur) ; To pick up new one
|
|
841 (setq mh-seq-list (mh-read-folder-sequences folder nil))
|
|
842 (mh-notate-user-sequences)
|
|
843 (mh-make-folder-mode-line (if (equal range "all")
|
|
844 nil
|
|
845 mh-partial-folder-mode-line-annotation)))
|
|
846 (message "Scanning %s...done" folder)))
|
|
847
|
|
848
|
|
849 (defun mh-get-new-mail (maildrop-name)
|
|
850 ;; Read new mail from a maildrop into the current buffer.
|
|
851 ;; Return in the current buffer.
|
|
852 (let ((point-before-inc (point))
|
|
853 (folder mh-current-folder)
|
|
854 (new-mail-p nil))
|
|
855 (with-mh-folder-updating (t)
|
|
856 (message (if maildrop-name
|
|
857 (format "inc %s -file %s..." folder maildrop-name)
|
|
858 (format "inc %s..." folder)))
|
|
859 (setq mh-next-direction 'forward)
|
|
860 (goto-char (point-max))
|
|
861 (let ((start-of-inc (point)))
|
|
862 (if maildrop-name
|
|
863 (mh-exec-cmd-output mh-inc-prog nil folder
|
|
864 "-file" (expand-file-name maildrop-name)
|
|
865 "-width" (window-width)
|
|
866 "-truncate")
|
|
867 (mh-exec-cmd-output "inc" nil
|
|
868 "-width" (window-width)))
|
|
869 (message
|
|
870 (if maildrop-name
|
|
871 (format "inc %s -file %s...done" folder maildrop-name)
|
|
872 (format "inc %s...done" folder)))
|
|
873 (goto-char start-of-inc)
|
|
874 (cond ((looking-at "inc: no mail")
|
|
875 (message "No new mail%s%s" (if maildrop-name " in " "")
|
|
876 (if maildrop-name maildrop-name "")))
|
|
877 ((re-search-forward "^inc:" nil t) ; Error messages
|
|
878 (error "inc error"))
|
|
879 (t
|
|
880 ;; remove old cur notation (cf mh-goto-cur-msg code)
|
|
881 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
|
|
882 (save-excursion
|
|
883 (and cur-msg
|
|
884 (mh-goto-msg cur-msg t nil)
|
|
885 (looking-at mh-cur-scan-msg-regexp)
|
|
886 (mh-notate nil ? mh-cmd-note))))
|
|
887 (setq new-mail-p t)))
|
|
888 (keep-lines mh-valid-scan-line) ; Flush random scan lines
|
|
889 (mh-delete-seq-locally 'cur) ; To pick up new one
|
|
890 (setq mh-seq-list (mh-read-folder-sequences folder t))
|
|
891 (mh-notate-user-sequences)
|
|
892 (if new-mail-p
|
|
893 (progn
|
|
894 (mh-goto-cur-msg)
|
|
895 (mh-make-folder-mode-line))
|
|
896 (goto-char point-before-inc))))))
|
|
897
|
|
898
|
|
899 (defun mh-make-folder-mode-line (&optional annotation)
|
|
900 ;; Set the fields of the mode line for a folder buffer.
|
|
901 ;; The optional ANNOTATION string is displayed after the folder's name.
|
|
902 (save-excursion
|
|
903 (mh-first-msg)
|
|
904 (setq mh-first-msg-num (mh-get-msg-num nil))
|
|
905 (mh-last-msg)
|
|
906 (setq mh-last-msg-num (mh-get-msg-num nil))
|
|
907 (let ((lines (count-lines (point-min) (point-max))))
|
|
908 (setq mode-line-buffer-identification
|
|
909 (list (format "{%%b%s} %d msg%s"
|
|
910 (if annotation (format "/%s" annotation) "")
|
|
911 lines
|
|
912 (if (zerop lines)
|
|
913 "s"
|
|
914 (if (> lines 1)
|
|
915 (format "s (%d-%d)" mh-first-msg-num
|
|
916 mh-last-msg-num)
|
|
917 (format " (%d)" mh-first-msg-num)))))))))
|
|
918
|
|
919
|
|
920 (defun mh-unmark-all-headers (remove-all-flags)
|
|
921 ;; Remove all '+' flags from the headers, and if called with a non-nil
|
|
922 ;; argument, remove all 'D', '^' and '%' flags too.
|
|
923 ;; Optimized for speed (i.e., no regular expressions).
|
|
924 (save-excursion
|
|
925 (let ((case-fold-search nil)
|
|
926 (last-line (- (point-max) mh-cmd-note))
|
|
927 char)
|
|
928 (mh-first-msg)
|
|
929 (while (<= (point) last-line)
|
|
930 (forward-char mh-cmd-note)
|
|
931 (setq char (following-char))
|
|
932 (if (or (and remove-all-flags
|
|
933 (or (eql char ?D)
|
|
934 (eql char ?^)
|
|
935 (eql char ?%)))
|
|
936 (eql char ?+))
|
|
937 (progn
|
|
938 (delete-char 1)
|
|
939 (insert " ")))
|
|
940 (forward-line)))))
|
|
941
|
|
942
|
|
943 (defun mh-goto-cur-msg ()
|
|
944 ;; Position the cursor at the current message.
|
|
945 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
|
|
946 (cond ((and cur-msg
|
|
947 (mh-goto-msg cur-msg t nil))
|
|
948 (mh-notate nil ?+ mh-cmd-note)
|
|
949 (mh-recenter 0)
|
|
950 (mh-maybe-show cur-msg))
|
|
951 (t
|
|
952 (mh-last-msg)
|
|
953 (message "No current message")))))
|
|
954
|
|
955
|
|
956 (defun mh-process-or-undo-commands (folder)
|
|
957 ;; If FOLDER has outstanding commands, then either process or discard them.
|
|
958 ;; Called by functions like mh-sort-folder, so also invalidate show buffer.
|
|
959 (set-buffer folder)
|
|
960 (if (mh-outstanding-commands-p)
|
|
961 (if (or mh-do-not-confirm
|
|
962 (y-or-n-p
|
|
963 "Process outstanding deletes and refiles (or lose them)? "))
|
|
964 (mh-process-commands folder)
|
|
965 (mh-undo-folder)))
|
|
966 (mh-update-unseen)
|
|
967 (mh-invalidate-show-buffer))
|
|
968
|
|
969
|
|
970 (defun mh-process-commands (folder)
|
|
971 ;; Process outstanding commands for the folder FOLDER.
|
|
972 (message "Processing deletes and refiles for %s..." folder)
|
|
973 (set-buffer folder)
|
|
974 (with-mh-folder-updating (nil)
|
|
975 ;; Update the unseen sequence if it exists
|
|
976 (mh-update-unseen)
|
|
977
|
|
978 ;; Then refile messages
|
|
979 (mh-mapc
|
|
980 (function
|
|
981 (lambda (dest)
|
|
982 (let ((msgs (mh-seq-to-msgs dest)))
|
|
983 (cond (msgs
|
|
984 (apply 'mh-exec-cmd "refile"
|
|
985 "-src" folder (symbol-name dest) msgs)
|
|
986 (mh-delete-scan-msgs msgs))))))
|
|
987 mh-refile-list)
|
|
988 (setq mh-refile-list nil)
|
|
989
|
|
990 ;; Now delete messages
|
|
991 (cond (mh-delete-list
|
|
992 (apply 'mh-exec-cmd "rmm" folder mh-delete-list)
|
|
993 (mh-delete-scan-msgs mh-delete-list)
|
|
994 (setq mh-delete-list nil)))
|
|
995
|
|
996 ;; Don't need to remove sequences since delete and refile do so.
|
|
997
|
|
998 ;; Mark cur message
|
|
999 (if (> (buffer-size) 0)
|
|
1000 (mh-define-sequence 'cur (or (mh-get-msg-num nil) "last")))
|
|
1001
|
|
1002 (and (buffer-file-name (get-buffer mh-show-buffer))
|
|
1003 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
|
|
1004 ;; If "inc" were to put a new msg in this file,
|
|
1005 ;; we would not notice, so mark it invalid now.
|
|
1006 (mh-invalidate-show-buffer))
|
|
1007
|
|
1008 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
|
|
1009 (mh-unmark-all-headers t)
|
|
1010 (mh-notate-user-sequences)
|
|
1011 (message "Processing deletes and refiles for %s...done" folder)))
|
|
1012
|
|
1013
|
|
1014 (defun mh-update-unseen ()
|
|
1015 ;; Push updates to the Unseen sequence out to MH.
|
|
1016 (if mh-seen-list
|
|
1017 (progn
|
|
1018 (if (mh-seq-to-msgs mh-unseen-seq)
|
|
1019 (mh-undefine-sequence mh-unseen-seq mh-seen-list))
|
|
1020 (setq mh-seen-list nil))))
|
|
1021
|
|
1022
|
|
1023 (defun mh-delete-scan-msgs (msgs)
|
|
1024 ;; Delete the scan listing lines for each of the msgs in the LIST.
|
|
1025 ;; Optimized for speed (i.e., no regular expressions).
|
|
1026 (setq msgs (sort msgs (function <))) ;okay to clobber msgs
|
|
1027 (save-excursion
|
|
1028 (mh-first-msg)
|
|
1029 (while (and msgs (< (point) (point-max)))
|
|
1030 (cond ((equal (mh-get-msg-num nil) (car msgs))
|
|
1031 (delete-region (point) (save-excursion (forward-line) (point)))
|
|
1032 (setq msgs (cdr msgs)))
|
|
1033 (t
|
|
1034 (forward-line))))))
|
|
1035
|
|
1036
|
|
1037 (defun mh-outstanding-commands-p ()
|
|
1038 ;; Returns non-nil if there are outstanding deletes or refiles.
|
|
1039 (or mh-delete-list mh-refile-list))
|
|
1040
|
|
1041
|
|
1042
|
|
1043 ;;; Basic sequence handling
|
|
1044
|
|
1045 (defun mh-delete-seq-locally (seq)
|
|
1046 ;; Remove mh-e's record of SEQUENCE.
|
|
1047 (let ((entry (mh-find-seq seq)))
|
|
1048 (setq mh-seq-list (delq entry mh-seq-list))))
|
|
1049
|
|
1050 (defun mh-read-folder-sequences (folder save-refiles)
|
|
1051 ;; Read and return the predefined sequences for a FOLDER.
|
|
1052 ;; If SAVE-REFILES is non-nil, then keep the sequences
|
|
1053 ;; that note messages to be refiled.
|
|
1054 (let ((seqs ()))
|
|
1055 (cond (save-refiles
|
|
1056 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
|
|
1057 (if (mh-folder-name-p (mh-seq-name seq))
|
|
1058 (setq seqs (cons seq seqs)))))
|
|
1059 mh-seq-list)))
|
|
1060 (save-excursion
|
|
1061 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
|
|
1062 (progn
|
|
1063 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
|
|
1064 (while (re-search-forward "^[^: ]+" nil t)
|
|
1065 (setq seqs (cons (mh-make-seq (intern (buffer-substring
|
|
1066 (match-beginning 0)
|
|
1067 (match-end 0)))
|
|
1068 (mh-read-msg-list))
|
|
1069 seqs)))
|
|
1070 (delete-region (point-min) (point))))) ; avoid race with mh-process-daemon
|
|
1071 seqs))
|
|
1072
|
|
1073 (defun mh-read-msg-list ()
|
|
1074 ;; Return a list of message numbers from the current point to the end of
|
|
1075 ;; the line.
|
|
1076 (let ((msgs ())
|
|
1077 (end-of-line (save-excursion (end-of-line) (point)))
|
|
1078 num)
|
|
1079 (while (re-search-forward "[0-9]+" end-of-line t)
|
|
1080 (setq num (string-to-int (buffer-substring (match-beginning 0)
|
|
1081 (match-end 0))))
|
|
1082 (cond ((looking-at "-") ; Message range
|
|
1083 (forward-char 1)
|
|
1084 (re-search-forward "[0-9]+" end-of-line t)
|
|
1085 (let ((num2 (string-to-int (buffer-substring (match-beginning 0)
|
|
1086 (match-end 0)))))
|
|
1087 (if (< num2 num)
|
|
1088 (error "Bad message range: %d-%d" num num2))
|
|
1089 (while (<= num num2)
|
|
1090 (setq msgs (cons num msgs))
|
|
1091 (setq num (1+ num)))))
|
|
1092 ((not (zerop num)) (setq msgs (cons num msgs)))))
|
|
1093 msgs))
|
|
1094
|
|
1095 (defun mh-notate-user-sequences ()
|
|
1096 ;; Mark the scan listing of all messages in user-defined sequences.
|
|
1097 (let ((seqs mh-seq-list)
|
|
1098 name)
|
|
1099 (while seqs
|
|
1100 (setq name (mh-seq-name (car seqs)))
|
|
1101 (if (not (mh-internal-seq name))
|
|
1102 (mh-notate-seq name ?% (1+ mh-cmd-note)))
|
|
1103 (setq seqs (cdr seqs)))))
|
|
1104
|
|
1105
|
|
1106 (defun mh-internal-seq (name)
|
|
1107 ;; Return non-NIL if NAME is the name of an internal mh-e sequence.
|
|
1108 (or (memq name '(answered cur deleted forwarded printed))
|
|
1109 (eq name mh-unseen-seq)
|
|
1110 (eq name mh-previous-seq)
|
|
1111 (mh-folder-name-p name)))
|
|
1112
|
|
1113
|
|
1114 (defun mh-delete-msg-from-seq (msg seq &optional internal-flag)
|
|
1115 "Delete MESSAGE from SEQUENCE. MESSAGE defaults to displayed message.
|
|
1116 From Lisp, optional third arg INTERNAL non-nil means do not
|
|
1117 inform MH of the change."
|
|
1118 (interactive (list (mh-get-msg-num t)
|
|
1119 (mh-read-seq-default "Delete from" t)
|
|
1120 nil))
|
|
1121 (let ((entry (mh-find-seq seq)))
|
|
1122 (cond (entry
|
|
1123 (mh-notate-if-in-one-seq msg ? (1+ mh-cmd-note) (mh-seq-name entry))
|
|
1124 (if (not internal-flag)
|
|
1125 (mh-undefine-sequence seq msg))
|
|
1126 (setcdr entry (delq msg (mh-seq-msgs entry)))))))
|
|
1127
|
|
1128
|
|
1129 (defun mh-undefine-sequence (seq msgs)
|
|
1130 ;; Remove from the SEQUENCE the MSGS, which may be a list or single msg.
|
|
1131 (mh-exec-cmd "mark" mh-current-folder "-delete"
|
|
1132 "-sequence" (symbol-name seq)
|
|
1133 msgs))
|
|
1134
|
|
1135
|
|
1136 (defun mh-define-sequence (seq msgs)
|
|
1137 ;; Define the SEQUENCE to contain the list of MSGS.
|
|
1138 ;; Do not mark pseudo-sequences or empty sequences.
|
|
1139 ;; Signals an error if SEQUENCE is an illegal name.
|
|
1140 (if (and msgs
|
|
1141 (not (mh-folder-name-p seq)))
|
|
1142 (save-excursion
|
|
1143 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
|
|
1144 "-sequence" (symbol-name seq)
|
|
1145 msgs))))
|
|
1146
|
|
1147
|
|
1148 (defun mh-define-sequences (seq-list)
|
|
1149 ;; Define the sequences in SEQ-LIST.
|
|
1150 (mh-map-over-seqs 'mh-define-sequence seq-list))
|
|
1151
|
|
1152
|
|
1153 (defun mh-map-over-seqs (func seq-list)
|
|
1154 ;; Apply the FUNCTION to each element in the list of SEQUENCES,
|
|
1155 ;; passing the sequence name and the list of messages as arguments.
|
|
1156 (while seq-list
|
|
1157 (funcall func (mh-seq-name (car seq-list)) (mh-seq-msgs (car seq-list)))
|
|
1158 (setq seq-list (cdr seq-list))))
|
|
1159
|
|
1160
|
|
1161 (defun mh-notate-if-in-one-seq (msg notation offset seq)
|
|
1162 ;; If the MESSAGE is in only the SEQUENCE, then mark the scan listing of the
|
|
1163 ;; message with the CHARACTER at the given OFFSET from the beginning of the
|
|
1164 ;; listing line.
|
|
1165 (let ((in-seqs (mh-seq-containing-msg msg)))
|
|
1166 (if (and (eq seq (car in-seqs)) (null (cdr in-seqs)))
|
|
1167 (mh-notate msg notation offset))))
|
|
1168
|
|
1169
|
|
1170 (defun mh-seq-containing-msg (msg)
|
|
1171 ;; Return a list of the sequences containing MESSAGE.
|
|
1172 (let ((l mh-seq-list)
|
|
1173 (seqs ()))
|
|
1174 (while l
|
|
1175 (if (memq msg (mh-seq-msgs (car l)))
|
|
1176 (setq seqs (cons (mh-seq-name (car l)) seqs)))
|
|
1177 (setq l (cdr l)))
|
|
1178 seqs))
|
|
1179
|
|
1180
|
|
1181
|
|
1182
|
|
1183 ;;; User prompting commands.
|
|
1184
|
|
1185
|
|
1186 (defun mh-read-msg-range (prompt)
|
|
1187 ;; Read a list of blank-separated items.
|
|
1188 (let* ((buf (read-string prompt))
|
|
1189 (buf-size (length buf))
|
|
1190 (start 0)
|
|
1191 (input ()))
|
|
1192 (while (< start buf-size)
|
|
1193 (let ((next (read-from-string buf start buf-size)))
|
|
1194 (setq input (cons (car next) input))
|
|
1195 (setq start (cdr next))))
|
|
1196 (nreverse input)))
|
|
1197
|
|
1198
|
|
1199
|
|
1200 ;;; Build the folder-mode keymap:
|
|
1201
|
|
1202 (suppress-keymap mh-folder-mode-map)
|
|
1203 (define-key mh-folder-mode-map "q" 'mh-quit)
|
|
1204 (define-key mh-folder-mode-map "b" 'mh-compat-quit)
|
|
1205 (define-key mh-folder-mode-map "?" 'mh-msg-is-in-seq)
|
|
1206 (define-key mh-folder-mode-map "%" 'mh-put-msg-in-seq)
|
|
1207 (define-key mh-folder-mode-map "|" 'mh-pipe-msg)
|
|
1208 (define-key mh-folder-mode-map "\ea" 'mh-edit-again)
|
|
1209 (define-key mh-folder-mode-map "\e%" 'mh-delete-msg-from-seq)
|
|
1210 (define-key mh-folder-mode-map "\e#" 'mh-delete-seq)
|
|
1211 (define-key mh-folder-mode-map "\C-xn" 'mh-narrow-to-seq)
|
|
1212 (define-key mh-folder-mode-map "\C-xw" 'mh-widen)
|
|
1213 (define-key mh-folder-mode-map "\eb" 'mh-burst-digest)
|
|
1214 (define-key mh-folder-mode-map "\eu" 'mh-undo-folder)
|
|
1215 (define-key mh-folder-mode-map "\e " 'mh-page-digest)
|
|
1216 (define-key mh-folder-mode-map "\e\177" 'mh-page-digest-backwards)
|
|
1217 (define-key mh-folder-mode-map "\ed" 'mh-redistribute)
|
|
1218 (define-key mh-folder-mode-map "\ee" 'mh-extract-rejected-mail)
|
|
1219 (define-key mh-folder-mode-map "\ef" 'mh-visit-folder)
|
|
1220 (define-key mh-folder-mode-map "\ek" 'mh-kill-folder)
|
|
1221 (define-key mh-folder-mode-map "\el" 'mh-list-folders)
|
|
1222 (define-key mh-folder-mode-map "\en" 'mh-store-msg)
|
|
1223 (define-key mh-folder-mode-map "\ep" 'mh-pack-folder)
|
|
1224 (define-key mh-folder-mode-map "\eq" 'mh-list-sequences)
|
|
1225 (define-key mh-folder-mode-map "\es" 'mh-search-folder)
|
|
1226 (define-key mh-folder-mode-map "\er" 'mh-rescan-folder)
|
|
1227 (define-key mh-folder-mode-map "l" 'mh-print-msg)
|
|
1228 (define-key mh-folder-mode-map "t" 'mh-toggle-showing)
|
|
1229 (define-key mh-folder-mode-map "c" 'mh-copy-msg)
|
|
1230 (define-key mh-folder-mode-map "i" 'mh-inc-folder)
|
|
1231 (define-key mh-folder-mode-map "x" 'mh-execute-commands)
|
|
1232 (define-key mh-folder-mode-map "e" 'mh-execute-commands)
|
|
1233 (define-key mh-folder-mode-map "f" 'mh-forward)
|
|
1234 (define-key mh-folder-mode-map "m" 'mh-send)
|
|
1235 (define-key mh-folder-mode-map "s" 'mh-send)
|
|
1236 (define-key mh-folder-mode-map "r" 'mh-reply)
|
|
1237 (define-key mh-folder-mode-map "a" 'mh-reply)
|
|
1238 (define-key mh-folder-mode-map "j" 'mh-goto-msg)
|
|
1239 (define-key mh-folder-mode-map "g" 'mh-goto-msg)
|
|
1240 (define-key mh-folder-mode-map "\e>" 'mh-last-msg)
|
|
1241 (define-key mh-folder-mode-map "\177" 'mh-previous-page)
|
|
1242 (define-key mh-folder-mode-map " " 'mh-page-msg)
|
|
1243 (define-key mh-folder-mode-map "." 'mh-show)
|
|
1244 (define-key mh-folder-mode-map "," 'mh-header-display)
|
|
1245 (define-key mh-folder-mode-map "u" 'mh-undo)
|
|
1246 (define-key mh-folder-mode-map "d" 'mh-delete-msg)
|
|
1247 (define-key mh-folder-mode-map "\C-d" 'mh-delete-msg-no-motion)
|
|
1248 (define-key mh-folder-mode-map "p" 'mh-previous-undeleted-msg)
|
|
1249 (define-key mh-folder-mode-map "n" 'mh-next-undeleted-msg)
|
|
1250 (define-key mh-folder-mode-map "o" 'mh-refile-msg)
|
|
1251 (define-key mh-folder-mode-map "^" 'mh-refile-msg)
|
|
1252 (define-key mh-folder-mode-map "\C-o" 'mh-write-msg-to-file)
|
|
1253 (define-key mh-folder-mode-map ">" 'mh-write-msg-to-file)
|
|
1254 (define-key mh-folder-mode-map "!" 'mh-refile-or-write-again)
|
|
1255
|
|
1256
|
|
1257
|
|
1258 ;;;autoload the other mh-e parts
|
|
1259
|
|
1260 ;;; mh-comp
|
|
1261
|
|
1262 (autoload 'mh-smail "mh-comp"
|
|
1263 "Compose and send mail with the MH mail system." t)
|
|
1264 (autoload 'mh-smail-other-window "mh-comp"
|
|
1265 "Compose and send mail in other window with the MH mail system." t)
|
|
1266 (autoload 'mh-edit-again "mh-comp"
|
|
1267 "Clean-up a draft or a message previously sent and make it resendable." t)
|
|
1268 (autoload 'mh-extract-rejected-mail "mh-comp"
|
|
1269 "Extract a letter returned by the mail system and make it resendable." t)
|
|
1270 (autoload 'mh-forward "mh-comp"
|
|
1271 "Forward MESSAGE(s) (default: displayed message)." t)
|
|
1272 (autoload 'mh-redistribute "mh-comp"
|
|
1273 "Redistribute a letter." t)
|
|
1274 (autoload 'mh-reply "mh-comp"
|
|
1275 "Reply to a MESSAGE (default: displayed message)." t)
|
|
1276 (autoload 'mh-send "mh-comp"
|
|
1277 "Compose and send a letter." t)
|
|
1278 (autoload 'mh-send-other-window "mh-comp"
|
|
1279 "Compose and send a letter in another window." t)
|
|
1280 (autoload 'mh-letter-mode "mh-comp"
|
|
1281 "Mode for composing letters in mh-e." t)
|
|
1282
|
|
1283
|
|
1284 ;;; mh-funcs
|
|
1285
|
|
1286 (autoload 'mh-burst-digest "mh-funcs"
|
|
1287 "Burst apart the current message, which should be a digest." t)
|
|
1288 (autoload 'mh-copy-msg "mh-funcs"
|
|
1289 "Copy specified MESSAGE(s) to another FOLDER without deleting them." t)
|
|
1290 (autoload 'mh-kill-folder "mh-funcs"
|
|
1291 "Remove the current folder." t)
|
|
1292 (autoload 'mh-list-folders "mh-funcs"
|
|
1293 "List mail folders." t)
|
|
1294 (autoload 'mh-pack-folder "mh-funcs"
|
|
1295 "Renumber the messages of a folder to be 1..n." t)
|
|
1296 (autoload 'mh-pipe-msg "mh-funcs"
|
|
1297 "Pipe the current message through the given shell COMMAND." t)
|
|
1298 (autoload 'mh-page-digest "mh-funcs"
|
|
1299 "Advance displayed message to next digested message." t)
|
|
1300 (autoload 'mh-page-digest-backwards "mh-funcs"
|
|
1301 "Back up displayed message to previous digested message." t)
|
|
1302 (autoload 'mh-print-msg "mh-funcs"
|
|
1303 "Print MESSAGE(s) (default: displayed message) on a line printer." t)
|
|
1304 (autoload 'mh-sort-folder "mh-funcs"
|
|
1305 "Sort the messages in the current folder by date." t)
|
|
1306 (autoload 'mh-undo-folder "mh-funcs"
|
|
1307 "Undo all commands in current folder." t)
|
|
1308 (autoload 'mh-store-msg "mh-funcs"
|
|
1309 "Store the file(s) contained in the current message." t)
|
|
1310
|
|
1311
|
|
1312 ;;; mh-pick
|
|
1313
|
|
1314 (autoload 'mh-search-folder "mh-pick"
|
|
1315 "Search FOLDER for messages matching a pattern." t)
|
|
1316
|
|
1317 ;;; mh-seq
|
|
1318
|
|
1319 (autoload 'mh-put-msg-in-seq "mh-seq"
|
|
1320 "Add MESSAGE(s) (default: displayed message) to SEQUENCE." t)
|
|
1321 (autoload 'mh-delete-seq "mh-seq"
|
|
1322 "Delete the SEQUENCE." t)
|
|
1323 (autoload 'mh-list-sequences "mh-seq"
|
|
1324 "List the sequences defined in FOLDER." t)
|
|
1325 (autoload 'mh-msg-is-in-seq "mh-seq"
|
|
1326 "Display the sequences that contain MESSAGE (default: displayed message)." t)
|
|
1327 (autoload 'mh-narrow-to-seq "mh-seq"
|
|
1328 "Restrict display of this folder to just messages in a sequence." t)
|
|
1329 (autoload 'mh-widen "mh-seq"
|
|
1330 "Remove restrictions from current folder, thereby showing all messages." t)
|
|
1331 (autoload 'mh-rename-seq "mh-seq"
|
|
1332 "Rename a SEQUENCE to have a new NAME." t)
|
|
1333
|
|
1334 ;;; mh-e.el ends here
|