1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system
3 ;; Copyright (C) 1985, 1986, 1987, 1988,
4 ;; 1990, 1992, 1993, 1994, 1995, 1997, 1999,
5 ;; 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
7 ;; Author: Bill Wohler <wohler@newt.com>
8 ;; Maintainer: Bill Wohler <wohler@newt.com>
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
32 ;; M-x mh-rmail to read mail. Type C-h m there for a list of commands.
33 ;; C-u M-x mh-rmail to visit any folder.
34 ;; M-x mh-smail to send mail. From within the mail reader, "m" works, too.
36 ;; Your .emacs might benefit from these bindings:
37 ;; (global-set-key "\C-cr" 'mh-rmail)
38 ;; (global-set-key "\C-xm" 'mh-smail)
39 ;; (global-set-key "\C-x4m" 'mh-smail-other-window)
41 ;; MH (Message Handler) is a powerful mail reader.
43 ;; The MH newsgroup is comp.mail.mh; the mailing list is mh-users@ics.uci.edu
44 ;; (send to mh-users-request to be added). See the monthly Frequently Asked
45 ;; Questions posting there for information on getting MH and MH-E:
46 ;; http://www.faqs.org/faqs/mail/mh-faq/part1/preamble.html
48 ;; N.B. MH must have been compiled with the MHE compiler flag or several
49 ;; features necessary for MH-E will be missing from MH commands, specifically
50 ;; the -build switch to repl and forw.
52 ;; MH-E is an Emacs interface to the MH mail system.
54 ;; MH-E is supported in GNU Emacs 20 and 21, with MH 6.8.4 and nmh 1.0.4.
57 ;; mh-e-users@lists.sourceforge.net
58 ;; mh-e-announce@lists.sourceforge.net
59 ;; mh-e-devel@lists.sourceforge.net
61 ;; Subscribe by sending a "subscribe" message to
62 ;; <list>-request@lists.sourceforge.net, or by using the web interface at
63 ;; https://sourceforge.net/mail/?group_id=13357
66 ;; https://sourceforge.net/tracker/?group_id=13357&atid=113357
67 ;; Include the output of M-x mh-version in any bug report.
70 ;; https://sourceforge.net/tracker/?atid=363357&group_id=13357&func=browse
73 ;; https://sourceforge.net/tracker/?group_id=13357&atid=213357
77 ;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
78 ;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
79 ;; Rewritten for GNU Emacs, James Larus, 1985.
80 ;; Modified by Stephen Gildea, 1988.
81 ;; Maintenance picked up by Bill Wohler and the
82 ;; SourceForge Crew <http://mh-e.sourceforge.net/>, 2001.
88 (eval-when-compile (require 'mh-acros))
97 ;; Shush the byte-compiler
98 (defvar font-lock-auto-fontify)
99 (defvar font-lock-defaults)
101 (defconst mh-version "7.85+cvs" "Version number of MH-E.")
103 (defvar mh-partial-folder-mode-line-annotation "select"
104 "Annotation when displaying part of a folder.
105 The string is displayed after the folder's name. nil for no
110 ;;; Scan Line Formats
112 ;; Parameterize MH-E to work with different scan formats. The defaults work
113 ;; with the standard MH scan listings, in which the first 4 characters on
114 ;; the line are the message number, followed by two places for notations.
116 ;; The following scan formats are passed to the scan program if the setting of
117 ;; `mh-scan-format-file' is t. They are identical except the later one makes
118 ;; use of the nmh `decode' function to decode RFC 2047 encodings. If you just
119 ;; want to change the column of the notations, use the `mh-set-cmd-note'
122 (defvar mh-scan-format-mh
127 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
128 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
129 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
130 "%?(nonnull(comp{newsgroups}))n%>"
132 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
133 "%<(mymbox{from})%<{to}To:%14(friendly{to})%>%>"
134 "%<(zero)%17(friendly{from})%> "
135 "%{subject}%<{body}<<%{body}%>")
136 "*Scan format string for MH.
137 This string is passed to the scan program via the -format
138 argument. This format is identical to the default except that
139 additional hints for fontification have been added to the fifth
140 column (remember that in Emacs, the first column is 0).
142 The values of the fifth column, in priority order, are: `-' if
143 the message has been replied to, t if an address on the To: line
144 matches one of the mailboxes of the current user, `c' if the Cc:
145 line matches, `b' if the Bcc: line matches, and `n' if a
146 non-empty Newsgroups: header is present.")
148 (defvar mh-scan-format-nmh
153 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
154 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
155 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
156 "%?(nonnull(comp{newsgroups}))n%>"
158 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
159 "%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>"
160 "%<(zero)%17(decode(friendly{from}))%> "
161 "%(decode{subject})%<{body}<<%{body}%>")
162 "*Scan format string for nmh.
163 This string is passed to the scan program via the -format arg.
164 This format is identical to the default except that additional
165 hints for fontification have been added to the fifth
166 column (remember that in Emacs, the first column is 0).
168 The values of the fifth column, in priority order, are: `-' if
169 the message has been replied to, t if an address on the To: field
170 matches one of the mailboxes of the current user, `c' if the Cc:
171 field matches, `b' if the Bcc: field matches, and `n' if a
172 non-empty Newsgroups: field is present.")
174 (defvar mh-note-deleted ?D
175 "Messages that have been deleted are marked by this character.
176 See also `mh-scan-deleted-msg-regexp'.")
178 (defvar mh-note-refiled ?^
179 "Messages that have been refiled are marked by this character.
180 See also `mh-scan-refiled-msg-regexp'.")
182 (defvar mh-note-cur ?+
183 "The current message (in MH, not in MH-E) is marked by this character.
184 See also `mh-scan-cur-msg-number-regexp'.")
186 (defvar mh-scan-good-msg-regexp "^\\( *[0-9]+\\)[^D^0-9]"
187 "This regular expression matches \"good\" messages.
189 It must match from the beginning of the line. Note that the
190 default setting of `mh-folder-font-lock-keywords' expects this
191 expression to contain at least one parenthesized expression which
192 matches the message number as in the default of
194 \"^\\\\( *[0-9]+\\\\)[^D^0-9]\".
196 This expression includes the leading space within the parenthesis
197 since it looks better to highlight it as well. This regular
198 expression should be correct as it is needed by non-fontification
201 (defvar mh-scan-deleted-msg-regexp "^\\( *[0-9]+\\)D"
202 "This regular expression matches deleted messages.
204 It must match from the beginning of the line. Note that the
205 default setting of `mh-folder-font-lock-keywords' expects this
206 expression to contain at least one parenthesized expression which
207 matches the message number as in the default of
209 \"^\\\\( *[0-9]+\\\\)D\".
211 This expression includes the leading space within the parenthesis
212 since it looks better to highlight it as well. This regular
213 expression should be correct as it is needed by non-fontification
214 functions. See also `mh-note-deleted'.")
216 (defvar mh-scan-refiled-msg-regexp "^\\( *[0-9]+\\)\\^"
217 "This regular expression matches refiled messages.
219 It must match from the beginning of the line. Note that the
220 default setting of `mh-folder-font-lock-keywords' expects this
221 expression to contain at least one parenthesized expression which
222 matches the message number as in the default of
224 \"^\\\\( *[0-9]+\\\\)\\\\^\".
226 This expression includes the leading space within the parenthesis
227 since it looks better to highlight it as well. This regular
228 expression should be correct as it is needed by non-fontification
229 functions. See also `mh-note-refiled'.")
231 (defvar mh-scan-valid-regexp "^ *[0-9]"
232 "This regular expression describes a valid scan line.
234 This is used to eliminate error messages that are occasionally
235 produced by \"inc\".")
237 (defvar mh-scan-cur-msg-number-regexp "^\\( *[0-9]+\\+\\).*"
238 "This regular expression matches the current message.
240 It must match from the beginning of the line. Note that the
241 default setting of `mh-folder-font-lock-keywords' expects this
242 expression to contain at least one parenthesized expression which
243 matches the message number as in the default of
245 \"^\\\\( *[0-9]+\\\\+\\\\).*\".
247 This expression includes the leading space and current message
248 marker \"+\" within the parenthesis since it looks better to
249 highlight these items as well. This regular expression should be
250 correct as it is needed by non-fontification functions. See also
253 (defvar mh-scan-date-regexp "\\([0-9][0-9]/[0-9][0-9]\\)"
254 "This regular expression matches a valid date.
256 It must not be anchored to the beginning or the end of the line.
257 Note that the default setting of `mh-folder-font-lock-keywords'
258 expects this expression to contain only one parenthesized
259 expression which matches the date field as in the default of
260 \"\\\\([0-9][0-9]/[0-9][0-9]\\\\)\"}. If this regular expression
261 is not correct, the date will not be highlighted. See also
262 `mh-scan-format-regexp'.")
264 (defvar mh-scan-rcpt-regexp "\\(To:\\)\\(..............\\)"
265 "This regular expression specifies the recipient in messages you sent.
267 Note that the default setting of `mh-folder-font-lock-keywords'
268 expects this expression to contain two parenthesized expressions.
269 The first is expected to match the `To:' that the default scan
270 format file generates. The second is expected to match the
271 recipient's name as in the default of
272 \"\\\\(To:\\\\)\\\\(..............\\\\)\". If this regular
273 expression is not correct, the recipient will not be
276 (defvar mh-scan-body-regexp "\\(<<\\([^\n]+\\)?\\)"
277 "This regular expression matches the message body fragment.
279 Note that the default setting of `mh-folder-font-lock-keywords'
280 expects this expression to contain at least one parenthesized
281 expression which matches the body text as in the default of
282 \"\\\\(<<\\\\([^\\n]+\\\\)?\\\\)\". If this regular expression is
283 not correct, the body fragment will not be highlighted.")
285 (defvar mh-scan-subject-regexp
286 "^ *[0-9]+........[ ]*...................\\([Rr][Ee]\\(\\[[0-9]+\\]\\)?:\\s-*\\)*\\([^<\n]*\\)"
287 "This regular expression matches the subject.
289 It must match from the beginning of the line. Note that the
290 default setting of `mh-folder-font-lock-keywords' expects this
291 expression to contain at least three parenthesized expressions.
292 The first is expected to match the `Re:' string, if any. The
293 second matches an optional bracketed number after `Re:', such as
294 in `Re[2]:' (and is thus a sub-expression of the first
295 expression) and the third is expected to match the subject line
296 itself as in the default of \(broken on multiple lines for
299 ^ *[0-9]+........[ ]*...................
300 \\\\([Rr][Ee]\\\\(\\\\\\=[[0-9]+\\\\]\\\\)?:\\\\s-*\\\\)*
303 This regular expression should be correct as it is needed by
304 non-fontification functions.")
306 (defvar mh-scan-format-regexp
307 (concat "\\([bct]\\)" mh-scan-date-regexp " *\\(..................\\)")
308 "This regular expression matches the output of scan.
310 Note that the default setting of `mh-folder-font-lock-keywords'
311 expects this expression to contain at least three parenthesized
312 expressions. The first should match the fontification hint (see
313 `mh-scan-format-nmh'), the second is found in
314 `mh-scan-date-regexp', and the third should match the user name
317 \"(concat \"\\\\([bct]\\\\)\" mh-scan-date-regexp
318 \"*\\\\(..................\\\\)\")\".
320 If this regular expression is not correct, the notation hints and
321 the sender will not be highlighted.")
325 (defvar mh-folder-font-lock-keywords
327 ;; Folders when displaying index buffer
329 '(0 mh-index-folder-face))
330 ;; Marked for deletion
331 (list (concat mh-scan-deleted-msg-regexp ".*")
332 '(0 mh-folder-deleted-face))
334 (list (concat mh-scan-refiled-msg-regexp ".*")
335 '(0 mh-folder-refiled-face))
337 (list mh-scan-body-regexp '(1 mh-folder-body-face nil t))
338 '(mh-folder-font-lock-subject
339 (1 mh-folder-followup-face append t)
340 (2 mh-folder-subject-face append t))
342 (list mh-scan-cur-msg-number-regexp
343 '(1 mh-folder-cur-msg-number-face))
344 (list mh-scan-good-msg-regexp
345 '(1 mh-folder-msg-number-face)) ;; Msg number
346 (list mh-scan-date-regexp '(1 mh-folder-date-face)) ;; Date
347 (list mh-scan-rcpt-regexp
348 '(1 mh-folder-to-face) ;; To:
349 '(2 mh-folder-address-face)) ;; address
350 ;; scan font-lock name
351 (list mh-scan-format-regexp
352 '(1 mh-folder-date-face)
353 '(3 mh-folder-scan-format-face)))
354 "Keywords (regular expressions) used to fontify the MH-Folder buffer.")
356 (defvar mh-scan-cmd-note-width 1
357 "Number of columns consumed by the cmd-note field in `mh-scan-format'.
359 This column will have one of the values: ` ', `D', `^', `+' and
360 where ` ' is the default value,
362 `D' is the `mh-note-deleted' character,
363 `^' is the `mh-note-refiled' character, and
364 `+' is the `mh-note-cur' character.")
366 (defvar mh-scan-destination-width 1
367 "Number of columns consumed by the destination field in `mh-scan-format'.
369 This column will have one of ' ', '%', '-', 't', 'c', 'b', or `n'
372 ' ' blank space is the default character.
373 '%' indicates that the message in in a named MH sequence.
374 '-' indicates that the message has been annotated with a replied field.
375 't' indicates that the message contains mymbox in the To: field.
376 'c' indicates that the message contains mymbox in the Cc: field.
377 'b' indicates that the message contains mymbox in the Bcc: field.
378 'n' indicates that the message contains a Newsgroups: field.")
380 (defvar mh-scan-date-width 5
381 "Number of columns consumed by the date field in `mh-scan-format'.
382 This column will typically be of the form mm/dd.")
384 (defvar mh-scan-date-flag-width 1
385 "Number of columns consumed to flag (in)valid dates in `mh-scan-format'.
386 This column will have ` ' for valid and `*' for invalid or
389 (defvar mh-scan-from-mbox-width 17
390 "Number of columns consumed with the \"From:\" line in `mh-scan-format'.
391 This column will have a friendly name or e-mail address of the
392 originator, or a \"To: address\" for outgoing e-mail messages.")
394 (defvar mh-scan-from-mbox-sep-width 2
395 "Number of columns consumed by whitespace after from-mbox in `mh-scan-format'.
396 This column will only ever have spaces in it.")
398 (defvar mh-scan-field-destination-offset
399 (+ mh-scan-cmd-note-width)
400 "The offset from the `mh-cmd-note' for the destination column.")
402 (defvar mh-scan-field-from-start-offset
403 (+ mh-scan-cmd-note-width
404 mh-scan-destination-width
406 mh-scan-date-flag-width)
407 "The offset from the `mh-cmd-note' to find the start of \"From:\" address.")
409 (defvar mh-scan-field-from-end-offset
410 (+ mh-scan-field-from-start-offset mh-scan-from-mbox-width)
411 "The offset from the `mh-cmd-note' to find the end of \"From:\" address.")
413 (defvar mh-scan-field-subject-start-offset
414 (+ mh-scan-cmd-note-width
415 mh-scan-destination-width
417 mh-scan-date-flag-width
418 mh-scan-from-mbox-width
419 mh-scan-from-mbox-sep-width)
420 "The offset from the `mh-cmd-note' to find the start of the subject.")
422 (defun mh-folder-font-lock-subject (limit)
423 "Return MH-E scan subject strings to font-lock between point and LIMIT."
424 (if (not (re-search-forward mh-scan-subject-regexp limit t))
426 (if (match-beginning 1)
427 (set-match-data (list (match-beginning 1) (match-end 3)
428 (match-beginning 1) (match-end 3) nil nil))
429 (set-match-data (list (match-beginning 3) (match-end 3)
430 nil nil (match-beginning 3) (match-end 3))))
435 ;; Fontifify unseen mesages in bold.
437 (defmacro mh-generate-sequence-font-lock (seq prefix face)
438 "Generate the appropriate code to fontify messages in SEQ.
439 PREFIX is used to generate unique names for the variables and
440 functions defined by the macro. So a different prefix should be
441 provided for every invocation.
442 FACE is the font-lock face used to display the matching scan lines."
443 (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix)))
444 (func (intern (format "mh-folder-font-lock-%s" prefix))))
447 "Internal cache variable used for font-lock in MH-E.
448 Should only be non-nil through font-lock stepping, and nil once
449 font-lock is done highlighting.")
450 (make-variable-buffer-local ',cache)
453 "Return unseen message lines to font-lock between point and LIMIT."
454 (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq))))
455 (let ((cur-msg (mh-get-msg-num nil)))
458 ((>= (point) limit) ;Presumably at end of buffer
461 ((member cur-msg ,cache)
462 (let ((bpoint (progn (beginning-of-line)(point)))
463 (epoint (progn (forward-line 1)(point))))
464 (if (<= limit (point)) (setq ,cache nil))
465 (set-match-data (list bpoint epoint bpoint epoint))
468 ;; move forward one line at a time, checking each message
469 (while (and (= 0 (forward-line 1))
471 (not (member (mh-get-msg-num nil) ,cache))))
472 ;; Examine how we must have exited the loop...
473 (let ((cur-msg (mh-get-msg-num nil)))
474 (cond ((or (<= limit (point))
475 (not (member cur-msg ,cache)))
478 ((member cur-msg ,cache)
479 (let ((bpoint (progn (beginning-of-line) (point)))
480 (epoint (progn (forward-line 1) (point))))
481 (if (<= limit (point)) (setq ,cache nil))
483 (list bpoint epoint bpoint epoint))
486 (setq mh-folder-font-lock-keywords
487 (append mh-folder-font-lock-keywords
488 (list (list ',func (list 1 '',face 'prepend t))))))))
490 (mh-generate-sequence-font-lock mh-unseen-seq unseen bold)
491 (mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick)
495 ;;; Internal variables:
497 (defvar mh-last-destination nil
498 "Destination of last refile or write command.")
500 (defvar mh-last-destination-folder nil
501 "Destination of last refile command.")
503 (defvar mh-last-destination-write nil
504 "Destination of last write command.")
506 (defvar mh-folder-mode-map (make-keymap)
507 "Keymap for MH folders.")
509 (defvar mh-arrow-marker nil
510 "Marker for arrow display in fringe.")
512 (defvar mh-delete-list nil
513 "List of message numbers to delete.
514 This variable can be used by
515 `mh-before-commands-processed-hook'.")
517 (defvar mh-refile-list nil
518 "List of folder names in `mh-seq-list'.
519 This variable can be used by
520 `mh-before-commands-processed-hook'.")
522 (defvar mh-folders-changed nil
523 "Lists which folders were affected by deletes and refiles.
524 This list will always include the current folder
525 `mh-current-folder'. This variable can be used by
526 `mh-before-commands-processed-hook'.")
528 (defvar mh-next-direction 'forward
529 "Direction to move to next message.")
531 (defvar mh-view-ops ()
532 "Stack of operations that change the folder view.
533 These operations include narrowing or threading.")
535 (defvar mh-folder-view-stack ()
536 "Stack of previous folder views.")
538 (defvar mh-index-data nil
539 "Info about index search results.")
541 (defvar mh-index-previous-search nil)
542 (defvar mh-index-msg-checksum-map nil)
543 (defvar mh-index-checksum-origin-map nil)
544 (defvar mh-index-sequence-search-flag nil)
546 (defvar mh-first-msg-num nil
547 "Number of first message in buffer.")
549 (defvar mh-last-msg-num nil
550 "Number of last msg in buffer.")
552 (defvar mh-mode-line-annotation nil
553 "Message range displayed in buffer.")
555 (defvar mh-sequence-notation-history nil
556 "Remember original notation that is overwritten by `mh-note-seq'.")
558 (defvar mh-colors-available-flag nil
559 "Non-nil means colors are available.")
563 ;;; Macros and generic functions:
565 (defun mh-mapc (function list)
566 "Apply FUNCTION to each element of LIST for side effects only."
568 (funcall function (car list))
569 (setq list (cdr list))))
571 (defun mh-scan-format ()
572 "Return the output format argument for the scan program."
573 (if (equal mh-scan-format-file t)
574 (list "-format" (if (mh-variant-p 'nmh 'mu-mh)
575 (list (mh-update-scan-format
576 mh-scan-format-nmh mh-cmd-note))
577 (list (mh-update-scan-format
578 mh-scan-format-mh mh-cmd-note))))
579 (if (not (equal mh-scan-format-file nil))
580 (list "-form" mh-scan-format-file))))
587 (defun mh-rmail (&optional arg)
588 "Incorporate new mail with MH.
589 Scan an MH folder if ARG is non-nil.
591 This function is an entry point to MH-E, the Emacs interface to
596 (call-interactively 'mh-visit-folder)
597 (unless (get-buffer mh-inbox)
598 (mh-visit-folder mh-inbox (symbol-name mh-unseen-seq)))
602 (defun mh-nmail (&optional arg)
603 "Check for new mail in inbox folder.
604 Scan an MH folder if ARG is non-nil.
606 This function is an entry point to MH-E, the Emacs interface to
609 (mh-find-path) ; init mh-inbox
611 (call-interactively 'mh-visit-folder)
612 (mh-visit-folder mh-inbox)))
616 ;;; User executable MH-E commands:
618 (defun mh-delete-msg (range)
619 "Delete RANGE\\<mh-folder-mode-map>.
621 To mark a message for deletion, use this command. A \"D\" is
622 placed by the message in the scan window, and the next undeleted
623 message is displayed. If the previous command had been
624 \\[mh-previous-undeleted-msg], then the next message displayed is
625 the first undeleted message previous to the message just deleted.
626 Use \\[mh-next-undeleted-msg] to force subsequent
627 \\[mh-delete-msg] commands to move forward to the next undeleted
628 message after deleting the message under the cursor.
630 The hook `mh-delete-msg-hook' is called after you mark a message
631 for deletion. For example, a past maintainer of MH-E used this
632 once when he kept statistics on his mail usage.
634 Check the documentation of `mh-interactive-range' to see how
635 RANGE is read in interactive use."
636 (interactive (list (mh-interactive-range "Delete")))
637 (mh-delete-msg-no-motion range)
638 (if (looking-at mh-scan-deleted-msg-regexp)
641 (defun mh-delete-msg-no-motion (range)
642 "Delete RANGE, don't move to next message.
644 This command marks the RANGE for deletion but leaves the cursor
645 at the current message in case you wish to perform other
646 operations on the message.
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-iterate-on-range () range
652 (mh-delete-a-msg nil)))
654 (defun mh-execute-commands ()
655 "Process outstanding delete and refile requests\\<mh-folder-mode-map>.
657 If you've marked messages to be deleted or refiled and you want
658 to go ahead and delete or refile the messages, use this command.
659 Many MH-E commands that may affect the numbering of the
660 messages (such as \\[mh-rescan-folder] or \\[mh-pack-folder])
661 will ask if you want to process refiles or deletes first and then
662 either run this command for you or undo the pending refiles and
663 deletes, which are lost.
665 This function runs `mh-before-commands-processed-hook' before the
666 commands are processed and `mh-after-commands-processed-hook'
667 after the commands are processed."
669 (if mh-folder-view-stack (mh-widen t))
670 (mh-process-commands mh-current-folder)
672 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
673 (mh-make-folder-mode-line)
674 t) ; return t for write-file-functions
676 (defun mh-first-msg ()
677 "Display first message."
679 (goto-char (point-min))
680 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp)))
683 (defun mh-header-display ()
684 "Display message with all header fields\\<mh-folder-mode-map>.
686 Use the command \\[mh-show] to show the message normally again."
688 (and (not mh-showing-with-headers)
689 (or mh-mhl-format-file mh-clean-message-header-flag)
690 (mh-invalidate-show-buffer))
691 (let ((mh-decode-mime-flag nil)
692 (mh-mhl-format-file nil)
693 (mh-clean-message-header-flag nil))
695 (mh-in-show-buffer (mh-show-buffer)
696 (goto-char (point-min))
698 (setq mh-showing-with-headers t)))
700 (defun mh-inc-folder (&optional maildrop-name folder)
701 "Incorporate new mail into a folder.
703 You can incorporate mail from any file into the current folder by
704 specifying a prefix argument; you'll be prompted for the name of
705 the file to use as well as the destination folder
707 The hook `mh-inc-folder-hook' is run after incorporating new
708 mail. Do not call this function from outside MH-E; use
709 \\[mh-rmail] instead.
711 In a program optional argument MAILDROP-NAME specifies an
712 alternate maildrop from the default. The optional argument FOLDER
713 specifies where to incorporate mail instead of the default named
715 (interactive (list (if current-prefix-arg
717 (read-file-name "inc mail from file: "
719 (if current-prefix-arg
720 (mh-prompt-for-folder "inc mail into" mh-inbox t))))
722 (setq folder mh-inbox))
723 (let ((threading-needed-flag nil))
724 (let ((config (current-window-configuration)))
725 (when (and mh-show-buffer (get-buffer mh-show-buffer))
726 (delete-windows-on mh-show-buffer))
727 (cond ((not (get-buffer folder))
728 (mh-make-folder folder)
729 (setq threading-needed-flag mh-show-threads-flag)
730 (setq mh-previous-window-config config))
731 ((not (eq (current-buffer) (get-buffer folder)))
732 (switch-to-buffer folder)
733 (setq mh-previous-window-config config))))
734 (mh-get-new-mail maildrop-name)
735 (when (and threading-needed-flag
737 (goto-char (point-min))
738 (or (null mh-large-folder)
739 (not (equal (forward-line (1+ mh-large-folder)) 0))
740 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
744 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show))
745 (run-hooks 'mh-inc-folder-hook)))
747 (defun mh-last-msg ()
748 "Display last message."
750 (goto-char (point-max))
751 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp)))
755 (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag)
756 "Display next message.
758 This command can be given a prefix argument COUNT to specify how
759 many unread messages to skip.
761 In a program, pause for a second after printing message if we are
762 at the last undeleted message and optional argument
763 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
765 (setq mh-next-direction 'forward)
767 (cond ((re-search-forward mh-scan-good-msg-regexp nil t count)
771 (message "No more undeleted messages")
772 (if wait-after-complaining-flag (sit-for 1)))))
774 (defun mh-folder-from-address ()
775 "Derive folder name from sender.
777 The name of the folder is derived as follows:
779 a) The folder name associated with the first address found in
780 the list `mh-default-folder-list' is used. Each element in
781 this list contains a `Check Recipient' item. If this item is
782 turned on, then the address is checked against the recipient
783 instead of the sender. This is useful for mailing lists.
785 b) An alias prefixed by `mh-default-folder-prefix'
786 corresponding to the address is used. The prefix is used to
787 prevent clutter in your mail directory.
789 Return nil if a folder name was not derived, or if the variable
790 `mh-default-folder-must-exist-flag' is t and the folder does not
792 ;; Loop for all entries in mh-default-folder-list
794 (goto-char (point-min))
795 (re-search-forward "\n\n" nil 'limit)
796 (narrow-to-region (point-min) (point))
797 (let ((to/cc (concat (or (message-fetch-field "to") "") ", "
798 (or (message-fetch-field "cc") "")))
799 (from (or (message-fetch-field "from") ""))
802 (loop for list in mh-default-folder-list
803 when (string-match (nth 0 list) (if (nth 2 list) to/cc from))
807 ;; Make sure a result from `mh-default-folder-list' begins with "+"
808 ;; since 'mh-expand-file-name below depends on it
809 (when (and folder-name (not (eq (aref folder-name 0) ?+)))
810 (setq folder-name (concat "+" folder-name)))
812 ;; If not, is there an alias for the address?
813 (when (not folder-name)
814 (let* ((from-header (mh-extract-from-header-value))
815 (address (and from-header
816 (nth 1 (mail-extract-address-components
818 (alias (and address (mh-alias-address-to-alias address))))
821 (and alias (concat "+" mh-default-folder-prefix alias))))))
823 ;; If mh-default-folder-must-exist-flag set, check that folder exists.
825 (or (not mh-default-folder-must-exist-flag)
826 (file-exists-p (mh-expand-file-name folder-name))))
829 (defun mh-prompt-for-refile-folder ()
830 "Prompt the user for a folder in which the message should be filed.
831 The folder is returned as a string.
833 The default folder name is generated by the option
834 `mh-default-folder-for-message-function' if it is non-nil or
835 `mh-folder-from-address'."
836 (mh-prompt-for-folder
838 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t)))))
839 (if (null refile-file) ""
841 (set-buffer (get-buffer-create mh-temp-buffer))
843 (insert-file-contents refile-file)
844 (or (and mh-default-folder-for-message-function
845 (let ((buffer-file-name refile-file))
846 (funcall mh-default-folder-for-message-function)))
847 (mh-folder-from-address)
848 (and (eq 'refile (car mh-last-destination-folder))
849 (symbol-name (cdr mh-last-destination-folder)))
853 (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag)
854 "Refile (output) RANGE into FOLDER.
856 You are prompted for the folder name. Note that this command can also
857 be used to create folders. If you specify a folder that does not
858 exist, you will be prompted to create it.
860 The hook `mh-refile-msg-hook' is called after a message is marked to
863 Check the documentation of `mh-interactive-range' to see how RANGE is
864 read in interactive use.
866 In a program, the variables `mh-last-destination' and
867 `mh-last-destination-folder' are not updated if
868 DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil."
869 (interactive (list (mh-interactive-range "Refile")
870 (intern (mh-prompt-for-refile-folder))))
871 (unless dont-update-last-destination-flag
872 (setq mh-last-destination (cons 'refile folder)
873 mh-last-destination-folder mh-last-destination))
874 (mh-iterate-on-range () range
875 (mh-refile-a-msg nil folder))
876 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg)))
878 (defun mh-refile-or-write-again (range &optional interactive-flag)
879 "Repeat last output command.
881 If you are refiling several messages into the same folder, you can use
882 this command to repeat the last refile or write. You can use a range.
884 Check the documentation of `mh-interactive-range' to see how RANGE is
885 read in interactive use.
887 In a program, a non-nil INTERACTIVE-FLAG means that the function was
888 called interactively."
889 (interactive (list (mh-interactive-range "Redo") t))
890 (if (null mh-last-destination)
891 (error "No previous refile or write"))
892 (cond ((eq (car mh-last-destination) 'refile)
893 (mh-refile-msg range (cdr mh-last-destination))
894 (message "%s" (format "Destination folder: %s"
895 (cdr mh-last-destination))))
897 (mh-iterate-on-range msg range
898 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination)))
899 (mh-next-msg interactive-flag))))
902 "Quit the current MH-E folder.
904 When you want to quit using MH-E and go back to editing, you can use
905 this command. This buries the buffers of the current MH-E folder and
906 restores the buffers that were present when you first ran
907 \\[mh-rmail]. It also removes any MH-E working buffers whose name
908 begins with \" *mh-\" or \"*MH-E \". You can later restore your MH-E
909 session by selecting the \"+inbox\" buffer or by running \\[mh-rmail]
912 The two hooks `mh-before-quit-hook' and `mh-quit-hook' are called by
913 this function. The former one is called before the quit occurs, so you
914 might use it to perform any MH-E operations; you could perform some
915 query and abort the quit or call `mh-execute-commands', for example.
916 The latter is not run in an MH-E context, so you might use it to
917 modify the window setup."
919 (run-hooks 'mh-before-quit-hook)
920 (let ((show-buffer (get-buffer mh-show-buffer)))
922 (kill-buffer show-buffer)))
923 (mh-update-sequences)
924 (mh-destroy-postponed-handles)
925 (bury-buffer (current-buffer))
927 ;; Delete all MH-E temporary and working buffers.
928 (dolist (buffer (buffer-list))
929 (when (or (string-match "^ \\*mh-" (buffer-name buffer))
930 (string-match "^\\*MH-E " (buffer-name buffer)))
931 (kill-buffer buffer)))
933 (if mh-previous-window-config
934 (set-window-configuration mh-previous-window-config))
935 (run-hooks 'mh-quit-hook))
937 (defun mh-page-msg (&optional lines)
938 "Display next page in message.
940 You can give this command a prefix argument that specifies the
941 number of LINES to scroll. This command will also show the next
942 undeleted message if it is used at the bottom of a message."
945 (if mh-page-to-next-msg-flag
946 (if (equal mh-next-direction 'backward)
947 (mh-previous-undeleted-msg)
948 (mh-next-undeleted-msg))
949 (if (mh-in-show-buffer (mh-show-buffer)
950 (pos-visible-in-window-p (point-max)))
953 "End of message (Type %s to read %s undeleted message)"
954 (single-key-description last-input-event)
955 (if (equal mh-next-direction 'backward)
958 (setq mh-page-to-next-msg-flag t))
959 (scroll-other-window lines)))
962 (defun mh-previous-page (&optional lines)
963 "Display next page in message.
965 You can give this command a prefix argument that specifies the
966 number of LINES to scroll."
968 (mh-in-show-buffer (mh-show-buffer)
969 (scroll-down lines)))
971 (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag)
972 "Display previous message.
974 This command can be given a prefix argument COUNT to specify how
975 many unread messages to skip.
977 In a program, pause for a second after printing message if we are
978 at the last undeleted message and optional argument
979 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
981 (setq mh-next-direction 'backward)
983 (cond ((re-search-backward mh-scan-good-msg-regexp nil t count)
985 (t (message "No previous undeleted message")
986 (if wait-after-complaining-flag (sit-for 1)))))
988 (defun mh-previous-unread-msg (&optional count)
989 "Display previous unread message.
991 This command can be given a prefix argument COUNT to specify how
992 many unread messages to skip."
995 (error "The function mh-previous-unread-msg expects positive argument"))
996 (setq count (1- count))
997 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list)))
998 (cur-msg (mh-get-msg-num nil)))
999 (cond ((and (not cur-msg) (not (bobp))
1000 ;; If we are at the end of the buffer back up one line and go
1001 ;; to unread message after that.
1004 (setq cur-msg (mh-get-msg-num nil)))
1006 ((or (null unread-sequence) (not cur-msg))
1007 ;; No unread message or there aren't any messages in buffer...
1008 (message "No more unread messages"))
1010 ;; Skip count messages...
1011 (while (and unread-sequence (>= (car unread-sequence) cur-msg))
1012 (setq unread-sequence (cdr unread-sequence)))
1014 (setq unread-sequence (cdr unread-sequence))
1015 (setq count (1- count)))
1016 (not (car unread-sequence)))
1017 (message "No more unread messages"))
1018 (t (loop for msg in unread-sequence
1019 when (mh-goto-msg msg t) return nil
1020 finally (message "No more unread messages"))))))
1022 (defun mh-goto-next-button (backward-flag &optional criterion)
1023 "Search for next button satisfying criterion.
1025 If BACKWARD-FLAG is non-nil search backward in the buffer for a mime
1027 If CRITERION is a function or a symbol which has a function binding
1028 then that function must return non-nil at the button we stop."
1029 (unless (or (and (symbolp criterion) (fboundp criterion))
1030 (functionp criterion))
1031 (setq criterion (lambda (x) t)))
1032 ;; Move to the next button in the buffer satisfying criterion
1033 (goto-char (or (save-excursion
1035 ;; Find point before current button
1036 (let ((point-before-current-button
1038 (while (get-text-property (point) 'mh-data)
1039 (unless (= (forward-line
1040 (if backward-flag 1 -1))
1043 (goto-char (point-min))
1044 (goto-char (point-max)))))
1046 ;; Skip over current button
1047 (while (and (get-text-property (point) 'mh-data)
1048 (not (if backward-flag (bobp) (eobp))))
1049 (forward-line (if backward-flag -1 1)))
1050 ;; Stop at next MIME button if any exists.
1053 (unless (= (forward-line
1054 (if backward-flag -1 1))
1057 (goto-char (point-max))
1058 (goto-char (point-min)))
1059 (beginning-of-line))
1061 point-before-current-button)
1062 (when (and (get-text-property (point) 'mh-data)
1063 (funcall criterion (point)))
1064 (return-from loop (point))))
1068 (defun mh-next-button (&optional backward-flag)
1069 "Go to the next button.
1071 If the end of the buffer is reached then the search wraps over to
1072 the start of the buffer.
1074 If an optional prefix argument BACKWARD-FLAG is given, the cursor
1075 will move to the previous button."
1076 (interactive (list current-prefix-arg))
1077 (unless mh-showing-mode
1079 (mh-in-show-buffer (mh-show-buffer)
1080 (mh-goto-next-button backward-flag)))
1082 (defun mh-prev-button ()
1083 "Go to the previous button.
1085 If the beginning of the buffer is reached then the search wraps
1086 over to the end of the buffer."
1090 (defun mh-folder-mime-action (part-index action include-security-flag)
1091 "Go to PART-INDEX and carry out ACTION.
1093 If PART-INDEX is nil then go to the next part in the buffer. The
1094 search for the next buffer wraps around if end of buffer is reached.
1095 If argument INCLUDE-SECURITY-FLAG is non-nil then include security
1096 info buttons when searching for a suitable parts."
1097 (unless mh-showing-mode
1099 (mh-in-show-buffer (mh-show-buffer)
1103 (let ((part (get-text-property p 'mh-part)))
1104 (and (integerp part) (= part part-index)))))
1106 (if include-security-flag
1107 (get-text-property p 'mh-data)
1108 (integerp (get-text-property p 'mh-part)))))))
1110 (cond ((and (get-text-property point 'mh-part)
1111 (or (null part-index)
1112 (= (get-text-property point 'mh-part) part-index)))
1114 ((and (get-text-property point 'mh-data)
1115 include-security-flag
1119 (mh-goto-next-button nil criterion)
1120 (if (= (point) point)
1121 (message "No matching MIME part found")
1122 (funcall action)))))))
1124 (defun mh-folder-toggle-mime-part (part-index)
1127 This command displays (or hides) the attachment associated with
1128 the button under the cursor. If the cursor is not located over a
1129 button, then the cursor first moves to the next button, wrapping
1130 to the beginning of the message if necessary. This command has
1131 the advantage over related commands of working from the MH-Folder
1134 You can also provide a numeric prefix argument PART-INDEX to view
1135 the attachment labeled with that number. If Emacs does not know
1136 how to display the attachment, then Emacs offers to save the
1137 attachment in a file."
1139 (when (consp part-index) (setq part-index (car part-index)))
1140 (mh-folder-mime-action part-index #'mh-press-button t))
1142 (defun mh-folder-inline-mime-part (part-index)
1143 "Show attachment verbatim.
1145 You can view the raw contents of an attachment with this command.
1146 This command displays (or hides) the contents of the attachment
1147 associated with the button under the cursor verbatim. If the
1148 cursor is not located over a button, then the cursor first moves
1149 to the next button, wrapping to the beginning of the message if
1152 You can also provide a numeric prefix argument PART-INDEX to view
1153 the attachment labeled with that number."
1155 (when (consp part-index) (setq part-index (car part-index)))
1156 (mh-folder-mime-action part-index #'mh-mime-inline-part nil))
1158 (defun mh-folder-save-mime-part (part-index)
1159 "Save (output) attachment.
1161 This command saves the attachment associated with the button under the
1162 cursor. If the cursor is not located over a button, then the cursor
1163 first moves to the next button, wrapping to the beginning of the
1164 message if necessary.
1166 You can also provide a numeric prefix argument PART-INDEX to save the
1167 attachment labeled with that number.
1169 This command prompts you for a filename and suggests a specific name
1170 if it is available."
1172 (when (consp part-index) (setq part-index (car part-index)))
1173 (mh-folder-mime-action part-index #'mh-mime-save-part nil))
1175 (defvar mh-thread-scan-line-map-stack)
1177 (defun mh-reset-threads-and-narrowing ()
1178 "Reset all variables pertaining to threads and narrowing.
1179 Also removes all content from the folder buffer."
1180 (setq mh-view-ops ())
1181 (setq mh-folder-view-stack ())
1182 (setq mh-thread-scan-line-map-stack ())
1183 (let ((buffer-read-only nil)) (erase-buffer)))
1185 (defun mh-rescan-folder (&optional range dont-exec-pending)
1186 "Rescan folder\\<mh-folder-mode-map>.
1188 This command is useful to grab all messages in your \"+inbox\" after
1189 processing your new mail for the first time. If you don't want to
1190 rescan the entire folder, this command will accept a RANGE. Check the
1191 documentation of `mh-interactive-range' to see how RANGE is read in
1194 This command will ask if you want to process refiles or deletes first
1195 and then either run \\[mh-execute-commands] for you or undo the
1196 pending refiles and deletes, which are lost.
1198 In a program, the processing of outstanding commands is not performed
1199 if DONT-EXEC-PENDING is non-nil."
1200 (interactive (list (if current-prefix-arg
1201 (mh-read-range "Rescan" mh-current-folder t nil t
1202 mh-interpret-number-as-range-flag)
1204 (setq mh-next-direction 'forward)
1205 (let ((threaded-flag (memq 'unthread mh-view-ops)))
1206 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending)
1207 (cond (threaded-flag (mh-toggle-threads))
1208 (mh-index-data (mh-index-insert-folder-headers)))))
1210 (defun mh-write-msg-to-file (message file no-header)
1211 "Append MESSAGE to end of FILE\\<mh-folder-mode-map>.
1213 You are prompted for the filename. If the file already exists,
1214 the message is appended to it. You can also write the message to
1215 the file without the header by specifying a prefix argument
1216 NO-HEADER. Subsequent writes to the same file can be made with
1217 the command \\[mh-refile-or-write-again]."
1219 (list (mh-get-msg-num t)
1220 (let ((default-dir (if (eq 'write (car mh-last-destination-write))
1221 (file-name-directory
1222 (car (cdr mh-last-destination-write)))
1223 default-directory)))
1224 (read-file-name (format "Save message%s in file: "
1225 (if current-prefix-arg " body" ""))
1227 (if (eq 'write (car mh-last-destination-write))
1228 (car (cdr mh-last-destination-write))
1229 (expand-file-name "mail.out" default-dir))))
1230 current-prefix-arg))
1231 (let ((msg-file-to-output (mh-msg-filename message))
1232 (output-file (mh-expand-file-name file)))
1233 (setq mh-last-destination (list 'write file (if no-header 'no-header))
1234 mh-last-destination-write mh-last-destination)
1236 (set-buffer (get-buffer-create mh-temp-buffer))
1238 (insert-file-contents msg-file-to-output)
1239 (goto-char (point-min))
1240 (if no-header (search-forward "\n\n"))
1241 (append-to-file (point) (point-max) output-file))))
1243 (defun mh-toggle-showing ()
1244 "Toggle the scanning mode/showing mode of displaying messages."
1250 (defun mh-undo (range)
1251 "Undo pending deletes or refiles in RANGE.
1253 If you've deleted a message or refiled it, but changed your mind,
1254 you can cancel the action before you've executed it. Use this
1255 command to undo a refile on or deletion of a single message. You
1256 can also undo refiles and deletes for messages that are found in
1259 Check the documentation of `mh-interactive-range' to see how
1260 RANGE is read in interactive use."
1261 (interactive (list (mh-interactive-range "Undo")))
1262 (cond ((numberp range)
1263 (let ((original-position (point)))
1265 (while (not (or (looking-at mh-scan-deleted-msg-regexp)
1266 (looking-at mh-scan-refiled-msg-regexp)
1267 (and (eq mh-next-direction 'forward) (bobp))
1268 (and (eq mh-next-direction 'backward)
1269 (save-excursion (forward-line) (eobp)))))
1270 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
1271 (if (or (looking-at mh-scan-deleted-msg-regexp)
1272 (looking-at mh-scan-refiled-msg-regexp))
1274 (mh-undo-msg (mh-get-msg-num t))
1276 (goto-char original-position)
1277 (error "Nothing to undo"))))
1278 (t (mh-iterate-on-range () range
1279 (mh-undo-msg nil))))
1280 (if (not (mh-outstanding-commands-p))
1281 (mh-set-folder-modified-p nil)))
1284 (defun mh-folder-line-matches-show-buffer-p ()
1285 "Return t if the message under point in folder-mode is in the show buffer.
1286 Return nil in any other circumstance (no message under point, no
1287 show buffer, the message in the show buffer doesn't match."
1288 (and (eq major-mode 'mh-folder-mode)
1289 (mh-get-msg-num nil)
1291 (get-buffer mh-show-buffer)
1292 (buffer-file-name (get-buffer mh-show-buffer))
1293 (string-match ".*/\\([0-9]+\\)$"
1294 (buffer-file-name (get-buffer mh-show-buffer)))
1296 (match-string 1 (buffer-file-name (get-buffer mh-show-buffer)))
1297 (int-to-string (mh-get-msg-num nil)))))
1299 (eval-when-compile (require 'gnus))
1301 (defmacro mh-macro-expansion-time-gnus-version ()
1302 "Return Gnus version available at macro expansion time.
1303 The macro evaluates the Gnus version at macro expansion time. If
1304 MH-E was compiled then macro expansion happens at compile time."
1307 (defun mh-run-time-gnus-version ()
1308 "Return Gnus version available at run time."
1313 (defun mh-version ()
1314 "Display version information about MH-E and the MH mail handling system."
1316 (set-buffer (get-buffer-create mh-info-buffer))
1319 (insert "MH-E " mh-version "\n\n")
1320 ;; MH-E compilation details.
1321 (insert "MH-E compilation details:\n")
1322 (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version)))
1323 (gnus-compiled-version (if compiled-mhe
1324 (mh-macro-expansion-time-gnus-version)
1326 (insert " Byte compiled:\t\t" (if compiled-mhe "yes" "no") "\n"
1327 " Gnus (compile-time):\t" gnus-compiled-version "\n"
1328 " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
1330 (insert (emacs-version) "\n\n")
1332 (if mh-variant-in-use
1333 (insert mh-variant-in-use "\n"
1334 " mh-progs:\t" mh-progs "\n"
1335 " mh-lib:\t" mh-lib "\n"
1336 " mh-lib-progs:\t" mh-lib-progs "\n\n")
1337 (insert "No MH variant detected\n"))
1340 (call-process "uname" nil t nil "-a")
1342 (goto-char (point-min))
1343 (display-buffer mh-info-buffer))
1345 (defun mh-parse-flist-output-line (line &optional current-folder)
1346 "Parse LINE to generate folder name, unseen messages and total messages.
1347 If CURRENT-FOLDER is non-nil then it contains the current folder
1348 name and it is used to avoid problems in corner cases involving
1349 folders whose names end with a '+' character."
1352 (goto-char (point-max))
1353 (let (folder unseen total p)
1354 (when (search-backward " out of " (point-min) t)
1355 (setq total (read-from-string
1356 (buffer-substring-no-properties
1357 (match-end 0) (line-end-position))))
1358 (when (search-backward " in sequence " (point-min) t)
1360 (when (search-backward " has " (point-min) t)
1361 (setq unseen (read-from-string (buffer-substring-no-properties
1363 (while (eq (char-after) ? )
1365 (setq folder (buffer-substring-no-properties
1366 (point-min) (1+ (point))))
1367 (when (and (equal (aref folder (1- (length folder))) ?+)
1368 (equal current-folder folder))
1369 (setq folder (substring folder 0 (1- (length folder)))))
1370 (values (format "+%s" folder) (car unseen) (car total))))))))
1372 (defun mh-folder-size-folder (folder)
1373 "Find size of FOLDER using `folder'."
1375 (let ((u (length (cdr (assoc mh-unseen-seq
1376 (mh-read-folder-sequences folder nil))))))
1377 (call-process (expand-file-name "folder" mh-progs) nil t nil
1378 "-norecurse" folder)
1379 (goto-char (point-min))
1380 (if (re-search-forward " has \\([0-9]+\\) " nil t)
1381 (values (car (read-from-string (match-string 1))) u folder)
1382 (values 0 u folder)))))
1384 (defun mh-folder-size-flist (folder)
1385 "Find size of FOLDER using `flist'."
1387 (call-process (expand-file-name "flist" mh-progs) nil t nil "-showzero"
1388 "-norecurse" folder "-sequence" (symbol-name mh-unseen-seq))
1389 (goto-char (point-min))
1390 (multiple-value-bind (folder unseen total)
1391 (mh-parse-flist-output-line
1392 (buffer-substring (point) (line-end-position)))
1393 (values total unseen folder))))
1395 (defun mh-folder-size (folder)
1396 "Find size of FOLDER."
1397 (if mh-flists-present-flag
1398 (mh-folder-size-flist folder)
1399 (mh-folder-size-folder folder)))
1401 (defun mh-visit-folder (folder &optional range index-data)
1404 When you want to read the messages that you have refiled into folders,
1405 use this command to visit the folder. You are prompted for the folder
1408 The folder buffer will show just unseen messages if there are any;
1409 otherwise, it will show all the messages in the buffer as long there
1410 are fewer than `mh-large-folder' messages. If there are more, then you
1411 are prompted for a range of messages to scan.
1413 You can provide a prefix argument in order to specify a RANGE of
1414 messages to show when you visit the folder. In this case, regions are
1415 not used to specify the range and `mh-large-folder' is ignored. Check
1416 the documentation of `mh-interactive-range' to see how RANGE is read
1419 Note that this command can also be used to create folders. If you
1420 specify a folder that does not exist, you will be prompted to create
1423 Do not call this function from outside MH-E; use \\[mh-rmail] instead.
1425 If, in a program, RANGE is nil (the default), then all messages in
1426 FOLDER are displayed. If an index buffer is being created then
1427 INDEX-DATA is used to initialize the index buffer specific data
1429 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t)))
1431 (mh-read-range "Scan" folder-name t nil
1433 mh-interpret-number-as-range-flag))))
1434 (let ((config (current-window-configuration))
1435 (current-buffer (current-buffer))
1436 (threaded-view-flag mh-show-threads-flag))
1437 (delete-other-windows)
1439 (when (get-buffer folder)
1441 (setq threaded-view-flag (memq 'unthread mh-view-ops))))
1443 (mh-make-folder folder)
1444 (setq mh-index-data (car index-data)
1445 mh-index-msg-checksum-map (make-hash-table :test #'equal)
1446 mh-index-checksum-origin-map (make-hash-table :test #'equal))
1447 (mh-index-update-maps folder (cadr index-data))
1448 (mh-index-create-sequences))
1449 (mh-scan-folder folder (or range "all"))
1450 (cond ((and threaded-view-flag
1452 (goto-char (point-min))
1453 (or (null mh-large-folder)
1454 (not (equal (forward-line (1+ mh-large-folder)) 0))
1455 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
1457 (mh-toggle-threads))
1459 (mh-index-insert-folder-headers)))
1460 (unless (eq current-buffer (current-buffer))
1461 (setq mh-previous-window-config config)))
1465 (defun mh-update-sequences ()
1466 "Flush MH-E's state out to MH.
1468 This function updates the sequence specified by your
1469 \"Unseen-Sequence:\" profile component, \"cur\", and the sequence
1470 listed by the `mh-tick-seq' option which is \"tick\" by default.
1471 The message at the cursor is used for \"cur\"."
1473 ;; mh-update-sequences is the opposite of mh-read-folder-sequences,
1474 ;; which updates MH-E's state from MH.
1475 (let ((folder-set (mh-update-unseen))
1476 (new-cur (mh-get-msg-num nil)))
1478 (let ((seq-entry (mh-find-seq 'cur)))
1479 (mh-remove-cur-notation)
1481 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq
1482 (mh-define-sequence 'cur (list new-cur))
1484 (if (looking-at mh-scan-good-msg-regexp)
1488 ;; psg - mh-current-folder is nil if mh-summary-height < 4 !
1489 ;; So I added this sanity check.
1490 (if (stringp mh-current-folder)
1491 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast")
1492 (mh-exec-cmd-quiet t "folder" "-fast")))))))
1496 ;;; Support routines.
1498 (defun mh-delete-a-msg (message)
1500 If MESSAGE is nil then the message at point is deleted.
1501 The hook `mh-delete-msg-hook' is called after you mark a message
1502 for deletion. For example, a past maintainer of MH-E used this
1503 once when he kept statistics on his mail usage."
1505 (if (numberp message)
1506 (mh-goto-msg message nil t)
1508 (setq message (mh-get-msg-num t)))
1509 (if (looking-at mh-scan-refiled-msg-regexp)
1510 (error "Message %d is refiled. Undo refile before deleting" message))
1511 (if (looking-at mh-scan-deleted-msg-regexp)
1513 (mh-set-folder-modified-p t)
1514 (setq mh-delete-list (cons message mh-delete-list))
1515 (mh-notate nil mh-note-deleted mh-cmd-note)
1516 (run-hooks 'mh-delete-msg-hook))))
1518 (defun mh-refile-a-msg (message folder)
1519 "Refile MESSAGE in FOLDER.
1520 If MESSAGE is nil then the message at point is refiled.
1521 Folder is a symbol, not a string.
1522 The hook `mh-refile-msg-hook' is called after a message is marked to
1525 (if (numberp message)
1526 (mh-goto-msg message nil t)
1528 (setq message (mh-get-msg-num t)))
1529 (cond ((looking-at mh-scan-deleted-msg-regexp)
1530 (error "Message %d is deleted. Undo delete before moving" message))
1531 ((looking-at mh-scan-refiled-msg-regexp)
1533 (format "Message %d already refiled. Copy to %s as well? "
1535 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
1536 "-src" mh-current-folder
1537 (symbol-name folder))
1538 (message "Message not copied")))
1540 (mh-set-folder-modified-p t)
1541 (cond ((null (assoc folder mh-refile-list))
1542 (push (list folder message) mh-refile-list))
1543 ((not (member message (cdr (assoc folder mh-refile-list))))
1544 (push message (cdr (assoc folder mh-refile-list)))))
1545 (mh-notate nil mh-note-refiled mh-cmd-note)
1546 (run-hooks 'mh-refile-msg-hook)))))
1548 (defun mh-next-msg (&optional wait-after-complaining-flag)
1549 "Move backward or forward to the next undeleted message in the buffer.
1550 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and
1551 we are at the last message, then wait for a second after telling
1552 the user that there aren't any more unread messages."
1553 (if (eq mh-next-direction 'forward)
1554 (mh-next-undeleted-msg 1 wait-after-complaining-flag)
1555 (mh-previous-undeleted-msg 1 wait-after-complaining-flag)))
1557 (defun mh-next-unread-msg (&optional count)
1558 "Display next unread message.
1560 This command can be given a prefix argument COUNT to specify how
1561 many unread messages to skip."
1564 (error "The function mh-next-unread-msg expects positive argument"))
1565 (setq count (1- count))
1566 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list))))
1567 (cur-msg (mh-get-msg-num nil)))
1568 (cond ((and (not cur-msg) (not (bobp))
1569 ;; If we are at the end of the buffer back up one line and go
1570 ;; to unread message after that.
1573 (setq cur-msg (mh-get-msg-num nil)))
1575 ((or (null unread-sequence) (not cur-msg))
1576 ;; No unread message or there aren't any messages in buffer...
1577 (message "No more unread messages"))
1580 (while (and unread-sequence (>= cur-msg (car unread-sequence)))
1581 (setq unread-sequence (cdr unread-sequence)))
1583 (setq unread-sequence (cdr unread-sequence))
1584 (setq count (1- count)))
1585 (not (car unread-sequence)))
1586 (message "No more unread messages"))
1587 (t (loop for msg in unread-sequence
1588 when (mh-goto-msg msg t) return nil
1589 finally (message "No more unread messages"))))))
1591 (defun mh-set-scan-mode ()
1592 "Display the scan listing buffer, but do not show a message."
1593 (if (get-buffer mh-show-buffer)
1594 (delete-windows-on mh-show-buffer))
1596 (force-mode-line-update)
1597 (if mh-recenter-summary-flag
1600 (defun mh-undo-msg (msg)
1601 "Undo the deletion or refile of one MSG.
1602 If MSG is nil then act on the message at point"
1605 (mh-goto-msg msg t t)
1607 (setq msg (mh-get-msg-num t)))
1608 (cond ((memq msg mh-delete-list)
1609 (setq mh-delete-list (delq msg mh-delete-list)))
1611 (dolist (folder-msg-list mh-refile-list)
1612 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list))))
1613 (setq mh-refile-list (loop for x in mh-refile-list
1614 unless (null (cdr x)) collect x))))
1615 (mh-notate nil ? mh-cmd-note)))
1619 ;;; The folder data abstraction.
1621 (defvar mh-index-data-file ".mhe_index"
1622 "MH-E specific file where index seach info is stored.")
1624 (defun mh-make-folder (name)
1625 "Create a new mail folder called NAME.
1626 Make it the current folder."
1627 (switch-to-buffer name)
1628 (setq buffer-read-only nil)
1630 (if mh-adaptive-cmd-note-flag
1631 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name))))
1632 (setq buffer-read-only t)
1634 (mh-set-folder-modified-p nil)
1635 (setq buffer-file-name mh-folder-filename)
1636 (when (and (not mh-index-data)
1637 (file-exists-p (concat buffer-file-name mh-index-data-file)))
1638 (mh-index-read-data))
1639 (mh-make-folder-mode-line))
1641 ;; Ensure new buffers won't get this mode if default-major-mode is nil.
1642 (put 'mh-folder-mode 'mode-class 'special)
1646 ;;; Build mh-folder-mode menu
1648 ;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
1649 ;; Menus for folder mode: folder, message, sequence (in that order)
1650 ;; folder-mode "Sequence" menu
1652 mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence."
1654 ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)]
1655 ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)]
1656 ["Delete Message from Sequence..." mh-delete-msg-from-seq
1657 (mh-get-msg-num nil)]
1658 ["List Sequences in Folder..." mh-list-sequences t]
1659 ["Delete Sequence..." mh-delete-seq t]
1660 ["Narrow to Sequence..." mh-narrow-to-seq t]
1661 ["Widen from Sequence" mh-widen mh-folder-view-stack]
1663 ["Narrow to Subject Sequence" mh-narrow-to-subject t]
1664 ["Narrow to Tick Sequence" mh-narrow-to-tick
1665 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))]
1666 ["Delete Rest of Same Subject" mh-delete-subject t]
1667 ["Toggle Tick Mark" mh-toggle-tick t]
1669 ["Push State Out to MH" mh-update-sequences t]))
1671 ;; folder-mode "Message" menu
1673 mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message."
1675 ["Show Message" mh-show (mh-get-msg-num nil)]
1676 ["Show Message with Header" mh-header-display (mh-get-msg-num nil)]
1677 ["Next Message" mh-next-undeleted-msg t]
1678 ["Previous Message" mh-previous-undeleted-msg t]
1679 ["Go to First Message" mh-first-msg t]
1680 ["Go to Last Message" mh-last-msg t]
1681 ["Go to Message by Number..." mh-goto-msg t]
1682 ["Modify Message" mh-modify t]
1683 ["Delete Message" mh-delete-msg (mh-get-msg-num nil)]
1684 ["Refile Message" mh-refile-msg (mh-get-msg-num nil)]
1685 ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)]
1686 ["Execute Delete/Refile" mh-execute-commands
1687 (mh-outstanding-commands-p)]
1689 ["Compose a New Message" mh-send t]
1690 ["Reply to Message..." mh-reply (mh-get-msg-num nil)]
1691 ["Forward Message..." mh-forward (mh-get-msg-num nil)]
1692 ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)]
1693 ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)]
1694 ["Re-edit a Bounced Message" mh-extract-rejected-mail t]
1696 ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)]
1697 ["Print Message" mh-print-msg (mh-get-msg-num nil)]
1698 ["Write Message to File..." mh-write-msg-to-file
1699 (mh-get-msg-num nil)]
1700 ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)]
1701 ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)]
1702 ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)]))
1704 ;; folder-mode "Folder" menu
1706 mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder."
1708 ["Incorporate New Mail" mh-inc-folder t]
1709 ["Toggle Show/Folder" mh-toggle-showing t]
1710 ["Execute Delete/Refile" mh-execute-commands
1711 (mh-outstanding-commands-p)]
1712 ["Rescan Folder" mh-rescan-folder t]
1713 ["Thread Folder" mh-toggle-threads
1714 (not (memq 'unthread mh-view-ops))]
1715 ["Pack Folder" mh-pack-folder t]
1716 ["Sort Folder" mh-sort-folder t]
1718 ["List Folders" mh-list-folders t]
1719 ["Visit a Folder..." mh-visit-folder t]
1720 ["View New Messages" mh-index-new-messages t]
1721 ["Search a Folder..." mh-search-folder t]
1722 ["Indexed Search..." mh-index-search t]
1724 ["Quit MH-E" mh-quit t]))
1728 (defmacro mh-remove-xemacs-horizontal-scrollbar ()
1729 "Get rid of the horizontal scrollbar that XEmacs insists on putting in."
1730 (when mh-xemacs-flag
1731 `(if (and (featurep 'scrollbar)
1732 (fboundp 'set-specifier))
1733 (set-specifier horizontal-scrollbar-visible-p nil
1734 (cons (current-buffer) nil)))))
1736 (defmacro mh-write-file-functions-compat ()
1737 "Return `write-file-functions' if it exists.
1738 Otherwise return `local-write-file-hooks'. This macro exists
1739 purely for compatibility. The former symbol is used in Emacs 21.4
1740 onward while the latter is used in previous versions and XEmacs."
1741 (if (boundp 'write-file-functions)
1742 ''write-file-functions ;Emacs 21.4
1743 ''local-write-file-hooks)) ;<Emacs 21.4, XEmacs
1745 ;; Avoid compiler warnings in non-bleeding edge versions of Emacs.
1747 (defvar tool-bar-mode)
1748 (defvar tool-bar-map)
1749 (defvar desktop-save-buffer)) ;Emacs 21.4
1751 ;; Register mh-folder-mode as supporting which-function-mode...
1752 (load "which-func" t t)
1753 (when (and (boundp 'which-func-modes)
1754 (not (member 'mh-folder-mode which-func-modes)))
1755 (push 'mh-folder-mode which-func-modes))
1757 (defvar mh-folder-buttons-init-flag nil)
1759 ;; Autoload cookie needed by desktop.el
1761 (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder"
1762 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
1764 You can show the message the cursor is pointing to, and step through
1765 the messages. Messages can be marked for deletion or refiling into
1766 another folder; these commands are executed all at once with a
1769 Options that control this mode can be changed with
1770 \\[customize-group]; specify the \"mh\" group. In particular, please
1771 see the `mh-scan-format-file' option if you wish to modify scan's
1774 When a folder is visited, the hook `mh-folder-mode-hook' is run.
1778 Many commands that operate on individual messages, such as
1779 `mh-forward' or `mh-refile-msg' take a RANGE argument. This argument
1780 can be used in several ways.
1782 If you provide the prefix argument (\\[universal-argument]) to
1783 these commands, then you will be prompted for the message range.
1784 This can be any valid MH range which can include messages,
1785 sequences, and the abbreviations (described in the mh(1) man
1789 Indicates all messages in the range <num1> to <num2>, inclusive.
1790 The range must be nonempty.
1795 Up to N messages beginning with (or ending with) message num. Num
1796 may be any of the predefined symbols: first, prev, cur, next or
1803 The first, previous, next or last messages, if they exist.
1806 All of the messages.
1808 For example, a range that shows all of these things is `1 2 3
1809 5-10 last:5 unseen'.
1811 If the option `transient-mark-mode' is set to t and you set a
1812 region in the MH-Folder buffer, then the MH-E command will
1813 perform the operation on all messages in that region.
1815 \\{mh-folder-mode-map}"
1817 (unless mh-folder-buttons-init-flag
1818 (mh-tool-bar-folder-buttons-init)
1819 (setq mh-folder-buttons-init-flag t)))
1820 (make-local-variable 'font-lock-defaults)
1821 (setq font-lock-defaults '(mh-folder-font-lock-keywords t))
1822 (make-local-variable 'desktop-save-buffer)
1823 (setq desktop-save-buffer t)
1825 'mh-colors-available-flag (mh-colors-available-p)
1826 ; Do we have colors available
1827 'mh-current-folder (buffer-name) ; Name of folder, a string
1828 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
1829 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
1830 (file-name-as-directory (mh-expand-file-name (buffer-name)))
1831 'mh-display-buttons-for-inline-parts-flag
1832 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to
1834 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed
1835 'overlay-arrow-position nil ; Allow for simultaneous display in
1836 'overlay-arrow-string ">" ; different MH-E buffers.
1837 'mh-showing-mode nil ; Show message also?
1838 'mh-delete-list nil ; List of msgs nums to delete
1839 'mh-refile-list nil ; List of folder names in mh-seq-list
1840 'mh-seq-list nil ; Alist of (seq . msgs) nums
1841 'mh-seen-list nil ; List of displayed messages
1842 'mh-next-direction 'forward ; Direction to move to next message
1843 'mh-view-ops () ; Stack that keeps track of the order
1844 ; in which narrowing/threading has been
1846 'mh-folder-view-stack () ; Stack of previous views of the
1848 'mh-index-data nil ; If the folder was created by a call
1849 ; to mh-index-search this contains info
1850 ; about the search results.
1851 'mh-index-previous-search nil ; Previous folder and search-regexp
1852 'mh-index-msg-checksum-map nil ; msg -> checksum map
1853 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg )
1854 'mh-index-sequence-search-flag nil ; folder resulted from sequence search
1855 'mh-first-msg-num nil ; Number of first msg in buffer
1856 'mh-last-msg-num nil ; Number of last msg in buffer
1857 'mh-msg-count nil ; Number of msgs in buffer
1858 'mh-mode-line-annotation nil ; Indicates message range
1859 'mh-sequence-notation-history (make-hash-table)
1860 ; Remember what is overwritten by
1862 'imenu-create-index-function 'mh-index-create-imenu-index
1863 ; Setup imenu support
1864 'mh-previous-window-config nil) ; Previous window configuration
1865 (mh-remove-xemacs-horizontal-scrollbar)
1866 (setq truncate-lines t)
1868 (setq buffer-offer-save t)
1869 (mh-make-local-hook (mh-write-file-functions-compat))
1870 (add-hook (mh-write-file-functions-compat) 'mh-execute-commands nil t)
1871 (make-local-variable 'revert-buffer-function)
1872 (make-local-variable 'hl-line-mode) ; avoid pollution
1873 (mh-funcall-if-exists hl-line-mode 1)
1874 (setq revert-buffer-function 'mh-undo-folder)
1875 (or (assq 'mh-showing-mode minor-mode-alist)
1876 (setq minor-mode-alist
1877 (cons '(mh-showing-mode " Show") minor-mode-alist)))
1878 (easy-menu-add mh-folder-sequence-menu)
1879 (easy-menu-add mh-folder-message-menu)
1880 (easy-menu-add mh-folder-folder-menu)
1881 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)
1882 (mh-funcall-if-exists mh-tool-bar-init :folder)
1883 (if (and mh-xemacs-flag
1884 font-lock-auto-fontify)
1885 (turn-on-font-lock))) ; Force font-lock in XEmacs.
1887 (defun mh-toggle-mime-buttons ()
1888 "Toggle option `mh-display-buttons-for-inline-parts-flag'."
1890 (setq mh-display-buttons-for-inline-parts-flag
1891 (not mh-display-buttons-for-inline-parts-flag))
1894 (defun mh-colors-available-p ()
1895 "Check if colors are available in the Emacs being used."
1898 (or (ignore-errors (mh-funcall-if-exists display-color-cells))
1899 (ignore-errors (mh-funcall-if-exists
1900 x-display-color-cells)))))
1901 (and (numberp color-cells) (>= color-cells 8)))))
1903 (defun mh-colors-in-use-p ()
1904 "Check if colors are being used in the folder buffer."
1905 (and mh-colors-available-flag font-lock-mode))
1907 (defun mh-make-local-vars (&rest pairs)
1908 "Initialize local variables according to the variable-value PAIRS."
1911 (set (make-local-variable (car pairs)) (car (cdr pairs)))
1912 (setq pairs (cdr (cdr pairs)))))
1914 (defun mh-restore-desktop-buffer (desktop-buffer-file-name
1916 desktop-buffer-misc)
1917 "Restore an MH folder buffer specified in a desktop file.
1918 When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the
1919 file name to visit, DESKTOP-BUFFER-NAME holds the desired buffer
1920 name, and DESKTOP-BUFFER-MISC holds a list of miscellaneous info
1921 used by the `desktop-buffer-handlers' functions."
1923 (mh-visit-folder desktop-buffer-name)
1926 ;; desktop-buffer-mode-handlers appeared in Emacs 22.
1927 (if (fboundp 'desktop-buffer-mode-handlers)
1928 (add-to-list 'desktop-buffer-mode-handlers
1929 '(mh-folder-mode . mh-restore-desktop-buffer)))
1931 (defun mh-scan-folder (folder range &optional dont-exec-pending)
1932 "Scan FOLDER over RANGE.
1934 After the scan is performed, switch to the buffer associated with
1937 Check the documentation of `mh-interactive-range' to see how RANGE is
1938 read in interactive use.
1940 The processing of outstanding commands is not performed if
1941 DONT-EXEC-PENDING is non-nil."
1942 (when (stringp range)
1943 (setq range (delete "" (split-string range "[ \t\n]"))))
1944 (cond ((null (get-buffer folder))
1945 (mh-make-folder folder))
1947 (unless dont-exec-pending
1948 (mh-process-or-undo-commands folder)
1949 (mh-reset-threads-and-narrowing))
1950 (switch-to-buffer folder)))
1951 (mh-regenerate-headers range)
1952 (if (zerop (buffer-size))
1953 (if (equal range "all")
1954 (message "Folder %s is empty" folder)
1955 (message "No messages in %s, range %s" folder range))
1957 (when (mh-outstanding-commands-p)
1958 (mh-notate-deleted-and-refiled)))
1960 (defun mh-msg-num-width-to-column (width)
1961 "Return the column for notations given message number WIDTH.
1962 Note that columns in Emacs start with 0.
1964 If `mh-scan-format-file' is set to \"Use MH-E scan Format\" this
1965 means that either `mh-scan-format-mh' or `mh-scan-format-nmh' are
1966 in use. This function therefore assumes that the first column is
1967 empty (to provide room for the cursor), the following WIDTH
1968 columns contain the message number, and the column for notations
1970 (if (eq mh-scan-format-file t)
1972 (error "%s %s" "Can't call mh-msg-num-width-to-column"
1973 "when mh-scan-format-file is not t")))
1975 (defun mh-set-cmd-note (column)
1976 "Set `mh-cmd-note' to COLUMN.
1977 Note that columns in Emacs start with 0."
1978 (setq mh-cmd-note column))
1980 (defun mh-regenerate-headers (range &optional update)
1981 "Scan folder over RANGE.
1982 If UPDATE, append the scan lines, otherwise replace."
1983 (let ((folder mh-current-folder)
1984 (range (if (and range (atom range)) (list range) range))
1986 (message "Scanning %s..." folder)
1987 (mh-remove-all-notation)
1988 (with-mh-folder-updating (nil)
1990 (goto-char (point-max))
1991 (delete-region (point-min) (point-max))
1992 (if mh-adaptive-cmd-note-flag
1993 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width
1995 (setq scan-start (point))
1996 (apply #'mh-exec-cmd-output
1999 "-noclear" "-noheader"
2000 "-width" (window-width)
2002 (goto-char scan-start)
2003 (cond ((looking-at "scan: no messages in")
2004 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines
2005 ((looking-at (if (mh-variant-p 'mu-mh)
2006 "scan: message set .* does not exist"
2007 "scan: bad message list "))
2008 (keep-lines mh-scan-valid-regexp))
2009 ((looking-at "scan: ")) ; Keep error messages
2011 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines
2012 (setq mh-seq-list (mh-read-folder-sequences folder nil))
2013 (mh-notate-user-sequences)
2015 (setq mh-mode-line-annotation
2016 (if (equal range '("all"))
2018 mh-partial-folder-mode-line-annotation)))
2019 (mh-make-folder-mode-line))
2020 (message "Scanning %s...done" folder)))
2022 (defun mh-generate-new-cmd-note (folder)
2023 "Fix the `mh-cmd-note' value for this FOLDER.
2025 After doing an `mh-get-new-mail' operation in this FOLDER, at least
2026 one line that looks like a truncated message number was found.
2028 Remove the text added by the last `mh-inc' command. It should be the
2029 messages cur-last. Call `mh-set-cmd-note', adjusting the notation
2030 column with the width of the largest message number in FOLDER.
2032 Reformat the message number width on each line in the buffer and trim
2033 the line length to fit in the window.
2035 Rescan the FOLDER in the range cur-last in order to display the
2036 messages that were removed earlier. They should all fit in the scan
2037 line now with no message truncation."
2039 (let ((maxcol (1- (window-width)))
2040 (old-cmd-note mh-cmd-note)
2043 ;; Nuke all of the lines just added by the last inc
2044 (delete-char (- (point-max) (point)))
2045 ;; Update the current buffer to reflect the new mh-cmd-note
2046 ;; value needed to display messages.
2047 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder)))
2048 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d"))
2049 ;; Cleanup the messages that are in the buffer right now
2050 (goto-char (point-min))
2051 (cond ((memq 'unthread mh-view-ops)
2052 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note)))
2053 (t (while (re-search-forward mh-scan-msg-number-regexp nil 0 1)
2054 ;; reformat the number to fix in mh-cmd-note columns
2055 (setq msgnum (string-to-number
2057 (match-beginning 1) (match-end 1))))
2058 (replace-match (format mh-cmd-note-fmt msgnum))
2059 ;; trim the line to fix in the window
2061 (let ((eol (point)))
2062 (move-to-column maxcol)
2063 (if (<= (point) eol)
2064 (delete-char (- eol (point))))))))
2065 ;; now re-read the lost messages
2066 (goto-char (point-max))
2068 (mh-regenerate-headers "cur-last" t)))))
2070 (defun mh-get-new-mail (maildrop-name)
2071 "Read new mail from MAILDROP-NAME into the current buffer.
2072 Return in the current buffer."
2073 (let ((point-before-inc (point))
2074 (folder mh-current-folder)
2075 (new-mail-flag nil))
2076 (with-mh-folder-updating (t)
2078 (message "inc %s -file %s..." folder maildrop-name)
2079 (message "inc %s..." folder))
2080 (setq mh-next-direction 'forward)
2081 (goto-char (point-max))
2082 (mh-remove-cur-notation)
2083 (let ((start-of-inc (point)))
2085 ;; I think MH 5 used "-ms-file" instead of "-file",
2086 ;; which would make inc'ing from maildrops fail.
2087 (mh-exec-cmd-output mh-inc-prog nil folder
2089 "-file" (expand-file-name maildrop-name)
2090 "-width" (window-width)
2092 (mh-exec-cmd-output mh-inc-prog nil
2094 "-width" (window-width)))
2096 (message "inc %s -file %s...done" folder maildrop-name)
2097 (message "inc %s...done" folder))
2098 (goto-char start-of-inc)
2099 (cond ((save-excursion
2100 (re-search-forward "^inc: no mail" nil t))
2101 (message "No new mail%s%s" (if maildrop-name " in " "")
2102 (if maildrop-name maildrop-name "")))
2103 ((and (when mh-folder-view-stack
2104 (let ((saved-text (buffer-substring-no-properties
2105 start-of-inc (point-max))))
2106 (delete-region start-of-inc (point-max))
2107 (unwind-protect (mh-widen t)
2108 (mh-remove-cur-notation)
2109 (goto-char (point-max))
2110 (setq start-of-inc (point))
2112 (goto-char start-of-inc))))
2114 ((re-search-forward "^inc:" nil t) ; Error messages
2115 (error "Error incorporating mail"))
2117 (equal mh-scan-format-file t)
2118 mh-adaptive-cmd-note-flag
2119 ;; Have we reached an edge condition?
2121 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1))
2122 (setq start-of-inc (mh-generate-new-cmd-note folder))
2125 (setq new-mail-flag t)))
2126 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines
2127 (let* ((sequences (mh-read-folder-sequences folder t))
2128 (new-cur (assoc 'cur sequences))
2129 (new-unseen (assoc mh-unseen-seq sequences)))
2130 (unless (assoc 'cur mh-seq-list)
2131 (push (list 'cur) mh-seq-list))
2132 (unless (assoc mh-unseen-seq mh-seq-list)
2133 (push (list mh-unseen-seq) mh-seq-list))
2134 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur))
2135 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen)))
2136 (when (equal (point-max) start-of-inc)
2140 (mh-make-folder-mode-line)
2141 (when (mh-speed-flists-active-p)
2142 (mh-speed-flists t mh-current-folder))
2143 (when (memq 'unthread mh-view-ops)
2144 (mh-thread-inc folder start-of-inc))
2146 (goto-char point-before-inc))
2147 (mh-notate-user-sequences (cons start-of-inc (point-max)))))))
2149 (defun mh-make-folder-mode-line (&optional ignored)
2150 "Set the fields of the mode line for a folder buffer.
2151 The optional argument is now obsolete and IGNORED. It used to be
2152 used to pass in what is now stored in the buffer-local variable
2153 `mh-mode-line-annotation'."
2155 (save-window-excursion
2157 (let ((new-first-msg-num (mh-get-msg-num nil)))
2158 (when (or (not (memq 'unthread mh-view-ops))
2159 (null mh-first-msg-num)
2160 (null new-first-msg-num)
2161 (< new-first-msg-num mh-first-msg-num))
2162 (setq mh-first-msg-num new-first-msg-num)))
2164 (let ((new-last-msg-num (mh-get-msg-num nil)))
2165 (when (or (not (memq 'unthread mh-view-ops))
2166 (null mh-last-msg-num)
2167 (null new-last-msg-num)
2168 (> new-last-msg-num mh-last-msg-num))
2169 (setq mh-last-msg-num new-last-msg-num)))
2170 (setq mh-msg-count (if mh-first-msg-num
2171 (count-lines (point-min) (point-max))
2173 (setq mode-line-buffer-identification
2174 (list (format " {%%b%s} %s msg%s"
2175 (if mh-mode-line-annotation
2176 (format "/%s" mh-mode-line-annotation)
2178 (if (zerop mh-msg-count)
2180 (format "%d" mh-msg-count))
2181 (if (zerop mh-msg-count)
2183 (cond ((> mh-msg-count 1)
2184 (format "s (%d-%d)" mh-first-msg-num
2187 (format " (%d)" mh-first-msg-num))
2189 (mh-logo-display))))
2191 (defun mh-add-sequence-notation (msg internal-seq-flag)
2192 "Add sequence notation to the MSG on the current line.
2193 If INTERNAL-SEQ-FLAG is non-nil, then refontify the scan line if
2194 font-lock is turned on."
2195 (with-mh-folder-updating (t)
2198 (if internal-seq-flag
2200 ;; Change the buffer so that if transient-mark-mode is active
2201 ;; and there is an active region it will get deactivated as in
2202 ;; the case of user sequences.
2203 (mh-notate nil nil mh-cmd-note)
2204 (when font-lock-mode
2205 (font-lock-fontify-region (point) (line-end-position))))
2206 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2207 (let ((stack (gethash msg mh-sequence-notation-history)))
2208 (setf (gethash msg mh-sequence-notation-history)
2209 (cons (char-after) stack)))
2210 (mh-notate nil mh-note-seq
2211 (+ mh-cmd-note mh-scan-field-destination-offset))))))
2213 (defun mh-remove-sequence-notation (msg internal-seq-flag &optional all)
2214 "Remove sequence notation from the MSG on the current line.
2215 If INTERNAL-SEQ-FLAG is non-nil, then `font-lock' was used to
2216 highlight the sequence. In that case, no notation needs to be removed.
2217 Otherwise the effect of inserting `mh-note-seq' needs to be reversed.
2218 If ALL is non-nil, then all sequence marks on the scan line are
2220 (with-mh-folder-updating (t)
2221 ;; This takes care of internal sequences...
2222 (mh-notate nil nil mh-cmd-note)
2223 (unless internal-seq-flag
2224 ;; ... and this takes care of user sequences.
2225 (let ((stack (gethash msg mh-sequence-notation-history)))
2226 (while (and all (cdr stack))
2227 (setq stack (cdr stack)))
2231 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2233 (insert (car stack))))
2234 (setf (gethash msg mh-sequence-notation-history) (cdr stack))))))
2236 (defun mh-remove-cur-notation ()
2237 "Remove old cur notation."
2238 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2241 (mh-goto-msg cur-msg t t)
2242 (looking-at mh-scan-cur-msg-number-regexp))
2243 (mh-notate nil ? mh-cmd-note)
2244 (setq overlay-arrow-position nil)))))
2246 (defun mh-remove-all-notation ()
2247 "Remove all notations on all scan lines that MH-E introduces."
2249 (setq overlay-arrow-position nil)
2250 (goto-char (point-min))
2251 (mh-iterate-on-range msg (cons (point-min) (point-max))
2252 (mh-notate nil ? mh-cmd-note)
2253 (mh-remove-sequence-notation msg nil t))
2254 (clrhash mh-sequence-notation-history)))
2257 (defun mh-goto-cur-msg (&optional minimal-changes-flag)
2258 "Position the cursor at the current message.
2259 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the
2260 function doesn't recenter the folder buffer."
2261 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2263 (mh-goto-msg cur-msg t t))
2264 (unless minimal-changes-flag
2267 (mh-maybe-show cur-msg)))
2269 (setq overlay-arrow-position nil)
2270 (message "No current message")))))
2272 (defun mh-process-or-undo-commands (folder)
2273 "If FOLDER has outstanding commands, then either process or discard them.
2274 Called by functions like `mh-sort-folder', so also invalidate
2277 (if (mh-outstanding-commands-p)
2278 (if (or mh-do-not-confirm-flag
2280 "Process outstanding deletes and refiles? "))
2281 (mh-process-commands folder)
2285 (mh-invalidate-show-buffer))
2287 (defun mh-process-commands (folder)
2288 "Process outstanding commands for FOLDER.
2290 This function runs `mh-before-commands-processed-hook' before the
2291 commands are processed and `mh-after-commands-processed-hook'
2292 after the commands are processed."
2293 (message "Processing deletes and refiles for %s..." folder)
2295 (with-mh-folder-updating (nil)
2296 ;; Run the before hook -- the refile and delete lists are still valid
2297 (run-hooks 'mh-before-commands-processed-hook)
2299 ;; Update the unseen sequence if it exists
2302 (let ((redraw-needed-flag mh-index-data)
2303 (folders-changed (list mh-current-folder))
2304 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag
2305 (mh-create-sequence-map mh-seq-list)))
2306 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag
2307 (make-hash-table))))
2308 ;; Remove invalid scan lines if we are in an index folder and then remove
2309 ;; the real messages
2311 (mh-index-delete-folder-headers)
2312 (setq folders-changed
2313 (append folders-changed (mh-index-execute-commands))))
2315 ;; Then refile messages
2316 (mh-mapc #'(lambda (folder-msg-list)
2317 (let* ((dest-folder (symbol-name (car folder-msg-list)))
2318 (last (car (mh-translate-range dest-folder "last")))
2319 (msgs (cdr folder-msg-list)))
2320 (push dest-folder folders-changed)
2321 (setq redraw-needed-flag t)
2322 (apply #'mh-exec-cmd
2323 "refile" "-src" folder dest-folder
2324 (mh-coalesce-msg-list msgs))
2325 (mh-delete-scan-msgs msgs)
2326 ;; Preserve sequences in destination folder...
2327 (when mh-refile-preserves-sequences-flag
2329 (loop for i from (1+ (or last 0))
2330 for msg in (sort (copy-sequence msgs) #'<)
2331 do (loop for seq-name in (gethash msg seq-map)
2332 do (push i (gethash seq-name dest-map))))
2334 #'(lambda (seq msgs)
2335 ;; Can't be run in the background, since the
2336 ;; current folder is changed by mark this could
2337 ;; lead to a race condition with the next refile.
2338 (apply #'mh-exec-cmd "mark"
2339 "-sequence" (symbol-name seq) dest-folder
2340 "-add" (mapcar #'(lambda (x) (format "%s" x))
2341 (mh-coalesce-msg-list msgs))))
2344 (setq mh-refile-list ())
2346 ;; Now delete messages
2347 (cond (mh-delete-list
2348 (setq redraw-needed-flag t)
2349 (apply 'mh-exec-cmd "rmm" folder
2350 (mh-coalesce-msg-list mh-delete-list))
2351 (mh-delete-scan-msgs mh-delete-list)
2352 (setq mh-delete-list nil)))
2354 ;; Don't need to remove sequences since delete and refile do so.
2356 (if (> (buffer-size) 0)
2357 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last"))))
2359 ;; Redraw folder buffer if needed
2360 (when (and redraw-needed-flag)
2361 (when (mh-speed-flists-active-p)
2362 (apply #'mh-speed-flists t folders-changed))
2363 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max)))
2364 (mh-index-data (mh-index-insert-folder-headers))))
2366 (and (buffer-file-name (get-buffer mh-show-buffer))
2367 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
2368 ;; If "inc" were to put a new msg in this file,
2369 ;; we would not notice, so mark it invalid now.
2370 (mh-invalidate-show-buffer))
2372 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
2373 (mh-remove-all-notation)
2374 (mh-notate-user-sequences)
2376 ;; Run the after hook -- now folders-changed is valid,
2377 ;; but not the lists of specific messages.
2378 (let ((mh-folders-changed folders-changed))
2379 (run-hooks 'mh-after-commands-processed-hook)))
2381 (message "Processing deletes and refiles for %s...done" folder)))
2383 (defun mh-update-unseen ()
2384 "Synchronize the unseen sequence with MH.
2385 Return non-nil iff the MH folder was set.
2386 The hook `mh-unseen-updated-hook' is called after the unseen sequence
2389 (let* ((unseen-seq (mh-find-seq mh-unseen-seq))
2390 (unseen-msgs (mh-seq-msgs unseen-seq)))
2393 (mh-undefine-sequence mh-unseen-seq mh-seen-list)
2394 (run-hooks 'mh-unseen-updated-hook)
2396 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs))
2397 (setq mh-seen-list (cdr mh-seen-list)))
2398 (setcdr unseen-seq unseen-msgs)
2399 t) ;since we set the folder
2400 (setq mh-seen-list nil)))))
2402 (defun mh-delete-scan-msgs (msgs)
2403 "Delete the scan listing lines for MSGS."
2406 (when (mh-goto-msg (car msgs) t t)
2407 (when (memq 'unthread mh-view-ops)
2408 (mh-thread-forget-message (car msgs)))
2410 (setq msgs (cdr msgs)))))
2412 (defun mh-outstanding-commands-p ()
2413 "Return non-nil if there are outstanding deletes or refiles."
2415 (when (eq major-mode 'mh-show-mode)
2416 (set-buffer mh-show-folder-buffer))
2417 (or mh-delete-list mh-refile-list)))
2419 (defun mh-coalesce-msg-list (messages)
2420 "Given a list of MESSAGES, return a list of message number ranges.
2421 This is the inverse of `mh-read-msg-list', which expands ranges.
2422 Message lists passed to MH programs should be processed by this
2423 function to avoid exceeding system command line argument limits."
2424 (let ((msgs (sort (copy-sequence messages) 'mh-greaterp))
2430 (if (or (not (numberp prev))
2431 (not (equal (car msgs) (1- prev))))
2432 (progn ;non-sequential, flush old range
2433 (if (eq prev range-high)
2434 (setq ranges (cons range-high ranges))
2435 (setq ranges (cons (format "%s-%s" prev range-high) ranges)))
2436 (setq range-high nil))))
2438 (setq range-high (car msgs))) ;start new or first range
2439 (setq prev (car msgs))
2440 (setq msgs (cdr msgs)))
2443 (defun mh-greaterp (msg1 msg2)
2444 "Return the greater of two message indicators MSG1 and MSG2.
2445 Strings are \"smaller\" than numbers.
2446 Valid values are things like \"cur\", \"last\", 1, and 1820."
2453 (string-lessp msg2 msg1))))
2455 (defun mh-lessp (msg1 msg2)
2456 "Return the lesser of two message indicators MSG1 and MSG2.
2457 Strings are \"smaller\" than numbers.
2458 Valid values are things like \"cur\", \"last\", 1, and 1820."
2459 (not (mh-greaterp msg1 msg2)))
2463 ;;; Basic sequence handling
2465 (defun mh-delete-seq-locally (seq)
2466 "Remove MH-E's record of SEQ."
2467 (let ((entry (mh-find-seq seq)))
2468 (setq mh-seq-list (delq entry mh-seq-list))))
2470 (defun mh-read-folder-sequences (folder save-refiles)
2471 "Read and return the predefined sequences for a FOLDER.
2472 If SAVE-REFILES is non-nil, then keep the sequences
2473 that note messages to be refiled."
2476 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
2477 (if (mh-folder-name-p (mh-seq-name seq))
2478 (setq seqs (cons seq seqs)))))
2481 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
2483 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
2484 (while (re-search-forward "^[^: ]+" nil t)
2485 (setq seqs (cons (mh-make-seq (intern (buffer-substring
2490 (delete-region (point-min) (point))))) ; avoid race with
2494 (defun mh-read-msg-list ()
2495 "Return a list of message numbers from point to the end of the line.
2496 Expands ranges into set of individual numbers."
2498 (end-of-line (save-excursion (end-of-line) (point)))
2500 (while (re-search-forward "[0-9]+" end-of-line t)
2501 (setq num (string-to-number (buffer-substring (match-beginning 0)
2503 (cond ((looking-at "-") ; Message range
2505 (re-search-forward "[0-9]+" end-of-line t)
2506 (let ((num2 (string-to-number
2507 (buffer-substring (match-beginning 0)
2510 (error "Bad message range: %d-%d" num num2))
2511 (while (<= num num2)
2512 (setq msgs (cons num msgs))
2513 (setq num (1+ num)))))
2514 ((not (zerop num)) ;"pick" outputs "0" to mean no match
2515 (setq msgs (cons num msgs)))))
2518 (defun mh-notate-user-sequences (&optional range)
2519 "Mark user-defined sequences in RANGE.
2521 Check the documentation of `mh-interactive-range' to see how
2522 RANGE is read in interactive use; if nil all messages are
2525 (setq range (cons (point-min) (point-max))))
2526 (let ((seqs mh-seq-list)
2527 (msg-hash (make-hash-table)))
2529 (dolist (msg (mh-seq-msgs seq))
2530 (push (car seq) (gethash msg msg-hash))))
2531 (mh-iterate-on-range msg range
2532 (loop for seq in (gethash msg msg-hash)
2533 do (mh-add-sequence-notation msg (mh-internal-seq seq))))))
2535 (defvar mh-internal-seqs '(answered cur deleted forwarded printed))
2537 (defun mh-internal-seq (name)
2538 "Return non-nil if NAME is the name of an internal MH-E sequence."
2539 (or (memq name mh-internal-seqs)
2540 (eq name mh-unseen-seq)
2541 (and (mh-colors-in-use-p) mh-tick-seq (eq name mh-tick-seq))
2542 (eq name mh-previous-seq)
2543 (mh-folder-name-p name)))
2545 (defun mh-valid-seq-p (name)
2546 "Return non-nil if NAME is a valid MH sequence name."
2548 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" (symbol-name name))))
2550 (defun mh-delete-msg-from-seq (range sequence &optional internal-flag)
2551 "Delete RANGE from SEQUENCE.
2553 Check the documentation of `mh-interactive-range' to see how
2554 RANGE is read in interactive use.
2556 In a program, non-nil INTERNAL-FLAG means do not inform MH of the
2558 (interactive (list (mh-interactive-range "Delete")
2559 (mh-read-seq-default "Delete from" t)
2561 (let ((entry (mh-find-seq sequence))
2562 (user-sequence-flag (not (mh-internal-seq sequence)))
2563 (folders-changed (list mh-current-folder))
2566 (mh-iterate-on-range msg range
2568 ;; Calling "mark" repeatedly takes too long. So we will pretend here
2569 ;; that we are just modifying an internal sequence...
2570 (when (memq msg (cdr entry))
2571 (mh-remove-sequence-notation msg (not user-sequence-flag)))
2572 (mh-delete-a-msg-from-seq msg sequence t))
2573 ;; ... and here we will "mark" all the messages at one go.
2574 (unless internal-flag (mh-undefine-sequence sequence msg-list))
2575 (when (and mh-index-data (not internal-flag))
2576 (setq folders-changed
2577 (append folders-changed
2578 (mh-index-delete-from-sequence sequence msg-list))))
2579 (when (and (eq sequence mh-unseen-seq) (mh-speed-flists-active-p))
2580 (apply #'mh-speed-flists t folders-changed)))))
2582 (defun mh-catchup (range)
2583 "Delete RANGE from the \"unseen\" sequence.
2585 Check the documentation of `mh-interactive-range' to see how
2586 RANGE is read in interactive use."
2587 (interactive (list (mh-interactive-range "Catchup"
2588 (cons (point-min) (point-max)))))
2589 (mh-delete-msg-from-seq range mh-unseen-seq))
2591 (defun mh-delete-a-msg-from-seq (msg sequence internal-flag)
2592 "Delete MSG from SEQUENCE.
2593 If INTERNAL-FLAG is non-nil, then do not inform MH of the
2595 (let ((entry (mh-find-seq sequence)))
2596 (when (and entry (memq msg (mh-seq-msgs entry)))
2597 (if (not internal-flag)
2598 (mh-undefine-sequence sequence (list msg)))
2599 (setcdr entry (delq msg (mh-seq-msgs entry))))))
2601 (defun mh-undefine-sequence (seq msgs)
2602 "Remove from the SEQ the list of MSGS."
2603 (when (and (mh-valid-seq-p seq) msgs)
2604 (apply #'mh-exec-cmd "mark" mh-current-folder "-delete"
2605 "-sequence" (symbol-name seq) (mh-coalesce-msg-list msgs))))
2607 (defun mh-define-sequence (seq msgs)
2608 "Define the SEQ to contain the list of MSGS.
2609 Do not mark pseudo-sequences or empty sequences.
2610 Signals an error if SEQ is an invalid name."
2612 (mh-valid-seq-p seq)
2613 (not (mh-folder-name-p seq)))
2615 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
2616 "-sequence" (symbol-name seq)
2617 (mh-coalesce-msg-list msgs)))))
2619 (defun mh-seq-containing-msg (msg &optional include-internal-flag)
2620 "Return a list of the sequences containing MSG.
2621 If INCLUDE-INTERNAL-FLAG non-nil, include MH-E internal sequences
2623 (let ((l mh-seq-list)
2626 (and (memq msg (mh-seq-msgs (car l)))
2627 (or include-internal-flag
2628 (not (mh-internal-seq (mh-seq-name (car l)))))
2629 (setq seqs (cons (mh-seq-name (car l)) seqs)))
2635 ;;; Build mh-folder-mode keymap:
2637 (suppress-keymap mh-folder-mode-map)
2639 ;; Use defalias to make sure the documented primary key bindings
2640 ;; appear in menu lists.
2641 (defalias 'mh-alt-show 'mh-show)
2642 (defalias 'mh-alt-refile-msg 'mh-refile-msg)
2643 (defalias 'mh-alt-send 'mh-send)
2644 (defalias 'mh-alt-visit-folder 'mh-visit-folder)
2646 ;; Save the `b' binding for a future `back'. Maybe?
2647 (gnus-define-keys mh-folder-mode-map
2649 "!" mh-refile-or-write-again
2651 "," mh-header-display
2653 ";" mh-toggle-mh-decode-mime-flag
2654 ">" mh-write-msg-to-file
2656 "E" mh-extract-rejected-mail
2658 "\177" mh-previous-page
2659 "\C-d" mh-delete-msg-no-motion
2660 "\t" mh-index-next-folder
2661 [backtab] mh-index-previous-folder
2662 "\M-\t" mh-index-previous-folder
2665 "\ed" mh-redistribute
2667 "^" mh-alt-refile-msg
2674 "k" mh-delete-subject-or-thread
2676 "n" mh-next-undeleted-msg
2677 "\M-n" mh-next-unread-msg
2679 "p" mh-previous-undeleted-msg
2680 "\M-p" mh-previous-unread-msg
2684 "t" mh-toggle-showing
2686 "v" mh-index-visit-folder
2687 "x" mh-execute-commands
2690 (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map)
2692 "'" mh-index-ticked-messages
2695 "f" mh-alt-visit-folder
2699 "n" mh-index-new-messages
2700 "o" mh-alt-visit-folder
2702 "q" mh-index-sequenced-messages
2703 "r" mh-rescan-folder
2704 "s" mh-search-folder
2706 "v" mh-visit-folder)
2708 (define-key mh-folder-mode-map "I" mh-inc-spool-map)
2710 (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map)
2712 "b" mh-junk-blacklist
2713 "w" mh-junk-whitelist)
2715 (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map)
2717 "C" mh-ps-print-toggle-color
2718 "F" mh-ps-print-toggle-faces
2719 "f" mh-ps-print-msg-file
2721 "p" mh-ps-print-msg)
2723 (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map)
2724 "'" mh-narrow-to-tick
2726 "d" mh-delete-msg-from-seq
2728 "l" mh-list-sequences
2729 "n" mh-narrow-to-seq
2730 "p" mh-put-msg-in-seq
2731 "s" mh-msg-is-in-seq
2734 (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map)
2736 "u" mh-thread-ancestor
2737 "p" mh-thread-previous-sibling
2738 "n" mh-thread-next-sibling
2739 "t" mh-toggle-threads
2740 "d" mh-thread-delete
2741 "o" mh-thread-refile)
2743 (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map)
2744 "'" mh-narrow-to-tick
2747 "f" mh-narrow-to-from
2748 "r" mh-narrow-to-range
2749 "s" mh-narrow-to-subject
2753 (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map)
2755 "s" mh-store-msg ;shar
2756 "u" mh-store-msg) ;uuencode
2758 (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map)
2761 "\177" mh-page-digest-backwards
2762 "b" mh-burst-digest)
2764 (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map)
2766 "a" mh-mime-save-parts
2767 "e" mh-display-with-external-viewer
2768 "i" mh-folder-inline-mime-part
2769 "o" mh-folder-save-mime-part
2770 "t" mh-toggle-mime-buttons
2771 "v" mh-folder-toggle-mime-part
2773 [backtab] mh-prev-button
2774 "\M-\t" mh-prev-button)
2778 (define-key mh-folder-mode-map [button2] 'mh-show-mouse))
2780 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse)))
2782 ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt
2788 ;; If you add a new prefix, add appropriate text to the nil key.
2790 ;; In general, messages are grouped logically. Taking the main commands for
2791 ;; example, the first line is "ways to view messages," the second line is
2792 ;; "things you can do with messages", and the third is "composing" messages.
2794 ;; When adding a new prefix, ensure that the help message contains "what" the
2795 ;; prefix is for. For example, if the word "folder" were not present in the
2796 ;; `F' entry, it would not be clear what these commands operated upon.
2797 (defvar mh-help-messages
2798 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n"
2799 "[d]elete, [o]refile, e[x]ecute,\n"
2800 "[s]end, [r]eply,\n"
2801 "[;]toggle MIME decoding.\n"
2802 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys,"
2803 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.")
2805 (?F "[l]ist; [v]isit folder;\n"
2806 "[n]ew messages; [']ticked messages; [s]earch; [i]ndexed search;\n"
2807 "[p]ack; [S]ort; [r]escan; [k]ill")
2808 (?P "[p]rint message to [f]ile; old-style [l]pr printing;\n"
2809 "Toggle printing of [C]olors, [F]aces")
2810 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n"
2811 "[s]equences, [l]ist,\n"
2812 "[d]elete message from sequence, [k]ill sequence")
2813 (?T "[t]oggle, [d]elete, [o]refile thread")
2814 (?/ "Limit to [c]c, [f]rom, [r]ange, [s]ubject, [t]o; [w]iden")
2815 (?X "un[s]har, [u]udecode message")
2816 (?D "[b]urst digest")
2817 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n"
2818 "[TAB] next; [SHIFT-TAB] previous")
2819 (?J "[b]lacklist, [w]hitelist message"))
2820 "Key binding cheat sheet.
2822 This is an associative array which is used to show the most common commands.
2823 The key is a prefix char. The value is one or more strings which are
2824 concatenated together and displayed in the minibuffer if ? is pressed after
2825 the prefix character. The special key nil is used to display the
2826 non-prefixed commands.
2828 The substitutions described in `substitute-command-keys' are performed as
2833 (dolist (mess '("^Cursor not pointing to message$"
2834 "^There is no other window$"))
2835 (add-to-list 'debug-ignored-errors mess))
2840 ;; indent-tabs-mode: nil
2841 ;; sentence-end-double-space: nil
2844 ;; arch-tag: cce884de-bd37-4104-9963-e4439d5ed22b
2845 ;;; mh-e.el ends here