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, 2006 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
99 (defvar font-lock-auto-fontify)
100 (defvar font-lock-defaults))
102 (defconst mh-version "7.85+cvs" "Version number of MH-E.")
104 (defvar mh-partial-folder-mode-line-annotation "select"
105 "Annotation when displaying part of a folder.
106 The string is displayed after the folder's name. nil for no
111 ;;; Scan Line Formats
113 ;; Parameterize MH-E to work with different scan formats. The defaults work
114 ;; with the standard MH scan listings, in which the first 4 characters on
115 ;; the line are the message number, followed by two places for notations.
117 ;; The following scan formats are passed to the scan program if the setting of
118 ;; `mh-scan-format-file' is t. They are identical except the later one makes
119 ;; use of the nmh `decode' function to decode RFC 2047 encodings. If you just
120 ;; want to change the column of the notations, use the `mh-set-cmd-note'
123 (defvar mh-scan-format-mh
128 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
129 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
130 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
131 "%?(nonnull(comp{newsgroups}))n%>"
133 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
134 "%<(mymbox{from})%<{to}To:%14(friendly{to})%>%>"
135 "%<(zero)%17(friendly{from})%> "
136 "%{subject}%<{body}<<%{body}%>")
137 "*Scan format string for MH.
138 This string is passed to the scan program via the -format
139 argument. This format is identical to the default except that
140 additional hints for fontification have been added to the fifth
141 column (remember that in Emacs, the first column is 0).
143 The values of the fifth column, in priority order, are: \"-\" if
144 the message has been replied to, t if an address on the To: line
145 matches one of the mailboxes of the current user, \"c\" if the Cc:
146 line matches, \"b\" if the Bcc: line matches, and \"n\" if a
147 non-empty Newsgroups: header is present.")
149 (defvar mh-scan-format-nmh
154 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
155 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
156 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
157 "%?(nonnull(comp{newsgroups}))n%>"
159 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
160 "%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>"
161 "%<(zero)%17(decode(friendly{from}))%> "
162 "%(decode{subject})%<{body}<<%{body}%>")
163 "*Scan format string for nmh.
164 This string is passed to the scan program via the -format arg.
165 This format is identical to the default except that additional
166 hints for fontification have been added to the fifth
167 column (remember that in Emacs, the first column is 0).
169 The values of the fifth column, in priority order, are: \"-\" if
170 the message has been replied to, t if an address on the To: field
171 matches one of the mailboxes of the current user, \"c\" if the Cc:
172 field matches, \"b\" if the Bcc: field matches, and \"n\" if a
173 non-empty Newsgroups: field is present.")
175 (defvar mh-note-deleted ?D
176 "Messages that have been deleted are marked by this character.
177 See also `mh-scan-deleted-msg-regexp'.")
179 (defvar mh-note-refiled ?^
180 "Messages that have been refiled are marked by this character.
181 See also `mh-scan-refiled-msg-regexp'.")
183 (defvar mh-note-cur ?+
184 "The current message (in MH, not in MH-E) is marked by this character.
185 See also `mh-scan-cur-msg-number-regexp'.")
187 (defvar mh-scan-good-msg-regexp "^\\( *[0-9]+\\)[^D^0-9]"
188 "This regular expression matches \"good\" messages.
190 It must match from the beginning of the line. Note that the
191 default setting of `mh-folder-font-lock-keywords' expects this
192 expression to contain at least one parenthesized expression which
193 matches the message number as in the default of
195 \"^\\\\( *[0-9]+\\\\)[^D^0-9]\".
197 This expression includes the leading space within the parenthesis
198 since it looks better to highlight it as well. The highlighting
199 is done with the face `mh-folder-msg-number'. This regular
200 expression should be correct as it is needed by non-fontification
203 (defvar mh-scan-deleted-msg-regexp "^\\( *[0-9]+\\)D"
204 "This regular expression matches deleted messages.
206 It must match from the beginning of the line. Note that the
207 default setting of `mh-folder-font-lock-keywords' expects this
208 expression to contain at least one parenthesized expression which
209 matches the message number as in the default of
211 \"^\\\\( *[0-9]+\\\\)D\".
213 This expression includes the leading space within the parenthesis
214 since it looks better to highlight it as well. The highlighting
215 is done with the face `mh-folder-deleted'. This regular
216 expression should be correct as it is needed by non-fontification
217 functions. See also `mh-note-deleted'.")
219 (defvar mh-scan-refiled-msg-regexp "^\\( *[0-9]+\\)\\^"
220 "This regular expression matches refiled messages.
222 It must match from the beginning of the line. Note that the
223 default setting of `mh-folder-font-lock-keywords' expects this
224 expression to contain at least one parenthesized expression which
225 matches the message number as in the default of
227 \"^\\\\( *[0-9]+\\\\)\\\\^\".
229 This expression includes the leading space within the parenthesis
230 since it looks better to highlight it as well. The highlighting
231 is done with the face `mh-folder-refiled'. This regular
232 expression should be correct as it is needed by non-fontification
233 functions. See also `mh-note-refiled'.")
235 (defvar mh-scan-valid-regexp "^ *[0-9]"
236 "This regular expression describes a valid scan line.
238 This is used to eliminate error messages that are occasionally
239 produced by \"inc\".")
241 (defvar mh-scan-cur-msg-number-regexp "^\\( *[0-9]+\\+\\).*"
242 "This regular expression matches the current message.
244 It must match from the beginning of the line. Note that the
245 default setting of `mh-folder-font-lock-keywords' expects this
246 expression to contain at least one parenthesized expression which
247 matches the message number as in the default of
249 \"^\\\\( *[0-9]+\\\\+\\\\).*\".
251 This expression includes the leading space and current message
252 marker \"+\" within the parenthesis since it looks better to
253 highlight these items as well. The highlighting is done with the
254 face `mh-folder-cur-msg-number'. This regular expression should
255 be correct as it is needed by non-fontification functions. See
256 also `mh-note-cur'.")
258 (defvar mh-scan-date-regexp "\\([0-9][0-9]/[0-9][0-9]\\)"
259 "This regular expression matches a valid date.
261 It must not be anchored to the beginning or the end of the line.
262 Note that the default setting of `mh-folder-font-lock-keywords'
263 expects this expression to contain only one parenthesized
264 expression which matches the date field as in the default of
265 \"\\\\([0-9][0-9]/[0-9][0-9]\\\\)\"}. If this regular expression
266 is not correct, the date will not be highlighted with the face
269 (defvar mh-scan-rcpt-regexp "\\(To:\\)\\(..............\\)"
270 "This regular expression specifies the recipient in messages you sent.
272 Note that the default setting of `mh-folder-font-lock-keywords'
273 expects this expression to contain two parenthesized expressions.
274 The first is expected to match the \"To:\" that the default scan
275 format file generates. The second is expected to match the
276 recipient's name as in the default of
277 \"\\\\(To:\\\\)\\\\(..............\\\\)\". If this regular
278 expression is not correct, the \"To:\" string will not be
279 highlighted with the face `mh-folder-to' and the recipient will
280 not be highlighted with the face `mh-folder-address'")
282 (defvar mh-scan-body-regexp "\\(<<\\([^\n]+\\)?\\)"
283 "This regular expression matches the message body fragment.
285 Note that the default setting of `mh-folder-font-lock-keywords'
286 expects this expression to contain at least one parenthesized
287 expression which matches the body text as in the default of
288 \"\\\\(<<\\\\([^\\n]+\\\\)?\\\\)\". If this regular expression is
289 not correct, the body fragment will not be highlighted with the
290 face `mh-folder-body'.")
292 (defvar mh-scan-subject-regexp
293 "^ *[0-9]+........[ ]*...................\\([Rr][Ee]\\(\\[[0-9]+\\]\\)?:\\s-*\\)*\\([^<\n]*\\)"
294 "This regular expression matches the subject.
296 It must match from the beginning of the line. Note that the
297 default setting of `mh-folder-font-lock-keywords' expects this
298 expression to contain at least three parenthesized expressions.
299 The first is expected to match the \"Re:\" string, if any, and is
300 highlighted with the face `mh-folder-followup'. The second
301 matches an optional bracketed number after \"Re:\", such as in
302 \"Re[2]:\" (and is thus a sub-expression of the first expression)
303 and the third is expected to match the subject line itself which
304 is highlighted with the face `mh-folder-subject'. For example,
305 the default (broken on multiple lines for readability) is
307 ^ *[0-9]+........[ ]*...................
308 \\\\([Rr][Ee]\\\\(\\\\\\=[[0-9]+\\\\]\\\\)?:\\\\s-*\\\\)*
311 This regular expression should be correct as it is needed by
312 non-fontification functions.")
314 (defvar mh-scan-sent-to-me-sender-regexp
315 "^ *[0-9]+.\\([bct]\\).....[ ]*\\(..................\\)"
316 "This regular expression matches messages sent to us.
318 Note that the default setting of `mh-folder-font-lock-keywords'
319 expects this expression to contain at least two parenthesized
320 expressions. The first should match the fontification hint (see
321 `mh-scan-format-nmh') and the second should match the user name
324 ^ *[0-9]+.\\\\([bct]\\\\).....[ ]*\\\\(..................\\\\)
326 If this regular expression is not correct, the notation hints
327 will not be highlighted with the face
328 `mh-mh-folder-sent-to-me-hint' and the sender will not be
329 highlighted with the face `mh-folder-sent-to-me-sender'.")
333 (defvar mh-folder-font-lock-keywords
335 ;; Folders when displaying index buffer
337 '(0 'mh-index-folder))
338 ;; Marked for deletion
339 (list (concat mh-scan-deleted-msg-regexp ".*")
340 '(0 'mh-folder-deleted))
342 (list (concat mh-scan-refiled-msg-regexp ".*")
343 '(0 'mh-folder-refiled))
345 (list mh-scan-body-regexp
346 '(1 'mh-folder-body nil t))
348 '(mh-folder-font-lock-subject
349 (1 'mh-folder-followup append t)
350 (2 'mh-folder-subject append t))
351 ;; Current message number
352 (list mh-scan-cur-msg-number-regexp
353 '(1 'mh-folder-cur-msg-number))
355 (list mh-scan-good-msg-regexp
356 '(1 'mh-folder-msg-number))
358 (list mh-scan-date-regexp
359 '(1 'mh-folder-date))
360 ;; Messages from me (To:)
361 (list mh-scan-rcpt-regexp
363 '(2 'mh-folder-address))
365 (list mh-scan-sent-to-me-sender-regexp
366 '(1 'mh-folder-sent-to-me-hint)
367 '(2 'mh-folder-sent-to-me-sender)))
368 "Keywords (regular expressions) used to fontify the MH-Folder buffer.")
370 (defvar mh-scan-cmd-note-width 1
371 "Number of columns consumed by the cmd-note field in `mh-scan-format'.
373 This column will have one of the values: \" \", \"D\", \"^\", \"+\" and
374 where \" \" is the default value,
376 \"D\" is the `mh-note-deleted' character,
377 \"^\" is the `mh-note-refiled' character, and
378 \"+\" is the `mh-note-cur' character.")
380 (defvar mh-scan-destination-width 1
381 "Number of columns consumed by the destination field in `mh-scan-format'.
383 This column will have one of \" \", \"%\", \"-\", \"t\", \"c\", \"b\", or \"n\"
386 \" \" blank space is the default character.
387 \"%\" indicates that the message in in a named MH sequence.
388 \"-\" indicates that the message has been annotated with a replied field.
389 \"t\" indicates that the message contains mymbox in the To: field.
390 \"c\" indicates that the message contains mymbox in the Cc: field.
391 \"b\" indicates that the message contains mymbox in the Bcc: field.
392 \"n\" indicates that the message contains a Newsgroups: field.")
394 (defvar mh-scan-date-width 5
395 "Number of columns consumed by the date field in `mh-scan-format'.
396 This column will typically be of the form mm/dd.")
398 (defvar mh-scan-date-flag-width 1
399 "Number of columns consumed to flag (in)valid dates in `mh-scan-format'.
400 This column will have \" \" for valid and \"*\" for invalid or
403 (defvar mh-scan-from-mbox-width 17
404 "Number of columns consumed with the \"From:\" line in `mh-scan-format'.
405 This column will have a friendly name or e-mail address of the
406 originator, or a \"To: address\" for outgoing e-mail messages.")
408 (defvar mh-scan-from-mbox-sep-width 2
409 "Number of columns consumed by whitespace after from-mbox in `mh-scan-format'.
410 This column will only ever have spaces in it.")
412 (defvar mh-scan-field-destination-offset
413 (+ mh-scan-cmd-note-width)
414 "The offset from the `mh-cmd-note' for the destination column.")
416 (defvar mh-scan-field-from-start-offset
417 (+ mh-scan-cmd-note-width
418 mh-scan-destination-width
420 mh-scan-date-flag-width)
421 "The offset from the `mh-cmd-note' to find the start of \"From:\" address.")
423 (defvar mh-scan-field-from-end-offset
424 (+ mh-scan-field-from-start-offset mh-scan-from-mbox-width)
425 "The offset from the `mh-cmd-note' to find the end of \"From:\" address.")
427 (defvar mh-scan-field-subject-start-offset
428 (+ mh-scan-cmd-note-width
429 mh-scan-destination-width
431 mh-scan-date-flag-width
432 mh-scan-from-mbox-width
433 mh-scan-from-mbox-sep-width)
434 "The offset from the `mh-cmd-note' to find the start of the subject.")
436 (defun mh-folder-font-lock-subject (limit)
437 "Return MH-E scan subject strings to font-lock between point and LIMIT."
438 (if (not (re-search-forward mh-scan-subject-regexp limit t))
440 (if (match-beginning 1)
441 (set-match-data (list (match-beginning 1) (match-end 3)
442 (match-beginning 1) (match-end 3) nil nil))
443 (set-match-data (list (match-beginning 3) (match-end 3)
444 nil nil (match-beginning 3) (match-end 3))))
449 ;; Fontifify unseen mesages in bold.
451 (defmacro mh-generate-sequence-font-lock (seq prefix face)
452 "Generate the appropriate code to fontify messages in SEQ.
453 PREFIX is used to generate unique names for the variables and
454 functions defined by the macro. So a different prefix should be
455 provided for every invocation.
456 FACE is the font-lock face used to display the matching scan lines."
457 (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix)))
458 (func (intern (format "mh-folder-font-lock-%s" prefix))))
461 "Internal cache variable used for font-lock in MH-E.
462 Should only be non-nil through font-lock stepping, and nil once
463 font-lock is done highlighting.")
464 (make-variable-buffer-local ',cache)
467 "Return unseen message lines to font-lock between point and LIMIT."
468 (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq))))
469 (let ((cur-msg (mh-get-msg-num nil)))
472 ((>= (point) limit) ;Presumably at end of buffer
475 ((member cur-msg ,cache)
476 (let ((bpoint (progn (beginning-of-line)(point)))
477 (epoint (progn (forward-line 1)(point))))
478 (if (<= limit (point)) (setq ,cache nil))
479 (set-match-data (list bpoint epoint bpoint epoint))
482 ;; move forward one line at a time, checking each message
483 (while (and (= 0 (forward-line 1))
485 (not (member (mh-get-msg-num nil) ,cache))))
486 ;; Examine how we must have exited the loop...
487 (let ((cur-msg (mh-get-msg-num nil)))
488 (cond ((or (<= limit (point))
489 (not (member cur-msg ,cache)))
492 ((member cur-msg ,cache)
493 (let ((bpoint (progn (beginning-of-line) (point)))
494 (epoint (progn (forward-line 1) (point))))
495 (if (<= limit (point)) (setq ,cache nil))
497 (list bpoint epoint bpoint epoint))
500 (setq mh-folder-font-lock-keywords
501 (append mh-folder-font-lock-keywords
502 (list (list ',func (list 1 '',face 'prepend t))))))))
504 (mh-generate-sequence-font-lock mh-unseen-seq unseen bold)
505 (mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick)
509 ;;; Internal variables:
511 (defvar mh-last-destination nil
512 "Destination of last refile or write command.")
514 (defvar mh-last-destination-folder nil
515 "Destination of last refile command.")
517 (defvar mh-last-destination-write nil
518 "Destination of last write command.")
520 (defvar mh-folder-mode-map (make-keymap)
521 "Keymap for MH folders.")
523 (defvar mh-arrow-marker nil
524 "Marker for arrow display in fringe.")
526 (defvar mh-delete-list nil
527 "List of message numbers to delete.
528 This variable can be used by
529 `mh-before-commands-processed-hook'.")
531 (defvar mh-refile-list nil
532 "List of folder names in `mh-seq-list'.
533 This variable can be used by
534 `mh-before-commands-processed-hook'.")
536 (defvar mh-folders-changed nil
537 "Lists which folders were affected by deletes and refiles.
538 This list will always include the current folder
539 `mh-current-folder'. This variable can be used by
540 `mh-after-commands-processed-hook'.")
542 (defvar mh-next-direction 'forward
543 "Direction to move to next message.")
545 (defvar mh-view-ops ()
546 "Stack of operations that change the folder view.
547 These operations include narrowing or threading.")
549 (defvar mh-folder-view-stack ()
550 "Stack of previous folder views.")
552 (defvar mh-index-data nil
553 "Info about index search results.")
555 (defvar mh-index-previous-search nil)
556 (defvar mh-index-msg-checksum-map nil)
557 (defvar mh-index-checksum-origin-map nil)
558 (defvar mh-index-sequence-search-flag nil)
560 (defvar mh-first-msg-num nil
561 "Number of first message in buffer.")
563 (defvar mh-last-msg-num nil
564 "Number of last msg in buffer.")
566 (defvar mh-mode-line-annotation nil
567 "Message range displayed in buffer.")
569 (defvar mh-sequence-notation-history nil
570 "Remember original notation that is overwritten by `mh-note-seq'.")
572 (defvar mh-colors-available-flag nil
573 "Non-nil means colors are available.")
577 ;;; Macros and generic functions:
579 (defun mh-mapc (function list)
580 "Apply FUNCTION to each element of LIST for side effects only."
582 (funcall function (car list))
583 (setq list (cdr list))))
585 (defun mh-scan-format ()
586 "Return the output format argument for the scan program."
587 (if (equal mh-scan-format-file t)
588 (list "-format" (if (mh-variant-p 'nmh 'mu-mh)
589 (list (mh-update-scan-format
590 mh-scan-format-nmh mh-cmd-note))
591 (list (mh-update-scan-format
592 mh-scan-format-mh mh-cmd-note))))
593 (if (not (equal mh-scan-format-file nil))
594 (list "-form" mh-scan-format-file))))
601 (defun mh-rmail (&optional arg)
602 "Incorporate new mail with MH.
603 Scan an MH folder if ARG is non-nil.
605 This function is an entry point to MH-E, the Emacs interface to
610 (call-interactively 'mh-visit-folder)
611 (unless (get-buffer mh-inbox)
612 (mh-visit-folder mh-inbox (symbol-name mh-unseen-seq)))
616 (defun mh-nmail (&optional arg)
617 "Check for new mail in inbox folder.
618 Scan an MH folder if ARG is non-nil.
620 This function is an entry point to MH-E, the Emacs interface to
623 (mh-find-path) ; init mh-inbox
625 (call-interactively 'mh-visit-folder)
626 (mh-visit-folder mh-inbox)))
630 ;;; User executable MH-E commands:
632 (defun mh-delete-msg (range)
633 "Delete RANGE\\<mh-folder-mode-map>.
635 To mark a message for deletion, use this command. A \"D\" is
636 placed by the message in the scan window, and the next undeleted
637 message is displayed. If the previous command had been
638 \\[mh-previous-undeleted-msg], then the next message displayed is
639 the first undeleted message previous to the message just deleted.
640 Use \\[mh-next-undeleted-msg] to force subsequent
641 \\[mh-delete-msg] commands to move forward to the next undeleted
642 message after deleting the message under the cursor.
644 The hook `mh-delete-msg-hook' is called after you mark a message
645 for deletion. For example, a past maintainer of MH-E used this
646 once when he kept statistics on his mail usage.
648 Check the documentation of `mh-interactive-range' to see how
649 RANGE is read in interactive use."
650 (interactive (list (mh-interactive-range "Delete")))
651 (mh-delete-msg-no-motion range)
652 (if (looking-at mh-scan-deleted-msg-regexp)
655 (defun mh-delete-msg-no-motion (range)
656 "Delete RANGE, don't move to next message.
658 This command marks the RANGE for deletion but leaves the cursor
659 at the current message in case you wish to perform other
660 operations on the message.
662 Check the documentation of `mh-interactive-range' to see how
663 RANGE is read in interactive use."
664 (interactive (list (mh-interactive-range "Delete")))
665 (mh-iterate-on-range () range
666 (mh-delete-a-msg nil)))
668 (defun mh-execute-commands ()
669 "Process outstanding delete and refile requests\\<mh-folder-mode-map>.
671 If you've marked messages to be deleted or refiled and you want
672 to go ahead and delete or refile the messages, use this command.
673 Many MH-E commands that may affect the numbering of the
674 messages (such as \\[mh-rescan-folder] or \\[mh-pack-folder])
675 will ask if you want to process refiles or deletes first and then
676 either run this command for you or undo the pending refiles and
677 deletes, which are lost.
679 This function runs `mh-before-commands-processed-hook' before the
680 commands are processed and `mh-after-commands-processed-hook'
681 after the commands are processed."
683 (if mh-folder-view-stack (mh-widen t))
684 (mh-process-commands mh-current-folder)
686 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
687 (mh-make-folder-mode-line)
688 t) ; return t for write-file-functions
690 (defun mh-first-msg ()
691 "Display first message."
693 (goto-char (point-min))
694 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp)))
697 (defun mh-header-display ()
698 "Display message with all header fields\\<mh-folder-mode-map>.
700 Use the command \\[mh-show] to show the message normally again."
702 (and (not mh-showing-with-headers)
703 (or mh-mhl-format-file mh-clean-message-header-flag)
704 (mh-invalidate-show-buffer))
705 (let ((mh-decode-mime-flag nil)
706 (mh-mhl-format-file nil)
707 (mh-clean-message-header-flag nil))
709 (mh-in-show-buffer (mh-show-buffer)
710 (goto-char (point-min))
712 (setq mh-showing-with-headers t)))
714 (defun mh-inc-folder (&optional file folder)
715 "Incorporate new mail into a folder.
717 You can incorporate mail from any file into the current folder by
718 specifying a prefix argument; you'll be prompted for the name of
719 the FILE to use as well as the destination FOLDER
721 The hook `mh-inc-folder-hook' is run after incorporating new
724 Do not call this function from outside MH-E; use \\[mh-rmail]
726 (interactive (list (if current-prefix-arg
728 (read-file-name "inc mail from file: "
730 (if current-prefix-arg
731 (mh-prompt-for-folder "inc mail into" mh-inbox t))))
733 (setq folder mh-inbox))
734 (let ((threading-needed-flag nil))
735 (let ((config (current-window-configuration)))
736 (when (and mh-show-buffer (get-buffer mh-show-buffer))
737 (delete-windows-on mh-show-buffer))
738 (cond ((not (get-buffer folder))
739 (mh-make-folder folder)
740 (setq threading-needed-flag mh-show-threads-flag)
741 (setq mh-previous-window-config config))
742 ((not (eq (current-buffer) (get-buffer folder)))
743 (switch-to-buffer folder)
744 (setq mh-previous-window-config config))))
745 (mh-get-new-mail file)
746 (when (and threading-needed-flag
748 (goto-char (point-min))
749 (or (null mh-large-folder)
750 (not (equal (forward-line (1+ mh-large-folder)) 0))
751 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
755 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show))
756 (run-hooks 'mh-inc-folder-hook)))
758 (defun mh-last-msg ()
759 "Display last message."
761 (goto-char (point-max))
762 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp)))
766 (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag)
767 "Display next message.
769 This command can be given a prefix argument COUNT to specify how
770 many unread messages to skip.
772 In a program, pause for a second after printing message if we are
773 at the last undeleted message and optional argument
774 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
776 (setq mh-next-direction 'forward)
778 (cond ((re-search-forward mh-scan-good-msg-regexp nil t count)
782 (message "No more undeleted messages")
783 (if wait-after-complaining-flag (sit-for 1)))))
785 (defun mh-folder-from-address ()
786 "Derive folder name from sender.
788 The name of the folder is derived as follows:
790 a) The folder name associated with the first address found in
791 the list `mh-default-folder-list' is used. Each element in
792 this list contains a \"Check Recipient\" item. If this item is
793 turned on, then the address is checked against the recipient
794 instead of the sender. This is useful for mailing lists.
796 b) An alias prefixed by `mh-default-folder-prefix'
797 corresponding to the address is used. The prefix is used to
798 prevent clutter in your mail directory.
800 Return nil if a folder name was not derived, or if the variable
801 `mh-default-folder-must-exist-flag' is t and the folder does not
803 ;; Loop for all entries in mh-default-folder-list
805 (goto-char (point-min))
806 (re-search-forward "\n\n" nil 'limit)
807 (narrow-to-region (point-min) (point))
808 (let ((to/cc (concat (or (message-fetch-field "to") "") ", "
809 (or (message-fetch-field "cc") "")))
810 (from (or (message-fetch-field "from") ""))
813 (loop for list in mh-default-folder-list
814 when (string-match (nth 0 list) (if (nth 2 list) to/cc from))
818 ;; Make sure a result from `mh-default-folder-list' begins with "+"
819 ;; since 'mh-expand-file-name below depends on it
820 (when (and folder-name (not (eq (aref folder-name 0) ?+)))
821 (setq folder-name (concat "+" folder-name)))
823 ;; If not, is there an alias for the address?
824 (when (not folder-name)
825 (let* ((from-header (mh-extract-from-header-value))
826 (address (and from-header
827 (nth 1 (mail-extract-address-components
829 (alias (and address (mh-alias-address-to-alias address))))
832 (and alias (concat "+" mh-default-folder-prefix alias))))))
834 ;; If mh-default-folder-must-exist-flag set, check that folder exists.
836 (or (not mh-default-folder-must-exist-flag)
837 (file-exists-p (mh-expand-file-name folder-name))))
840 (defun mh-prompt-for-refile-folder ()
841 "Prompt the user for a folder in which the message should be filed.
842 The folder is returned as a string.
844 The default folder name is generated by the option
845 `mh-default-folder-for-message-function' if it is non-nil or
846 `mh-folder-from-address'."
847 (mh-prompt-for-folder
849 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t)))))
850 (if (null refile-file) ""
852 (set-buffer (get-buffer-create mh-temp-buffer))
854 (insert-file-contents refile-file)
855 (or (and mh-default-folder-for-message-function
856 (let ((buffer-file-name refile-file))
857 (funcall mh-default-folder-for-message-function)))
858 (mh-folder-from-address)
859 (and (eq 'refile (car mh-last-destination-folder))
860 (symbol-name (cdr mh-last-destination-folder)))
864 (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag)
865 "Refile (output) RANGE into FOLDER.
867 You are prompted for the folder name. Note that this command can also
868 be used to create folders. If you specify a folder that does not
869 exist, you will be prompted to create it.
871 The hook `mh-refile-msg-hook' is called after a message is marked to
874 Check the documentation of `mh-interactive-range' to see how RANGE is
875 read in interactive use.
877 In a program, the variables `mh-last-destination' and
878 `mh-last-destination-folder' are not updated if
879 DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil."
880 (interactive (list (mh-interactive-range "Refile")
881 (intern (mh-prompt-for-refile-folder))))
882 (unless dont-update-last-destination-flag
883 (setq mh-last-destination (cons 'refile folder)
884 mh-last-destination-folder mh-last-destination))
885 (mh-iterate-on-range () range
886 (mh-refile-a-msg nil folder))
887 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg)))
889 (defun mh-refile-or-write-again (range &optional interactive-flag)
890 "Repeat last output command.
892 If you are refiling several messages into the same folder, you
893 can use this command to repeat the last
894 refile (\\[mh-refile-msg]) or write (\\[mh-write-msg-to-file]).
897 Check the documentation of `mh-interactive-range' to see how RANGE is
898 read in interactive use.
900 In a program, a non-nil INTERACTIVE-FLAG means that the function was
901 called interactively."
902 (interactive (list (mh-interactive-range "Redo") t))
903 (if (null mh-last-destination)
904 (error "No previous refile or write"))
905 (cond ((eq (car mh-last-destination) 'refile)
906 (mh-refile-msg range (cdr mh-last-destination))
907 (message "Destination folder: %s" (cdr mh-last-destination)))
909 (mh-iterate-on-range msg range
910 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination)))
911 (mh-next-msg interactive-flag))))
914 "Quit the current MH-E folder.
916 When you want to quit using MH-E and go back to editing, you can use
917 this command. This buries the buffers of the current MH-E folder and
918 restores the buffers that were present when you first ran
919 \\[mh-rmail]. It also removes any MH-E working buffers whose name
920 begins with \" *mh-\" or \"*MH-E \". You can later restore your MH-E
921 session by selecting the \"+inbox\" buffer or by running \\[mh-rmail]
924 The two hooks `mh-before-quit-hook' and `mh-quit-hook' are called by
925 this function. The former one is called before the quit occurs, so you
926 might use it to perform any MH-E operations; you could perform some
927 query and abort the quit or call `mh-execute-commands', for example.
928 The latter is not run in an MH-E context, so you might use it to
929 modify the window setup."
931 (run-hooks 'mh-before-quit-hook)
932 (let ((show-buffer (get-buffer mh-show-buffer)))
934 (kill-buffer show-buffer)))
935 (mh-update-sequences)
936 (mh-destroy-postponed-handles)
937 (bury-buffer (current-buffer))
939 ;; Delete all MH-E temporary and working buffers.
940 (dolist (buffer (buffer-list))
941 (when (or (string-match "^ \\*mh-" (buffer-name buffer))
942 (string-match "^\\*MH-E " (buffer-name buffer)))
943 (kill-buffer buffer)))
945 (if mh-previous-window-config
946 (set-window-configuration mh-previous-window-config))
947 (run-hooks 'mh-quit-hook))
949 (defun mh-page-msg (&optional lines)
950 "Display next page in message.
952 You can give this command a prefix argument that specifies the
953 number of LINES to scroll. This command will also show the next
954 undeleted message if it is used at the bottom of a message."
957 (if mh-page-to-next-msg-flag
958 (if (equal mh-next-direction 'backward)
959 (mh-previous-undeleted-msg)
960 (mh-next-undeleted-msg))
961 (if (mh-in-show-buffer (mh-show-buffer)
962 (pos-visible-in-window-p (point-max)))
965 "End of message (Type %s to read %s undeleted message)"
966 (single-key-description last-input-event)
967 (if (equal mh-next-direction 'backward)
970 (setq mh-page-to-next-msg-flag t))
971 (scroll-other-window lines)))
974 (defun mh-previous-page (&optional lines)
975 "Display next page in message.
977 You can give this command a prefix argument that specifies the
978 number of LINES to scroll."
980 (mh-in-show-buffer (mh-show-buffer)
981 (scroll-down lines)))
983 (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag)
984 "Display previous message.
986 This command can be given a prefix argument COUNT to specify how
987 many unread messages to skip.
989 In a program, pause for a second after printing message if we are
990 at the last undeleted message and optional argument
991 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
993 (setq mh-next-direction 'backward)
995 (cond ((re-search-backward mh-scan-good-msg-regexp nil t count)
997 (t (message "No previous undeleted message")
998 (if wait-after-complaining-flag (sit-for 1)))))
1000 (defun mh-previous-unread-msg (&optional count)
1001 "Display previous unread message.
1003 This command can be given a prefix argument COUNT to specify how
1004 many unread messages to skip."
1007 (error "The function `mh-previous-unread-msg' expects positive argument"))
1008 (setq count (1- count))
1009 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list)))
1010 (cur-msg (mh-get-msg-num nil)))
1011 (cond ((and (not cur-msg) (not (bobp))
1012 ;; If we are at the end of the buffer back up one line and go
1013 ;; to unread message after that.
1016 (setq cur-msg (mh-get-msg-num nil)))
1018 ((or (null unread-sequence) (not cur-msg))
1019 ;; No unread message or there aren't any messages in buffer...
1020 (message "No more unread messages"))
1022 ;; Skip count messages...
1023 (while (and unread-sequence (>= (car unread-sequence) cur-msg))
1024 (setq unread-sequence (cdr unread-sequence)))
1026 (setq unread-sequence (cdr unread-sequence))
1027 (setq count (1- count)))
1028 (not (car unread-sequence)))
1029 (message "No more unread messages"))
1030 (t (loop for msg in unread-sequence
1031 when (mh-goto-msg msg t) return nil
1032 finally (message "No more unread messages"))))))
1034 (defun mh-goto-next-button (backward-flag &optional criterion)
1035 "Search for next button satisfying criterion.
1037 If BACKWARD-FLAG is non-nil search backward in the buffer for a mime
1039 If CRITERION is a function or a symbol which has a function binding
1040 then that function must return non-nil at the button we stop."
1041 (unless (or (and (symbolp criterion) (fboundp criterion))
1042 (functionp criterion))
1043 (setq criterion (lambda (x) t)))
1044 ;; Move to the next button in the buffer satisfying criterion
1045 (goto-char (or (save-excursion
1047 ;; Find point before current button
1048 (let ((point-before-current-button
1050 (while (get-text-property (point) 'mh-data)
1051 (unless (= (forward-line
1052 (if backward-flag 1 -1))
1055 (goto-char (point-min))
1056 (goto-char (point-max)))))
1058 ;; Skip over current button
1059 (while (and (get-text-property (point) 'mh-data)
1060 (not (if backward-flag (bobp) (eobp))))
1061 (forward-line (if backward-flag -1 1)))
1062 ;; Stop at next MIME button if any exists.
1065 (unless (= (forward-line
1066 (if backward-flag -1 1))
1069 (goto-char (point-max))
1070 (goto-char (point-min)))
1071 (beginning-of-line))
1073 point-before-current-button)
1074 (when (and (get-text-property (point) 'mh-data)
1075 (funcall criterion (point)))
1076 (return-from loop (point))))
1080 (defun mh-next-button (&optional backward-flag)
1081 "Go to the next button.
1083 If the end of the buffer is reached then the search wraps over to
1084 the start of the buffer.
1086 If an optional prefix argument BACKWARD-FLAG is given, the cursor
1087 will move to the previous button."
1088 (interactive (list current-prefix-arg))
1089 (unless mh-showing-mode
1091 (mh-in-show-buffer (mh-show-buffer)
1092 (mh-goto-next-button backward-flag)))
1094 (defun mh-prev-button ()
1095 "Go to the previous button.
1097 If the beginning of the buffer is reached then the search wraps
1098 over to the end of the buffer."
1102 (defun mh-folder-mime-action (part-index action include-security-flag)
1103 "Go to PART-INDEX and carry out ACTION.
1105 If PART-INDEX is nil then go to the next part in the buffer. The
1106 search for the next buffer wraps around if end of buffer is reached.
1107 If argument INCLUDE-SECURITY-FLAG is non-nil then include security
1108 info buttons when searching for a suitable parts."
1109 (unless mh-showing-mode
1111 (mh-in-show-buffer (mh-show-buffer)
1115 (let ((part (get-text-property p 'mh-part)))
1116 (and (integerp part) (= part part-index)))))
1118 (if include-security-flag
1119 (get-text-property p 'mh-data)
1120 (integerp (get-text-property p 'mh-part)))))))
1122 (cond ((and (get-text-property point 'mh-part)
1123 (or (null part-index)
1124 (= (get-text-property point 'mh-part) part-index)))
1126 ((and (get-text-property point 'mh-data)
1127 include-security-flag
1131 (mh-goto-next-button nil criterion)
1132 (if (= (point) point)
1133 (message "No matching MIME part found")
1134 (funcall action)))))))
1136 (defun mh-folder-toggle-mime-part (part-index)
1139 This command displays (or hides) the attachment associated with
1140 the button under the cursor. If the cursor is not located over a
1141 button, then the cursor first moves to the next button, wrapping
1142 to the beginning of the message if necessary. This command has
1143 the advantage over related commands of working from the MH-Folder
1146 You can also provide a numeric prefix argument PART-INDEX to view
1147 the attachment labeled with that number. If Emacs does not know
1148 how to display the attachment, then Emacs offers to save the
1149 attachment in a file."
1151 (when (consp part-index) (setq part-index (car part-index)))
1152 (mh-folder-mime-action part-index #'mh-press-button t))
1154 (defun mh-folder-inline-mime-part (part-index)
1155 "Show attachment verbatim.
1157 You can view the raw contents of an attachment with this command.
1158 This command displays (or hides) the contents of the attachment
1159 associated with the button under the cursor verbatim. If the
1160 cursor is not located over a button, then the cursor first moves
1161 to the next button, wrapping to the beginning of the message if
1164 You can also provide a numeric prefix argument PART-INDEX to view
1165 the attachment labeled with that number."
1167 (when (consp part-index) (setq part-index (car part-index)))
1168 (mh-folder-mime-action part-index #'mh-mime-inline-part nil))
1170 (defun mh-folder-save-mime-part (part-index)
1171 "Save (output) attachment.
1173 This command saves the attachment associated with the button under the
1174 cursor. If the cursor is not located over a button, then the cursor
1175 first moves to the next button, wrapping to the beginning of the
1176 message if necessary.
1178 You can also provide a numeric prefix argument PART-INDEX to save the
1179 attachment labeled with that number.
1181 This command prompts you for a filename and suggests a specific name
1182 if it is available."
1184 (when (consp part-index) (setq part-index (car part-index)))
1185 (mh-folder-mime-action part-index #'mh-mime-save-part nil))
1187 (defvar mh-thread-scan-line-map-stack)
1189 (defun mh-reset-threads-and-narrowing ()
1190 "Reset all variables pertaining to threads and narrowing.
1191 Also removes all content from the folder buffer."
1192 (setq mh-view-ops ())
1193 (setq mh-folder-view-stack ())
1194 (setq mh-thread-scan-line-map-stack ())
1195 (let ((buffer-read-only nil)) (erase-buffer)))
1197 (defun mh-rescan-folder (&optional range dont-exec-pending)
1198 "Rescan folder\\<mh-folder-mode-map>.
1200 This command is useful to grab all messages in your \"+inbox\" after
1201 processing your new mail for the first time. If you don't want to
1202 rescan the entire folder, this command will accept a RANGE. Check the
1203 documentation of `mh-interactive-range' to see how RANGE is read in
1206 This command will ask if you want to process refiles or deletes first
1207 and then either run \\[mh-execute-commands] for you or undo the
1208 pending refiles and deletes, which are lost.
1210 In a program, the processing of outstanding commands is not performed
1211 if DONT-EXEC-PENDING is non-nil."
1212 (interactive (list (if current-prefix-arg
1213 (mh-read-range "Rescan" mh-current-folder t nil t
1214 mh-interpret-number-as-range-flag)
1216 (setq mh-next-direction 'forward)
1217 (let ((threaded-flag (memq 'unthread mh-view-ops)))
1218 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending)
1219 (cond (threaded-flag (mh-toggle-threads))
1220 (mh-index-data (mh-index-insert-folder-headers)))))
1222 (defun mh-write-msg-to-file (message file no-header)
1223 "Append MESSAGE to end of FILE\\<mh-folder-mode-map>.
1225 You are prompted for the filename. If the file already exists,
1226 the message is appended to it. You can also write the message to
1227 the file without the header by specifying a prefix argument
1228 NO-HEADER. Subsequent writes to the same file can be made with
1229 the command \\[mh-refile-or-write-again]."
1231 (list (mh-get-msg-num t)
1232 (let ((default-dir (if (eq 'write (car mh-last-destination-write))
1233 (file-name-directory
1234 (car (cdr mh-last-destination-write)))
1235 default-directory)))
1236 (read-file-name (format "Save message%s in file: "
1237 (if current-prefix-arg " body" ""))
1239 (if (eq 'write (car mh-last-destination-write))
1240 (car (cdr mh-last-destination-write))
1241 (expand-file-name "mail.out" default-dir))))
1242 current-prefix-arg))
1243 (let ((msg-file-to-output (mh-msg-filename message))
1244 (output-file (mh-expand-file-name file)))
1245 (setq mh-last-destination (list 'write file (if no-header 'no-header))
1246 mh-last-destination-write mh-last-destination)
1248 (set-buffer (get-buffer-create mh-temp-buffer))
1250 (insert-file-contents msg-file-to-output)
1251 (goto-char (point-min))
1252 (if no-header (search-forward "\n\n"))
1253 (append-to-file (point) (point-max) output-file))))
1255 (defun mh-toggle-showing ()
1256 "Toggle between MH-Folder and MH-Folder Show modes.
1258 This command switches between MH-Folder mode and MH-Folder Show
1259 mode. MH-Folder mode turns off the associated show buffer so that
1260 you can perform operations on the messages quickly without
1261 reading them. This is an excellent way to prune out your junk
1262 mail or to refile a group of messages to another folder for later
1269 (defun mh-undo (range)
1270 "Undo pending deletes or refiles in RANGE.
1272 If you've deleted a message or refiled it, but changed your mind,
1273 you can cancel the action before you've executed it. Use this
1274 command to undo a refile on or deletion of a single message. You
1275 can also undo refiles and deletes for messages that are found in
1278 Check the documentation of `mh-interactive-range' to see how
1279 RANGE is read in interactive use."
1280 (interactive (list (mh-interactive-range "Undo")))
1281 (cond ((numberp range)
1282 (let ((original-position (point)))
1284 (while (not (or (looking-at mh-scan-deleted-msg-regexp)
1285 (looking-at mh-scan-refiled-msg-regexp)
1286 (and (eq mh-next-direction 'forward) (bobp))
1287 (and (eq mh-next-direction 'backward)
1288 (save-excursion (forward-line) (eobp)))))
1289 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
1290 (if (or (looking-at mh-scan-deleted-msg-regexp)
1291 (looking-at mh-scan-refiled-msg-regexp))
1293 (mh-undo-msg (mh-get-msg-num t))
1295 (goto-char original-position)
1296 (error "Nothing to undo"))))
1297 (t (mh-iterate-on-range () range
1298 (mh-undo-msg nil))))
1299 (if (not (mh-outstanding-commands-p))
1300 (mh-set-folder-modified-p nil)))
1303 (defun mh-folder-line-matches-show-buffer-p ()
1304 "Return t if the message under point in folder-mode is in the show buffer.
1305 Return nil in any other circumstance (no message under point, no
1306 show buffer, the message in the show buffer doesn't match."
1307 (and (eq major-mode 'mh-folder-mode)
1308 (mh-get-msg-num nil)
1310 (get-buffer mh-show-buffer)
1311 (buffer-file-name (get-buffer mh-show-buffer))
1312 (string-match ".*/\\([0-9]+\\)$"
1313 (buffer-file-name (get-buffer mh-show-buffer)))
1315 (match-string 1 (buffer-file-name (get-buffer mh-show-buffer)))
1316 (int-to-string (mh-get-msg-num nil)))))
1318 (eval-when-compile (require 'gnus))
1320 (defmacro mh-macro-expansion-time-gnus-version ()
1321 "Return Gnus version available at macro expansion time.
1322 The macro evaluates the Gnus version at macro expansion time. If
1323 MH-E was compiled then macro expansion happens at compile time."
1326 (defun mh-run-time-gnus-version ()
1327 "Return Gnus version available at run time."
1332 (defun mh-version ()
1333 "Display version information about MH-E and the MH mail handling system."
1335 (set-buffer (get-buffer-create mh-info-buffer))
1338 (insert "MH-E " mh-version "\n\n")
1339 ;; MH-E compilation details.
1340 (insert "MH-E compilation details:\n")
1341 (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version)))
1342 (gnus-compiled-version (if compiled-mhe
1343 (mh-macro-expansion-time-gnus-version)
1345 (insert " Byte compiled:\t\t" (if compiled-mhe "yes" "no") "\n"
1346 " Gnus (compile-time):\t" gnus-compiled-version "\n"
1347 " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
1349 (insert (emacs-version) "\n\n")
1351 (if mh-variant-in-use
1352 (insert mh-variant-in-use "\n"
1353 " mh-progs:\t" mh-progs "\n"
1354 " mh-lib:\t" mh-lib "\n"
1355 " mh-lib-progs:\t" mh-lib-progs "\n\n")
1356 (insert "No MH variant detected\n"))
1359 (call-process "uname" nil t nil "-a")
1361 (goto-char (point-min))
1362 (display-buffer mh-info-buffer))
1364 (defun mh-parse-flist-output-line (line &optional current-folder)
1365 "Parse LINE to generate folder name, unseen messages and total messages.
1366 If CURRENT-FOLDER is non-nil then it contains the current folder
1367 name and it is used to avoid problems in corner cases involving
1368 folders whose names end with a '+' character."
1371 (goto-char (point-max))
1372 (let (folder unseen total p)
1373 (when (search-backward " out of " (point-min) t)
1374 (setq total (read-from-string
1375 (buffer-substring-no-properties
1376 (match-end 0) (line-end-position))))
1377 (when (search-backward " in sequence " (point-min) t)
1379 (when (search-backward " has " (point-min) t)
1380 (setq unseen (read-from-string (buffer-substring-no-properties
1382 (while (eq (char-after) ? )
1384 (setq folder (buffer-substring-no-properties
1385 (point-min) (1+ (point))))
1386 (when (and (equal (aref folder (1- (length folder))) ?+)
1387 (equal current-folder folder))
1388 (setq folder (substring folder 0 (1- (length folder)))))
1389 (values (format "+%s" folder) (car unseen) (car total))))))))
1391 (defun mh-folder-size-folder (folder)
1392 "Find size of FOLDER using \"folder\"."
1394 (let ((u (length (cdr (assoc mh-unseen-seq
1395 (mh-read-folder-sequences folder nil))))))
1396 (call-process (expand-file-name "folder" mh-progs) nil t nil
1397 "-norecurse" folder)
1398 (goto-char (point-min))
1399 (if (re-search-forward " has \\([0-9]+\\) " nil t)
1400 (values (car (read-from-string (match-string 1))) u folder)
1401 (values 0 u folder)))))
1403 (defun mh-folder-size-flist (folder)
1404 "Find size of FOLDER using \"flist\"."
1406 (call-process (expand-file-name "flist" mh-progs) nil t nil "-showzero"
1407 "-norecurse" folder "-sequence" (symbol-name mh-unseen-seq))
1408 (goto-char (point-min))
1409 (multiple-value-bind (folder unseen total)
1410 (mh-parse-flist-output-line
1411 (buffer-substring (point) (line-end-position)))
1412 (values total unseen folder))))
1414 (defun mh-folder-size (folder)
1415 "Find size of FOLDER."
1416 (if mh-flists-present-flag
1417 (mh-folder-size-flist folder)
1418 (mh-folder-size-folder folder)))
1420 (defun mh-visit-folder (folder &optional range index-data)
1423 When you want to read the messages that you have refiled into folders,
1424 use this command to visit the folder. You are prompted for the folder
1427 The folder buffer will show just unseen messages if there are any;
1428 otherwise, it will show all the messages in the buffer as long there
1429 are fewer than `mh-large-folder' messages. If there are more, then you
1430 are prompted for a range of messages to scan.
1432 You can provide a prefix argument in order to specify a RANGE of
1433 messages to show when you visit the folder. In this case, regions are
1434 not used to specify the range and `mh-large-folder' is ignored. Check
1435 the documentation of `mh-interactive-range' to see how RANGE is read
1438 Note that this command can also be used to create folders. If you
1439 specify a folder that does not exist, you will be prompted to create
1442 Do not call this function from outside MH-E; use \\[mh-rmail] instead.
1444 If, in a program, RANGE is nil (the default), then all messages in
1445 FOLDER are displayed. If an index buffer is being created then
1446 INDEX-DATA is used to initialize the index buffer specific data
1448 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t)))
1450 (mh-read-range "Scan" folder-name t nil
1452 mh-interpret-number-as-range-flag))))
1453 (let ((config (current-window-configuration))
1454 (current-buffer (current-buffer))
1455 (threaded-view-flag mh-show-threads-flag))
1456 (delete-other-windows)
1458 (when (get-buffer folder)
1460 (setq threaded-view-flag (memq 'unthread mh-view-ops))))
1462 (mh-make-folder folder)
1463 (setq mh-index-data (car index-data)
1464 mh-index-msg-checksum-map (make-hash-table :test #'equal)
1465 mh-index-checksum-origin-map (make-hash-table :test #'equal))
1466 (mh-index-update-maps folder (cadr index-data))
1467 (mh-index-create-sequences))
1468 (mh-scan-folder folder (or range "all"))
1469 (cond ((and threaded-view-flag
1471 (goto-char (point-min))
1472 (or (null mh-large-folder)
1473 (not (equal (forward-line (1+ mh-large-folder)) 0))
1474 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
1476 (mh-toggle-threads))
1478 (mh-index-insert-folder-headers)))
1479 (unless (eq current-buffer (current-buffer))
1480 (setq mh-previous-window-config config)))
1484 (defun mh-update-sequences ()
1485 "Flush MH-E's state out to MH.
1487 This function updates the sequence specified by your
1488 \"Unseen-Sequence:\" profile component, \"cur\", and the sequence
1489 listed by the `mh-tick-seq' option which is \"tick\" by default.
1490 The message at the cursor is used for \"cur\"."
1492 ;; mh-update-sequences is the opposite of mh-read-folder-sequences,
1493 ;; which updates MH-E's state from MH.
1494 (let ((folder-set (mh-update-unseen))
1495 (new-cur (mh-get-msg-num nil)))
1497 (let ((seq-entry (mh-find-seq 'cur)))
1498 (mh-remove-cur-notation)
1500 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq
1501 (mh-define-sequence 'cur (list new-cur))
1503 (if (looking-at mh-scan-good-msg-regexp)
1507 ;; psg - mh-current-folder is nil if mh-summary-height < 4 !
1508 ;; So I added this sanity check.
1509 (if (stringp mh-current-folder)
1510 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast")
1511 (mh-exec-cmd-quiet t "folder" "-fast")))))))
1515 ;;; Support routines.
1517 (defun mh-delete-a-msg (message)
1519 If MESSAGE is nil then the message at point is deleted.
1520 The hook `mh-delete-msg-hook' is called after you mark a message
1521 for deletion. For example, a past maintainer of MH-E used this
1522 once when he kept statistics on his mail usage."
1524 (if (numberp message)
1525 (mh-goto-msg message nil t)
1527 (setq message (mh-get-msg-num t)))
1528 (if (looking-at mh-scan-refiled-msg-regexp)
1529 (error "Message %d is refiled; undo refile before deleting" message))
1530 (if (looking-at mh-scan-deleted-msg-regexp)
1532 (mh-set-folder-modified-p t)
1533 (setq mh-delete-list (cons message mh-delete-list))
1534 (mh-notate nil mh-note-deleted mh-cmd-note)
1535 (run-hooks 'mh-delete-msg-hook))))
1537 (defun mh-refile-a-msg (message folder)
1538 "Refile MESSAGE in FOLDER.
1539 If MESSAGE is nil then the message at point is refiled.
1540 Folder is a symbol, not a string.
1541 The hook `mh-refile-msg-hook' is called after a message is marked to
1544 (if (numberp message)
1545 (mh-goto-msg message nil t)
1547 (setq message (mh-get-msg-num t)))
1548 (cond ((looking-at mh-scan-deleted-msg-regexp)
1549 (error "Message %d is deleted; undo delete before moving" message))
1550 ((looking-at mh-scan-refiled-msg-regexp)
1552 (format "Message %d already refiled; copy to %s as well? "
1554 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
1555 "-src" mh-current-folder
1556 (symbol-name folder))
1557 (message "Message not copied")))
1559 (mh-set-folder-modified-p t)
1560 (cond ((null (assoc folder mh-refile-list))
1561 (push (list folder message) mh-refile-list))
1562 ((not (member message (cdr (assoc folder mh-refile-list))))
1563 (push message (cdr (assoc folder mh-refile-list)))))
1564 (mh-notate nil mh-note-refiled mh-cmd-note)
1565 (run-hooks 'mh-refile-msg-hook)))))
1567 (defun mh-next-msg (&optional wait-after-complaining-flag)
1568 "Move backward or forward to the next undeleted message in the buffer.
1569 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and
1570 we are at the last message, then wait for a second after telling
1571 the user that there aren't any more unread messages."
1572 (if (eq mh-next-direction 'forward)
1573 (mh-next-undeleted-msg 1 wait-after-complaining-flag)
1574 (mh-previous-undeleted-msg 1 wait-after-complaining-flag)))
1576 (defun mh-next-unread-msg (&optional count)
1577 "Display next unread message.
1579 This command can be given a prefix argument COUNT to specify how
1580 many unread messages to skip."
1583 (error "The function `mh-next-unread-msg' expects positive argument"))
1584 (setq count (1- count))
1585 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list))))
1586 (cur-msg (mh-get-msg-num nil)))
1587 (cond ((and (not cur-msg) (not (bobp))
1588 ;; If we are at the end of the buffer back up one line and go
1589 ;; to unread message after that.
1592 (setq cur-msg (mh-get-msg-num nil)))
1594 ((or (null unread-sequence) (not cur-msg))
1595 ;; No unread message or there aren't any messages in buffer...
1596 (message "No more unread messages"))
1599 (while (and unread-sequence (>= cur-msg (car unread-sequence)))
1600 (setq unread-sequence (cdr unread-sequence)))
1602 (setq unread-sequence (cdr unread-sequence))
1603 (setq count (1- count)))
1604 (not (car unread-sequence)))
1605 (message "No more unread messages"))
1606 (t (loop for msg in unread-sequence
1607 when (mh-goto-msg msg t) return nil
1608 finally (message "No more unread messages"))))))
1610 (defun mh-set-scan-mode ()
1611 "Display the scan listing buffer, but do not show a message."
1612 (if (get-buffer mh-show-buffer)
1613 (delete-windows-on mh-show-buffer))
1615 (force-mode-line-update)
1616 (if mh-recenter-summary-flag
1619 (defun mh-undo-msg (msg)
1620 "Undo the deletion or refile of one MSG.
1621 If MSG is nil then act on the message at point"
1624 (mh-goto-msg msg t t)
1626 (setq msg (mh-get-msg-num t)))
1627 (cond ((memq msg mh-delete-list)
1628 (setq mh-delete-list (delq msg mh-delete-list)))
1630 (dolist (folder-msg-list mh-refile-list)
1631 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list))))
1632 (setq mh-refile-list (loop for x in mh-refile-list
1633 unless (null (cdr x)) collect x))))
1634 (mh-notate nil ? mh-cmd-note)))
1638 ;;; The folder data abstraction.
1640 (defvar mh-index-data-file ".mhe_index"
1641 "MH-E specific file where index seach info is stored.")
1643 (defun mh-make-folder (name)
1644 "Create a new mail folder called NAME.
1645 Make it the current folder."
1646 (switch-to-buffer name)
1647 (setq buffer-read-only nil)
1649 (if mh-adaptive-cmd-note-flag
1650 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name))))
1651 (setq buffer-read-only t)
1653 (mh-set-folder-modified-p nil)
1654 (setq buffer-file-name mh-folder-filename)
1655 (when (and (not mh-index-data)
1656 (file-exists-p (concat buffer-file-name mh-index-data-file)))
1657 (mh-index-read-data))
1658 (mh-make-folder-mode-line))
1660 ;; Ensure new buffers won't get this mode if default-major-mode is nil.
1661 (put 'mh-folder-mode 'mode-class 'special)
1665 ;;; Build mh-folder-mode menu
1667 ;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
1668 ;; Menus for folder mode: folder, message, sequence (in that order)
1669 ;; folder-mode "Sequence" menu
1671 mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence."
1673 ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)]
1674 ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)]
1675 ["Delete Message from Sequence..." mh-delete-msg-from-seq
1676 (mh-get-msg-num nil)]
1677 ["List Sequences in Folder..." mh-list-sequences t]
1678 ["Delete Sequence..." mh-delete-seq t]
1679 ["Narrow to Sequence..." mh-narrow-to-seq t]
1680 ["Widen from Sequence" mh-widen mh-folder-view-stack]
1682 ["Narrow to Subject Sequence" mh-narrow-to-subject t]
1683 ["Narrow to Tick Sequence" mh-narrow-to-tick
1684 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))]
1685 ["Delete Rest of Same Subject" mh-delete-subject t]
1686 ["Toggle Tick Mark" mh-toggle-tick t]
1688 ["Push State Out to MH" mh-update-sequences t]))
1690 ;; folder-mode "Message" menu
1692 mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message."
1694 ["Show Message" mh-show (mh-get-msg-num nil)]
1695 ["Show Message with Header" mh-header-display (mh-get-msg-num nil)]
1696 ["Next Message" mh-next-undeleted-msg t]
1697 ["Previous Message" mh-previous-undeleted-msg t]
1698 ["Go to First Message" mh-first-msg t]
1699 ["Go to Last Message" mh-last-msg t]
1700 ["Go to Message by Number..." mh-goto-msg t]
1701 ["Modify Message" mh-modify t]
1702 ["Delete Message" mh-delete-msg (mh-get-msg-num nil)]
1703 ["Refile Message" mh-refile-msg (mh-get-msg-num nil)]
1704 ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)]
1705 ["Execute Delete/Refile" mh-execute-commands
1706 (mh-outstanding-commands-p)]
1708 ["Compose a New Message" mh-send t]
1709 ["Reply to Message..." mh-reply (mh-get-msg-num nil)]
1710 ["Forward Message..." mh-forward (mh-get-msg-num nil)]
1711 ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)]
1712 ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)]
1713 ["Re-edit a Bounced Message" mh-extract-rejected-mail t]
1715 ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)]
1716 ["Print Message" mh-print-msg (mh-get-msg-num nil)]
1717 ["Write Message to File..." mh-write-msg-to-file
1718 (mh-get-msg-num nil)]
1719 ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)]
1720 ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)]
1721 ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)]))
1723 ;; folder-mode "Folder" menu
1725 mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder."
1727 ["Incorporate New Mail" mh-inc-folder t]
1728 ["Toggle Show/Folder" mh-toggle-showing t]
1729 ["Execute Delete/Refile" mh-execute-commands
1730 (mh-outstanding-commands-p)]
1731 ["Rescan Folder" mh-rescan-folder t]
1732 ["Thread Folder" mh-toggle-threads
1733 (not (memq 'unthread mh-view-ops))]
1734 ["Pack Folder" mh-pack-folder t]
1735 ["Sort Folder" mh-sort-folder t]
1737 ["List Folders" mh-list-folders t]
1738 ["Visit a Folder..." mh-visit-folder t]
1739 ["View New Messages" mh-index-new-messages t]
1740 ["Search a Folder..." mh-search-folder t]
1741 ["Indexed Search..." mh-index-search t]
1743 ["Quit MH-E" mh-quit t]))
1747 (defmacro mh-remove-xemacs-horizontal-scrollbar ()
1748 "Get rid of the horizontal scrollbar that XEmacs insists on putting in."
1749 (when mh-xemacs-flag
1750 `(if (and (featurep 'scrollbar)
1751 (fboundp 'set-specifier))
1752 (set-specifier horizontal-scrollbar-visible-p nil
1753 (cons (current-buffer) nil)))))
1755 (defmacro mh-write-file-functions-compat ()
1756 "Return `write-file-functions' if it exists.
1757 Otherwise return `local-write-file-hooks'. This macro exists
1758 purely for compatibility. The former symbol is used in Emacs 21.4
1759 onward while the latter is used in previous versions and XEmacs."
1760 (if (boundp 'write-file-functions)
1761 ''write-file-functions ;Emacs 21.4
1762 ''local-write-file-hooks)) ;<Emacs 21.4, XEmacs
1764 ;; Avoid compiler warnings in non-bleeding edge versions of Emacs.
1766 (defvar tool-bar-mode)
1767 (defvar tool-bar-map)
1768 (defvar desktop-save-buffer)) ;Emacs 21.4
1770 ;; Register mh-folder-mode as supporting which-function-mode...
1771 (load "which-func" t t)
1772 (when (and (boundp 'which-func-modes)
1773 (not (member 'mh-folder-mode which-func-modes)))
1774 (push 'mh-folder-mode which-func-modes))
1776 (defvar mh-folder-buttons-init-flag nil)
1778 ;; Autoload cookie needed by desktop.el
1780 (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder"
1781 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
1783 You can show the message the cursor is pointing to, and step through
1784 the messages. Messages can be marked for deletion or refiling into
1785 another folder; these commands are executed all at once with a
1788 Options that control this mode can be changed with
1789 \\[customize-group]; specify the \"mh\" group. In particular, please
1790 see the `mh-scan-format-file' option if you wish to modify scan's
1793 When a folder is visited, the hook `mh-folder-mode-hook' is run.
1797 Many commands that operate on individual messages, such as
1798 `mh-forward' or `mh-refile-msg' take a RANGE argument. This argument
1799 can be used in several ways.
1801 If you provide the prefix argument (\\[universal-argument]) to
1802 these commands, then you will be prompted for the message range.
1803 This can be any valid MH range which can include messages,
1804 sequences, and the abbreviations (described in the mh(1) man
1808 Indicates all messages in the range <num1> to <num2>, inclusive.
1809 The range must be nonempty.
1814 Up to N messages beginning with (or ending with) message num. Num
1815 may be any of the predefined symbols: first, prev, cur, next or
1822 The first, previous, next or last messages, if they exist.
1825 All of the messages.
1827 For example, a range that shows all of these things is `1 2 3
1828 5-10 last:5 unseen'.
1830 If the option `transient-mark-mode' is set to t and you set a
1831 region in the MH-Folder buffer, then the MH-E command will
1832 perform the operation on all messages in that region.
1834 \\{mh-folder-mode-map}"
1836 (unless mh-folder-buttons-init-flag
1837 (mh-tool-bar-folder-buttons-init)
1838 (setq mh-folder-buttons-init-flag t)))
1839 (make-local-variable 'font-lock-defaults)
1840 (setq font-lock-defaults '(mh-folder-font-lock-keywords t))
1841 (make-local-variable 'desktop-save-buffer)
1842 (setq desktop-save-buffer t)
1844 'mh-colors-available-flag (mh-colors-available-p)
1845 ; Do we have colors available
1846 'mh-current-folder (buffer-name) ; Name of folder, a string
1847 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
1848 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
1849 (file-name-as-directory (mh-expand-file-name (buffer-name)))
1850 'mh-display-buttons-for-inline-parts-flag
1851 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to
1853 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed
1854 'overlay-arrow-position nil ; Allow for simultaneous display in
1855 'overlay-arrow-string ">" ; different MH-E buffers.
1856 'mh-showing-mode nil ; Show message also?
1857 'mh-delete-list nil ; List of msgs nums to delete
1858 'mh-refile-list nil ; List of folder names in mh-seq-list
1859 'mh-seq-list nil ; Alist of (seq . msgs) nums
1860 'mh-seen-list nil ; List of displayed messages
1861 'mh-next-direction 'forward ; Direction to move to next message
1862 'mh-view-ops () ; Stack that keeps track of the order
1863 ; in which narrowing/threading has been
1865 'mh-folder-view-stack () ; Stack of previous views of the
1867 'mh-index-data nil ; If the folder was created by a call
1868 ; to mh-index-search this contains info
1869 ; about the search results.
1870 'mh-index-previous-search nil ; Previous folder and search-regexp
1871 'mh-index-msg-checksum-map nil ; msg -> checksum map
1872 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg )
1873 'mh-index-sequence-search-flag nil ; folder resulted from sequence search
1874 'mh-first-msg-num nil ; Number of first msg in buffer
1875 'mh-last-msg-num nil ; Number of last msg in buffer
1876 'mh-msg-count nil ; Number of msgs in buffer
1877 'mh-mode-line-annotation nil ; Indicates message range
1878 'mh-sequence-notation-history (make-hash-table)
1879 ; Remember what is overwritten by
1881 'imenu-create-index-function 'mh-index-create-imenu-index
1882 ; Setup imenu support
1883 'mh-previous-window-config nil) ; Previous window configuration
1884 (mh-remove-xemacs-horizontal-scrollbar)
1885 (setq truncate-lines t)
1887 (setq buffer-offer-save t)
1888 (mh-make-local-hook (mh-write-file-functions-compat))
1889 (add-hook (mh-write-file-functions-compat) 'mh-execute-commands nil t)
1890 (make-local-variable 'revert-buffer-function)
1891 (make-local-variable 'hl-line-mode) ; avoid pollution
1892 (mh-funcall-if-exists hl-line-mode 1)
1893 (setq revert-buffer-function 'mh-undo-folder)
1894 (or (assq 'mh-showing-mode minor-mode-alist)
1895 (setq minor-mode-alist
1896 (cons '(mh-showing-mode " Show") minor-mode-alist)))
1897 (easy-menu-add mh-folder-sequence-menu)
1898 (easy-menu-add mh-folder-message-menu)
1899 (easy-menu-add mh-folder-folder-menu)
1900 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)
1901 (mh-funcall-if-exists mh-tool-bar-init :folder)
1902 (if (and mh-xemacs-flag
1903 font-lock-auto-fontify)
1904 (turn-on-font-lock))) ; Force font-lock in XEmacs.
1906 (defun mh-toggle-mime-buttons ()
1907 "Toggle option `mh-display-buttons-for-inline-parts-flag'."
1909 (setq mh-display-buttons-for-inline-parts-flag
1910 (not mh-display-buttons-for-inline-parts-flag))
1913 (defun mh-colors-available-p ()
1914 "Check if colors are available in the Emacs being used."
1917 (or (ignore-errors (mh-funcall-if-exists display-color-cells))
1918 (ignore-errors (mh-funcall-if-exists
1919 x-display-color-cells)))))
1920 (and (numberp color-cells) (>= color-cells 8)))))
1922 (defun mh-colors-in-use-p ()
1923 "Check if colors are being used in the folder buffer."
1924 (and mh-colors-available-flag font-lock-mode))
1926 (defun mh-make-local-vars (&rest pairs)
1927 "Initialize local variables according to the variable-value PAIRS."
1930 (set (make-local-variable (car pairs)) (car (cdr pairs)))
1931 (setq pairs (cdr (cdr pairs)))))
1933 (defun mh-restore-desktop-buffer (desktop-buffer-file-name
1935 desktop-buffer-misc)
1936 "Restore an MH folder buffer specified in a desktop file.
1937 When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the
1938 file name to visit, DESKTOP-BUFFER-NAME holds the desired buffer
1939 name, and DESKTOP-BUFFER-MISC holds a list of miscellaneous info
1940 used by the `desktop-buffer-handlers' functions."
1942 (mh-visit-folder desktop-buffer-name)
1945 ;; desktop-buffer-mode-handlers appeared in Emacs 22.
1946 (if (fboundp 'desktop-buffer-mode-handlers)
1947 (add-to-list 'desktop-buffer-mode-handlers
1948 '(mh-folder-mode . mh-restore-desktop-buffer)))
1950 (defun mh-scan-folder (folder range &optional dont-exec-pending)
1951 "Scan FOLDER over RANGE.
1953 After the scan is performed, switch to the buffer associated with
1956 Check the documentation of `mh-interactive-range' to see how RANGE is
1957 read in interactive use.
1959 The processing of outstanding commands is not performed if
1960 DONT-EXEC-PENDING is non-nil."
1961 (when (stringp range)
1962 (setq range (delete "" (split-string range "[ \t\n]"))))
1963 (cond ((null (get-buffer folder))
1964 (mh-make-folder folder))
1966 (unless dont-exec-pending
1967 (mh-process-or-undo-commands folder)
1968 (mh-reset-threads-and-narrowing))
1969 (switch-to-buffer folder)))
1970 (mh-regenerate-headers range)
1971 (if (zerop (buffer-size))
1972 (if (equal range "all")
1973 (message "Folder %s is empty" folder)
1974 (message "No messages in %s, range %s" folder range))
1976 (when (mh-outstanding-commands-p)
1977 (mh-notate-deleted-and-refiled)))
1979 (defun mh-msg-num-width-to-column (width)
1980 "Return the column for notations given message number WIDTH.
1981 Note that columns in Emacs start with 0.
1983 If `mh-scan-format-file' is set to \"Use MH-E scan Format\" this
1984 means that either `mh-scan-format-mh' or `mh-scan-format-nmh' are
1985 in use. This function therefore assumes that the first column is
1986 empty (to provide room for the cursor), the following WIDTH
1987 columns contain the message number, and the column for notations
1989 (if (eq mh-scan-format-file t)
1991 (error "%s %s" "Can't call `mh-msg-num-width-to-column' when"
1992 "`mh-scan-format-file' is not set to \"Use MH-E scan Format\"")))
1994 (defun mh-set-cmd-note (column)
1995 "Set `mh-cmd-note' to COLUMN.
1996 Note that columns in Emacs start with 0."
1997 (setq mh-cmd-note column))
1999 (defun mh-regenerate-headers (range &optional update)
2000 "Scan folder over RANGE.
2001 If UPDATE, append the scan lines, otherwise replace."
2002 (let ((folder mh-current-folder)
2003 (range (if (and range (atom range)) (list range) range))
2005 (message "Scanning %s..." folder)
2006 (mh-remove-all-notation)
2007 (with-mh-folder-updating (nil)
2009 (goto-char (point-max))
2010 (delete-region (point-min) (point-max))
2011 (if mh-adaptive-cmd-note-flag
2012 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width
2014 (setq scan-start (point))
2015 (apply #'mh-exec-cmd-output
2018 "-noclear" "-noheader"
2019 "-width" (window-width)
2021 (goto-char scan-start)
2022 (cond ((looking-at "scan: no messages in")
2023 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines
2024 ((looking-at (if (mh-variant-p 'mu-mh)
2025 "scan: message set .* does not exist"
2026 "scan: bad message list "))
2027 (keep-lines mh-scan-valid-regexp))
2028 ((looking-at "scan: ")) ; Keep error messages
2030 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines
2031 (setq mh-seq-list (mh-read-folder-sequences folder nil))
2032 (mh-notate-user-sequences)
2034 (setq mh-mode-line-annotation
2035 (if (equal range '("all"))
2037 mh-partial-folder-mode-line-annotation)))
2038 (mh-make-folder-mode-line))
2039 (message "Scanning %s...done" folder)))
2041 (defun mh-generate-new-cmd-note (folder)
2042 "Fix the `mh-cmd-note' value for this FOLDER.
2044 After doing an `mh-get-new-mail' operation in this FOLDER, at least
2045 one line that looks like a truncated message number was found.
2047 Remove the text added by the last `mh-inc' command. It should be the
2048 messages cur-last. Call `mh-set-cmd-note', adjusting the notation
2049 column with the width of the largest message number in FOLDER.
2051 Reformat the message number width on each line in the buffer and trim
2052 the line length to fit in the window.
2054 Rescan the FOLDER in the range cur-last in order to display the
2055 messages that were removed earlier. They should all fit in the scan
2056 line now with no message truncation."
2058 (let ((maxcol (1- (window-width)))
2059 (old-cmd-note mh-cmd-note)
2062 ;; Nuke all of the lines just added by the last inc
2063 (delete-char (- (point-max) (point)))
2064 ;; Update the current buffer to reflect the new mh-cmd-note
2065 ;; value needed to display messages.
2066 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder)))
2067 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d"))
2068 ;; Cleanup the messages that are in the buffer right now
2069 (goto-char (point-min))
2070 (cond ((memq 'unthread mh-view-ops)
2071 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note)))
2072 (t (while (re-search-forward mh-scan-msg-number-regexp nil 0 1)
2073 ;; reformat the number to fix in mh-cmd-note columns
2074 (setq msgnum (string-to-number
2076 (match-beginning 1) (match-end 1))))
2077 (replace-match (format mh-cmd-note-fmt msgnum))
2078 ;; trim the line to fix in the window
2080 (let ((eol (point)))
2081 (move-to-column maxcol)
2082 (if (<= (point) eol)
2083 (delete-char (- eol (point))))))))
2084 ;; now re-read the lost messages
2085 (goto-char (point-max))
2087 (mh-regenerate-headers "cur-last" t)))))
2089 (defun mh-get-new-mail (maildrop-name)
2090 "Read new mail from MAILDROP-NAME into the current buffer.
2091 Return in the current buffer."
2092 (let ((point-before-inc (point))
2093 (folder mh-current-folder)
2094 (new-mail-flag nil))
2095 (with-mh-folder-updating (t)
2097 (message "inc %s -file %s..." folder maildrop-name)
2098 (message "inc %s..." folder))
2099 (setq mh-next-direction 'forward)
2100 (goto-char (point-max))
2101 (mh-remove-cur-notation)
2102 (let ((start-of-inc (point)))
2104 ;; I think MH 5 used "-ms-file" instead of "-file",
2105 ;; which would make inc'ing from maildrops fail.
2106 (mh-exec-cmd-output mh-inc-prog nil folder
2108 "-file" (expand-file-name maildrop-name)
2109 "-width" (window-width)
2111 (mh-exec-cmd-output mh-inc-prog nil
2113 "-width" (window-width)))
2115 (message "inc %s -file %s...done" folder maildrop-name)
2116 (message "inc %s...done" folder))
2117 (goto-char start-of-inc)
2118 (cond ((save-excursion
2119 (re-search-forward "^inc: no mail" nil t))
2120 (message "No new mail%s%s" (if maildrop-name " in " "")
2121 (if maildrop-name maildrop-name "")))
2122 ((and (when mh-folder-view-stack
2123 (let ((saved-text (buffer-substring-no-properties
2124 start-of-inc (point-max))))
2125 (delete-region start-of-inc (point-max))
2126 (unwind-protect (mh-widen t)
2127 (mh-remove-cur-notation)
2128 (goto-char (point-max))
2129 (setq start-of-inc (point))
2131 (goto-char start-of-inc))))
2133 ((re-search-forward "^inc:" nil t) ; Error messages
2134 (error "Error incorporating mail"))
2136 (equal mh-scan-format-file t)
2137 mh-adaptive-cmd-note-flag
2138 ;; Have we reached an edge condition?
2140 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1))
2141 (setq start-of-inc (mh-generate-new-cmd-note folder))
2144 (setq new-mail-flag t)))
2145 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines
2146 (let* ((sequences (mh-read-folder-sequences folder t))
2147 (new-cur (assoc 'cur sequences))
2148 (new-unseen (assoc mh-unseen-seq sequences)))
2149 (unless (assoc 'cur mh-seq-list)
2150 (push (list 'cur) mh-seq-list))
2151 (unless (assoc mh-unseen-seq mh-seq-list)
2152 (push (list mh-unseen-seq) mh-seq-list))
2153 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur))
2154 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen)))
2155 (when (equal (point-max) start-of-inc)
2159 (mh-make-folder-mode-line)
2160 (when (mh-speed-flists-active-p)
2161 (mh-speed-flists t mh-current-folder))
2162 (when (memq 'unthread mh-view-ops)
2163 (mh-thread-inc folder start-of-inc))
2165 (goto-char point-before-inc))
2166 (mh-notate-user-sequences (cons start-of-inc (point-max)))))))
2168 (defun mh-make-folder-mode-line (&optional ignored)
2169 "Set the fields of the mode line for a folder buffer.
2170 The optional argument is now obsolete and IGNORED. It used to be
2171 used to pass in what is now stored in the buffer-local variable
2172 `mh-mode-line-annotation'."
2174 (save-window-excursion
2176 (let ((new-first-msg-num (mh-get-msg-num nil)))
2177 (when (or (not (memq 'unthread mh-view-ops))
2178 (null mh-first-msg-num)
2179 (null new-first-msg-num)
2180 (< new-first-msg-num mh-first-msg-num))
2181 (setq mh-first-msg-num new-first-msg-num)))
2183 (let ((new-last-msg-num (mh-get-msg-num nil)))
2184 (when (or (not (memq 'unthread mh-view-ops))
2185 (null mh-last-msg-num)
2186 (null new-last-msg-num)
2187 (> new-last-msg-num mh-last-msg-num))
2188 (setq mh-last-msg-num new-last-msg-num)))
2189 (setq mh-msg-count (if mh-first-msg-num
2190 (count-lines (point-min) (point-max))
2192 (setq mode-line-buffer-identification
2193 (list (format " {%%b%s} %s msg%s"
2194 (if mh-mode-line-annotation
2195 (format "/%s" mh-mode-line-annotation)
2197 (if (zerop mh-msg-count)
2199 (format "%d" mh-msg-count))
2200 (if (zerop mh-msg-count)
2202 (cond ((> mh-msg-count 1)
2203 (format "s (%d-%d)" mh-first-msg-num
2206 (format " (%d)" mh-first-msg-num))
2208 (mh-logo-display))))
2210 (defun mh-add-sequence-notation (msg internal-seq-flag)
2211 "Add sequence notation to the MSG on the current line.
2212 If INTERNAL-SEQ-FLAG is non-nil, then refontify the scan line if
2213 font-lock is turned on."
2214 (with-mh-folder-updating (t)
2217 (if internal-seq-flag
2219 ;; Change the buffer so that if transient-mark-mode is active
2220 ;; and there is an active region it will get deactivated as in
2221 ;; the case of user sequences.
2222 (mh-notate nil nil mh-cmd-note)
2223 (when font-lock-mode
2224 (font-lock-fontify-region (point) (line-end-position))))
2225 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2226 (let ((stack (gethash msg mh-sequence-notation-history)))
2227 (setf (gethash msg mh-sequence-notation-history)
2228 (cons (char-after) stack)))
2229 (mh-notate nil mh-note-seq
2230 (+ mh-cmd-note mh-scan-field-destination-offset))))))
2232 (defun mh-remove-sequence-notation (msg internal-seq-flag &optional all)
2233 "Remove sequence notation from the MSG on the current line.
2234 If INTERNAL-SEQ-FLAG is non-nil, then `font-lock' was used to
2235 highlight the sequence. In that case, no notation needs to be removed.
2236 Otherwise the effect of inserting `mh-note-seq' needs to be reversed.
2237 If ALL is non-nil, then all sequence marks on the scan line are
2239 (with-mh-folder-updating (t)
2240 ;; This takes care of internal sequences...
2241 (mh-notate nil nil mh-cmd-note)
2242 (unless internal-seq-flag
2243 ;; ... and this takes care of user sequences.
2244 (let ((stack (gethash msg mh-sequence-notation-history)))
2245 (while (and all (cdr stack))
2246 (setq stack (cdr stack)))
2250 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2252 (insert (car stack))))
2253 (setf (gethash msg mh-sequence-notation-history) (cdr stack))))))
2255 (defun mh-remove-cur-notation ()
2256 "Remove old cur notation."
2257 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2260 (mh-goto-msg cur-msg t t)
2261 (looking-at mh-scan-cur-msg-number-regexp))
2262 (mh-notate nil ? mh-cmd-note)
2263 (setq overlay-arrow-position nil)))))
2265 (defun mh-remove-all-notation ()
2266 "Remove all notations on all scan lines that MH-E introduces."
2268 (setq overlay-arrow-position nil)
2269 (goto-char (point-min))
2270 (mh-iterate-on-range msg (cons (point-min) (point-max))
2271 (mh-notate nil ? mh-cmd-note)
2272 (mh-remove-sequence-notation msg nil t))
2273 (clrhash mh-sequence-notation-history)))
2276 (defun mh-goto-cur-msg (&optional minimal-changes-flag)
2277 "Position the cursor at the current message.
2278 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the
2279 function doesn't recenter the folder buffer."
2280 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2282 (mh-goto-msg cur-msg t t))
2283 (unless minimal-changes-flag
2286 (mh-maybe-show cur-msg)))
2288 (setq overlay-arrow-position nil)
2289 (message "No current message")))))
2291 (defun mh-process-or-undo-commands (folder)
2292 "If FOLDER has outstanding commands, then either process or discard them.
2293 Called by functions like `mh-sort-folder', so also invalidate
2296 (if (mh-outstanding-commands-p)
2297 (if (or mh-do-not-confirm-flag
2299 "Process outstanding deletes and refiles? "))
2300 (mh-process-commands folder)
2304 (mh-invalidate-show-buffer))
2306 (defun mh-process-commands (folder)
2307 "Process outstanding commands for FOLDER.
2309 This function runs `mh-before-commands-processed-hook' before the
2310 commands are processed and `mh-after-commands-processed-hook'
2311 after the commands are processed."
2312 (message "Processing deletes and refiles for %s..." folder)
2314 (with-mh-folder-updating (nil)
2315 ;; Run the before hook -- the refile and delete lists are still valid
2316 (run-hooks 'mh-before-commands-processed-hook)
2318 ;; Update the unseen sequence if it exists
2321 (let ((redraw-needed-flag mh-index-data)
2322 (folders-changed (list mh-current-folder))
2323 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag
2324 (mh-create-sequence-map mh-seq-list)))
2325 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag
2326 (make-hash-table))))
2327 ;; Remove invalid scan lines if we are in an index folder and then remove
2328 ;; the real messages
2330 (mh-index-delete-folder-headers)
2331 (setq folders-changed
2332 (append folders-changed (mh-index-execute-commands))))
2334 ;; Then refile messages
2335 (mh-mapc #'(lambda (folder-msg-list)
2336 (let* ((dest-folder (symbol-name (car folder-msg-list)))
2337 (last (car (mh-translate-range dest-folder "last")))
2338 (msgs (cdr folder-msg-list)))
2339 (push dest-folder folders-changed)
2340 (setq redraw-needed-flag t)
2341 (apply #'mh-exec-cmd
2342 "refile" "-src" folder dest-folder
2343 (mh-coalesce-msg-list msgs))
2344 (mh-delete-scan-msgs msgs)
2345 ;; Preserve sequences in destination folder...
2346 (when mh-refile-preserves-sequences-flag
2348 (loop for i from (1+ (or last 0))
2349 for msg in (sort (copy-sequence msgs) #'<)
2350 do (loop for seq-name in (gethash msg seq-map)
2351 do (push i (gethash seq-name dest-map))))
2353 #'(lambda (seq msgs)
2354 ;; Can't be run in the background, since the
2355 ;; current folder is changed by mark this could
2356 ;; lead to a race condition with the next refile.
2357 (apply #'mh-exec-cmd "mark"
2358 "-sequence" (symbol-name seq) dest-folder
2359 "-add" (mapcar #'(lambda (x) (format "%s" x))
2360 (mh-coalesce-msg-list msgs))))
2363 (setq mh-refile-list ())
2365 ;; Now delete messages
2366 (cond (mh-delete-list
2367 (setq redraw-needed-flag t)
2368 (apply 'mh-exec-cmd "rmm" folder
2369 (mh-coalesce-msg-list mh-delete-list))
2370 (mh-delete-scan-msgs mh-delete-list)
2371 (setq mh-delete-list nil)))
2373 ;; Don't need to remove sequences since delete and refile do so.
2375 (if (> (buffer-size) 0)
2376 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last"))))
2378 ;; Redraw folder buffer if needed
2379 (when (and redraw-needed-flag)
2380 (when (mh-speed-flists-active-p)
2381 (apply #'mh-speed-flists t folders-changed))
2382 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max)))
2383 (mh-index-data (mh-index-insert-folder-headers))))
2385 (and (buffer-file-name (get-buffer mh-show-buffer))
2386 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
2387 ;; If "inc" were to put a new msg in this file,
2388 ;; we would not notice, so mark it invalid now.
2389 (mh-invalidate-show-buffer))
2391 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
2392 (mh-remove-all-notation)
2393 (mh-notate-user-sequences)
2395 ;; Run the after hook -- now folders-changed is valid,
2396 ;; but not the lists of specific messages.
2397 (let ((mh-folders-changed folders-changed))
2398 (run-hooks 'mh-after-commands-processed-hook)))
2400 (message "Processing deletes and refiles for %s...done" folder)))
2402 (defun mh-update-unseen ()
2403 "Synchronize the unseen sequence with MH.
2404 Return non-nil iff the MH folder was set.
2405 The hook `mh-unseen-updated-hook' is called after the unseen sequence
2408 (let* ((unseen-seq (mh-find-seq mh-unseen-seq))
2409 (unseen-msgs (mh-seq-msgs unseen-seq)))
2412 (mh-undefine-sequence mh-unseen-seq mh-seen-list)
2413 (run-hooks 'mh-unseen-updated-hook)
2415 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs))
2416 (setq mh-seen-list (cdr mh-seen-list)))
2417 (setcdr unseen-seq unseen-msgs)
2418 t) ;since we set the folder
2419 (setq mh-seen-list nil)))))
2421 (defun mh-delete-scan-msgs (msgs)
2422 "Delete the scan listing lines for MSGS."
2425 (when (mh-goto-msg (car msgs) t t)
2426 (when (memq 'unthread mh-view-ops)
2427 (mh-thread-forget-message (car msgs)))
2429 (setq msgs (cdr msgs)))))
2431 (defun mh-outstanding-commands-p ()
2432 "Return non-nil if there are outstanding deletes or refiles."
2434 (when (eq major-mode 'mh-show-mode)
2435 (set-buffer mh-show-folder-buffer))
2436 (or mh-delete-list mh-refile-list)))
2438 (defun mh-coalesce-msg-list (messages)
2439 "Given a list of MESSAGES, return a list of message number ranges.
2440 This is the inverse of `mh-read-msg-list', which expands ranges.
2441 Message lists passed to MH programs should be processed by this
2442 function to avoid exceeding system command line argument limits."
2443 (let ((msgs (sort (copy-sequence messages) 'mh-greaterp))
2449 (if (or (not (numberp prev))
2450 (not (equal (car msgs) (1- prev))))
2451 (progn ;non-sequential, flush old range
2452 (if (eq prev range-high)
2453 (setq ranges (cons range-high ranges))
2454 (setq ranges (cons (format "%s-%s" prev range-high) ranges)))
2455 (setq range-high nil))))
2457 (setq range-high (car msgs))) ;start new or first range
2458 (setq prev (car msgs))
2459 (setq msgs (cdr msgs)))
2462 (defun mh-greaterp (msg1 msg2)
2463 "Return the greater of two message indicators MSG1 and MSG2.
2464 Strings are \"smaller\" than numbers.
2465 Valid values are things like \"cur\", \"last\", 1, and 1820."
2472 (string-lessp msg2 msg1))))
2474 (defun mh-lessp (msg1 msg2)
2475 "Return the lesser of two message indicators MSG1 and MSG2.
2476 Strings are \"smaller\" than numbers.
2477 Valid values are things like \"cur\", \"last\", 1, and 1820."
2478 (not (mh-greaterp msg1 msg2)))
2482 ;;; Basic sequence handling
2484 (defun mh-delete-seq-locally (seq)
2485 "Remove MH-E's record of SEQ."
2486 (let ((entry (mh-find-seq seq)))
2487 (setq mh-seq-list (delq entry mh-seq-list))))
2489 (defun mh-read-folder-sequences (folder save-refiles)
2490 "Read and return the predefined sequences for a FOLDER.
2491 If SAVE-REFILES is non-nil, then keep the sequences
2492 that note messages to be refiled."
2495 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
2496 (if (mh-folder-name-p (mh-seq-name seq))
2497 (setq seqs (cons seq seqs)))))
2500 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
2502 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
2503 (while (re-search-forward "^[^: ]+" nil t)
2504 (setq seqs (cons (mh-make-seq (intern (buffer-substring
2509 (delete-region (point-min) (point))))) ; avoid race with
2513 (defun mh-read-msg-list ()
2514 "Return a list of message numbers from point to the end of the line.
2515 Expands ranges into set of individual numbers."
2517 (end-of-line (save-excursion (end-of-line) (point)))
2519 (while (re-search-forward "[0-9]+" end-of-line t)
2520 (setq num (string-to-number (buffer-substring (match-beginning 0)
2522 (cond ((looking-at "-") ; Message range
2524 (re-search-forward "[0-9]+" end-of-line t)
2525 (let ((num2 (string-to-number
2526 (buffer-substring (match-beginning 0)
2529 (error "Bad message range: %d-%d" num num2))
2530 (while (<= num num2)
2531 (setq msgs (cons num msgs))
2532 (setq num (1+ num)))))
2533 ((not (zerop num)) ;"pick" outputs "0" to mean no match
2534 (setq msgs (cons num msgs)))))
2537 (defun mh-notate-user-sequences (&optional range)
2538 "Mark user-defined sequences in RANGE.
2540 Check the documentation of `mh-interactive-range' to see how
2541 RANGE is read in interactive use; if nil all messages are
2544 (setq range (cons (point-min) (point-max))))
2545 (let ((seqs mh-seq-list)
2546 (msg-hash (make-hash-table)))
2548 (dolist (msg (mh-seq-msgs seq))
2549 (push (car seq) (gethash msg msg-hash))))
2550 (mh-iterate-on-range msg range
2551 (loop for seq in (gethash msg msg-hash)
2552 do (mh-add-sequence-notation msg (mh-internal-seq seq))))))
2554 (defvar mh-internal-seqs '(answered cur deleted forwarded printed))
2556 (defun mh-internal-seq (name)
2557 "Return non-nil if NAME is the name of an internal MH-E sequence."
2558 (or (memq name mh-internal-seqs)
2559 (eq name mh-unseen-seq)
2560 (and (mh-colors-in-use-p) mh-tick-seq (eq name mh-tick-seq))
2561 (eq name mh-previous-seq)
2562 (mh-folder-name-p name)))
2564 (defun mh-valid-seq-p (name)
2565 "Return non-nil if NAME is a valid MH sequence name."
2567 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" (symbol-name name))))
2569 (defun mh-delete-msg-from-seq (range sequence &optional internal-flag)
2570 "Delete RANGE from SEQUENCE.
2572 Check the documentation of `mh-interactive-range' to see how
2573 RANGE is read in interactive use.
2575 In a program, non-nil INTERNAL-FLAG means do not inform MH of the
2577 (interactive (list (mh-interactive-range "Delete")
2578 (mh-read-seq-default "Delete from" t)
2580 (let ((entry (mh-find-seq sequence))
2581 (user-sequence-flag (not (mh-internal-seq sequence)))
2582 (folders-changed (list mh-current-folder))
2585 (mh-iterate-on-range msg range
2587 ;; Calling "mark" repeatedly takes too long. So we will pretend here
2588 ;; that we are just modifying an internal sequence...
2589 (when (memq msg (cdr entry))
2590 (mh-remove-sequence-notation msg (not user-sequence-flag)))
2591 (mh-delete-a-msg-from-seq msg sequence t))
2592 ;; ... and here we will "mark" all the messages at one go.
2593 (unless internal-flag (mh-undefine-sequence sequence msg-list))
2594 (when (and mh-index-data (not internal-flag))
2595 (setq folders-changed
2596 (append folders-changed
2597 (mh-index-delete-from-sequence sequence msg-list))))
2598 (when (and (eq sequence mh-unseen-seq) (mh-speed-flists-active-p))
2599 (apply #'mh-speed-flists t folders-changed)))))
2601 (defun mh-catchup (range)
2602 "Delete RANGE from the \"unseen\" sequence.
2604 Check the documentation of `mh-interactive-range' to see how
2605 RANGE is read in interactive use."
2606 (interactive (list (mh-interactive-range "Catchup"
2607 (cons (point-min) (point-max)))))
2608 (mh-delete-msg-from-seq range mh-unseen-seq))
2610 (defun mh-delete-a-msg-from-seq (msg sequence internal-flag)
2611 "Delete MSG from SEQUENCE.
2612 If INTERNAL-FLAG is non-nil, then do not inform MH of the
2614 (let ((entry (mh-find-seq sequence)))
2615 (when (and entry (memq msg (mh-seq-msgs entry)))
2616 (if (not internal-flag)
2617 (mh-undefine-sequence sequence (list msg)))
2618 (setcdr entry (delq msg (mh-seq-msgs entry))))))
2620 (defun mh-undefine-sequence (seq msgs)
2621 "Remove from the SEQ the list of MSGS."
2622 (when (and (mh-valid-seq-p seq) msgs)
2623 (apply #'mh-exec-cmd "mark" mh-current-folder "-delete"
2624 "-sequence" (symbol-name seq) (mh-coalesce-msg-list msgs))))
2626 (defun mh-define-sequence (seq msgs)
2627 "Define the SEQ to contain the list of MSGS.
2628 Do not mark pseudo-sequences or empty sequences.
2629 Signals an error if SEQ is an invalid name."
2631 (mh-valid-seq-p seq)
2632 (not (mh-folder-name-p seq)))
2634 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
2635 "-sequence" (symbol-name seq)
2636 (mh-coalesce-msg-list msgs)))))
2638 (defun mh-seq-containing-msg (msg &optional include-internal-flag)
2639 "Return a list of the sequences containing MSG.
2640 If INCLUDE-INTERNAL-FLAG non-nil, include MH-E internal sequences
2642 (let ((l mh-seq-list)
2645 (and (memq msg (mh-seq-msgs (car l)))
2646 (or include-internal-flag
2647 (not (mh-internal-seq (mh-seq-name (car l)))))
2648 (setq seqs (cons (mh-seq-name (car l)) seqs)))
2654 ;;; Build mh-folder-mode keymap:
2656 (suppress-keymap mh-folder-mode-map)
2658 ;; Use defalias to make sure the documented primary key bindings
2659 ;; appear in menu lists.
2660 (defalias 'mh-alt-show 'mh-show)
2661 (defalias 'mh-alt-refile-msg 'mh-refile-msg)
2662 (defalias 'mh-alt-send 'mh-send)
2663 (defalias 'mh-alt-visit-folder 'mh-visit-folder)
2665 ;; Save the "b" binding for a future `back'. Maybe?
2666 (gnus-define-keys mh-folder-mode-map
2668 "!" mh-refile-or-write-again
2670 "," mh-header-display
2672 ";" mh-toggle-mh-decode-mime-flag
2673 ">" mh-write-msg-to-file
2675 "E" mh-extract-rejected-mail
2677 "\177" mh-previous-page
2678 "\C-d" mh-delete-msg-no-motion
2679 "\t" mh-index-next-folder
2680 [backtab] mh-index-previous-folder
2681 "\M-\t" mh-index-previous-folder
2684 "\ed" mh-redistribute
2686 "^" mh-alt-refile-msg
2693 "k" mh-delete-subject-or-thread
2695 "n" mh-next-undeleted-msg
2696 "\M-n" mh-next-unread-msg
2698 "p" mh-previous-undeleted-msg
2699 "\M-p" mh-previous-unread-msg
2703 "t" mh-toggle-showing
2705 "v" mh-index-visit-folder
2706 "x" mh-execute-commands
2709 (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map)
2711 "'" mh-index-ticked-messages
2714 "f" mh-alt-visit-folder
2718 "n" mh-index-new-messages
2719 "o" mh-alt-visit-folder
2721 "q" mh-index-sequenced-messages
2722 "r" mh-rescan-folder
2723 "s" mh-search-folder
2725 "v" mh-visit-folder)
2727 (define-key mh-folder-mode-map "I" mh-inc-spool-map)
2729 (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map)
2731 "b" mh-junk-blacklist
2732 "w" mh-junk-whitelist)
2734 (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map)
2736 "C" mh-ps-print-toggle-color
2737 "F" mh-ps-print-toggle-faces
2738 "f" mh-ps-print-msg-file
2740 "p" mh-ps-print-msg)
2742 (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map)
2743 "'" mh-narrow-to-tick
2745 "d" mh-delete-msg-from-seq
2747 "l" mh-list-sequences
2748 "n" mh-narrow-to-seq
2749 "p" mh-put-msg-in-seq
2750 "s" mh-msg-is-in-seq
2753 (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map)
2755 "u" mh-thread-ancestor
2756 "p" mh-thread-previous-sibling
2757 "n" mh-thread-next-sibling
2758 "t" mh-toggle-threads
2759 "d" mh-thread-delete
2760 "o" mh-thread-refile)
2762 (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map)
2763 "'" mh-narrow-to-tick
2766 "f" mh-narrow-to-from
2767 "r" mh-narrow-to-range
2768 "s" mh-narrow-to-subject
2772 (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map)
2774 "s" mh-store-msg ;shar
2775 "u" mh-store-msg) ;uuencode
2777 (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map)
2780 "\177" mh-page-digest-backwards
2781 "b" mh-burst-digest)
2783 (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map)
2785 "a" mh-mime-save-parts
2786 "e" mh-display-with-external-viewer
2787 "i" mh-folder-inline-mime-part
2788 "o" mh-folder-save-mime-part
2789 "t" mh-toggle-mime-buttons
2790 "v" mh-folder-toggle-mime-part
2792 [backtab] mh-prev-button
2793 "\M-\t" mh-prev-button)
2797 (define-key mh-folder-mode-map [button2] 'mh-show-mouse))
2799 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse)))
2801 ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt
2807 ;; If you add a new prefix, add appropriate text to the nil key.
2809 ;; In general, messages are grouped logically. Taking the main commands for
2810 ;; example, the first line is "ways to view messages," the second line is
2811 ;; "things you can do with messages", and the third is "composing" messages.
2813 ;; When adding a new prefix, ensure that the help message contains "what" the
2814 ;; prefix is for. For example, if the word "folder" were not present in the
2815 ;; "F" entry, it would not be clear what these commands operated upon.
2816 (defvar mh-help-messages
2817 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n"
2818 "[d]elete, [o]refile, e[x]ecute,\n"
2819 "[s]end, [r]eply,\n"
2820 "[;]toggle MIME decoding.\n"
2821 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys,"
2822 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.")
2824 (?F "[l]ist; [v]isit folder;\n"
2825 "[n]ew messages; [']ticked messages; [s]earch; [i]ndexed search;\n"
2826 "[p]ack; [S]ort; [r]escan; [k]ill")
2827 (?P "[p]rint message to [f]ile; old-style [l]pr printing;\n"
2828 "Toggle printing of [C]olors, [F]aces")
2829 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n"
2830 "[s]equences, [l]ist,\n"
2831 "[d]elete message from sequence, [k]ill sequence")
2832 (?T "[t]oggle, [d]elete, [o]refile thread")
2833 (?/ "Limit to [c]c, [f]rom, [r]ange, [s]ubject, [t]o; [w]iden")
2834 (?X "un[s]har, [u]udecode message")
2835 (?D "[b]urst digest")
2836 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n"
2837 "[TAB] next; [SHIFT-TAB] previous")
2838 (?J "[b]lacklist, [w]hitelist message"))
2839 "Key binding cheat sheet.
2841 This is an associative array which is used to show the most common commands.
2842 The key is a prefix char. The value is one or more strings which are
2843 concatenated together and displayed in the minibuffer if ? is pressed after
2844 the prefix character. The special key nil is used to display the
2845 non-prefixed commands.
2847 The substitutions described in `substitute-command-keys' are performed as
2852 (dolist (mess '("^Cursor not pointing to message$"
2853 "^There is no other window$"))
2854 (add-to-list 'debug-ignored-errors mess))
2859 ;; indent-tabs-mode: nil
2860 ;; sentence-end-double-space: nil
2863 ;; arch-tag: cce884de-bd37-4104-9963-e4439d5ed22b
2864 ;;; mh-e.el ends here