1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system
3 ;; Copyright (C) 1985, 1986, 1987, 1988,
4 ;; 1990, 1992, 1993, 1994, 1995, 1997, 1999,
5 ;; 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
7 ;; Author: Bill Wohler <wohler@newt.com>
8 ;; Maintainer: Bill Wohler <wohler@newt.com>
12 ;; This file is part of GNU Emacs.
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)
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.
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.
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.
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)
41 ;; MH (Message Handler) is a powerful mail reader.
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
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.
52 ;; MH-E is an Emacs interface to the MH mail system.
54 ;; MH-E is supported in GNU Emacs 20 and 21, with MH 6.8.4 and nmh 1.0.4.
57 ;; mh-e-users@lists.sourceforge.net
58 ;; mh-e-announce@lists.sourceforge.net
59 ;; mh-e-devel@lists.sourceforge.net
61 ;; Subscribe by sending a "subscribe" message to
62 ;; <list>-request@lists.sourceforge.net, or by using the web interface at
63 ;; https://sourceforge.net/mail/?group_id=13357
66 ;; https://sourceforge.net/tracker/?group_id=13357&atid=113357
67 ;; Include the output of M-x mh-version in any bug report.
70 ;; https://sourceforge.net/tracker/?atid=363357&group_id=13357&func=browse
73 ;; https://sourceforge.net/tracker/?group_id=13357&atid=213357
77 ;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
78 ;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
79 ;; Rewritten for GNU Emacs, James Larus, 1985.
80 ;; Modified by Stephen Gildea, 1988.
81 ;; Maintenance picked up by Bill Wohler and the
82 ;; SourceForge Crew <http://mh-e.sourceforge.net/>, 2001.
88 (eval-when-compile (require 'mh-acros))
97 ;; Shush the byte-compiler
98 (defvar font-lock-auto-fontify)
99 (defvar font-lock-defaults)
101 (defconst mh-version "7.85+cvs" "Version number of MH-E.")
103 (defvar mh-partial-folder-mode-line-annotation "select"
104 "Annotation when displaying part of a folder.
105 The string is displayed after the folder's name. nil for no annotation.")
108 ;;; Scan Line Formats
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.
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'
120 (defvar mh-scan-format-mh
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%>"
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 arg.
136 This format is identical to the default except that additional hints for
137 fontification have been added to the fifth column (remember that in Emacs, the
140 The values of the fifth column, in priority order, are: `-' if the message has
141 been replied to, t if an address on the To: line matches one of the
142 mailboxes of the current user, `c' if the Cc: line matches, `b' if the Bcc:
143 line matches, and `n' if a non-empty Newsgroups: header is present.")
145 (defvar mh-scan-format-nmh
150 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
151 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
152 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
153 "%?(nonnull(comp{newsgroups}))n%>"
155 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
156 "%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>"
157 "%<(zero)%17(decode(friendly{from}))%> "
158 "%(decode{subject})%<{body}<<%{body}%>")
159 "*Scan format string for nmh.
160 This string is passed to the scan program via the -format arg.
161 This format is identical to the default except that additional hints for
162 fontification have been added to the fifth column (remember that in Emacs, the
165 The values of the fifth column, in priority order, are: `-' if the message has
166 been replied to, t if an address on the To: field matches one of the
167 mailboxes of the current user, `c' if the Cc: field matches, `b' if the Bcc:
168 field matches, and `n' if a non-empty Newsgroups: field is present.")
170 (defvar mh-note-deleted ?D
171 "Messages that have been deleted are marked by this character.
172 See also `mh-scan-deleted-msg-regexp'.")
174 (defvar mh-note-refiled ?^
175 "Messages that have been refiled are marked by this character.
176 See also `mh-scan-refiled-msg-regexp'.")
178 (defvar mh-note-cur ?+
179 "The current message (in MH, not in MH-E) is marked by this character.
180 See also `mh-scan-cur-msg-number-regexp'.")
182 (defvar mh-scan-good-msg-regexp "^\\( *[0-9]+\\)[^D^0-9]"
183 "This regular expression matches \"good\" messages.
184 It must match from the beginning of the line. Note that the default setting of
185 `mh-folder-font-lock-keywords' expects this expression to contain at least one
186 parenthesized expression which matches the message number as in the default of
187 \"^\\\\( *[0-9]+\\\\)[^D^0-9]\". This regular expression should be correct as
188 it is needed by non-fontifying functions.")
190 (defvar mh-scan-deleted-msg-regexp "^\\( *[0-9]+\\)D"
191 "This regular expression matches deleted messages.
192 It must match from the beginning of the line. Note that the default setting of
193 `mh-folder-font-lock-keywords' expects this expression to contain at least one
194 parenthesized expression which matches the message number as in the default of
195 \"^\\\\( *[0-9]+\\\\)D\". This regular expression should be correct as it is
196 needed by non-fontifying functions. See also `mh-note-deleted'.")
198 (defvar mh-scan-refiled-msg-regexp "^\\( *[0-9]+\\)\\^"
199 "This regular expression matches refiled messages.
200 It must match from the beginning of the line. Note that the default setting of
201 `mh-folder-font-lock-keywords' expects this expression to contain at least one
202 parenthesized expression which matches the message number as in the default of
203 \"^\\\\( *[0-9]+\\\\)\\\\^\". This regular expression should be correct as it
204 is needed by non-fontifying functions. See also `mh-note-refiled'.")
206 (defvar mh-scan-valid-regexp "^ *[0-9]"
207 "This regular expression describes a valid scan line.
208 This is used to eliminate error messages that are occasionally produced by
211 (defvar mh-scan-cur-msg-number-regexp "^\\( *[0-9]+\\+\\).*"
212 "This regular expression matches the current message.
213 It must match from the beginning of the line. Note that the default setting of
214 `mh-folder-font-lock-keywords' expects this expression to contain at least one
215 parenthesized expression which matches the message number as in the default of
216 \"^\\\\( *[0-9]+\\\\+\\\\).*\". This regular expression should be correct as
217 it is needed by non-fontifying functions. See also `mh-note-cur'.")
219 (defvar mh-scan-date-regexp "\\([0-9][0-9]/[0-9][0-9]\\)"
220 "This regular expression matches a valid date.
221 It must not be anchored to the beginning or the end of the line. Note that the
222 default setting of `mh-folder-font-lock-keywords' expects this expression to
223 contain only one parenthesized expression which matches the date field as in
224 the default of \"\\\\([0-9][0-9]/[0-9][0-9]\\\\)\"}. If this regular
225 expression is not correct, the date will not be highlighted. See also
226 `mh-scan-format-regexp'.")
228 (defvar mh-scan-rcpt-regexp "\\(To:\\)\\(..............\\)"
229 "This regular expression specifies the recipient in messages you sent.
230 Note that the default setting of `mh-folder-font-lock-keywords'
231 expects this expression to contain two parenthesized expressions. The
232 first is expected to match the `To:' that the default scan format
233 file generates. The second is expected to match the recipient's name
234 as in the default of \"\\\\(To:\\\\)\\\\(..............\\\\)\". If this
235 regular expression is not correct, the recipient will not be highlighted.")
237 (defvar mh-scan-body-regexp "\\(<<\\([^\n]+\\)?\\)"
238 "This regular expression matches the message body fragment.
239 Note that the default setting of `mh-folder-font-lock-keywords' expects this
240 expression to contain at least one parenthesized expression which matches the
241 body text as in the default of \"\\\\(<<\\\\([^\\n]+\\\\)?\\\\)\". If this
242 regular expression is not correct, the body fragment will not be highlighted.")
244 (defvar mh-scan-subject-regexp
245 "^ *[0-9]+........[ ]*...................\\([Rr][Ee]\\(\\[[0-9]+\\]\\)?:\\s-*\\)*\\([^<\n]*\\)"
246 "This regular expression matches the subject.
247 It must match from the beginning of the line. Note that the default setting
248 of `mh-folder-font-lock-keywords' expects this expression to contain at least
249 three parenthesized expressions. The first is expected to match the `Re:'
250 string, if any. The second matches an optional bracketed number after `Re:',
251 such as in `Re[2]:' (and is thus a sub-expression of the first expression) and
252 the third is expected to match the subject line itself as in the default of
253 \(broken on multiple lines for readability):
254 ^ *[0-9]+........[ ]*...................
255 \\\\([Rr][Ee]\\\\(\\\\\\=[[0-9]+\\\\]\\\\)?:\\\\s-*\\\\)*
257 This regular expression should be correct as it is needed by non-fontifying
260 (defvar mh-scan-format-regexp
261 (concat "\\([bct]\\)" mh-scan-date-regexp " *\\(..................\\)")
262 "This regular expression matches the output of scan.
263 Note that the default setting of `mh-folder-font-lock-keywords' expects this
264 expression to contain at least three parenthesized expressions. The first
265 should match the fontification hint (see `mh-scan-format-nmh'), the second is
266 found in `mh-scan-date-regexp', and the third should match the user name as in
267 the default of \"(concat \"\\\\([bct]\\\\)\" mh-scan-date-regexp
268 \"*\\\\(..................\\\\)\")\".
269 If this regular expression is not correct, the notation hints and the sender
270 will not be highlighted.")
274 (defvar mh-folder-font-lock-keywords
276 ;; Folders when displaying index buffer
278 '(0 mh-index-folder-face))
279 ;; Marked for deletion
280 (list (concat mh-scan-deleted-msg-regexp ".*")
281 '(0 mh-folder-deleted-face))
283 (list (concat mh-scan-refiled-msg-regexp ".*")
284 '(0 mh-folder-refiled-face))
286 (list mh-scan-body-regexp '(1 mh-folder-body-face nil t))
287 '(mh-folder-font-lock-subject
288 (1 mh-folder-followup-face append t)
289 (2 mh-folder-subject-face append t))
291 (list mh-scan-cur-msg-number-regexp
292 '(1 mh-folder-cur-msg-number-face))
293 (list mh-scan-good-msg-regexp
294 '(1 mh-folder-msg-number-face)) ;; Msg number
295 (list mh-scan-date-regexp '(1 mh-folder-date-face)) ;; Date
296 (list mh-scan-rcpt-regexp
297 '(1 mh-folder-to-face) ;; To:
298 '(2 mh-folder-address-face)) ;; address
299 ;; scan font-lock name
300 (list mh-scan-format-regexp
301 '(1 mh-folder-date-face)
302 '(3 mh-folder-scan-format-face)))
303 "Keywords (regular expressions) used to fontify the MH-Folder buffer.")
305 (defvar mh-scan-cmd-note-width 1
306 "Number of columns consumed by the cmd-note field in `mh-scan-format'.
307 This column will have one of the values: ` ', `D', `^', `+' and where
308 ` ' is the default value,
309 `D' is the `mh-note-deleted' character,
310 `^' is the `mh-note-refiled' character, and
311 `+' is the `mh-note-cur' character.")
313 (defvar mh-scan-destination-width 1
314 "Number of columns consumed by the destination field in `mh-scan-format'.
315 This column will have one of ' ', '%', '-', 't', 'c', 'b', or `n' in it.
316 A ' ' blank space is the default character.
317 A '%' indicates that the message in in a named MH sequence.
318 A '-' indicates that the message has been annotated with a replied field.
319 A 't' indicates that the message contains mymbox in the To: field.
320 A 'c' indicates that the message contains mymbox in the Cc: field.
321 A 'b' indicates that the message contains mymbox in the Bcc: field.
322 A 'n' indicates that the message contains a Newsgroups: field.")
324 (defvar mh-scan-date-width 5
325 "Number of columns consumed by the date field in `mh-scan-format'.
326 This column will typically be of the form mm/dd.")
328 (defvar mh-scan-date-flag-width 1
329 "Number of columns consumed to flag (in)valid dates in `mh-scan-format'.
330 This column will have ` ' for valid and `*' for invalid or missing dates.")
332 (defvar mh-scan-from-mbox-width 17
333 "Number of columns consumed with the \"From:\" line in `mh-scan-format'.
334 This column will have a friendly name or e-mail address of the
335 originator, or a \"To: address\" for outgoing e-mail messages.")
337 (defvar mh-scan-from-mbox-sep-width 2
338 "Number of columns consumed by whitespace after from-mbox in `mh-scan-format'.
339 This column will only ever have spaces in it.")
341 (defvar mh-scan-field-destination-offset
342 (+ mh-scan-cmd-note-width)
343 "The offset from the `mh-cmd-note' for the destination column.")
345 (defvar mh-scan-field-from-start-offset
346 (+ mh-scan-cmd-note-width
347 mh-scan-destination-width
349 mh-scan-date-flag-width)
350 "The offset from the `mh-cmd-note' to find the start of \"From:\" address.")
352 (defvar mh-scan-field-from-end-offset
353 (+ mh-scan-field-from-start-offset mh-scan-from-mbox-width)
354 "The offset from the `mh-cmd-note' to find the end of \"From:\" address.")
356 (defvar mh-scan-field-subject-start-offset
357 (+ mh-scan-cmd-note-width
358 mh-scan-destination-width
360 mh-scan-date-flag-width
361 mh-scan-from-mbox-width
362 mh-scan-from-mbox-sep-width)
363 "The offset from the `mh-cmd-note' to find the start of the subject.")
365 (defun mh-folder-font-lock-subject (limit)
366 "Return MH-E scan subject strings to font-lock between point and LIMIT."
367 (if (not (re-search-forward mh-scan-subject-regexp limit t))
369 (if (match-beginning 1)
370 (set-match-data (list (match-beginning 1) (match-end 3)
371 (match-beginning 1) (match-end 3) nil nil))
372 (set-match-data (list (match-beginning 3) (match-end 3)
373 nil nil (match-beginning 3) (match-end 3))))
378 ;; Fontifify unseen mesages in bold.
380 (defmacro mh-generate-sequence-font-lock (seq prefix face)
381 "Generate the appropriate code to fontify messages in SEQ.
382 PREFIX is used to generate unique names for the variables and functions
383 defined by the macro. So a different prefix should be provided for every
385 FACE is the font-lock face used to display the matching scan lines."
386 (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix)))
387 (func (intern (format "mh-folder-font-lock-%s" prefix))))
390 "Internal cache variable used for font-lock in MH-E.
391 Should only be non-nil through font-lock stepping, and nil once font-lock
392 is done highlighting.")
393 (make-variable-buffer-local ',cache)
396 "Return unseen message lines to font-lock between point and LIMIT."
397 (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq))))
398 (let ((cur-msg (mh-get-msg-num nil)))
401 ((>= (point) limit) ;Presumably at end of buffer
404 ((member cur-msg ,cache)
405 (let ((bpoint (progn (beginning-of-line)(point)))
406 (epoint (progn (forward-line 1)(point))))
407 (if (<= limit (point)) (setq ,cache nil))
408 (set-match-data (list bpoint epoint bpoint epoint))
411 ;; move forward one line at a time, checking each message
412 (while (and (= 0 (forward-line 1))
414 (not (member (mh-get-msg-num nil) ,cache))))
415 ;; Examine how we must have exited the loop...
416 (let ((cur-msg (mh-get-msg-num nil)))
417 (cond ((or (<= limit (point))
418 (not (member cur-msg ,cache)))
421 ((member cur-msg ,cache)
422 (let ((bpoint (progn (beginning-of-line) (point)))
423 (epoint (progn (forward-line 1) (point))))
424 (if (<= limit (point)) (setq ,cache nil))
426 (list bpoint epoint bpoint epoint))
429 (setq mh-folder-font-lock-keywords
430 (append mh-folder-font-lock-keywords
431 (list (list ',func (list 1 '',face 'prepend t))))))))
433 (mh-generate-sequence-font-lock mh-unseen-seq unseen bold)
434 (mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick)
438 ;;; Internal variables:
440 (defvar mh-last-destination nil) ;Destination of last refile or write
442 (defvar mh-last-destination-folder nil) ;Destination of last refile command.
443 (defvar mh-last-destination-write nil) ;Destination of last write command.
445 (defvar mh-folder-mode-map (make-keymap)
446 "Keymap for MH folders.")
448 (defvar mh-arrow-marker nil) ;Marker for arrow display in fringe.
450 (defvar mh-delete-list nil) ;List of msg numbers to delete.
452 (defvar mh-refile-list nil) ;List of folder names in mh-seq-list.
454 (defvar mh-next-direction 'forward) ;Direction to move to next message.
456 (defvar mh-view-ops ()) ;Stack of ops that change the folder
457 ;view (such as narrowing or threading).
458 (defvar mh-folder-view-stack ()) ;Stack of previous folder views.
460 (defvar mh-index-data nil) ;Info about index search results
461 (defvar mh-index-previous-search nil)
462 (defvar mh-index-msg-checksum-map nil)
463 (defvar mh-index-checksum-origin-map nil)
464 (defvar mh-index-sequence-search-flag nil)
466 (defvar mh-first-msg-num nil) ;Number of first msg in buffer.
468 (defvar mh-last-msg-num nil) ;Number of last msg in buffer.
470 (defvar mh-mode-line-annotation nil) ;Message range displayed in buffer.
472 (defvar mh-sequence-notation-history nil)
473 ;Rememeber original notation that
474 ;is overwritten by `mh-note-seq'.
476 (defvar mh-colors-available-flag nil) ;Are colors available?
478 ;;; Macros and generic functions:
480 (defun mh-mapc (function list)
481 "Apply FUNCTION to each element of LIST for side effects only."
483 (funcall function (car list))
484 (setq list (cdr list))))
486 (defun mh-scan-format ()
487 "Return the output format argument for the scan program."
488 (if (equal mh-scan-format-file t)
489 (list "-format" (if (mh-variant-p 'nmh 'mu-mh)
490 (list (mh-update-scan-format
491 mh-scan-format-nmh mh-cmd-note))
492 (list (mh-update-scan-format
493 mh-scan-format-mh mh-cmd-note))))
494 (if (not (equal mh-scan-format-file nil))
495 (list "-form" mh-scan-format-file))))
502 (defun mh-rmail (&optional arg)
503 "Inc(orporate) new mail with MH.
504 Scan an MH folder if ARG is non-nil. This function is an entry point to MH-E,
505 the Emacs interface to the MH mail system."
509 (call-interactively 'mh-visit-folder)
510 (unless (get-buffer mh-inbox)
511 (mh-visit-folder mh-inbox (symbol-name mh-unseen-seq)))
515 (defun mh-nmail (&optional arg)
516 "Check for new mail in inbox folder.
517 Scan an MH folder if ARG is non-nil. This function is an entry point to MH-E,
518 the Emacs interface to the MH mail system."
520 (mh-find-path) ; init mh-inbox
522 (call-interactively 'mh-visit-folder)
523 (mh-visit-folder mh-inbox)))
527 ;;; User executable MH-E commands:
529 (defun mh-delete-msg (range)
530 "Mark the specified RANGE for subsequent deletion and move to the next.
531 Default is the displayed message.
533 Check the documentation of `mh-interactive-range' to see how RANGE is read in
535 (interactive (list (mh-interactive-range "Delete")))
536 (mh-delete-msg-no-motion range)
537 (if (looking-at mh-scan-deleted-msg-regexp) (mh-next-msg)))
539 (defun mh-delete-msg-no-motion (range)
540 "Mark the specified RANGE for subsequent deletion.
542 Check the documentation of `mh-interactive-range' to see how RANGE is read in
544 (interactive (list (mh-interactive-range "Delete")))
545 (mh-iterate-on-range () range
546 (mh-delete-a-msg nil)))
548 (defun mh-execute-commands ()
549 "Process outstanding delete and refile requests."
551 (if mh-folder-view-stack (mh-widen t))
552 (mh-process-commands mh-current-folder)
554 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
555 (mh-make-folder-mode-line)
556 t) ; return t for write-file-functions
558 (defun mh-first-msg ()
559 "Move to the first message."
561 (goto-char (point-min))
562 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp)))
565 (defun mh-header-display ()
566 "Show the current message with all its headers.
567 Displays headers that might have been suppressed by setting the
568 variables `mh-clean-message-header-flag' or `mhl-formfile', or by the fallback
569 behavior of scrolling uninteresting headers off the top of the window.
570 Type \"\\[mh-show]\" to show the message normally again."
572 (and (not mh-showing-with-headers)
573 (or mhl-formfile mh-clean-message-header-flag)
574 (mh-invalidate-show-buffer))
575 (let ((mh-decode-mime-flag nil)
577 (mh-clean-message-header-flag nil))
579 (mh-in-show-buffer (mh-show-buffer)
580 (goto-char (point-min))
582 (setq mh-showing-with-headers t)))
584 (defun mh-inc-folder (&optional maildrop-name folder)
585 "Inc(orporate)s new mail into the Inbox folder.
586 Optional argument MAILDROP-NAME specifies an alternate maildrop from the
587 default. The optional argument FOLDER specifies where to incorporate mail
588 instead of the default named by `mh-inbox'.
589 The value of `mh-inc-folder-hook' is a list of functions to be called, with no
590 arguments, after incorporating new mail.
591 Do not call this function from outside MH-E; use \\[mh-rmail] instead."
592 (interactive (list (if current-prefix-arg
594 (read-file-name "inc mail from file: "
596 (if current-prefix-arg
597 (mh-prompt-for-folder "inc mail into" mh-inbox t))))
599 (setq folder mh-inbox))
600 (let ((threading-needed-flag nil))
601 (let ((config (current-window-configuration)))
602 (when (and mh-show-buffer (get-buffer mh-show-buffer))
603 (delete-windows-on mh-show-buffer))
604 (cond ((not (get-buffer folder))
605 (mh-make-folder folder)
606 (setq threading-needed-flag mh-show-threads-flag)
607 (setq mh-previous-window-config config))
608 ((not (eq (current-buffer) (get-buffer folder)))
609 (switch-to-buffer folder)
610 (setq mh-previous-window-config config))))
611 (mh-get-new-mail maildrop-name)
612 (when (and threading-needed-flag
614 (goto-char (point-min))
615 (or (null mh-large-folder)
616 (not (equal (forward-line (1+ mh-large-folder)) 0))
617 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
621 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show))
622 (run-hooks 'mh-inc-folder-hook)))
624 (defun mh-last-msg ()
625 "Move to the last message."
627 (goto-char (point-max))
628 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp)))
632 (defun mh-next-undeleted-msg (&optional arg wait-after-complaining-flag)
633 "Move to the next undeleted message ARG in window.
634 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and we are at the
635 last undeleted message then pause for a second after printing message."
637 (setq mh-next-direction 'forward)
639 (cond ((re-search-forward mh-scan-good-msg-regexp nil t arg)
643 (message "No more undeleted messages")
644 (if wait-after-complaining-flag (sit-for 1)))))
646 (defun mh-folder-from-address ()
647 "Derive folder name from sender.
649 The name of the folder is derived as follows:
651 a) The folder name associated with the first address found in the list
652 `mh-default-folder-list' is used. Each element in this list contains a
653 `Check Recipient' item. If this item is turned on, then the address is
654 checked against the recipient instead of the sender. This is useful for
657 b) An alias prefixed by `mh-default-folder-prefix' corresponding to the
658 address is used. The prefix is used to prevent clutter in your mail
661 Return nil if a folder name was not derived, or if the variable
662 `mh-default-folder-must-exist-flag' is t and the folder does not exist."
663 ;; Loop for all entries in mh-default-folder-list
665 (goto-char (point-min))
666 (re-search-forward "\n\n" nil 'limit)
667 (narrow-to-region (point-min) (point))
668 (let ((to/cc (concat (or (message-fetch-field "to") "") ", "
669 (or (message-fetch-field "cc") "")))
670 (from (or (message-fetch-field "from") ""))
673 (loop for list in mh-default-folder-list
674 when (string-match (nth 0 list) (if (nth 2 list) to/cc from))
678 ;; Make sure a result from `mh-default-folder-list' begins with "+"
679 ;; since 'mh-expand-file-name below depends on it
680 (when (and folder-name (not (eq (aref folder-name 0) ?+)))
681 (setq folder-name (concat "+" folder-name)))
683 ;; If not, is there an alias for the address?
684 (when (not folder-name)
685 (let* ((from-header (mh-extract-from-header-value))
686 (address (and from-header
687 (nth 1 (mail-extract-address-components
689 (alias (and address (mh-alias-address-to-alias address))))
692 (and alias (concat "+" mh-default-folder-prefix alias))))))
694 ;; If mh-default-folder-must-exist-flag set, check that folder exists.
696 (or (not mh-default-folder-must-exist-flag)
697 (file-exists-p (mh-expand-file-name folder-name))))
700 (defun mh-prompt-for-refile-folder ()
701 "Prompt the user for a folder in which the message should be filed.
702 The folder is returned as a string.
704 The default folder name is generated by the option
705 `mh-default-folder-for-message-function' if it is non-nil or
706 `mh-folder-from-address'."
707 (mh-prompt-for-folder
709 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t)))))
710 (if (null refile-file) ""
712 (set-buffer (get-buffer-create mh-temp-buffer))
714 (insert-file-contents refile-file)
715 (or (and mh-default-folder-for-message-function
716 (let ((buffer-file-name refile-file))
717 (funcall mh-default-folder-for-message-function)))
718 (mh-folder-from-address)
719 (and (eq 'refile (car mh-last-destination-folder))
720 (symbol-name (cdr mh-last-destination-folder)))
724 (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag)
725 "Refile RANGE into FOLDER.
727 Check the documentation of `mh-interactive-range' to see how RANGE is read in
730 If optional argument DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil then the
731 variables `mh-last-destination' and `mh-last-destination-folder' are not
733 (interactive (list (mh-interactive-range "Refile")
734 (intern (mh-prompt-for-refile-folder))))
735 (unless dont-update-last-destination-flag
736 (setq mh-last-destination (cons 'refile folder)
737 mh-last-destination-folder mh-last-destination))
738 (mh-iterate-on-range () range
739 (mh-refile-a-msg nil folder))
740 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg)))
742 (defun mh-refile-or-write-again (range &optional interactive-flag)
743 "Re-execute the last refile or write command on the given RANGE.
744 Default is the displayed message. Use the same folder or file as the previous
745 refile or write command.
746 If INTERACTIVE-FLAG is non-nil then the function was called interactively."
747 (interactive (list (mh-interactive-range "Redo") t))
748 (if (null mh-last-destination)
749 (error "No previous refile or write"))
752 (cond ((eq (car mh-last-destination) 'refile)
753 (mh-refile-msg range (cdr mh-last-destination))
754 (format "Destination folder: %s" (cdr mh-last-destination)))
756 (mh-iterate-on-range msg range
757 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination)))
758 (mh-next-msg interactive-flag)
759 (format "Destination: %s" (cdr mh-last-destination)))))
760 (message "%s" output)))
763 "Quit the current MH-E folder.
764 Restore the previous window configuration, if one exists.
765 The value of `mh-before-quit-hook' is a list of functions to be called, with
766 no arguments, immediately upon entry to this function.
767 The value of `mh-quit-hook' is a list of functions to be called, with no
768 arguments, upon exit of this function.
769 MH-E working buffers (whose name begins with \" *mh-\" or \"*MH-E \") are
772 (run-hooks 'mh-before-quit-hook)
773 (let ((show-buffer (get-buffer mh-show-buffer)))
775 (kill-buffer show-buffer)))
776 (mh-update-sequences)
777 (mh-destroy-postponed-handles)
778 (bury-buffer (current-buffer))
780 ;; Delete all MH-E temporary and working buffers.
781 (dolist (buffer (buffer-list))
782 (when (or (string-match "^ \\*mh-" (buffer-name buffer))
783 (string-match "^\\*MH-E " (buffer-name buffer)))
784 (kill-buffer buffer)))
786 (if mh-previous-window-config
787 (set-window-configuration mh-previous-window-config))
788 (run-hooks 'mh-quit-hook))
790 (defun mh-page-msg (&optional arg)
791 "Page the displayed message forwards.
792 Scrolls ARG lines or a full screen if no argument is supplied. Show buffer
793 first if not displayed. Show the next undeleted message if looking at the
794 bottom of the current message."
797 (if mh-page-to-next-msg-flag
798 (if (equal mh-next-direction 'backward)
799 (mh-previous-undeleted-msg)
800 (mh-next-undeleted-msg))
801 (if (mh-in-show-buffer (mh-show-buffer)
802 (pos-visible-in-window-p (point-max)))
805 "End of message (Type %s to read %s undeleted message)"
806 (single-key-description last-input-event)
807 (if (equal mh-next-direction 'backward)
810 (setq mh-page-to-next-msg-flag t))
811 (scroll-other-window arg)))
814 (defun mh-previous-page (&optional arg)
815 "Page the displayed message backwards.
816 Scrolls ARG lines or a full screen if no argument is supplied."
818 (mh-in-show-buffer (mh-show-buffer)
821 (defun mh-previous-undeleted-msg (&optional arg wait-after-complaining-flag)
822 "Move to the previous undeleted message ARG in window.
823 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and we are at the
824 first undeleted message then pause for a second after printing message."
826 (setq mh-next-direction 'backward)
828 (cond ((re-search-backward mh-scan-good-msg-regexp nil t arg)
830 (t (message "No previous undeleted message")
831 (if wait-after-complaining-flag (sit-for 1)))))
833 (defun mh-previous-unread-msg (&optional count)
834 "Move to previous unread message.
835 With optional argument COUNT, COUNT-1 unread messages before current message
839 (error "The function mh-previous-unread-msg expects positive argument"))
840 (setq count (1- count))
841 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list)))
842 (cur-msg (mh-get-msg-num nil)))
843 (cond ((and (not cur-msg) (not (bobp))
844 ;; If we are at the end of the buffer back up one line and go
845 ;; to unread message after that.
848 (setq cur-msg (mh-get-msg-num nil)))
850 ((or (null unread-sequence) (not cur-msg))
851 ;; No unread message or there aren't any messages in buffer...
852 (message "No more unread messages"))
854 ;; Skip count messages...
855 (while (and unread-sequence (>= (car unread-sequence) cur-msg))
856 (setq unread-sequence (cdr unread-sequence)))
858 (setq unread-sequence (cdr unread-sequence))
859 (setq count (1- count)))
860 (not (car unread-sequence)))
861 (message "No more unread messages"))
862 (t (loop for msg in unread-sequence
863 when (mh-goto-msg msg t) return nil
864 finally (message "No more unread messages"))))))
866 (defun mh-goto-next-button (backward-flag &optional criterion)
867 "Search for next button satisfying criterion.
868 If BACKWARD-FLAG is non-nil search backward in the buffer for a mime button. If
869 CRITERION is a function or a symbol which has a function binding then that
870 function must return non-nil at the button we stop."
871 (unless (or (and (symbolp criterion) (fboundp criterion))
872 (functionp criterion))
873 (setq criterion (lambda (x) t)))
874 ;; Move to the next button in the buffer satisfying criterion
875 (goto-char (or (save-excursion
877 ;; Find point before current button
878 (let ((point-before-current-button
880 (while (get-text-property (point) 'mh-data)
881 (unless (= (forward-line
882 (if backward-flag 1 -1))
885 (goto-char (point-min))
886 (goto-char (point-max)))))
888 ;; Skip over current button
889 (while (and (get-text-property (point) 'mh-data)
890 (not (if backward-flag (bobp) (eobp))))
891 (forward-line (if backward-flag -1 1)))
892 ;; Stop at next MIME button if any exists.
895 (unless (= (forward-line
896 (if backward-flag -1 1))
899 (goto-char (point-max))
900 (goto-char (point-min)))
903 point-before-current-button)
904 (when (and (get-text-property (point) 'mh-data)
905 (funcall criterion (point)))
906 (return-from loop (point))))
910 (defun mh-next-button (&optional backward-flag)
911 "Go to the next MIME button.
912 Advance point to the next MIME button in the show buffer. If the end
913 of buffer is reached then the search wraps over to the start of the
914 buffer. With prefix argument, BACKWARD-FLAG the point will move to the
915 previous MIME button."
916 (interactive (list current-prefix-arg))
917 (unless mh-showing-mode
919 (mh-in-show-buffer (mh-show-buffer)
920 (mh-goto-next-button backward-flag)))
922 (defun mh-prev-button ()
923 "Go to the prev MIME button.
924 Move point to the previous MIME button in the show buffer. If the beginning
925 of the buffer is reached then the search wraps over to the end of the
930 (defun mh-folder-mime-action (part-index action include-security-flag)
931 "Go to PART-INDEX and carry out ACTION.
932 If PART-INDEX is nil then go to the next part in the buffer. The search for
933 the next buffer wraps around if end of buffer is reached. If argument
934 INCLUDE-SECURITY-FLAG is non-nil then include security info buttons when
935 searching for a suitable parts."
936 (unless mh-showing-mode
938 (mh-in-show-buffer (mh-show-buffer)
942 (let ((part (get-text-property p 'mh-part)))
943 (and (integerp part) (= part part-index)))))
945 (if include-security-flag
946 (get-text-property p 'mh-data)
947 (integerp (get-text-property p 'mh-part)))))))
949 (cond ((and (get-text-property point 'mh-part)
950 (or (null part-index)
951 (= (get-text-property point 'mh-part) part-index)))
953 ((and (get-text-property point 'mh-data)
954 include-security-flag
958 (mh-goto-next-button nil criterion)
959 (if (= (point) point)
960 (message "No matching MIME part found")
961 (funcall action)))))))
963 (defun mh-folder-toggle-mime-part (part-index)
964 "Toggle display of button.
965 If point in show buffer is at a button then that part is toggled.
966 If not at a button and PART-INDEX is non-nil point is moved to that part.
967 With nil PART-INDEX find the first button after point (search wraps around if
968 end of buffer is reached) and toggle it."
970 (when (consp part-index) (setq part-index (car part-index)))
971 (mh-folder-mime-action part-index #'mh-press-button t))
973 (defun mh-folder-inline-mime-part (part-index)
974 "Show the raw bytes of MIME part inline.
975 If point in show buffer is at a mime part then that part is inlined.
976 If not at a mime-part and PART-INDEX is non-nil point is moved to that part.
977 With nil PART-INDEX find the first button after point (search wraps around if
978 end of buffer is reached) and inline it."
980 (when (consp part-index) (setq part-index (car part-index)))
981 (mh-folder-mime-action part-index #'mh-mime-inline-part nil))
983 (defun mh-folder-save-mime-part (part-index)
985 If point in show buffer is at a mime part then that part is saved.
986 If not at a mime-part and PART-INDEX is non-nil point is moved to that part.
987 With nil PART-INDEX find the first button after point (search wraps around if
988 end of buffer is reached) and save it."
990 (when (consp part-index) (setq part-index (car part-index)))
991 (mh-folder-mime-action part-index #'mh-mime-save-part nil))
993 (defvar mh-thread-scan-line-map-stack)
995 (defun mh-reset-threads-and-narrowing ()
996 "Reset all variables pertaining to threads and narrowing.
997 Also removes all content from the folder buffer."
998 (setq mh-view-ops ())
999 (setq mh-folder-view-stack ())
1000 (setq mh-thread-scan-line-map-stack ())
1001 (let ((buffer-read-only nil)) (erase-buffer)))
1003 (defun mh-rescan-folder (&optional range dont-exec-pending)
1004 "Rescan a folder after optionally processing the outstanding commands.
1005 If optional prefix argument RANGE is provided, prompt for the range of
1006 messages to display. Otherwise show the entire folder.
1007 If optional argument DONT-EXEC-PENDING is non-nil then pending deletes and
1008 refiles aren't carried out."
1009 (interactive (list (if current-prefix-arg
1010 (mh-read-range "Rescan" mh-current-folder t nil t
1011 mh-interpret-number-as-range-flag)
1013 (setq mh-next-direction 'forward)
1014 (let ((threaded-flag (memq 'unthread mh-view-ops)))
1015 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending)
1016 (cond (threaded-flag (mh-toggle-threads))
1017 (mh-index-data (mh-index-insert-folder-headers)))))
1019 (defun mh-write-msg-to-file (msg file no-headers)
1020 "Append MSG to the end of a FILE.
1021 If prefix argument NO-HEADERS is provided, write only the message body.
1022 Otherwise send the entire message including the headers."
1024 (list (mh-get-msg-num t)
1025 (let ((default-dir (if (eq 'write (car mh-last-destination-write))
1026 (file-name-directory
1027 (car (cdr mh-last-destination-write)))
1028 default-directory)))
1029 (read-file-name (format "Save message%s in file: "
1030 (if current-prefix-arg " body" ""))
1032 (if (eq 'write (car mh-last-destination-write))
1033 (car (cdr mh-last-destination-write))
1034 (expand-file-name "mail.out" default-dir))))
1035 current-prefix-arg))
1036 (let ((msg-file-to-output (mh-msg-filename msg))
1037 (output-file (mh-expand-file-name file)))
1038 (setq mh-last-destination (list 'write file (if no-headers 'no-headers))
1039 mh-last-destination-write mh-last-destination)
1041 (set-buffer (get-buffer-create mh-temp-buffer))
1043 (insert-file-contents msg-file-to-output)
1044 (goto-char (point-min))
1045 (if no-headers (search-forward "\n\n"))
1046 (append-to-file (point) (point-max) output-file))))
1048 (defun mh-toggle-showing ()
1049 "Toggle the scanning mode/showing mode of displaying messages."
1055 (defun mh-undo (range)
1056 "Undo the pending deletion or refile of the specified RANGE.
1058 Check the documentation of `mh-interactive-range' to see how RANGE is read in
1060 (interactive (list (mh-interactive-range "Undo")))
1061 (cond ((numberp range)
1062 (let ((original-position (point)))
1064 (while (not (or (looking-at mh-scan-deleted-msg-regexp)
1065 (looking-at mh-scan-refiled-msg-regexp)
1066 (and (eq mh-next-direction 'forward) (bobp))
1067 (and (eq mh-next-direction 'backward)
1068 (save-excursion (forward-line) (eobp)))))
1069 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
1070 (if (or (looking-at mh-scan-deleted-msg-regexp)
1071 (looking-at mh-scan-refiled-msg-regexp))
1073 (mh-undo-msg (mh-get-msg-num t))
1075 (goto-char original-position)
1076 (error "Nothing to undo"))))
1077 (t (mh-iterate-on-range () range
1078 (mh-undo-msg nil))))
1079 (if (not (mh-outstanding-commands-p))
1080 (mh-set-folder-modified-p nil)))
1083 (defun mh-folder-line-matches-show-buffer-p ()
1084 "Return t if the message under point in folder-mode is in the show buffer.
1085 Return nil in any other circumstance (no message under point, no show buffer,
1086 the message in the show buffer doesn't match."
1087 (and (eq major-mode 'mh-folder-mode)
1088 (mh-get-msg-num nil)
1090 (get-buffer mh-show-buffer)
1091 (buffer-file-name (get-buffer mh-show-buffer))
1092 (string-match ".*/\\([0-9]+\\)$"
1093 (buffer-file-name (get-buffer mh-show-buffer)))
1095 (match-string 1 (buffer-file-name (get-buffer mh-show-buffer)))
1096 (int-to-string (mh-get-msg-num nil)))))
1098 (eval-when-compile (require 'gnus))
1100 (defmacro mh-macro-expansion-time-gnus-version ()
1101 "Return Gnus version available at macro expansion time.
1102 The macro evaluates the Gnus version at macro expansion time. If MH-E was
1103 compiled then macro expansion happens at compile time."
1106 (defun mh-run-time-gnus-version ()
1107 "Return Gnus version available at run time."
1112 (defun mh-version ()
1113 "Display version information about MH-E and the MH mail handling system."
1115 (set-buffer (get-buffer-create mh-info-buffer))
1118 (insert "MH-E " mh-version "\n\n")
1119 ;; MH-E compilation details.
1120 (insert "MH-E compilation details:\n")
1121 (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version)))
1122 (gnus-compiled-version (if compiled-mhe
1123 (mh-macro-expansion-time-gnus-version)
1125 (insert " Byte compiled:\t\t" (if compiled-mhe "yes" "no") "\n"
1126 " Gnus (compile-time):\t" gnus-compiled-version "\n"
1127 " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
1129 (insert (emacs-version) "\n\n")
1131 (if mh-variant-in-use
1132 (insert mh-variant-in-use "\n"
1133 " mh-progs:\t" mh-progs "\n"
1134 " mh-lib:\t" mh-lib "\n"
1135 " mh-lib-progs:\t" mh-lib-progs "\n\n")
1136 (insert "No MH variant detected\n"))
1139 (call-process "uname" nil t nil "-a")
1141 (goto-char (point-min))
1142 (display-buffer mh-info-buffer))
1144 (defun mh-parse-flist-output-line (line &optional current-folder)
1145 "Parse LINE to generate folder name, unseen messages and total messages.
1146 If CURRENT-FOLDER is non-nil then it contains the current folder name and it is
1147 used to avoid problems in corner cases involving folders whose names end with a
1151 (goto-char (point-max))
1152 (let (folder unseen total p)
1153 (when (search-backward " out of " (point-min) t)
1154 (setq total (read-from-string
1155 (buffer-substring-no-properties
1156 (match-end 0) (line-end-position))))
1157 (when (search-backward " in sequence " (point-min) t)
1159 (when (search-backward " has " (point-min) t)
1160 (setq unseen (read-from-string (buffer-substring-no-properties
1162 (while (eq (char-after) ? )
1164 (setq folder (buffer-substring-no-properties
1165 (point-min) (1+ (point))))
1166 (when (and (equal (aref folder (1- (length folder))) ?+)
1167 (equal current-folder folder))
1168 (setq folder (substring folder 0 (1- (length folder)))))
1169 (values (format "+%s" folder) (car unseen) (car total))))))))
1171 (defun mh-folder-size-folder (folder)
1172 "Find size of FOLDER using `folder'."
1174 (let ((u (length (cdr (assoc mh-unseen-seq
1175 (mh-read-folder-sequences folder nil))))))
1176 (call-process (expand-file-name "folder" mh-progs) nil t nil
1177 "-norecurse" folder)
1178 (goto-char (point-min))
1179 (if (re-search-forward " has \\([0-9]+\\) " nil t)
1180 (values (car (read-from-string (match-string 1))) u folder)
1181 (values 0 u folder)))))
1183 (defun mh-folder-size-flist (folder)
1184 "Find size of FOLDER using `flist'."
1186 (call-process (expand-file-name "flist" mh-progs) nil t nil "-showzero"
1187 "-norecurse" folder "-sequence" (symbol-name mh-unseen-seq))
1188 (goto-char (point-min))
1189 (multiple-value-bind (folder unseen total)
1190 (mh-parse-flist-output-line
1191 (buffer-substring (point) (line-end-position)))
1192 (values total unseen folder))))
1194 (defun mh-folder-size (folder)
1195 "Find size of FOLDER."
1196 (if mh-flists-present-flag
1197 (mh-folder-size-flist folder)
1198 (mh-folder-size-folder folder)))
1200 (defun mh-visit-folder (folder &optional range index-data)
1201 "Visit FOLDER and display RANGE of messages.
1202 Do not call this function from outside MH-E; see \\[mh-rmail] instead.
1204 If RANGE is nil (the default if it is omitted when called non-interactively),
1205 then all messages in FOLDER are displayed.
1207 If an index buffer is being created then INDEX-DATA is used to initialize the
1208 index buffer specific data structures.
1210 A prefix argument will cause a prompt for the RANGE of messages
1211 regardless of the size of the `mh-large-folder' variable."
1212 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t)))
1214 (mh-read-range "Scan" folder-name t nil
1216 mh-interpret-number-as-range-flag))))
1217 (let ((config (current-window-configuration))
1218 (current-buffer (current-buffer))
1219 (threaded-view-flag mh-show-threads-flag))
1220 (delete-other-windows)
1222 (when (get-buffer folder)
1224 (setq threaded-view-flag (memq 'unthread mh-view-ops))))
1226 (mh-make-folder folder)
1227 (setq mh-index-data (car index-data)
1228 mh-index-msg-checksum-map (make-hash-table :test #'equal)
1229 mh-index-checksum-origin-map (make-hash-table :test #'equal))
1230 (mh-index-update-maps folder (cadr index-data))
1231 (mh-index-create-sequences))
1232 (mh-scan-folder folder (or range "all"))
1233 (cond ((and threaded-view-flag
1235 (goto-char (point-min))
1236 (or (null mh-large-folder)
1237 (not (equal (forward-line (1+ mh-large-folder)) 0))
1238 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
1240 (mh-toggle-threads))
1242 (mh-index-insert-folder-headers)))
1243 (unless (eq current-buffer (current-buffer))
1244 (setq mh-previous-window-config config)))
1248 (defun mh-update-sequences ()
1249 "Update MH's Unseen-Sequence and current folder and message.
1250 Flush MH-E's state out to MH. The message at the cursor becomes current."
1252 ;; mh-update-sequences is the opposite of mh-read-folder-sequences,
1253 ;; which updates MH-E's state from MH.
1254 (let ((folder-set (mh-update-unseen))
1255 (new-cur (mh-get-msg-num nil)))
1257 (let ((seq-entry (mh-find-seq 'cur)))
1258 (mh-remove-cur-notation)
1260 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq
1261 (mh-define-sequence 'cur (list new-cur))
1263 (if (looking-at mh-scan-good-msg-regexp)
1267 ;; psg - mh-current-folder is nil if mh-summary-height < 4 !
1268 ;; So I added this sanity check.
1269 (if (stringp mh-current-folder)
1270 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast")
1271 (mh-exec-cmd-quiet t "folder" "-fast")))))))
1275 ;;; Support routines.
1277 (defun mh-delete-a-msg (msg)
1279 If MSG is nil then the message at point is deleted.
1281 The value of `mh-delete-msg-hook' is a list of functions to be called, with no
1282 arguments, after the message has been deleted."
1285 (mh-goto-msg msg nil t)
1287 (setq msg (mh-get-msg-num t)))
1288 (if (looking-at mh-scan-refiled-msg-regexp)
1289 (error "Message %d is refiled. Undo refile before deleting" msg))
1290 (if (looking-at mh-scan-deleted-msg-regexp)
1292 (mh-set-folder-modified-p t)
1293 (setq mh-delete-list (cons msg mh-delete-list))
1294 (mh-notate nil mh-note-deleted mh-cmd-note)
1295 (run-hooks 'mh-delete-msg-hook))))
1297 (defun mh-refile-a-msg (msg folder)
1298 "Refile MSG in FOLDER.
1299 If MSG is nil then the message at point is refiled.
1301 Folder is a symbol, not a string.
1302 The value of `mh-refile-msg-hook' is a list of functions to be called, with no
1303 arguments, after the message has been refiled."
1306 (mh-goto-msg msg nil t)
1308 (setq msg (mh-get-msg-num t)))
1309 (cond ((looking-at mh-scan-deleted-msg-regexp)
1310 (error "Message %d is deleted. Undo delete before moving" msg))
1311 ((looking-at mh-scan-refiled-msg-regexp)
1313 (format "Message %d already refiled. Copy to %s as well? "
1315 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
1316 "-src" mh-current-folder
1317 (symbol-name folder))
1318 (message "Message not copied")))
1320 (mh-set-folder-modified-p t)
1321 (cond ((null (assoc folder mh-refile-list))
1322 (push (list folder msg) mh-refile-list))
1323 ((not (member msg (cdr (assoc folder mh-refile-list))))
1324 (push msg (cdr (assoc folder mh-refile-list)))))
1325 (mh-notate nil mh-note-refiled mh-cmd-note)
1326 (run-hooks 'mh-refile-msg-hook)))))
1328 (defun mh-next-msg (&optional wait-after-complaining-flag)
1329 "Move backward or forward to the next undeleted message in the buffer.
1330 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and we are at the
1331 last message, then wait for a second after telling the user that there aren't
1332 any more unread messages."
1333 (if (eq mh-next-direction 'forward)
1334 (mh-next-undeleted-msg 1 wait-after-complaining-flag)
1335 (mh-previous-undeleted-msg 1 wait-after-complaining-flag)))
1337 (defun mh-next-unread-msg (&optional count)
1338 "Move to next unread message.
1339 With optional argument COUNT, COUNT-1 unread messages are skipped."
1342 (error "The function mh-next-unread-msg expects positive argument"))
1343 (setq count (1- count))
1344 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list))))
1345 (cur-msg (mh-get-msg-num nil)))
1346 (cond ((and (not cur-msg) (not (bobp))
1347 ;; If we are at the end of the buffer back up one line and go
1348 ;; to unread message after that.
1351 (setq cur-msg (mh-get-msg-num nil)))
1353 ((or (null unread-sequence) (not cur-msg))
1354 ;; No unread message or there aren't any messages in buffer...
1355 (message "No more unread messages"))
1358 (while (and unread-sequence (>= cur-msg (car unread-sequence)))
1359 (setq unread-sequence (cdr unread-sequence)))
1361 (setq unread-sequence (cdr unread-sequence))
1362 (setq count (1- count)))
1363 (not (car unread-sequence)))
1364 (message "No more unread messages"))
1365 (t (loop for msg in unread-sequence
1366 when (mh-goto-msg msg t) return nil
1367 finally (message "No more unread messages"))))))
1369 (defun mh-set-scan-mode ()
1370 "Display the scan listing buffer, but do not show a message."
1371 (if (get-buffer mh-show-buffer)
1372 (delete-windows-on mh-show-buffer))
1374 (force-mode-line-update)
1375 (if mh-recenter-summary-flag
1378 (defun mh-undo-msg (msg)
1379 "Undo the deletion or refile of one MSG.
1380 If MSG is nil then act on the message at point"
1383 (mh-goto-msg msg t t)
1385 (setq msg (mh-get-msg-num t)))
1386 (cond ((memq msg mh-delete-list)
1387 (setq mh-delete-list (delq msg mh-delete-list)))
1389 (dolist (folder-msg-list mh-refile-list)
1390 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list))))
1391 (setq mh-refile-list (loop for x in mh-refile-list
1392 unless (null (cdr x)) collect x))))
1393 (mh-notate nil ? mh-cmd-note)))
1397 ;;; The folder data abstraction.
1399 (defvar mh-index-data-file ".mhe_index"
1400 "MH-E specific file where index seach info is stored.")
1402 (defun mh-make-folder (name)
1403 "Create a new mail folder called NAME.
1404 Make it the current folder."
1405 (switch-to-buffer name)
1406 (setq buffer-read-only nil)
1408 (if mh-adaptive-cmd-note-flag
1409 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name))))
1410 (setq buffer-read-only t)
1412 (mh-set-folder-modified-p nil)
1413 (setq buffer-file-name mh-folder-filename)
1414 (when (and (not mh-index-data)
1415 (file-exists-p (concat buffer-file-name mh-index-data-file)))
1416 (mh-index-read-data))
1417 (mh-make-folder-mode-line))
1419 ;;; Ensure new buffers won't get this mode if default-major-mode is nil.
1420 (put 'mh-folder-mode 'mode-class 'special)
1424 ;;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
1425 ;;; Menus for folder mode: folder, message, sequence (in that order)
1426 ;;; folder-mode "Sequence" menu
1428 mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence."
1430 ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)]
1431 ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)]
1432 ["Delete Message from Sequence..." mh-delete-msg-from-seq
1433 (mh-get-msg-num nil)]
1434 ["List Sequences in Folder..." mh-list-sequences t]
1435 ["Delete Sequence..." mh-delete-seq t]
1436 ["Narrow to Sequence..." mh-narrow-to-seq t]
1437 ["Widen from Sequence" mh-widen mh-folder-view-stack]
1439 ["Narrow to Subject Sequence" mh-narrow-to-subject t]
1440 ["Narrow to Tick Sequence" mh-narrow-to-tick
1441 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))]
1442 ["Delete Rest of Same Subject" mh-delete-subject t]
1443 ["Toggle Tick Mark" mh-toggle-tick t]
1445 ["Push State Out to MH" mh-update-sequences t]))
1447 ;;; folder-mode "Message" menu
1449 mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message."
1451 ["Show Message" mh-show (mh-get-msg-num nil)]
1452 ["Show Message with Header" mh-header-display (mh-get-msg-num nil)]
1453 ["Next Message" mh-next-undeleted-msg t]
1454 ["Previous Message" mh-previous-undeleted-msg t]
1455 ["Go to First Message" mh-first-msg t]
1456 ["Go to Last Message" mh-last-msg t]
1457 ["Go to Message by Number..." mh-goto-msg t]
1458 ["Modify Message" mh-modify t]
1459 ["Delete Message" mh-delete-msg (mh-get-msg-num nil)]
1460 ["Refile Message" mh-refile-msg (mh-get-msg-num nil)]
1461 ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)]
1462 ["Execute Delete/Refile" mh-execute-commands
1463 (mh-outstanding-commands-p)]
1465 ["Compose a New Message" mh-send t]
1466 ["Reply to Message..." mh-reply (mh-get-msg-num nil)]
1467 ["Forward Message..." mh-forward (mh-get-msg-num nil)]
1468 ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)]
1469 ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)]
1470 ["Re-edit a Bounced Message" mh-extract-rejected-mail t]
1472 ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)]
1473 ["Print Message" mh-print-msg (mh-get-msg-num nil)]
1474 ["Write Message to File..." mh-write-msg-to-file
1475 (mh-get-msg-num nil)]
1476 ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)]
1477 ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)]
1478 ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)]))
1480 ;;; folder-mode "Folder" menu
1482 mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder."
1484 ["Incorporate New Mail" mh-inc-folder t]
1485 ["Toggle Show/Folder" mh-toggle-showing t]
1486 ["Execute Delete/Refile" mh-execute-commands
1487 (mh-outstanding-commands-p)]
1488 ["Rescan Folder" mh-rescan-folder t]
1489 ["Thread Folder" mh-toggle-threads
1490 (not (memq 'unthread mh-view-ops))]
1491 ["Pack Folder" mh-pack-folder t]
1492 ["Sort Folder" mh-sort-folder t]
1494 ["List Folders" mh-list-folders t]
1495 ["Visit a Folder..." mh-visit-folder t]
1496 ["View New Messages" mh-index-new-messages t]
1497 ["Search a Folder..." mh-search-folder t]
1498 ["Indexed Search..." mh-index-search t]
1500 ["Quit MH-E" mh-quit t]))
1504 (defmacro mh-remove-xemacs-horizontal-scrollbar ()
1505 "Get rid of the horizontal scrollbar that XEmacs insists on putting in."
1506 (when mh-xemacs-flag
1507 `(if (and (featurep 'scrollbar)
1508 (fboundp 'set-specifier))
1509 (set-specifier horizontal-scrollbar-visible-p nil
1510 (cons (current-buffer) nil)))))
1512 (defmacro mh-write-file-functions-compat ()
1513 "Return `write-file-functions' if it exists.
1514 Otherwise return `local-write-file-hooks'. This macro exists purely for
1515 compatibility. The former symbol is used in Emacs 21.4 onward while the latter
1516 is used in previous versions and XEmacs."
1517 (if (boundp 'write-file-functions)
1518 ''write-file-functions ;Emacs 21.4
1519 ''local-write-file-hooks)) ;<Emacs 21.4, XEmacs
1521 ;; Avoid compiler warnings in non-bleeding edge versions of Emacs.
1523 (defvar tool-bar-mode)
1524 (defvar tool-bar-map)
1525 (defvar desktop-save-buffer)) ;Emacs 21.4
1527 ;; Register mh-folder-mode as supporting which-function-mode...
1528 (load "which-func" t t)
1529 (when (and (boundp 'which-func-modes)
1530 (not (member 'mh-folder-mode which-func-modes)))
1531 (push 'mh-folder-mode which-func-modes))
1533 (defvar mh-folder-buttons-init-flag nil)
1535 ;; Autoload cookie needed by desktop.el
1537 (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder"
1538 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
1540 You can show the message the cursor is pointing to, and step through the
1541 messages. Messages can be marked for deletion or refiling into another
1542 folder; these commands are executed all at once with a separate command.
1544 Options that control this mode can be changed with \\[customize-group];
1545 specify the \"mh\" group. In particular, please see the `mh-scan-format-file'
1546 option if you wish to modify scan's format.
1548 When a folder is visited, the hook `mh-folder-mode-hook' is run.
1552 Many commands that operate on individual messages, such as `mh-forward' or
1553 `mh-refile-msg' take a RANGE argument. This argument can be used in several
1556 If you provide the prefix argument (\\[universal-argument]) to these commands,
1557 then you will be prompted for the message range. This can be any valid MH
1558 range which can include messages, sequences, and the abbreviations (described
1559 in the mh(1) man page):
1562 Indicates all messages in the range <num1> to <num2>, inclusive. The range
1568 Up to N messages beginning with (or ending with) message num. Num may be
1569 any of the pre-defined symbols: first, prev, cur, next or last.
1575 The first, previous, next or last messages, if they exist.
1578 All of the messages.
1580 For example, a range that shows all of these things is `1 2 3 5-10 last:5
1583 If the option `transient-mark-mode' is set to t and you set a region in the
1584 MH-Folder buffer, then the MH-E command will perform the operation on all
1585 messages in that region.
1587 \\{mh-folder-mode-map}"
1589 (unless mh-folder-buttons-init-flag
1590 (mh-tool-bar-folder-buttons-init)
1591 (setq mh-folder-buttons-init-flag t)))
1592 (make-local-variable 'font-lock-defaults)
1593 (setq font-lock-defaults '(mh-folder-font-lock-keywords t))
1594 (make-local-variable 'desktop-save-buffer)
1595 (setq desktop-save-buffer t)
1597 'mh-colors-available-flag (mh-colors-available-p)
1598 ; Do we have colors available
1599 'mh-current-folder (buffer-name) ; Name of folder, a string
1600 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
1601 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
1602 (file-name-as-directory (mh-expand-file-name (buffer-name)))
1603 'mh-display-buttons-for-inline-parts-flag
1604 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to
1606 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed
1607 'overlay-arrow-position nil ; Allow for simultaneous display in
1608 'overlay-arrow-string ">" ; different MH-E buffers.
1609 'mh-showing-mode nil ; Show message also?
1610 'mh-delete-list nil ; List of msgs nums to delete
1611 'mh-refile-list nil ; List of folder names in mh-seq-list
1612 'mh-seq-list nil ; Alist of (seq . msgs) nums
1613 'mh-seen-list nil ; List of displayed messages
1614 'mh-next-direction 'forward ; Direction to move to next message
1615 'mh-view-ops () ; Stack that keeps track of the order
1616 ; in which narrowing/threading has been
1618 'mh-folder-view-stack () ; Stack of previous views of the
1620 'mh-index-data nil ; If the folder was created by a call
1621 ; to mh-index-search this contains info
1622 ; about the search results.
1623 'mh-index-previous-search nil ; Previous folder and search-regexp
1624 'mh-index-msg-checksum-map nil ; msg -> checksum map
1625 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg )
1626 'mh-index-sequence-search-flag nil ; folder resulted from sequence search
1627 'mh-first-msg-num nil ; Number of first msg in buffer
1628 'mh-last-msg-num nil ; Number of last msg in buffer
1629 'mh-msg-count nil ; Number of msgs in buffer
1630 'mh-mode-line-annotation nil ; Indicates message range
1631 'mh-sequence-notation-history (make-hash-table)
1632 ; Remember what is overwritten by
1634 'imenu-create-index-function 'mh-index-create-imenu-index
1635 ; Setup imenu support
1636 'mh-previous-window-config nil) ; Previous window configuration
1637 (mh-remove-xemacs-horizontal-scrollbar)
1638 (setq truncate-lines t)
1640 (setq buffer-offer-save t)
1641 (mh-make-local-hook (mh-write-file-functions-compat))
1642 (add-hook (mh-write-file-functions-compat) 'mh-execute-commands nil t)
1643 (make-local-variable 'revert-buffer-function)
1644 (make-local-variable 'hl-line-mode) ; avoid pollution
1645 (mh-funcall-if-exists hl-line-mode 1)
1646 (setq revert-buffer-function 'mh-undo-folder)
1647 (or (assq 'mh-showing-mode minor-mode-alist)
1648 (setq minor-mode-alist
1649 (cons '(mh-showing-mode " Show") minor-mode-alist)))
1650 (easy-menu-add mh-folder-sequence-menu)
1651 (easy-menu-add mh-folder-message-menu)
1652 (easy-menu-add mh-folder-folder-menu)
1653 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)
1654 (mh-funcall-if-exists mh-toolbar-init :folder)
1655 (if (and mh-xemacs-flag
1656 font-lock-auto-fontify)
1657 (turn-on-font-lock))) ; Force font-lock in XEmacs.
1659 (defun mh-toggle-mime-buttons ()
1660 "Toggle display of buttons for inline MIME parts."
1662 (setq mh-display-buttons-for-inline-parts-flag
1663 (not mh-display-buttons-for-inline-parts-flag))
1666 (defun mh-colors-available-p ()
1667 "Check if colors are available in the Emacs being used."
1670 (or (ignore-errors (mh-funcall-if-exists display-color-cells))
1671 (ignore-errors (mh-funcall-if-exists
1672 x-display-color-cells)))))
1673 (and (numberp color-cells) (>= color-cells 8)))))
1675 (defun mh-colors-in-use-p ()
1676 "Check if colors are being used in the folder buffer."
1677 (and mh-colors-available-flag font-lock-mode))
1679 (defun mh-make-local-vars (&rest pairs)
1680 "Initialize local variables according to the variable-value PAIRS."
1683 (set (make-local-variable (car pairs)) (car (cdr pairs)))
1684 (setq pairs (cdr (cdr pairs)))))
1686 (defun mh-restore-desktop-buffer (desktop-buffer-file-name
1688 desktop-buffer-misc)
1689 "Restore an MH folder buffer specified in a desktop file.
1690 When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the file name to
1691 visit, DESKTOP-BUFFER-NAME holds the desired buffer name, and
1692 DESKTOP-BUFFER-MISC holds a list of miscellaneous info used by the
1693 `desktop-buffer-handlers' functions."
1695 (mh-visit-folder desktop-buffer-name)
1698 ;;; desktop-buffer-mode-handlers appeared in Emacs 22.
1699 (if (fboundp 'desktop-buffer-mode-handlers)
1700 (add-to-list 'desktop-buffer-mode-handlers
1701 '(mh-folder-mode . mh-restore-desktop-buffer)))
1703 (defun mh-scan-folder (folder range &optional dont-exec-pending)
1704 "Scan the FOLDER over the RANGE.
1705 If the optional argument DONT-EXEC-PENDING is non-nil then pending deletes and
1706 refiles aren't carried out.
1707 Return in the folder's buffer."
1708 (when (stringp range)
1709 (setq range (delete "" (split-string range "[ \t\n]"))))
1710 (cond ((null (get-buffer folder))
1711 (mh-make-folder folder))
1713 (unless dont-exec-pending
1714 (mh-process-or-undo-commands folder)
1715 (mh-reset-threads-and-narrowing))
1716 (switch-to-buffer folder)))
1717 (mh-regenerate-headers range)
1718 (if (zerop (buffer-size))
1719 (if (equal range "all")
1720 (message "Folder %s is empty" folder)
1721 (message "No messages in %s, range %s" folder range))
1723 (when (mh-outstanding-commands-p)
1724 (mh-notate-deleted-and-refiled)))
1726 (defun mh-msg-num-width-to-column (width)
1727 "Return the column for notations given message number WIDTH.
1728 Note that columns in Emacs start with 0.
1730 If `mh-scan-format-file' is set to \"Use MH-E scan Format\" this means that
1731 either `mh-scan-format-mh' or `mh-scan-format-nmh' are in use. This function
1732 therefore assumes that the first column is empty (to provide room for the
1733 cursor), the following WIDTH columns contain the message number, and the
1734 column for notations comes after that."
1735 (if (eq mh-scan-format-file t)
1737 (error "%s %s" "Can't call mh-msg-num-width-to-column"
1738 "when mh-scan-format-file is not t")))
1740 (defun mh-set-cmd-note (column)
1741 "Set `mh-cmd-note' to COLUMN.
1742 Note that columns in Emacs start with 0."
1743 (setq mh-cmd-note column))
1745 (defun mh-regenerate-headers (range &optional update)
1746 "Scan folder over range RANGE.
1747 If UPDATE, append the scan lines, otherwise replace."
1748 (let ((folder mh-current-folder)
1749 (range (if (and range (atom range)) (list range) range))
1751 (message "Scanning %s..." folder)
1752 (mh-remove-all-notation)
1753 (with-mh-folder-updating (nil)
1755 (goto-char (point-max))
1756 (delete-region (point-min) (point-max))
1757 (if mh-adaptive-cmd-note-flag
1758 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width
1760 (setq scan-start (point))
1761 (apply #'mh-exec-cmd-output
1764 "-noclear" "-noheader"
1765 "-width" (window-width)
1767 (goto-char scan-start)
1768 (cond ((looking-at "scan: no messages in")
1769 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines
1770 ((looking-at (if (mh-variant-p 'mu-mh)
1771 "scan: message set .* does not exist"
1772 "scan: bad message list "))
1773 (keep-lines mh-scan-valid-regexp))
1774 ((looking-at "scan: ")) ; Keep error messages
1776 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines
1777 (setq mh-seq-list (mh-read-folder-sequences folder nil))
1778 (mh-notate-user-sequences)
1780 (setq mh-mode-line-annotation
1781 (if (equal range '("all"))
1783 mh-partial-folder-mode-line-annotation)))
1784 (mh-make-folder-mode-line))
1785 (message "Scanning %s...done" folder)))
1787 (defun mh-generate-new-cmd-note (folder)
1788 "Fix the `mh-cmd-note' value for this FOLDER.
1790 After doing an `mh-get-new-mail' operation in this FOLDER, at least
1791 one line that looks like a truncated message number was found.
1793 Remove the text added by the last `mh-inc' command. It should be the messages
1794 cur-last. Call `mh-set-cmd-note', adjusting the notation column with the width
1795 of the largest message number in FOLDER.
1797 Reformat the message number width on each line in the buffer and trim
1798 the line length to fit in the window.
1800 Rescan the FOLDER in the range cur-last in order to display the
1801 messages that were removed earlier. They should all fit in the scan
1802 line now with no message truncation."
1804 (let ((maxcol (1- (window-width)))
1805 (old-cmd-note mh-cmd-note)
1808 ;; Nuke all of the lines just added by the last inc
1809 (delete-char (- (point-max) (point)))
1810 ;; Update the current buffer to reflect the new mh-cmd-note
1811 ;; value needed to display messages.
1812 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder)))
1813 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d"))
1814 ;; Cleanup the messages that are in the buffer right now
1815 (goto-char (point-min))
1816 (cond ((memq 'unthread mh-view-ops)
1817 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note)))
1818 (t (while (re-search-forward mh-scan-msg-number-regexp nil 0 1)
1819 ;; reformat the number to fix in mh-cmd-note columns
1820 (setq msgnum (string-to-number
1822 (match-beginning 1) (match-end 1))))
1823 (replace-match (format mh-cmd-note-fmt msgnum))
1824 ;; trim the line to fix in the window
1826 (let ((eol (point)))
1827 (move-to-column maxcol)
1828 (if (<= (point) eol)
1829 (delete-char (- eol (point))))))))
1830 ;; now re-read the lost messages
1831 (goto-char (point-max))
1833 (mh-regenerate-headers "cur-last" t)))))
1835 (defun mh-get-new-mail (maildrop-name)
1836 "Read new mail from MAILDROP-NAME into the current buffer.
1837 Return in the current buffer."
1838 (let ((point-before-inc (point))
1839 (folder mh-current-folder)
1840 (new-mail-flag nil))
1841 (with-mh-folder-updating (t)
1843 (message "inc %s -file %s..." folder maildrop-name)
1844 (message "inc %s..." folder))
1845 (setq mh-next-direction 'forward)
1846 (goto-char (point-max))
1847 (mh-remove-cur-notation)
1848 (let ((start-of-inc (point)))
1850 ;; I think MH 5 used "-ms-file" instead of "-file",
1851 ;; which would make inc'ing from maildrops fail.
1852 (mh-exec-cmd-output mh-inc-prog nil folder
1854 "-file" (expand-file-name maildrop-name)
1855 "-width" (window-width)
1857 (mh-exec-cmd-output mh-inc-prog nil
1859 "-width" (window-width)))
1861 (message "inc %s -file %s...done" folder maildrop-name)
1862 (message "inc %s...done" folder))
1863 (goto-char start-of-inc)
1864 (cond ((save-excursion
1865 (re-search-forward "^inc: no mail" nil t))
1866 (message "No new mail%s%s" (if maildrop-name " in " "")
1867 (if maildrop-name maildrop-name "")))
1868 ((and (when mh-folder-view-stack
1869 (let ((saved-text (buffer-substring-no-properties
1870 start-of-inc (point-max))))
1871 (delete-region start-of-inc (point-max))
1872 (unwind-protect (mh-widen t)
1873 (mh-remove-cur-notation)
1874 (goto-char (point-max))
1875 (setq start-of-inc (point))
1877 (goto-char start-of-inc))))
1879 ((re-search-forward "^inc:" nil t) ; Error messages
1880 (error "Error incorporating mail"))
1882 (equal mh-scan-format-file t)
1883 mh-adaptive-cmd-note-flag
1884 ;; Have we reached an edge condition?
1886 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1))
1887 (setq start-of-inc (mh-generate-new-cmd-note folder))
1890 (setq new-mail-flag t)))
1891 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines
1892 (let* ((sequences (mh-read-folder-sequences folder t))
1893 (new-cur (assoc 'cur sequences))
1894 (new-unseen (assoc mh-unseen-seq sequences)))
1895 (unless (assoc 'cur mh-seq-list)
1896 (push (list 'cur) mh-seq-list))
1897 (unless (assoc mh-unseen-seq mh-seq-list)
1898 (push (list mh-unseen-seq) mh-seq-list))
1899 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur))
1900 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen)))
1901 (when (equal (point-max) start-of-inc)
1905 (mh-make-folder-mode-line)
1906 (when (mh-speed-flists-active-p)
1907 (mh-speed-flists t mh-current-folder))
1908 (when (memq 'unthread mh-view-ops)
1909 (mh-thread-inc folder start-of-inc))
1911 (goto-char point-before-inc))
1912 (mh-notate-user-sequences (cons start-of-inc (point-max)))))))
1914 (defun mh-make-folder-mode-line (&optional ignored)
1915 "Set the fields of the mode line for a folder buffer.
1916 The optional argument is now obsolete and IGNORED. It used to be used to pass
1917 in what is now stored in the buffer-local variable `mh-mode-line-annotation'."
1919 (save-window-excursion
1921 (let ((new-first-msg-num (mh-get-msg-num nil)))
1922 (when (or (not (memq 'unthread mh-view-ops))
1923 (null mh-first-msg-num)
1924 (null new-first-msg-num)
1925 (< new-first-msg-num mh-first-msg-num))
1926 (setq mh-first-msg-num new-first-msg-num)))
1928 (let ((new-last-msg-num (mh-get-msg-num nil)))
1929 (when (or (not (memq 'unthread mh-view-ops))
1930 (null mh-last-msg-num)
1931 (null new-last-msg-num)
1932 (> new-last-msg-num mh-last-msg-num))
1933 (setq mh-last-msg-num new-last-msg-num)))
1934 (setq mh-msg-count (if mh-first-msg-num
1935 (count-lines (point-min) (point-max))
1937 (setq mode-line-buffer-identification
1938 (list (format " {%%b%s} %s msg%s"
1939 (if mh-mode-line-annotation
1940 (format "/%s" mh-mode-line-annotation)
1942 (if (zerop mh-msg-count)
1944 (format "%d" mh-msg-count))
1945 (if (zerop mh-msg-count)
1947 (cond ((> mh-msg-count 1)
1948 (format "s (%d-%d)" mh-first-msg-num
1951 (format " (%d)" mh-first-msg-num))
1953 (mh-logo-display))))
1955 (defun mh-add-sequence-notation (msg internal-seq-flag)
1956 "Add sequence notation to the MSG on the current line.
1957 If INTERNAL-SEQ-FLAG is non-nil, then refontify the scan line if font-lock is
1959 (with-mh-folder-updating (t)
1962 (if internal-seq-flag
1964 ;; Change the buffer so that if transient-mark-mode is active
1965 ;; and there is an active region it will get deactivated as in
1966 ;; the case of user sequences.
1967 (mh-notate nil nil mh-cmd-note)
1968 (when font-lock-mode
1969 (font-lock-fontify-region (point) (line-end-position))))
1970 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
1971 (let ((stack (gethash msg mh-sequence-notation-history)))
1972 (setf (gethash msg mh-sequence-notation-history)
1973 (cons (char-after) stack)))
1974 (mh-notate nil mh-note-seq
1975 (+ mh-cmd-note mh-scan-field-destination-offset))))))
1977 (defun mh-remove-sequence-notation (msg internal-seq-flag &optional all)
1978 "Remove sequence notation from the MSG on the current line.
1979 If INTERNAL-SEQ-FLAG is non-nil, then `font-lock' was used to highlight the
1980 sequence. In that case, no notation needs to be removed. Otherwise the effect
1981 of inserting `mh-note-seq' needs to be reversed.
1982 If ALL is non-nil, then all sequence marks on the scan line are removed."
1983 (with-mh-folder-updating (t)
1984 ;; This takes care of internal sequences...
1985 (mh-notate nil nil mh-cmd-note)
1986 (unless internal-seq-flag
1987 ;; ... and this takes care of user sequences.
1988 (let ((stack (gethash msg mh-sequence-notation-history)))
1989 (while (and all (cdr stack))
1990 (setq stack (cdr stack)))
1994 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
1996 (insert (car stack))))
1997 (setf (gethash msg mh-sequence-notation-history) (cdr stack))))))
1999 (defun mh-remove-cur-notation ()
2000 "Remove old cur notation."
2001 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2004 (mh-goto-msg cur-msg t t)
2005 (looking-at mh-scan-cur-msg-number-regexp))
2006 (mh-notate nil ? mh-cmd-note)
2007 (setq overlay-arrow-position nil)))))
2009 (defun mh-remove-all-notation ()
2010 "Remove all notations on all scan lines that MH-E introduces."
2012 (setq overlay-arrow-position nil)
2013 (goto-char (point-min))
2014 (mh-iterate-on-range msg (cons (point-min) (point-max))
2015 (mh-notate nil ? mh-cmd-note)
2016 (mh-remove-sequence-notation msg nil t))
2017 (clrhash mh-sequence-notation-history)))
2020 (defun mh-goto-cur-msg (&optional minimal-changes-flag)
2021 "Position the cursor at the current message.
2022 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the function doesn't
2023 recenter the folder buffer."
2024 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2026 (mh-goto-msg cur-msg t t))
2027 (unless minimal-changes-flag
2030 (mh-maybe-show cur-msg)))
2032 (setq overlay-arrow-position nil)
2033 (message "No current message")))))
2035 (defun mh-process-or-undo-commands (folder)
2036 "If FOLDER has outstanding commands, then either process or discard them.
2037 Called by functions like `mh-sort-folder', so also invalidate show buffer."
2039 (if (mh-outstanding-commands-p)
2040 (if (or mh-do-not-confirm-flag
2042 "Process outstanding deletes and refiles? "))
2043 (mh-process-commands folder)
2047 (mh-invalidate-show-buffer))
2049 (defun mh-process-commands (folder)
2050 "Process outstanding commands for FOLDER.
2051 The value of `mh-folder-updated-hook' is a list of functions to be called,
2052 with no arguments, before the commands are processed."
2053 (message "Processing deletes and refiles for %s..." folder)
2055 (with-mh-folder-updating (nil)
2056 ;; Run the hook while the lists are still valid
2057 (run-hooks 'mh-folder-updated-hook)
2059 ;; Update the unseen sequence if it exists
2062 (let ((redraw-needed-flag mh-index-data)
2063 (folders-changed (list mh-current-folder))
2064 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag
2065 (mh-create-sequence-map mh-seq-list)))
2066 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag
2067 (make-hash-table))))
2068 ;; Remove invalid scan lines if we are in an index folder and then remove
2069 ;; the real messages
2071 (mh-index-delete-folder-headers)
2072 (setq folders-changed
2073 (append folders-changed (mh-index-execute-commands))))
2075 ;; Then refile messages
2076 (mh-mapc #'(lambda (folder-msg-list)
2077 (let* ((dest-folder (symbol-name (car folder-msg-list)))
2078 (last (car (mh-translate-range dest-folder "last")))
2079 (msgs (cdr folder-msg-list)))
2080 (push dest-folder folders-changed)
2081 (setq redraw-needed-flag t)
2082 (apply #'mh-exec-cmd
2083 "refile" "-src" folder dest-folder
2084 (mh-coalesce-msg-list msgs))
2085 (mh-delete-scan-msgs msgs)
2086 ;; Preserve sequences in destination folder...
2087 (when mh-refile-preserves-sequences-flag
2089 (loop for i from (1+ (or last 0))
2090 for msg in (sort (copy-sequence msgs) #'<)
2091 do (loop for seq-name in (gethash msg seq-map)
2092 do (push i (gethash seq-name dest-map))))
2094 #'(lambda (seq msgs)
2095 ;; Can't be run in the background, since the
2096 ;; current folder is changed by mark this could
2097 ;; lead to a race condition with the next refile.
2098 (apply #'mh-exec-cmd "mark"
2099 "-sequence" (symbol-name seq) dest-folder
2100 "-add" (mapcar #'(lambda (x) (format "%s" x))
2101 (mh-coalesce-msg-list msgs))))
2104 (setq mh-refile-list ())
2106 ;; Now delete messages
2107 (cond (mh-delete-list
2108 (setq redraw-needed-flag t)
2109 (apply 'mh-exec-cmd "rmm" folder
2110 (mh-coalesce-msg-list mh-delete-list))
2111 (mh-delete-scan-msgs mh-delete-list)
2112 (setq mh-delete-list nil)))
2114 ;; Don't need to remove sequences since delete and refile do so.
2116 (if (> (buffer-size) 0)
2117 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last"))))
2119 ;; Redraw folder buffer if needed
2120 (when (and redraw-needed-flag)
2121 (when (mh-speed-flists-active-p)
2122 (apply #'mh-speed-flists t folders-changed))
2123 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max)))
2124 (mh-index-data (mh-index-insert-folder-headers)))))
2126 (and (buffer-file-name (get-buffer mh-show-buffer))
2127 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
2128 ;; If "inc" were to put a new msg in this file,
2129 ;; we would not notice, so mark it invalid now.
2130 (mh-invalidate-show-buffer))
2132 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
2133 (mh-remove-all-notation)
2134 (mh-notate-user-sequences)
2135 (message "Processing deletes and refiles for %s...done" folder)))
2137 (defun mh-update-unseen ()
2138 "Synchronize the unseen sequence with MH.
2139 Return non-nil iff the MH folder was set.
2140 The value of `mh-unseen-updated-hook' is a list of functions to be called,
2141 with no arguments, after the unseen sequence is updated."
2143 (let* ((unseen-seq (mh-find-seq mh-unseen-seq))
2144 (unseen-msgs (mh-seq-msgs unseen-seq)))
2147 (mh-undefine-sequence mh-unseen-seq mh-seen-list)
2148 (run-hooks 'mh-unseen-updated-hook)
2150 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs))
2151 (setq mh-seen-list (cdr mh-seen-list)))
2152 (setcdr unseen-seq unseen-msgs)
2153 t) ;since we set the folder
2154 (setq mh-seen-list nil)))))
2156 (defun mh-delete-scan-msgs (msgs)
2157 "Delete the scan listing lines for MSGS."
2160 (when (mh-goto-msg (car msgs) t t)
2161 (when (memq 'unthread mh-view-ops)
2162 (mh-thread-forget-message (car msgs)))
2164 (setq msgs (cdr msgs)))))
2166 (defun mh-outstanding-commands-p ()
2167 "Return non-nil if there are outstanding deletes or refiles."
2169 (when (eq major-mode 'mh-show-mode)
2170 (set-buffer mh-show-folder-buffer))
2171 (or mh-delete-list mh-refile-list)))
2173 (defun mh-coalesce-msg-list (messages)
2174 "Given a list of MESSAGES, return a list of message number ranges.
2175 This is the inverse of `mh-read-msg-list', which expands ranges.
2176 Message lists passed to MH programs should be processed by this function
2177 to avoid exceeding system command line argument limits."
2178 (let ((msgs (sort (copy-sequence messages) 'mh-greaterp))
2184 (if (or (not (numberp prev))
2185 (not (equal (car msgs) (1- prev))))
2186 (progn ;non-sequential, flush old range
2187 (if (eq prev range-high)
2188 (setq ranges (cons range-high ranges))
2189 (setq ranges (cons (format "%s-%s" prev range-high) ranges)))
2190 (setq range-high nil))))
2192 (setq range-high (car msgs))) ;start new or first range
2193 (setq prev (car msgs))
2194 (setq msgs (cdr msgs)))
2197 (defun mh-greaterp (msg1 msg2)
2198 "Return the greater of two message indicators MSG1 and MSG2.
2199 Strings are \"smaller\" than numbers.
2200 Valid values are things like \"cur\", \"last\", 1, and 1820."
2207 (string-lessp msg2 msg1))))
2209 (defun mh-lessp (msg1 msg2)
2210 "Return the lesser of two message indicators MSG1 and MSG2.
2211 Strings are \"smaller\" than numbers.
2212 Valid values are things like \"cur\", \"last\", 1, and 1820."
2213 (not (mh-greaterp msg1 msg2)))
2217 ;;; Basic sequence handling
2219 (defun mh-delete-seq-locally (seq)
2220 "Remove MH-E's record of SEQ."
2221 (let ((entry (mh-find-seq seq)))
2222 (setq mh-seq-list (delq entry mh-seq-list))))
2224 (defun mh-read-folder-sequences (folder save-refiles)
2225 "Read and return the predefined sequences for a FOLDER.
2226 If SAVE-REFILES is non-nil, then keep the sequences
2227 that note messages to be refiled."
2230 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
2231 (if (mh-folder-name-p (mh-seq-name seq))
2232 (setq seqs (cons seq seqs)))))
2235 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
2237 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
2238 (while (re-search-forward "^[^: ]+" nil t)
2239 (setq seqs (cons (mh-make-seq (intern (buffer-substring
2244 (delete-region (point-min) (point))))) ; avoid race with
2248 (defun mh-read-msg-list ()
2249 "Return a list of message numbers from point to the end of the line.
2250 Expands ranges into set of individual numbers."
2252 (end-of-line (save-excursion (end-of-line) (point)))
2254 (while (re-search-forward "[0-9]+" end-of-line t)
2255 (setq num (string-to-number (buffer-substring (match-beginning 0)
2257 (cond ((looking-at "-") ; Message range
2259 (re-search-forward "[0-9]+" end-of-line t)
2260 (let ((num2 (string-to-number
2261 (buffer-substring (match-beginning 0)
2264 (error "Bad message range: %d-%d" num num2))
2265 (while (<= num num2)
2266 (setq msgs (cons num msgs))
2267 (setq num (1+ num)))))
2268 ((not (zerop num)) ;"pick" outputs "0" to mean no match
2269 (setq msgs (cons num msgs)))))
2272 (defun mh-notate-user-sequences (&optional range)
2273 "Mark user-defined sequences in the messages specified by RANGE.
2274 The optional argument RANGE can be a message number, a list of message
2275 numbers, a sequence, a region in a cons cell. If nil all messages are notated."
2277 (setq range (cons (point-min) (point-max))))
2278 (let ((seqs mh-seq-list)
2279 (msg-hash (make-hash-table)))
2281 (dolist (msg (mh-seq-msgs seq))
2282 (push (car seq) (gethash msg msg-hash))))
2283 (mh-iterate-on-range msg range
2284 (loop for seq in (gethash msg msg-hash)
2285 do (mh-add-sequence-notation msg (mh-internal-seq seq))))))
2287 (defvar mh-internal-seqs '(answered cur deleted forwarded printed))
2289 (defun mh-internal-seq (name)
2290 "Return non-nil if NAME is the name of an internal MH-E sequence."
2291 (or (memq name mh-internal-seqs)
2292 (eq name mh-unseen-seq)
2293 (and (mh-colors-in-use-p) mh-tick-seq (eq name mh-tick-seq))
2294 (eq name mh-previous-seq)
2295 (mh-folder-name-p name)))
2297 (defun mh-valid-seq-p (name)
2298 "Return non-nil if NAME is a valid MH sequence name."
2300 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" (symbol-name name))))
2302 (defun mh-delete-msg-from-seq (range sequence &optional internal-flag)
2303 "Delete RANGE from SEQUENCE.
2305 Check the documentation of `mh-interactive-range' to see how RANGE is read in
2308 Optional third arg INTERNAL-FLAG non-nil means do not inform MH of the
2310 (interactive (list (mh-interactive-range "Delete")
2311 (mh-read-seq-default "Delete from" t)
2313 (let ((entry (mh-find-seq sequence))
2314 (user-sequence-flag (not (mh-internal-seq sequence)))
2315 (folders-changed (list mh-current-folder))
2318 (mh-iterate-on-range msg range
2320 ;; Calling "mark" repeatedly takes too long. So we will pretend here
2321 ;; that we are just modifying an internal sequence...
2322 (when (memq msg (cdr entry))
2323 (mh-remove-sequence-notation msg (not user-sequence-flag)))
2324 (mh-delete-a-msg-from-seq msg sequence t))
2325 ;; ... and here we will "mark" all the messages at one go.
2326 (unless internal-flag (mh-undefine-sequence sequence msg-list))
2327 (when (and mh-index-data (not internal-flag))
2328 (setq folders-changed
2329 (append folders-changed
2330 (mh-index-delete-from-sequence sequence msg-list))))
2331 (when (and (eq sequence mh-unseen-seq) (mh-speed-flists-active-p))
2332 (apply #'mh-speed-flists t folders-changed)))))
2334 (defun mh-catchup (range)
2335 "Delete RANGE from the `mh-unseen-seq' sequence.
2337 Check the document of `mh-interactive-range' to see how RANGE is read in
2339 (interactive (list (mh-interactive-range "Catchup"
2340 (cons (point-min) (point-max)))))
2341 (mh-delete-msg-from-seq range mh-unseen-seq))
2343 (defun mh-delete-a-msg-from-seq (msg sequence internal-flag)
2344 "Delete MSG from SEQUENCE.
2345 If INTERNAL-FLAG is non-nil, then do not inform MH of the change."
2346 (let ((entry (mh-find-seq sequence)))
2347 (when (and entry (memq msg (mh-seq-msgs entry)))
2348 (if (not internal-flag)
2349 (mh-undefine-sequence sequence (list msg)))
2350 (setcdr entry (delq msg (mh-seq-msgs entry))))))
2352 (defun mh-undefine-sequence (seq msgs)
2353 "Remove from the SEQ the list of MSGS."
2354 (when (and (mh-valid-seq-p seq) msgs)
2355 (apply #'mh-exec-cmd "mark" mh-current-folder "-delete"
2356 "-sequence" (symbol-name seq) (mh-coalesce-msg-list msgs))))
2358 (defun mh-define-sequence (seq msgs)
2359 "Define the SEQ to contain the list of MSGS.
2360 Do not mark pseudo-sequences or empty sequences.
2361 Signals an error if SEQ is an invalid name."
2363 (mh-valid-seq-p seq)
2364 (not (mh-folder-name-p seq)))
2366 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
2367 "-sequence" (symbol-name seq)
2368 (mh-coalesce-msg-list msgs)))))
2370 (defun mh-seq-containing-msg (msg &optional include-internal-flag)
2371 "Return a list of the sequences containing MSG.
2372 If INCLUDE-INTERNAL-FLAG non-nil, include MH-E internal sequences in list."
2373 (let ((l mh-seq-list)
2376 (and (memq msg (mh-seq-msgs (car l)))
2377 (or include-internal-flag
2378 (not (mh-internal-seq (mh-seq-name (car l)))))
2379 (setq seqs (cons (mh-seq-name (car l)) seqs)))
2385 ;;; Build the folder-mode keymap:
2387 (suppress-keymap mh-folder-mode-map)
2389 ;; Use defalias to make sure the documented primary key bindings
2390 ;; appear in menu lists.
2391 (defalias 'mh-alt-show 'mh-show)
2392 (defalias 'mh-alt-refile-msg 'mh-refile-msg)
2393 (defalias 'mh-alt-send 'mh-send)
2394 (defalias 'mh-alt-visit-folder 'mh-visit-folder)
2396 ;; Save the `b' binding for a future `back'. Maybe?
2397 (gnus-define-keys mh-folder-mode-map
2399 "!" mh-refile-or-write-again
2401 "," mh-header-display
2403 ";" mh-toggle-mh-decode-mime-flag
2404 ">" mh-write-msg-to-file
2406 "E" mh-extract-rejected-mail
2408 "\177" mh-previous-page
2409 "\C-d" mh-delete-msg-no-motion
2410 "\t" mh-index-next-folder
2411 [backtab] mh-index-previous-folder
2412 "\M-\t" mh-index-previous-folder
2415 "\ed" mh-redistribute
2417 "^" mh-alt-refile-msg
2424 "k" mh-delete-subject-or-thread
2426 "n" mh-next-undeleted-msg
2427 "\M-n" mh-next-unread-msg
2429 "p" mh-previous-undeleted-msg
2430 "\M-p" mh-previous-unread-msg
2434 "t" mh-toggle-showing
2436 "v" mh-index-visit-folder
2437 "x" mh-execute-commands
2440 (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map)
2442 "'" mh-index-ticked-messages
2445 "f" mh-alt-visit-folder
2449 "n" mh-index-new-messages
2450 "o" mh-alt-visit-folder
2452 "q" mh-index-sequenced-messages
2453 "r" mh-rescan-folder
2454 "s" mh-search-folder
2456 "v" mh-visit-folder)
2458 (define-key mh-folder-mode-map "I" mh-inc-spool-map)
2460 (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map)
2462 "b" mh-junk-blacklist
2463 "w" mh-junk-whitelist)
2465 (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map)
2467 "A" mh-ps-print-toggle-mime
2468 "C" mh-ps-print-toggle-color
2469 "F" mh-ps-print-toggle-faces
2470 "M" mh-ps-print-toggle-mime
2471 "f" mh-ps-print-msg-file
2474 "s" mh-ps-print-msg-show)
2476 (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map)
2477 "'" mh-narrow-to-tick
2479 "d" mh-delete-msg-from-seq
2481 "l" mh-list-sequences
2482 "n" mh-narrow-to-seq
2483 "p" mh-put-msg-in-seq
2484 "s" mh-msg-is-in-seq
2487 (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map)
2489 "u" mh-thread-ancestor
2490 "p" mh-thread-previous-sibling
2491 "n" mh-thread-next-sibling
2492 "t" mh-toggle-threads
2493 "d" mh-thread-delete
2494 "o" mh-thread-refile)
2496 (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map)
2497 "'" mh-narrow-to-tick
2500 "f" mh-narrow-to-from
2501 "r" mh-narrow-to-range
2502 "s" mh-narrow-to-subject
2506 (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map)
2508 "s" mh-store-msg ;shar
2509 "u" mh-store-msg) ;uuencode
2511 (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map)
2514 "\177" mh-page-digest-backwards
2515 "b" mh-burst-digest)
2517 (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map)
2519 "a" mh-mime-save-parts
2520 "e" mh-display-with-external-viewer
2521 "i" mh-folder-inline-mime-part
2522 "o" mh-folder-save-mime-part
2523 "t" mh-toggle-mime-buttons
2524 "v" mh-folder-toggle-mime-part
2526 [backtab] mh-prev-button
2527 "\M-\t" mh-prev-button)
2531 (define-key mh-folder-mode-map [button2] 'mh-show-mouse))
2533 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse)))
2535 ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt
2541 ;;; If you add a new prefix, add appropriate text to the nil key.
2543 ;;; In general, messages are grouped logically. Taking the main commands for
2544 ;;; example, the first line is "ways to view messages," the second line is
2545 ;;; "things you can do with messages", and the third is "composing" messages.
2547 ;;; When adding a new prefix, ensure that the help message contains "what" the
2548 ;;; prefix is for. For example, if the word "folder" were not present in the
2549 ;;; `F' entry, it would not be clear what these commands operated upon.
2550 (defvar mh-help-messages
2551 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n"
2552 "[d]elete, [o]refile, e[x]ecute,\n"
2553 "[s]end, [r]eply,\n"
2554 "[;]toggle MIME decoding.\n"
2555 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys,"
2556 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.")
2558 (?F "[l]ist; [v]isit folder;\n"
2559 "[n]ew messages; [']ticked messages; [s]earch; [i]ndexed search;\n"
2560 "[p]ack; [S]ort; [r]escan; [k]ill")
2561 (?P "PS [p]rint message; [l]non-PS print;\n"
2562 "PS Print [s]how window, message to [f]ile;\n"
2563 "Toggle printing of [M]IME parts, [C]olor, [F]aces")
2564 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n"
2565 "[s]equences, [l]ist,\n"
2566 "[d]elete message from sequence, [k]ill sequence")
2567 (?T "[t]oggle, [d]elete, [o]refile thread")
2568 (?/ "Limit to [c]c, [f]rom, [r]ange, [s]ubject, [t]o; [w]iden")
2569 (?X "un[s]har, [u]udecode message")
2570 (?D "[b]urst digest")
2571 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n"
2572 "[TAB] next; [SHIFT-TAB] previous")
2573 (?J "[b]lacklist, [w]hitelist message"))
2574 "Key binding cheat sheet.
2576 This is an associative array which is used to show the most common commands.
2577 The key is a prefix char. The value is one or more strings which are
2578 concatenated together and displayed in the minibuffer if ? is pressed after
2579 the prefix character. The special key nil is used to display the
2580 non-prefixed commands.
2582 The substitutions described in `substitute-command-keys' are performed as
2587 (dolist (mess '("^Cursor not pointing to message$"
2588 "^There is no other window$"))
2589 (add-to-list 'debug-ignored-errors mess))
2593 ;;; Local Variables:
2594 ;;; indent-tabs-mode: nil
2595 ;;; sentence-end-double-space: nil
2598 ;;; arch-tag: cce884de-bd37-4104-9963-e4439d5ed22b
2599 ;;; mh-e.el ends here