1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system
3 ;; Copyright (C) 1985, 1986, 1987, 1988,
4 ;; 1990, 1992, 1993, 1994, 1995, 1997, 1999,
5 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
7 ;; Author: Bill Wohler <wohler@newt.com>
8 ;; Maintainer: Bill Wohler <wohler@newt.com>
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
32 ;; M-x mh-rmail to read mail. Type C-h m there for a list of commands.
33 ;; C-u M-x mh-rmail to visit any folder.
34 ;; M-x mh-smail to send mail. From within the mail reader, "m" works, too.
36 ;; Your .emacs might benefit from these bindings:
37 ;; (global-set-key "\C-cr" 'mh-rmail)
38 ;; (global-set-key "\C-xm" 'mh-smail)
39 ;; (global-set-key "\C-x4m" 'mh-smail-other-window)
41 ;; MH (Message Handler) is a powerful mail reader.
43 ;; The MH newsgroup is comp.mail.mh; the mailing list is mh-users@ics.uci.edu
44 ;; (send to mh-users-request to be added). See the monthly Frequently Asked
45 ;; Questions posting there for information on getting MH and MH-E:
46 ;; http://www.faqs.org/faqs/mail/mh-faq/part1/preamble.html
48 ;; N.B. MH must have been compiled with the MHE compiler flag or several
49 ;; features necessary for MH-E will be missing from MH commands, specifically
50 ;; the -build switch to repl and forw.
52 ;; MH-E is an Emacs interface to the MH mail system.
54 ;; MH-E is supported in GNU Emacs 21 and 22 as well as XEmacs 21
55 ;; (except for versions 21.5.9-21.5.16), with MH 6.8.4 on, nmh 1.0.4
56 ;; on, and GNU mailutils 0.4 on.
59 ;; mh-e-users@lists.sourceforge.net
60 ;; mh-e-announce@lists.sourceforge.net
61 ;; mh-e-devel@lists.sourceforge.net
63 ;; Subscribe by sending a "subscribe" message to
64 ;; <list>-request@lists.sourceforge.net, or by using the web interface at
65 ;; https://sourceforge.net/mail/?group_id=13357
68 ;; https://sourceforge.net/tracker/?group_id=13357&atid=113357
69 ;; Include the output of M-x mh-version in any bug report.
72 ;; https://sourceforge.net/tracker/?atid=363357&group_id=13357&func=browse
75 ;; https://sourceforge.net/tracker/?group_id=13357&atid=213357
79 ;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
80 ;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
81 ;; Rewritten for GNU Emacs, James Larus, 1985.
82 ;; Modified by Stephen Gildea, 1988.
83 ;; Maintenance picked up by Bill Wohler and the
84 ;; SourceForge Crew <http://mh-e.sourceforge.net/>, 2001.
91 (eval-when-compile (require 'mh-acros))
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. The highlighting
198 is done with the face `mh-folder-msg-number'. This regular
199 expression should be correct as it is needed by non-fontification
202 (defvar mh-scan-deleted-msg-regexp "^\\( *[0-9]+\\)D"
203 "This regular expression matches deleted messages.
205 It must match from the beginning of the line. Note that the
206 default setting of `mh-folder-font-lock-keywords' expects this
207 expression to contain at least one parenthesized expression which
208 matches the message number as in the default of
210 \"^\\\\( *[0-9]+\\\\)D\".
212 This expression includes the leading space within the parenthesis
213 since it looks better to highlight it as well. The highlighting
214 is done with the face `mh-folder-deleted'. This regular
215 expression should be correct as it is needed by non-fontification
216 functions. See also `mh-note-deleted'.")
218 (defvar mh-scan-refiled-msg-regexp "^\\( *[0-9]+\\)\\^"
219 "This regular expression matches refiled messages.
221 It must match from the beginning of the line. Note that the
222 default setting of `mh-folder-font-lock-keywords' expects this
223 expression to contain at least one parenthesized expression which
224 matches the message number as in the default of
226 \"^\\\\( *[0-9]+\\\\)\\\\^\".
228 This expression includes the leading space within the parenthesis
229 since it looks better to highlight it as well. The highlighting
230 is done with the face `mh-folder-refiled'. This regular
231 expression should be correct as it is needed by non-fontification
232 functions. See also `mh-note-refiled'.")
234 (defvar mh-scan-valid-regexp "^ *[0-9]"
235 "This regular expression describes a valid scan line.
237 This is used to eliminate error messages that are occasionally
238 produced by \"inc\".")
240 (defvar mh-scan-cur-msg-number-regexp "^\\( *[0-9]+\\+\\).*"
241 "This regular expression matches the current message.
243 It must match from the beginning of the line. Note that the
244 default setting of `mh-folder-font-lock-keywords' expects this
245 expression to contain at least one parenthesized expression which
246 matches the message number as in the default of
248 \"^\\\\( *[0-9]+\\\\+\\\\).*\".
250 This expression includes the leading space and current message
251 marker \"+\" within the parenthesis since it looks better to
252 highlight these items as well. The highlighting is done with the
253 face `mh-folder-cur-msg-number'. This regular expression should
254 be correct as it is needed by non-fontification functions. See
255 also `mh-note-cur'.")
257 (defvar mh-scan-date-regexp "\\([0-9][0-9]/[0-9][0-9]\\)"
258 "This regular expression matches a valid date.
260 It must not be anchored to the beginning or the end of the line.
261 Note that the default setting of `mh-folder-font-lock-keywords'
262 expects this expression to contain only one parenthesized
263 expression which matches the date field as in the default of
264 \"\\\\([0-9][0-9]/[0-9][0-9]\\\\)\"}. If this regular expression
265 is not correct, the date will not be highlighted with the face
268 (defvar mh-scan-rcpt-regexp "\\(To:\\)\\(..............\\)"
269 "This regular expression specifies the recipient in messages you sent.
271 Note that the default setting of `mh-folder-font-lock-keywords'
272 expects this expression to contain two parenthesized expressions.
273 The first is expected to match the \"To:\" that the default scan
274 format file generates. The second is expected to match the
275 recipient's name as in the default of
276 \"\\\\(To:\\\\)\\\\(..............\\\\)\". If this regular
277 expression is not correct, the \"To:\" string will not be
278 highlighted with the face `mh-folder-to' and the recipient will
279 not be highlighted with the face `mh-folder-address'")
281 (defvar mh-scan-body-regexp "\\(<<\\([^\n]+\\)?\\)"
282 "This regular expression matches the message body fragment.
284 Note that the default setting of `mh-folder-font-lock-keywords'
285 expects this expression to contain at least one parenthesized
286 expression which matches the body text as in the default of
287 \"\\\\(<<\\\\([^\\n]+\\\\)?\\\\)\". If this regular expression is
288 not correct, the body fragment will not be highlighted with the
289 face `mh-folder-body'.")
291 (defvar mh-scan-subject-regexp
292 "^ *[0-9]+........[ ]*...................\\([Rr][Ee]\\(\\[[0-9]+\\]\\)?:\\s-*\\)*\\([^<\n]*\\)"
293 "This regular expression matches the subject.
295 It must match from the beginning of the line. Note that the
296 default setting of `mh-folder-font-lock-keywords' expects this
297 expression to contain at least three parenthesized expressions.
298 The first is expected to match the \"Re:\" string, if any, and is
299 highlighted with the face `mh-folder-followup'. The second
300 matches an optional bracketed number after \"Re:\", such as in
301 \"Re[2]:\" (and is thus a sub-expression of the first expression)
302 and the third is expected to match the subject line itself which
303 is highlighted with the face `mh-folder-subject'. For example,
304 the default (broken on multiple lines for readability) is
306 ^ *[0-9]+........[ ]*...................
307 \\\\([Rr][Ee]\\\\(\\\\\\=[[0-9]+\\\\]\\\\)?:\\\\s-*\\\\)*
310 This regular expression should be correct as it is needed by
311 non-fontification functions.")
313 (defvar mh-scan-sent-to-me-sender-regexp
314 "^ *[0-9]+.\\([bct]\\).....[ ]*\\(..................\\)"
315 "This regular expression matches messages sent to us.
317 Note that the default setting of `mh-folder-font-lock-keywords'
318 expects this expression to contain at least two parenthesized
319 expressions. The first should match the fontification hint (see
320 `mh-scan-format-nmh') and the second should match the user name
323 ^ *[0-9]+.\\\\([bct]\\\\).....[ ]*\\\\(..................\\\\)
325 If this regular expression is not correct, the notation hints
326 will not be highlighted with the face
327 `mh-mh-folder-sent-to-me-hint' and the sender will not be
328 highlighted with the face `mh-folder-sent-to-me-sender'.")
332 (defvar mh-folder-font-lock-keywords
334 ;; Folders when displaying index buffer
336 '(0 'mh-search-folder))
337 ;; Marked for deletion
338 (list (concat mh-scan-deleted-msg-regexp ".*")
339 '(0 'mh-folder-deleted))
341 (list (concat mh-scan-refiled-msg-regexp ".*")
342 '(0 'mh-folder-refiled))
344 (list mh-scan-body-regexp
345 '(1 'mh-folder-body nil t))
347 '(mh-folder-font-lock-subject
348 (1 'mh-folder-followup append t)
349 (2 'mh-folder-subject append t))
350 ;; Current message number
351 (list mh-scan-cur-msg-number-regexp
352 '(1 'mh-folder-cur-msg-number))
354 (list mh-scan-good-msg-regexp
355 '(1 'mh-folder-msg-number))
357 (list mh-scan-date-regexp
358 '(1 'mh-folder-date))
359 ;; Messages from me (To:)
360 (list mh-scan-rcpt-regexp
362 '(2 'mh-folder-address))
364 (list mh-scan-sent-to-me-sender-regexp
365 '(1 'mh-folder-sent-to-me-hint)
366 '(2 'mh-folder-sent-to-me-sender)))
367 "Keywords (regular expressions) used to fontify the MH-Folder buffer.")
369 (defvar mh-scan-cmd-note-width 1
370 "Number of columns consumed by the cmd-note field in `mh-scan-format'.
372 This column will have one of the values: \" \", \"D\", \"^\", \"+\" and
373 where \" \" is the default value,
375 \"D\" is the `mh-note-deleted' character,
376 \"^\" is the `mh-note-refiled' character, and
377 \"+\" is the `mh-note-cur' character.")
379 (defvar mh-scan-destination-width 1
380 "Number of columns consumed by the destination field in `mh-scan-format'.
382 This column will have one of \" \", \"%\", \"-\", \"t\", \"c\", \"b\", or \"n\"
385 \" \" blank space is the default character.
386 \"%\" indicates that the message in in a named MH sequence.
387 \"-\" indicates that the message has been annotated with a replied field.
388 \"t\" indicates that the message contains mymbox in the To: field.
389 \"c\" indicates that the message contains mymbox in the Cc: field.
390 \"b\" indicates that the message contains mymbox in the Bcc: field.
391 \"n\" indicates that the message contains a Newsgroups: field.")
393 (defvar mh-scan-date-width 5
394 "Number of columns consumed by the date field in `mh-scan-format'.
395 This column will typically be of the form mm/dd.")
397 (defvar mh-scan-date-flag-width 1
398 "Number of columns consumed to flag (in)valid dates in `mh-scan-format'.
399 This column will have \" \" for valid and \"*\" for invalid or
402 (defvar mh-scan-from-mbox-width 17
403 "Number of columns consumed with the \"From:\" line in `mh-scan-format'.
404 This column will have a friendly name or e-mail address of the
405 originator, or a \"To: address\" for outgoing e-mail messages.")
407 (defvar mh-scan-from-mbox-sep-width 2
408 "Number of columns consumed by whitespace after from-mbox in `mh-scan-format'.
409 This column will only ever have spaces in it.")
411 (defvar mh-scan-field-destination-offset
412 (+ mh-scan-cmd-note-width)
413 "The offset from the `mh-cmd-note' for the destination column.")
415 (defvar mh-scan-field-from-start-offset
416 (+ mh-scan-cmd-note-width
417 mh-scan-destination-width
419 mh-scan-date-flag-width)
420 "The offset from the `mh-cmd-note' to find the start of \"From:\" address.")
422 (defvar mh-scan-field-from-end-offset
423 (+ mh-scan-field-from-start-offset mh-scan-from-mbox-width)
424 "The offset from the `mh-cmd-note' to find the end of \"From:\" address.")
426 (defvar mh-scan-field-subject-start-offset
427 (+ mh-scan-cmd-note-width
428 mh-scan-destination-width
430 mh-scan-date-flag-width
431 mh-scan-from-mbox-width
432 mh-scan-from-mbox-sep-width)
433 "The offset from the `mh-cmd-note' to find the start of the subject.")
435 (defun mh-folder-font-lock-subject (limit)
436 "Return MH-E scan subject strings to font-lock between point and LIMIT."
437 (if (not (re-search-forward mh-scan-subject-regexp limit t))
439 (if (match-beginning 1)
440 (set-match-data (list (match-beginning 1) (match-end 3)
441 (match-beginning 1) (match-end 3) nil nil))
442 (set-match-data (list (match-beginning 3) (match-end 3)
443 nil nil (match-beginning 3) (match-end 3))))
448 ;; Fontifify unseen mesages in bold.
450 (defmacro mh-generate-sequence-font-lock (seq prefix face)
451 "Generate the appropriate code to fontify messages in SEQ.
452 PREFIX is used to generate unique names for the variables and
453 functions defined by the macro. So a different prefix should be
454 provided for every invocation.
455 FACE is the font-lock face used to display the matching scan lines."
456 (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix)))
457 (func (intern (format "mh-folder-font-lock-%s" prefix))))
460 "Internal cache variable used for font-lock in MH-E.
461 Should only be non-nil through font-lock stepping, and nil once
462 font-lock is done highlighting.")
463 (make-variable-buffer-local ',cache)
466 "Return unseen message lines to font-lock between point and LIMIT."
467 (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq))))
468 (let ((cur-msg (mh-get-msg-num nil)))
471 ((>= (point) limit) ;Presumably at end of buffer
474 ((member cur-msg ,cache)
475 (let ((bpoint (progn (beginning-of-line)(point)))
476 (epoint (progn (forward-line 1)(point))))
477 (if (<= limit (point)) (setq ,cache nil))
478 (set-match-data (list bpoint epoint bpoint epoint))
481 ;; move forward one line at a time, checking each message
482 (while (and (= 0 (forward-line 1))
484 (not (member (mh-get-msg-num nil) ,cache))))
485 ;; Examine how we must have exited the loop...
486 (let ((cur-msg (mh-get-msg-num nil)))
487 (cond ((or (<= limit (point))
488 (not (member cur-msg ,cache)))
491 ((member cur-msg ,cache)
492 (let ((bpoint (progn (beginning-of-line) (point)))
493 (epoint (progn (forward-line 1) (point))))
494 (if (<= limit (point)) (setq ,cache nil))
496 (list bpoint epoint bpoint epoint))
499 (setq mh-folder-font-lock-keywords
500 (append mh-folder-font-lock-keywords
501 (list (list ',func (list 1 '',face 'prepend t))))))))
503 (mh-generate-sequence-font-lock mh-unseen-seq unseen bold)
504 (mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick)
508 ;;; Internal variables:
510 (defvar mh-last-destination nil
511 "Destination of last refile or write command.")
513 (defvar mh-last-destination-folder nil
514 "Destination of last refile command.")
516 (defvar mh-last-destination-write nil
517 "Destination of last write command.")
519 (defvar mh-folder-mode-map (make-keymap)
520 "Keymap for MH folders.")
522 (defvar mh-arrow-marker nil
523 "Marker for arrow display in fringe.")
525 (defvar mh-delete-list nil
526 "List of message numbers to delete.
527 This variable can be used by
528 `mh-before-commands-processed-hook'.")
530 (defvar mh-refile-list nil
531 "List of folder names in `mh-seq-list'.
532 This variable can be used by
533 `mh-before-commands-processed-hook'.")
535 (defvar mh-folders-changed nil
536 "Lists which folders were affected by deletes and refiles.
537 This list will always include the current folder
538 `mh-current-folder'. This variable can be used by
539 `mh-after-commands-processed-hook'.")
541 (defvar mh-next-direction 'forward
542 "Direction to move to next message.")
544 (defvar mh-view-ops ()
545 "Stack of operations that change the folder view.
546 These operations include narrowing or threading.")
548 (defvar mh-folder-view-stack ()
549 "Stack of previous folder views.")
551 (defvar mh-index-data nil
552 "Info about index search results.")
554 (defvar mh-index-previous-search nil)
555 (defvar mh-index-msg-checksum-map nil)
556 (defvar mh-index-checksum-origin-map nil)
557 (defvar mh-index-sequence-search-flag nil)
559 (defvar mh-first-msg-num nil
560 "Number of first message in buffer.")
562 (defvar mh-last-msg-num nil
563 "Number of last msg in buffer.")
565 (defvar mh-mode-line-annotation nil
566 "Message range displayed in buffer.")
568 (defvar mh-sequence-notation-history nil
569 "Remember original notation that is overwritten by `mh-note-seq'.")
571 (defvar mh-colors-available-flag nil
572 "Non-nil means colors are available.")
576 ;;; Macros and generic functions:
578 (defun mh-mapc (function list)
579 "Apply FUNCTION to each element of LIST for side effects only."
581 (funcall function (car list))
582 (setq list (cdr list))))
584 (defun mh-scan-format ()
585 "Return the output format argument for the scan program."
586 (if (equal mh-scan-format-file t)
587 (list "-format" (if (mh-variant-p 'nmh 'mu-mh)
588 (list (mh-update-scan-format
589 mh-scan-format-nmh mh-cmd-note))
590 (list (mh-update-scan-format
591 mh-scan-format-mh mh-cmd-note))))
592 (if (not (equal mh-scan-format-file nil))
593 (list "-form" mh-scan-format-file))))
600 (defun mh-rmail (&optional arg)
601 "Incorporate new mail with MH.
602 Scan an MH folder if ARG is non-nil.
604 This function is an entry point to MH-E, the Emacs interface to
609 (call-interactively 'mh-visit-folder)
610 (unless (get-buffer mh-inbox)
611 (mh-visit-folder mh-inbox (symbol-name mh-unseen-seq)))
615 (defun mh-nmail (&optional arg)
616 "Check for new mail in inbox folder.
617 Scan an MH folder if ARG is non-nil.
619 This function is an entry point to MH-E, the Emacs interface to
622 (mh-find-path) ; init mh-inbox
624 (call-interactively 'mh-visit-folder)
625 (mh-visit-folder mh-inbox)))
629 ;;; User executable MH-E commands:
631 (defun mh-delete-msg (range)
632 "Delete RANGE\\<mh-folder-mode-map>.
634 To mark a message for deletion, use this command. A \"D\" is
635 placed by the message in the scan window, and the next undeleted
636 message is displayed. If the previous command had been
637 \\[mh-previous-undeleted-msg], then the next message displayed is
638 the first undeleted message previous to the message just deleted.
639 Use \\[mh-next-undeleted-msg] to force subsequent
640 \\[mh-delete-msg] commands to move forward to the next undeleted
641 message after deleting the message under the cursor.
643 The hook `mh-delete-msg-hook' is called after you mark a message
644 for deletion. For example, a past maintainer of MH-E used this
645 once when he kept statistics on his mail usage.
647 Check the documentation of `mh-interactive-range' to see how
648 RANGE is read in interactive use."
649 (interactive (list (mh-interactive-range "Delete")))
650 (mh-delete-msg-no-motion range)
651 (if (looking-at mh-scan-deleted-msg-regexp)
654 (defun mh-delete-msg-no-motion (range)
655 "Delete RANGE, don't move to next message.
657 This command marks the RANGE for deletion but leaves the cursor
658 at the current message in case you wish to perform other
659 operations on the message.
661 Check the documentation of `mh-interactive-range' to see how
662 RANGE is read in interactive use."
663 (interactive (list (mh-interactive-range "Delete")))
664 (mh-iterate-on-range () range
665 (mh-delete-a-msg nil)))
667 (defun mh-execute-commands ()
668 "Process outstanding delete and refile requests\\<mh-folder-mode-map>.
670 If you've marked messages to be deleted or refiled and you want
671 to go ahead and delete or refile the messages, use this command.
672 Many MH-E commands that may affect the numbering of the
673 messages (such as \\[mh-rescan-folder] or \\[mh-pack-folder])
674 will ask if you want to process refiles or deletes first and then
675 either run this command for you or undo the pending refiles and
676 deletes, which are lost.
678 This function runs `mh-before-commands-processed-hook' before the
679 commands are processed and `mh-after-commands-processed-hook'
680 after the commands are processed."
682 (if mh-folder-view-stack (mh-widen t))
683 (mh-process-commands mh-current-folder)
685 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
686 (mh-make-folder-mode-line)
687 t) ; return t for write-file-functions
689 (defun mh-first-msg ()
690 "Display first message."
692 (goto-char (point-min))
693 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp)))
696 (defun mh-header-display ()
697 "Display message with all header fields\\<mh-folder-mode-map>.
699 Use the command \\[mh-show] to show the message normally again."
701 (and (not mh-showing-with-headers)
702 (or mh-mhl-format-file mh-clean-message-header-flag)
703 (mh-invalidate-show-buffer))
704 (let ((mh-decode-mime-flag nil)
705 (mh-mhl-format-file nil)
706 (mh-clean-message-header-flag nil))
708 (mh-in-show-buffer (mh-show-buffer)
709 (goto-char (point-min))
711 (setq mh-showing-with-headers t)))
713 (defun mh-inc-folder (&optional file folder)
714 "Incorporate new mail into a folder.
716 You can incorporate mail from any file into the current folder by
717 specifying a prefix argument; you'll be prompted for the name of
718 the FILE to use as well as the destination FOLDER
720 The hook `mh-inc-folder-hook' is run after incorporating new
723 Do not call this function from outside MH-E; use \\[mh-rmail]
725 (interactive (list (if current-prefix-arg
727 (read-file-name "inc mail from file: "
729 (if current-prefix-arg
730 (mh-prompt-for-folder "inc mail into" mh-inbox t))))
732 (setq folder mh-inbox))
733 (let ((threading-needed-flag nil))
734 (let ((config (current-window-configuration)))
735 (when (and mh-show-buffer (get-buffer mh-show-buffer))
736 (delete-windows-on mh-show-buffer))
737 (cond ((not (get-buffer folder))
738 (mh-make-folder folder)
739 (setq threading-needed-flag mh-show-threads-flag)
740 (setq mh-previous-window-config config))
741 ((not (eq (current-buffer) (get-buffer folder)))
742 (switch-to-buffer folder)
743 (setq mh-previous-window-config config))))
744 (mh-get-new-mail file)
745 (when (and threading-needed-flag
747 (goto-char (point-min))
748 (or (null mh-large-folder)
749 (not (equal (forward-line (1+ mh-large-folder)) 0))
750 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
754 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show))
755 (run-hooks 'mh-inc-folder-hook)))
757 (defun mh-last-msg ()
758 "Display last message."
760 (goto-char (point-max))
761 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp)))
765 (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag)
766 "Display next message.
768 This command can be given a prefix argument COUNT to specify how
769 many unread messages to skip.
771 In a program, pause for a second after printing message if we are
772 at the last undeleted message and optional argument
773 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
775 (setq mh-next-direction 'forward)
777 (cond ((re-search-forward mh-scan-good-msg-regexp nil t count)
781 (message "No more undeleted messages")
782 (if wait-after-complaining-flag (sit-for 1)))))
784 (defun mh-folder-from-address ()
785 "Derive folder name from sender.
787 The name of the folder is derived as follows:
789 a) The folder name associated with the first address found in
790 the list `mh-default-folder-list' is used. Each element in
791 this list contains a \"Check Recipient\" item. If this item is
792 turned on, then the address is checked against the recipient
793 instead of the sender. This is useful for mailing lists.
795 b) An alias prefixed by `mh-default-folder-prefix'
796 corresponding to the address is used. The prefix is used to
797 prevent clutter in your mail directory.
799 Return nil if a folder name was not derived, or if the variable
800 `mh-default-folder-must-exist-flag' is t and the folder does not
802 ;; Loop for all entries in mh-default-folder-list
804 (goto-char (point-min))
805 (re-search-forward "\n\n" nil 'limit)
806 (narrow-to-region (point-min) (point))
807 (let ((to/cc (concat (or (message-fetch-field "to") "") ", "
808 (or (message-fetch-field "cc") "")))
809 (from (or (message-fetch-field "from") ""))
812 (loop for list in mh-default-folder-list
813 when (string-match (nth 0 list) (if (nth 2 list) to/cc from))
817 ;; Make sure a result from `mh-default-folder-list' begins with "+"
818 ;; since 'mh-expand-file-name below depends on it
819 (when (and folder-name (not (eq (aref folder-name 0) ?+)))
820 (setq folder-name (concat "+" folder-name)))
822 ;; If not, is there an alias for the address?
823 (when (not folder-name)
824 (let* ((from-header (mh-extract-from-header-value))
825 (address (and from-header
826 (nth 1 (mail-extract-address-components
828 (alias (and address (mh-alias-address-to-alias address))))
831 (and alias (concat "+" mh-default-folder-prefix alias))))))
833 ;; If mh-default-folder-must-exist-flag set, check that folder exists.
835 (or (not mh-default-folder-must-exist-flag)
836 (file-exists-p (mh-expand-file-name folder-name))))
839 (defun mh-prompt-for-refile-folder ()
840 "Prompt the user for a folder in which the message should be filed.
841 The folder is returned as a string.
843 The default folder name is generated by the option
844 `mh-default-folder-for-message-function' if it is non-nil or
845 `mh-folder-from-address'."
846 (mh-prompt-for-folder
848 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t)))))
849 (if (null refile-file) ""
851 (set-buffer (get-buffer-create mh-temp-buffer))
853 (insert-file-contents refile-file)
854 (or (and mh-default-folder-for-message-function
855 (let ((buffer-file-name refile-file))
856 (funcall mh-default-folder-for-message-function)))
857 (mh-folder-from-address)
858 (and (eq 'refile (car mh-last-destination-folder))
859 (symbol-name (cdr mh-last-destination-folder)))
863 (defun mh-refile-msg (range folder &optional dont-update-last-destination-flag)
864 "Refile (output) RANGE into FOLDER.
866 You are prompted for the folder name. Note that this command can also
867 be used to create folders. If you specify a folder that does not
868 exist, you will be prompted to create it.
870 The hook `mh-refile-msg-hook' is called after a message is marked to
873 Check the documentation of `mh-interactive-range' to see how RANGE is
874 read in interactive use.
876 In a program, the variables `mh-last-destination' and
877 `mh-last-destination-folder' are not updated if
878 DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil."
879 (interactive (list (mh-interactive-range "Refile")
880 (intern (mh-prompt-for-refile-folder))))
881 (unless dont-update-last-destination-flag
882 (setq mh-last-destination (cons 'refile folder)
883 mh-last-destination-folder mh-last-destination))
884 (mh-iterate-on-range () range
885 (mh-refile-a-msg nil folder))
886 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg)))
888 (defun mh-refile-or-write-again (range &optional interactive-flag)
889 "Repeat last output command.
891 If you are refiling several messages into the same folder, you
892 can use this command to repeat the last
893 refile (\\[mh-refile-msg]) or write (\\[mh-write-msg-to-file]).
896 Check the documentation of `mh-interactive-range' to see how RANGE is
897 read in interactive use.
899 In a program, a non-nil INTERACTIVE-FLAG means that the function was
900 called interactively."
901 (interactive (list (mh-interactive-range "Redo") t))
902 (if (null mh-last-destination)
903 (error "No previous refile or write"))
904 (cond ((eq (car mh-last-destination) 'refile)
905 (mh-refile-msg range (cdr mh-last-destination))
906 (message "Destination folder: %s" (cdr mh-last-destination)))
908 (mh-iterate-on-range msg range
909 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination)))
910 (mh-next-msg interactive-flag))))
913 "Quit the current MH-E folder.
915 When you want to quit using MH-E and go back to editing, you can use
916 this command. This buries the buffers of the current MH-E folder and
917 restores the buffers that were present when you first ran
918 \\[mh-rmail]. It also removes any MH-E working buffers whose name
919 begins with \" *mh-\" or \"*MH-E \". You can later restore your MH-E
920 session by selecting the \"+inbox\" buffer or by running \\[mh-rmail]
923 The two hooks `mh-before-quit-hook' and `mh-quit-hook' are called by
924 this function. The former one is called before the quit occurs, so you
925 might use it to perform any MH-E operations; you could perform some
926 query and abort the quit or call `mh-execute-commands', for example.
927 The latter is not run in an MH-E context, so you might use it to
928 modify the window setup."
930 (run-hooks 'mh-before-quit-hook)
931 (let ((show-buffer (get-buffer mh-show-buffer)))
933 (kill-buffer show-buffer)))
934 (mh-update-sequences)
935 (mh-destroy-postponed-handles)
936 (bury-buffer (current-buffer))
938 ;; Delete all MH-E temporary and working buffers.
939 (dolist (buffer (buffer-list))
940 (when (or (string-match "^ \\*mh-" (buffer-name buffer))
941 (string-match "^\\*MH-E " (buffer-name buffer)))
942 (kill-buffer buffer)))
944 (if mh-previous-window-config
945 (set-window-configuration mh-previous-window-config))
946 (run-hooks 'mh-quit-hook))
948 (defun mh-page-msg (&optional lines)
949 "Display next page in message.
951 You can give this command a prefix argument that specifies the
952 number of LINES to scroll. This command will also show the next
953 undeleted message if it is used at the bottom of a message."
956 (if mh-page-to-next-msg-flag
957 (if (equal mh-next-direction 'backward)
958 (mh-previous-undeleted-msg)
959 (mh-next-undeleted-msg))
960 (if (mh-in-show-buffer (mh-show-buffer)
961 (pos-visible-in-window-p (point-max)))
964 "End of message (Type %s to read %s undeleted message)"
965 (single-key-description last-input-event)
966 (if (equal mh-next-direction 'backward)
969 (setq mh-page-to-next-msg-flag t))
970 (scroll-other-window lines)))
973 (defun mh-previous-page (&optional lines)
974 "Display next page in message.
976 You can give this command a prefix argument that specifies the
977 number of LINES to scroll."
979 (mh-in-show-buffer (mh-show-buffer)
980 (scroll-down lines)))
982 (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag)
983 "Display previous message.
985 This command can be given a prefix argument COUNT to specify how
986 many unread messages to skip.
988 In a program, pause for a second after printing message if we are
989 at the last undeleted message and optional argument
990 WAIT-AFTER-COMPLAINING-FLAG is non-nil."
992 (setq mh-next-direction 'backward)
994 (cond ((re-search-backward mh-scan-good-msg-regexp nil t count)
996 (t (message "No previous undeleted message")
997 (if wait-after-complaining-flag (sit-for 1)))))
999 (defun mh-previous-unread-msg (&optional count)
1000 "Display previous unread message.
1002 This command can be given a prefix argument COUNT to specify how
1003 many unread messages to skip."
1006 (error "The function `mh-previous-unread-msg' expects positive argument"))
1007 (setq count (1- count))
1008 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list)))
1009 (cur-msg (mh-get-msg-num nil)))
1010 (cond ((and (not cur-msg) (not (bobp))
1011 ;; If we are at the end of the buffer back up one line and go
1012 ;; to unread message after that.
1015 (setq cur-msg (mh-get-msg-num nil)))
1017 ((or (null unread-sequence) (not cur-msg))
1018 ;; No unread message or there aren't any messages in buffer...
1019 (message "No more unread messages"))
1021 ;; Skip count messages...
1022 (while (and unread-sequence (>= (car unread-sequence) cur-msg))
1023 (setq unread-sequence (cdr unread-sequence)))
1025 (setq unread-sequence (cdr unread-sequence))
1026 (setq count (1- count)))
1027 (not (car unread-sequence)))
1028 (message "No more unread messages"))
1029 (t (loop for msg in unread-sequence
1030 when (mh-goto-msg msg t) return nil
1031 finally (message "No more unread messages"))))))
1033 (defun mh-goto-next-button (backward-flag &optional criterion)
1034 "Search for next button satisfying criterion.
1036 If BACKWARD-FLAG is non-nil search backward in the buffer for a mime
1038 If CRITERION is a function or a symbol which has a function binding
1039 then that function must return non-nil at the button we stop."
1040 (unless (or (and (symbolp criterion) (fboundp criterion))
1041 (functionp criterion))
1042 (setq criterion (lambda (x) t)))
1043 ;; Move to the next button in the buffer satisfying criterion
1044 (goto-char (or (save-excursion
1046 ;; Find point before current button
1047 (let ((point-before-current-button
1049 (while (get-text-property (point) 'mh-data)
1050 (unless (= (forward-line
1051 (if backward-flag 1 -1))
1054 (goto-char (point-min))
1055 (goto-char (point-max)))))
1057 ;; Skip over current button
1058 (while (and (get-text-property (point) 'mh-data)
1059 (not (if backward-flag (bobp) (eobp))))
1060 (forward-line (if backward-flag -1 1)))
1061 ;; Stop at next MIME button if any exists.
1064 (unless (= (forward-line
1065 (if backward-flag -1 1))
1068 (goto-char (point-max))
1069 (goto-char (point-min)))
1070 (beginning-of-line))
1072 point-before-current-button)
1073 (when (and (get-text-property (point) 'mh-data)
1074 (funcall criterion (point)))
1075 (return-from loop (point))))
1079 (defun mh-next-button (&optional backward-flag)
1080 "Go to the next button.
1082 If the end of the buffer is reached then the search wraps over to
1083 the start of the buffer.
1085 If an optional prefix argument BACKWARD-FLAG is given, the cursor
1086 will move to the previous button."
1087 (interactive (list current-prefix-arg))
1088 (unless mh-showing-mode
1090 (mh-in-show-buffer (mh-show-buffer)
1091 (mh-goto-next-button backward-flag)))
1093 (defun mh-prev-button ()
1094 "Go to the previous button.
1096 If the beginning of the buffer is reached then the search wraps
1097 over to the end of the buffer."
1101 (defun mh-folder-mime-action (part-index action include-security-flag)
1102 "Go to PART-INDEX and carry out ACTION.
1104 If PART-INDEX is nil then go to the next part in the buffer. The
1105 search for the next buffer wraps around if end of buffer is reached.
1106 If argument INCLUDE-SECURITY-FLAG is non-nil then include security
1107 info buttons when searching for a suitable parts."
1108 (unless mh-showing-mode
1110 (mh-in-show-buffer (mh-show-buffer)
1114 (let ((part (get-text-property p 'mh-part)))
1115 (and (integerp part) (= part part-index)))))
1117 (if include-security-flag
1118 (get-text-property p 'mh-data)
1119 (integerp (get-text-property p 'mh-part)))))))
1121 (cond ((and (get-text-property point 'mh-part)
1122 (or (null part-index)
1123 (= (get-text-property point 'mh-part) part-index)))
1125 ((and (get-text-property point 'mh-data)
1126 include-security-flag
1130 (mh-goto-next-button nil criterion)
1131 (if (= (point) point)
1132 (message "No matching MIME part found")
1133 (funcall action)))))))
1135 (defun mh-folder-toggle-mime-part (part-index)
1138 This command displays (or hides) the attachment associated with
1139 the button under the cursor. If the cursor is not located over a
1140 button, then the cursor first moves to the next button, wrapping
1141 to the beginning of the message if necessary. This command has
1142 the advantage over related commands of working from the MH-Folder
1145 You can also provide a numeric prefix argument PART-INDEX to view
1146 the attachment labeled with that number. If Emacs does not know
1147 how to display the attachment, then Emacs offers to save the
1148 attachment in a file."
1150 (when (consp part-index) (setq part-index (car part-index)))
1151 (mh-folder-mime-action part-index #'mh-press-button t))
1153 (defun mh-folder-inline-mime-part (part-index)
1154 "Show attachment verbatim.
1156 You can view the raw contents of an attachment with this command.
1157 This command displays (or hides) the contents of the attachment
1158 associated with the button under the cursor verbatim. If the
1159 cursor is not located over a button, then the cursor first moves
1160 to the next button, wrapping to the beginning of the message if
1163 You can also provide a numeric prefix argument PART-INDEX to view
1164 the attachment labeled with that number."
1166 (when (consp part-index) (setq part-index (car part-index)))
1167 (mh-folder-mime-action part-index #'mh-mime-inline-part nil))
1169 (defun mh-folder-save-mime-part (part-index)
1170 "Save (output) attachment.
1172 This command saves the attachment associated with the button under the
1173 cursor. If the cursor is not located over a button, then the cursor
1174 first moves to the next button, wrapping to the beginning of the
1175 message if necessary.
1177 You can also provide a numeric prefix argument PART-INDEX to save the
1178 attachment labeled with that number.
1180 This command prompts you for a filename and suggests a specific name
1181 if it is available."
1183 (when (consp part-index) (setq part-index (car part-index)))
1184 (mh-folder-mime-action part-index #'mh-mime-save-part nil))
1186 (defun mh-reset-threads-and-narrowing ()
1187 "Reset all variables pertaining to threads and narrowing.
1188 Also removes all content from the folder buffer."
1189 (setq mh-view-ops ())
1190 (setq mh-folder-view-stack ())
1191 (setq mh-thread-scan-line-map-stack ())
1192 (let ((buffer-read-only nil)) (erase-buffer)))
1194 (defun mh-rescan-folder (&optional range dont-exec-pending)
1195 "Rescan folder\\<mh-folder-mode-map>.
1197 This command is useful to grab all messages in your \"+inbox\" after
1198 processing your new mail for the first time. If you don't want to
1199 rescan the entire folder, this command will accept a RANGE. Check the
1200 documentation of `mh-interactive-range' to see how RANGE is read in
1203 This command will ask if you want to process refiles or deletes first
1204 and then either run \\[mh-execute-commands] for you or undo the
1205 pending refiles and deletes, which are lost.
1207 In a program, the processing of outstanding commands is not performed
1208 if DONT-EXEC-PENDING is non-nil."
1209 (interactive (list (if current-prefix-arg
1210 (mh-read-range "Rescan" mh-current-folder t nil t
1211 mh-interpret-number-as-range-flag)
1213 (setq mh-next-direction 'forward)
1214 (let ((threaded-flag (memq 'unthread mh-view-ops))
1215 (msg-num (mh-get-msg-num nil)))
1216 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending)
1217 ;; If there isn't a cur sequence, mh-scan-folder goes to the first message.
1218 ;; Try to stay where we were.
1219 (if (null (car (mh-seq-to-msgs 'cur)))
1220 (mh-goto-msg msg-num t t))
1221 (cond (threaded-flag (mh-toggle-threads))
1222 (mh-index-data (mh-index-insert-folder-headers)))))
1224 (defun mh-write-msg-to-file (message file no-header)
1225 "Append MESSAGE to end of FILE\\<mh-folder-mode-map>.
1227 You are prompted for the filename. If the file already exists,
1228 the message is appended to it. You can also write the message to
1229 the file without the header by specifying a prefix argument
1230 NO-HEADER. Subsequent writes to the same file can be made with
1231 the command \\[mh-refile-or-write-again]."
1233 (list (mh-get-msg-num t)
1234 (let ((default-dir (if (eq 'write (car mh-last-destination-write))
1235 (file-name-directory
1236 (car (cdr mh-last-destination-write)))
1237 default-directory)))
1238 (read-file-name (format "Save message%s in file: "
1239 (if current-prefix-arg " body" ""))
1241 (if (eq 'write (car mh-last-destination-write))
1242 (car (cdr mh-last-destination-write))
1243 (expand-file-name "mail.out" default-dir))))
1244 current-prefix-arg))
1245 (let ((msg-file-to-output (mh-msg-filename message))
1246 (output-file (mh-expand-file-name file)))
1247 (setq mh-last-destination (list 'write file (if no-header 'no-header))
1248 mh-last-destination-write mh-last-destination)
1250 (set-buffer (get-buffer-create mh-temp-buffer))
1252 (insert-file-contents msg-file-to-output)
1253 (goto-char (point-min))
1254 (if no-header (search-forward "\n\n"))
1255 (append-to-file (point) (point-max) output-file))))
1257 (defun mh-toggle-showing ()
1258 "Toggle between MH-Folder and MH-Folder Show modes.
1260 This command switches between MH-Folder mode and MH-Folder Show
1261 mode. MH-Folder mode turns off the associated show buffer so that
1262 you can perform operations on the messages quickly without
1263 reading them. This is an excellent way to prune out your junk
1264 mail or to refile a group of messages to another folder for later
1271 (defun mh-undo (range)
1272 "Undo pending deletes or refiles in RANGE.
1274 If you've deleted a message or refiled it, but changed your mind,
1275 you can cancel the action before you've executed it. Use this
1276 command to undo a refile on or deletion of a single message. You
1277 can also undo refiles and deletes for messages that are found in
1280 Check the documentation of `mh-interactive-range' to see how
1281 RANGE is read in interactive use."
1282 (interactive (list (mh-interactive-range "Undo")))
1283 (cond ((numberp range)
1284 (let ((original-position (point)))
1286 (while (not (or (looking-at mh-scan-deleted-msg-regexp)
1287 (looking-at mh-scan-refiled-msg-regexp)
1288 (and (eq mh-next-direction 'forward) (bobp))
1289 (and (eq mh-next-direction 'backward)
1290 (save-excursion (forward-line) (eobp)))))
1291 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
1292 (if (or (looking-at mh-scan-deleted-msg-regexp)
1293 (looking-at mh-scan-refiled-msg-regexp))
1295 (mh-undo-msg (mh-get-msg-num t))
1297 (goto-char original-position)
1298 (error "Nothing to undo"))))
1299 (t (mh-iterate-on-range () range
1300 (mh-undo-msg nil))))
1301 (if (not (mh-outstanding-commands-p))
1302 (mh-set-folder-modified-p nil)))
1304 (defun mh-folder-line-matches-show-buffer-p ()
1305 "Return t if the message under point in folder-mode is in the show buffer.
1306 Return nil in any other circumstance (no message under point, no
1307 show buffer, the message in the show buffer doesn't match."
1308 (and (eq major-mode 'mh-folder-mode)
1309 (mh-get-msg-num nil)
1311 (get-buffer mh-show-buffer)
1312 (buffer-file-name (get-buffer mh-show-buffer))
1313 (string-match ".*/\\([0-9]+\\)$"
1314 (buffer-file-name (get-buffer mh-show-buffer)))
1316 (match-string 1 (buffer-file-name (get-buffer mh-show-buffer)))
1317 (int-to-string (mh-get-msg-num nil)))))
1319 (eval-when-compile (require 'gnus))
1321 (defmacro mh-macro-expansion-time-gnus-version ()
1322 "Return Gnus version available at macro expansion time.
1323 The macro evaluates the Gnus version at macro expansion time. If
1324 MH-E was compiled then macro expansion happens at compile time."
1327 (defun mh-run-time-gnus-version ()
1328 "Return Gnus version available at run time."
1333 (defun mh-version ()
1334 "Display version information about MH-E and the MH mail handling system."
1336 (set-buffer (get-buffer-create mh-info-buffer))
1339 (insert "MH-E " mh-version "\n\n")
1340 ;; MH-E compilation details.
1341 (insert "MH-E compilation details:\n")
1342 (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version)))
1343 (gnus-compiled-version (if compiled-mhe
1344 (mh-macro-expansion-time-gnus-version)
1346 (insert " Byte compiled:\t\t" (if compiled-mhe "yes" "no") "\n"
1347 " Gnus (compile-time):\t" gnus-compiled-version "\n"
1348 " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
1350 (insert (emacs-version) "\n\n")
1352 (if mh-variant-in-use
1353 (insert mh-variant-in-use "\n"
1354 " mh-progs:\t" mh-progs "\n"
1355 " mh-lib:\t" mh-lib "\n"
1356 " mh-lib-progs:\t" mh-lib-progs "\n\n")
1357 (insert "No MH variant detected\n"))
1360 (call-process "uname" nil t nil "-a")
1362 (goto-char (point-min))
1363 (display-buffer mh-info-buffer))
1365 (defun mh-parse-flist-output-line (line &optional current-folder)
1366 "Parse LINE to generate folder name, unseen messages and total messages.
1367 If CURRENT-FOLDER is non-nil then it contains the current folder
1368 name and it is used to avoid problems in corner cases involving
1369 folders whose names end with a '+' character."
1372 (goto-char (point-max))
1373 (let (folder unseen total p)
1374 (when (search-backward " out of " (point-min) t)
1375 (setq total (read-from-string
1376 (buffer-substring-no-properties
1377 (match-end 0) (line-end-position))))
1378 (when (search-backward " in sequence " (point-min) t)
1380 (when (search-backward " has " (point-min) t)
1381 (setq unseen (read-from-string (buffer-substring-no-properties
1383 (while (eq (char-after) ? )
1385 (setq folder (buffer-substring-no-properties
1386 (point-min) (1+ (point))))
1387 (when (and (equal (aref folder (1- (length folder))) ?+)
1388 (equal current-folder folder))
1389 (setq folder (substring folder 0 (1- (length folder)))))
1390 (values (format "+%s" folder) (car unseen) (car total))))))))
1392 (defun mh-folder-size-folder (folder)
1393 "Find size of FOLDER using \"folder\"."
1395 (let ((u (length (cdr (assoc mh-unseen-seq
1396 (mh-read-folder-sequences folder nil))))))
1397 (call-process (expand-file-name "folder" mh-progs) nil t nil
1398 "-norecurse" folder)
1399 (goto-char (point-min))
1400 (if (re-search-forward " has \\([0-9]+\\) " nil t)
1401 (values (car (read-from-string (match-string 1))) u folder)
1402 (values 0 u folder)))))
1404 (defun mh-folder-size-flist (folder)
1405 "Find size of FOLDER using \"flist\"."
1407 (call-process (expand-file-name "flist" mh-progs) nil t nil "-showzero"
1408 "-norecurse" folder "-sequence" (symbol-name mh-unseen-seq))
1409 (goto-char (point-min))
1410 (multiple-value-bind (folder unseen total)
1411 (mh-parse-flist-output-line
1412 (buffer-substring (point) (line-end-position)))
1413 (values total unseen folder))))
1415 (defun mh-folder-size (folder)
1416 "Find size of FOLDER."
1417 (if mh-flists-present-flag
1418 (mh-folder-size-flist folder)
1419 (mh-folder-size-folder folder)))
1421 (defun mh-visit-folder (folder &optional range index-data)
1424 When you want to read the messages that you have refiled into folders,
1425 use this command to visit the folder. You are prompted for the folder
1428 The folder buffer will show just unseen messages if there are any;
1429 otherwise, it will show all the messages in the buffer as long there
1430 are fewer than `mh-large-folder' messages. If there are more, then you
1431 are prompted for a range of messages to scan.
1433 You can provide a prefix argument in order to specify a RANGE of
1434 messages to show when you visit the folder. In this case, regions are
1435 not used to specify the range and `mh-large-folder' is ignored. Check
1436 the documentation of `mh-interactive-range' to see how RANGE is read
1439 Note that this command can also be used to create folders. If you
1440 specify a folder that does not exist, you will be prompted to create
1443 Do not call this function from outside MH-E; use \\[mh-rmail] instead.
1445 If, in a program, RANGE is nil (the default), then all messages in
1446 FOLDER are displayed. If an index buffer is being created then
1447 INDEX-DATA is used to initialize the index buffer specific data
1449 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t)))
1451 (mh-read-range "Scan" folder-name t nil
1453 mh-interpret-number-as-range-flag))))
1454 (let ((config (current-window-configuration))
1455 (current-buffer (current-buffer))
1456 (threaded-view-flag mh-show-threads-flag))
1457 (delete-other-windows)
1459 (when (get-buffer folder)
1461 (setq threaded-view-flag (memq 'unthread mh-view-ops))))
1463 (mh-make-folder folder)
1464 (setq mh-index-data (car index-data)
1465 mh-index-msg-checksum-map (make-hash-table :test #'equal)
1466 mh-index-checksum-origin-map (make-hash-table :test #'equal))
1467 (mh-index-update-maps folder (cadr index-data))
1468 (mh-index-create-sequences))
1469 (mh-scan-folder folder (or range "all"))
1470 (cond ((and threaded-view-flag
1472 (goto-char (point-min))
1473 (or (null mh-large-folder)
1474 (not (equal (forward-line (1+ mh-large-folder)) 0))
1475 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
1477 (mh-toggle-threads))
1479 (mh-index-insert-folder-headers)))
1480 (unless (eq current-buffer (current-buffer))
1481 (setq mh-previous-window-config config)))
1484 (defun mh-update-sequences ()
1485 "Flush MH-E's state out to MH.
1487 This function updates the sequence specified by your
1488 \"Unseen-Sequence:\" profile component, \"cur\", and the sequence
1489 listed by the `mh-tick-seq' option which is \"tick\" by default.
1490 The message at the cursor is used for \"cur\"."
1492 ;; mh-update-sequences is the opposite of mh-read-folder-sequences,
1493 ;; which updates MH-E's state from MH.
1494 (let ((folder-set (mh-update-unseen))
1495 (new-cur (mh-get-msg-num nil)))
1497 (let ((seq-entry (mh-find-seq 'cur)))
1498 (mh-remove-cur-notation)
1500 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq
1501 (mh-define-sequence 'cur (list new-cur))
1503 (if (looking-at mh-scan-good-msg-regexp)
1507 ;; psg - mh-current-folder is nil if mh-summary-height < 4 !
1508 ;; So I added this sanity check.
1509 (if (stringp mh-current-folder)
1510 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast")
1511 (mh-exec-cmd-quiet t "folder" "-fast")))))))
1515 ;;; Support routines.
1517 (defun mh-delete-a-msg (message)
1519 If MESSAGE is nil then the message at point is deleted.
1520 The hook `mh-delete-msg-hook' is called after you mark a message
1521 for deletion. For example, a past maintainer of MH-E used this
1522 once when he kept statistics on his mail usage."
1524 (if (numberp message)
1525 (mh-goto-msg message nil t)
1527 (setq message (mh-get-msg-num t)))
1528 (if (looking-at mh-scan-refiled-msg-regexp)
1529 (error "Message %d is refiled; undo refile before deleting" message))
1530 (if (looking-at mh-scan-deleted-msg-regexp)
1532 (mh-set-folder-modified-p t)
1533 (setq mh-delete-list (cons message mh-delete-list))
1534 (mh-notate nil mh-note-deleted mh-cmd-note)
1535 (run-hooks 'mh-delete-msg-hook))))
1537 (defun mh-refile-a-msg (message folder)
1538 "Refile MESSAGE in FOLDER.
1539 If MESSAGE is nil then the message at point is refiled.
1540 Folder is a symbol, not a string.
1541 The hook `mh-refile-msg-hook' is called after a message is marked to
1544 (if (numberp message)
1545 (mh-goto-msg message nil t)
1547 (setq message (mh-get-msg-num t)))
1548 (cond ((looking-at mh-scan-deleted-msg-regexp)
1549 (error "Message %d is deleted; undo delete before moving" message))
1550 ((looking-at mh-scan-refiled-msg-regexp)
1552 (format "Message %d already refiled; copy to %s as well? "
1554 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
1555 "-src" mh-current-folder
1556 (symbol-name folder))
1557 (message "Message not copied")))
1559 (mh-set-folder-modified-p t)
1560 (cond ((null (assoc folder mh-refile-list))
1561 (push (list folder message) mh-refile-list))
1562 ((not (member message (cdr (assoc folder mh-refile-list))))
1563 (push message (cdr (assoc folder mh-refile-list)))))
1564 (mh-notate nil mh-note-refiled mh-cmd-note)
1565 (run-hooks 'mh-refile-msg-hook)))))
1567 (defun mh-next-msg (&optional wait-after-complaining-flag)
1568 "Move backward or forward to the next undeleted message in the buffer.
1569 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and
1570 we are at the last message, then wait for a second after telling
1571 the user that there aren't any more unread messages."
1572 (if (eq mh-next-direction 'forward)
1573 (mh-next-undeleted-msg 1 wait-after-complaining-flag)
1574 (mh-previous-undeleted-msg 1 wait-after-complaining-flag)))
1576 (defun mh-next-unread-msg (&optional count)
1577 "Display next unread message.
1579 This command can be given a prefix argument COUNT to specify how
1580 many unread messages to skip."
1583 (error "The function `mh-next-unread-msg' expects positive argument"))
1584 (setq count (1- count))
1585 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list))))
1586 (cur-msg (mh-get-msg-num nil)))
1587 (cond ((and (not cur-msg) (not (bobp))
1588 ;; If we are at the end of the buffer back up one line and go
1589 ;; to unread message after that.
1592 (setq cur-msg (mh-get-msg-num nil)))
1594 ((or (null unread-sequence) (not cur-msg))
1595 ;; No unread message or there aren't any messages in buffer...
1596 (message "No more unread messages"))
1599 (while (and unread-sequence (>= cur-msg (car unread-sequence)))
1600 (setq unread-sequence (cdr unread-sequence)))
1602 (setq unread-sequence (cdr unread-sequence))
1603 (setq count (1- count)))
1604 (not (car unread-sequence)))
1605 (message "No more unread messages"))
1606 (t (loop for msg in unread-sequence
1607 when (mh-goto-msg msg t) return nil
1608 finally (message "No more unread messages"))))))
1610 (defun mh-set-scan-mode ()
1611 "Display the scan listing buffer, but do not show a message."
1612 (if (get-buffer mh-show-buffer)
1613 (delete-windows-on mh-show-buffer))
1615 (force-mode-line-update)
1616 (if mh-recenter-summary-flag
1619 (defun mh-undo-msg (msg)
1620 "Undo the deletion or refile of one MSG.
1621 If MSG is nil then act on the message at point"
1624 (mh-goto-msg msg t t)
1626 (setq msg (mh-get-msg-num t)))
1627 (cond ((memq msg mh-delete-list)
1628 (setq mh-delete-list (delq msg mh-delete-list)))
1630 (dolist (folder-msg-list mh-refile-list)
1631 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list))))
1632 (setq mh-refile-list (loop for x in mh-refile-list
1633 unless (null (cdr x)) collect x))))
1634 (mh-notate nil ? mh-cmd-note)))
1638 ;;; The folder data abstraction.
1640 (defvar mh-index-data-file ".mhe_index"
1641 "MH-E specific file where index seach info is stored.")
1643 (defun mh-make-folder (name)
1644 "Create a new mail folder called NAME.
1645 Make it the current folder."
1646 (switch-to-buffer name)
1647 (setq buffer-read-only nil)
1649 (if mh-adaptive-cmd-note-flag
1650 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name))))
1651 (setq buffer-read-only t)
1653 (mh-set-folder-modified-p nil)
1654 (setq buffer-file-name mh-folder-filename)
1655 (when (and (not mh-index-data)
1656 (file-exists-p (concat buffer-file-name mh-index-data-file)))
1657 (mh-index-read-data))
1658 (mh-make-folder-mode-line))
1660 ;; Ensure new buffers won't get this mode if default-major-mode is nil.
1661 (put 'mh-folder-mode 'mode-class 'special)
1665 ;;; Build mh-folder-mode menu
1667 ;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
1668 ;; Menus for folder mode: folder, message, sequence (in that order)
1669 ;; folder-mode "Sequence" menu
1671 mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence."
1673 ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)]
1674 ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)]
1675 ["Delete Message from Sequence..." mh-delete-msg-from-seq
1676 (mh-get-msg-num nil)]
1677 ["List Sequences in Folder..." mh-list-sequences t]
1678 ["Delete Sequence..." mh-delete-seq t]
1679 ["Narrow to Sequence..." mh-narrow-to-seq t]
1680 ["Widen from Sequence" mh-widen mh-folder-view-stack]
1682 ["Narrow to Subject Sequence" mh-narrow-to-subject t]
1683 ["Narrow to Tick Sequence" mh-narrow-to-tick
1684 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))]
1685 ["Delete Rest of Same Subject" mh-delete-subject t]
1686 ["Toggle Tick Mark" mh-toggle-tick t]
1688 ["Push State Out to MH" mh-update-sequences t]))
1690 ;; folder-mode "Message" menu
1692 mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message."
1694 ["Show Message" mh-show (mh-get-msg-num nil)]
1695 ["Show Message with Header" mh-header-display (mh-get-msg-num nil)]
1696 ["Next Message" mh-next-undeleted-msg t]
1697 ["Previous Message" mh-previous-undeleted-msg t]
1698 ["Go to First Message" mh-first-msg t]
1699 ["Go to Last Message" mh-last-msg t]
1700 ["Go to Message by Number..." mh-goto-msg t]
1701 ["Modify Message" mh-modify t]
1702 ["Delete Message" mh-delete-msg (mh-get-msg-num nil)]
1703 ["Refile Message" mh-refile-msg (mh-get-msg-num nil)]
1704 ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)]
1705 ["Execute Delete/Refile" mh-execute-commands
1706 (mh-outstanding-commands-p)]
1708 ["Compose a New Message" mh-send t]
1709 ["Reply to Message..." mh-reply (mh-get-msg-num nil)]
1710 ["Forward Message..." mh-forward (mh-get-msg-num nil)]
1711 ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)]
1712 ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)]
1713 ["Re-edit a Bounced Message" mh-extract-rejected-mail t]
1715 ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)]
1716 ["Print Message" mh-print-msg (mh-get-msg-num nil)]
1717 ["Write Message to File..." mh-write-msg-to-file
1718 (mh-get-msg-num nil)]
1719 ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)]
1720 ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)]
1721 ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)]))
1723 ;; folder-mode "Folder" menu
1725 mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder."
1727 ["Incorporate New Mail" mh-inc-folder t]
1728 ["Toggle Show/Folder" mh-toggle-showing t]
1729 ["Execute Delete/Refile" mh-execute-commands
1730 (mh-outstanding-commands-p)]
1731 ["Rescan Folder" mh-rescan-folder t]
1732 ["Thread Folder" mh-toggle-threads
1733 (not (memq 'unthread mh-view-ops))]
1734 ["Pack Folder" mh-pack-folder t]
1735 ["Sort Folder" mh-sort-folder t]
1737 ["List Folders" mh-list-folders t]
1738 ["Visit a Folder..." mh-visit-folder t]
1739 ["View New Messages" mh-index-new-messages t]
1740 ["Search..." mh-search t]
1742 ["Quit MH-E" mh-quit t]))
1746 (defmacro mh-remove-xemacs-horizontal-scrollbar ()
1747 "Get rid of the horizontal scrollbar that XEmacs insists on putting in."
1748 (when mh-xemacs-flag
1749 `(if (and (featurep 'scrollbar)
1750 (fboundp 'set-specifier))
1751 (set-specifier horizontal-scrollbar-visible-p nil
1752 (cons (current-buffer) nil)))))
1754 (defmacro mh-write-file-functions-compat ()
1755 "Return `write-file-functions' if it exists.
1756 Otherwise return `local-write-file-hooks'. This macro exists
1757 purely for compatibility. The former symbol is used in Emacs 21.4
1758 onward while the latter is used in previous versions and XEmacs."
1759 (if (boundp 'write-file-functions)
1760 ''write-file-functions ;Emacs 21.4
1761 ''local-write-file-hooks)) ;XEmacs
1763 ;; Register mh-folder-mode as supporting which-function-mode...
1764 (load "which-func" t t)
1765 (when (and (boundp 'which-func-modes)
1766 (not (member 'mh-folder-mode which-func-modes)))
1767 (push 'mh-folder-mode which-func-modes))
1771 (defvar desktop-save-buffer)
1772 (defvar font-lock-auto-fontify))
1774 (defvar mh-folder-buttons-init-flag nil)
1776 ;; Autoload cookie needed by desktop.el
1778 (define-derived-mode mh-folder-mode fundamental-mode "MH-Folder"
1779 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
1781 You can show the message the cursor is pointing to, and step through
1782 the messages. Messages can be marked for deletion or refiling into
1783 another folder; these commands are executed all at once with a
1786 Options that control this mode can be changed with
1787 \\[customize-group]; specify the \"mh\" group. In particular, please
1788 see the `mh-scan-format-file' option if you wish to modify scan's
1791 When a folder is visited, the hook `mh-folder-mode-hook' is run.
1795 Many commands that operate on individual messages, such as
1796 `mh-forward' or `mh-refile-msg' take a RANGE argument. This argument
1797 can be used in several ways.
1799 If you provide the prefix argument (\\[universal-argument]) to
1800 these commands, then you will be prompted for the message range.
1801 This can be any valid MH range which can include messages,
1802 sequences, and the abbreviations (described in the mh(1) man
1806 Indicates all messages in the range <num1> to <num2>, inclusive.
1807 The range must be nonempty.
1812 Up to N messages beginning with (or ending with) message num. Num
1813 may be any of the predefined symbols: first, prev, cur, next or
1820 The first, previous, next or last messages, if they exist.
1823 All of the messages.
1825 For example, a range that shows all of these things is `1 2 3
1826 5-10 last:5 unseen'.
1828 If the option `transient-mark-mode' is set to t and you set a
1829 region in the MH-Folder buffer, then the MH-E command will
1830 perform the operation on all messages in that region.
1832 \\{mh-folder-mode-map}"
1834 (unless mh-folder-buttons-init-flag
1835 (mh-tool-bar-folder-buttons-init)
1836 (setq mh-folder-buttons-init-flag t)))
1837 (make-local-variable 'font-lock-defaults)
1838 (setq font-lock-defaults '(mh-folder-font-lock-keywords t))
1839 (make-local-variable 'desktop-save-buffer)
1840 (setq desktop-save-buffer t)
1842 'mh-colors-available-flag (mh-colors-available-p)
1843 ; Do we have colors available
1844 'mh-current-folder (buffer-name) ; Name of folder, a string
1845 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
1846 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
1847 (file-name-as-directory (mh-expand-file-name (buffer-name)))
1848 'mh-display-buttons-for-inline-parts-flag
1849 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to
1851 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed
1852 'overlay-arrow-position nil ; Allow for simultaneous display in
1853 'overlay-arrow-string ">" ; different MH-E buffers.
1854 'mh-showing-mode nil ; Show message also?
1855 'mh-delete-list nil ; List of msgs nums to delete
1856 'mh-refile-list nil ; List of folder names in mh-seq-list
1857 'mh-seq-list nil ; Alist of (seq . msgs) nums
1858 'mh-seen-list nil ; List of displayed messages
1859 'mh-next-direction 'forward ; Direction to move to next message
1860 'mh-view-ops () ; Stack that keeps track of the order
1861 ; in which narrowing/threading has been
1863 'mh-folder-view-stack () ; Stack of previous views of the
1865 'mh-index-data nil ; If the folder was created by a call
1866 ; to mh-search, this contains info
1867 ; about the search results.
1868 'mh-index-previous-search nil ; folder, indexer, search-regexp
1869 'mh-index-msg-checksum-map nil ; msg -> checksum map
1870 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg )
1871 'mh-index-sequence-search-flag nil ; folder resulted from sequence search
1872 'mh-first-msg-num nil ; Number of first msg in buffer
1873 'mh-last-msg-num nil ; Number of last msg in buffer
1874 'mh-msg-count nil ; Number of msgs in buffer
1875 'mh-mode-line-annotation nil ; Indicates message range
1876 'mh-sequence-notation-history (make-hash-table)
1877 ; Remember what is overwritten by
1879 'imenu-create-index-function 'mh-index-create-imenu-index
1880 ; Setup imenu support
1881 'mh-previous-window-config nil) ; Previous window configuration
1882 (mh-remove-xemacs-horizontal-scrollbar)
1883 (setq truncate-lines t)
1885 (setq buffer-offer-save t)
1886 (mh-make-local-hook (mh-write-file-functions-compat))
1887 (add-hook (mh-write-file-functions-compat) 'mh-execute-commands nil t)
1888 (make-local-variable 'revert-buffer-function)
1889 (make-local-variable 'hl-line-mode) ; avoid pollution
1890 (mh-funcall-if-exists hl-line-mode 1)
1891 (setq revert-buffer-function 'mh-undo-folder)
1892 (or (assq 'mh-showing-mode minor-mode-alist)
1893 (setq minor-mode-alist
1894 (cons '(mh-showing-mode " Show") minor-mode-alist)))
1895 (easy-menu-add mh-folder-sequence-menu)
1896 (easy-menu-add mh-folder-message-menu)
1897 (easy-menu-add mh-folder-folder-menu)
1898 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)
1899 (mh-funcall-if-exists mh-tool-bar-init :folder)
1900 (if (and mh-xemacs-flag
1901 font-lock-auto-fontify)
1902 (turn-on-font-lock))) ; Force font-lock in XEmacs.
1904 (defun mh-toggle-mime-buttons ()
1905 "Toggle option `mh-display-buttons-for-inline-parts-flag'."
1907 (setq mh-display-buttons-for-inline-parts-flag
1908 (not mh-display-buttons-for-inline-parts-flag))
1911 (defun mh-colors-available-p ()
1912 "Check if colors are available in the Emacs being used."
1914 (let ((color-cells (display-color-cells)))
1915 (and (numberp color-cells) (>= color-cells 8)))))
1917 (defun mh-colors-in-use-p ()
1918 "Check if colors are being used in the folder buffer."
1919 (and mh-colors-available-flag font-lock-mode))
1921 (defun mh-make-local-vars (&rest pairs)
1922 "Initialize local variables according to the variable-value PAIRS."
1925 (set (make-local-variable (car pairs)) (car (cdr pairs)))
1926 (setq pairs (cdr (cdr pairs)))))
1928 (defun mh-restore-desktop-buffer (desktop-buffer-file-name
1930 desktop-buffer-misc)
1931 "Restore an MH folder buffer specified in a desktop file.
1932 When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the
1933 file name to visit, DESKTOP-BUFFER-NAME holds the desired buffer
1934 name, and DESKTOP-BUFFER-MISC holds a list of miscellaneous info
1935 used by the `desktop-buffer-handlers' functions."
1937 (mh-visit-folder desktop-buffer-name)
1940 ;; desktop-buffer-mode-handlers appeared in Emacs 22.
1941 (if (fboundp 'desktop-buffer-mode-handlers)
1942 (add-to-list 'desktop-buffer-mode-handlers
1943 '(mh-folder-mode . mh-restore-desktop-buffer)))
1945 (defun mh-scan-folder (folder range &optional dont-exec-pending)
1946 "Scan FOLDER over RANGE.
1948 After the scan is performed, switch to the buffer associated with
1951 Check the documentation of `mh-interactive-range' to see how RANGE is
1952 read in interactive use.
1954 The processing of outstanding commands is not performed if
1955 DONT-EXEC-PENDING is non-nil."
1956 (when (stringp range)
1957 (setq range (delete "" (split-string range "[ \t\n]"))))
1958 (cond ((null (get-buffer folder))
1959 (mh-make-folder folder))
1961 (unless dont-exec-pending
1962 (mh-process-or-undo-commands folder)
1963 (mh-reset-threads-and-narrowing))
1964 (switch-to-buffer folder)))
1965 (mh-regenerate-headers range)
1966 (if (zerop (buffer-size))
1967 (if (equal range "all")
1968 (message "Folder %s is empty" folder)
1969 (message "No messages in %s, range %s" folder range))
1971 (when (mh-outstanding-commands-p)
1972 (mh-notate-deleted-and-refiled)))
1974 (defun mh-msg-num-width-to-column (width)
1975 "Return the column for notations given message number WIDTH.
1976 Note that columns in Emacs start with 0.
1978 If `mh-scan-format-file' is set to \"Use MH-E scan Format\" this
1979 means that either `mh-scan-format-mh' or `mh-scan-format-nmh' are
1980 in use. This function therefore assumes that the first column is
1981 empty (to provide room for the cursor), the following WIDTH
1982 columns contain the message number, and the column for notations
1984 (if (eq mh-scan-format-file t)
1986 (error "%s %s" "Can't call `mh-msg-num-width-to-column' when"
1987 "`mh-scan-format-file' is not set to \"Use MH-E scan Format\"")))
1989 (defun mh-set-cmd-note (column)
1990 "Set `mh-cmd-note' to COLUMN.
1991 Note that columns in Emacs start with 0."
1992 (setq mh-cmd-note column))
1994 (defun mh-regenerate-headers (range &optional update)
1995 "Scan folder over RANGE.
1996 If UPDATE, append the scan lines, otherwise replace."
1997 (let ((folder mh-current-folder)
1998 (range (if (and range (atom range)) (list range) range))
2000 (message "Scanning %s..." folder)
2001 (mh-remove-all-notation)
2002 (with-mh-folder-updating (nil)
2004 (goto-char (point-max))
2005 (delete-region (point-min) (point-max))
2006 (if mh-adaptive-cmd-note-flag
2007 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width
2009 (setq scan-start (point))
2010 (apply #'mh-exec-cmd-output
2013 "-noclear" "-noheader"
2014 "-width" (window-width)
2016 (goto-char scan-start)
2017 (cond ((looking-at "scan: no messages in")
2018 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines
2019 ((looking-at (if (mh-variant-p 'mu-mh)
2020 "scan: message set .* does not exist"
2021 "scan: bad message list "))
2022 (keep-lines mh-scan-valid-regexp))
2023 ((looking-at "scan: ")) ; Keep error messages
2025 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines
2026 (setq mh-seq-list (mh-read-folder-sequences folder nil))
2027 (mh-notate-user-sequences)
2029 (setq mh-mode-line-annotation
2030 (if (equal range '("all"))
2032 mh-partial-folder-mode-line-annotation)))
2033 (mh-make-folder-mode-line))
2034 (message "Scanning %s...done" folder)))
2036 (defun mh-generate-new-cmd-note (folder)
2037 "Fix the `mh-cmd-note' value for this FOLDER.
2039 After doing an `mh-get-new-mail' operation in this FOLDER, at least
2040 one line that looks like a truncated message number was found.
2042 Remove the text added by the last `mh-inc' command. It should be the
2043 messages cur-last. Call `mh-set-cmd-note', adjusting the notation
2044 column with the width of the largest message number in FOLDER.
2046 Reformat the message number width on each line in the buffer and trim
2047 the line length to fit in the window.
2049 Rescan the FOLDER in the range cur-last in order to display the
2050 messages that were removed earlier. They should all fit in the scan
2051 line now with no message truncation."
2053 (let ((maxcol (1- (window-width)))
2054 (old-cmd-note mh-cmd-note)
2057 ;; Nuke all of the lines just added by the last inc
2058 (delete-char (- (point-max) (point)))
2059 ;; Update the current buffer to reflect the new mh-cmd-note
2060 ;; value needed to display messages.
2061 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder)))
2062 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d"))
2063 ;; Cleanup the messages that are in the buffer right now
2064 (goto-char (point-min))
2065 (cond ((memq 'unthread mh-view-ops)
2066 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note)))
2067 (t (while (re-search-forward mh-scan-msg-number-regexp nil 0 1)
2068 ;; reformat the number to fix in mh-cmd-note columns
2069 (setq msgnum (string-to-number
2071 (match-beginning 1) (match-end 1))))
2072 (replace-match (format mh-cmd-note-fmt msgnum))
2073 ;; trim the line to fix in the window
2075 (let ((eol (point)))
2076 (move-to-column maxcol)
2077 (if (<= (point) eol)
2078 (delete-char (- eol (point))))))))
2079 ;; now re-read the lost messages
2080 (goto-char (point-max))
2082 (mh-regenerate-headers "cur-last" t)))))
2084 (defun mh-get-new-mail (maildrop-name)
2085 "Read new mail from MAILDROP-NAME into the current buffer.
2086 Return in the current buffer."
2087 (let ((point-before-inc (point))
2088 (folder mh-current-folder)
2089 (new-mail-flag nil))
2090 (with-mh-folder-updating (t)
2092 (message "inc %s -file %s..." folder maildrop-name)
2093 (message "inc %s..." folder))
2094 (setq mh-next-direction 'forward)
2095 (goto-char (point-max))
2096 (mh-remove-cur-notation)
2097 (let ((start-of-inc (point)))
2099 ;; I think MH 5 used "-ms-file" instead of "-file",
2100 ;; which would make inc'ing from maildrops fail.
2101 (mh-exec-cmd-output mh-inc-prog nil folder
2103 "-file" (expand-file-name maildrop-name)
2104 "-width" (window-width)
2106 (mh-exec-cmd-output mh-inc-prog nil
2108 "-width" (window-width)))
2110 (message "inc %s -file %s...done" folder maildrop-name)
2111 (message "inc %s...done" folder))
2112 (goto-char start-of-inc)
2113 (cond ((save-excursion
2114 (re-search-forward "^inc: no mail" nil t))
2115 (message "No new mail%s%s" (if maildrop-name " in " "")
2116 (if maildrop-name maildrop-name "")))
2117 ((and (when mh-folder-view-stack
2118 (let ((saved-text (buffer-substring-no-properties
2119 start-of-inc (point-max))))
2120 (delete-region start-of-inc (point-max))
2121 (unwind-protect (mh-widen t)
2122 (mh-remove-cur-notation)
2123 (goto-char (point-max))
2124 (setq start-of-inc (point))
2126 (goto-char start-of-inc))))
2128 ((re-search-forward "^inc:" nil t) ; Error messages
2129 (error "Error incorporating mail"))
2131 (equal mh-scan-format-file t)
2132 mh-adaptive-cmd-note-flag
2133 ;; Have we reached an edge condition?
2135 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1))
2136 (setq start-of-inc (mh-generate-new-cmd-note folder))
2139 (setq new-mail-flag t)))
2140 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines
2141 (let* ((sequences (mh-read-folder-sequences folder t))
2142 (new-cur (assoc 'cur sequences))
2143 (new-unseen (assoc mh-unseen-seq sequences)))
2144 (unless (assoc 'cur mh-seq-list)
2145 (push (list 'cur) mh-seq-list))
2146 (unless (assoc mh-unseen-seq mh-seq-list)
2147 (push (list mh-unseen-seq) mh-seq-list))
2148 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur))
2149 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen)))
2150 (when (equal (point-max) start-of-inc)
2154 (mh-make-folder-mode-line)
2155 (when (mh-speed-flists-active-p)
2156 (mh-speed-flists t mh-current-folder))
2157 (when (memq 'unthread mh-view-ops)
2158 (mh-thread-inc folder start-of-inc))
2160 (goto-char point-before-inc))
2161 (mh-notate-user-sequences (cons start-of-inc (point-max)))))))
2163 (defun mh-make-folder-mode-line (&optional ignored)
2164 "Set the fields of the mode line for a folder buffer.
2165 The optional argument is now obsolete and IGNORED. It used to be
2166 used to pass in what is now stored in the buffer-local variable
2167 `mh-mode-line-annotation'."
2169 (save-window-excursion
2171 (let ((new-first-msg-num (mh-get-msg-num nil)))
2172 (when (or (not (memq 'unthread mh-view-ops))
2173 (null mh-first-msg-num)
2174 (null new-first-msg-num)
2175 (< new-first-msg-num mh-first-msg-num))
2176 (setq mh-first-msg-num new-first-msg-num)))
2178 (let ((new-last-msg-num (mh-get-msg-num nil)))
2179 (when (or (not (memq 'unthread mh-view-ops))
2180 (null mh-last-msg-num)
2181 (null new-last-msg-num)
2182 (> new-last-msg-num mh-last-msg-num))
2183 (setq mh-last-msg-num new-last-msg-num)))
2184 (setq mh-msg-count (if mh-first-msg-num
2185 (count-lines (point-min) (point-max))
2187 (setq mode-line-buffer-identification
2188 (list (format " {%%b%s} %s msg%s"
2189 (if mh-mode-line-annotation
2190 (format "/%s" mh-mode-line-annotation)
2192 (if (zerop mh-msg-count)
2194 (format "%d" mh-msg-count))
2195 (if (zerop mh-msg-count)
2197 (cond ((> mh-msg-count 1)
2198 (format "s (%d-%d)" mh-first-msg-num
2201 (format " (%d)" mh-first-msg-num))
2203 (mh-logo-display))))
2205 (defun mh-add-sequence-notation (msg internal-seq-flag)
2206 "Add sequence notation to the MSG on the current line.
2207 If INTERNAL-SEQ-FLAG is non-nil, then refontify the scan line if
2208 font-lock is turned on."
2209 (with-mh-folder-updating (t)
2212 (if internal-seq-flag
2214 ;; Change the buffer so that if transient-mark-mode is active
2215 ;; and there is an active region it will get deactivated as in
2216 ;; the case of user sequences.
2217 (mh-notate nil nil mh-cmd-note)
2218 (when font-lock-mode
2219 (font-lock-fontify-region (point) (line-end-position))))
2220 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2221 (let ((stack (gethash msg mh-sequence-notation-history)))
2222 (setf (gethash msg mh-sequence-notation-history)
2223 (cons (char-after) stack)))
2224 (mh-notate nil mh-note-seq
2225 (+ mh-cmd-note mh-scan-field-destination-offset))))))
2227 (defun mh-remove-sequence-notation (msg internal-seq-flag &optional all)
2228 "Remove sequence notation from the MSG on the current line.
2229 If INTERNAL-SEQ-FLAG is non-nil, then `font-lock' was used to
2230 highlight the sequence. In that case, no notation needs to be removed.
2231 Otherwise the effect of inserting `mh-note-seq' needs to be reversed.
2232 If ALL is non-nil, then all sequence marks on the scan line are
2234 (with-mh-folder-updating (t)
2235 ;; This takes care of internal sequences...
2236 (mh-notate nil nil mh-cmd-note)
2237 (unless internal-seq-flag
2238 ;; ... and this takes care of user sequences.
2239 (let ((stack (gethash msg mh-sequence-notation-history)))
2240 (while (and all (cdr stack))
2241 (setq stack (cdr stack)))
2245 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset))
2247 (insert (car stack))))
2248 (setf (gethash msg mh-sequence-notation-history) (cdr stack))))))
2250 (defun mh-remove-cur-notation ()
2251 "Remove old cur notation."
2252 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2255 (mh-goto-msg cur-msg t t)
2256 (looking-at mh-scan-cur-msg-number-regexp))
2257 (mh-notate nil ? mh-cmd-note)
2258 (setq overlay-arrow-position nil)))))
2260 (defun mh-remove-all-notation ()
2261 "Remove all notations on all scan lines that MH-E introduces."
2263 (setq overlay-arrow-position nil)
2264 (goto-char (point-min))
2265 (mh-iterate-on-range msg (cons (point-min) (point-max))
2266 (mh-notate nil ? mh-cmd-note)
2267 (mh-remove-sequence-notation msg nil t))
2268 (clrhash mh-sequence-notation-history)))
2270 (defun mh-goto-cur-msg (&optional minimal-changes-flag)
2271 "Position the cursor at the current message.
2272 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the
2273 function doesn't recenter the folder buffer."
2274 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
2276 (mh-goto-msg cur-msg t t))
2277 (unless minimal-changes-flag
2280 (mh-maybe-show cur-msg)))
2282 (setq overlay-arrow-position nil)
2283 (message "No current message")))))
2285 (defun mh-process-or-undo-commands (folder)
2286 "If FOLDER has outstanding commands, then either process or discard them.
2287 Called by functions like `mh-sort-folder', so also invalidate
2290 (if (mh-outstanding-commands-p)
2291 (if (or mh-do-not-confirm-flag
2293 "Process outstanding deletes and refiles? "))
2294 (mh-process-commands folder)
2298 (mh-invalidate-show-buffer))
2300 (defun mh-process-commands (folder)
2301 "Process outstanding commands for FOLDER.
2303 This function runs `mh-before-commands-processed-hook' before the
2304 commands are processed and `mh-after-commands-processed-hook'
2305 after the commands are processed."
2306 (message "Processing deletes and refiles for %s..." folder)
2308 (with-mh-folder-updating (nil)
2309 ;; Run the before hook -- the refile and delete lists are still valid
2310 (run-hooks 'mh-before-commands-processed-hook)
2312 ;; Update the unseen sequence if it exists
2315 (let ((redraw-needed-flag mh-index-data)
2316 (folders-changed (list mh-current-folder))
2317 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag
2318 (mh-create-sequence-map mh-seq-list)))
2319 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag
2320 (make-hash-table))))
2321 ;; Remove invalid scan lines if we are in an index folder and then remove
2322 ;; the real messages
2324 (mh-index-delete-folder-headers)
2325 (setq folders-changed
2326 (append folders-changed (mh-index-execute-commands))))
2328 ;; Then refile messages
2329 (mh-mapc #'(lambda (folder-msg-list)
2330 (let* ((dest-folder (symbol-name (car folder-msg-list)))
2331 (last (car (mh-translate-range dest-folder "last")))
2332 (msgs (cdr folder-msg-list)))
2333 (push dest-folder folders-changed)
2334 (setq redraw-needed-flag t)
2335 (apply #'mh-exec-cmd
2336 "refile" "-src" folder dest-folder
2337 (mh-coalesce-msg-list msgs))
2338 (mh-delete-scan-msgs msgs)
2339 ;; Preserve sequences in destination folder...
2340 (when mh-refile-preserves-sequences-flag
2342 (loop for i from (1+ (or last 0))
2343 for msg in (sort (copy-sequence msgs) #'<)
2344 do (loop for seq-name in (gethash msg seq-map)
2345 do (push i (gethash seq-name dest-map))))
2347 #'(lambda (seq msgs)
2348 ;; Can't be run in the background, since the
2349 ;; current folder is changed by mark this could
2350 ;; lead to a race condition with the next refile.
2351 (apply #'mh-exec-cmd "mark"
2352 "-sequence" (symbol-name seq) dest-folder
2353 "-add" (mapcar #'(lambda (x) (format "%s" x))
2354 (mh-coalesce-msg-list msgs))))
2357 (setq mh-refile-list ())
2359 ;; Now delete messages
2360 (cond (mh-delete-list
2361 (setq redraw-needed-flag t)
2362 (apply 'mh-exec-cmd "rmm" folder
2363 (mh-coalesce-msg-list mh-delete-list))
2364 (mh-delete-scan-msgs mh-delete-list)
2365 (setq mh-delete-list nil)))
2367 ;; Don't need to remove sequences since delete and refile do so.
2369 (if (> (buffer-size) 0)
2370 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last"))))
2372 ;; Redraw folder buffer if needed
2373 (when (and redraw-needed-flag)
2374 (when (mh-speed-flists-active-p)
2375 (apply #'mh-speed-flists t folders-changed))
2376 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max)))
2377 (mh-index-data (mh-index-insert-folder-headers))))
2379 (and (buffer-file-name (get-buffer mh-show-buffer))
2380 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
2381 ;; If "inc" were to put a new msg in this file,
2382 ;; we would not notice, so mark it invalid now.
2383 (mh-invalidate-show-buffer))
2385 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
2386 (mh-remove-all-notation)
2387 (mh-notate-user-sequences)
2389 ;; Run the after hook -- now folders-changed is valid,
2390 ;; but not the lists of specific messages.
2391 (let ((mh-folders-changed folders-changed))
2392 (run-hooks 'mh-after-commands-processed-hook)))
2394 (message "Processing deletes and refiles for %s...done" folder)))
2396 (defun mh-update-unseen ()
2397 "Synchronize the unseen sequence with MH.
2398 Return non-nil iff the MH folder was set.
2399 The hook `mh-unseen-updated-hook' is called after the unseen sequence
2402 (let* ((unseen-seq (mh-find-seq mh-unseen-seq))
2403 (unseen-msgs (mh-seq-msgs unseen-seq)))
2406 (mh-undefine-sequence mh-unseen-seq mh-seen-list)
2407 (run-hooks 'mh-unseen-updated-hook)
2409 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs))
2410 (setq mh-seen-list (cdr mh-seen-list)))
2411 (setcdr unseen-seq unseen-msgs)
2412 t) ;since we set the folder
2413 (setq mh-seen-list nil)))))
2415 (defun mh-delete-scan-msgs (msgs)
2416 "Delete the scan listing lines for MSGS."
2419 (when (mh-goto-msg (car msgs) t t)
2420 (when (memq 'unthread mh-view-ops)
2421 (mh-thread-forget-message (car msgs)))
2423 (setq msgs (cdr msgs)))))
2425 (defun mh-outstanding-commands-p ()
2426 "Return non-nil if there are outstanding deletes or refiles."
2428 (when (eq major-mode 'mh-show-mode)
2429 (set-buffer mh-show-folder-buffer))
2430 (or mh-delete-list mh-refile-list)))
2432 (defun mh-coalesce-msg-list (messages)
2433 "Given a list of MESSAGES, return a list of message number ranges.
2434 This is the inverse of `mh-read-msg-list', which expands ranges.
2435 Message lists passed to MH programs should be processed by this
2436 function to avoid exceeding system command line argument limits."
2437 (let ((msgs (sort (copy-sequence messages) 'mh-greaterp))
2443 (if (or (not (numberp prev))
2444 (not (equal (car msgs) (1- prev))))
2445 (progn ;non-sequential, flush old range
2446 (if (eq prev range-high)
2447 (setq ranges (cons range-high ranges))
2448 (setq ranges (cons (format "%s-%s" prev range-high) ranges)))
2449 (setq range-high nil))))
2451 (setq range-high (car msgs))) ;start new or first range
2452 (setq prev (car msgs))
2453 (setq msgs (cdr msgs)))
2456 (defun mh-greaterp (msg1 msg2)
2457 "Return the greater of two message indicators MSG1 and MSG2.
2458 Strings are \"smaller\" than numbers.
2459 Valid values are things like \"cur\", \"last\", 1, and 1820."
2466 (string-lessp msg2 msg1))))
2468 (defun mh-lessp (msg1 msg2)
2469 "Return the lesser of two message indicators MSG1 and MSG2.
2470 Strings are \"smaller\" than numbers.
2471 Valid values are things like \"cur\", \"last\", 1, and 1820."
2472 (not (mh-greaterp msg1 msg2)))
2476 ;;; Basic sequence handling
2478 (defun mh-delete-seq-locally (seq)
2479 "Remove MH-E's record of SEQ."
2480 (let ((entry (mh-find-seq seq)))
2481 (setq mh-seq-list (delq entry mh-seq-list))))
2483 (defun mh-read-folder-sequences (folder save-refiles)
2484 "Read and return the predefined sequences for a FOLDER.
2485 If SAVE-REFILES is non-nil, then keep the sequences
2486 that note messages to be refiled."
2489 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
2490 (if (mh-folder-name-p (mh-seq-name seq))
2491 (setq seqs (cons seq seqs)))))
2494 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
2496 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
2497 (while (re-search-forward "^[^: ]+" nil t)
2498 (setq seqs (cons (mh-make-seq (intern (buffer-substring
2503 (delete-region (point-min) (point))))) ; avoid race with
2507 (defun mh-read-msg-list ()
2508 "Return a list of message numbers from point to the end of the line.
2509 Expands ranges into set of individual numbers."
2511 (end-of-line (save-excursion (end-of-line) (point)))
2513 (while (re-search-forward "[0-9]+" end-of-line t)
2514 (setq num (string-to-number (buffer-substring (match-beginning 0)
2516 (cond ((looking-at "-") ; Message range
2518 (re-search-forward "[0-9]+" end-of-line t)
2519 (let ((num2 (string-to-number
2520 (buffer-substring (match-beginning 0)
2523 (error "Bad message range: %d-%d" num num2))
2524 (while (<= num num2)
2525 (setq msgs (cons num msgs))
2526 (setq num (1+ num)))))
2527 ((not (zerop num)) ;"pick" outputs "0" to mean no match
2528 (setq msgs (cons num msgs)))))
2531 (defun mh-notate-user-sequences (&optional range)
2532 "Mark user-defined sequences in RANGE.
2534 Check the documentation of `mh-interactive-range' to see how
2535 RANGE is read in interactive use; if nil all messages are
2538 (setq range (cons (point-min) (point-max))))
2539 (let ((seqs mh-seq-list)
2540 (msg-hash (make-hash-table)))
2542 (dolist (msg (mh-seq-msgs seq))
2543 (push (car seq) (gethash msg msg-hash))))
2544 (mh-iterate-on-range msg range
2545 (loop for seq in (gethash msg msg-hash)
2546 do (mh-add-sequence-notation msg (mh-internal-seq seq))))))
2548 (defvar mh-internal-seqs '(answered cur deleted forwarded printed))
2550 (defun mh-internal-seq (name)
2551 "Return non-nil if NAME is the name of an internal MH-E sequence."
2552 (or (memq name mh-internal-seqs)
2553 (eq name mh-unseen-seq)
2554 (and (mh-colors-in-use-p) mh-tick-seq (eq name mh-tick-seq))
2555 (eq name mh-previous-seq)
2556 (mh-folder-name-p name)))
2558 (defun mh-valid-seq-p (name)
2559 "Return non-nil if NAME is a valid MH sequence name."
2561 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" (symbol-name name))))
2563 (defun mh-delete-msg-from-seq (range sequence &optional internal-flag)
2564 "Delete RANGE from SEQUENCE.
2566 Check the documentation of `mh-interactive-range' to see how
2567 RANGE is read in interactive use.
2569 In a program, non-nil INTERNAL-FLAG means do not inform MH of the
2571 (interactive (list (mh-interactive-range "Delete")
2572 (mh-read-seq-default "Delete from" t)
2574 (let ((entry (mh-find-seq sequence))
2575 (user-sequence-flag (not (mh-internal-seq sequence)))
2576 (folders-changed (list mh-current-folder))
2579 (mh-iterate-on-range msg range
2581 ;; Calling "mark" repeatedly takes too long. So we will pretend here
2582 ;; that we are just modifying an internal sequence...
2583 (when (memq msg (cdr entry))
2584 (mh-remove-sequence-notation msg (not user-sequence-flag)))
2585 (mh-delete-a-msg-from-seq msg sequence t))
2586 ;; ... and here we will "mark" all the messages at one go.
2587 (unless internal-flag (mh-undefine-sequence sequence msg-list))
2588 (when (and mh-index-data (not internal-flag))
2589 (setq folders-changed
2590 (append folders-changed
2591 (mh-index-delete-from-sequence sequence msg-list))))
2592 (when (and (eq sequence mh-unseen-seq) (mh-speed-flists-active-p))
2593 (apply #'mh-speed-flists t folders-changed)))))
2595 (defun mh-catchup (range)
2596 "Delete RANGE from the \"unseen\" sequence.
2598 Check the documentation of `mh-interactive-range' to see how
2599 RANGE is read in interactive use."
2600 (interactive (list (mh-interactive-range "Catchup"
2601 (cons (point-min) (point-max)))))
2602 (mh-delete-msg-from-seq range mh-unseen-seq))
2604 (defun mh-delete-a-msg-from-seq (msg sequence internal-flag)
2605 "Delete MSG from SEQUENCE.
2606 If INTERNAL-FLAG is non-nil, then do not inform MH of the
2608 (let ((entry (mh-find-seq sequence)))
2609 (when (and entry (memq msg (mh-seq-msgs entry)))
2610 (if (not internal-flag)
2611 (mh-undefine-sequence sequence (list msg)))
2612 (setcdr entry (delq msg (mh-seq-msgs entry))))))
2614 (defun mh-undefine-sequence (seq msgs)
2615 "Remove from the SEQ the list of MSGS."
2616 (when (and (mh-valid-seq-p seq) msgs)
2617 (apply #'mh-exec-cmd "mark" mh-current-folder "-delete"
2618 "-sequence" (symbol-name seq) (mh-coalesce-msg-list msgs))))
2620 (defun mh-define-sequence (seq msgs)
2621 "Define the SEQ to contain the list of MSGS.
2622 Do not mark pseudo-sequences or empty sequences.
2623 Signals an error if SEQ is an invalid name."
2625 (mh-valid-seq-p seq)
2626 (not (mh-folder-name-p seq)))
2628 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
2629 "-sequence" (symbol-name seq)
2630 (mh-coalesce-msg-list msgs)))))
2632 (defun mh-seq-containing-msg (msg &optional include-internal-flag)
2633 "Return a list of the sequences containing MSG.
2634 If INCLUDE-INTERNAL-FLAG non-nil, include MH-E internal sequences
2636 (let ((l mh-seq-list)
2639 (and (memq msg (mh-seq-msgs (car l)))
2640 (or include-internal-flag
2641 (not (mh-internal-seq (mh-seq-name (car l)))))
2642 (setq seqs (cons (mh-seq-name (car l)) seqs)))
2648 ;;; Build mh-folder-mode keymap:
2650 (suppress-keymap mh-folder-mode-map)
2652 ;; Use defalias to make sure the documented primary key bindings
2653 ;; appear in menu lists.
2654 (defalias 'mh-alt-show 'mh-show)
2655 (defalias 'mh-alt-refile-msg 'mh-refile-msg)
2656 (defalias 'mh-alt-send 'mh-send)
2657 (defalias 'mh-alt-visit-folder 'mh-visit-folder)
2659 ;; Save the "b" binding for a future `back'. Maybe?
2660 (gnus-define-keys mh-folder-mode-map
2662 "!" mh-refile-or-write-again
2664 "," mh-header-display
2666 ";" mh-toggle-mh-decode-mime-flag
2667 ">" mh-write-msg-to-file
2669 "E" mh-extract-rejected-mail
2671 "\177" mh-previous-page
2672 "\C-d" mh-delete-msg-no-motion
2673 "\t" mh-index-next-folder
2674 [backtab] mh-index-previous-folder
2675 "\M-\t" mh-index-previous-folder
2678 "\ed" mh-redistribute
2680 "^" mh-alt-refile-msg
2687 "k" mh-delete-subject-or-thread
2689 "n" mh-next-undeleted-msg
2690 "\M-n" mh-next-unread-msg
2692 "p" mh-previous-undeleted-msg
2693 "\M-p" mh-previous-unread-msg
2697 "t" mh-toggle-showing
2699 "v" mh-index-visit-folder
2700 "x" mh-execute-commands
2703 (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map)
2705 "'" mh-index-ticked-messages
2708 "f" mh-alt-visit-folder
2711 "n" mh-index-new-messages
2712 "o" mh-alt-visit-folder
2714 "q" mh-index-sequenced-messages
2715 "r" mh-rescan-folder
2718 "v" mh-visit-folder)
2720 (define-key mh-folder-mode-map "I" mh-inc-spool-map)
2722 (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map)
2724 "b" mh-junk-blacklist
2725 "w" mh-junk-whitelist)
2727 (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map)
2729 "C" mh-ps-print-toggle-color
2730 "F" mh-ps-print-toggle-faces
2731 "f" mh-ps-print-msg-file
2733 "p" mh-ps-print-msg)
2735 (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map)
2736 "'" mh-narrow-to-tick
2738 "d" mh-delete-msg-from-seq
2740 "l" mh-list-sequences
2741 "n" mh-narrow-to-seq
2742 "p" mh-put-msg-in-seq
2743 "s" mh-msg-is-in-seq
2746 (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map)
2748 "u" mh-thread-ancestor
2749 "p" mh-thread-previous-sibling
2750 "n" mh-thread-next-sibling
2751 "t" mh-toggle-threads
2752 "d" mh-thread-delete
2753 "o" mh-thread-refile)
2755 (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map)
2756 "'" mh-narrow-to-tick
2759 "f" mh-narrow-to-from
2760 "r" mh-narrow-to-range
2761 "s" mh-narrow-to-subject
2765 (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map)
2767 "s" mh-store-msg ;shar
2768 "u" mh-store-msg) ;uuencode
2770 (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map)
2773 "\177" mh-page-digest-backwards
2774 "b" mh-burst-digest)
2776 (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map)
2778 "a" mh-mime-save-parts
2779 "e" mh-display-with-external-viewer
2780 "i" mh-folder-inline-mime-part
2781 "o" mh-folder-save-mime-part
2782 "t" mh-toggle-mime-buttons
2783 "v" mh-folder-toggle-mime-part
2785 [backtab] mh-prev-button
2786 "\M-\t" mh-prev-button)
2790 (define-key mh-folder-mode-map [button2] 'mh-show-mouse))
2792 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse)))
2794 ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt
2800 ;; If you add a new prefix, add appropriate text to the nil key.
2802 ;; In general, messages are grouped logically. Taking the main commands for
2803 ;; example, the first line is "ways to view messages," the second line is
2804 ;; "things you can do with messages", and the third is "composing" messages.
2806 ;; When adding a new prefix, ensure that the help message contains "what" the
2807 ;; prefix is for. For example, if the word "folder" were not present in the
2808 ;; "F" entry, it would not be clear what these commands operated upon.
2809 (defvar mh-help-messages
2810 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n"
2811 "[d]elete, [o]refile, e[x]ecute,\n"
2812 "[s]end, [r]eply,\n"
2813 "[;]toggle MIME decoding.\n"
2814 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys,"
2815 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.")
2817 (?F "[l]ist; [v]isit folder;\n"
2818 "[n]ew messages; [']ticked messages; [s]earch; [i]ndexed search;\n"
2819 "[p]ack; [S]ort; [r]escan; [k]ill")
2820 (?P "[p]rint message to [f]ile; old-style [l]pr printing;\n"
2821 "Toggle printing of [C]olors, [F]aces")
2822 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n"
2823 "[s]equences, [l]ist,\n"
2824 "[d]elete message from sequence, [k]ill sequence")
2825 (?T "[t]oggle, [d]elete, [o]refile thread")
2826 (?/ "Limit to [c]c, [f]rom, [r]ange, [s]ubject, [t]o; [w]iden")
2827 (?X "un[s]har, [u]udecode message")
2828 (?D "[b]urst digest")
2829 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n"
2830 "[TAB] next; [SHIFT-TAB] previous")
2831 (?J "[b]lacklist, [w]hitelist message"))
2832 "Key binding cheat sheet.
2834 This is an associative array which is used to show the most common commands.
2835 The key is a prefix char. The value is one or more strings which are
2836 concatenated together and displayed in the minibuffer if ? is pressed after
2837 the prefix character. The special key nil is used to display the
2838 non-prefixed commands.
2840 The substitutions described in `substitute-command-keys' are performed as
2845 (dolist (mess '("^Cursor not pointing to message$"
2846 "^There is no other window$"))
2847 (add-to-list 'debug-ignored-errors mess))
2852 ;; indent-tabs-mode: nil
2853 ;; sentence-end-double-space: nil
2856 ;; arch-tag: cce884de-bd37-4104-9963-e4439d5ed22b
2857 ;;; mh-e.el ends here