]> code.delx.au - gnu-emacs/blob - lisp/mh-e/mh-e.el
* mh-customize.el (mh-index): Rename group to mh-search and sort group
[gnu-emacs] / lisp / mh-e / mh-e.el
1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system
2
3 ;; Copyright (C) 1985, 1986, 1987, 1988,
4 ;; 1990, 1992, 1993, 1994, 1995, 1997, 1999,
5 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6
7 ;; Author: Bill Wohler <wohler@newt.com>
8 ;; Maintainer: Bill Wohler <wohler@newt.com>
9 ;; Version: 7.85+cvs
10 ;; Keywords: mail
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28
29 ;;; Commentary:
30
31 ;; How to Use:
32 ;; M-x mh-rmail to read mail. Type C-h m there for a list of commands.
33 ;; C-u M-x mh-rmail to visit any folder.
34 ;; M-x mh-smail to send mail. From within the mail reader, "m" works, too.
35
36 ;; Your .emacs might benefit from these bindings:
37 ;; (global-set-key "\C-cr" 'mh-rmail)
38 ;; (global-set-key "\C-xm" 'mh-smail)
39 ;; (global-set-key "\C-x4m" 'mh-smail-other-window)
40
41 ;; MH (Message Handler) is a powerful mail reader.
42
43 ;; The MH newsgroup is comp.mail.mh; the mailing list is mh-users@ics.uci.edu
44 ;; (send to mh-users-request to be added). See the monthly Frequently Asked
45 ;; Questions posting there for information on getting MH and MH-E:
46 ;; http://www.faqs.org/faqs/mail/mh-faq/part1/preamble.html
47
48 ;; N.B. MH must have been compiled with the MHE compiler flag or several
49 ;; features necessary for MH-E will be missing from MH commands, specifically
50 ;; the -build switch to repl and forw.
51
52 ;; MH-E is an Emacs interface to the MH mail system.
53
54 ;; MH-E is supported in GNU Emacs 21 and 22 as well as XEmacs 21
55 ;; (except for versions 21.5.9-21.5.16), with MH 6.8.4 on, nmh 1.0.4
56 ;; on, and GNU mailutils 0.4 on.
57
58 ;; Mailing Lists:
59 ;; mh-e-users@lists.sourceforge.net
60 ;; mh-e-announce@lists.sourceforge.net
61 ;; mh-e-devel@lists.sourceforge.net
62 ;;
63 ;; Subscribe by sending a "subscribe" message to
64 ;; <list>-request@lists.sourceforge.net, or by using the web interface at
65 ;; https://sourceforge.net/mail/?group_id=13357
66
67 ;; Bug Reports:
68 ;; https://sourceforge.net/tracker/?group_id=13357&atid=113357
69 ;; Include the output of M-x mh-version in any bug report.
70
71 ;; Feature Requests:
72 ;; https://sourceforge.net/tracker/?atid=363357&group_id=13357&func=browse
73
74 ;; Support:
75 ;; https://sourceforge.net/tracker/?group_id=13357&atid=213357
76
77 ;;; Change Log:
78
79 ;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
80 ;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
81 ;; Rewritten for GNU Emacs, James Larus, 1985.
82 ;; Modified by Stephen Gildea, 1988.
83 ;; Maintenance picked up by Bill Wohler and the
84 ;; SourceForge Crew <http://mh-e.sourceforge.net/>, 2001.
85
86 ;;; Code:
87
88 (provide 'mh-e)
89
90 (eval-when-compile (require 'mh-acros))
91 (mh-require-cl)
92
93 (require 'easymenu)
94 (require 'gnus-util)
95 (require 'mh-buffers)
96 (require 'mh-seq)
97 (require 'mh-utils)
98
99 (defconst mh-version "7.85+cvs" "Version number of MH-E.")
100
101 (defvar mh-partial-folder-mode-line-annotation "select"
102 "Annotation when displaying part of a folder.
103 The string is displayed after the folder's name. nil for no
104 annotation.")
105
106 \f
107
108 ;;; Scan Line Formats
109
110 ;; Parameterize MH-E to work with different scan formats. The defaults work
111 ;; with the standard MH scan listings, in which the first 4 characters on
112 ;; the line are the message number, followed by two places for notations.
113
114 ;; The following scan formats are passed to the scan program if the setting of
115 ;; `mh-scan-format-file' is t. They are identical except the later one makes
116 ;; use of the nmh `decode' function to decode RFC 2047 encodings. If you just
117 ;; want to change the column of the notations, use the `mh-set-cmd-note'
118 ;; function.
119
120 (defvar mh-scan-format-mh
121 (concat
122 "%4(msg)"
123 "%<(cur)+%| %>"
124 "%<{replied}-"
125 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
126 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
127 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
128 "%?(nonnull(comp{newsgroups}))n%>"
129 "%<(zero) %>"
130 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
131 "%<(mymbox{from})%<{to}To:%14(friendly{to})%>%>"
132 "%<(zero)%17(friendly{from})%> "
133 "%{subject}%<{body}<<%{body}%>")
134 "*Scan format string for MH.
135 This string is passed to the scan program via the -format
136 argument. This format is identical to the default except that
137 additional hints for fontification have been added to the fifth
138 column (remember that in Emacs, the first column is 0).
139
140 The values of the fifth column, in priority order, are: \"-\" if
141 the message has been replied to, t if an address on the To: line
142 matches one of the mailboxes of the current user, \"c\" if the Cc:
143 line matches, \"b\" if the Bcc: line matches, and \"n\" if a
144 non-empty Newsgroups: header is present.")
145
146 (defvar mh-scan-format-nmh
147 (concat
148 "%4(msg)"
149 "%<(cur)+%| %>"
150 "%<{replied}-"
151 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
152 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
153 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
154 "%?(nonnull(comp{newsgroups}))n%>"
155 "%<(zero) %>"
156 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
157 "%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>"
158 "%<(zero)%17(decode(friendly{from}))%> "
159 "%(decode{subject})%<{body}<<%{body}%>")
160 "*Scan format string for nmh.
161 This string is passed to the scan program via the -format arg.
162 This format is identical to the default except that additional
163 hints for fontification have been added to the fifth
164 column (remember that in Emacs, the first column is 0).
165
166 The values of the fifth column, in priority order, are: \"-\" if
167 the message has been replied to, t if an address on the To: field
168 matches one of the mailboxes of the current user, \"c\" if the Cc:
169 field matches, \"b\" if the Bcc: field matches, and \"n\" if a
170 non-empty Newsgroups: field is present.")
171
172 (defvar mh-note-deleted ?D
173 "Messages that have been deleted are marked by this character.
174 See also `mh-scan-deleted-msg-regexp'.")
175
176 (defvar mh-note-refiled ?^
177 "Messages that have been refiled are marked by this character.
178 See also `mh-scan-refiled-msg-regexp'.")
179
180 (defvar mh-note-cur ?+
181 "The current message (in MH, not in MH-E) is marked by this character.
182 See also `mh-scan-cur-msg-number-regexp'.")
183
184 (defvar mh-scan-good-msg-regexp "^\\( *[0-9]+\\)[^D^0-9]"
185 "This regular expression matches \"good\" messages.
186
187 It must match from the beginning of the line. Note that the
188 default setting of `mh-folder-font-lock-keywords' expects this
189 expression to contain at least one parenthesized expression which
190 matches the message number as in the default of
191
192 \"^\\\\( *[0-9]+\\\\)[^D^0-9]\".
193
194 This expression includes the leading space within the parenthesis
195 since it looks better to highlight it as well. The highlighting
196 is done with the face `mh-folder-msg-number'. This regular
197 expression should be correct as it is needed by non-fontification
198 functions.")
199
200 (defvar mh-scan-deleted-msg-regexp "^\\( *[0-9]+\\)D"
201 "This regular expression matches deleted messages.
202
203 It must match from the beginning of the line. Note that the
204 default setting of `mh-folder-font-lock-keywords' expects this
205 expression to contain at least one parenthesized expression which
206 matches the message number as in the default of
207
208 \"^\\\\( *[0-9]+\\\\)D\".
209
210 This expression includes the leading space within the parenthesis
211 since it looks better to highlight it as well. The highlighting
212 is done with the face `mh-folder-deleted'. This regular
213 expression should be correct as it is needed by non-fontification
214 functions. See also `mh-note-deleted'.")
215
216 (defvar mh-scan-refiled-msg-regexp "^\\( *[0-9]+\\)\\^"
217 "This regular expression matches refiled messages.
218
219 It must match from the beginning of the line. Note that the
220 default setting of `mh-folder-font-lock-keywords' expects this
221 expression to contain at least one parenthesized expression which
222 matches the message number as in the default of
223
224 \"^\\\\( *[0-9]+\\\\)\\\\^\".
225
226 This expression includes the leading space within the parenthesis
227 since it looks better to highlight it as well. The highlighting
228 is done with the face `mh-folder-refiled'. This regular
229 expression should be correct as it is needed by non-fontification
230 functions. See also `mh-note-refiled'.")
231
232 (defvar mh-scan-valid-regexp "^ *[0-9]"
233 "This regular expression describes a valid scan line.
234
235 This is used to eliminate error messages that are occasionally
236 produced by \"inc\".")
237
238 (defvar mh-scan-cur-msg-number-regexp "^\\( *[0-9]+\\+\\).*"
239 "This regular expression matches the current message.
240
241 It must match from the beginning of the line. Note that the
242 default setting of `mh-folder-font-lock-keywords' expects this
243 expression to contain at least one parenthesized expression which
244 matches the message number as in the default of
245
246 \"^\\\\( *[0-9]+\\\\+\\\\).*\".
247
248 This expression includes the leading space and current message
249 marker \"+\" within the parenthesis since it looks better to
250 highlight these items as well. The highlighting is done with the
251 face `mh-folder-cur-msg-number'. This regular expression should
252 be correct as it is needed by non-fontification functions. See
253 also `mh-note-cur'.")
254
255 (defvar mh-scan-date-regexp "\\([0-9][0-9]/[0-9][0-9]\\)"
256 "This regular expression matches a valid date.
257
258 It must not be anchored to the beginning or the end of the line.
259 Note that the default setting of `mh-folder-font-lock-keywords'
260 expects this expression to contain only one parenthesized
261 expression which matches the date field as in the default of
262 \"\\\\([0-9][0-9]/[0-9][0-9]\\\\)\"}. If this regular expression
263 is not correct, the date will not be highlighted with the face
264 `mh-folder-date'.")
265
266 (defvar mh-scan-rcpt-regexp "\\(To:\\)\\(..............\\)"
267 "This regular expression specifies the recipient in messages you sent.
268
269 Note that the default setting of `mh-folder-font-lock-keywords'
270 expects this expression to contain two parenthesized expressions.
271 The first is expected to match the \"To:\" that the default scan
272 format file generates. The second is expected to match the
273 recipient's name as in the default of
274 \"\\\\(To:\\\\)\\\\(..............\\\\)\". If this regular
275 expression is not correct, the \"To:\" string will not be
276 highlighted with the face `mh-folder-to' and the recipient will
277 not be highlighted with the face `mh-folder-address'")
278
279 (defvar mh-scan-body-regexp "\\(<<\\([^\n]+\\)?\\)"
280 "This regular expression matches the message body fragment.
281
282 Note that the default setting of `mh-folder-font-lock-keywords'
283 expects this expression to contain at least one parenthesized
284 expression which matches the body text as in the default of
285 \"\\\\(<<\\\\([^\\n]+\\\\)?\\\\)\". If this regular expression is
286 not correct, the body fragment will not be highlighted with the
287 face `mh-folder-body'.")
288
289 (defvar mh-scan-subject-regexp
290 "^ *[0-9]+........[ ]*...................\\([Rr][Ee]\\(\\[[0-9]+\\]\\)?:\\s-*\\)*\\([^<\n]*\\)"
291 "This regular expression matches the subject.
292
293 It must match from the beginning of the line. Note that the
294 default setting of `mh-folder-font-lock-keywords' expects this
295 expression to contain at least three parenthesized expressions.
296 The first is expected to match the \"Re:\" string, if any, and is
297 highlighted with the face `mh-folder-followup'. The second
298 matches an optional bracketed number after \"Re:\", such as in
299 \"Re[2]:\" (and is thus a sub-expression of the first expression)
300 and the third is expected to match the subject line itself which
301 is highlighted with the face `mh-folder-subject'. For example,
302 the default (broken on multiple lines for readability) is
303
304 ^ *[0-9]+........[ ]*...................
305 \\\\([Rr][Ee]\\\\(\\\\\\=[[0-9]+\\\\]\\\\)?:\\\\s-*\\\\)*
306 \\\\([^<\\n]*\\\\)
307
308 This regular expression should be correct as it is needed by
309 non-fontification functions.")
310
311 (defvar mh-scan-sent-to-me-sender-regexp
312 "^ *[0-9]+.\\([bct]\\).....[ ]*\\(..................\\)"
313 "This regular expression matches messages sent to us.
314
315 Note that the default setting of `mh-folder-font-lock-keywords'
316 expects this expression to contain at least two parenthesized
317 expressions. The first should match the fontification hint (see
318 `mh-scan-format-nmh') and the second should match the user name
319 as in the default of
320
321 ^ *[0-9]+.\\\\([bct]\\\\).....[ ]*\\\\(..................\\\\)
322
323 If this regular expression is not correct, the notation hints
324 will not be highlighted with the face
325 `mh-mh-folder-sent-to-me-hint' and the sender will not be
326 highlighted with the face `mh-folder-sent-to-me-sender'.")
327
328 \f
329
330 (defvar mh-folder-font-lock-keywords
331 (list
332 ;; Folders when displaying index buffer
333 (list "^\\+.*"
334 '(0 'mh-search-folder))
335 ;; Marked for deletion
336 (list (concat mh-scan-deleted-msg-regexp ".*")
337 '(0 'mh-folder-deleted))
338 ;; Marked for refile
339 (list (concat mh-scan-refiled-msg-regexp ".*")
340 '(0 'mh-folder-refiled))
341 ;; After subject
342 (list mh-scan-body-regexp
343 '(1 'mh-folder-body nil t))
344 ;; Subject
345 '(mh-folder-font-lock-subject
346 (1 'mh-folder-followup append t)
347 (2 'mh-folder-subject append t))
348 ;; Current message number
349 (list mh-scan-cur-msg-number-regexp
350 '(1 'mh-folder-cur-msg-number))
351 ;; Message number
352 (list mh-scan-good-msg-regexp
353 '(1 'mh-folder-msg-number))
354 ;; Date
355 (list mh-scan-date-regexp
356 '(1 'mh-folder-date))
357 ;; Messages from me (To:)
358 (list mh-scan-rcpt-regexp
359 '(1 'mh-folder-to)
360 '(2 'mh-folder-address))
361 ;; Messages to me
362 (list mh-scan-sent-to-me-sender-regexp
363 '(1 'mh-folder-sent-to-me-hint)
364 '(2 'mh-folder-sent-to-me-sender)))
365 "Keywords (regular expressions) used to fontify the MH-Folder buffer.")
366
367 (defvar mh-scan-cmd-note-width 1
368 "Number of columns consumed by the cmd-note field in `mh-scan-format'.
369
370 This column will have one of the values: \" \", \"D\", \"^\", \"+\" and
371 where \" \" is the default value,
372
373 \"D\" is the `mh-note-deleted' character,
374 \"^\" is the `mh-note-refiled' character, and
375 \"+\" is the `mh-note-cur' character.")
376
377 (defvar mh-scan-destination-width 1
378 "Number of columns consumed by the destination field in `mh-scan-format'.
379
380 This column will have one of \" \", \"%\", \"-\", \"t\", \"c\", \"b\", or \"n\"
381 in it.
382
383 \" \" blank space is the default character.
384 \"%\" indicates that the message in in a named MH sequence.
385 \"-\" indicates that the message has been annotated with a replied field.
386 \"t\" indicates that the message contains mymbox in the To: field.
387 \"c\" indicates that the message contains mymbox in the Cc: field.
388 \"b\" indicates that the message contains mymbox in the Bcc: field.
389 \"n\" indicates that the message contains a Newsgroups: field.")
390
391 (defvar mh-scan-date-width 5
392 "Number of columns consumed by the date field in `mh-scan-format'.
393 This column will typically be of the form mm/dd.")
394
395 (defvar mh-scan-date-flag-width 1
396 "Number of columns consumed to flag (in)valid dates in `mh-scan-format'.
397 This column will have \" \" for valid and \"*\" for invalid or
398 missing dates.")
399
400 (defvar mh-scan-from-mbox-width 17
401 "Number of columns consumed with the \"From:\" line in `mh-scan-format'.
402 This column will have a friendly name or e-mail address of the
403 originator, or a \"To: address\" for outgoing e-mail messages.")
404
405 (defvar mh-scan-from-mbox-sep-width 2
406 "Number of columns consumed by whitespace after from-mbox in `mh-scan-format'.
407 This column will only ever have spaces in it.")
408
409 (defvar mh-scan-field-destination-offset
410 (+ mh-scan-cmd-note-width)
411 "The offset from the `mh-cmd-note' for the destination column.")
412
413 (defvar mh-scan-field-from-start-offset
414 (+ mh-scan-cmd-note-width
415 mh-scan-destination-width
416 mh-scan-date-width
417 mh-scan-date-flag-width)
418 "The offset from the `mh-cmd-note' to find the start of \"From:\" address.")
419
420 (defvar mh-scan-field-from-end-offset
421 (+ mh-scan-field-from-start-offset mh-scan-from-mbox-width)
422 "The offset from the `mh-cmd-note' to find the end of \"From:\" address.")
423
424 (defvar mh-scan-field-subject-start-offset
425 (+ mh-scan-cmd-note-width
426 mh-scan-destination-width
427 mh-scan-date-width
428 mh-scan-date-flag-width
429 mh-scan-from-mbox-width
430 mh-scan-from-mbox-sep-width)
431 "The offset from the `mh-cmd-note' to find the start of the subject.")
432
433 (defun mh-folder-font-lock-subject (limit)
434 "Return MH-E scan subject strings to font-lock between point and LIMIT."
435 (if (not (re-search-forward mh-scan-subject-regexp limit t))
436 nil
437 (if (match-beginning 1)
438 (set-match-data (list (match-beginning 1) (match-end 3)
439 (match-beginning 1) (match-end 3) nil nil))
440 (set-match-data (list (match-beginning 3) (match-end 3)
441 nil nil (match-beginning 3) (match-end 3))))
442 t))
443
444 \f
445
446 ;; Fontifify unseen mesages in bold.
447
448 (defmacro mh-generate-sequence-font-lock (seq prefix face)
449 "Generate the appropriate code to fontify messages in SEQ.
450 PREFIX is used to generate unique names for the variables and
451 functions defined by the macro. So a different prefix should be
452 provided for every invocation.
453 FACE is the font-lock face used to display the matching scan lines."
454 (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix)))
455 (func (intern (format "mh-folder-font-lock-%s" prefix))))
456 `(progn
457 (defvar ,cache nil
458 "Internal cache variable used for font-lock in MH-E.
459 Should only be non-nil through font-lock stepping, and nil once
460 font-lock is done highlighting.")
461 (make-variable-buffer-local ',cache)
462
463 (defun ,func (limit)
464 "Return unseen message lines to font-lock between point and LIMIT."
465 (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq))))
466 (let ((cur-msg (mh-get-msg-num nil)))
467 (cond ((not ,cache)
468 nil)
469 ((>= (point) limit) ;Presumably at end of buffer
470 (setq ,cache nil)
471 nil)
472 ((member cur-msg ,cache)
473 (let ((bpoint (progn (beginning-of-line)(point)))
474 (epoint (progn (forward-line 1)(point))))
475 (if (<= limit (point)) (setq ,cache nil))
476 (set-match-data (list bpoint epoint bpoint epoint))
477 t))
478 (t
479 ;; move forward one line at a time, checking each message
480 (while (and (= 0 (forward-line 1))
481 (> limit (point))
482 (not (member (mh-get-msg-num nil) ,cache))))
483 ;; Examine how we must have exited the loop...
484 (let ((cur-msg (mh-get-msg-num nil)))
485 (cond ((or (<= limit (point))
486 (not (member cur-msg ,cache)))
487 (setq ,cache nil)
488 nil)
489 ((member cur-msg ,cache)
490 (let ((bpoint (progn (beginning-of-line) (point)))
491 (epoint (progn (forward-line 1) (point))))
492 (if (<= limit (point)) (setq ,cache nil))
493 (set-match-data
494 (list bpoint epoint bpoint epoint))
495 t))))))))
496
497 (setq mh-folder-font-lock-keywords
498 (append mh-folder-font-lock-keywords
499 (list (list ',func (list 1 '',face 'prepend t))))))))
500
501 (mh-generate-sequence-font-lock mh-unseen-seq unseen bold)
502 (mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick)
503
504 \f
505
506 ;;; Internal variables:
507
508 (defvar mh-last-destination nil
509 "Destination of last refile or write command.")
510
511 (defvar mh-last-destination-folder nil
512 "Destination of last refile command.")
513
514 (defvar mh-last-destination-write nil
515 "Destination of last write command.")
516
517 (defvar mh-folder-mode-map (make-keymap)
518 "Keymap for MH folders.")
519
520 (defvar mh-arrow-marker nil
521 "Marker for arrow display in fringe.")
522
523 (defvar mh-delete-list nil
524 "List of message numbers to delete.
525 This variable can be used by
526 `mh-before-commands-processed-hook'.")
527
528 (defvar mh-refile-list nil
529 "List of folder names in `mh-seq-list'.
530 This variable can be used by
531 `mh-before-commands-processed-hook'.")
532
533 (defvar mh-folders-changed nil
534 "Lists which folders were affected by deletes and refiles.
535 This list will always include the current folder
536 `mh-current-folder'. This variable can be used by
537 `mh-after-commands-processed-hook'.")
538
539 (defvar mh-next-direction 'forward
540 "Direction to move to next message.")
541
542 (defvar mh-view-ops ()
543 "Stack of operations that change the folder view.
544 These operations include narrowing or threading.")
545
546 (defvar mh-folder-view-stack ()
547 "Stack of previous folder views.")
548
549 (defvar mh-index-data nil
550 "Info about index search results.")
551
552 (defvar mh-index-previous-search nil)
553 (defvar mh-index-msg-checksum-map nil)
554 (defvar mh-index-checksum-origin-map nil)
555 (defvar mh-index-sequence-search-flag nil)
556
557 (defvar mh-first-msg-num nil
558 "Number of first message in buffer.")
559
560 (defvar mh-last-msg-num nil
561 "Number of last msg in buffer.")
562
563 (defvar mh-mode-line-annotation nil
564 "Message range displayed in buffer.")
565
566 (defvar mh-sequence-notation-history nil
567 "Remember original notation that is overwritten by `mh-note-seq'.")
568
569 (defvar mh-colors-available-flag nil
570 "Non-nil means colors are available.")
571
572 \f
573
574 ;;; Macros and generic functions:
575
576 (defun mh-mapc (function list)
577 "Apply FUNCTION to each element of LIST for side effects only."
578 (while list
579 (funcall function (car list))
580 (setq list (cdr list))))
581
582 (defun mh-scan-format ()
583 "Return the output format argument for the scan program."
584 (if (equal mh-scan-format-file t)
585 (list "-format" (if (mh-variant-p 'nmh 'mu-mh)
586 (list (mh-update-scan-format
587 mh-scan-format-nmh mh-cmd-note))
588 (list (mh-update-scan-format
589 mh-scan-format-mh mh-cmd-note))))
590 (if (not (equal mh-scan-format-file nil))
591 (list "-form" mh-scan-format-file))))
592
593 \f
594
595 ;;; Entry points:
596
597 ;;;###autoload
598 (defun mh-rmail (&optional arg)
599 "Incorporate new mail with MH.
600 Scan an MH folder if ARG is non-nil.
601
602 This function is an entry point to MH-E, the Emacs interface to
603 the MH mail system."
604 (interactive "P")
605 (mh-find-path)
606 (if arg
607 (call-interactively 'mh-visit-folder)
608 (unless (get-buffer mh-inbox)
609 (mh-visit-folder mh-inbox (symbol-name mh-unseen-seq)))
610 (mh-inc-folder)))
611
612 ;;;###autoload
613 (defun mh-nmail (&optional arg)
614 "Check for new mail in inbox folder.
615 Scan an MH folder if ARG is non-nil.
616
617 This function is an entry point to MH-E, the Emacs interface to
618 the MH mail system."
619 (interactive "P")
620 (mh-find-path) ; init mh-inbox
621 (if arg
622 (call-interactively 'mh-visit-folder)
623 (mh-visit-folder mh-inbox)))
624
625 \f
626
627 ;;; User executable MH-E commands:
628
629 (defun mh-delete-msg (range)
630 "Delete RANGE\\<mh-folder-mode-map>.
631
632 To mark a message for deletion, use this command. A \"D\" is
633 placed by the message in the scan window, and the next undeleted
634 message is displayed. If the previous command had been
635 \\[mh-previous-undeleted-msg], then the next message displayed is
636 the first undeleted message previous to the message just deleted.
637 Use \\[mh-next-undeleted-msg] to force subsequent
638 \\[mh-delete-msg] commands to move forward to the next undeleted
639 message after deleting the message under the cursor.
640
641 The hook `mh-delete-msg-hook' is called after you mark a message
642 for deletion. For example, a past maintainer of MH-E used this
643 once when he kept statistics on his mail usage.
644
645 Check the documentation of `mh-interactive-range' to see how
646 RANGE is read in interactive use."
647 (interactive (list (mh-interactive-range "Delete")))
648 (mh-delete-msg-no-motion range)
649 (if (looking-at mh-scan-deleted-msg-regexp)
650 (mh-next-msg)))
651
652 (defun mh-delete-msg-no-motion (range)
653 "Delete RANGE, don't move to next message.
654
655 This command marks the RANGE for deletion but leaves the cursor
656 at the current message in case you wish to perform other
657 operations on the message.
658
659 Check the documentation of `mh-interactive-range' to see how
660 RANGE is read in interactive use."
661 (interactive (list (mh-interactive-range "Delete")))
662 (mh-iterate-on-range () range
663 (mh-delete-a-msg nil)))
664
665 (defun mh-execute-commands ()
666 "Process outstanding delete and refile requests\\<mh-folder-mode-map>.
667
668 If you've marked messages to be deleted or refiled and you want
669 to go ahead and delete or refile the messages, use this command.
670 Many MH-E commands that may affect the numbering of the
671 messages (such as \\[mh-rescan-folder] or \\[mh-pack-folder])
672 will ask if you want to process refiles or deletes first and then
673 either run this command for you or undo the pending refiles and
674 deletes, which are lost.
675
676 This function runs `mh-before-commands-processed-hook' before the
677 commands are processed and `mh-after-commands-processed-hook'
678 after the commands are processed."
679 (interactive)
680 (if mh-folder-view-stack (mh-widen t))
681 (mh-process-commands mh-current-folder)
682 (mh-set-scan-mode)
683 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
684 (mh-make-folder-mode-line)
685 t) ; return t for write-file-functions
686
687 (defun mh-first-msg ()
688 "Display first message."
689 (interactive)
690 (goto-char (point-min))
691 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp)))
692 (forward-line 1)))
693
694 (defun mh-header-display ()
695 "Display message with all header fields\\<mh-folder-mode-map>.
696
697 Use the command \\[mh-show] to show the message normally again."
698 (interactive)
699 (and (not mh-showing-with-headers)
700 (or mh-mhl-format-file mh-clean-message-header-flag)
701 (mh-invalidate-show-buffer))
702 (let ((mh-decode-mime-flag nil)
703 (mh-mhl-format-file nil)
704 (mh-clean-message-header-flag nil))
705 (mh-show-msg nil)
706 (mh-in-show-buffer (mh-show-buffer)
707 (goto-char (point-min))
708 (mh-recenter 0))
709 (setq mh-showing-with-headers t)))
710
711 (defun mh-inc-folder (&optional file folder)
712 "Incorporate new mail into a folder.
713
714 You can incorporate mail from any file into the current folder by
715 specifying a prefix argument; you'll be prompted for the name of
716 the FILE to use as well as the destination FOLDER
717
718 The hook `mh-inc-folder-hook' is run after incorporating new
719 mail.
720
721 Do not call this function from outside MH-E; use \\[mh-rmail]
722 instead."
723 (interactive (list (if current-prefix-arg
724 (expand-file-name
725 (read-file-name "inc mail from file: "
726 mh-user-path)))
727 (if current-prefix-arg
728 (mh-prompt-for-folder "inc mail into" mh-inbox t))))
729 (if (not folder)
730 (setq folder mh-inbox))
731 (let ((threading-needed-flag nil))
732 (let ((config (current-window-configuration)))
733 (when (and mh-show-buffer (get-buffer mh-show-buffer))
734 (delete-windows-on mh-show-buffer))
735 (cond ((not (get-buffer folder))
736 (mh-make-folder folder)
737 (setq threading-needed-flag mh-show-threads-flag)
738 (setq mh-previous-window-config config))
739 ((not (eq (current-buffer) (get-buffer folder)))
740 (switch-to-buffer folder)
741 (setq mh-previous-window-config config))))
742 (mh-get-new-mail file)
743 (when (and threading-needed-flag
744 (save-excursion
745 (goto-char (point-min))
746 (or (null mh-large-folder)
747 (not (equal (forward-line (1+ mh-large-folder)) 0))
748 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
749 nil))))
750 (mh-toggle-threads))
751 (beginning-of-line)
752 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show))
753 (run-hooks 'mh-inc-folder-hook)))
754
755 (defun mh-last-msg ()
756 "Display last message."
757 (interactive)
758 (goto-char (point-max))
759 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp)))
760 (forward-line -1))
761 (mh-recenter nil))
762
763 (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag)
764 "Display next message.
765
766 This command can be given a prefix argument COUNT to specify how
767 many unread messages to skip.
768
769 In a program, pause for a second after printing message if we are
770 at the last undeleted message and optional argument
771 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
772 (interactive "p")
773 (setq mh-next-direction 'forward)
774 (forward-line 1)
775 (cond ((re-search-forward mh-scan-good-msg-regexp nil t count)
776 (beginning-of-line)
777 (mh-maybe-show))
778 (t (forward-line -1)
779 (message "No more undeleted messages")
780 (if wait-after-complaining-flag (sit-for 1)))))
781
782 (defun mh-folder-from-address ()
783 "Derive folder name from sender.
784
785 The name of the folder is derived as follows:
786
787 a) The folder name associated with the first address found in
788 the list `mh-default-folder-list' is used. Each element in
789 this list contains a \"Check Recipient\" item. If this item is
790 turned on, then the address is checked against the recipient
791 instead of the sender. This is useful for mailing lists.
792
793 b) An alias prefixed by `mh-default-folder-prefix'
794 corresponding to the address is used. The prefix is used to
795 prevent clutter in your mail directory.
796
797 Return nil if a folder name was not derived, or if the variable
798 `mh-default-folder-must-exist-flag' is t and the folder does not
799 exist."
800 ;; Loop for all entries in mh-default-folder-list
801 (save-restriction
802 (goto-char (point-min))
803 (re-search-forward "\n\n" nil 'limit)
804 (narrow-to-region (point-min) (point))
805 (let ((to/cc (concat (or (message-fetch-field "to") "") ", "
806 (or (message-fetch-field "cc") "")))
807 (from (or (message-fetch-field "from") ""))
808 folder-name)
809 (setq folder-name
810 (loop for list in mh-default-folder-list
811 when (string-match (nth 0 list) (if (nth 2 list) to/cc from))
812 return (nth 1 list)
813 finally return nil))
814
815 ;; Make sure a result from `mh-default-folder-list' begins with "+"
816 ;; since 'mh-expand-file-name below depends on it
817 (when (and folder-name (not (eq (aref folder-name 0) ?+)))
818 (setq folder-name (concat "+" folder-name)))
819
820 ;; If not, is there an alias for the address?
821 (when (not folder-name)
822 (let* ((from-header (mh-extract-from-header-value))
823 (address (and from-header
824 (nth 1 (mail-extract-address-components
825 from-header))))
826 (alias (and address (mh-alias-address-to-alias address))))
827 (when alias
828 (setq folder-name
829 (and alias (concat "+" mh-default-folder-prefix alias))))))
830
831 ;; If mh-default-folder-must-exist-flag set, check that folder exists.
832 (if (and folder-name
833 (or (not mh-default-folder-must-exist-flag)
834 (file-exists-p (mh-expand-file-name folder-name))))
835 folder-name))))
836
837 (defun mh-prompt-for-refile-folder ()
838 "Prompt the user for a folder in which the message should be filed.
839 The folder is returned as a string.
840
841 The default folder name is generated by the option
842 `mh-default-folder-for-message-function' if it is non-nil or
843 `mh-folder-from-address'."
844 (mh-prompt-for-folder
845 "Destination"
846 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t)))))
847 (if (null refile-file) ""
848 (save-excursion
849 (set-buffer (get-buffer-create mh-temp-buffer))
850 (erase-buffer)
851 (insert-file-contents refile-file)
852 (or (and mh-default-folder-for-message-function
853 (let ((buffer-file-name refile-file))
854 (funcall mh-default-folder-for-message-function)))
855 (mh-folder-from-address)
856 (and (eq 'refile (car mh-last-destination-folder))
857 (symbol-name (cdr mh-last-destination-folder)))
858 ""))))
859 t))
860
861 (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag)
862 "Refile (output) RANGE into FOLDER.
863
864 You are prompted for the folder name. Note that this command can also
865 be used to create folders. If you specify a folder that does not
866 exist, you will be prompted to create it.
867
868 The hook `mh-refile-msg-hook' is called after a message is marked to
869 be refiled.
870
871 Check the documentation of `mh-interactive-range' to see how RANGE is
872 read in interactive use.
873
874 In a program, the variables `mh-last-destination' and
875 `mh-last-destination-folder' are not updated if
876 DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil."
877 (interactive (list (mh-interactive-range "Refile")
878 (intern (mh-prompt-for-refile-folder))))
879 (unless dont-update-last-destination-flag
880 (setq mh-last-destination (cons 'refile folder)
881 mh-last-destination-folder mh-last-destination))
882 (mh-iterate-on-range () range
883 (mh-refile-a-msg nil folder))
884 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg)))
885
886 (defun mh-refile-or-write-again (range &optional interactive-flag)
887 "Repeat last output command.
888
889 If you are refiling several messages into the same folder, you
890 can use this command to repeat the last
891 refile (\\[mh-refile-msg]) or write (\\[mh-write-msg-to-file]).
892 You can use a range.
893
894 Check the documentation of `mh-interactive-range' to see how RANGE is
895 read in interactive use.
896
897 In a program, a non-nil INTERACTIVE-FLAG means that the function was
898 called interactively."
899 (interactive (list (mh-interactive-range "Redo") t))
900 (if (null mh-last-destination)
901 (error "No previous refile or write"))
902 (cond ((eq (car mh-last-destination) 'refile)
903 (mh-refile-msg range (cdr mh-last-destination))
904 (message "Destination folder: %s" (cdr mh-last-destination)))
905 (t
906 (mh-iterate-on-range msg range
907 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination)))
908 (mh-next-msg interactive-flag))))
909
910 (defun mh-quit ()
911 "Quit the current MH-E folder.
912
913 When you want to quit using MH-E and go back to editing, you can use
914 this command. This buries the buffers of the current MH-E folder and
915 restores the buffers that were present when you first ran
916 \\[mh-rmail]. It also removes any MH-E working buffers whose name
917 begins with \" *mh-\" or \"*MH-E \". You can later restore your MH-E
918 session by selecting the \"+inbox\" buffer or by running \\[mh-rmail]
919 again.
920
921 The two hooks `mh-before-quit-hook' and `mh-quit-hook' are called by
922 this function. The former one is called before the quit occurs, so you
923 might use it to perform any MH-E operations; you could perform some
924 query and abort the quit or call `mh-execute-commands', for example.
925 The latter is not run in an MH-E context, so you might use it to
926 modify the window setup."
927 (interactive)
928 (run-hooks 'mh-before-quit-hook)
929 (let ((show-buffer (get-buffer mh-show-buffer)))
930 (when show-buffer
931 (kill-buffer show-buffer)))
932 (mh-update-sequences)
933 (mh-destroy-postponed-handles)
934 (bury-buffer (current-buffer))
935
936 ;; Delete all MH-E temporary and working buffers.
937 (dolist (buffer (buffer-list))
938 (when (or (string-match "^ \\*mh-" (buffer-name buffer))
939 (string-match "^\\*MH-E " (buffer-name buffer)))
940 (kill-buffer buffer)))
941
942 (if mh-previous-window-config
943 (set-window-configuration mh-previous-window-config))
944 (run-hooks 'mh-quit-hook))
945
946 (defun mh-page-msg (&optional lines)
947 "Display next page in message.
948
949 You can give this command a prefix argument that specifies the
950 number of LINES to scroll. This command will also show the next
951 undeleted message if it is used at the bottom of a message."
952 (interactive "P")
953 (if mh-showing-mode
954 (if mh-page-to-next-msg-flag
955 (if (equal mh-next-direction 'backward)
956 (mh-previous-undeleted-msg)
957 (mh-next-undeleted-msg))
958 (if (mh-in-show-buffer (mh-show-buffer)
959 (pos-visible-in-window-p (point-max)))
960 (progn
961 (message
962 "End of message (Type %s to read %s undeleted message)"
963 (single-key-description last-input-event)
964 (if (equal mh-next-direction 'backward)
965 "previous"
966 "next"))
967 (setq mh-page-to-next-msg-flag t))
968 (scroll-other-window lines)))
969 (mh-show)))
970
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 (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag)
981 "Display previous message.
982
983 This command can be given a prefix argument COUNT to specify how
984 many unread messages to skip.
985
986 In a program, pause for a second after printing message if we are
987 at the last undeleted message and optional argument
988 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
989 (interactive "p")
990 (setq mh-next-direction 'backward)
991 (beginning-of-line)
992 (cond ((re-search-backward mh-scan-good-msg-regexp nil t count)
993 (mh-maybe-show))
994 (t (message "No previous undeleted message")
995 (if wait-after-complaining-flag (sit-for 1)))))
996
997 (defun mh-previous-unread-msg (&optional count)
998 "Display previous unread message.
999
1000 This command can be given a prefix argument COUNT to specify how
1001 many unread messages to skip."
1002 (interactive "p")
1003 (unless (> count 0)
1004 (error "The function `mh-previous-unread-msg' expects positive argument"))
1005 (setq count (1- count))
1006 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list)))
1007 (cur-msg (mh-get-msg-num nil)))
1008 (cond ((and (not cur-msg) (not (bobp))
1009 ;; If we are at the end of the buffer back up one line and go
1010 ;; to unread message after that.
1011 (progn
1012 (forward-line -1)
1013 (setq cur-msg (mh-get-msg-num nil)))
1014 nil))
1015 ((or (null unread-sequence) (not cur-msg))
1016 ;; No unread message or there aren't any messages in buffer...
1017 (message "No more unread messages"))
1018 ((progn
1019 ;; Skip count messages...
1020 (while (and unread-sequence (>= (car unread-sequence) cur-msg))
1021 (setq unread-sequence (cdr unread-sequence)))
1022 (while (> count 0)
1023 (setq unread-sequence (cdr unread-sequence))
1024 (setq count (1- count)))
1025 (not (car unread-sequence)))
1026 (message "No more unread messages"))
1027 (t (loop for msg in unread-sequence
1028 when (mh-goto-msg msg t) return nil
1029 finally (message "No more unread messages"))))))
1030
1031 (defun mh-goto-next-button (backward-flag &optional criterion)
1032 "Search for next button satisfying criterion.
1033
1034 If BACKWARD-FLAG is non-nil search backward in the buffer for a mime
1035 button.
1036 If CRITERION is a function or a symbol which has a function binding
1037 then that function must return non-nil at the button we stop."
1038 (unless (or (and (symbolp criterion) (fboundp criterion))
1039 (functionp criterion))
1040 (setq criterion (lambda (x) t)))
1041 ;; Move to the next button in the buffer satisfying criterion
1042 (goto-char (or (save-excursion
1043 (beginning-of-line)
1044 ;; Find point before current button
1045 (let ((point-before-current-button
1046 (save-excursion
1047 (while (get-text-property (point) 'mh-data)
1048 (unless (= (forward-line
1049 (if backward-flag 1 -1))
1050 0)
1051 (if backward-flag
1052 (goto-char (point-min))
1053 (goto-char (point-max)))))
1054 (point))))
1055 ;; Skip over current button
1056 (while (and (get-text-property (point) 'mh-data)
1057 (not (if backward-flag (bobp) (eobp))))
1058 (forward-line (if backward-flag -1 1)))
1059 ;; Stop at next MIME button if any exists.
1060 (block loop
1061 (while (/= (progn
1062 (unless (= (forward-line
1063 (if backward-flag -1 1))
1064 0)
1065 (if backward-flag
1066 (goto-char (point-max))
1067 (goto-char (point-min)))
1068 (beginning-of-line))
1069 (point))
1070 point-before-current-button)
1071 (when (and (get-text-property (point) 'mh-data)
1072 (funcall criterion (point)))
1073 (return-from loop (point))))
1074 nil)))
1075 (point))))
1076
1077 (defun mh-next-button (&optional backward-flag)
1078 "Go to the next button.
1079
1080 If the end of the buffer is reached then the search wraps over to
1081 the start of the buffer.
1082
1083 If an optional prefix argument BACKWARD-FLAG is given, the cursor
1084 will move to the previous button."
1085 (interactive (list current-prefix-arg))
1086 (unless mh-showing-mode
1087 (mh-show))
1088 (mh-in-show-buffer (mh-show-buffer)
1089 (mh-goto-next-button backward-flag)))
1090
1091 (defun mh-prev-button ()
1092 "Go to the previous button.
1093
1094 If the beginning of the buffer is reached then the search wraps
1095 over to the end of the buffer."
1096 (interactive)
1097 (mh-next-button t))
1098
1099 (defun mh-folder-mime-action (part-index action include-security-flag)
1100 "Go to PART-INDEX and carry out ACTION.
1101
1102 If PART-INDEX is nil then go to the next part in the buffer. The
1103 search for the next buffer wraps around if end of buffer is reached.
1104 If argument INCLUDE-SECURITY-FLAG is non-nil then include security
1105 info buttons when searching for a suitable parts."
1106 (unless mh-showing-mode
1107 (mh-show))
1108 (mh-in-show-buffer (mh-show-buffer)
1109 (let ((criterion
1110 (cond (part-index
1111 (lambda (p)
1112 (let ((part (get-text-property p 'mh-part)))
1113 (and (integerp part) (= part part-index)))))
1114 (t (lambda (p)
1115 (if include-security-flag
1116 (get-text-property p 'mh-data)
1117 (integerp (get-text-property p 'mh-part)))))))
1118 (point (point)))
1119 (cond ((and (get-text-property point 'mh-part)
1120 (or (null part-index)
1121 (= (get-text-property point 'mh-part) part-index)))
1122 (funcall action))
1123 ((and (get-text-property point 'mh-data)
1124 include-security-flag
1125 (null part-index))
1126 (funcall action))
1127 (t
1128 (mh-goto-next-button nil criterion)
1129 (if (= (point) point)
1130 (message "No matching MIME part found")
1131 (funcall action)))))))
1132
1133 (defun mh-folder-toggle-mime-part (part-index)
1134 "View attachment.
1135
1136 This command displays (or hides) the attachment associated with
1137 the button under the cursor. If the cursor is not located over a
1138 button, then the cursor first moves to the next button, wrapping
1139 to the beginning of the message if necessary. This command has
1140 the advantage over related commands of working from the MH-Folder
1141 buffer.
1142
1143 You can also provide a numeric prefix argument PART-INDEX to view
1144 the attachment labeled with that number. If Emacs does not know
1145 how to display the attachment, then Emacs offers to save the
1146 attachment in a file."
1147 (interactive "P")
1148 (when (consp part-index) (setq part-index (car part-index)))
1149 (mh-folder-mime-action part-index #'mh-press-button t))
1150
1151 (defun mh-folder-inline-mime-part (part-index)
1152 "Show attachment verbatim.
1153
1154 You can view the raw contents of an attachment with this command.
1155 This command displays (or hides) the contents of the attachment
1156 associated with the button under the cursor verbatim. If the
1157 cursor is not located over a button, then the cursor first moves
1158 to the next button, wrapping to the beginning of the message if
1159 necessary.
1160
1161 You can also provide a numeric prefix argument PART-INDEX to view
1162 the attachment labeled with that number."
1163 (interactive "P")
1164 (when (consp part-index) (setq part-index (car part-index)))
1165 (mh-folder-mime-action part-index #'mh-mime-inline-part nil))
1166
1167 (defun mh-folder-save-mime-part (part-index)
1168 "Save (output) attachment.
1169
1170 This command saves the attachment associated with the button under the
1171 cursor. If the cursor is not located over a button, then the cursor
1172 first moves to the next button, wrapping to the beginning of the
1173 message if necessary.
1174
1175 You can also provide a numeric prefix argument PART-INDEX to save the
1176 attachment labeled with that number.
1177
1178 This command prompts you for a filename and suggests a specific name
1179 if it is available."
1180 (interactive "P")
1181 (when (consp part-index) (setq part-index (car part-index)))
1182 (mh-folder-mime-action part-index #'mh-mime-save-part nil))
1183
1184 (defun mh-reset-threads-and-narrowing ()
1185 "Reset all variables pertaining to threads and narrowing.
1186 Also removes all content from the folder buffer."
1187 (setq mh-view-ops ())
1188 (setq mh-folder-view-stack ())
1189 (setq mh-thread-scan-line-map-stack ())
1190 (let ((buffer-read-only nil)) (erase-buffer)))
1191
1192 (defun mh-rescan-folder (&optional range dont-exec-pending)
1193 "Rescan folder\\<mh-folder-mode-map>.
1194
1195 This command is useful to grab all messages in your \"+inbox\" after
1196 processing your new mail for the first time. If you don't want to
1197 rescan the entire folder, this command will accept a RANGE. Check the
1198 documentation of `mh-interactive-range' to see how RANGE is read in
1199 interactive use.
1200
1201 This command will ask if you want to process refiles or deletes first
1202 and then either run \\[mh-execute-commands] for you or undo the
1203 pending refiles and deletes, which are lost.
1204
1205 In a program, the processing of outstanding commands is not performed
1206 if DONT-EXEC-PENDING is non-nil."
1207 (interactive (list (if current-prefix-arg
1208 (mh-read-range "Rescan" mh-current-folder t nil t
1209 mh-interpret-number-as-range-flag)
1210 nil)))
1211 (setq mh-next-direction 'forward)
1212 (let ((threaded-flag (memq 'unthread mh-view-ops))
1213 (msg-num (mh-get-msg-num nil)))
1214 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending)
1215 ;; If there isn't a cur sequence, mh-scan-folder goes to the first message.
1216 ;; Try to stay where we were.
1217 (if (null (car (mh-seq-to-msgs 'cur)))
1218 (mh-goto-msg msg-num t t))
1219 (cond (threaded-flag (mh-toggle-threads))
1220 (mh-index-data (mh-index-insert-folder-headers)))))
1221
1222 (defun mh-write-msg-to-file (message file no-header)
1223 "Append MESSAGE to end of FILE\\<mh-folder-mode-map>.
1224
1225 You are prompted for the filename. If the file already exists,
1226 the message is appended to it. You can also write the message to
1227 the file without the header by specifying a prefix argument
1228 NO-HEADER. Subsequent writes to the same file can be made with
1229 the command \\[mh-refile-or-write-again]."
1230 (interactive
1231 (list (mh-get-msg-num t)
1232 (let ((default-dir (if (eq 'write (car mh-last-destination-write))
1233 (file-name-directory
1234 (car (cdr mh-last-destination-write)))
1235 default-directory)))
1236 (read-file-name (format "Save message%s in file: "
1237 (if current-prefix-arg " body" ""))
1238 default-dir
1239 (if (eq 'write (car mh-last-destination-write))
1240 (car (cdr mh-last-destination-write))
1241 (expand-file-name "mail.out" default-dir))))
1242 current-prefix-arg))
1243 (let ((msg-file-to-output (mh-msg-filename message))
1244 (output-file (mh-expand-file-name file)))
1245 (setq mh-last-destination (list 'write file (if no-header 'no-header))
1246 mh-last-destination-write mh-last-destination)
1247 (save-excursion
1248 (set-buffer (get-buffer-create mh-temp-buffer))
1249 (erase-buffer)
1250 (insert-file-contents msg-file-to-output)
1251 (goto-char (point-min))
1252 (if no-header (search-forward "\n\n"))
1253 (append-to-file (point) (point-max) output-file))))
1254
1255 (defun mh-toggle-showing ()
1256 "Toggle between MH-Folder and MH-Folder Show modes.
1257
1258 This command switches between MH-Folder mode and MH-Folder Show
1259 mode. MH-Folder mode turns off the associated show buffer so that
1260 you can perform operations on the messages quickly without
1261 reading them. This is an excellent way to prune out your junk
1262 mail or to refile a group of messages to another folder for later
1263 examination."
1264 (interactive)
1265 (if mh-showing-mode
1266 (mh-set-scan-mode)
1267 (mh-show)))
1268
1269 (defun mh-undo (range)
1270 "Undo pending deletes or refiles in RANGE.
1271
1272 If you've deleted a message or refiled it, but changed your mind,
1273 you can cancel the action before you've executed it. Use this
1274 command to undo a refile on or deletion of a single message. You
1275 can also undo refiles and deletes for messages that are found in
1276 a given RANGE.
1277
1278 Check the documentation of `mh-interactive-range' to see how
1279 RANGE is read in interactive use."
1280 (interactive (list (mh-interactive-range "Undo")))
1281 (cond ((numberp range)
1282 (let ((original-position (point)))
1283 (beginning-of-line)
1284 (while (not (or (looking-at mh-scan-deleted-msg-regexp)
1285 (looking-at mh-scan-refiled-msg-regexp)
1286 (and (eq mh-next-direction 'forward) (bobp))
1287 (and (eq mh-next-direction 'backward)
1288 (save-excursion (forward-line) (eobp)))))
1289 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
1290 (if (or (looking-at mh-scan-deleted-msg-regexp)
1291 (looking-at mh-scan-refiled-msg-regexp))
1292 (progn
1293 (mh-undo-msg (mh-get-msg-num t))
1294 (mh-maybe-show))
1295 (goto-char original-position)
1296 (error "Nothing to undo"))))
1297 (t (mh-iterate-on-range () range
1298 (mh-undo-msg nil))))
1299 (if (not (mh-outstanding-commands-p))
1300 (mh-set-folder-modified-p nil)))
1301
1302 (defun mh-folder-line-matches-show-buffer-p ()
1303 "Return t if the message under point in folder-mode is in the show buffer.
1304 Return nil in any other circumstance (no message under point, no
1305 show buffer, the message in the show buffer doesn't match."
1306 (and (eq major-mode 'mh-folder-mode)
1307 (mh-get-msg-num nil)
1308 mh-show-buffer
1309 (get-buffer mh-show-buffer)
1310 (buffer-file-name (get-buffer mh-show-buffer))
1311 (string-match ".*/\\([0-9]+\\)$"
1312 (buffer-file-name (get-buffer mh-show-buffer)))
1313 (string-equal
1314 (match-string 1 (buffer-file-name (get-buffer mh-show-buffer)))
1315 (int-to-string (mh-get-msg-num nil)))))
1316
1317 (eval-when-compile (require 'gnus))
1318
1319 (defmacro mh-macro-expansion-time-gnus-version ()
1320 "Return Gnus version available at macro expansion time.
1321 The macro evaluates the Gnus version at macro expansion time. If
1322 MH-E was compiled then macro expansion happens at compile time."
1323 gnus-version)
1324
1325 (defun mh-run-time-gnus-version ()
1326 "Return Gnus version available at run time."
1327 (require 'gnus)
1328 gnus-version)
1329
1330 ;;;###autoload
1331 (defun mh-version ()
1332 "Display version information about MH-E and the MH mail handling system."
1333 (interactive)
1334 (set-buffer (get-buffer-create mh-info-buffer))
1335 (erase-buffer)
1336 ;; MH-E version.
1337 (insert "MH-E " mh-version "\n\n")
1338 ;; MH-E compilation details.
1339 (insert "MH-E compilation details:\n")
1340 (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version)))
1341 (gnus-compiled-version (if compiled-mhe
1342 (mh-macro-expansion-time-gnus-version)
1343 "N/A")))
1344 (insert " Byte compiled:\t\t" (if compiled-mhe "yes" "no") "\n"
1345 " Gnus (compile-time):\t" gnus-compiled-version "\n"
1346 " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
1347 ;; Emacs version.
1348 (insert (emacs-version) "\n\n")
1349 ;; MH version.
1350 (if mh-variant-in-use
1351 (insert mh-variant-in-use "\n"
1352 " mh-progs:\t" mh-progs "\n"
1353 " mh-lib:\t" mh-lib "\n"
1354 " mh-lib-progs:\t" mh-lib-progs "\n\n")
1355 (insert "No MH variant detected\n"))
1356 ;; Linux version.
1357 (condition-case ()
1358 (call-process "uname" nil t nil "-a")
1359 (file-error))
1360 (goto-char (point-min))
1361 (display-buffer mh-info-buffer))
1362
1363 (defun mh-parse-flist-output-line (line &optional current-folder)
1364 "Parse LINE to generate folder name, unseen messages and total messages.
1365 If CURRENT-FOLDER is non-nil then it contains the current folder
1366 name and it is used to avoid problems in corner cases involving
1367 folders whose names end with a '+' character."
1368 (with-temp-buffer
1369 (insert line)
1370 (goto-char (point-max))
1371 (let (folder unseen total p)
1372 (when (search-backward " out of " (point-min) t)
1373 (setq total (read-from-string
1374 (buffer-substring-no-properties
1375 (match-end 0) (line-end-position))))
1376 (when (search-backward " in sequence " (point-min) t)
1377 (setq p (point))
1378 (when (search-backward " has " (point-min) t)
1379 (setq unseen (read-from-string (buffer-substring-no-properties
1380 (match-end 0) p)))
1381 (while (eq (char-after) ? )
1382 (backward-char))
1383 (setq folder (buffer-substring-no-properties
1384 (point-min) (1+ (point))))
1385 (when (and (equal (aref folder (1- (length folder))) ?+)
1386 (equal current-folder folder))
1387 (setq folder (substring folder 0 (1- (length folder)))))
1388 (values (format "+%s" folder) (car unseen) (car total))))))))
1389
1390 (defun mh-folder-size-folder (folder)
1391 "Find size of FOLDER using \"folder\"."
1392 (with-temp-buffer
1393 (let ((u (length (cdr (assoc mh-unseen-seq
1394 (mh-read-folder-sequences folder nil))))))
1395 (call-process (expand-file-name "folder" mh-progs) nil t nil
1396 "-norecurse" folder)
1397 (goto-char (point-min))
1398 (if (re-search-forward " has \\([0-9]+\\) " nil t)
1399 (values (car (read-from-string (match-string 1))) u folder)
1400 (values 0 u folder)))))
1401
1402 (defun mh-folder-size-flist (folder)
1403 "Find size of FOLDER using \"flist\"."
1404 (with-temp-buffer
1405 (call-process (expand-file-name "flist" mh-progs) nil t nil "-showzero"
1406 "-norecurse" folder "-sequence" (symbol-name mh-unseen-seq))
1407 (goto-char (point-min))
1408 (multiple-value-bind (folder unseen total)
1409 (mh-parse-flist-output-line
1410 (buffer-substring (point) (line-end-position)))
1411 (values total unseen folder))))
1412
1413 (defun mh-folder-size (folder)
1414 "Find size of FOLDER."
1415 (if mh-flists-present-flag
1416 (mh-folder-size-flist folder)
1417 (mh-folder-size-folder folder)))
1418
1419 (defun mh-visit-folder (folder &optional range index-data)
1420 "Visit FOLDER.
1421
1422 When you want to read the messages that you have refiled into folders,
1423 use this command to visit the folder. You are prompted for the folder
1424 name.
1425
1426 The folder buffer will show just unseen messages if there are any;
1427 otherwise, it will show all the messages in the buffer as long there
1428 are fewer than `mh-large-folder' messages. If there are more, then you
1429 are prompted for a range of messages to scan.
1430
1431 You can provide a prefix argument in order to specify a RANGE of
1432 messages to show when you visit the folder. In this case, regions are
1433 not used to specify the range and `mh-large-folder' is ignored. Check
1434 the documentation of `mh-interactive-range' to see how RANGE is read
1435 in interactive use.
1436
1437 Note that this command can also be used to create folders. If you
1438 specify a folder that does not exist, you will be prompted to create
1439 it.
1440
1441 Do not call this function from outside MH-E; use \\[mh-rmail] instead.
1442
1443 If, in a program, RANGE is nil (the default), then all messages in
1444 FOLDER are displayed. If an index buffer is being created then
1445 INDEX-DATA is used to initialize the index buffer specific data
1446 structures."
1447 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t)))
1448 (list folder-name
1449 (mh-read-range "Scan" folder-name t nil
1450 current-prefix-arg
1451 mh-interpret-number-as-range-flag))))
1452 (let ((config (current-window-configuration))
1453 (current-buffer (current-buffer))
1454 (threaded-view-flag mh-show-threads-flag))
1455 (delete-other-windows)
1456 (save-excursion
1457 (when (get-buffer folder)
1458 (set-buffer folder)
1459 (setq threaded-view-flag (memq 'unthread mh-view-ops))))
1460 (when index-data
1461 (mh-make-folder folder)
1462 (setq mh-index-data (car index-data)
1463 mh-index-msg-checksum-map (make-hash-table :test #'equal)
1464 mh-index-checksum-origin-map (make-hash-table :test #'equal))
1465 (mh-index-update-maps folder (cadr index-data))
1466 (mh-index-create-sequences))
1467 (mh-scan-folder folder (or range "all"))
1468 (cond ((and threaded-view-flag
1469 (save-excursion
1470 (goto-char (point-min))
1471 (or (null mh-large-folder)
1472 (not (equal (forward-line (1+ mh-large-folder)) 0))
1473 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
1474 nil))))
1475 (mh-toggle-threads))
1476 (mh-index-data
1477 (mh-index-insert-folder-headers)))
1478 (unless (eq current-buffer (current-buffer))
1479 (setq mh-previous-window-config config)))
1480 nil)
1481
1482 (defun mh-update-sequences ()
1483 "Flush MH-E's state out to MH.
1484
1485 This function updates the sequence specified by your
1486 \"Unseen-Sequence:\" profile component, \"cur\", and the sequence
1487 listed by the `mh-tick-seq' option which is \"tick\" by default.
1488 The message at the cursor is used for \"cur\"."
1489 (interactive)
1490 ;; mh-update-sequences is the opposite of mh-read-folder-sequences,
1491 ;; which updates MH-E's state from MH.
1492 (let ((folder-set (mh-update-unseen))
1493 (new-cur (mh-get-msg-num nil)))
1494 (if new-cur
1495 (let ((seq-entry (mh-find-seq 'cur)))
1496 (mh-remove-cur-notation)
1497 (setcdr seq-entry
1498 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq
1499 (mh-define-sequence 'cur (list new-cur))
1500 (beginning-of-line)
1501 (if (looking-at mh-scan-good-msg-regexp)
1502 (mh-notate-cur)))
1503 (or folder-set
1504 (save-excursion
1505 ;; psg - mh-current-folder is nil if mh-summary-height < 4 !
1506 ;; So I added this sanity check.
1507 (if (stringp mh-current-folder)
1508 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast")
1509 (mh-exec-cmd-quiet t "folder" "-fast")))))))
1510
1511 \f
1512
1513 ;;; Support routines.
1514
1515 (defun mh-delete-a-msg (message)
1516 "Delete MESSAGE.
1517 If MESSAGE is nil then the message at point is deleted.
1518 The hook `mh-delete-msg-hook' is called after you mark a message
1519 for deletion. For example, a past maintainer of MH-E used this
1520 once when he kept statistics on his mail usage."
1521 (save-excursion
1522 (if (numberp message)
1523 (mh-goto-msg message nil t)
1524 (beginning-of-line)
1525 (setq message (mh-get-msg-num t)))
1526 (if (looking-at mh-scan-refiled-msg-regexp)
1527 (error "Message %d is refiled; undo refile before deleting" message))
1528 (if (looking-at mh-scan-deleted-msg-regexp)
1529 nil
1530 (mh-set-folder-modified-p t)
1531 (setq mh-delete-list (cons message mh-delete-list))
1532 (mh-notate nil mh-note-deleted mh-cmd-note)
1533 (run-hooks 'mh-delete-msg-hook))))
1534
1535 (defun mh-refile-a-msg (message folder)
1536 "Refile MESSAGE in FOLDER.
1537 If MESSAGE is nil then the message at point is refiled.
1538 Folder is a symbol, not a string.
1539 The hook `mh-refile-msg-hook' is called after a message is marked to
1540 be refiled."
1541 (save-excursion
1542 (if (numberp message)
1543 (mh-goto-msg message nil t)
1544 (beginning-of-line)
1545 (setq message (mh-get-msg-num t)))
1546 (cond ((looking-at mh-scan-deleted-msg-regexp)
1547 (error "Message %d is deleted; undo delete before moving" message))
1548 ((looking-at mh-scan-refiled-msg-regexp)
1549 (if (y-or-n-p
1550 (format "Message %d already refiled; copy to %s as well? "
1551 message folder))
1552 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
1553 "-src" mh-current-folder
1554 (symbol-name folder))
1555 (message "Message not copied")))
1556 (t
1557 (mh-set-folder-modified-p t)
1558 (cond ((null (assoc folder mh-refile-list))
1559 (push (list folder message) mh-refile-list))
1560 ((not (member message (cdr (assoc folder mh-refile-list))))
1561 (push message (cdr (assoc folder mh-refile-list)))))
1562 (mh-notate nil mh-note-refiled mh-cmd-note)
1563 (run-hooks 'mh-refile-msg-hook)))))
1564
1565 (defun mh-next-msg (&optional wait-after-complaining-flag)
1566 "Move backward or forward to the next undeleted message in the buffer.
1567 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and
1568 we are at the last message, then wait for a second after telling
1569 the user that there aren't any more unread messages."
1570 (if (eq mh-next-direction 'forward)
1571 (mh-next-undeleted-msg 1 wait-after-complaining-flag)
1572 (mh-previous-undeleted-msg 1 wait-after-complaining-flag)))
1573
1574 (defun mh-next-unread-msg (&optional count)
1575 "Display next unread message.
1576
1577 This command can be given a prefix argument COUNT to specify how
1578 many unread messages to skip."
1579 (interactive "p")
1580 (unless (> count 0)
1581 (error "The function `mh-next-unread-msg' expects positive argument"))
1582 (setq count (1- count))
1583 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list))))
1584 (cur-msg (mh-get-msg-num nil)))
1585 (cond ((and (not cur-msg) (not (bobp))
1586 ;; If we are at the end of the buffer back up one line and go
1587 ;; to unread message after that.
1588 (progn
1589 (forward-line -1)
1590 (setq cur-msg (mh-get-msg-num nil)))
1591 nil))
1592 ((or (null unread-sequence) (not cur-msg))
1593 ;; No unread message or there aren't any messages in buffer...
1594 (message "No more unread messages"))
1595 ((progn
1596 ;; Skip messages
1597 (while (and unread-sequence (>= cur-msg (car unread-sequence)))
1598 (setq unread-sequence (cdr unread-sequence)))
1599 (while (> count 0)
1600 (setq unread-sequence (cdr unread-sequence))
1601 (setq count (1- count)))
1602 (not (car unread-sequence)))
1603 (message "No more unread messages"))
1604 (t (loop for msg in unread-sequence
1605 when (mh-goto-msg msg t) return nil
1606 finally (message "No more unread messages"))))))
1607
1608 (defun mh-set-scan-mode ()
1609 "Display the scan listing buffer, but do not show a message."
1610 (if (get-buffer mh-show-buffer)
1611 (delete-windows-on mh-show-buffer))
1612 (mh-showing-mode 0)
1613 (force-mode-line-update)
1614 (if mh-recenter-summary-flag
1615 (mh-recenter nil)))
1616
1617 (defun mh-undo-msg (msg)
1618 "Undo the deletion or refile of one MSG.
1619 If MSG is nil then act on the message at point"
1620 (save-excursion
1621 (if (numberp msg)
1622 (mh-goto-msg msg t t)
1623 (beginning-of-line)
1624 (setq msg (mh-get-msg-num t)))
1625 (cond ((memq msg mh-delete-list)
1626 (setq mh-delete-list (delq msg mh-delete-list)))
1627 (t
1628 (dolist (folder-msg-list mh-refile-list)
1629 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list))))
1630 (setq mh-refile-list (loop for x in mh-refile-list
1631 unless (null (cdr x)) collect x))))
1632 (mh-notate nil ? mh-cmd-note)))
1633
1634 \f
1635
1636 ;;; The folder data abstraction.
1637
1638 (defvar mh-index-data-file ".mhe_index"
1639 "MH-E specific file where index seach info is stored.")
1640
1641 (defun mh-make-folder (name)
1642 "Create a new mail folder called NAME.
1643 Make it the current folder."
1644 (switch-to-buffer name)
1645 (setq buffer-read-only nil)
1646 (erase-buffer)
1647 (if mh-adaptive-cmd-note-flag
1648 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name))))
1649 (setq buffer-read-only t)
1650 (mh-folder-mode)
1651 (mh-set-folder-modified-p nil)
1652 (setq buffer-file-name mh-folder-filename)
1653 (when (and (not mh-index-data)
1654 (file-exists-p (concat buffer-file-name mh-index-data-file)))
1655 (mh-index-read-data))
1656 (mh-make-folder-mode-line))
1657
1658 ;; Ensure new buffers won't get this mode if default-major-mode is nil.
1659 (put 'mh-folder-mode 'mode-class 'special)
1660
1661 \f
1662
1663 ;;; Build mh-folder-mode menu
1664
1665 ;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
1666 ;; Menus for folder mode: folder, message, sequence (in that order)
1667 ;; folder-mode "Sequence" menu
1668 (easy-menu-define
1669 mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence."
1670 '("Sequence"
1671 ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)]
1672 ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)]
1673 ["Delete Message from Sequence..." mh-delete-msg-from-seq
1674 (mh-get-msg-num nil)]
1675 ["List Sequences in Folder..." mh-list-sequences t]
1676 ["Delete Sequence..." mh-delete-seq t]
1677 ["Narrow to Sequence..." mh-narrow-to-seq t]
1678 ["Widen from Sequence" mh-widen mh-folder-view-stack]
1679 "--"
1680 ["Narrow to Subject Sequence" mh-narrow-to-subject t]
1681 ["Narrow to Tick Sequence" mh-narrow-to-tick
1682 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))]
1683 ["Delete Rest of Same Subject" mh-delete-subject t]
1684 ["Toggle Tick Mark" mh-toggle-tick t]
1685 "--"
1686 ["Push State Out to MH" mh-update-sequences t]))
1687
1688 ;; folder-mode "Message" menu
1689 (easy-menu-define
1690 mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message."
1691 '("Message"
1692 ["Show Message" mh-show (mh-get-msg-num nil)]
1693 ["Show Message with Header" mh-header-display (mh-get-msg-num nil)]
1694 ["Next Message" mh-next-undeleted-msg t]
1695 ["Previous Message" mh-previous-undeleted-msg t]
1696 ["Go to First Message" mh-first-msg t]
1697 ["Go to Last Message" mh-last-msg t]
1698 ["Go to Message by Number..." mh-goto-msg t]
1699 ["Modify Message" mh-modify t]
1700 ["Delete Message" mh-delete-msg (mh-get-msg-num nil)]
1701 ["Refile Message" mh-refile-msg (mh-get-msg-num nil)]
1702 ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)]
1703 ["Execute Delete/Refile" mh-execute-commands
1704 (mh-outstanding-commands-p)]
1705 "--"
1706 ["Compose a New Message" mh-send t]
1707 ["Reply to Message..." mh-reply (mh-get-msg-num nil)]
1708 ["Forward Message..." mh-forward (mh-get-msg-num nil)]
1709 ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)]
1710 ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)]
1711 ["Re-edit a Bounced Message" mh-extract-rejected-mail t]
1712 "--"
1713 ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)]
1714 ["Print Message" mh-print-msg (mh-get-msg-num nil)]
1715 ["Write Message to File..." mh-write-msg-to-file
1716 (mh-get-msg-num nil)]
1717 ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)]
1718 ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)]
1719 ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)]))
1720
1721 ;; folder-mode "Folder" menu
1722 (easy-menu-define
1723 mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder."
1724 '("Folder"
1725 ["Incorporate New Mail" mh-inc-folder t]
1726 ["Toggle Show/Folder" mh-toggle-showing t]
1727 ["Execute Delete/Refile" mh-execute-commands
1728 (mh-outstanding-commands-p)]
1729 ["Rescan Folder" mh-rescan-folder t]
1730 ["Thread Folder" mh-toggle-threads
1731 (not (memq 'unthread mh-view-ops))]
1732 ["Pack Folder" mh-pack-folder t]
1733 ["Sort Folder" mh-sort-folder t]
1734 "--"
1735 ["List Folders" mh-list-folders t]
1736 ["Visit a Folder..." mh-visit-folder t]
1737 ["View New Messages" mh-index-new-messages t]
1738 ["Search..." mh-search t]
1739 "--"
1740 ["Quit MH-E" mh-quit t]))
1741
1742 \f
1743
1744 (defmacro mh-remove-xemacs-horizontal-scrollbar ()
1745 "Get rid of the horizontal scrollbar that XEmacs insists on putting in."
1746 (when mh-xemacs-flag
1747 `(if (and (featurep 'scrollbar)
1748 (fboundp 'set-specifier))
1749 (set-specifier horizontal-scrollbar-visible-p nil
1750 (cons (current-buffer) nil)))))
1751
1752 (defmacro mh-write-file-functions-compat ()
1753 "Return `write-file-functions' if it exists.
1754 Otherwise return `local-write-file-hooks'. This macro exists
1755 purely for compatibility. The former symbol is used in Emacs 21.4
1756 onward while the latter is used in previous versions and XEmacs."
1757 (if (boundp 'write-file-functions)
1758 ''write-file-functions ;Emacs 21.4
1759 ''local-write-file-hooks)) ;XEmacs
1760
1761 ;; Register mh-folder-mode as supporting which-function-mode...
1762 (load "which-func" t t)
1763 (when (and (boundp 'which-func-modes)
1764 (not (member 'mh-folder-mode which-func-modes)))
1765 (push 'mh-folder-mode which-func-modes))
1766
1767 ;; Shush compiler.
1768 (eval-when-compile
1769 (defvar desktop-save-buffer)
1770 (defvar font-lock-auto-fontify))
1771
1772 (defvar mh-folder-buttons-init-flag nil)
1773
1774 ;; Autoload cookie needed by desktop.el
1775 ;;;###autoload
1776 (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder"
1777 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
1778
1779 You can show the message the cursor is pointing to, and step through
1780 the messages. Messages can be marked for deletion or refiling into
1781 another folder; these commands are executed all at once with a
1782 separate command.
1783
1784 Options that control this mode can be changed with
1785 \\[customize-group]; specify the \"mh\" group. In particular, please
1786 see the `mh-scan-format-file' option if you wish to modify scan's
1787 format.
1788
1789 When a folder is visited, the hook `mh-folder-mode-hook' is run.
1790
1791 Ranges
1792 ======
1793 Many commands that operate on individual messages, such as
1794 `mh-forward' or `mh-refile-msg' take a RANGE argument. This argument
1795 can be used in several ways.
1796
1797 If you provide the prefix argument (\\[universal-argument]) to
1798 these commands, then you will be prompted for the message range.
1799 This can be any valid MH range which can include messages,
1800 sequences, and the abbreviations (described in the mh(1) man
1801 page):
1802
1803 <num1>-<num2>
1804 Indicates all messages in the range <num1> to <num2>, inclusive.
1805 The range must be nonempty.
1806
1807 <num>:N
1808 <num>:+N
1809 <num>:-N
1810 Up to N messages beginning with (or ending with) message num. Num
1811 may be any of the predefined symbols: first, prev, cur, next or
1812 last.
1813
1814 first:N
1815 prev:N
1816 next:N
1817 last:N
1818 The first, previous, next or last messages, if they exist.
1819
1820 all
1821 All of the messages.
1822
1823 For example, a range that shows all of these things is `1 2 3
1824 5-10 last:5 unseen'.
1825
1826 If the option `transient-mark-mode' is set to t and you set a
1827 region in the MH-Folder buffer, then the MH-E command will
1828 perform the operation on all messages in that region.
1829
1830 \\{mh-folder-mode-map}"
1831 (mh-do-in-gnu-emacs
1832 (unless mh-folder-buttons-init-flag
1833 (mh-tool-bar-folder-buttons-init)
1834 (setq mh-folder-buttons-init-flag t)))
1835 (make-local-variable 'font-lock-defaults)
1836 (setq font-lock-defaults '(mh-folder-font-lock-keywords t))
1837 (make-local-variable 'desktop-save-buffer)
1838 (setq desktop-save-buffer t)
1839 (mh-make-local-vars
1840 'mh-colors-available-flag (mh-colors-available-p)
1841 ; Do we have colors available
1842 'mh-current-folder (buffer-name) ; Name of folder, a string
1843 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
1844 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
1845 (file-name-as-directory (mh-expand-file-name (buffer-name)))
1846 'mh-display-buttons-for-inline-parts-flag
1847 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to
1848 ; be toggled.
1849 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed
1850 'overlay-arrow-position nil ; Allow for simultaneous display in
1851 'overlay-arrow-string ">" ; different MH-E buffers.
1852 'mh-showing-mode nil ; Show message also?
1853 'mh-delete-list nil ; List of msgs nums to delete
1854 'mh-refile-list nil ; List of folder names in mh-seq-list
1855 'mh-seq-list nil ; Alist of (seq . msgs) nums
1856 'mh-seen-list nil ; List of displayed messages
1857 'mh-next-direction 'forward ; Direction to move to next message
1858 'mh-view-ops () ; Stack that keeps track of the order
1859 ; in which narrowing/threading has been
1860 ; carried out.
1861 'mh-folder-view-stack () ; Stack of previous views of the
1862 ; folder.
1863 'mh-index-data nil ; If the folder was created by a call
1864 ; to mh-search, this contains info
1865 ; about the search results.
1866 'mh-index-previous-search nil ; folder, indexer, search-regexp
1867 'mh-index-msg-checksum-map nil ; msg -> checksum map
1868 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg )
1869 'mh-index-sequence-search-flag nil ; folder resulted from sequence search
1870 'mh-first-msg-num nil ; Number of first msg in buffer
1871 'mh-last-msg-num nil ; Number of last msg in buffer
1872 'mh-msg-count nil ; Number of msgs in buffer
1873 'mh-mode-line-annotation nil ; Indicates message range
1874 'mh-sequence-notation-history (make-hash-table)
1875 ; Remember what is overwritten by
1876 ; mh-note-seq.
1877 'imenu-create-index-function 'mh-index-create-imenu-index
1878 ; Setup imenu support
1879 'mh-previous-window-config nil) ; Previous window configuration
1880 (mh-remove-xemacs-horizontal-scrollbar)
1881 (setq truncate-lines t)
1882 (auto-save-mode -1)
1883 (setq buffer-offer-save t)
1884 (mh-make-local-hook (mh-write-file-functions-compat))
1885 (add-hook (mh-write-file-functions-compat) 'mh-execute-commands nil t)
1886 (make-local-variable 'revert-buffer-function)
1887 (make-local-variable 'hl-line-mode) ; avoid pollution
1888 (mh-funcall-if-exists hl-line-mode 1)
1889 (setq revert-buffer-function 'mh-undo-folder)
1890 (or (assq 'mh-showing-mode minor-mode-alist)
1891 (setq minor-mode-alist
1892 (cons '(mh-showing-mode " Show") minor-mode-alist)))
1893 (easy-menu-add mh-folder-sequence-menu)
1894 (easy-menu-add mh-folder-message-menu)
1895 (easy-menu-add mh-folder-folder-menu)
1896 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)
1897 (mh-funcall-if-exists mh-tool-bar-init :folder)
1898 (if (and mh-xemacs-flag
1899 font-lock-auto-fontify)
1900 (turn-on-font-lock))) ; Force font-lock in XEmacs.
1901
1902 (defun mh-toggle-mime-buttons ()
1903 "Toggle option `mh-display-buttons-for-inline-parts-flag'."
1904 (interactive)
1905 (setq mh-display-buttons-for-inline-parts-flag
1906 (not mh-display-buttons-for-inline-parts-flag))
1907 (mh-show nil t))
1908
1909 (defun mh-colors-available-p ()
1910 "Check if colors are available in the Emacs being used."
1911 (or mh-xemacs-flag
1912 (let ((color-cells (display-color-cells)))
1913 (and (numberp color-cells) (>= color-cells 8)))))
1914
1915 (defun mh-colors-in-use-p ()
1916 "Check if colors are being used in the folder buffer."
1917 (and mh-colors-available-flag font-lock-mode))
1918
1919 (defun mh-make-local-vars (&rest pairs)
1920 "Initialize local variables according to the variable-value PAIRS."
1921
1922 (while pairs
1923 (set (make-local-variable (car pairs)) (car (cdr pairs)))
1924 (setq pairs (cdr (cdr pairs)))))
1925
1926 (defun mh-restore-desktop-buffer (desktop-buffer-file-name
1927 desktop-buffer-name
1928 desktop-buffer-misc)
1929 "Restore an MH folder buffer specified in a desktop file.
1930 When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the
1931 file name to visit, DESKTOP-BUFFER-NAME holds the desired buffer
1932 name, and DESKTOP-BUFFER-MISC holds a list of miscellaneous info
1933 used by the `desktop-buffer-handlers' functions."
1934 (mh-find-path)
1935 (mh-visit-folder desktop-buffer-name)
1936 (current-buffer))
1937
1938 ;; desktop-buffer-mode-handlers appeared in Emacs 22.
1939 (if (fboundp 'desktop-buffer-mode-handlers)
1940 (add-to-list 'desktop-buffer-mode-handlers
1941 '(mh-folder-mode . mh-restore-desktop-buffer)))
1942
1943 (defun mh-scan-folder (folder range &optional dont-exec-pending)
1944 "Scan FOLDER over RANGE.
1945
1946 After the scan is performed, switch to the buffer associated with
1947 FOLDER.
1948
1949 Check the documentation of `mh-interactive-range' to see how RANGE is
1950 read in interactive use.
1951
1952 The processing of outstanding commands is not performed if
1953 DONT-EXEC-PENDING is non-nil."
1954 (when (stringp range)
1955 (setq range (delete "" (split-string range "[ \t\n]"))))
1956 (cond ((null (get-buffer folder))
1957 (mh-make-folder folder))
1958 (t
1959 (unless dont-exec-pending
1960 (mh-process-or-undo-commands folder)
1961 (mh-reset-threads-and-narrowing))
1962 (switch-to-buffer folder)))
1963 (mh-regenerate-headers range)
1964 (if (zerop (buffer-size))
1965 (if (equal range "all")
1966 (message "Folder %s is empty" folder)
1967 (message "No messages in %s, range %s" folder range))
1968 (mh-goto-cur-msg))
1969 (when (mh-outstanding-commands-p)
1970 (mh-notate-deleted-and-refiled)))
1971
1972 (defun mh-msg-num-width-to-column (width)
1973 "Return the column for notations given message number WIDTH.
1974 Note that columns in Emacs start with 0.
1975
1976 If `mh-scan-format-file' is set to \"Use MH-E scan Format\" this
1977 means that either `mh-scan-format-mh' or `mh-scan-format-nmh' are
1978 in use. This function therefore assumes that the first column is
1979 empty (to provide room for the cursor), the following WIDTH
1980 columns contain the message number, and the column for notations
1981 comes after that."
1982 (if (eq mh-scan-format-file t)
1983 (max (1+ width) 2)
1984 (error "%s %s" "Can't call `mh-msg-num-width-to-column' when"
1985 "`mh-scan-format-file' is not set to \"Use MH-E scan Format\"")))
1986
1987 (defun mh-set-cmd-note (column)
1988 "Set `mh-cmd-note' to COLUMN.
1989 Note that columns in Emacs start with 0."
1990 (setq mh-cmd-note column))
1991
1992 (defun mh-regenerate-headers (range &optional update)
1993 "Scan folder over RANGE.
1994 If UPDATE, append the scan lines, otherwise replace."
1995 (let ((folder mh-current-folder)
1996 (range (if (and range (atom range)) (list range) range))
1997 scan-start)
1998 (message "Scanning %s..." folder)
1999 (mh-remove-all-notation)
2000 (with-mh-folder-updating (nil)
2001 (if update
2002 (goto-char (point-max))
2003 (delete-region (point-min) (point-max))
2004 (if mh-adaptive-cmd-note-flag
2005 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width
2006 folder)))))
2007 (setq scan-start (point))
2008 (apply #'mh-exec-cmd-output
2009 mh-scan-prog nil
2010 (mh-scan-format)
2011 "-noclear" "-noheader"
2012 "-width" (window-width)
2013 folder range)
2014 (goto-char scan-start)
2015 (cond ((looking-at "scan: no messages in")
2016 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines
2017 ((looking-at (if (mh-variant-p 'mu-mh)
2018 "scan: message set .* does not exist"
2019 "scan: bad message list "))
2020 (keep-lines mh-scan-valid-regexp))
2021 ((looking-at "scan: ")) ; Keep error messages
2022 (t
2023 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines
2024 (setq mh-seq-list (mh-read-folder-sequences folder nil))
2025 (mh-notate-user-sequences)
2026 (or update
2027 (setq mh-mode-line-annotation
2028 (if (equal range '("all"))
2029 nil
2030 mh-partial-folder-mode-line-annotation)))
2031 (mh-make-folder-mode-line))
2032 (message "Scanning %s...done" folder)))
2033
2034 (defun mh-generate-new-cmd-note (folder)
2035 "Fix the `mh-cmd-note' value for this FOLDER.
2036
2037 After doing an `mh-get-new-mail' operation in this FOLDER, at least
2038 one line that looks like a truncated message number was found.
2039
2040 Remove the text added by the last `mh-inc' command. It should be the
2041 messages cur-last. Call `mh-set-cmd-note', adjusting the notation
2042 column with the width of the largest message number in FOLDER.
2043
2044 Reformat the message number width on each line in the buffer and trim
2045 the line length to fit in the window.
2046
2047 Rescan the FOLDER in the range cur-last in order to display the
2048 messages that were removed earlier. They should all fit in the scan
2049 line now with no message truncation."
2050 (save-excursion
2051 (let ((maxcol (1- (window-width)))
2052 (old-cmd-note mh-cmd-note)
2053 mh-cmd-note-fmt
2054 msgnum)
2055 ;; Nuke all of the lines just added by the last inc
2056 (delete-char (- (point-max) (point)))
2057 ;; Update the current buffer to reflect the new mh-cmd-note
2058 ;; value needed to display messages.
2059 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder)))
2060 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d"))
2061 ;; Cleanup the messages that are in the buffer right now
2062 (goto-char (point-min))
2063 (cond ((memq 'unthread mh-view-ops)
2064 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note)))
2065 (t (while (re-search-forward mh-scan-msg-number-regexp nil 0 1)
2066 ;; reformat the number to fix in mh-cmd-note columns
2067 (setq msgnum (string-to-number
2068 (buffer-substring
2069 (match-beginning 1) (match-end 1))))
2070 (replace-match (format mh-cmd-note-fmt msgnum))
2071 ;; trim the line to fix in the window
2072 (end-of-line)
2073 (let ((eol (point)))
2074 (move-to-column maxcol)
2075 (if (<= (point) eol)
2076 (delete-char (- eol (point))))))))
2077 ;; now re-read the lost messages
2078 (goto-char (point-max))
2079 (prog1 (point)
2080 (mh-regenerate-headers "cur-last" t)))))
2081
2082 (defun mh-get-new-mail (maildrop-name)
2083 "Read new mail from MAILDROP-NAME into the current buffer.
2084 Return in the current buffer."
2085 (let ((point-before-inc (point))
2086 (folder mh-current-folder)
2087 (new-mail-flag nil))
2088 (with-mh-folder-updating (t)
2089 (if maildrop-name
2090 (message "inc %s -file %s..." folder maildrop-name)
2091 (message "inc %s..." folder))
2092 (setq mh-next-direction 'forward)
2093 (goto-char (point-max))
2094 (mh-remove-cur-notation)
2095 (let ((start-of-inc (point)))
2096 (if maildrop-name
2097 ;; I think MH 5 used "-ms-file" instead of "-file",
2098 ;; which would make inc'ing from maildrops fail.
2099 (mh-exec-cmd-output mh-inc-prog nil folder
2100 (mh-scan-format)
2101 "-file" (expand-file-name maildrop-name)
2102 "-width" (window-width)
2103 "-truncate")
2104 (mh-exec-cmd-output mh-inc-prog nil
2105 (mh-scan-format)
2106 "-width" (window-width)))
2107 (if maildrop-name
2108 (message "inc %s -file %s...done" folder maildrop-name)
2109 (message "inc %s...done" folder))
2110 (goto-char start-of-inc)
2111 (cond ((save-excursion
2112 (re-search-forward "^inc: no mail" nil t))
2113 (message "No new mail%s%s" (if maildrop-name " in " "")
2114 (if maildrop-name maildrop-name "")))
2115 ((and (when mh-folder-view-stack
2116 (let ((saved-text (buffer-substring-no-properties
2117 start-of-inc (point-max))))
2118 (delete-region start-of-inc (point-max))
2119 (unwind-protect (mh-widen t)
2120 (mh-remove-cur-notation)
2121 (goto-char (point-max))
2122 (setq start-of-inc (point))
2123 (insert saved-text)
2124 (goto-char start-of-inc))))
2125 nil))
2126 ((re-search-forward "^inc:" nil t) ; Error messages
2127 (error "Error incorporating mail"))
2128 ((and
2129 (equal mh-scan-format-file t)
2130 mh-adaptive-cmd-note-flag
2131 ;; Have we reached an edge condition?
2132 (save-excursion
2133 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1))
2134 (setq start-of-inc (mh-generate-new-cmd-note folder))
2135 nil))
2136 (t
2137 (setq new-mail-flag t)))
2138 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines
2139 (let* ((sequences (mh-read-folder-sequences folder t))
2140 (new-cur (assoc 'cur sequences))
2141 (new-unseen (assoc mh-unseen-seq sequences)))
2142 (unless (assoc 'cur mh-seq-list)
2143 (push (list 'cur) mh-seq-list))
2144 (unless (assoc mh-unseen-seq mh-seq-list)
2145 (push (list mh-unseen-seq) mh-seq-list))
2146 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur))
2147 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen)))
2148 (when (equal (point-max) start-of-inc)
2149 (mh-notate-cur))
2150 (if new-mail-flag
2151 (progn
2152 (mh-make-folder-mode-line)
2153 (when (mh-speed-flists-active-p)
2154 (mh-speed-flists t mh-current-folder))
2155 (when (memq 'unthread mh-view-ops)
2156 (mh-thread-inc folder start-of-inc))
2157 (mh-goto-cur-msg))
2158 (goto-char point-before-inc))
2159 (mh-notate-user-sequences (cons start-of-inc (point-max)))))))
2160
2161 (defun mh-make-folder-mode-line (&optional ignored)
2162 "Set the fields of the mode line for a folder buffer.
2163 The optional argument is now obsolete and IGNORED. It used to be
2164 used to pass in what is now stored in the buffer-local variable
2165 `mh-mode-line-annotation'."
2166 (save-excursion
2167 (save-window-excursion
2168 (mh-first-msg)
2169 (let ((new-first-msg-num (mh-get-msg-num nil)))
2170 (when (or (not (memq 'unthread mh-view-ops))
2171 (null mh-first-msg-num)
2172 (null new-first-msg-num)
2173 (< new-first-msg-num mh-first-msg-num))
2174 (setq mh-first-msg-num new-first-msg-num)))
2175 (mh-last-msg)
2176 (let ((new-last-msg-num (mh-get-msg-num nil)))
2177 (when (or (not (memq 'unthread mh-view-ops))
2178 (null mh-last-msg-num)
2179 (null new-last-msg-num)
2180 (> new-last-msg-num mh-last-msg-num))
2181 (setq mh-last-msg-num new-last-msg-num)))
2182 (setq mh-msg-count (if mh-first-msg-num
2183 (count-lines (point-min) (point-max))
2184 0))
2185 (setq mode-line-buffer-identification
2186 (list (format " {%%b%s} %s msg%s"
2187 (if mh-mode-line-annotation
2188 (format "/%s" mh-mode-line-annotation)
2189 "")
2190 (if (zerop mh-msg-count)
2191 "no"
2192 (format "%d" mh-msg-count))
2193 (if (zerop mh-msg-count)
2194 "s"
2195 (cond ((> mh-msg-count 1)
2196 (format "s (%d-%d)" mh-first-msg-num
2197 mh-last-msg-num))
2198 (mh-first-msg-num
2199 (format " (%d)" mh-first-msg-num))
2200 (""))))))
2201 (mh-logo-display))))
2202
2203 (defun mh-add-sequence-notation (msg internal-seq-flag)
2204 "Add sequence notation to the MSG on the current line.
2205 If INTERNAL-SEQ-FLAG is non-nil, then refontify the scan line if
2206 font-lock is turned on."
2207 (with-mh-folder-updating (t)
2208 (save-excursion
2209 (beginning-of-line)
2210 (if internal-seq-flag
2211 (progn
2212 ;; Change the buffer so that if transient-mark-mode is active
2213 ;; and there is an active region it will get deactivated as in
2214 ;; the case of user sequences.
2215 (mh-notate nil nil mh-cmd-note)
2216 (when font-lock-mode
2217 (font-lock-fontify-region (point) (line-end-position))))
2218 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2219 (let ((stack (gethash msg mh-sequence-notation-history)))
2220 (setf (gethash msg mh-sequence-notation-history)
2221 (cons (char-after) stack)))
2222 (mh-notate nil mh-note-seq
2223 (+ mh-cmd-note mh-scan-field-destination-offset))))))
2224
2225 (defun mh-remove-sequence-notation (msg internal-seq-flag &optional all)
2226 "Remove sequence notation from the MSG on the current line.
2227 If INTERNAL-SEQ-FLAG is non-nil, then `font-lock' was used to
2228 highlight the sequence. In that case, no notation needs to be removed.
2229 Otherwise the effect of inserting `mh-note-seq' needs to be reversed.
2230 If ALL is non-nil, then all sequence marks on the scan line are
2231 removed."
2232 (with-mh-folder-updating (t)
2233 ;; This takes care of internal sequences...
2234 (mh-notate nil nil mh-cmd-note)
2235 (unless internal-seq-flag
2236 ;; ... and this takes care of user sequences.
2237 (let ((stack (gethash msg mh-sequence-notation-history)))
2238 (while (and all (cdr stack))
2239 (setq stack (cdr stack)))
2240 (when stack
2241 (save-excursion
2242 (beginning-of-line)
2243 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2244 (delete-char 1)
2245 (insert (car stack))))
2246 (setf (gethash msg mh-sequence-notation-history) (cdr stack))))))
2247
2248 (defun mh-remove-cur-notation ()
2249 "Remove old cur notation."
2250 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2251 (save-excursion
2252 (when (and cur-msg
2253 (mh-goto-msg cur-msg t t)
2254 (looking-at mh-scan-cur-msg-number-regexp))
2255 (mh-notate nil ? mh-cmd-note)
2256 (setq overlay-arrow-position nil)))))
2257
2258 (defun mh-remove-all-notation ()
2259 "Remove all notations on all scan lines that MH-E introduces."
2260 (save-excursion
2261 (setq overlay-arrow-position nil)
2262 (goto-char (point-min))
2263 (mh-iterate-on-range msg (cons (point-min) (point-max))
2264 (mh-notate nil ? mh-cmd-note)
2265 (mh-remove-sequence-notation msg nil t))
2266 (clrhash mh-sequence-notation-history)))
2267
2268 (defun mh-goto-cur-msg (&optional minimal-changes-flag)
2269 "Position the cursor at the current message.
2270 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the
2271 function doesn't recenter the folder buffer."
2272 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2273 (cond ((and cur-msg
2274 (mh-goto-msg cur-msg t t))
2275 (unless minimal-changes-flag
2276 (mh-notate-cur)
2277 (mh-recenter 0)
2278 (mh-maybe-show cur-msg)))
2279 (t
2280 (setq overlay-arrow-position nil)
2281 (message "No current message")))))
2282
2283 (defun mh-process-or-undo-commands (folder)
2284 "If FOLDER has outstanding commands, then either process or discard them.
2285 Called by functions like `mh-sort-folder', so also invalidate
2286 show buffer."
2287 (set-buffer folder)
2288 (if (mh-outstanding-commands-p)
2289 (if (or mh-do-not-confirm-flag
2290 (y-or-n-p
2291 "Process outstanding deletes and refiles? "))
2292 (mh-process-commands folder)
2293 (set-buffer folder)
2294 (mh-undo-folder)))
2295 (mh-update-unseen)
2296 (mh-invalidate-show-buffer))
2297
2298 (defun mh-process-commands (folder)
2299 "Process outstanding commands for FOLDER.
2300
2301 This function runs `mh-before-commands-processed-hook' before the
2302 commands are processed and `mh-after-commands-processed-hook'
2303 after the commands are processed."
2304 (message "Processing deletes and refiles for %s..." folder)
2305 (set-buffer folder)
2306 (with-mh-folder-updating (nil)
2307 ;; Run the before hook -- the refile and delete lists are still valid
2308 (run-hooks 'mh-before-commands-processed-hook)
2309
2310 ;; Update the unseen sequence if it exists
2311 (mh-update-unseen)
2312
2313 (let ((redraw-needed-flag mh-index-data)
2314 (folders-changed (list mh-current-folder))
2315 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag
2316 (mh-create-sequence-map mh-seq-list)))
2317 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag
2318 (make-hash-table))))
2319 ;; Remove invalid scan lines if we are in an index folder and then remove
2320 ;; the real messages
2321 (when mh-index-data
2322 (mh-index-delete-folder-headers)
2323 (setq folders-changed
2324 (append folders-changed (mh-index-execute-commands))))
2325
2326 ;; Then refile messages
2327 (mh-mapc #'(lambda (folder-msg-list)
2328 (let* ((dest-folder (symbol-name (car folder-msg-list)))
2329 (last (car (mh-translate-range dest-folder "last")))
2330 (msgs (cdr folder-msg-list)))
2331 (push dest-folder folders-changed)
2332 (setq redraw-needed-flag t)
2333 (apply #'mh-exec-cmd
2334 "refile" "-src" folder dest-folder
2335 (mh-coalesce-msg-list msgs))
2336 (mh-delete-scan-msgs msgs)
2337 ;; Preserve sequences in destination folder...
2338 (when mh-refile-preserves-sequences-flag
2339 (clrhash dest-map)
2340 (loop for i from (1+ (or last 0))
2341 for msg in (sort (copy-sequence msgs) #'<)
2342 do (loop for seq-name in (gethash msg seq-map)
2343 do (push i (gethash seq-name dest-map))))
2344 (maphash
2345 #'(lambda (seq msgs)
2346 ;; Can't be run in the background, since the
2347 ;; current folder is changed by mark this could
2348 ;; lead to a race condition with the next refile.
2349 (apply #'mh-exec-cmd "mark"
2350 "-sequence" (symbol-name seq) dest-folder
2351 "-add" (mapcar #'(lambda (x) (format "%s" x))
2352 (mh-coalesce-msg-list msgs))))
2353 dest-map))))
2354 mh-refile-list)
2355 (setq mh-refile-list ())
2356
2357 ;; Now delete messages
2358 (cond (mh-delete-list
2359 (setq redraw-needed-flag t)
2360 (apply 'mh-exec-cmd "rmm" folder
2361 (mh-coalesce-msg-list mh-delete-list))
2362 (mh-delete-scan-msgs mh-delete-list)
2363 (setq mh-delete-list nil)))
2364
2365 ;; Don't need to remove sequences since delete and refile do so.
2366 ;; Mark cur message
2367 (if (> (buffer-size) 0)
2368 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last"))))
2369
2370 ;; Redraw folder buffer if needed
2371 (when (and redraw-needed-flag)
2372 (when (mh-speed-flists-active-p)
2373 (apply #'mh-speed-flists t folders-changed))
2374 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max)))
2375 (mh-index-data (mh-index-insert-folder-headers))))
2376
2377 (and (buffer-file-name (get-buffer mh-show-buffer))
2378 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
2379 ;; If "inc" were to put a new msg in this file,
2380 ;; we would not notice, so mark it invalid now.
2381 (mh-invalidate-show-buffer))
2382
2383 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
2384 (mh-remove-all-notation)
2385 (mh-notate-user-sequences)
2386
2387 ;; Run the after hook -- now folders-changed is valid,
2388 ;; but not the lists of specific messages.
2389 (let ((mh-folders-changed folders-changed))
2390 (run-hooks 'mh-after-commands-processed-hook)))
2391
2392 (message "Processing deletes and refiles for %s...done" folder)))
2393
2394 (defun mh-update-unseen ()
2395 "Synchronize the unseen sequence with MH.
2396 Return non-nil iff the MH folder was set.
2397 The hook `mh-unseen-updated-hook' is called after the unseen sequence
2398 is updated."
2399 (if mh-seen-list
2400 (let* ((unseen-seq (mh-find-seq mh-unseen-seq))
2401 (unseen-msgs (mh-seq-msgs unseen-seq)))
2402 (if unseen-msgs
2403 (progn
2404 (mh-undefine-sequence mh-unseen-seq mh-seen-list)
2405 (run-hooks 'mh-unseen-updated-hook)
2406 (while mh-seen-list
2407 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs))
2408 (setq mh-seen-list (cdr mh-seen-list)))
2409 (setcdr unseen-seq unseen-msgs)
2410 t) ;since we set the folder
2411 (setq mh-seen-list nil)))))
2412
2413 (defun mh-delete-scan-msgs (msgs)
2414 "Delete the scan listing lines for MSGS."
2415 (save-excursion
2416 (while msgs
2417 (when (mh-goto-msg (car msgs) t t)
2418 (when (memq 'unthread mh-view-ops)
2419 (mh-thread-forget-message (car msgs)))
2420 (mh-delete-line 1))
2421 (setq msgs (cdr msgs)))))
2422
2423 (defun mh-outstanding-commands-p ()
2424 "Return non-nil if there are outstanding deletes or refiles."
2425 (save-excursion
2426 (when (eq major-mode 'mh-show-mode)
2427 (set-buffer mh-show-folder-buffer))
2428 (or mh-delete-list mh-refile-list)))
2429
2430 (defun mh-coalesce-msg-list (messages)
2431 "Given a list of MESSAGES, return a list of message number ranges.
2432 This is the inverse of `mh-read-msg-list', which expands ranges.
2433 Message lists passed to MH programs should be processed by this
2434 function to avoid exceeding system command line argument limits."
2435 (let ((msgs (sort (copy-sequence messages) 'mh-greaterp))
2436 (range-high nil)
2437 (prev -1)
2438 (ranges nil))
2439 (while prev
2440 (if range-high
2441 (if (or (not (numberp prev))
2442 (not (equal (car msgs) (1- prev))))
2443 (progn ;non-sequential, flush old range
2444 (if (eq prev range-high)
2445 (setq ranges (cons range-high ranges))
2446 (setq ranges (cons (format "%s-%s" prev range-high) ranges)))
2447 (setq range-high nil))))
2448 (or range-high
2449 (setq range-high (car msgs))) ;start new or first range
2450 (setq prev (car msgs))
2451 (setq msgs (cdr msgs)))
2452 ranges))
2453
2454 (defun mh-greaterp (msg1 msg2)
2455 "Return the greater of two message indicators MSG1 and MSG2.
2456 Strings are \"smaller\" than numbers.
2457 Valid values are things like \"cur\", \"last\", 1, and 1820."
2458 (if (numberp msg1)
2459 (if (numberp msg2)
2460 (> msg1 msg2)
2461 t)
2462 (if (numberp msg2)
2463 nil
2464 (string-lessp msg2 msg1))))
2465
2466 (defun mh-lessp (msg1 msg2)
2467 "Return the lesser of two message indicators MSG1 and MSG2.
2468 Strings are \"smaller\" than numbers.
2469 Valid values are things like \"cur\", \"last\", 1, and 1820."
2470 (not (mh-greaterp msg1 msg2)))
2471
2472 \f
2473
2474 ;;; Basic sequence handling
2475
2476 (defun mh-delete-seq-locally (seq)
2477 "Remove MH-E's record of SEQ."
2478 (let ((entry (mh-find-seq seq)))
2479 (setq mh-seq-list (delq entry mh-seq-list))))
2480
2481 (defun mh-read-folder-sequences (folder save-refiles)
2482 "Read and return the predefined sequences for a FOLDER.
2483 If SAVE-REFILES is non-nil, then keep the sequences
2484 that note messages to be refiled."
2485 (let ((seqs ()))
2486 (cond (save-refiles
2487 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
2488 (if (mh-folder-name-p (mh-seq-name seq))
2489 (setq seqs (cons seq seqs)))))
2490 mh-seq-list)))
2491 (save-excursion
2492 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
2493 (progn
2494 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
2495 (while (re-search-forward "^[^: ]+" nil t)
2496 (setq seqs (cons (mh-make-seq (intern (buffer-substring
2497 (match-beginning 0)
2498 (match-end 0)))
2499 (mh-read-msg-list))
2500 seqs)))
2501 (delete-region (point-min) (point))))) ; avoid race with
2502 ; mh-process-daemon
2503 seqs))
2504
2505 (defun mh-read-msg-list ()
2506 "Return a list of message numbers from point to the end of the line.
2507 Expands ranges into set of individual numbers."
2508 (let ((msgs ())
2509 (end-of-line (save-excursion (end-of-line) (point)))
2510 num)
2511 (while (re-search-forward "[0-9]+" end-of-line t)
2512 (setq num (string-to-number (buffer-substring (match-beginning 0)
2513 (match-end 0))))
2514 (cond ((looking-at "-") ; Message range
2515 (forward-char 1)
2516 (re-search-forward "[0-9]+" end-of-line t)
2517 (let ((num2 (string-to-number
2518 (buffer-substring (match-beginning 0)
2519 (match-end 0)))))
2520 (if (< num2 num)
2521 (error "Bad message range: %d-%d" num num2))
2522 (while (<= num num2)
2523 (setq msgs (cons num msgs))
2524 (setq num (1+ num)))))
2525 ((not (zerop num)) ;"pick" outputs "0" to mean no match
2526 (setq msgs (cons num msgs)))))
2527 msgs))
2528
2529 (defun mh-notate-user-sequences (&optional range)
2530 "Mark user-defined sequences in RANGE.
2531
2532 Check the documentation of `mh-interactive-range' to see how
2533 RANGE is read in interactive use; if nil all messages are
2534 notated."
2535 (unless range
2536 (setq range (cons (point-min) (point-max))))
2537 (let ((seqs mh-seq-list)
2538 (msg-hash (make-hash-table)))
2539 (dolist (seq seqs)
2540 (dolist (msg (mh-seq-msgs seq))
2541 (push (car seq) (gethash msg msg-hash))))
2542 (mh-iterate-on-range msg range
2543 (loop for seq in (gethash msg msg-hash)
2544 do (mh-add-sequence-notation msg (mh-internal-seq seq))))))
2545
2546 (defvar mh-internal-seqs '(answered cur deleted forwarded printed))
2547
2548 (defun mh-internal-seq (name)
2549 "Return non-nil if NAME is the name of an internal MH-E sequence."
2550 (or (memq name mh-internal-seqs)
2551 (eq name mh-unseen-seq)
2552 (and (mh-colors-in-use-p) mh-tick-seq (eq name mh-tick-seq))
2553 (eq name mh-previous-seq)
2554 (mh-folder-name-p name)))
2555
2556 (defun mh-valid-seq-p (name)
2557 "Return non-nil if NAME is a valid MH sequence name."
2558 (and (symbolp name)
2559 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" (symbol-name name))))
2560
2561 (defun mh-delete-msg-from-seq (range sequence &optional internal-flag)
2562 "Delete RANGE from SEQUENCE.
2563
2564 Check the documentation of `mh-interactive-range' to see how
2565 RANGE is read in interactive use.
2566
2567 In a program, non-nil INTERNAL-FLAG means do not inform MH of the
2568 change."
2569 (interactive (list (mh-interactive-range "Delete")
2570 (mh-read-seq-default "Delete from" t)
2571 nil))
2572 (let ((entry (mh-find-seq sequence))
2573 (user-sequence-flag (not (mh-internal-seq sequence)))
2574 (folders-changed (list mh-current-folder))
2575 (msg-list ()))
2576 (when entry
2577 (mh-iterate-on-range msg range
2578 (push msg msg-list)
2579 ;; Calling "mark" repeatedly takes too long. So we will pretend here
2580 ;; that we are just modifying an internal sequence...
2581 (when (memq msg (cdr entry))
2582 (mh-remove-sequence-notation msg (not user-sequence-flag)))
2583 (mh-delete-a-msg-from-seq msg sequence t))
2584 ;; ... and here we will "mark" all the messages at one go.
2585 (unless internal-flag (mh-undefine-sequence sequence msg-list))
2586 (when (and mh-index-data (not internal-flag))
2587 (setq folders-changed
2588 (append folders-changed
2589 (mh-index-delete-from-sequence sequence msg-list))))
2590 (when (and (eq sequence mh-unseen-seq) (mh-speed-flists-active-p))
2591 (apply #'mh-speed-flists t folders-changed)))))
2592
2593 (defun mh-catchup (range)
2594 "Delete RANGE from the \"unseen\" sequence.
2595
2596 Check the documentation of `mh-interactive-range' to see how
2597 RANGE is read in interactive use."
2598 (interactive (list (mh-interactive-range "Catchup"
2599 (cons (point-min) (point-max)))))
2600 (mh-delete-msg-from-seq range mh-unseen-seq))
2601
2602 (defun mh-delete-a-msg-from-seq (msg sequence internal-flag)
2603 "Delete MSG from SEQUENCE.
2604 If INTERNAL-FLAG is non-nil, then do not inform MH of the
2605 change."
2606 (let ((entry (mh-find-seq sequence)))
2607 (when (and entry (memq msg (mh-seq-msgs entry)))
2608 (if (not internal-flag)
2609 (mh-undefine-sequence sequence (list msg)))
2610 (setcdr entry (delq msg (mh-seq-msgs entry))))))
2611
2612 (defun mh-undefine-sequence (seq msgs)
2613 "Remove from the SEQ the list of MSGS."
2614 (when (and (mh-valid-seq-p seq) msgs)
2615 (apply #'mh-exec-cmd "mark" mh-current-folder "-delete"
2616 "-sequence" (symbol-name seq) (mh-coalesce-msg-list msgs))))
2617
2618 (defun mh-define-sequence (seq msgs)
2619 "Define the SEQ to contain the list of MSGS.
2620 Do not mark pseudo-sequences or empty sequences.
2621 Signals an error if SEQ is an invalid name."
2622 (if (and msgs
2623 (mh-valid-seq-p seq)
2624 (not (mh-folder-name-p seq)))
2625 (save-excursion
2626 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
2627 "-sequence" (symbol-name seq)
2628 (mh-coalesce-msg-list msgs)))))
2629
2630 (defun mh-seq-containing-msg (msg &optional include-internal-flag)
2631 "Return a list of the sequences containing MSG.
2632 If INCLUDE-INTERNAL-FLAG non-nil, include MH-E internal sequences
2633 in list."
2634 (let ((l mh-seq-list)
2635 (seqs ()))
2636 (while l
2637 (and (memq msg (mh-seq-msgs (car l)))
2638 (or include-internal-flag
2639 (not (mh-internal-seq (mh-seq-name (car l)))))
2640 (setq seqs (cons (mh-seq-name (car l)) seqs)))
2641 (setq l (cdr l)))
2642 seqs))
2643
2644 \f
2645
2646 ;;; Build mh-folder-mode keymap:
2647
2648 (suppress-keymap mh-folder-mode-map)
2649
2650 ;; Use defalias to make sure the documented primary key bindings
2651 ;; appear in menu lists.
2652 (defalias 'mh-alt-show 'mh-show)
2653 (defalias 'mh-alt-refile-msg 'mh-refile-msg)
2654 (defalias 'mh-alt-send 'mh-send)
2655 (defalias 'mh-alt-visit-folder 'mh-visit-folder)
2656
2657 ;; Save the "b" binding for a future `back'. Maybe?
2658 (gnus-define-keys mh-folder-mode-map
2659 " " mh-page-msg
2660 "!" mh-refile-or-write-again
2661 "'" mh-toggle-tick
2662 "," mh-header-display
2663 "." mh-alt-show
2664 ";" mh-toggle-mh-decode-mime-flag
2665 ">" mh-write-msg-to-file
2666 "?" mh-help
2667 "E" mh-extract-rejected-mail
2668 "M" mh-modify
2669 "\177" mh-previous-page
2670 "\C-d" mh-delete-msg-no-motion
2671 "\t" mh-index-next-folder
2672 [backtab] mh-index-previous-folder
2673 "\M-\t" mh-index-previous-folder
2674 "\e<" mh-first-msg
2675 "\e>" mh-last-msg
2676 "\ed" mh-redistribute
2677 "\r" mh-show
2678 "^" mh-alt-refile-msg
2679 "c" mh-copy-msg
2680 "d" mh-delete-msg
2681 "e" mh-edit-again
2682 "f" mh-forward
2683 "g" mh-goto-msg
2684 "i" mh-inc-folder
2685 "k" mh-delete-subject-or-thread
2686 "m" mh-alt-send
2687 "n" mh-next-undeleted-msg
2688 "\M-n" mh-next-unread-msg
2689 "o" mh-refile-msg
2690 "p" mh-previous-undeleted-msg
2691 "\M-p" mh-previous-unread-msg
2692 "q" mh-quit
2693 "r" mh-reply
2694 "s" mh-send
2695 "t" mh-toggle-showing
2696 "u" mh-undo
2697 "v" mh-index-visit-folder
2698 "x" mh-execute-commands
2699 "|" mh-pipe-msg)
2700
2701 (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map)
2702 "?" mh-prefix-help
2703 "'" mh-index-ticked-messages
2704 "S" mh-sort-folder
2705 "c" mh-catchup
2706 "f" mh-alt-visit-folder
2707 "k" mh-kill-folder
2708 "l" mh-list-folders
2709 "n" mh-index-new-messages
2710 "o" mh-alt-visit-folder
2711 "p" mh-pack-folder
2712 "q" mh-index-sequenced-messages
2713 "r" mh-rescan-folder
2714 "s" mh-search
2715 "u" mh-undo-folder
2716 "v" mh-visit-folder)
2717
2718 (define-key mh-folder-mode-map "I" mh-inc-spool-map)
2719
2720 (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map)
2721 "?" mh-prefix-help
2722 "b" mh-junk-blacklist
2723 "w" mh-junk-whitelist)
2724
2725 (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map)
2726 "?" mh-prefix-help
2727 "C" mh-ps-print-toggle-color
2728 "F" mh-ps-print-toggle-faces
2729 "f" mh-ps-print-msg-file
2730 "l" mh-print-msg
2731 "p" mh-ps-print-msg)
2732
2733 (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map)
2734 "'" mh-narrow-to-tick
2735 "?" mh-prefix-help
2736 "d" mh-delete-msg-from-seq
2737 "k" mh-delete-seq
2738 "l" mh-list-sequences
2739 "n" mh-narrow-to-seq
2740 "p" mh-put-msg-in-seq
2741 "s" mh-msg-is-in-seq
2742 "w" mh-widen)
2743
2744 (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map)
2745 "?" mh-prefix-help
2746 "u" mh-thread-ancestor
2747 "p" mh-thread-previous-sibling
2748 "n" mh-thread-next-sibling
2749 "t" mh-toggle-threads
2750 "d" mh-thread-delete
2751 "o" mh-thread-refile)
2752
2753 (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map)
2754 "'" mh-narrow-to-tick
2755 "?" mh-prefix-help
2756 "c" mh-narrow-to-cc
2757 "f" mh-narrow-to-from
2758 "r" mh-narrow-to-range
2759 "s" mh-narrow-to-subject
2760 "t" mh-narrow-to-to
2761 "w" mh-widen)
2762
2763 (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map)
2764 "?" mh-prefix-help
2765 "s" mh-store-msg ;shar
2766 "u" mh-store-msg) ;uuencode
2767
2768 (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map)
2769 " " mh-page-digest
2770 "?" mh-prefix-help
2771 "\177" mh-page-digest-backwards
2772 "b" mh-burst-digest)
2773
2774 (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map)
2775 "?" mh-prefix-help
2776 "a" mh-mime-save-parts
2777 "e" mh-display-with-external-viewer
2778 "i" mh-folder-inline-mime-part
2779 "o" mh-folder-save-mime-part
2780 "t" mh-toggle-mime-buttons
2781 "v" mh-folder-toggle-mime-part
2782 "\t" mh-next-button
2783 [backtab] mh-prev-button
2784 "\M-\t" mh-prev-button)
2785
2786 (cond
2787 (mh-xemacs-flag
2788 (define-key mh-folder-mode-map [button2] 'mh-show-mouse))
2789 (t
2790 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse)))
2791
2792 ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt
2793
2794 \f
2795
2796 ;;; Help Messages
2797
2798 ;; If you add a new prefix, add appropriate text to the nil key.
2799 ;;
2800 ;; In general, messages are grouped logically. Taking the main commands for
2801 ;; example, the first line is "ways to view messages," the second line is
2802 ;; "things you can do with messages", and the third is "composing" messages.
2803 ;;
2804 ;; When adding a new prefix, ensure that the help message contains "what" the
2805 ;; prefix is for. For example, if the word "folder" were not present in the
2806 ;; "F" entry, it would not be clear what these commands operated upon.
2807 (defvar mh-help-messages
2808 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n"
2809 "[d]elete, [o]refile, e[x]ecute,\n"
2810 "[s]end, [r]eply,\n"
2811 "[;]toggle MIME decoding.\n"
2812 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys,"
2813 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.")
2814
2815 (?F "[l]ist; [v]isit folder;\n"
2816 "[n]ew messages; [']ticked messages; [s]earch; [i]ndexed search;\n"
2817 "[p]ack; [S]ort; [r]escan; [k]ill")
2818 (?P "[p]rint message to [f]ile; old-style [l]pr printing;\n"
2819 "Toggle printing of [C]olors, [F]aces")
2820 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n"
2821 "[s]equences, [l]ist,\n"
2822 "[d]elete message from sequence, [k]ill sequence")
2823 (?T "[t]oggle, [d]elete, [o]refile thread")
2824 (?/ "Limit to [c]c, [f]rom, [r]ange, [s]ubject, [t]o; [w]iden")
2825 (?X "un[s]har, [u]udecode message")
2826 (?D "[b]urst digest")
2827 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n"
2828 "[TAB] next; [SHIFT-TAB] previous")
2829 (?J "[b]lacklist, [w]hitelist message"))
2830 "Key binding cheat sheet.
2831
2832 This is an associative array which is used to show the most common commands.
2833 The key is a prefix char. The value is one or more strings which are
2834 concatenated together and displayed in the minibuffer if ? is pressed after
2835 the prefix character. The special key nil is used to display the
2836 non-prefixed commands.
2837
2838 The substitutions described in `substitute-command-keys' are performed as
2839 well.")
2840
2841 \f
2842
2843 (dolist (mess '("^Cursor not pointing to message$"
2844 "^There is no other window$"))
2845 (add-to-list 'debug-ignored-errors mess))
2846
2847 (provide 'mh-e)
2848
2849 ;; Local Variables:
2850 ;; indent-tabs-mode: nil
2851 ;; sentence-end-double-space: nil
2852 ;; End:
2853
2854 ;; arch-tag: cce884de-bd37-4104-9963-e4439d5ed22b
2855 ;;; mh-e.el ends here