1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system
3 ;; Copyright (C) 1985, 1986, 1987, 1988,
4 ;; 1990, 1992, 1993, 1994, 1995, 1997, 1999,
5 ;; 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
7 ;; Author: Bill Wohler <wohler@newt.com>
8 ;; Maintainer: Bill Wohler <wohler@newt.com>
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
32 ;; M-x mh-rmail to read mail. Type C-h m there for a list of commands.
33 ;; C-u M-x mh-rmail to visit any folder.
34 ;; M-x mh-smail to send mail. From within the mail reader, "m" works, too.
36 ;; Your .emacs might benefit from these bindings:
37 ;; (global-set-key "\C-cr" 'mh-rmail)
38 ;; (global-set-key "\C-xm" 'mh-smail)
39 ;; (global-set-key "\C-x4m" 'mh-smail-other-window)
41 ;; MH (Message Handler) is a powerful mail reader.
43 ;; The MH newsgroup is comp.mail.mh; the mailing list is mh-users@ics.uci.edu
44 ;; (send to mh-users-request to be added). See the monthly Frequently Asked
45 ;; Questions posting there for information on getting MH and MH-E:
46 ;; http://www.faqs.org/faqs/mail/mh-faq/part1/preamble.html
48 ;; N.B. MH must have been compiled with the MHE compiler flag or several
49 ;; features necessary for MH-E will be missing from MH commands, specifically
50 ;; the -build switch to repl and forw.
52 ;; MH-E is an Emacs interface to the MH mail system.
54 ;; MH-E is supported in GNU Emacs 20 and 21, with MH 6.8.4 and nmh 1.0.4.
57 ;; mh-e-users@lists.sourceforge.net
58 ;; mh-e-announce@lists.sourceforge.net
59 ;; mh-e-devel@lists.sourceforge.net
61 ;; Subscribe by sending a "subscribe" message to
62 ;; <list>-request@lists.sourceforge.net, or by using the web interface at
63 ;; https://sourceforge.net/mail/?group_id=13357
66 ;; https://sourceforge.net/tracker/?group_id=13357&atid=113357
67 ;; Include the output of M-x mh-version in any bug report.
70 ;; https://sourceforge.net/tracker/?atid=363357&group_id=13357&func=browse
73 ;; https://sourceforge.net/tracker/?group_id=13357&atid=213357
77 ;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
78 ;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
79 ;; Rewritten for GNU Emacs, James Larus, 1985.
80 ;; Modified by Stephen Gildea, 1988.
81 ;; Maintenance picked up by Bill Wohler and the
82 ;; SourceForge Crew <http://mh-e.sourceforge.net/>, 2001.
88 (eval-when-compile (require 'mh-acros))
97 ;; Shush the byte-compiler
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 maildrop-name 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
722 mail. Do not call this function from outside MH-E; use
723 \\[mh-rmail] instead.
725 In a program optional argument MAILDROP-NAME specifies an
726 alternate maildrop from the default. The optional argument FOLDER
727 specifies where to incorporate mail instead of the default named
729 (interactive (list (if current-prefix-arg
731 (read-file-name "inc mail from file: "
733 (if current-prefix-arg
734 (mh-prompt-for-folder "inc mail into" mh-inbox t))))
736 (setq folder mh-inbox))
737 (let ((threading-needed-flag nil))
738 (let ((config (current-window-configuration)))
739 (when (and mh-show-buffer (get-buffer mh-show-buffer))
740 (delete-windows-on mh-show-buffer))
741 (cond ((not (get-buffer folder))
742 (mh-make-folder folder)
743 (setq threading-needed-flag mh-show-threads-flag)
744 (setq mh-previous-window-config config))
745 ((not (eq (current-buffer) (get-buffer folder)))
746 (switch-to-buffer folder)
747 (setq mh-previous-window-config config))))
748 (mh-get-new-mail maildrop-name)
749 (when (and threading-needed-flag
751 (goto-char (point-min))
752 (or (null mh-large-folder)
753 (not (equal (forward-line (1+ mh-large-folder)) 0))
754 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
758 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show))
759 (run-hooks 'mh-inc-folder-hook)))
761 (defun mh-last-msg ()
762 "Display last message."
764 (goto-char (point-max))
765 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp)))
769 (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag)
770 "Display next message.
772 This command can be given a prefix argument COUNT to specify how
773 many unread messages to skip.
775 In a program, pause for a second after printing message if we are
776 at the last undeleted message and optional argument
777 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
779 (setq mh-next-direction 'forward)
781 (cond ((re-search-forward mh-scan-good-msg-regexp nil t count)
785 (message "No more undeleted messages")
786 (if wait-after-complaining-flag (sit-for 1)))))
788 (defun mh-folder-from-address ()
789 "Derive folder name from sender.
791 The name of the folder is derived as follows:
793 a) The folder name associated with the first address found in
794 the list `mh-default-folder-list' is used. Each element in
795 this list contains a \"Check Recipient\" item. If this item is
796 turned on, then the address is checked against the recipient
797 instead of the sender. This is useful for mailing lists.
799 b) An alias prefixed by `mh-default-folder-prefix'
800 corresponding to the address is used. The prefix is used to
801 prevent clutter in your mail directory.
803 Return nil if a folder name was not derived, or if the variable
804 `mh-default-folder-must-exist-flag' is t and the folder does not
806 ;; Loop for all entries in mh-default-folder-list
808 (goto-char (point-min))
809 (re-search-forward "\n\n" nil 'limit)
810 (narrow-to-region (point-min) (point))
811 (let ((to/cc (concat (or (message-fetch-field "to") "") ", "
812 (or (message-fetch-field "cc") "")))
813 (from (or (message-fetch-field "from") ""))
816 (loop for list in mh-default-folder-list
817 when (string-match (nth 0 list) (if (nth 2 list) to/cc from))
821 ;; Make sure a result from `mh-default-folder-list' begins with "+"
822 ;; since 'mh-expand-file-name below depends on it
823 (when (and folder-name (not (eq (aref folder-name 0) ?+)))
824 (setq folder-name (concat "+" folder-name)))
826 ;; If not, is there an alias for the address?
827 (when (not folder-name)
828 (let* ((from-header (mh-extract-from-header-value))
829 (address (and from-header
830 (nth 1 (mail-extract-address-components
832 (alias (and address (mh-alias-address-to-alias address))))
835 (and alias (concat "+" mh-default-folder-prefix alias))))))
837 ;; If mh-default-folder-must-exist-flag set, check that folder exists.
839 (or (not mh-default-folder-must-exist-flag)
840 (file-exists-p (mh-expand-file-name folder-name))))
843 (defun mh-prompt-for-refile-folder ()
844 "Prompt the user for a folder in which the message should be filed.
845 The folder is returned as a string.
847 The default folder name is generated by the option
848 `mh-default-folder-for-message-function' if it is non-nil or
849 `mh-folder-from-address'."
850 (mh-prompt-for-folder
852 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t)))))
853 (if (null refile-file) ""
855 (set-buffer (get-buffer-create mh-temp-buffer))
857 (insert-file-contents refile-file)
858 (or (and mh-default-folder-for-message-function
859 (let ((buffer-file-name refile-file))
860 (funcall mh-default-folder-for-message-function)))
861 (mh-folder-from-address)
862 (and (eq 'refile (car mh-last-destination-folder))
863 (symbol-name (cdr mh-last-destination-folder)))
867 (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag)
868 "Refile (output) RANGE into FOLDER.
870 You are prompted for the folder name. Note that this command can also
871 be used to create folders. If you specify a folder that does not
872 exist, you will be prompted to create it.
874 The hook `mh-refile-msg-hook' is called after a message is marked to
877 Check the documentation of `mh-interactive-range' to see how RANGE is
878 read in interactive use.
880 In a program, the variables `mh-last-destination' and
881 `mh-last-destination-folder' are not updated if
882 DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil."
883 (interactive (list (mh-interactive-range "Refile")
884 (intern (mh-prompt-for-refile-folder))))
885 (unless dont-update-last-destination-flag
886 (setq mh-last-destination (cons 'refile folder)
887 mh-last-destination-folder mh-last-destination))
888 (mh-iterate-on-range () range
889 (mh-refile-a-msg nil folder))
890 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg)))
892 (defun mh-refile-or-write-again (range &optional interactive-flag)
893 "Repeat last output command.
895 If you are refiling several messages into the same folder, you can use
896 this command to repeat the last refile or write. You can use a range.
898 Check the documentation of `mh-interactive-range' to see how RANGE is
899 read in interactive use.
901 In a program, a non-nil INTERACTIVE-FLAG means that the function was
902 called interactively."
903 (interactive (list (mh-interactive-range "Redo") t))
904 (if (null mh-last-destination)
905 (error "No previous refile or write"))
906 (cond ((eq (car mh-last-destination) 'refile)
907 (mh-refile-msg range (cdr mh-last-destination))
908 (message "%s" (format "Destination folder: %s"
909 (cdr mh-last-destination))))
911 (mh-iterate-on-range msg range
912 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination)))
913 (mh-next-msg interactive-flag))))
916 "Quit the current MH-E folder.
918 When you want to quit using MH-E and go back to editing, you can use
919 this command. This buries the buffers of the current MH-E folder and
920 restores the buffers that were present when you first ran
921 \\[mh-rmail]. It also removes any MH-E working buffers whose name
922 begins with \" *mh-\" or \"*MH-E \". You can later restore your MH-E
923 session by selecting the \"+inbox\" buffer or by running \\[mh-rmail]
926 The two hooks `mh-before-quit-hook' and `mh-quit-hook' are called by
927 this function. The former one is called before the quit occurs, so you
928 might use it to perform any MH-E operations; you could perform some
929 query and abort the quit or call `mh-execute-commands', for example.
930 The latter is not run in an MH-E context, so you might use it to
931 modify the window setup."
933 (run-hooks 'mh-before-quit-hook)
934 (let ((show-buffer (get-buffer mh-show-buffer)))
936 (kill-buffer show-buffer)))
937 (mh-update-sequences)
938 (mh-destroy-postponed-handles)
939 (bury-buffer (current-buffer))
941 ;; Delete all MH-E temporary and working buffers.
942 (dolist (buffer (buffer-list))
943 (when (or (string-match "^ \\*mh-" (buffer-name buffer))
944 (string-match "^\\*MH-E " (buffer-name buffer)))
945 (kill-buffer buffer)))
947 (if mh-previous-window-config
948 (set-window-configuration mh-previous-window-config))
949 (run-hooks 'mh-quit-hook))
951 (defun mh-page-msg (&optional lines)
952 "Display next page in message.
954 You can give this command a prefix argument that specifies the
955 number of LINES to scroll. This command will also show the next
956 undeleted message if it is used at the bottom of a message."
959 (if mh-page-to-next-msg-flag
960 (if (equal mh-next-direction 'backward)
961 (mh-previous-undeleted-msg)
962 (mh-next-undeleted-msg))
963 (if (mh-in-show-buffer (mh-show-buffer)
964 (pos-visible-in-window-p (point-max)))
967 "End of message (Type %s to read %s undeleted message)"
968 (single-key-description last-input-event)
969 (if (equal mh-next-direction 'backward)
972 (setq mh-page-to-next-msg-flag t))
973 (scroll-other-window lines)))
976 (defun mh-previous-page (&optional lines)
977 "Display next page in message.
979 You can give this command a prefix argument that specifies the
980 number of LINES to scroll."
982 (mh-in-show-buffer (mh-show-buffer)
983 (scroll-down lines)))
985 (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag)
986 "Display previous message.
988 This command can be given a prefix argument COUNT to specify how
989 many unread messages to skip.
991 In a program, pause for a second after printing message if we are
992 at the last undeleted message and optional argument
993 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
995 (setq mh-next-direction 'backward)
997 (cond ((re-search-backward mh-scan-good-msg-regexp nil t count)
999 (t (message "No previous undeleted message")
1000 (if wait-after-complaining-flag (sit-for 1)))))
1002 (defun mh-previous-unread-msg (&optional count)
1003 "Display previous unread message.
1005 This command can be given a prefix argument COUNT to specify how
1006 many unread messages to skip."
1009 (error "The function mh-previous-unread-msg expects positive argument"))
1010 (setq count (1- count))
1011 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list)))
1012 (cur-msg (mh-get-msg-num nil)))
1013 (cond ((and (not cur-msg) (not (bobp))
1014 ;; If we are at the end of the buffer back up one line and go
1015 ;; to unread message after that.
1018 (setq cur-msg (mh-get-msg-num nil)))
1020 ((or (null unread-sequence) (not cur-msg))
1021 ;; No unread message or there aren't any messages in buffer...
1022 (message "No more unread messages"))
1024 ;; Skip count messages...
1025 (while (and unread-sequence (>= (car unread-sequence) cur-msg))
1026 (setq unread-sequence (cdr unread-sequence)))
1028 (setq unread-sequence (cdr unread-sequence))
1029 (setq count (1- count)))
1030 (not (car unread-sequence)))
1031 (message "No more unread messages"))
1032 (t (loop for msg in unread-sequence
1033 when (mh-goto-msg msg t) return nil
1034 finally (message "No more unread messages"))))))
1036 (defun mh-goto-next-button (backward-flag &optional criterion)
1037 "Search for next button satisfying criterion.
1039 If BACKWARD-FLAG is non-nil search backward in the buffer for a mime
1041 If CRITERION is a function or a symbol which has a function binding
1042 then that function must return non-nil at the button we stop."
1043 (unless (or (and (symbolp criterion) (fboundp criterion))
1044 (functionp criterion))
1045 (setq criterion (lambda (x) t)))
1046 ;; Move to the next button in the buffer satisfying criterion
1047 (goto-char (or (save-excursion
1049 ;; Find point before current button
1050 (let ((point-before-current-button
1052 (while (get-text-property (point) 'mh-data)
1053 (unless (= (forward-line
1054 (if backward-flag 1 -1))
1057 (goto-char (point-min))
1058 (goto-char (point-max)))))
1060 ;; Skip over current button
1061 (while (and (get-text-property (point) 'mh-data)
1062 (not (if backward-flag (bobp) (eobp))))
1063 (forward-line (if backward-flag -1 1)))
1064 ;; Stop at next MIME button if any exists.
1067 (unless (= (forward-line
1068 (if backward-flag -1 1))
1071 (goto-char (point-max))
1072 (goto-char (point-min)))
1073 (beginning-of-line))
1075 point-before-current-button)
1076 (when (and (get-text-property (point) 'mh-data)
1077 (funcall criterion (point)))
1078 (return-from loop (point))))
1082 (defun mh-next-button (&optional backward-flag)
1083 "Go to the next button.
1085 If the end of the buffer is reached then the search wraps over to
1086 the start of the buffer.
1088 If an optional prefix argument BACKWARD-FLAG is given, the cursor
1089 will move to the previous button."
1090 (interactive (list current-prefix-arg))
1091 (unless mh-showing-mode
1093 (mh-in-show-buffer (mh-show-buffer)
1094 (mh-goto-next-button backward-flag)))
1096 (defun mh-prev-button ()
1097 "Go to the previous button.
1099 If the beginning of the buffer is reached then the search wraps
1100 over to the end of the buffer."
1104 (defun mh-folder-mime-action (part-index action include-security-flag)
1105 "Go to PART-INDEX and carry out ACTION.
1107 If PART-INDEX is nil then go to the next part in the buffer. The
1108 search for the next buffer wraps around if end of buffer is reached.
1109 If argument INCLUDE-SECURITY-FLAG is non-nil then include security
1110 info buttons when searching for a suitable parts."
1111 (unless mh-showing-mode
1113 (mh-in-show-buffer (mh-show-buffer)
1117 (let ((part (get-text-property p 'mh-part)))
1118 (and (integerp part) (= part part-index)))))
1120 (if include-security-flag
1121 (get-text-property p 'mh-data)
1122 (integerp (get-text-property p 'mh-part)))))))
1124 (cond ((and (get-text-property point 'mh-part)
1125 (or (null part-index)
1126 (= (get-text-property point 'mh-part) part-index)))
1128 ((and (get-text-property point 'mh-data)
1129 include-security-flag
1133 (mh-goto-next-button nil criterion)
1134 (if (= (point) point)
1135 (message "No matching MIME part found")
1136 (funcall action)))))))
1138 (defun mh-folder-toggle-mime-part (part-index)
1141 This command displays (or hides) the attachment associated with
1142 the button under the cursor. If the cursor is not located over a
1143 button, then the cursor first moves to the next button, wrapping
1144 to the beginning of the message if necessary. This command has
1145 the advantage over related commands of working from the MH-Folder
1148 You can also provide a numeric prefix argument PART-INDEX to view
1149 the attachment labeled with that number. If Emacs does not know
1150 how to display the attachment, then Emacs offers to save the
1151 attachment in a file."
1153 (when (consp part-index) (setq part-index (car part-index)))
1154 (mh-folder-mime-action part-index #'mh-press-button t))
1156 (defun mh-folder-inline-mime-part (part-index)
1157 "Show attachment verbatim.
1159 You can view the raw contents of an attachment with this command.
1160 This command displays (or hides) the contents of the attachment
1161 associated with the button under the cursor verbatim. If the
1162 cursor is not located over a button, then the cursor first moves
1163 to the next button, wrapping to the beginning of the message if
1166 You can also provide a numeric prefix argument PART-INDEX to view
1167 the attachment labeled with that number."
1169 (when (consp part-index) (setq part-index (car part-index)))
1170 (mh-folder-mime-action part-index #'mh-mime-inline-part nil))
1172 (defun mh-folder-save-mime-part (part-index)
1173 "Save (output) attachment.
1175 This command saves the attachment associated with the button under the
1176 cursor. If the cursor is not located over a button, then the cursor
1177 first moves to the next button, wrapping to the beginning of the
1178 message if necessary.
1180 You can also provide a numeric prefix argument PART-INDEX to save the
1181 attachment labeled with that number.
1183 This command prompts you for a filename and suggests a specific name
1184 if it is available."
1186 (when (consp part-index) (setq part-index (car part-index)))
1187 (mh-folder-mime-action part-index #'mh-mime-save-part nil))
1189 (defvar mh-thread-scan-line-map-stack)
1191 (defun mh-reset-threads-and-narrowing ()
1192 "Reset all variables pertaining to threads and narrowing.
1193 Also removes all content from the folder buffer."
1194 (setq mh-view-ops ())
1195 (setq mh-folder-view-stack ())
1196 (setq mh-thread-scan-line-map-stack ())
1197 (let ((buffer-read-only nil)) (erase-buffer)))
1199 (defun mh-rescan-folder (&optional range dont-exec-pending)
1200 "Rescan folder\\<mh-folder-mode-map>.
1202 This command is useful to grab all messages in your \"+inbox\" after
1203 processing your new mail for the first time. If you don't want to
1204 rescan the entire folder, this command will accept a RANGE. Check the
1205 documentation of `mh-interactive-range' to see how RANGE is read in
1208 This command will ask if you want to process refiles or deletes first
1209 and then either run \\[mh-execute-commands] for you or undo the
1210 pending refiles and deletes, which are lost.
1212 In a program, the processing of outstanding commands is not performed
1213 if DONT-EXEC-PENDING is non-nil."
1214 (interactive (list (if current-prefix-arg
1215 (mh-read-range "Rescan" mh-current-folder t nil t
1216 mh-interpret-number-as-range-flag)
1218 (setq mh-next-direction 'forward)
1219 (let ((threaded-flag (memq 'unthread mh-view-ops)))
1220 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending)
1221 (cond (threaded-flag (mh-toggle-threads))
1222 (mh-index-data (mh-index-insert-folder-headers)))))
1224 (defun mh-write-msg-to-file (message file no-header)
1225 "Append MESSAGE to end of FILE\\<mh-folder-mode-map>.
1227 You are prompted for the filename. If the file already exists,
1228 the message is appended to it. You can also write the message to
1229 the file without the header by specifying a prefix argument
1230 NO-HEADER. Subsequent writes to the same file can be made with
1231 the command \\[mh-refile-or-write-again]."
1233 (list (mh-get-msg-num t)
1234 (let ((default-dir (if (eq 'write (car mh-last-destination-write))
1235 (file-name-directory
1236 (car (cdr mh-last-destination-write)))
1237 default-directory)))
1238 (read-file-name (format "Save message%s in file: "
1239 (if current-prefix-arg " body" ""))
1241 (if (eq 'write (car mh-last-destination-write))
1242 (car (cdr mh-last-destination-write))
1243 (expand-file-name "mail.out" default-dir))))
1244 current-prefix-arg))
1245 (let ((msg-file-to-output (mh-msg-filename message))
1246 (output-file (mh-expand-file-name file)))
1247 (setq mh-last-destination (list 'write file (if no-header 'no-header))
1248 mh-last-destination-write mh-last-destination)
1250 (set-buffer (get-buffer-create mh-temp-buffer))
1252 (insert-file-contents msg-file-to-output)
1253 (goto-char (point-min))
1254 (if no-header (search-forward "\n\n"))
1255 (append-to-file (point) (point-max) output-file))))
1257 (defun mh-toggle-showing ()
1258 "Toggle the scanning mode/showing mode of displaying messages."
1264 (defun mh-undo (range)
1265 "Undo pending deletes or refiles in RANGE.
1267 If you've deleted a message or refiled it, but changed your mind,
1268 you can cancel the action before you've executed it. Use this
1269 command to undo a refile on or deletion of a single message. You
1270 can also undo refiles and deletes for messages that are found in
1273 Check the documentation of `mh-interactive-range' to see how
1274 RANGE is read in interactive use."
1275 (interactive (list (mh-interactive-range "Undo")))
1276 (cond ((numberp range)
1277 (let ((original-position (point)))
1279 (while (not (or (looking-at mh-scan-deleted-msg-regexp)
1280 (looking-at mh-scan-refiled-msg-regexp)
1281 (and (eq mh-next-direction 'forward) (bobp))
1282 (and (eq mh-next-direction 'backward)
1283 (save-excursion (forward-line) (eobp)))))
1284 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
1285 (if (or (looking-at mh-scan-deleted-msg-regexp)
1286 (looking-at mh-scan-refiled-msg-regexp))
1288 (mh-undo-msg (mh-get-msg-num t))
1290 (goto-char original-position)
1291 (error "Nothing to undo"))))
1292 (t (mh-iterate-on-range () range
1293 (mh-undo-msg nil))))
1294 (if (not (mh-outstanding-commands-p))
1295 (mh-set-folder-modified-p nil)))
1298 (defun mh-folder-line-matches-show-buffer-p ()
1299 "Return t if the message under point in folder-mode is in the show buffer.
1300 Return nil in any other circumstance (no message under point, no
1301 show buffer, the message in the show buffer doesn't match."
1302 (and (eq major-mode 'mh-folder-mode)
1303 (mh-get-msg-num nil)
1305 (get-buffer mh-show-buffer)
1306 (buffer-file-name (get-buffer mh-show-buffer))
1307 (string-match ".*/\\([0-9]+\\)$"
1308 (buffer-file-name (get-buffer mh-show-buffer)))
1310 (match-string 1 (buffer-file-name (get-buffer mh-show-buffer)))
1311 (int-to-string (mh-get-msg-num nil)))))
1313 (eval-when-compile (require 'gnus))
1315 (defmacro mh-macro-expansion-time-gnus-version ()
1316 "Return Gnus version available at macro expansion time.
1317 The macro evaluates the Gnus version at macro expansion time. If
1318 MH-E was compiled then macro expansion happens at compile time."
1321 (defun mh-run-time-gnus-version ()
1322 "Return Gnus version available at run time."
1327 (defun mh-version ()
1328 "Display version information about MH-E and the MH mail handling system."
1330 (set-buffer (get-buffer-create mh-info-buffer))
1333 (insert "MH-E " mh-version "\n\n")
1334 ;; MH-E compilation details.
1335 (insert "MH-E compilation details:\n")
1336 (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version)))
1337 (gnus-compiled-version (if compiled-mhe
1338 (mh-macro-expansion-time-gnus-version)
1340 (insert " Byte compiled:\t\t" (if compiled-mhe "yes" "no") "\n"
1341 " Gnus (compile-time):\t" gnus-compiled-version "\n"
1342 " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
1344 (insert (emacs-version) "\n\n")
1346 (if mh-variant-in-use
1347 (insert mh-variant-in-use "\n"
1348 " mh-progs:\t" mh-progs "\n"
1349 " mh-lib:\t" mh-lib "\n"
1350 " mh-lib-progs:\t" mh-lib-progs "\n\n")
1351 (insert "No MH variant detected\n"))
1354 (call-process "uname" nil t nil "-a")
1356 (goto-char (point-min))
1357 (display-buffer mh-info-buffer))
1359 (defun mh-parse-flist-output-line (line &optional current-folder)
1360 "Parse LINE to generate folder name, unseen messages and total messages.
1361 If CURRENT-FOLDER is non-nil then it contains the current folder
1362 name and it is used to avoid problems in corner cases involving
1363 folders whose names end with a '+' character."
1366 (goto-char (point-max))
1367 (let (folder unseen total p)
1368 (when (search-backward " out of " (point-min) t)
1369 (setq total (read-from-string
1370 (buffer-substring-no-properties
1371 (match-end 0) (line-end-position))))
1372 (when (search-backward " in sequence " (point-min) t)
1374 (when (search-backward " has " (point-min) t)
1375 (setq unseen (read-from-string (buffer-substring-no-properties
1377 (while (eq (char-after) ? )
1379 (setq folder (buffer-substring-no-properties
1380 (point-min) (1+ (point))))
1381 (when (and (equal (aref folder (1- (length folder))) ?+)
1382 (equal current-folder folder))
1383 (setq folder (substring folder 0 (1- (length folder)))))
1384 (values (format "+%s" folder) (car unseen) (car total))))))))
1386 (defun mh-folder-size-folder (folder)
1387 "Find size of FOLDER using \"folder\"."
1389 (let ((u (length (cdr (assoc mh-unseen-seq
1390 (mh-read-folder-sequences folder nil))))))
1391 (call-process (expand-file-name "folder" mh-progs) nil t nil
1392 "-norecurse" folder)
1393 (goto-char (point-min))
1394 (if (re-search-forward " has \\([0-9]+\\) " nil t)
1395 (values (car (read-from-string (match-string 1))) u folder)
1396 (values 0 u folder)))))
1398 (defun mh-folder-size-flist (folder)
1399 "Find size of FOLDER using \"flist\"."
1401 (call-process (expand-file-name "flist" mh-progs) nil t nil "-showzero"
1402 "-norecurse" folder "-sequence" (symbol-name mh-unseen-seq))
1403 (goto-char (point-min))
1404 (multiple-value-bind (folder unseen total)
1405 (mh-parse-flist-output-line
1406 (buffer-substring (point) (line-end-position)))
1407 (values total unseen folder))))
1409 (defun mh-folder-size (folder)
1410 "Find size of FOLDER."
1411 (if mh-flists-present-flag
1412 (mh-folder-size-flist folder)
1413 (mh-folder-size-folder folder)))
1415 (defun mh-visit-folder (folder &optional range index-data)
1418 When you want to read the messages that you have refiled into folders,
1419 use this command to visit the folder. You are prompted for the folder
1422 The folder buffer will show just unseen messages if there are any;
1423 otherwise, it will show all the messages in the buffer as long there
1424 are fewer than `mh-large-folder' messages. If there are more, then you
1425 are prompted for a range of messages to scan.
1427 You can provide a prefix argument in order to specify a RANGE of
1428 messages to show when you visit the folder. In this case, regions are
1429 not used to specify the range and `mh-large-folder' is ignored. Check
1430 the documentation of `mh-interactive-range' to see how RANGE is read
1433 Note that this command can also be used to create folders. If you
1434 specify a folder that does not exist, you will be prompted to create
1437 Do not call this function from outside MH-E; use \\[mh-rmail] instead.
1439 If, in a program, RANGE is nil (the default), then all messages in
1440 FOLDER are displayed. If an index buffer is being created then
1441 INDEX-DATA is used to initialize the index buffer specific data
1443 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t)))
1445 (mh-read-range "Scan" folder-name t nil
1447 mh-interpret-number-as-range-flag))))
1448 (let ((config (current-window-configuration))
1449 (current-buffer (current-buffer))
1450 (threaded-view-flag mh-show-threads-flag))
1451 (delete-other-windows)
1453 (when (get-buffer folder)
1455 (setq threaded-view-flag (memq 'unthread mh-view-ops))))
1457 (mh-make-folder folder)
1458 (setq mh-index-data (car index-data)
1459 mh-index-msg-checksum-map (make-hash-table :test #'equal)
1460 mh-index-checksum-origin-map (make-hash-table :test #'equal))
1461 (mh-index-update-maps folder (cadr index-data))
1462 (mh-index-create-sequences))
1463 (mh-scan-folder folder (or range "all"))
1464 (cond ((and threaded-view-flag
1466 (goto-char (point-min))
1467 (or (null mh-large-folder)
1468 (not (equal (forward-line (1+ mh-large-folder)) 0))
1469 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
1471 (mh-toggle-threads))
1473 (mh-index-insert-folder-headers)))
1474 (unless (eq current-buffer (current-buffer))
1475 (setq mh-previous-window-config config)))
1479 (defun mh-update-sequences ()
1480 "Flush MH-E's state out to MH.
1482 This function updates the sequence specified by your
1483 \"Unseen-Sequence:\" profile component, \"cur\", and the sequence
1484 listed by the `mh-tick-seq' option which is \"tick\" by default.
1485 The message at the cursor is used for \"cur\"."
1487 ;; mh-update-sequences is the opposite of mh-read-folder-sequences,
1488 ;; which updates MH-E's state from MH.
1489 (let ((folder-set (mh-update-unseen))
1490 (new-cur (mh-get-msg-num nil)))
1492 (let ((seq-entry (mh-find-seq 'cur)))
1493 (mh-remove-cur-notation)
1495 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq
1496 (mh-define-sequence 'cur (list new-cur))
1498 (if (looking-at mh-scan-good-msg-regexp)
1502 ;; psg - mh-current-folder is nil if mh-summary-height < 4 !
1503 ;; So I added this sanity check.
1504 (if (stringp mh-current-folder)
1505 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast")
1506 (mh-exec-cmd-quiet t "folder" "-fast")))))))
1510 ;;; Support routines.
1512 (defun mh-delete-a-msg (message)
1514 If MESSAGE is nil then the message at point is deleted.
1515 The hook `mh-delete-msg-hook' is called after you mark a message
1516 for deletion. For example, a past maintainer of MH-E used this
1517 once when he kept statistics on his mail usage."
1519 (if (numberp message)
1520 (mh-goto-msg message nil t)
1522 (setq message (mh-get-msg-num t)))
1523 (if (looking-at mh-scan-refiled-msg-regexp)
1524 (error "Message %d is refiled. Undo refile before deleting" message))
1525 (if (looking-at mh-scan-deleted-msg-regexp)
1527 (mh-set-folder-modified-p t)
1528 (setq mh-delete-list (cons message mh-delete-list))
1529 (mh-notate nil mh-note-deleted mh-cmd-note)
1530 (run-hooks 'mh-delete-msg-hook))))
1532 (defun mh-refile-a-msg (message folder)
1533 "Refile MESSAGE in FOLDER.
1534 If MESSAGE is nil then the message at point is refiled.
1535 Folder is a symbol, not a string.
1536 The hook `mh-refile-msg-hook' is called after a message is marked to
1539 (if (numberp message)
1540 (mh-goto-msg message nil t)
1542 (setq message (mh-get-msg-num t)))
1543 (cond ((looking-at mh-scan-deleted-msg-regexp)
1544 (error "Message %d is deleted. Undo delete before moving" message))
1545 ((looking-at mh-scan-refiled-msg-regexp)
1547 (format "Message %d already refiled. Copy to %s as well? "
1549 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
1550 "-src" mh-current-folder
1551 (symbol-name folder))
1552 (message "Message not copied")))
1554 (mh-set-folder-modified-p t)
1555 (cond ((null (assoc folder mh-refile-list))
1556 (push (list folder message) mh-refile-list))
1557 ((not (member message (cdr (assoc folder mh-refile-list))))
1558 (push message (cdr (assoc folder mh-refile-list)))))
1559 (mh-notate nil mh-note-refiled mh-cmd-note)
1560 (run-hooks 'mh-refile-msg-hook)))))
1562 (defun mh-next-msg (&optional wait-after-complaining-flag)
1563 "Move backward or forward to the next undeleted message in the buffer.
1564 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and
1565 we are at the last message, then wait for a second after telling
1566 the user that there aren't any more unread messages."
1567 (if (eq mh-next-direction 'forward)
1568 (mh-next-undeleted-msg 1 wait-after-complaining-flag)
1569 (mh-previous-undeleted-msg 1 wait-after-complaining-flag)))
1571 (defun mh-next-unread-msg (&optional count)
1572 "Display next unread message.
1574 This command can be given a prefix argument COUNT to specify how
1575 many unread messages to skip."
1578 (error "The function mh-next-unread-msg expects positive argument"))
1579 (setq count (1- count))
1580 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list))))
1581 (cur-msg (mh-get-msg-num nil)))
1582 (cond ((and (not cur-msg) (not (bobp))
1583 ;; If we are at the end of the buffer back up one line and go
1584 ;; to unread message after that.
1587 (setq cur-msg (mh-get-msg-num nil)))
1589 ((or (null unread-sequence) (not cur-msg))
1590 ;; No unread message or there aren't any messages in buffer...
1591 (message "No more unread messages"))
1594 (while (and unread-sequence (>= cur-msg (car unread-sequence)))
1595 (setq unread-sequence (cdr unread-sequence)))
1597 (setq unread-sequence (cdr unread-sequence))
1598 (setq count (1- count)))
1599 (not (car unread-sequence)))
1600 (message "No more unread messages"))
1601 (t (loop for msg in unread-sequence
1602 when (mh-goto-msg msg t) return nil
1603 finally (message "No more unread messages"))))))
1605 (defun mh-set-scan-mode ()
1606 "Display the scan listing buffer, but do not show a message."
1607 (if (get-buffer mh-show-buffer)
1608 (delete-windows-on mh-show-buffer))
1610 (force-mode-line-update)
1611 (if mh-recenter-summary-flag
1614 (defun mh-undo-msg (msg)
1615 "Undo the deletion or refile of one MSG.
1616 If MSG is nil then act on the message at point"
1619 (mh-goto-msg msg t t)
1621 (setq msg (mh-get-msg-num t)))
1622 (cond ((memq msg mh-delete-list)
1623 (setq mh-delete-list (delq msg mh-delete-list)))
1625 (dolist (folder-msg-list mh-refile-list)
1626 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list))))
1627 (setq mh-refile-list (loop for x in mh-refile-list
1628 unless (null (cdr x)) collect x))))
1629 (mh-notate nil ? mh-cmd-note)))
1633 ;;; The folder data abstraction.
1635 (defvar mh-index-data-file ".mhe_index"
1636 "MH-E specific file where index seach info is stored.")
1638 (defun mh-make-folder (name)
1639 "Create a new mail folder called NAME.
1640 Make it the current folder."
1641 (switch-to-buffer name)
1642 (setq buffer-read-only nil)
1644 (if mh-adaptive-cmd-note-flag
1645 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name))))
1646 (setq buffer-read-only t)
1648 (mh-set-folder-modified-p nil)
1649 (setq buffer-file-name mh-folder-filename)
1650 (when (and (not mh-index-data)
1651 (file-exists-p (concat buffer-file-name mh-index-data-file)))
1652 (mh-index-read-data))
1653 (mh-make-folder-mode-line))
1655 ;; Ensure new buffers won't get this mode if default-major-mode is nil.
1656 (put 'mh-folder-mode 'mode-class 'special)
1660 ;;; Build mh-folder-mode menu
1662 ;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
1663 ;; Menus for folder mode: folder, message, sequence (in that order)
1664 ;; folder-mode "Sequence" menu
1666 mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence."
1668 ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)]
1669 ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)]
1670 ["Delete Message from Sequence..." mh-delete-msg-from-seq
1671 (mh-get-msg-num nil)]
1672 ["List Sequences in Folder..." mh-list-sequences t]
1673 ["Delete Sequence..." mh-delete-seq t]
1674 ["Narrow to Sequence..." mh-narrow-to-seq t]
1675 ["Widen from Sequence" mh-widen mh-folder-view-stack]
1677 ["Narrow to Subject Sequence" mh-narrow-to-subject t]
1678 ["Narrow to Tick Sequence" mh-narrow-to-tick
1679 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))]
1680 ["Delete Rest of Same Subject" mh-delete-subject t]
1681 ["Toggle Tick Mark" mh-toggle-tick t]
1683 ["Push State Out to MH" mh-update-sequences t]))
1685 ;; folder-mode "Message" menu
1687 mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message."
1689 ["Show Message" mh-show (mh-get-msg-num nil)]
1690 ["Show Message with Header" mh-header-display (mh-get-msg-num nil)]
1691 ["Next Message" mh-next-undeleted-msg t]
1692 ["Previous Message" mh-previous-undeleted-msg t]
1693 ["Go to First Message" mh-first-msg t]
1694 ["Go to Last Message" mh-last-msg t]
1695 ["Go to Message by Number..." mh-goto-msg t]
1696 ["Modify Message" mh-modify t]
1697 ["Delete Message" mh-delete-msg (mh-get-msg-num nil)]
1698 ["Refile Message" mh-refile-msg (mh-get-msg-num nil)]
1699 ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)]
1700 ["Execute Delete/Refile" mh-execute-commands
1701 (mh-outstanding-commands-p)]
1703 ["Compose a New Message" mh-send t]
1704 ["Reply to Message..." mh-reply (mh-get-msg-num nil)]
1705 ["Forward Message..." mh-forward (mh-get-msg-num nil)]
1706 ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)]
1707 ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)]
1708 ["Re-edit a Bounced Message" mh-extract-rejected-mail t]
1710 ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)]
1711 ["Print Message" mh-print-msg (mh-get-msg-num nil)]
1712 ["Write Message to File..." mh-write-msg-to-file
1713 (mh-get-msg-num nil)]
1714 ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)]
1715 ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)]
1716 ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)]))
1718 ;; folder-mode "Folder" menu
1720 mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder."
1722 ["Incorporate New Mail" mh-inc-folder t]
1723 ["Toggle Show/Folder" mh-toggle-showing t]
1724 ["Execute Delete/Refile" mh-execute-commands
1725 (mh-outstanding-commands-p)]
1726 ["Rescan Folder" mh-rescan-folder t]
1727 ["Thread Folder" mh-toggle-threads
1728 (not (memq 'unthread mh-view-ops))]
1729 ["Pack Folder" mh-pack-folder t]
1730 ["Sort Folder" mh-sort-folder t]
1732 ["List Folders" mh-list-folders t]
1733 ["Visit a Folder..." mh-visit-folder t]
1734 ["View New Messages" mh-index-new-messages t]
1735 ["Search a Folder..." mh-search-folder t]
1736 ["Indexed Search..." mh-index-search t]
1738 ["Quit MH-E" mh-quit t]))
1742 (defmacro mh-remove-xemacs-horizontal-scrollbar ()
1743 "Get rid of the horizontal scrollbar that XEmacs insists on putting in."
1744 (when mh-xemacs-flag
1745 `(if (and (featurep 'scrollbar)
1746 (fboundp 'set-specifier))
1747 (set-specifier horizontal-scrollbar-visible-p nil
1748 (cons (current-buffer) nil)))))
1750 (defmacro mh-write-file-functions-compat ()
1751 "Return `write-file-functions' if it exists.
1752 Otherwise return `local-write-file-hooks'. This macro exists
1753 purely for compatibility. The former symbol is used in Emacs 21.4
1754 onward while the latter is used in previous versions and XEmacs."
1755 (if (boundp 'write-file-functions)
1756 ''write-file-functions ;Emacs 21.4
1757 ''local-write-file-hooks)) ;<Emacs 21.4, XEmacs
1759 ;; Avoid compiler warnings in non-bleeding edge versions of Emacs.
1761 (defvar tool-bar-mode)
1762 (defvar tool-bar-map)
1763 (defvar desktop-save-buffer)) ;Emacs 21.4
1765 ;; Register mh-folder-mode as supporting which-function-mode...
1766 (load "which-func" t t)
1767 (when (and (boundp 'which-func-modes)
1768 (not (member 'mh-folder-mode which-func-modes)))
1769 (push 'mh-folder-mode which-func-modes))
1771 (defvar mh-folder-buttons-init-flag nil)
1773 ;; Autoload cookie needed by desktop.el
1775 (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder"
1776 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
1778 You can show the message the cursor is pointing to, and step through
1779 the messages. Messages can be marked for deletion or refiling into
1780 another folder; these commands are executed all at once with a
1783 Options that control this mode can be changed with
1784 \\[customize-group]; specify the \"mh\" group. In particular, please
1785 see the `mh-scan-format-file' option if you wish to modify scan's
1788 When a folder is visited, the hook `mh-folder-mode-hook' is run.
1792 Many commands that operate on individual messages, such as
1793 `mh-forward' or `mh-refile-msg' take a RANGE argument. This argument
1794 can be used in several ways.
1796 If you provide the prefix argument (\\[universal-argument]) to
1797 these commands, then you will be prompted for the message range.
1798 This can be any valid MH range which can include messages,
1799 sequences, and the abbreviations (described in the mh(1) man
1803 Indicates all messages in the range <num1> to <num2>, inclusive.
1804 The range must be nonempty.
1809 Up to N messages beginning with (or ending with) message num. Num
1810 may be any of the predefined symbols: first, prev, cur, next or
1817 The first, previous, next or last messages, if they exist.
1820 All of the messages.
1822 For example, a range that shows all of these things is `1 2 3
1823 5-10 last:5 unseen'.
1825 If the option `transient-mark-mode' is set to t and you set a
1826 region in the MH-Folder buffer, then the MH-E command will
1827 perform the operation on all messages in that region.
1829 \\{mh-folder-mode-map}"
1831 (unless mh-folder-buttons-init-flag
1832 (mh-tool-bar-folder-buttons-init)
1833 (setq mh-folder-buttons-init-flag t)))
1834 (make-local-variable 'font-lock-defaults)
1835 (setq font-lock-defaults '(mh-folder-font-lock-keywords t))
1836 (make-local-variable 'desktop-save-buffer)
1837 (setq desktop-save-buffer t)
1839 'mh-colors-available-flag (mh-colors-available-p)
1840 ; Do we have colors available
1841 'mh-current-folder (buffer-name) ; Name of folder, a string
1842 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
1843 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
1844 (file-name-as-directory (mh-expand-file-name (buffer-name)))
1845 'mh-display-buttons-for-inline-parts-flag
1846 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to
1848 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed
1849 'overlay-arrow-position nil ; Allow for simultaneous display in
1850 'overlay-arrow-string ">" ; different MH-E buffers.
1851 'mh-showing-mode nil ; Show message also?
1852 'mh-delete-list nil ; List of msgs nums to delete
1853 'mh-refile-list nil ; List of folder names in mh-seq-list
1854 'mh-seq-list nil ; Alist of (seq . msgs) nums
1855 'mh-seen-list nil ; List of displayed messages
1856 'mh-next-direction 'forward ; Direction to move to next message
1857 'mh-view-ops () ; Stack that keeps track of the order
1858 ; in which narrowing/threading has been
1860 'mh-folder-view-stack () ; Stack of previous views of the
1862 'mh-index-data nil ; If the folder was created by a call
1863 ; to mh-index-search this contains info
1864 ; about the search results.
1865 'mh-index-previous-search nil ; Previous folder and search-regexp
1866 'mh-index-msg-checksum-map nil ; msg -> checksum map
1867 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg )
1868 'mh-index-sequence-search-flag nil ; folder resulted from sequence search
1869 'mh-first-msg-num nil ; Number of first msg in buffer
1870 'mh-last-msg-num nil ; Number of last msg in buffer
1871 'mh-msg-count nil ; Number of msgs in buffer
1872 'mh-mode-line-annotation nil ; Indicates message range
1873 'mh-sequence-notation-history (make-hash-table)
1874 ; Remember what is overwritten by
1876 'imenu-create-index-function 'mh-index-create-imenu-index
1877 ; Setup imenu support
1878 'mh-previous-window-config nil) ; Previous window configuration
1879 (mh-remove-xemacs-horizontal-scrollbar)
1880 (setq truncate-lines t)
1882 (setq buffer-offer-save t)
1883 (mh-make-local-hook (mh-write-file-functions-compat))
1884 (add-hook (mh-write-file-functions-compat) 'mh-execute-commands nil t)
1885 (make-local-variable 'revert-buffer-function)
1886 (make-local-variable 'hl-line-mode) ; avoid pollution
1887 (mh-funcall-if-exists hl-line-mode 1)
1888 (setq revert-buffer-function 'mh-undo-folder)
1889 (or (assq 'mh-showing-mode minor-mode-alist)
1890 (setq minor-mode-alist
1891 (cons '(mh-showing-mode " Show") minor-mode-alist)))
1892 (easy-menu-add mh-folder-sequence-menu)
1893 (easy-menu-add mh-folder-message-menu)
1894 (easy-menu-add mh-folder-folder-menu)
1895 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)
1896 (mh-funcall-if-exists mh-tool-bar-init :folder)
1897 (if (and mh-xemacs-flag
1898 font-lock-auto-fontify)
1899 (turn-on-font-lock))) ; Force font-lock in XEmacs.
1901 (defun mh-toggle-mime-buttons ()
1902 "Toggle option `mh-display-buttons-for-inline-parts-flag'."
1904 (setq mh-display-buttons-for-inline-parts-flag
1905 (not mh-display-buttons-for-inline-parts-flag))
1908 (defun mh-colors-available-p ()
1909 "Check if colors are available in the Emacs being used."
1912 (or (ignore-errors (mh-funcall-if-exists display-color-cells))
1913 (ignore-errors (mh-funcall-if-exists
1914 x-display-color-cells)))))
1915 (and (numberp color-cells) (>= color-cells 8)))))
1917 (defun mh-colors-in-use-p ()
1918 "Check if colors are being used in the folder buffer."
1919 (and mh-colors-available-flag font-lock-mode))
1921 (defun mh-make-local-vars (&rest pairs)
1922 "Initialize local variables according to the variable-value PAIRS."
1925 (set (make-local-variable (car pairs)) (car (cdr pairs)))
1926 (setq pairs (cdr (cdr pairs)))))
1928 (defun mh-restore-desktop-buffer (desktop-buffer-file-name
1930 desktop-buffer-misc)
1931 "Restore an MH folder buffer specified in a desktop file.
1932 When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the
1933 file name to visit, DESKTOP-BUFFER-NAME holds the desired buffer
1934 name, and DESKTOP-BUFFER-MISC holds a list of miscellaneous info
1935 used by the `desktop-buffer-handlers' functions."
1937 (mh-visit-folder desktop-buffer-name)
1940 ;; desktop-buffer-mode-handlers appeared in Emacs 22.
1941 (if (fboundp 'desktop-buffer-mode-handlers)
1942 (add-to-list 'desktop-buffer-mode-handlers
1943 '(mh-folder-mode . mh-restore-desktop-buffer)))
1945 (defun mh-scan-folder (folder range &optional dont-exec-pending)
1946 "Scan FOLDER over RANGE.
1948 After the scan is performed, switch to the buffer associated with
1951 Check the documentation of `mh-interactive-range' to see how RANGE is
1952 read in interactive use.
1954 The processing of outstanding commands is not performed if
1955 DONT-EXEC-PENDING is non-nil."
1956 (when (stringp range)
1957 (setq range (delete "" (split-string range "[ \t\n]"))))
1958 (cond ((null (get-buffer folder))
1959 (mh-make-folder folder))
1961 (unless dont-exec-pending
1962 (mh-process-or-undo-commands folder)
1963 (mh-reset-threads-and-narrowing))
1964 (switch-to-buffer folder)))
1965 (mh-regenerate-headers range)
1966 (if (zerop (buffer-size))
1967 (if (equal range "all")
1968 (message "Folder %s is empty" folder)
1969 (message "No messages in %s, range %s" folder range))
1971 (when (mh-outstanding-commands-p)
1972 (mh-notate-deleted-and-refiled)))
1974 (defun mh-msg-num-width-to-column (width)
1975 "Return the column for notations given message number WIDTH.
1976 Note that columns in Emacs start with 0.
1978 If `mh-scan-format-file' is set to \"Use MH-E scan Format\" this
1979 means that either `mh-scan-format-mh' or `mh-scan-format-nmh' are
1980 in use. This function therefore assumes that the first column is
1981 empty (to provide room for the cursor), the following WIDTH
1982 columns contain the message number, and the column for notations
1984 (if (eq mh-scan-format-file t)
1986 (error "%s %s" "Can't call mh-msg-num-width-to-column"
1987 "when mh-scan-format-file is not t")))
1989 (defun mh-set-cmd-note (column)
1990 "Set `mh-cmd-note' to COLUMN.
1991 Note that columns in Emacs start with 0."
1992 (setq mh-cmd-note column))
1994 (defun mh-regenerate-headers (range &optional update)
1995 "Scan folder over RANGE.
1996 If UPDATE, append the scan lines, otherwise replace."
1997 (let ((folder mh-current-folder)
1998 (range (if (and range (atom range)) (list range) range))
2000 (message "Scanning %s..." folder)
2001 (mh-remove-all-notation)
2002 (with-mh-folder-updating (nil)
2004 (goto-char (point-max))
2005 (delete-region (point-min) (point-max))
2006 (if mh-adaptive-cmd-note-flag
2007 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width
2009 (setq scan-start (point))
2010 (apply #'mh-exec-cmd-output
2013 "-noclear" "-noheader"
2014 "-width" (window-width)
2016 (goto-char scan-start)
2017 (cond ((looking-at "scan: no messages in")
2018 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines
2019 ((looking-at (if (mh-variant-p 'mu-mh)
2020 "scan: message set .* does not exist"
2021 "scan: bad message list "))
2022 (keep-lines mh-scan-valid-regexp))
2023 ((looking-at "scan: ")) ; Keep error messages
2025 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines
2026 (setq mh-seq-list (mh-read-folder-sequences folder nil))
2027 (mh-notate-user-sequences)
2029 (setq mh-mode-line-annotation
2030 (if (equal range '("all"))
2032 mh-partial-folder-mode-line-annotation)))
2033 (mh-make-folder-mode-line))
2034 (message "Scanning %s...done" folder)))
2036 (defun mh-generate-new-cmd-note (folder)
2037 "Fix the `mh-cmd-note' value for this FOLDER.
2039 After doing an `mh-get-new-mail' operation in this FOLDER, at least
2040 one line that looks like a truncated message number was found.
2042 Remove the text added by the last `mh-inc' command. It should be the
2043 messages cur-last. Call `mh-set-cmd-note', adjusting the notation
2044 column with the width of the largest message number in FOLDER.
2046 Reformat the message number width on each line in the buffer and trim
2047 the line length to fit in the window.
2049 Rescan the FOLDER in the range cur-last in order to display the
2050 messages that were removed earlier. They should all fit in the scan
2051 line now with no message truncation."
2053 (let ((maxcol (1- (window-width)))
2054 (old-cmd-note mh-cmd-note)
2057 ;; Nuke all of the lines just added by the last inc
2058 (delete-char (- (point-max) (point)))
2059 ;; Update the current buffer to reflect the new mh-cmd-note
2060 ;; value needed to display messages.
2061 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder)))
2062 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d"))
2063 ;; Cleanup the messages that are in the buffer right now
2064 (goto-char (point-min))
2065 (cond ((memq 'unthread mh-view-ops)
2066 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note)))
2067 (t (while (re-search-forward mh-scan-msg-number-regexp nil 0 1)
2068 ;; reformat the number to fix in mh-cmd-note columns
2069 (setq msgnum (string-to-number
2071 (match-beginning 1) (match-end 1))))
2072 (replace-match (format mh-cmd-note-fmt msgnum))
2073 ;; trim the line to fix in the window
2075 (let ((eol (point)))
2076 (move-to-column maxcol)
2077 (if (<= (point) eol)
2078 (delete-char (- eol (point))))))))
2079 ;; now re-read the lost messages
2080 (goto-char (point-max))
2082 (mh-regenerate-headers "cur-last" t)))))
2084 (defun mh-get-new-mail (maildrop-name)
2085 "Read new mail from MAILDROP-NAME into the current buffer.
2086 Return in the current buffer."
2087 (let ((point-before-inc (point))
2088 (folder mh-current-folder)
2089 (new-mail-flag nil))
2090 (with-mh-folder-updating (t)
2092 (message "inc %s -file %s..." folder maildrop-name)
2093 (message "inc %s..." folder))
2094 (setq mh-next-direction 'forward)
2095 (goto-char (point-max))
2096 (mh-remove-cur-notation)
2097 (let ((start-of-inc (point)))
2099 ;; I think MH 5 used "-ms-file" instead of "-file",
2100 ;; which would make inc'ing from maildrops fail.
2101 (mh-exec-cmd-output mh-inc-prog nil folder
2103 "-file" (expand-file-name maildrop-name)
2104 "-width" (window-width)
2106 (mh-exec-cmd-output mh-inc-prog nil
2108 "-width" (window-width)))
2110 (message "inc %s -file %s...done" folder maildrop-name)
2111 (message "inc %s...done" folder))
2112 (goto-char start-of-inc)
2113 (cond ((save-excursion
2114 (re-search-forward "^inc: no mail" nil t))
2115 (message "No new mail%s%s" (if maildrop-name " in " "")
2116 (if maildrop-name maildrop-name "")))
2117 ((and (when mh-folder-view-stack
2118 (let ((saved-text (buffer-substring-no-properties
2119 start-of-inc (point-max))))
2120 (delete-region start-of-inc (point-max))
2121 (unwind-protect (mh-widen t)
2122 (mh-remove-cur-notation)
2123 (goto-char (point-max))
2124 (setq start-of-inc (point))
2126 (goto-char start-of-inc))))
2128 ((re-search-forward "^inc:" nil t) ; Error messages
2129 (error "Error incorporating mail"))
2131 (equal mh-scan-format-file t)
2132 mh-adaptive-cmd-note-flag
2133 ;; Have we reached an edge condition?
2135 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1))
2136 (setq start-of-inc (mh-generate-new-cmd-note folder))
2139 (setq new-mail-flag t)))
2140 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines
2141 (let* ((sequences (mh-read-folder-sequences folder t))
2142 (new-cur (assoc 'cur sequences))
2143 (new-unseen (assoc mh-unseen-seq sequences)))
2144 (unless (assoc 'cur mh-seq-list)
2145 (push (list 'cur) mh-seq-list))
2146 (unless (assoc mh-unseen-seq mh-seq-list)
2147 (push (list mh-unseen-seq) mh-seq-list))
2148 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur))
2149 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen)))
2150 (when (equal (point-max) start-of-inc)
2154 (mh-make-folder-mode-line)
2155 (when (mh-speed-flists-active-p)
2156 (mh-speed-flists t mh-current-folder))
2157 (when (memq 'unthread mh-view-ops)
2158 (mh-thread-inc folder start-of-inc))
2160 (goto-char point-before-inc))
2161 (mh-notate-user-sequences (cons start-of-inc (point-max)))))))
2163 (defun mh-make-folder-mode-line (&optional ignored)
2164 "Set the fields of the mode line for a folder buffer.
2165 The optional argument is now obsolete and IGNORED. It used to be
2166 used to pass in what is now stored in the buffer-local variable
2167 `mh-mode-line-annotation'."
2169 (save-window-excursion
2171 (let ((new-first-msg-num (mh-get-msg-num nil)))
2172 (when (or (not (memq 'unthread mh-view-ops))
2173 (null mh-first-msg-num)
2174 (null new-first-msg-num)
2175 (< new-first-msg-num mh-first-msg-num))
2176 (setq mh-first-msg-num new-first-msg-num)))
2178 (let ((new-last-msg-num (mh-get-msg-num nil)))
2179 (when (or (not (memq 'unthread mh-view-ops))
2180 (null mh-last-msg-num)
2181 (null new-last-msg-num)
2182 (> new-last-msg-num mh-last-msg-num))
2183 (setq mh-last-msg-num new-last-msg-num)))
2184 (setq mh-msg-count (if mh-first-msg-num
2185 (count-lines (point-min) (point-max))
2187 (setq mode-line-buffer-identification
2188 (list (format " {%%b%s} %s msg%s"
2189 (if mh-mode-line-annotation
2190 (format "/%s" mh-mode-line-annotation)
2192 (if (zerop mh-msg-count)
2194 (format "%d" mh-msg-count))
2195 (if (zerop mh-msg-count)
2197 (cond ((> mh-msg-count 1)
2198 (format "s (%d-%d)" mh-first-msg-num
2201 (format " (%d)" mh-first-msg-num))
2203 (mh-logo-display))))
2205 (defun mh-add-sequence-notation (msg internal-seq-flag)
2206 "Add sequence notation to the MSG on the current line.
2207 If INTERNAL-SEQ-FLAG is non-nil, then refontify the scan line if
2208 font-lock is turned on."
2209 (with-mh-folder-updating (t)
2212 (if internal-seq-flag
2214 ;; Change the buffer so that if transient-mark-mode is active
2215 ;; and there is an active region it will get deactivated as in
2216 ;; the case of user sequences.
2217 (mh-notate nil nil mh-cmd-note)
2218 (when font-lock-mode
2219 (font-lock-fontify-region (point) (line-end-position))))
2220 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2221 (let ((stack (gethash msg mh-sequence-notation-history)))
2222 (setf (gethash msg mh-sequence-notation-history)
2223 (cons (char-after) stack)))
2224 (mh-notate nil mh-note-seq
2225 (+ mh-cmd-note mh-scan-field-destination-offset))))))
2227 (defun mh-remove-sequence-notation (msg internal-seq-flag &optional all)
2228 "Remove sequence notation from the MSG on the current line.
2229 If INTERNAL-SEQ-FLAG is non-nil, then `font-lock' was used to
2230 highlight the sequence. In that case, no notation needs to be removed.
2231 Otherwise the effect of inserting `mh-note-seq' needs to be reversed.
2232 If ALL is non-nil, then all sequence marks on the scan line are
2234 (with-mh-folder-updating (t)
2235 ;; This takes care of internal sequences...
2236 (mh-notate nil nil mh-cmd-note)
2237 (unless internal-seq-flag
2238 ;; ... and this takes care of user sequences.
2239 (let ((stack (gethash msg mh-sequence-notation-history)))
2240 (while (and all (cdr stack))
2241 (setq stack (cdr stack)))
2245 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2247 (insert (car stack))))
2248 (setf (gethash msg mh-sequence-notation-history) (cdr stack))))))
2250 (defun mh-remove-cur-notation ()
2251 "Remove old cur notation."
2252 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2255 (mh-goto-msg cur-msg t t)
2256 (looking-at mh-scan-cur-msg-number-regexp))
2257 (mh-notate nil ? mh-cmd-note)
2258 (setq overlay-arrow-position nil)))))
2260 (defun mh-remove-all-notation ()
2261 "Remove all notations on all scan lines that MH-E introduces."
2263 (setq overlay-arrow-position nil)
2264 (goto-char (point-min))
2265 (mh-iterate-on-range msg (cons (point-min) (point-max))
2266 (mh-notate nil ? mh-cmd-note)
2267 (mh-remove-sequence-notation msg nil t))
2268 (clrhash mh-sequence-notation-history)))
2271 (defun mh-goto-cur-msg (&optional minimal-changes-flag)
2272 "Position the cursor at the current message.
2273 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the
2274 function doesn't recenter the folder buffer."
2275 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2277 (mh-goto-msg cur-msg t t))
2278 (unless minimal-changes-flag
2281 (mh-maybe-show cur-msg)))
2283 (setq overlay-arrow-position nil)
2284 (message "No current message")))))
2286 (defun mh-process-or-undo-commands (folder)
2287 "If FOLDER has outstanding commands, then either process or discard them.
2288 Called by functions like `mh-sort-folder', so also invalidate
2291 (if (mh-outstanding-commands-p)
2292 (if (or mh-do-not-confirm-flag
2294 "Process outstanding deletes and refiles? "))
2295 (mh-process-commands folder)
2299 (mh-invalidate-show-buffer))
2301 (defun mh-process-commands (folder)
2302 "Process outstanding commands for FOLDER.
2304 This function runs `mh-before-commands-processed-hook' before the
2305 commands are processed and `mh-after-commands-processed-hook'
2306 after the commands are processed."
2307 (message "Processing deletes and refiles for %s..." folder)
2309 (with-mh-folder-updating (nil)
2310 ;; Run the before hook -- the refile and delete lists are still valid
2311 (run-hooks 'mh-before-commands-processed-hook)
2313 ;; Update the unseen sequence if it exists
2316 (let ((redraw-needed-flag mh-index-data)
2317 (folders-changed (list mh-current-folder))
2318 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag
2319 (mh-create-sequence-map mh-seq-list)))
2320 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag
2321 (make-hash-table))))
2322 ;; Remove invalid scan lines if we are in an index folder and then remove
2323 ;; the real messages
2325 (mh-index-delete-folder-headers)
2326 (setq folders-changed
2327 (append folders-changed (mh-index-execute-commands))))
2329 ;; Then refile messages
2330 (mh-mapc #'(lambda (folder-msg-list)
2331 (let* ((dest-folder (symbol-name (car folder-msg-list)))
2332 (last (car (mh-translate-range dest-folder "last")))
2333 (msgs (cdr folder-msg-list)))
2334 (push dest-folder folders-changed)
2335 (setq redraw-needed-flag t)
2336 (apply #'mh-exec-cmd
2337 "refile" "-src" folder dest-folder
2338 (mh-coalesce-msg-list msgs))
2339 (mh-delete-scan-msgs msgs)
2340 ;; Preserve sequences in destination folder...
2341 (when mh-refile-preserves-sequences-flag
2343 (loop for i from (1+ (or last 0))
2344 for msg in (sort (copy-sequence msgs) #'<)
2345 do (loop for seq-name in (gethash msg seq-map)
2346 do (push i (gethash seq-name dest-map))))
2348 #'(lambda (seq msgs)
2349 ;; Can't be run in the background, since the
2350 ;; current folder is changed by mark this could
2351 ;; lead to a race condition with the next refile.
2352 (apply #'mh-exec-cmd "mark"
2353 "-sequence" (symbol-name seq) dest-folder
2354 "-add" (mapcar #'(lambda (x) (format "%s" x))
2355 (mh-coalesce-msg-list msgs))))
2358 (setq mh-refile-list ())
2360 ;; Now delete messages
2361 (cond (mh-delete-list
2362 (setq redraw-needed-flag t)
2363 (apply 'mh-exec-cmd "rmm" folder
2364 (mh-coalesce-msg-list mh-delete-list))
2365 (mh-delete-scan-msgs mh-delete-list)
2366 (setq mh-delete-list nil)))
2368 ;; Don't need to remove sequences since delete and refile do so.
2370 (if (> (buffer-size) 0)
2371 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last"))))
2373 ;; Redraw folder buffer if needed
2374 (when (and redraw-needed-flag)
2375 (when (mh-speed-flists-active-p)
2376 (apply #'mh-speed-flists t folders-changed))
2377 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max)))
2378 (mh-index-data (mh-index-insert-folder-headers))))
2380 (and (buffer-file-name (get-buffer mh-show-buffer))
2381 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
2382 ;; If "inc" were to put a new msg in this file,
2383 ;; we would not notice, so mark it invalid now.
2384 (mh-invalidate-show-buffer))
2386 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
2387 (mh-remove-all-notation)
2388 (mh-notate-user-sequences)
2390 ;; Run the after hook -- now folders-changed is valid,
2391 ;; but not the lists of specific messages.
2392 (let ((mh-folders-changed folders-changed))
2393 (run-hooks 'mh-after-commands-processed-hook)))
2395 (message "Processing deletes and refiles for %s...done" folder)))
2397 (defun mh-update-unseen ()
2398 "Synchronize the unseen sequence with MH.
2399 Return non-nil iff the MH folder was set.
2400 The hook `mh-unseen-updated-hook' is called after the unseen sequence
2403 (let* ((unseen-seq (mh-find-seq mh-unseen-seq))
2404 (unseen-msgs (mh-seq-msgs unseen-seq)))
2407 (mh-undefine-sequence mh-unseen-seq mh-seen-list)
2408 (run-hooks 'mh-unseen-updated-hook)
2410 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs))
2411 (setq mh-seen-list (cdr mh-seen-list)))
2412 (setcdr unseen-seq unseen-msgs)
2413 t) ;since we set the folder
2414 (setq mh-seen-list nil)))))
2416 (defun mh-delete-scan-msgs (msgs)
2417 "Delete the scan listing lines for MSGS."
2420 (when (mh-goto-msg (car msgs) t t)
2421 (when (memq 'unthread mh-view-ops)
2422 (mh-thread-forget-message (car msgs)))
2424 (setq msgs (cdr msgs)))))
2426 (defun mh-outstanding-commands-p ()
2427 "Return non-nil if there are outstanding deletes or refiles."
2429 (when (eq major-mode 'mh-show-mode)
2430 (set-buffer mh-show-folder-buffer))
2431 (or mh-delete-list mh-refile-list)))
2433 (defun mh-coalesce-msg-list (messages)
2434 "Given a list of MESSAGES, return a list of message number ranges.
2435 This is the inverse of `mh-read-msg-list', which expands ranges.
2436 Message lists passed to MH programs should be processed by this
2437 function to avoid exceeding system command line argument limits."
2438 (let ((msgs (sort (copy-sequence messages) 'mh-greaterp))
2444 (if (or (not (numberp prev))
2445 (not (equal (car msgs) (1- prev))))
2446 (progn ;non-sequential, flush old range
2447 (if (eq prev range-high)
2448 (setq ranges (cons range-high ranges))
2449 (setq ranges (cons (format "%s-%s" prev range-high) ranges)))
2450 (setq range-high nil))))
2452 (setq range-high (car msgs))) ;start new or first range
2453 (setq prev (car msgs))
2454 (setq msgs (cdr msgs)))
2457 (defun mh-greaterp (msg1 msg2)
2458 "Return the greater of two message indicators MSG1 and MSG2.
2459 Strings are \"smaller\" than numbers.
2460 Valid values are things like \"cur\", \"last\", 1, and 1820."
2467 (string-lessp msg2 msg1))))
2469 (defun mh-lessp (msg1 msg2)
2470 "Return the lesser of two message indicators MSG1 and MSG2.
2471 Strings are \"smaller\" than numbers.
2472 Valid values are things like \"cur\", \"last\", 1, and 1820."
2473 (not (mh-greaterp msg1 msg2)))
2477 ;;; Basic sequence handling
2479 (defun mh-delete-seq-locally (seq)
2480 "Remove MH-E's record of SEQ."
2481 (let ((entry (mh-find-seq seq)))
2482 (setq mh-seq-list (delq entry mh-seq-list))))
2484 (defun mh-read-folder-sequences (folder save-refiles)
2485 "Read and return the predefined sequences for a FOLDER.
2486 If SAVE-REFILES is non-nil, then keep the sequences
2487 that note messages to be refiled."
2490 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
2491 (if (mh-folder-name-p (mh-seq-name seq))
2492 (setq seqs (cons seq seqs)))))
2495 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
2497 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
2498 (while (re-search-forward "^[^: ]+" nil t)
2499 (setq seqs (cons (mh-make-seq (intern (buffer-substring
2504 (delete-region (point-min) (point))))) ; avoid race with
2508 (defun mh-read-msg-list ()
2509 "Return a list of message numbers from point to the end of the line.
2510 Expands ranges into set of individual numbers."
2512 (end-of-line (save-excursion (end-of-line) (point)))
2514 (while (re-search-forward "[0-9]+" end-of-line t)
2515 (setq num (string-to-number (buffer-substring (match-beginning 0)
2517 (cond ((looking-at "-") ; Message range
2519 (re-search-forward "[0-9]+" end-of-line t)
2520 (let ((num2 (string-to-number
2521 (buffer-substring (match-beginning 0)
2524 (error "Bad message range: %d-%d" num num2))
2525 (while (<= num num2)
2526 (setq msgs (cons num msgs))
2527 (setq num (1+ num)))))
2528 ((not (zerop num)) ;"pick" outputs "0" to mean no match
2529 (setq msgs (cons num msgs)))))
2532 (defun mh-notate-user-sequences (&optional range)
2533 "Mark user-defined sequences in RANGE.
2535 Check the documentation of `mh-interactive-range' to see how
2536 RANGE is read in interactive use; if nil all messages are
2539 (setq range (cons (point-min) (point-max))))
2540 (let ((seqs mh-seq-list)
2541 (msg-hash (make-hash-table)))
2543 (dolist (msg (mh-seq-msgs seq))
2544 (push (car seq) (gethash msg msg-hash))))
2545 (mh-iterate-on-range msg range
2546 (loop for seq in (gethash msg msg-hash)
2547 do (mh-add-sequence-notation msg (mh-internal-seq seq))))))
2549 (defvar mh-internal-seqs '(answered cur deleted forwarded printed))
2551 (defun mh-internal-seq (name)
2552 "Return non-nil if NAME is the name of an internal MH-E sequence."
2553 (or (memq name mh-internal-seqs)
2554 (eq name mh-unseen-seq)
2555 (and (mh-colors-in-use-p) mh-tick-seq (eq name mh-tick-seq))
2556 (eq name mh-previous-seq)
2557 (mh-folder-name-p name)))
2559 (defun mh-valid-seq-p (name)
2560 "Return non-nil if NAME is a valid MH sequence name."
2562 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" (symbol-name name))))
2564 (defun mh-delete-msg-from-seq (range sequence &optional internal-flag)
2565 "Delete RANGE from SEQUENCE.
2567 Check the documentation of `mh-interactive-range' to see how
2568 RANGE is read in interactive use.
2570 In a program, non-nil INTERNAL-FLAG means do not inform MH of the
2572 (interactive (list (mh-interactive-range "Delete")
2573 (mh-read-seq-default "Delete from" t)
2575 (let ((entry (mh-find-seq sequence))
2576 (user-sequence-flag (not (mh-internal-seq sequence)))
2577 (folders-changed (list mh-current-folder))
2580 (mh-iterate-on-range msg range
2582 ;; Calling "mark" repeatedly takes too long. So we will pretend here
2583 ;; that we are just modifying an internal sequence...
2584 (when (memq msg (cdr entry))
2585 (mh-remove-sequence-notation msg (not user-sequence-flag)))
2586 (mh-delete-a-msg-from-seq msg sequence t))
2587 ;; ... and here we will "mark" all the messages at one go.
2588 (unless internal-flag (mh-undefine-sequence sequence msg-list))
2589 (when (and mh-index-data (not internal-flag))
2590 (setq folders-changed
2591 (append folders-changed
2592 (mh-index-delete-from-sequence sequence msg-list))))
2593 (when (and (eq sequence mh-unseen-seq) (mh-speed-flists-active-p))
2594 (apply #'mh-speed-flists t folders-changed)))))
2596 (defun mh-catchup (range)
2597 "Delete RANGE from the \"unseen\" sequence.
2599 Check the documentation of `mh-interactive-range' to see how
2600 RANGE is read in interactive use."
2601 (interactive (list (mh-interactive-range "Catchup"
2602 (cons (point-min) (point-max)))))
2603 (mh-delete-msg-from-seq range mh-unseen-seq))
2605 (defun mh-delete-a-msg-from-seq (msg sequence internal-flag)
2606 "Delete MSG from SEQUENCE.
2607 If INTERNAL-FLAG is non-nil, then do not inform MH of the
2609 (let ((entry (mh-find-seq sequence)))
2610 (when (and entry (memq msg (mh-seq-msgs entry)))
2611 (if (not internal-flag)
2612 (mh-undefine-sequence sequence (list msg)))
2613 (setcdr entry (delq msg (mh-seq-msgs entry))))))
2615 (defun mh-undefine-sequence (seq msgs)
2616 "Remove from the SEQ the list of MSGS."
2617 (when (and (mh-valid-seq-p seq) msgs)
2618 (apply #'mh-exec-cmd "mark" mh-current-folder "-delete"
2619 "-sequence" (symbol-name seq) (mh-coalesce-msg-list msgs))))
2621 (defun mh-define-sequence (seq msgs)
2622 "Define the SEQ to contain the list of MSGS.
2623 Do not mark pseudo-sequences or empty sequences.
2624 Signals an error if SEQ is an invalid name."
2626 (mh-valid-seq-p seq)
2627 (not (mh-folder-name-p seq)))
2629 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
2630 "-sequence" (symbol-name seq)
2631 (mh-coalesce-msg-list msgs)))))
2633 (defun mh-seq-containing-msg (msg &optional include-internal-flag)
2634 "Return a list of the sequences containing MSG.
2635 If INCLUDE-INTERNAL-FLAG non-nil, include MH-E internal sequences
2637 (let ((l mh-seq-list)
2640 (and (memq msg (mh-seq-msgs (car l)))
2641 (or include-internal-flag
2642 (not (mh-internal-seq (mh-seq-name (car l)))))
2643 (setq seqs (cons (mh-seq-name (car l)) seqs)))
2649 ;;; Build mh-folder-mode keymap:
2651 (suppress-keymap mh-folder-mode-map)
2653 ;; Use defalias to make sure the documented primary key bindings
2654 ;; appear in menu lists.
2655 (defalias 'mh-alt-show 'mh-show)
2656 (defalias 'mh-alt-refile-msg 'mh-refile-msg)
2657 (defalias 'mh-alt-send 'mh-send)
2658 (defalias 'mh-alt-visit-folder 'mh-visit-folder)
2660 ;; Save the "b" binding for a future `back'. Maybe?
2661 (gnus-define-keys mh-folder-mode-map
2663 "!" mh-refile-or-write-again
2665 "," mh-header-display
2667 ";" mh-toggle-mh-decode-mime-flag
2668 ">" mh-write-msg-to-file
2670 "E" mh-extract-rejected-mail
2672 "\177" mh-previous-page
2673 "\C-d" mh-delete-msg-no-motion
2674 "\t" mh-index-next-folder
2675 [backtab] mh-index-previous-folder
2676 "\M-\t" mh-index-previous-folder
2679 "\ed" mh-redistribute
2681 "^" mh-alt-refile-msg
2688 "k" mh-delete-subject-or-thread
2690 "n" mh-next-undeleted-msg
2691 "\M-n" mh-next-unread-msg
2693 "p" mh-previous-undeleted-msg
2694 "\M-p" mh-previous-unread-msg
2698 "t" mh-toggle-showing
2700 "v" mh-index-visit-folder
2701 "x" mh-execute-commands
2704 (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map)
2706 "'" mh-index-ticked-messages
2709 "f" mh-alt-visit-folder
2713 "n" mh-index-new-messages
2714 "o" mh-alt-visit-folder
2716 "q" mh-index-sequenced-messages
2717 "r" mh-rescan-folder
2718 "s" mh-search-folder
2720 "v" mh-visit-folder)
2722 (define-key mh-folder-mode-map "I" mh-inc-spool-map)
2724 (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map)
2726 "b" mh-junk-blacklist
2727 "w" mh-junk-whitelist)
2729 (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map)
2731 "C" mh-ps-print-toggle-color
2732 "F" mh-ps-print-toggle-faces
2733 "f" mh-ps-print-msg-file
2735 "p" mh-ps-print-msg)
2737 (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map)
2738 "'" mh-narrow-to-tick
2740 "d" mh-delete-msg-from-seq
2742 "l" mh-list-sequences
2743 "n" mh-narrow-to-seq
2744 "p" mh-put-msg-in-seq
2745 "s" mh-msg-is-in-seq
2748 (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map)
2750 "u" mh-thread-ancestor
2751 "p" mh-thread-previous-sibling
2752 "n" mh-thread-next-sibling
2753 "t" mh-toggle-threads
2754 "d" mh-thread-delete
2755 "o" mh-thread-refile)
2757 (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map)
2758 "'" mh-narrow-to-tick
2761 "f" mh-narrow-to-from
2762 "r" mh-narrow-to-range
2763 "s" mh-narrow-to-subject
2767 (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map)
2769 "s" mh-store-msg ;shar
2770 "u" mh-store-msg) ;uuencode
2772 (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map)
2775 "\177" mh-page-digest-backwards
2776 "b" mh-burst-digest)
2778 (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map)
2780 "a" mh-mime-save-parts
2781 "e" mh-display-with-external-viewer
2782 "i" mh-folder-inline-mime-part
2783 "o" mh-folder-save-mime-part
2784 "t" mh-toggle-mime-buttons
2785 "v" mh-folder-toggle-mime-part
2787 [backtab] mh-prev-button
2788 "\M-\t" mh-prev-button)
2792 (define-key mh-folder-mode-map [button2] 'mh-show-mouse))
2794 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse)))
2796 ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt
2802 ;; If you add a new prefix, add appropriate text to the nil key.
2804 ;; In general, messages are grouped logically. Taking the main commands for
2805 ;; example, the first line is "ways to view messages," the second line is
2806 ;; "things you can do with messages", and the third is "composing" messages.
2808 ;; When adding a new prefix, ensure that the help message contains "what" the
2809 ;; prefix is for. For example, if the word "folder" were not present in the
2810 ;; "F" entry, it would not be clear what these commands operated upon.
2811 (defvar mh-help-messages
2812 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n"
2813 "[d]elete, [o]refile, e[x]ecute,\n"
2814 "[s]end, [r]eply,\n"
2815 "[;]toggle MIME decoding.\n"
2816 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys,"
2817 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.")
2819 (?F "[l]ist; [v]isit folder;\n"
2820 "[n]ew messages; [']ticked messages; [s]earch; [i]ndexed search;\n"
2821 "[p]ack; [S]ort; [r]escan; [k]ill")
2822 (?P "[p]rint message to [f]ile; old-style [l]pr printing;\n"
2823 "Toggle printing of [C]olors, [F]aces")
2824 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n"
2825 "[s]equences, [l]ist,\n"
2826 "[d]elete message from sequence, [k]ill sequence")
2827 (?T "[t]oggle, [d]elete, [o]refile thread")
2828 (?/ "Limit to [c]c, [f]rom, [r]ange, [s]ubject, [t]o; [w]iden")
2829 (?X "un[s]har, [u]udecode message")
2830 (?D "[b]urst digest")
2831 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n"
2832 "[TAB] next; [SHIFT-TAB] previous")
2833 (?J "[b]lacklist, [w]hitelist message"))
2834 "Key binding cheat sheet.
2836 This is an associative array which is used to show the most common commands.
2837 The key is a prefix char. The value is one or more strings which are
2838 concatenated together and displayed in the minibuffer if ? is pressed after
2839 the prefix character. The special key nil is used to display the
2840 non-prefixed commands.
2842 The substitutions described in `substitute-command-keys' are performed as
2847 (dolist (mess '("^Cursor not pointing to message$"
2848 "^There is no other window$"))
2849 (add-to-list 'debug-ignored-errors mess))
2854 ;; indent-tabs-mode: nil
2855 ;; sentence-end-double-space: nil
2858 ;; arch-tag: cce884de-bd37-4104-9963-e4439d5ed22b
2859 ;;; mh-e.el ends here