1 ;;; mh-e.el --- GNU Emacs interface to the MH mail system
3 ;; Copyright (C) 1985, 1986, 1987, 1988,
4 ;; 1990, 1992, 1993, 1994, 1995, 1997, 1999,
5 ;; 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
7 ;; Author: Bill Wohler <wohler@newt.com>
8 ;; Maintainer: Bill Wohler <wohler@newt.com>
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
32 ;; M-x mh-rmail to read mail. Type C-h m there for a list of commands.
33 ;; C-u M-x mh-rmail to visit any folder.
34 ;; M-x mh-smail to send mail. From within the mail reader, "m" works, too.
36 ;; Your .emacs might benefit from these bindings:
37 ;; (global-set-key "\C-cr" 'mh-rmail)
38 ;; (global-set-key "\C-xm" 'mh-smail)
39 ;; (global-set-key "\C-x4m" 'mh-smail-other-window)
41 ;; MH (Message Handler) is a powerful mail reader.
43 ;; The MH newsgroup is comp.mail.mh; the mailing list is mh-users@ics.uci.edu
44 ;; (send to mh-users-request to be added). See the monthly Frequently Asked
45 ;; Questions posting there for information on getting MH and MH-E:
46 ;; http://www.faqs.org/faqs/mail/mh-faq/part1/preamble.html
48 ;; N.B. MH must have been compiled with the MHE compiler flag or several
49 ;; features necessary for MH-E will be missing from MH commands, specifically
50 ;; the -build switch to repl and forw.
52 ;; MH-E is an Emacs interface to the MH mail system.
54 ;; MH-E is supported in GNU Emacs 20 and 21, with MH 6.8.4 and nmh 1.0.4.
57 ;; mh-e-users@lists.sourceforge.net
58 ;; mh-e-announce@lists.sourceforge.net
59 ;; mh-e-devel@lists.sourceforge.net
61 ;; Subscribe by sending a "subscribe" message to
62 ;; <list>-request@lists.sourceforge.net, or by using the web interface at
63 ;; https://sourceforge.net/mail/?group_id=13357
66 ;; https://sourceforge.net/tracker/?group_id=13357&atid=113357
67 ;; Include the output of M-x mh-version in any bug report.
70 ;; https://sourceforge.net/tracker/?atid=363357&group_id=13357&func=browse
73 ;; https://sourceforge.net/tracker/?group_id=13357&atid=213357
77 ;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
78 ;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
79 ;; Rewritten for GNU Emacs, James Larus, 1985.
80 ;; Modified by Stephen Gildea, 1988.
81 ;; Maintenance picked up by Bill Wohler and the
82 ;; SourceForge Crew <http://mh-e.sourceforge.net/>, 2001.
88 (eval-when-compile (require 'mh-acros
))
97 ;; Shush the byte-compiler
98 (defvar font-lock-auto-fontify
)
99 (defvar font-lock-defaults
)
101 (defconst mh-version
"7.85+cvs" "Version number of MH-E.")
103 (defvar mh-partial-folder-mode-line-annotation
"select"
104 "Annotation when displaying part of a folder.
105 The string is displayed after the folder's name. nil for no annotation.")
108 ;;; Scan Line Formats
110 ;;; Parameterize MH-E to work with different scan formats. The defaults work
111 ;;; with the standard MH scan listings, in which the first 4 characters on
112 ;;; the line are the message number, followed by two places for notations.
114 ;; The following scan formats are passed to the scan program if the setting of
115 ;; `mh-scan-format-file' is t. They are identical except the later one makes
116 ;; use of the nmh `decode' function to decode RFC 2047 encodings. If you just
117 ;; want to change the column of the notations, use the `mh-set-cmd-note'
120 (defvar mh-scan-format-mh
125 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
126 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
127 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
128 "%?(nonnull(comp{newsgroups}))n%>"
130 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
131 "%<(mymbox{from})%<{to}To:%14(friendly{to})%>%>"
132 "%<(zero)%17(friendly{from})%> "
133 "%{subject}%<{body}<<%{body}%>")
134 "*Scan format string for MH.
135 This string is passed to the scan program via the -format argument.
136 This format is identical to the default except that additional hints for
137 fontification have been added to the fifth column (remember that in Emacs, the
140 The values of the fifth column, in priority order, are: `-' if the message has
141 been replied to, t if an address on the To: line matches one of the
142 mailboxes of the current user, `c' if the Cc: line matches, `b' if the Bcc:
143 line matches, and `n' if a non-empty Newsgroups: header is present.")
145 (defvar mh-scan-format-nmh
150 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
151 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
152 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
153 "%?(nonnull(comp{newsgroups}))n%>"
155 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
156 "%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>"
157 "%<(zero)%17(decode(friendly{from}))%> "
158 "%(decode{subject})%<{body}<<%{body}%>")
159 "*Scan format string for nmh.
160 This string is passed to the scan program via the -format arg.
161 This format is identical to the default except that additional hints for
162 fontification have been added to the fifth column (remember that in Emacs, the
165 The values of the fifth column, in priority order, are: `-' if the message has
166 been replied to, t if an address on the To: field matches one of the
167 mailboxes of the current user, `c' if the Cc: field matches, `b' if the Bcc:
168 field matches, and `n' if a non-empty Newsgroups: field is present.")
170 (defvar mh-note-deleted ?D
171 "Messages that have been deleted are marked by this character.
172 See also `mh-scan-deleted-msg-regexp'.")
174 (defvar mh-note-refiled ?^
175 "Messages that have been refiled are marked by this character.
176 See also `mh-scan-refiled-msg-regexp'.")
178 (defvar mh-note-cur ?
+
179 "The current message (in MH, not in MH-E) is marked by this character.
180 See also `mh-scan-cur-msg-number-regexp'.")
182 (defvar mh-scan-good-msg-regexp
"^\\( *[0-9]+\\)[^D^0-9]"
183 "This regular expression matches \"good\" messages.
184 It must match from the beginning of the line. Note that the default setting of
185 `mh-folder-font-lock-keywords' expects this expression to contain at least one
186 parenthesized expression which matches the message number as in the default of
187 \"^\\\\( *[0-9]+\\\\)[^D^0-9]\". This expression includes the leading space
188 within the parenthesis since it looks better to highlight it as well. This
189 regular expression should be correct as it is needed by non-fontification
192 (defvar mh-scan-deleted-msg-regexp
"^\\( *[0-9]+\\)D"
193 "This regular expression matches deleted messages.
194 It must match from the beginning of the line. Note that the default setting of
195 `mh-folder-font-lock-keywords' expects this expression to contain at least one
196 parenthesized expression which matches the message number as in the default of
197 \"^\\\\( *[0-9]+\\\\)D\". This expression includes the leading space within
198 the parenthesis since it looks better to highlight it as well. This regular
199 expression should be correct as it is needed by non-fontification functions.
200 See also `mh-note-deleted'.")
202 (defvar mh-scan-refiled-msg-regexp
"^\\( *[0-9]+\\)\\^"
203 "This regular expression matches refiled messages.
204 It must match from the beginning of the line. Note that the default setting of
205 `mh-folder-font-lock-keywords' expects this expression to contain at least one
206 parenthesized expression which matches the message number as in the default of
207 \"^\\\\( *[0-9]+\\\\)\\\\^\". This expression includes the leading space
208 within the parenthesis since it looks better to highlight it as well. This
209 regular expression should be correct as it is needed by non-fontification
210 functions. See also `mh-note-refiled'.")
212 (defvar mh-scan-valid-regexp
"^ *[0-9]"
213 "This regular expression describes a valid scan line.
214 This is used to eliminate error messages that are occasionally produced by
217 (defvar mh-scan-cur-msg-number-regexp
"^\\( *[0-9]+\\+\\).*"
218 "This regular expression matches the current message.
219 It must match from the beginning of the line. Note that the default setting of
220 `mh-folder-font-lock-keywords' expects this expression to contain at least one
221 parenthesized expression which matches the message number as in the default of
222 \"^\\\\( *[0-9]+\\\\+\\\\).*\". This expression includes the leading space and
223 current message marker \"+\" within the parenthesis since it looks better to
224 highlight these items as well. This regular expression should be correct as it
225 is needed by non-fontification functions. See also `mh-note-cur'.")
227 (defvar mh-scan-date-regexp
"\\([0-9][0-9]/[0-9][0-9]\\)"
228 "This regular expression matches a valid date.
229 It must not be anchored to the beginning or the end of the line. Note that the
230 default setting of `mh-folder-font-lock-keywords' expects this expression to
231 contain only one parenthesized expression which matches the date field as in
232 the default of \"\\\\([0-9][0-9]/[0-9][0-9]\\\\)\"}. If this regular
233 expression is not correct, the date will not be highlighted. See also
234 `mh-scan-format-regexp'.")
236 (defvar mh-scan-rcpt-regexp
"\\(To:\\)\\(..............\\)"
237 "This regular expression specifies the recipient in messages you sent.
238 Note that the default setting of `mh-folder-font-lock-keywords'
239 expects this expression to contain two parenthesized expressions. The
240 first is expected to match the `To:' that the default scan format
241 file generates. The second is expected to match the recipient's name
242 as in the default of \"\\\\(To:\\\\)\\\\(..............\\\\)\". If this
243 regular expression is not correct, the recipient will not be highlighted.")
245 (defvar mh-scan-body-regexp
"\\(<<\\([^\n]+\\)?\\)"
246 "This regular expression matches the message body fragment.
247 Note that the default setting of `mh-folder-font-lock-keywords' expects this
248 expression to contain at least one parenthesized expression which matches the
249 body text as in the default of \"\\\\(<<\\\\([^\\n]+\\\\)?\\\\)\". If this
250 regular expression is not correct, the body fragment will not be highlighted.")
252 (defvar mh-scan-subject-regexp
253 "^ *[0-9]+........[ ]*...................\\([Rr][Ee]\\(\\[[0-9]+\\]\\)?:\\s-*\\)*\\([^<\n]*\\)"
254 "This regular expression matches the subject.
255 It must match from the beginning of the line. Note that the default setting
256 of `mh-folder-font-lock-keywords' expects this expression to contain at least
257 three parenthesized expressions. The first is expected to match the `Re:'
258 string, if any. The second matches an optional bracketed number after `Re:',
259 such as in `Re[2]:' (and is thus a sub-expression of the first expression) and
260 the third is expected to match the subject line itself as in the default of
261 \(broken on multiple lines for readability):
262 ^ *[0-9]+........[ ]*...................
263 \\\\([Rr][Ee]\\\\(\\\\\\=[[0-9]+\\\\]\\\\)?:\\\\s-*\\\\)*
265 This regular expression should be correct as it is needed by non-fontification
268 (defvar mh-scan-format-regexp
269 (concat "\\([bct]\\)" mh-scan-date-regexp
" *\\(..................\\)")
270 "This regular expression matches the output of scan.
271 Note that the default setting of `mh-folder-font-lock-keywords' expects this
272 expression to contain at least three parenthesized expressions. The first
273 should match the fontification hint (see `mh-scan-format-nmh'), the second is
274 found in `mh-scan-date-regexp', and the third should match the user name as in
275 the default of \"(concat \"\\\\([bct]\\\\)\" mh-scan-date-regexp
276 \"*\\\\(..................\\\\)\")\".
277 If this regular expression is not correct, the notation hints and the sender
278 will not be highlighted.")
282 (defvar mh-folder-font-lock-keywords
284 ;; Folders when displaying index buffer
286 '(0 mh-index-folder-face
))
287 ;; Marked for deletion
288 (list (concat mh-scan-deleted-msg-regexp
".*")
289 '(0 mh-folder-deleted-face
))
291 (list (concat mh-scan-refiled-msg-regexp
".*")
292 '(0 mh-folder-refiled-face
))
294 (list mh-scan-body-regexp
'(1 mh-folder-body-face nil t
))
295 '(mh-folder-font-lock-subject
296 (1 mh-folder-followup-face append t
)
297 (2 mh-folder-subject-face append t
))
299 (list mh-scan-cur-msg-number-regexp
300 '(1 mh-folder-cur-msg-number-face
))
301 (list mh-scan-good-msg-regexp
302 '(1 mh-folder-msg-number-face
)) ;; Msg number
303 (list mh-scan-date-regexp
'(1 mh-folder-date-face
)) ;; Date
304 (list mh-scan-rcpt-regexp
305 '(1 mh-folder-to-face
) ;; To:
306 '(2 mh-folder-address-face
)) ;; address
307 ;; scan font-lock name
308 (list mh-scan-format-regexp
309 '(1 mh-folder-date-face
)
310 '(3 mh-folder-scan-format-face
)))
311 "Keywords (regular expressions) used to fontify the MH-Folder buffer.")
313 (defvar mh-scan-cmd-note-width
1
314 "Number of columns consumed by the cmd-note field in `mh-scan-format'.
315 This column will have one of the values: ` ', `D', `^', `+' and where
316 ` ' is the default value,
317 `D' is the `mh-note-deleted' character,
318 `^' is the `mh-note-refiled' character, and
319 `+' is the `mh-note-cur' character.")
321 (defvar mh-scan-destination-width
1
322 "Number of columns consumed by the destination field in `mh-scan-format'.
323 This column will have one of ' ', '%', '-', 't', 'c', 'b', or `n' in it.
324 A ' ' blank space is the default character.
325 A '%' indicates that the message in in a named MH sequence.
326 A '-' indicates that the message has been annotated with a replied field.
327 A 't' indicates that the message contains mymbox in the To: field.
328 A 'c' indicates that the message contains mymbox in the Cc: field.
329 A 'b' indicates that the message contains mymbox in the Bcc: field.
330 A 'n' indicates that the message contains a Newsgroups: field.")
332 (defvar mh-scan-date-width
5
333 "Number of columns consumed by the date field in `mh-scan-format'.
334 This column will typically be of the form mm/dd.")
336 (defvar mh-scan-date-flag-width
1
337 "Number of columns consumed to flag (in)valid dates in `mh-scan-format'.
338 This column will have ` ' for valid and `*' for invalid or missing dates.")
340 (defvar mh-scan-from-mbox-width
17
341 "Number of columns consumed with the \"From:\" line in `mh-scan-format'.
342 This column will have a friendly name or e-mail address of the
343 originator, or a \"To: address\" for outgoing e-mail messages.")
345 (defvar mh-scan-from-mbox-sep-width
2
346 "Number of columns consumed by whitespace after from-mbox in `mh-scan-format'.
347 This column will only ever have spaces in it.")
349 (defvar mh-scan-field-destination-offset
350 (+ mh-scan-cmd-note-width
)
351 "The offset from the `mh-cmd-note' for the destination column.")
353 (defvar mh-scan-field-from-start-offset
354 (+ mh-scan-cmd-note-width
355 mh-scan-destination-width
357 mh-scan-date-flag-width
)
358 "The offset from the `mh-cmd-note' to find the start of \"From:\" address.")
360 (defvar mh-scan-field-from-end-offset
361 (+ mh-scan-field-from-start-offset mh-scan-from-mbox-width
)
362 "The offset from the `mh-cmd-note' to find the end of \"From:\" address.")
364 (defvar mh-scan-field-subject-start-offset
365 (+ mh-scan-cmd-note-width
366 mh-scan-destination-width
368 mh-scan-date-flag-width
369 mh-scan-from-mbox-width
370 mh-scan-from-mbox-sep-width
)
371 "The offset from the `mh-cmd-note' to find the start of the subject.")
373 (defun mh-folder-font-lock-subject (limit)
374 "Return MH-E scan subject strings to font-lock between point and LIMIT."
375 (if (not (re-search-forward mh-scan-subject-regexp limit t
))
377 (if (match-beginning 1)
378 (set-match-data (list (match-beginning 1) (match-end 3)
379 (match-beginning 1) (match-end 3) nil nil
))
380 (set-match-data (list (match-beginning 3) (match-end 3)
381 nil nil
(match-beginning 3) (match-end 3))))
386 ;; Fontifify unseen mesages in bold.
388 (defmacro mh-generate-sequence-font-lock
(seq prefix face
)
389 "Generate the appropriate code to fontify messages in SEQ.
390 PREFIX is used to generate unique names for the variables and functions
391 defined by the macro. So a different prefix should be provided for every
393 FACE is the font-lock face used to display the matching scan lines."
394 (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix
)))
395 (func (intern (format "mh-folder-font-lock-%s" prefix
))))
398 "Internal cache variable used for font-lock in MH-E.
399 Should only be non-nil through font-lock stepping, and nil once font-lock
400 is done highlighting.")
401 (make-variable-buffer-local ',cache
)
404 "Return unseen message lines to font-lock between point and LIMIT."
405 (if (not ,cache
) (setq ,cache
(mh-seq-msgs (mh-find-seq ,seq
))))
406 (let ((cur-msg (mh-get-msg-num nil
)))
409 ((>= (point) limit
) ;Presumably at end of buffer
412 ((member cur-msg
,cache
)
413 (let ((bpoint (progn (beginning-of-line)(point)))
414 (epoint (progn (forward-line 1)(point))))
415 (if (<= limit
(point)) (setq ,cache nil
))
416 (set-match-data (list bpoint epoint bpoint epoint
))
419 ;; move forward one line at a time, checking each message
420 (while (and (= 0 (forward-line 1))
422 (not (member (mh-get-msg-num nil
) ,cache
))))
423 ;; Examine how we must have exited the loop...
424 (let ((cur-msg (mh-get-msg-num nil
)))
425 (cond ((or (<= limit
(point))
426 (not (member cur-msg
,cache
)))
429 ((member cur-msg
,cache
)
430 (let ((bpoint (progn (beginning-of-line) (point)))
431 (epoint (progn (forward-line 1) (point))))
432 (if (<= limit
(point)) (setq ,cache nil
))
434 (list bpoint epoint bpoint epoint
))
437 (setq mh-folder-font-lock-keywords
438 (append mh-folder-font-lock-keywords
439 (list (list ',func
(list 1 '',face
'prepend t
))))))))
441 (mh-generate-sequence-font-lock mh-unseen-seq unseen bold
)
442 (mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick
)
446 ;;; Internal variables:
448 (defvar mh-last-destination nil
) ;Destination of last refile or write
450 (defvar mh-last-destination-folder nil
) ;Destination of last refile command.
451 (defvar mh-last-destination-write nil
) ;Destination of last write command.
453 (defvar mh-folder-mode-map
(make-keymap)
454 "Keymap for MH folders.")
456 (defvar mh-arrow-marker nil
) ;Marker for arrow display in fringe.
458 (defvar mh-delete-list nil
) ;List of msg numbers to delete.
460 (defvar mh-refile-list nil
) ;List of folder names in mh-seq-list.
462 (defvar mh-next-direction
'forward
) ;Direction to move to next message.
464 (defvar mh-view-ops
()) ;Stack of ops that change the folder
465 ;view (such as narrowing or threading).
466 (defvar mh-folder-view-stack
()) ;Stack of previous folder views.
468 (defvar mh-index-data nil
) ;Info about index search results
469 (defvar mh-index-previous-search nil
)
470 (defvar mh-index-msg-checksum-map nil
)
471 (defvar mh-index-checksum-origin-map nil
)
472 (defvar mh-index-sequence-search-flag nil
)
474 (defvar mh-first-msg-num nil
) ;Number of first msg in buffer.
476 (defvar mh-last-msg-num nil
) ;Number of last msg in buffer.
478 (defvar mh-mode-line-annotation nil
) ;Message range displayed in buffer.
480 (defvar mh-sequence-notation-history nil
)
481 ;Rememeber original notation that
482 ;is overwritten by `mh-note-seq'.
484 (defvar mh-colors-available-flag nil
) ;Are colors available?
486 ;;; Macros and generic functions:
488 (defun mh-mapc (function list
)
489 "Apply FUNCTION to each element of LIST for side effects only."
491 (funcall function
(car list
))
492 (setq list
(cdr list
))))
494 (defun mh-scan-format ()
495 "Return the output format argument for the scan program."
496 (if (equal mh-scan-format-file t
)
497 (list "-format" (if (mh-variant-p 'nmh
'mu-mh
)
498 (list (mh-update-scan-format
499 mh-scan-format-nmh mh-cmd-note
))
500 (list (mh-update-scan-format
501 mh-scan-format-mh mh-cmd-note
))))
502 (if (not (equal mh-scan-format-file nil
))
503 (list "-form" mh-scan-format-file
))))
510 (defun mh-rmail (&optional arg
)
511 "Inc(orporate) new mail with MH.
512 Scan an MH folder if ARG is non-nil. This function is an entry point to MH-E,
513 the Emacs interface to the MH mail system."
517 (call-interactively 'mh-visit-folder
)
518 (unless (get-buffer mh-inbox
)
519 (mh-visit-folder mh-inbox
(symbol-name mh-unseen-seq
)))
523 (defun mh-nmail (&optional arg
)
524 "Check for new mail in inbox folder.
525 Scan an MH folder if ARG is non-nil. This function is an entry point to MH-E,
526 the Emacs interface to the MH mail system."
528 (mh-find-path) ; init mh-inbox
530 (call-interactively 'mh-visit-folder
)
531 (mh-visit-folder mh-inbox
)))
535 ;;; User executable MH-E commands:
537 (defun mh-delete-msg (range)
538 "Delete message\\<mh-folder-mode-map>.
540 To mark a message for deletion, use this command. A \"D\" is placed by the
541 message in the scan window, and the next undeleted message is displayed. If
542 the previous command had been \\[mh-previous-undeleted-msg], then the next
543 message displayed is the first undeleted message previous to the message just
544 deleted. Use \\[mh-next-undeleted-msg] to force subsequent \\[mh-delete-msg]
545 commands to move forward to the next undeleted message after deleting the
546 message under the cursor.
548 Check the documentation of `mh-interactive-range' to see how RANGE is read in
550 (interactive (list (mh-interactive-range "Delete")))
551 (mh-delete-msg-no-motion range
)
552 (if (looking-at mh-scan-deleted-msg-regexp
) (mh-next-msg)))
554 (defun mh-delete-msg-no-motion (range)
555 "Delete message, don't move to next message.
557 This command marks the message (or messages in RANGE) for deletion but leaves
558 the cursor at the current message in case you wish to perform other operations
561 Check the documentation of `mh-interactive-range' to see how RANGE is read in
563 (interactive (list (mh-interactive-range "Delete")))
564 (mh-iterate-on-range () range
565 (mh-delete-a-msg nil
)))
567 (defun mh-execute-commands ()
568 "Process outstanding delete and refile requests."
570 (if mh-folder-view-stack
(mh-widen t
))
571 (mh-process-commands mh-current-folder
)
573 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
574 (mh-make-folder-mode-line)
575 t
) ; return t for write-file-functions
577 (defun mh-first-msg ()
578 "Display first message."
580 (goto-char (point-min))
581 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp
)))
584 (defun mh-header-display ()
585 "Display message with all header fields\\<mh-folder-mode-map>.
587 Use the command \\[mh-show] to show the message normally again."
589 (and (not mh-showing-with-headers
)
590 (or mh-mhl-format-file mh-clean-message-header-flag
)
591 (mh-invalidate-show-buffer))
592 (let ((mh-decode-mime-flag nil
)
593 (mh-mhl-format-file nil
)
594 (mh-clean-message-header-flag nil
))
596 (mh-in-show-buffer (mh-show-buffer)
597 (goto-char (point-min))
599 (setq mh-showing-with-headers t
)))
601 (defun mh-inc-folder (&optional maildrop-name folder
)
602 "Inc(orporate)s new mail into the Inbox folder.
603 Optional argument MAILDROP-NAME specifies an alternate maildrop from the
604 default. The optional argument FOLDER specifies where to incorporate mail
605 instead of the default named by `mh-inbox'.
606 The value of `mh-inc-folder-hook' is a list of functions to be called, with no
607 arguments, after incorporating new mail.
608 Do not call this function from outside MH-E; use \\[mh-rmail] instead."
609 (interactive (list (if current-prefix-arg
611 (read-file-name "inc mail from file: "
613 (if current-prefix-arg
614 (mh-prompt-for-folder "inc mail into" mh-inbox t
))))
616 (setq folder mh-inbox
))
617 (let ((threading-needed-flag nil
))
618 (let ((config (current-window-configuration)))
619 (when (and mh-show-buffer
(get-buffer mh-show-buffer
))
620 (delete-windows-on mh-show-buffer
))
621 (cond ((not (get-buffer folder
))
622 (mh-make-folder folder
)
623 (setq threading-needed-flag mh-show-threads-flag
)
624 (setq mh-previous-window-config config
))
625 ((not (eq (current-buffer) (get-buffer folder
)))
626 (switch-to-buffer folder
)
627 (setq mh-previous-window-config config
))))
628 (mh-get-new-mail maildrop-name
)
629 (when (and threading-needed-flag
631 (goto-char (point-min))
632 (or (null mh-large-folder
)
633 (not (equal (forward-line (1+ mh-large-folder
)) 0))
634 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
638 (if (and mh-showing-mode
(looking-at mh-scan-valid-regexp
)) (mh-show))
639 (run-hooks 'mh-inc-folder-hook
)))
641 (defun mh-last-msg ()
642 "Display last message."
644 (goto-char (point-max))
645 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp
)))
649 (defun mh-next-undeleted-msg (&optional count wait-after-complaining-flag
)
650 "Display next message.
652 This command can be given a prefix argument COUNT to specify how many unread
655 In a program, pause for a second after printing message if we are at the last
656 undeleted message and optional argument WAIT-AFTER-COMPLAINING-FLAG is
659 (setq mh-next-direction
'forward
)
661 (cond ((re-search-forward mh-scan-good-msg-regexp nil t count
)
665 (message "No more undeleted messages")
666 (if wait-after-complaining-flag
(sit-for 1)))))
668 (defun mh-folder-from-address ()
669 "Derive folder name from sender.
671 The name of the folder is derived as follows:
673 a) The folder name associated with the first address found in the list
674 `mh-default-folder-list' is used. Each element in this list contains a
675 `Check Recipient' item. If this item is turned on, then the address is
676 checked against the recipient instead of the sender. This is useful for
679 b) An alias prefixed by `mh-default-folder-prefix' corresponding to the
680 address is used. The prefix is used to prevent clutter in your mail
683 Return nil if a folder name was not derived, or if the variable
684 `mh-default-folder-must-exist-flag' is t and the folder does not exist."
685 ;; Loop for all entries in mh-default-folder-list
687 (goto-char (point-min))
688 (re-search-forward "\n\n" nil
'limit
)
689 (narrow-to-region (point-min) (point))
690 (let ((to/cc
(concat (or (message-fetch-field "to") "") ", "
691 (or (message-fetch-field "cc") "")))
692 (from (or (message-fetch-field "from") ""))
695 (loop for list in mh-default-folder-list
696 when
(string-match (nth 0 list
) (if (nth 2 list
) to
/cc from
))
700 ;; Make sure a result from `mh-default-folder-list' begins with "+"
701 ;; since 'mh-expand-file-name below depends on it
702 (when (and folder-name
(not (eq (aref folder-name
0) ?
+)))
703 (setq folder-name
(concat "+" folder-name
)))
705 ;; If not, is there an alias for the address?
706 (when (not folder-name
)
707 (let* ((from-header (mh-extract-from-header-value))
708 (address (and from-header
709 (nth 1 (mail-extract-address-components
711 (alias (and address
(mh-alias-address-to-alias address
))))
714 (and alias
(concat "+" mh-default-folder-prefix alias
))))))
716 ;; If mh-default-folder-must-exist-flag set, check that folder exists.
718 (or (not mh-default-folder-must-exist-flag
)
719 (file-exists-p (mh-expand-file-name folder-name
))))
722 (defun mh-prompt-for-refile-folder ()
723 "Prompt the user for a folder in which the message should be filed.
724 The folder is returned as a string.
726 The default folder name is generated by the option
727 `mh-default-folder-for-message-function' if it is non-nil or
728 `mh-folder-from-address'."
729 (mh-prompt-for-folder
731 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t
)))))
732 (if (null refile-file
) ""
734 (set-buffer (get-buffer-create mh-temp-buffer
))
736 (insert-file-contents refile-file
)
737 (or (and mh-default-folder-for-message-function
738 (let ((buffer-file-name refile-file
))
739 (funcall mh-default-folder-for-message-function
)))
740 (mh-folder-from-address)
741 (and (eq 'refile
(car mh-last-destination-folder
))
742 (symbol-name (cdr mh-last-destination-folder
)))
746 (defun mh-refile-msg (range folder
&optional dont-update-last-destination-flag
)
747 "Refile RANGE into FOLDER.
749 Check the documentation of `mh-interactive-range' to see how RANGE is read in
752 If optional argument DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil then the
753 variables `mh-last-destination' and `mh-last-destination-folder' are not
755 (interactive (list (mh-interactive-range "Refile")
756 (intern (mh-prompt-for-refile-folder))))
757 (unless dont-update-last-destination-flag
758 (setq mh-last-destination
(cons 'refile folder
)
759 mh-last-destination-folder mh-last-destination
))
760 (mh-iterate-on-range () range
761 (mh-refile-a-msg nil folder
))
762 (when (looking-at mh-scan-refiled-msg-regexp
) (mh-next-msg)))
764 (defun mh-refile-or-write-again (range &optional interactive-flag
)
765 "Repeat last output command.
767 If you are refiling several messages into the same folder, you can use this
768 command to repeat the last refile or write. Or, you can use a range.
770 Check the documentation of `mh-interactive-range' to see how RANGE is read in
773 In a program, a non-nil INTERACTIVE-FLAG means that the function was called
775 (interactive (list (mh-interactive-range "Redo") t
))
776 (if (null mh-last-destination
)
777 (error "No previous refile or write"))
778 (cond ((eq (car mh-last-destination
) 'refile
)
779 (mh-refile-msg range
(cdr mh-last-destination
))
780 (message "%s" (format "Destination folder: %s"
781 (cdr mh-last-destination
))))
783 (mh-iterate-on-range msg range
784 (apply 'mh-write-msg-to-file msg
(cdr mh-last-destination
)))
785 (mh-next-msg interactive-flag
))))
788 "Quit the current MH-E folder.
789 Restore the previous window configuration, if one exists.
790 The value of `mh-before-quit-hook' is a list of functions to be called, with
791 no arguments, immediately upon entry to this function.
792 The value of `mh-quit-hook' is a list of functions to be called, with no
793 arguments, upon exit of this function.
794 MH-E working buffers (whose name begins with \" *mh-\" or \"*MH-E \") are
797 (run-hooks 'mh-before-quit-hook
)
798 (let ((show-buffer (get-buffer mh-show-buffer
)))
800 (kill-buffer show-buffer
)))
801 (mh-update-sequences)
802 (mh-destroy-postponed-handles)
803 (bury-buffer (current-buffer))
805 ;; Delete all MH-E temporary and working buffers.
806 (dolist (buffer (buffer-list))
807 (when (or (string-match "^ \\*mh-" (buffer-name buffer
))
808 (string-match "^\\*MH-E " (buffer-name buffer
)))
809 (kill-buffer buffer
)))
811 (if mh-previous-window-config
812 (set-window-configuration mh-previous-window-config
))
813 (run-hooks 'mh-quit-hook
))
815 (defun mh-page-msg (&optional lines
)
816 "Display next page in message.
818 You can give this command a prefix argument that specifies the number of LINES
819 to scroll. This command will also show the next undeleted message if it is
820 used at the bottom of a message."
823 (if mh-page-to-next-msg-flag
824 (if (equal mh-next-direction
'backward
)
825 (mh-previous-undeleted-msg)
826 (mh-next-undeleted-msg))
827 (if (mh-in-show-buffer (mh-show-buffer)
828 (pos-visible-in-window-p (point-max)))
831 "End of message (Type %s to read %s undeleted message)"
832 (single-key-description last-input-event
)
833 (if (equal mh-next-direction
'backward
)
836 (setq mh-page-to-next-msg-flag t
))
837 (scroll-other-window lines
)))
840 (defun mh-previous-page (&optional lines
)
841 "Display next page in message.
843 You can give this command a prefix argument that specifies the number of LINES
846 (mh-in-show-buffer (mh-show-buffer)
847 (scroll-down lines
)))
849 (defun mh-previous-undeleted-msg (&optional count wait-after-complaining-flag
)
850 "Display previous message.
852 This command can be given a prefix argument COUNT to specify how many unread
855 In a program, pause for a second after printing message if we are at the last
856 undeleted message and optional argument WAIT-AFTER-COMPLAINING-FLAG is
859 (setq mh-next-direction
'backward
)
861 (cond ((re-search-backward mh-scan-good-msg-regexp nil t count
)
863 (t (message "No previous undeleted message")
864 (if wait-after-complaining-flag
(sit-for 1)))))
866 (defun mh-previous-unread-msg (&optional count
)
867 "Display previous unread message.
869 This command can be given a prefix argument COUNT to specify how many unread
873 (error "The function mh-previous-unread-msg expects positive argument"))
874 (setq count
(1- count
))
875 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list
)))
876 (cur-msg (mh-get-msg-num nil
)))
877 (cond ((and (not cur-msg
) (not (bobp))
878 ;; If we are at the end of the buffer back up one line and go
879 ;; to unread message after that.
882 (setq cur-msg
(mh-get-msg-num nil
)))
884 ((or (null unread-sequence
) (not cur-msg
))
885 ;; No unread message or there aren't any messages in buffer...
886 (message "No more unread messages"))
888 ;; Skip count messages...
889 (while (and unread-sequence
(>= (car unread-sequence
) cur-msg
))
890 (setq unread-sequence
(cdr unread-sequence
)))
892 (setq unread-sequence
(cdr unread-sequence
))
893 (setq count
(1- count
)))
894 (not (car unread-sequence
)))
895 (message "No more unread messages"))
896 (t (loop for msg in unread-sequence
897 when
(mh-goto-msg msg t
) return nil
898 finally
(message "No more unread messages"))))))
900 (defun mh-goto-next-button (backward-flag &optional criterion
)
901 "Search for next button satisfying criterion.
902 If BACKWARD-FLAG is non-nil search backward in the buffer for a mime button. If
903 CRITERION is a function or a symbol which has a function binding then that
904 function must return non-nil at the button we stop."
905 (unless (or (and (symbolp criterion
) (fboundp criterion
))
906 (functionp criterion
))
907 (setq criterion
(lambda (x) t
)))
908 ;; Move to the next button in the buffer satisfying criterion
909 (goto-char (or (save-excursion
911 ;; Find point before current button
912 (let ((point-before-current-button
914 (while (get-text-property (point) 'mh-data
)
915 (unless (= (forward-line
916 (if backward-flag
1 -
1))
919 (goto-char (point-min))
920 (goto-char (point-max)))))
922 ;; Skip over current button
923 (while (and (get-text-property (point) 'mh-data
)
924 (not (if backward-flag
(bobp) (eobp))))
925 (forward-line (if backward-flag -
1 1)))
926 ;; Stop at next MIME button if any exists.
929 (unless (= (forward-line
930 (if backward-flag -
1 1))
933 (goto-char (point-max))
934 (goto-char (point-min)))
937 point-before-current-button
)
938 (when (and (get-text-property (point) 'mh-data
)
939 (funcall criterion
(point)))
940 (return-from loop
(point))))
944 (defun mh-next-button (&optional backward-flag
)
945 "Go to the next button.
947 If the end of the buffer is reached then the search wraps over to the start of
950 If an optional prefix argument BACKWARD-FLAG is given, the cursor will move to
951 the previous button."
952 (interactive (list current-prefix-arg
))
953 (unless mh-showing-mode
955 (mh-in-show-buffer (mh-show-buffer)
956 (mh-goto-next-button backward-flag
)))
958 (defun mh-prev-button ()
959 "Go to the previous button.
961 If the beginning of the buffer is reached then the search wraps over to the
966 (defun mh-folder-mime-action (part-index action include-security-flag
)
967 "Go to PART-INDEX and carry out ACTION.
968 If PART-INDEX is nil then go to the next part in the buffer. The search for
969 the next buffer wraps around if end of buffer is reached. If argument
970 INCLUDE-SECURITY-FLAG is non-nil then include security info buttons when
971 searching for a suitable parts."
972 (unless mh-showing-mode
974 (mh-in-show-buffer (mh-show-buffer)
978 (let ((part (get-text-property p
'mh-part
)))
979 (and (integerp part
) (= part part-index
)))))
981 (if include-security-flag
982 (get-text-property p
'mh-data
)
983 (integerp (get-text-property p
'mh-part
)))))))
985 (cond ((and (get-text-property point
'mh-part
)
986 (or (null part-index
)
987 (= (get-text-property point
'mh-part
) part-index
)))
989 ((and (get-text-property point
'mh-data
)
990 include-security-flag
994 (mh-goto-next-button nil criterion
)
995 (if (= (point) point
)
996 (message "No matching MIME part found")
997 (funcall action
)))))))
999 (defun mh-folder-toggle-mime-part (part-index)
1002 This command displays (or hides) the attachment associated with the button
1003 under the cursor. If the cursor is not located over a button, then the cursor
1004 first moves to the next button, wrapping to the beginning of the message if
1005 necessary. This command has the advantage over related commands of working
1006 from the MH-Folder buffer.
1008 You can also provide a numeric prefix argument PART-INDEX to view the
1009 attachment labeled with that number. If Emacs does not know how to display the
1010 attachment, then Emacs offers to save the attachment in a file."
1012 (when (consp part-index
) (setq part-index
(car part-index
)))
1013 (mh-folder-mime-action part-index
#'mh-press-button t
))
1015 (defun mh-folder-inline-mime-part (part-index)
1016 "Show attachment verbatim.
1018 You can view the raw contents of an attachment with this command. This command
1019 displays (or hides) the contents of the attachment associated with the button
1020 under the cursor verbatim. If the cursor is not located over a button, then
1021 the cursor first moves to the next button, wrapping to the beginning of the
1022 message if necessary.
1024 You can also provide a numeric prefix argument PART-INDEX to view the
1025 attachment labeled with that number."
1027 (when (consp part-index
) (setq part-index
(car part-index
)))
1028 (mh-folder-mime-action part-index
#'mh-mime-inline-part nil
))
1030 (defun mh-folder-save-mime-part (part-index)
1031 "Save (output) attachment.
1033 This command saves the attachment associated with the button under the cursor.
1034 If the cursor is not located over a button, then the cursor first moves to the
1035 next button, wrapping to the beginning of the message if necessary.
1037 You can also provide a numeric prefix argument PART-INDEX to save the
1038 attachment labeled with that number.
1040 This command prompts you for a filename and suggests a specific name if it is
1043 (when (consp part-index
) (setq part-index
(car part-index
)))
1044 (mh-folder-mime-action part-index
#'mh-mime-save-part nil
))
1046 (defvar mh-thread-scan-line-map-stack
)
1048 (defun mh-reset-threads-and-narrowing ()
1049 "Reset all variables pertaining to threads and narrowing.
1050 Also removes all content from the folder buffer."
1051 (setq mh-view-ops
())
1052 (setq mh-folder-view-stack
())
1053 (setq mh-thread-scan-line-map-stack
())
1054 (let ((buffer-read-only nil
)) (erase-buffer)))
1056 (defun mh-rescan-folder (&optional range dont-exec-pending
)
1057 "Rescan a folder after optionally processing the outstanding commands.
1058 If optional prefix argument RANGE is provided, prompt for the range of
1059 messages to display. Otherwise show the entire folder.
1060 If optional argument DONT-EXEC-PENDING is non-nil then pending deletes and
1061 refiles aren't carried out."
1062 (interactive (list (if current-prefix-arg
1063 (mh-read-range "Rescan" mh-current-folder t nil t
1064 mh-interpret-number-as-range-flag
)
1066 (setq mh-next-direction
'forward
)
1067 (let ((threaded-flag (memq 'unthread mh-view-ops
)))
1068 (mh-scan-folder mh-current-folder
(or range
"all") dont-exec-pending
)
1069 (cond (threaded-flag (mh-toggle-threads))
1070 (mh-index-data (mh-index-insert-folder-headers)))))
1072 (defun mh-write-msg-to-file (message file no-header
)
1073 "Append MESSAGE to end of FILE\\<mh-folder-mode-map>.
1075 You are prompted for the filename. If the file already exists, the message is
1076 appended to it. You can also write the message to the file without the header
1077 by specifying a prefix argument NO-HEADER. Subsequent writes to the same file
1078 can be made with the command \\[mh-refile-or-write-again]."
1080 (list (mh-get-msg-num t
)
1081 (let ((default-dir (if (eq 'write
(car mh-last-destination-write
))
1082 (file-name-directory
1083 (car (cdr mh-last-destination-write
)))
1084 default-directory
)))
1085 (read-file-name (format "Save message%s in file: "
1086 (if current-prefix-arg
" body" ""))
1088 (if (eq 'write
(car mh-last-destination-write
))
1089 (car (cdr mh-last-destination-write
))
1090 (expand-file-name "mail.out" default-dir
))))
1091 current-prefix-arg
))
1092 (let ((msg-file-to-output (mh-msg-filename message
))
1093 (output-file (mh-expand-file-name file
)))
1094 (setq mh-last-destination
(list 'write file
(if no-header
'no-header
))
1095 mh-last-destination-write mh-last-destination
)
1097 (set-buffer (get-buffer-create mh-temp-buffer
))
1099 (insert-file-contents msg-file-to-output
)
1100 (goto-char (point-min))
1101 (if no-header
(search-forward "\n\n"))
1102 (append-to-file (point) (point-max) output-file
))))
1104 (defun mh-toggle-showing ()
1105 "Toggle the scanning mode/showing mode of displaying messages."
1111 (defun mh-undo (range)
1112 "Undo the pending deletion or refile of the specified RANGE.
1114 Check the documentation of `mh-interactive-range' to see how RANGE is read in
1116 (interactive (list (mh-interactive-range "Undo")))
1117 (cond ((numberp range
)
1118 (let ((original-position (point)))
1120 (while (not (or (looking-at mh-scan-deleted-msg-regexp
)
1121 (looking-at mh-scan-refiled-msg-regexp
)
1122 (and (eq mh-next-direction
'forward
) (bobp))
1123 (and (eq mh-next-direction
'backward
)
1124 (save-excursion (forward-line) (eobp)))))
1125 (forward-line (if (eq mh-next-direction
'forward
) -
1 1)))
1126 (if (or (looking-at mh-scan-deleted-msg-regexp
)
1127 (looking-at mh-scan-refiled-msg-regexp
))
1129 (mh-undo-msg (mh-get-msg-num t
))
1131 (goto-char original-position
)
1132 (error "Nothing to undo"))))
1133 (t (mh-iterate-on-range () range
1134 (mh-undo-msg nil
))))
1135 (if (not (mh-outstanding-commands-p))
1136 (mh-set-folder-modified-p nil
)))
1139 (defun mh-folder-line-matches-show-buffer-p ()
1140 "Return t if the message under point in folder-mode is in the show buffer.
1141 Return nil in any other circumstance (no message under point, no show buffer,
1142 the message in the show buffer doesn't match."
1143 (and (eq major-mode
'mh-folder-mode
)
1144 (mh-get-msg-num nil
)
1146 (get-buffer mh-show-buffer
)
1147 (buffer-file-name (get-buffer mh-show-buffer
))
1148 (string-match ".*/\\([0-9]+\\)$"
1149 (buffer-file-name (get-buffer mh-show-buffer
)))
1151 (match-string 1 (buffer-file-name (get-buffer mh-show-buffer
)))
1152 (int-to-string (mh-get-msg-num nil
)))))
1154 (eval-when-compile (require 'gnus
))
1156 (defmacro mh-macro-expansion-time-gnus-version
()
1157 "Return Gnus version available at macro expansion time.
1158 The macro evaluates the Gnus version at macro expansion time. If MH-E was
1159 compiled then macro expansion happens at compile time."
1162 (defun mh-run-time-gnus-version ()
1163 "Return Gnus version available at run time."
1168 (defun mh-version ()
1169 "Display version information about MH-E and the MH mail handling system."
1171 (set-buffer (get-buffer-create mh-info-buffer
))
1174 (insert "MH-E " mh-version
"\n\n")
1175 ;; MH-E compilation details.
1176 (insert "MH-E compilation details:\n")
1177 (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version
)))
1178 (gnus-compiled-version (if compiled-mhe
1179 (mh-macro-expansion-time-gnus-version)
1181 (insert " Byte compiled:\t\t" (if compiled-mhe
"yes" "no") "\n"
1182 " Gnus (compile-time):\t" gnus-compiled-version
"\n"
1183 " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
1185 (insert (emacs-version) "\n\n")
1187 (if mh-variant-in-use
1188 (insert mh-variant-in-use
"\n"
1189 " mh-progs:\t" mh-progs
"\n"
1190 " mh-lib:\t" mh-lib
"\n"
1191 " mh-lib-progs:\t" mh-lib-progs
"\n\n")
1192 (insert "No MH variant detected\n"))
1195 (call-process "uname" nil t nil
"-a")
1197 (goto-char (point-min))
1198 (display-buffer mh-info-buffer
))
1200 (defun mh-parse-flist-output-line (line &optional current-folder
)
1201 "Parse LINE to generate folder name, unseen messages and total messages.
1202 If CURRENT-FOLDER is non-nil then it contains the current folder name and it is
1203 used to avoid problems in corner cases involving folders whose names end with a
1207 (goto-char (point-max))
1208 (let (folder unseen total p
)
1209 (when (search-backward " out of " (point-min) t
)
1210 (setq total
(read-from-string
1211 (buffer-substring-no-properties
1212 (match-end 0) (line-end-position))))
1213 (when (search-backward " in sequence " (point-min) t
)
1215 (when (search-backward " has " (point-min) t
)
1216 (setq unseen
(read-from-string (buffer-substring-no-properties
1218 (while (eq (char-after) ?
)
1220 (setq folder
(buffer-substring-no-properties
1221 (point-min) (1+ (point))))
1222 (when (and (equal (aref folder
(1- (length folder
))) ?
+)
1223 (equal current-folder folder
))
1224 (setq folder
(substring folder
0 (1- (length folder
)))))
1225 (values (format "+%s" folder
) (car unseen
) (car total
))))))))
1227 (defun mh-folder-size-folder (folder)
1228 "Find size of FOLDER using `folder'."
1230 (let ((u (length (cdr (assoc mh-unseen-seq
1231 (mh-read-folder-sequences folder nil
))))))
1232 (call-process (expand-file-name "folder" mh-progs
) nil t nil
1233 "-norecurse" folder
)
1234 (goto-char (point-min))
1235 (if (re-search-forward " has \\([0-9]+\\) " nil t
)
1236 (values (car (read-from-string (match-string 1))) u folder
)
1237 (values 0 u folder
)))))
1239 (defun mh-folder-size-flist (folder)
1240 "Find size of FOLDER using `flist'."
1242 (call-process (expand-file-name "flist" mh-progs
) nil t nil
"-showzero"
1243 "-norecurse" folder
"-sequence" (symbol-name mh-unseen-seq
))
1244 (goto-char (point-min))
1245 (multiple-value-bind (folder unseen total
)
1246 (mh-parse-flist-output-line
1247 (buffer-substring (point) (line-end-position)))
1248 (values total unseen folder
))))
1250 (defun mh-folder-size (folder)
1251 "Find size of FOLDER."
1252 (if mh-flists-present-flag
1253 (mh-folder-size-flist folder
)
1254 (mh-folder-size-folder folder
)))
1256 (defun mh-visit-folder (folder &optional range index-data
)
1257 "Visit FOLDER and display RANGE of messages.
1258 Do not call this function from outside MH-E; see \\[mh-rmail] instead.
1260 If RANGE is nil (the default if it is omitted when called non-interactively),
1261 then all messages in FOLDER are displayed.
1263 If an index buffer is being created then INDEX-DATA is used to initialize the
1264 index buffer specific data structures.
1266 A prefix argument will cause a prompt for the RANGE of messages
1267 regardless of the size of the `mh-large-folder' variable."
1268 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t
)))
1270 (mh-read-range "Scan" folder-name t nil
1272 mh-interpret-number-as-range-flag
))))
1273 (let ((config (current-window-configuration))
1274 (current-buffer (current-buffer))
1275 (threaded-view-flag mh-show-threads-flag
))
1276 (delete-other-windows)
1278 (when (get-buffer folder
)
1280 (setq threaded-view-flag
(memq 'unthread mh-view-ops
))))
1282 (mh-make-folder folder
)
1283 (setq mh-index-data
(car index-data
)
1284 mh-index-msg-checksum-map
(make-hash-table :test
#'equal
)
1285 mh-index-checksum-origin-map
(make-hash-table :test
#'equal
))
1286 (mh-index-update-maps folder
(cadr index-data
))
1287 (mh-index-create-sequences))
1288 (mh-scan-folder folder
(or range
"all"))
1289 (cond ((and threaded-view-flag
1291 (goto-char (point-min))
1292 (or (null mh-large-folder
)
1293 (not (equal (forward-line (1+ mh-large-folder
)) 0))
1294 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
1296 (mh-toggle-threads))
1298 (mh-index-insert-folder-headers)))
1299 (unless (eq current-buffer
(current-buffer))
1300 (setq mh-previous-window-config config
)))
1304 (defun mh-update-sequences ()
1305 "Flush MH-E's state out to MH.
1306 This function updates the sequence specified by your \"Unseen-Sequence:\"
1307 profile component, \"cur\", and the sequence listed by the `mh-tick-seq'
1308 option which is \"tick\" by default. The message at the cursor is used for
1311 ;; mh-update-sequences is the opposite of mh-read-folder-sequences,
1312 ;; which updates MH-E's state from MH.
1313 (let ((folder-set (mh-update-unseen))
1314 (new-cur (mh-get-msg-num nil
)))
1316 (let ((seq-entry (mh-find-seq 'cur
)))
1317 (mh-remove-cur-notation)
1319 (list new-cur
)) ;delete-seq-locally, add-msgs-to-seq
1320 (mh-define-sequence 'cur
(list new-cur
))
1322 (if (looking-at mh-scan-good-msg-regexp
)
1326 ;; psg - mh-current-folder is nil if mh-summary-height < 4 !
1327 ;; So I added this sanity check.
1328 (if (stringp mh-current-folder
)
1329 (mh-exec-cmd-quiet t
"folder" mh-current-folder
"-fast")
1330 (mh-exec-cmd-quiet t
"folder" "-fast")))))))
1334 ;;; Support routines.
1336 (defun mh-delete-a-msg (msg)
1338 If MSG is nil then the message at point is deleted.
1340 The value of `mh-delete-msg-hook' is a list of functions to be called, with no
1341 arguments, after the message has been deleted."
1344 (mh-goto-msg msg nil t
)
1346 (setq msg
(mh-get-msg-num t
)))
1347 (if (looking-at mh-scan-refiled-msg-regexp
)
1348 (error "Message %d is refiled. Undo refile before deleting" msg
))
1349 (if (looking-at mh-scan-deleted-msg-regexp
)
1351 (mh-set-folder-modified-p t
)
1352 (setq mh-delete-list
(cons msg mh-delete-list
))
1353 (mh-notate nil mh-note-deleted mh-cmd-note
)
1354 (run-hooks 'mh-delete-msg-hook
))))
1356 (defun mh-refile-a-msg (msg folder
)
1357 "Refile MSG in FOLDER.
1358 If MSG is nil then the message at point is refiled.
1360 Folder is a symbol, not a string.
1361 The value of `mh-refile-msg-hook' is a list of functions to be called, with no
1362 arguments, after the message has been refiled."
1365 (mh-goto-msg msg nil t
)
1367 (setq msg
(mh-get-msg-num t
)))
1368 (cond ((looking-at mh-scan-deleted-msg-regexp
)
1369 (error "Message %d is deleted. Undo delete before moving" msg
))
1370 ((looking-at mh-scan-refiled-msg-regexp
)
1372 (format "Message %d already refiled. Copy to %s as well? "
1374 (mh-exec-cmd "refile" (mh-get-msg-num t
) "-link"
1375 "-src" mh-current-folder
1376 (symbol-name folder
))
1377 (message "Message not copied")))
1379 (mh-set-folder-modified-p t
)
1380 (cond ((null (assoc folder mh-refile-list
))
1381 (push (list folder msg
) mh-refile-list
))
1382 ((not (member msg
(cdr (assoc folder mh-refile-list
))))
1383 (push msg
(cdr (assoc folder mh-refile-list
)))))
1384 (mh-notate nil mh-note-refiled mh-cmd-note
)
1385 (run-hooks 'mh-refile-msg-hook
)))))
1387 (defun mh-next-msg (&optional wait-after-complaining-flag
)
1388 "Move backward or forward to the next undeleted message in the buffer.
1389 If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and we are at the
1390 last message, then wait for a second after telling the user that there aren't
1391 any more unread messages."
1392 (if (eq mh-next-direction
'forward
)
1393 (mh-next-undeleted-msg 1 wait-after-complaining-flag
)
1394 (mh-previous-undeleted-msg 1 wait-after-complaining-flag
)))
1396 (defun mh-next-unread-msg (&optional count
)
1397 "Display next unread message.
1399 This command can be given a prefix argument COUNT to specify how many unread
1403 (error "The function mh-next-unread-msg expects positive argument"))
1404 (setq count
(1- count
))
1405 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list
))))
1406 (cur-msg (mh-get-msg-num nil
)))
1407 (cond ((and (not cur-msg
) (not (bobp))
1408 ;; If we are at the end of the buffer back up one line and go
1409 ;; to unread message after that.
1412 (setq cur-msg
(mh-get-msg-num nil
)))
1414 ((or (null unread-sequence
) (not cur-msg
))
1415 ;; No unread message or there aren't any messages in buffer...
1416 (message "No more unread messages"))
1419 (while (and unread-sequence
(>= cur-msg
(car unread-sequence
)))
1420 (setq unread-sequence
(cdr unread-sequence
)))
1422 (setq unread-sequence
(cdr unread-sequence
))
1423 (setq count
(1- count
)))
1424 (not (car unread-sequence
)))
1425 (message "No more unread messages"))
1426 (t (loop for msg in unread-sequence
1427 when
(mh-goto-msg msg t
) return nil
1428 finally
(message "No more unread messages"))))))
1430 (defun mh-set-scan-mode ()
1431 "Display the scan listing buffer, but do not show a message."
1432 (if (get-buffer mh-show-buffer
)
1433 (delete-windows-on mh-show-buffer
))
1435 (force-mode-line-update)
1436 (if mh-recenter-summary-flag
1439 (defun mh-undo-msg (msg)
1440 "Undo the deletion or refile of one MSG.
1441 If MSG is nil then act on the message at point"
1444 (mh-goto-msg msg t t
)
1446 (setq msg
(mh-get-msg-num t
)))
1447 (cond ((memq msg mh-delete-list
)
1448 (setq mh-delete-list
(delq msg mh-delete-list
)))
1450 (dolist (folder-msg-list mh-refile-list
)
1451 (setf (cdr folder-msg-list
) (remove msg
(cdr folder-msg-list
))))
1452 (setq mh-refile-list
(loop for x in mh-refile-list
1453 unless
(null (cdr x
)) collect x
))))
1454 (mh-notate nil ? mh-cmd-note
)))
1458 ;;; The folder data abstraction.
1460 (defvar mh-index-data-file
".mhe_index"
1461 "MH-E specific file where index seach info is stored.")
1463 (defun mh-make-folder (name)
1464 "Create a new mail folder called NAME.
1465 Make it the current folder."
1466 (switch-to-buffer name
)
1467 (setq buffer-read-only nil
)
1469 (if mh-adaptive-cmd-note-flag
1470 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width name
))))
1471 (setq buffer-read-only t
)
1473 (mh-set-folder-modified-p nil
)
1474 (setq buffer-file-name mh-folder-filename
)
1475 (when (and (not mh-index-data
)
1476 (file-exists-p (concat buffer-file-name mh-index-data-file
)))
1477 (mh-index-read-data))
1478 (mh-make-folder-mode-line))
1480 ;;; Ensure new buffers won't get this mode if default-major-mode is nil.
1481 (put 'mh-folder-mode
'mode-class
'special
)
1485 ;;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
1486 ;;; Menus for folder mode: folder, message, sequence (in that order)
1487 ;;; folder-mode "Sequence" menu
1489 mh-folder-sequence-menu mh-folder-mode-map
"Menu for MH-E folder-sequence."
1491 ["Add Message to Sequence..." mh-put-msg-in-seq
(mh-get-msg-num nil
)]
1492 ["List Sequences for Message" mh-msg-is-in-seq
(mh-get-msg-num nil
)]
1493 ["Delete Message from Sequence..." mh-delete-msg-from-seq
1494 (mh-get-msg-num nil
)]
1495 ["List Sequences in Folder..." mh-list-sequences t
]
1496 ["Delete Sequence..." mh-delete-seq t
]
1497 ["Narrow to Sequence..." mh-narrow-to-seq t
]
1498 ["Widen from Sequence" mh-widen mh-folder-view-stack
]
1500 ["Narrow to Subject Sequence" mh-narrow-to-subject t
]
1501 ["Narrow to Tick Sequence" mh-narrow-to-tick
1502 (and mh-tick-seq
(mh-seq-msgs (mh-find-seq mh-tick-seq
)))]
1503 ["Delete Rest of Same Subject" mh-delete-subject t
]
1504 ["Toggle Tick Mark" mh-toggle-tick t
]
1506 ["Push State Out to MH" mh-update-sequences t
]))
1508 ;;; folder-mode "Message" menu
1510 mh-folder-message-menu mh-folder-mode-map
"Menu for MH-E folder-message."
1512 ["Show Message" mh-show
(mh-get-msg-num nil
)]
1513 ["Show Message with Header" mh-header-display
(mh-get-msg-num nil
)]
1514 ["Next Message" mh-next-undeleted-msg t
]
1515 ["Previous Message" mh-previous-undeleted-msg t
]
1516 ["Go to First Message" mh-first-msg t
]
1517 ["Go to Last Message" mh-last-msg t
]
1518 ["Go to Message by Number..." mh-goto-msg t
]
1519 ["Modify Message" mh-modify t
]
1520 ["Delete Message" mh-delete-msg
(mh-get-msg-num nil
)]
1521 ["Refile Message" mh-refile-msg
(mh-get-msg-num nil
)]
1522 ["Undo Delete/Refile" mh-undo
(mh-outstanding-commands-p)]
1523 ["Execute Delete/Refile" mh-execute-commands
1524 (mh-outstanding-commands-p)]
1526 ["Compose a New Message" mh-send t
]
1527 ["Reply to Message..." mh-reply
(mh-get-msg-num nil
)]
1528 ["Forward Message..." mh-forward
(mh-get-msg-num nil
)]
1529 ["Redistribute Message..." mh-redistribute
(mh-get-msg-num nil
)]
1530 ["Edit Message Again" mh-edit-again
(mh-get-msg-num nil
)]
1531 ["Re-edit a Bounced Message" mh-extract-rejected-mail t
]
1533 ["Copy Message to Folder..." mh-copy-msg
(mh-get-msg-num nil
)]
1534 ["Print Message" mh-print-msg
(mh-get-msg-num nil
)]
1535 ["Write Message to File..." mh-write-msg-to-file
1536 (mh-get-msg-num nil
)]
1537 ["Pipe Message to Command..." mh-pipe-msg
(mh-get-msg-num nil
)]
1538 ["Unpack Uuencoded Message..." mh-store-msg
(mh-get-msg-num nil
)]
1539 ["Burst Digest Message" mh-burst-digest
(mh-get-msg-num nil
)]))
1541 ;;; folder-mode "Folder" menu
1543 mh-folder-folder-menu mh-folder-mode-map
"Menu for MH-E folder."
1545 ["Incorporate New Mail" mh-inc-folder t
]
1546 ["Toggle Show/Folder" mh-toggle-showing t
]
1547 ["Execute Delete/Refile" mh-execute-commands
1548 (mh-outstanding-commands-p)]
1549 ["Rescan Folder" mh-rescan-folder t
]
1550 ["Thread Folder" mh-toggle-threads
1551 (not (memq 'unthread mh-view-ops
))]
1552 ["Pack Folder" mh-pack-folder t
]
1553 ["Sort Folder" mh-sort-folder t
]
1555 ["List Folders" mh-list-folders t
]
1556 ["Visit a Folder..." mh-visit-folder t
]
1557 ["View New Messages" mh-index-new-messages t
]
1558 ["Search a Folder..." mh-search-folder t
]
1559 ["Indexed Search..." mh-index-search t
]
1561 ["Quit MH-E" mh-quit t
]))
1565 (defmacro mh-remove-xemacs-horizontal-scrollbar
()
1566 "Get rid of the horizontal scrollbar that XEmacs insists on putting in."
1567 (when mh-xemacs-flag
1568 `(if (and (featurep 'scrollbar
)
1569 (fboundp 'set-specifier
))
1570 (set-specifier horizontal-scrollbar-visible-p nil
1571 (cons (current-buffer) nil
)))))
1573 (defmacro mh-write-file-functions-compat
()
1574 "Return `write-file-functions' if it exists.
1575 Otherwise return `local-write-file-hooks'. This macro exists purely for
1576 compatibility. The former symbol is used in Emacs 21.4 onward while the latter
1577 is used in previous versions and XEmacs."
1578 (if (boundp 'write-file-functions
)
1579 ''write-file-functions
;Emacs 21.4
1580 ''local-write-file-hooks
)) ;<Emacs 21.4, XEmacs
1582 ;; Avoid compiler warnings in non-bleeding edge versions of Emacs.
1584 (defvar tool-bar-mode
)
1585 (defvar tool-bar-map
)
1586 (defvar desktop-save-buffer
)) ;Emacs 21.4
1588 ;; Register mh-folder-mode as supporting which-function-mode...
1589 (load "which-func" t t
)
1590 (when (and (boundp 'which-func-modes
)
1591 (not (member 'mh-folder-mode which-func-modes
)))
1592 (push 'mh-folder-mode which-func-modes
))
1594 (defvar mh-folder-buttons-init-flag nil
)
1596 ;; Autoload cookie needed by desktop.el
1598 (define-derived-mode mh-folder-mode fundamental-mode
"MH-Folder"
1599 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
1601 You can show the message the cursor is pointing to, and step through the
1602 messages. Messages can be marked for deletion or refiling into another
1603 folder; these commands are executed all at once with a separate command.
1605 Options that control this mode can be changed with \\[customize-group];
1606 specify the \"mh\" group. In particular, please see the `mh-scan-format-file'
1607 option if you wish to modify scan's format.
1609 When a folder is visited, the hook `mh-folder-mode-hook' is run.
1613 Many commands that operate on individual messages, such as `mh-forward' or
1614 `mh-refile-msg' take a RANGE argument. This argument can be used in several
1617 If you provide the prefix argument (\\[universal-argument]) to these commands,
1618 then you will be prompted for the message range. This can be any valid MH
1619 range which can include messages, sequences, and the abbreviations (described
1620 in the mh(1) man page):
1623 Indicates all messages in the range <num1> to <num2>, inclusive. The range
1629 Up to N messages beginning with (or ending with) message num. Num may be
1630 any of the predefined symbols: first, prev, cur, next or last.
1636 The first, previous, next or last messages, if they exist.
1639 All of the messages.
1641 For example, a range that shows all of these things is `1 2 3 5-10 last:5
1644 If the option `transient-mark-mode' is set to t and you set a region in the
1645 MH-Folder buffer, then the MH-E command will perform the operation on all
1646 messages in that region.
1648 \\{mh-folder-mode-map}"
1650 (unless mh-folder-buttons-init-flag
1651 (mh-tool-bar-folder-buttons-init)
1652 (setq mh-folder-buttons-init-flag t
)))
1653 (make-local-variable 'font-lock-defaults
)
1654 (setq font-lock-defaults
'(mh-folder-font-lock-keywords t
))
1655 (make-local-variable 'desktop-save-buffer
)
1656 (setq desktop-save-buffer t
)
1658 'mh-colors-available-flag
(mh-colors-available-p)
1659 ; Do we have colors available
1660 'mh-current-folder
(buffer-name) ; Name of folder, a string
1661 'mh-show-buffer
(format "show-%s" (buffer-name)) ; Buffer that displays msgs
1662 'mh-folder-filename
; e.g. "/usr/foobar/Mail/inbox/"
1663 (file-name-as-directory (mh-expand-file-name (buffer-name)))
1664 'mh-display-buttons-for-inline-parts-flag
1665 mh-display-buttons-for-inline-parts-flag
; Allow for display of buttons to
1667 'mh-arrow-marker
(make-marker) ; Marker where arrow is displayed
1668 'overlay-arrow-position nil
; Allow for simultaneous display in
1669 'overlay-arrow-string
">" ; different MH-E buffers.
1670 'mh-showing-mode nil
; Show message also?
1671 'mh-delete-list nil
; List of msgs nums to delete
1672 'mh-refile-list nil
; List of folder names in mh-seq-list
1673 'mh-seq-list nil
; Alist of (seq . msgs) nums
1674 'mh-seen-list nil
; List of displayed messages
1675 'mh-next-direction
'forward
; Direction to move to next message
1676 'mh-view-ops
() ; Stack that keeps track of the order
1677 ; in which narrowing/threading has been
1679 'mh-folder-view-stack
() ; Stack of previous views of the
1681 'mh-index-data nil
; If the folder was created by a call
1682 ; to mh-index-search this contains info
1683 ; about the search results.
1684 'mh-index-previous-search nil
; Previous folder and search-regexp
1685 'mh-index-msg-checksum-map nil
; msg -> checksum map
1686 'mh-index-checksum-origin-map nil
; checksum -> ( orig-folder, orig-msg )
1687 'mh-index-sequence-search-flag nil
; folder resulted from sequence search
1688 'mh-first-msg-num nil
; Number of first msg in buffer
1689 'mh-last-msg-num nil
; Number of last msg in buffer
1690 'mh-msg-count nil
; Number of msgs in buffer
1691 'mh-mode-line-annotation nil
; Indicates message range
1692 'mh-sequence-notation-history
(make-hash-table)
1693 ; Remember what is overwritten by
1695 'imenu-create-index-function
'mh-index-create-imenu-index
1696 ; Setup imenu support
1697 'mh-previous-window-config nil
) ; Previous window configuration
1698 (mh-remove-xemacs-horizontal-scrollbar)
1699 (setq truncate-lines t
)
1701 (setq buffer-offer-save t
)
1702 (mh-make-local-hook (mh-write-file-functions-compat))
1703 (add-hook (mh-write-file-functions-compat) 'mh-execute-commands nil t
)
1704 (make-local-variable 'revert-buffer-function
)
1705 (make-local-variable 'hl-line-mode
) ; avoid pollution
1706 (mh-funcall-if-exists hl-line-mode
1)
1707 (setq revert-buffer-function
'mh-undo-folder
)
1708 (or (assq 'mh-showing-mode minor-mode-alist
)
1709 (setq minor-mode-alist
1710 (cons '(mh-showing-mode " Show") minor-mode-alist
)))
1711 (easy-menu-add mh-folder-sequence-menu
)
1712 (easy-menu-add mh-folder-message-menu
)
1713 (easy-menu-add mh-folder-folder-menu
)
1714 (set (make-local-variable 'tool-bar-map
) mh-folder-tool-bar-map
)
1715 (mh-funcall-if-exists mh-toolbar-init
:folder
)
1716 (if (and mh-xemacs-flag
1717 font-lock-auto-fontify
)
1718 (turn-on-font-lock))) ; Force font-lock in XEmacs.
1720 (defun mh-toggle-mime-buttons ()
1721 "Toggle option `mh-display-buttons-for-inline-parts-flag'."
1723 (setq mh-display-buttons-for-inline-parts-flag
1724 (not mh-display-buttons-for-inline-parts-flag
))
1727 (defun mh-colors-available-p ()
1728 "Check if colors are available in the Emacs being used."
1731 (or (ignore-errors (mh-funcall-if-exists display-color-cells
))
1732 (ignore-errors (mh-funcall-if-exists
1733 x-display-color-cells
)))))
1734 (and (numberp color-cells
) (>= color-cells
8)))))
1736 (defun mh-colors-in-use-p ()
1737 "Check if colors are being used in the folder buffer."
1738 (and mh-colors-available-flag font-lock-mode
))
1740 (defun mh-make-local-vars (&rest pairs
)
1741 "Initialize local variables according to the variable-value PAIRS."
1744 (set (make-local-variable (car pairs
)) (car (cdr pairs
)))
1745 (setq pairs
(cdr (cdr pairs
)))))
1747 (defun mh-restore-desktop-buffer (desktop-buffer-file-name
1749 desktop-buffer-misc
)
1750 "Restore an MH folder buffer specified in a desktop file.
1751 When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the file name to
1752 visit, DESKTOP-BUFFER-NAME holds the desired buffer name, and
1753 DESKTOP-BUFFER-MISC holds a list of miscellaneous info used by the
1754 `desktop-buffer-handlers' functions."
1756 (mh-visit-folder desktop-buffer-name
)
1759 ;;; desktop-buffer-mode-handlers appeared in Emacs 22.
1760 (if (fboundp 'desktop-buffer-mode-handlers
)
1761 (add-to-list 'desktop-buffer-mode-handlers
1762 '(mh-folder-mode . mh-restore-desktop-buffer
)))
1764 (defun mh-scan-folder (folder range
&optional dont-exec-pending
)
1765 "Scan the FOLDER over the RANGE.
1766 If the optional argument DONT-EXEC-PENDING is non-nil then pending deletes and
1767 refiles aren't carried out.
1768 Return in the folder's buffer."
1769 (when (stringp range
)
1770 (setq range
(delete "" (split-string range
"[ \t\n]"))))
1771 (cond ((null (get-buffer folder
))
1772 (mh-make-folder folder
))
1774 (unless dont-exec-pending
1775 (mh-process-or-undo-commands folder
)
1776 (mh-reset-threads-and-narrowing))
1777 (switch-to-buffer folder
)))
1778 (mh-regenerate-headers range
)
1779 (if (zerop (buffer-size))
1780 (if (equal range
"all")
1781 (message "Folder %s is empty" folder
)
1782 (message "No messages in %s, range %s" folder range
))
1784 (when (mh-outstanding-commands-p)
1785 (mh-notate-deleted-and-refiled)))
1787 (defun mh-msg-num-width-to-column (width)
1788 "Return the column for notations given message number WIDTH.
1789 Note that columns in Emacs start with 0.
1791 If `mh-scan-format-file' is set to \"Use MH-E scan Format\" this means that
1792 either `mh-scan-format-mh' or `mh-scan-format-nmh' are in use. This function
1793 therefore assumes that the first column is empty (to provide room for the
1794 cursor), the following WIDTH columns contain the message number, and the
1795 column for notations comes after that."
1796 (if (eq mh-scan-format-file t
)
1798 (error "%s %s" "Can't call mh-msg-num-width-to-column"
1799 "when mh-scan-format-file is not t")))
1801 (defun mh-set-cmd-note (column)
1802 "Set `mh-cmd-note' to COLUMN.
1803 Note that columns in Emacs start with 0."
1804 (setq mh-cmd-note column
))
1806 (defun mh-regenerate-headers (range &optional update
)
1807 "Scan folder over range RANGE.
1808 If UPDATE, append the scan lines, otherwise replace."
1809 (let ((folder mh-current-folder
)
1810 (range (if (and range
(atom range
)) (list range
) range
))
1812 (message "Scanning %s..." folder
)
1813 (mh-remove-all-notation)
1814 (with-mh-folder-updating (nil)
1816 (goto-char (point-max))
1817 (delete-region (point-min) (point-max))
1818 (if mh-adaptive-cmd-note-flag
1819 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width
1821 (setq scan-start
(point))
1822 (apply #'mh-exec-cmd-output
1825 "-noclear" "-noheader"
1826 "-width" (window-width)
1828 (goto-char scan-start
)
1829 (cond ((looking-at "scan: no messages in")
1830 (keep-lines mh-scan-valid-regexp
)) ; Flush random scan lines
1831 ((looking-at (if (mh-variant-p 'mu-mh
)
1832 "scan: message set .* does not exist"
1833 "scan: bad message list "))
1834 (keep-lines mh-scan-valid-regexp
))
1835 ((looking-at "scan: ")) ; Keep error messages
1837 (keep-lines mh-scan-valid-regexp
))) ; Flush random scan lines
1838 (setq mh-seq-list
(mh-read-folder-sequences folder nil
))
1839 (mh-notate-user-sequences)
1841 (setq mh-mode-line-annotation
1842 (if (equal range
'("all"))
1844 mh-partial-folder-mode-line-annotation
)))
1845 (mh-make-folder-mode-line))
1846 (message "Scanning %s...done" folder
)))
1848 (defun mh-generate-new-cmd-note (folder)
1849 "Fix the `mh-cmd-note' value for this FOLDER.
1851 After doing an `mh-get-new-mail' operation in this FOLDER, at least
1852 one line that looks like a truncated message number was found.
1854 Remove the text added by the last `mh-inc' command. It should be the messages
1855 cur-last. Call `mh-set-cmd-note', adjusting the notation column with the width
1856 of the largest message number in FOLDER.
1858 Reformat the message number width on each line in the buffer and trim
1859 the line length to fit in the window.
1861 Rescan the FOLDER in the range cur-last in order to display the
1862 messages that were removed earlier. They should all fit in the scan
1863 line now with no message truncation."
1865 (let ((maxcol (1- (window-width)))
1866 (old-cmd-note mh-cmd-note
)
1869 ;; Nuke all of the lines just added by the last inc
1870 (delete-char (- (point-max) (point)))
1871 ;; Update the current buffer to reflect the new mh-cmd-note
1872 ;; value needed to display messages.
1873 (mh-set-cmd-note (mh-msg-num-width-to-column (mh-msg-num-width folder
)))
1874 (setq mh-cmd-note-fmt
(concat "%" (format "%d" mh-cmd-note
) "d"))
1875 ;; Cleanup the messages that are in the buffer right now
1876 (goto-char (point-min))
1877 (cond ((memq 'unthread mh-view-ops
)
1878 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note
)))
1879 (t (while (re-search-forward mh-scan-msg-number-regexp nil
0 1)
1880 ;; reformat the number to fix in mh-cmd-note columns
1881 (setq msgnum
(string-to-number
1883 (match-beginning 1) (match-end 1))))
1884 (replace-match (format mh-cmd-note-fmt msgnum
))
1885 ;; trim the line to fix in the window
1887 (let ((eol (point)))
1888 (move-to-column maxcol
)
1889 (if (<= (point) eol
)
1890 (delete-char (- eol
(point))))))))
1891 ;; now re-read the lost messages
1892 (goto-char (point-max))
1894 (mh-regenerate-headers "cur-last" t
)))))
1896 (defun mh-get-new-mail (maildrop-name)
1897 "Read new mail from MAILDROP-NAME into the current buffer.
1898 Return in the current buffer."
1899 (let ((point-before-inc (point))
1900 (folder mh-current-folder
)
1901 (new-mail-flag nil
))
1902 (with-mh-folder-updating (t)
1904 (message "inc %s -file %s..." folder maildrop-name
)
1905 (message "inc %s..." folder
))
1906 (setq mh-next-direction
'forward
)
1907 (goto-char (point-max))
1908 (mh-remove-cur-notation)
1909 (let ((start-of-inc (point)))
1911 ;; I think MH 5 used "-ms-file" instead of "-file",
1912 ;; which would make inc'ing from maildrops fail.
1913 (mh-exec-cmd-output mh-inc-prog nil folder
1915 "-file" (expand-file-name maildrop-name
)
1916 "-width" (window-width)
1918 (mh-exec-cmd-output mh-inc-prog nil
1920 "-width" (window-width)))
1922 (message "inc %s -file %s...done" folder maildrop-name
)
1923 (message "inc %s...done" folder
))
1924 (goto-char start-of-inc
)
1925 (cond ((save-excursion
1926 (re-search-forward "^inc: no mail" nil t
))
1927 (message "No new mail%s%s" (if maildrop-name
" in " "")
1928 (if maildrop-name maildrop-name
"")))
1929 ((and (when mh-folder-view-stack
1930 (let ((saved-text (buffer-substring-no-properties
1931 start-of-inc
(point-max))))
1932 (delete-region start-of-inc
(point-max))
1933 (unwind-protect (mh-widen t
)
1934 (mh-remove-cur-notation)
1935 (goto-char (point-max))
1936 (setq start-of-inc
(point))
1938 (goto-char start-of-inc
))))
1940 ((re-search-forward "^inc:" nil t
) ; Error messages
1941 (error "Error incorporating mail"))
1943 (equal mh-scan-format-file t
)
1944 mh-adaptive-cmd-note-flag
1945 ;; Have we reached an edge condition?
1947 (re-search-forward mh-scan-msg-overflow-regexp nil
0 1))
1948 (setq start-of-inc
(mh-generate-new-cmd-note folder
))
1951 (setq new-mail-flag t
)))
1952 (keep-lines mh-scan-valid-regexp
) ; Flush random scan lines
1953 (let* ((sequences (mh-read-folder-sequences folder t
))
1954 (new-cur (assoc 'cur sequences
))
1955 (new-unseen (assoc mh-unseen-seq sequences
)))
1956 (unless (assoc 'cur mh-seq-list
)
1957 (push (list 'cur
) mh-seq-list
))
1958 (unless (assoc mh-unseen-seq mh-seq-list
)
1959 (push (list mh-unseen-seq
) mh-seq-list
))
1960 (setcdr (assoc 'cur mh-seq-list
) (cdr new-cur
))
1961 (setcdr (assoc mh-unseen-seq mh-seq-list
) (cdr new-unseen
)))
1962 (when (equal (point-max) start-of-inc
)
1966 (mh-make-folder-mode-line)
1967 (when (mh-speed-flists-active-p)
1968 (mh-speed-flists t mh-current-folder
))
1969 (when (memq 'unthread mh-view-ops
)
1970 (mh-thread-inc folder start-of-inc
))
1972 (goto-char point-before-inc
))
1973 (mh-notate-user-sequences (cons start-of-inc
(point-max)))))))
1975 (defun mh-make-folder-mode-line (&optional ignored
)
1976 "Set the fields of the mode line for a folder buffer.
1977 The optional argument is now obsolete and IGNORED. It used to be used to pass
1978 in what is now stored in the buffer-local variable `mh-mode-line-annotation'."
1980 (save-window-excursion
1982 (let ((new-first-msg-num (mh-get-msg-num nil
)))
1983 (when (or (not (memq 'unthread mh-view-ops
))
1984 (null mh-first-msg-num
)
1985 (null new-first-msg-num
)
1986 (< new-first-msg-num mh-first-msg-num
))
1987 (setq mh-first-msg-num new-first-msg-num
)))
1989 (let ((new-last-msg-num (mh-get-msg-num nil
)))
1990 (when (or (not (memq 'unthread mh-view-ops
))
1991 (null mh-last-msg-num
)
1992 (null new-last-msg-num
)
1993 (> new-last-msg-num mh-last-msg-num
))
1994 (setq mh-last-msg-num new-last-msg-num
)))
1995 (setq mh-msg-count
(if mh-first-msg-num
1996 (count-lines (point-min) (point-max))
1998 (setq mode-line-buffer-identification
1999 (list (format " {%%b%s} %s msg%s"
2000 (if mh-mode-line-annotation
2001 (format "/%s" mh-mode-line-annotation
)
2003 (if (zerop mh-msg-count
)
2005 (format "%d" mh-msg-count
))
2006 (if (zerop mh-msg-count
)
2008 (cond ((> mh-msg-count
1)
2009 (format "s (%d-%d)" mh-first-msg-num
2012 (format " (%d)" mh-first-msg-num
))
2014 (mh-logo-display))))
2016 (defun mh-add-sequence-notation (msg internal-seq-flag
)
2017 "Add sequence notation to the MSG on the current line.
2018 If INTERNAL-SEQ-FLAG is non-nil, then refontify the scan line if font-lock is
2020 (with-mh-folder-updating (t)
2023 (if internal-seq-flag
2025 ;; Change the buffer so that if transient-mark-mode is active
2026 ;; and there is an active region it will get deactivated as in
2027 ;; the case of user sequences.
2028 (mh-notate nil nil mh-cmd-note
)
2029 (when font-lock-mode
2030 (font-lock-fontify-region (point) (line-end-position))))
2031 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset
))
2032 (let ((stack (gethash msg mh-sequence-notation-history
)))
2033 (setf (gethash msg mh-sequence-notation-history
)
2034 (cons (char-after) stack
)))
2035 (mh-notate nil mh-note-seq
2036 (+ mh-cmd-note mh-scan-field-destination-offset
))))))
2038 (defun mh-remove-sequence-notation (msg internal-seq-flag
&optional all
)
2039 "Remove sequence notation from the MSG on the current line.
2040 If INTERNAL-SEQ-FLAG is non-nil, then `font-lock' was used to highlight the
2041 sequence. In that case, no notation needs to be removed. Otherwise the effect
2042 of inserting `mh-note-seq' needs to be reversed.
2043 If ALL is non-nil, then all sequence marks on the scan line are removed."
2044 (with-mh-folder-updating (t)
2045 ;; This takes care of internal sequences...
2046 (mh-notate nil nil mh-cmd-note
)
2047 (unless internal-seq-flag
2048 ;; ... and this takes care of user sequences.
2049 (let ((stack (gethash msg mh-sequence-notation-history
)))
2050 (while (and all
(cdr stack
))
2051 (setq stack
(cdr stack
)))
2055 (forward-char (+ mh-cmd-note mh-scan-field-destination-offset
))
2057 (insert (car stack
))))
2058 (setf (gethash msg mh-sequence-notation-history
) (cdr stack
))))))
2060 (defun mh-remove-cur-notation ()
2061 "Remove old cur notation."
2062 (let ((cur-msg (car (mh-seq-to-msgs 'cur
))))
2065 (mh-goto-msg cur-msg t t
)
2066 (looking-at mh-scan-cur-msg-number-regexp
))
2067 (mh-notate nil ? mh-cmd-note
)
2068 (setq overlay-arrow-position nil
)))))
2070 (defun mh-remove-all-notation ()
2071 "Remove all notations on all scan lines that MH-E introduces."
2073 (setq overlay-arrow-position nil
)
2074 (goto-char (point-min))
2075 (mh-iterate-on-range msg
(cons (point-min) (point-max))
2076 (mh-notate nil ? mh-cmd-note
)
2077 (mh-remove-sequence-notation msg nil t
))
2078 (clrhash mh-sequence-notation-history
)))
2081 (defun mh-goto-cur-msg (&optional minimal-changes-flag
)
2082 "Position the cursor at the current message.
2083 When optional argument MINIMAL-CHANGES-FLAG is non-nil, the function doesn't
2084 recenter the folder buffer."
2085 (let ((cur-msg (car (mh-seq-to-msgs 'cur
))))
2087 (mh-goto-msg cur-msg t t
))
2088 (unless minimal-changes-flag
2091 (mh-maybe-show cur-msg
)))
2093 (setq overlay-arrow-position nil
)
2094 (message "No current message")))))
2096 (defun mh-process-or-undo-commands (folder)
2097 "If FOLDER has outstanding commands, then either process or discard them.
2098 Called by functions like `mh-sort-folder', so also invalidate show buffer."
2100 (if (mh-outstanding-commands-p)
2101 (if (or mh-do-not-confirm-flag
2103 "Process outstanding deletes and refiles? "))
2104 (mh-process-commands folder
)
2108 (mh-invalidate-show-buffer))
2110 (defun mh-process-commands (folder)
2111 "Process outstanding commands for FOLDER.
2112 The value of `mh-folder-updated-hook' is a list of functions to be called,
2113 with no arguments, before the commands are processed."
2114 (message "Processing deletes and refiles for %s..." folder
)
2116 (with-mh-folder-updating (nil)
2117 ;; Run the hook while the lists are still valid
2118 (run-hooks 'mh-folder-updated-hook
)
2120 ;; Update the unseen sequence if it exists
2123 (let ((redraw-needed-flag mh-index-data
)
2124 (folders-changed (list mh-current-folder
))
2125 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag
2126 (mh-create-sequence-map mh-seq-list
)))
2127 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag
2128 (make-hash-table))))
2129 ;; Remove invalid scan lines if we are in an index folder and then remove
2130 ;; the real messages
2132 (mh-index-delete-folder-headers)
2133 (setq folders-changed
2134 (append folders-changed
(mh-index-execute-commands))))
2136 ;; Then refile messages
2137 (mh-mapc #'(lambda (folder-msg-list)
2138 (let* ((dest-folder (symbol-name (car folder-msg-list
)))
2139 (last (car (mh-translate-range dest-folder
"last")))
2140 (msgs (cdr folder-msg-list
)))
2141 (push dest-folder folders-changed
)
2142 (setq redraw-needed-flag t
)
2143 (apply #'mh-exec-cmd
2144 "refile" "-src" folder dest-folder
2145 (mh-coalesce-msg-list msgs
))
2146 (mh-delete-scan-msgs msgs
)
2147 ;; Preserve sequences in destination folder...
2148 (when mh-refile-preserves-sequences-flag
2150 (loop for i from
(1+ (or last
0))
2151 for msg in
(sort (copy-sequence msgs
) #'<)
2152 do
(loop for seq-name in
(gethash msg seq-map
)
2153 do
(push i
(gethash seq-name dest-map
))))
2155 #'(lambda (seq msgs
)
2156 ;; Can't be run in the background, since the
2157 ;; current folder is changed by mark this could
2158 ;; lead to a race condition with the next refile.
2159 (apply #'mh-exec-cmd
"mark"
2160 "-sequence" (symbol-name seq
) dest-folder
2161 "-add" (mapcar #'(lambda (x) (format "%s" x
))
2162 (mh-coalesce-msg-list msgs
))))
2165 (setq mh-refile-list
())
2167 ;; Now delete messages
2168 (cond (mh-delete-list
2169 (setq redraw-needed-flag t
)
2170 (apply 'mh-exec-cmd
"rmm" folder
2171 (mh-coalesce-msg-list mh-delete-list
))
2172 (mh-delete-scan-msgs mh-delete-list
)
2173 (setq mh-delete-list nil
)))
2175 ;; Don't need to remove sequences since delete and refile do so.
2177 (if (> (buffer-size) 0)
2178 (mh-define-sequence 'cur
(list (or (mh-get-msg-num nil
) "last"))))
2180 ;; Redraw folder buffer if needed
2181 (when (and redraw-needed-flag
)
2182 (when (mh-speed-flists-active-p)
2183 (apply #'mh-speed-flists t folders-changed
))
2184 (cond ((memq 'unthread mh-view-ops
) (mh-thread-inc folder
(point-max)))
2185 (mh-index-data (mh-index-insert-folder-headers)))))
2187 (and (buffer-file-name (get-buffer mh-show-buffer
))
2188 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer
))))
2189 ;; If "inc" were to put a new msg in this file,
2190 ;; we would not notice, so mark it invalid now.
2191 (mh-invalidate-show-buffer))
2193 (setq mh-seq-list
(mh-read-folder-sequences mh-current-folder nil
))
2194 (mh-remove-all-notation)
2195 (mh-notate-user-sequences)
2196 (message "Processing deletes and refiles for %s...done" folder
)))
2198 (defun mh-update-unseen ()
2199 "Synchronize the unseen sequence with MH.
2200 Return non-nil iff the MH folder was set.
2201 The value of `mh-unseen-updated-hook' is a list of functions to be called,
2202 with no arguments, after the unseen sequence is updated."
2204 (let* ((unseen-seq (mh-find-seq mh-unseen-seq
))
2205 (unseen-msgs (mh-seq-msgs unseen-seq
)))
2208 (mh-undefine-sequence mh-unseen-seq mh-seen-list
)
2209 (run-hooks 'mh-unseen-updated-hook
)
2211 (setq unseen-msgs
(delq (car mh-seen-list
) unseen-msgs
))
2212 (setq mh-seen-list
(cdr mh-seen-list
)))
2213 (setcdr unseen-seq unseen-msgs
)
2214 t
) ;since we set the folder
2215 (setq mh-seen-list nil
)))))
2217 (defun mh-delete-scan-msgs (msgs)
2218 "Delete the scan listing lines for MSGS."
2221 (when (mh-goto-msg (car msgs
) t t
)
2222 (when (memq 'unthread mh-view-ops
)
2223 (mh-thread-forget-message (car msgs
)))
2225 (setq msgs
(cdr msgs
)))))
2227 (defun mh-outstanding-commands-p ()
2228 "Return non-nil if there are outstanding deletes or refiles."
2230 (when (eq major-mode
'mh-show-mode
)
2231 (set-buffer mh-show-folder-buffer
))
2232 (or mh-delete-list mh-refile-list
)))
2234 (defun mh-coalesce-msg-list (messages)
2235 "Given a list of MESSAGES, return a list of message number ranges.
2236 This is the inverse of `mh-read-msg-list', which expands ranges.
2237 Message lists passed to MH programs should be processed by this function
2238 to avoid exceeding system command line argument limits."
2239 (let ((msgs (sort (copy-sequence messages
) 'mh-greaterp
))
2245 (if (or (not (numberp prev
))
2246 (not (equal (car msgs
) (1- prev
))))
2247 (progn ;non-sequential, flush old range
2248 (if (eq prev range-high
)
2249 (setq ranges
(cons range-high ranges
))
2250 (setq ranges
(cons (format "%s-%s" prev range-high
) ranges
)))
2251 (setq range-high nil
))))
2253 (setq range-high
(car msgs
))) ;start new or first range
2254 (setq prev
(car msgs
))
2255 (setq msgs
(cdr msgs
)))
2258 (defun mh-greaterp (msg1 msg2
)
2259 "Return the greater of two message indicators MSG1 and MSG2.
2260 Strings are \"smaller\" than numbers.
2261 Valid values are things like \"cur\", \"last\", 1, and 1820."
2268 (string-lessp msg2 msg1
))))
2270 (defun mh-lessp (msg1 msg2
)
2271 "Return the lesser of two message indicators MSG1 and MSG2.
2272 Strings are \"smaller\" than numbers.
2273 Valid values are things like \"cur\", \"last\", 1, and 1820."
2274 (not (mh-greaterp msg1 msg2
)))
2278 ;;; Basic sequence handling
2280 (defun mh-delete-seq-locally (seq)
2281 "Remove MH-E's record of SEQ."
2282 (let ((entry (mh-find-seq seq
)))
2283 (setq mh-seq-list
(delq entry mh-seq-list
))))
2285 (defun mh-read-folder-sequences (folder save-refiles
)
2286 "Read and return the predefined sequences for a FOLDER.
2287 If SAVE-REFILES is non-nil, then keep the sequences
2288 that note messages to be refiled."
2291 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
2292 (if (mh-folder-name-p (mh-seq-name seq
))
2293 (setq seqs
(cons seq seqs
)))))
2296 (if (eq 0 (mh-exec-cmd-quiet nil
"mark" folder
"-list"))
2298 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
2299 (while (re-search-forward "^[^: ]+" nil t
)
2300 (setq seqs
(cons (mh-make-seq (intern (buffer-substring
2305 (delete-region (point-min) (point))))) ; avoid race with
2309 (defun mh-read-msg-list ()
2310 "Return a list of message numbers from point to the end of the line.
2311 Expands ranges into set of individual numbers."
2313 (end-of-line (save-excursion (end-of-line) (point)))
2315 (while (re-search-forward "[0-9]+" end-of-line t
)
2316 (setq num
(string-to-number (buffer-substring (match-beginning 0)
2318 (cond ((looking-at "-") ; Message range
2320 (re-search-forward "[0-9]+" end-of-line t
)
2321 (let ((num2 (string-to-number
2322 (buffer-substring (match-beginning 0)
2325 (error "Bad message range: %d-%d" num num2
))
2326 (while (<= num num2
)
2327 (setq msgs
(cons num msgs
))
2328 (setq num
(1+ num
)))))
2329 ((not (zerop num
)) ;"pick" outputs "0" to mean no match
2330 (setq msgs
(cons num msgs
)))))
2333 (defun mh-notate-user-sequences (&optional range
)
2334 "Mark user-defined sequences in the messages specified by RANGE.
2335 The optional argument RANGE can be a message number, a list of message
2336 numbers, a sequence, a region in a cons cell. If nil all messages are notated."
2338 (setq range
(cons (point-min) (point-max))))
2339 (let ((seqs mh-seq-list
)
2340 (msg-hash (make-hash-table)))
2342 (dolist (msg (mh-seq-msgs seq
))
2343 (push (car seq
) (gethash msg msg-hash
))))
2344 (mh-iterate-on-range msg range
2345 (loop for seq in
(gethash msg msg-hash
)
2346 do
(mh-add-sequence-notation msg
(mh-internal-seq seq
))))))
2348 (defvar mh-internal-seqs
'(answered cur deleted forwarded printed
))
2350 (defun mh-internal-seq (name)
2351 "Return non-nil if NAME is the name of an internal MH-E sequence."
2352 (or (memq name mh-internal-seqs
)
2353 (eq name mh-unseen-seq
)
2354 (and (mh-colors-in-use-p) mh-tick-seq
(eq name mh-tick-seq
))
2355 (eq name mh-previous-seq
)
2356 (mh-folder-name-p name
)))
2358 (defun mh-valid-seq-p (name)
2359 "Return non-nil if NAME is a valid MH sequence name."
2361 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" (symbol-name name
))))
2363 (defun mh-delete-msg-from-seq (range sequence
&optional internal-flag
)
2364 "Delete RANGE from SEQUENCE.
2366 Check the documentation of `mh-interactive-range' to see how RANGE is read in
2369 Optional third arg INTERNAL-FLAG non-nil means do not inform MH of the
2371 (interactive (list (mh-interactive-range "Delete")
2372 (mh-read-seq-default "Delete from" t
)
2374 (let ((entry (mh-find-seq sequence
))
2375 (user-sequence-flag (not (mh-internal-seq sequence
)))
2376 (folders-changed (list mh-current-folder
))
2379 (mh-iterate-on-range msg range
2381 ;; Calling "mark" repeatedly takes too long. So we will pretend here
2382 ;; that we are just modifying an internal sequence...
2383 (when (memq msg
(cdr entry
))
2384 (mh-remove-sequence-notation msg
(not user-sequence-flag
)))
2385 (mh-delete-a-msg-from-seq msg sequence t
))
2386 ;; ... and here we will "mark" all the messages at one go.
2387 (unless internal-flag
(mh-undefine-sequence sequence msg-list
))
2388 (when (and mh-index-data
(not internal-flag
))
2389 (setq folders-changed
2390 (append folders-changed
2391 (mh-index-delete-from-sequence sequence msg-list
))))
2392 (when (and (eq sequence mh-unseen-seq
) (mh-speed-flists-active-p))
2393 (apply #'mh-speed-flists t folders-changed
)))))
2395 (defun mh-catchup (range)
2396 "Delete RANGE from the `mh-unseen-seq' sequence.
2398 Check the document of `mh-interactive-range' to see how RANGE is read in
2400 (interactive (list (mh-interactive-range "Catchup"
2401 (cons (point-min) (point-max)))))
2402 (mh-delete-msg-from-seq range mh-unseen-seq
))
2404 (defun mh-delete-a-msg-from-seq (msg sequence internal-flag
)
2405 "Delete MSG from SEQUENCE.
2406 If INTERNAL-FLAG is non-nil, then do not inform MH of the change."
2407 (let ((entry (mh-find-seq sequence
)))
2408 (when (and entry
(memq msg
(mh-seq-msgs entry
)))
2409 (if (not internal-flag
)
2410 (mh-undefine-sequence sequence
(list msg
)))
2411 (setcdr entry
(delq msg
(mh-seq-msgs entry
))))))
2413 (defun mh-undefine-sequence (seq msgs
)
2414 "Remove from the SEQ the list of MSGS."
2415 (when (and (mh-valid-seq-p seq
) msgs
)
2416 (apply #'mh-exec-cmd
"mark" mh-current-folder
"-delete"
2417 "-sequence" (symbol-name seq
) (mh-coalesce-msg-list msgs
))))
2419 (defun mh-define-sequence (seq msgs
)
2420 "Define the SEQ to contain the list of MSGS.
2421 Do not mark pseudo-sequences or empty sequences.
2422 Signals an error if SEQ is an invalid name."
2424 (mh-valid-seq-p seq
)
2425 (not (mh-folder-name-p seq
)))
2427 (mh-exec-cmd-error nil
"mark" mh-current-folder
"-add" "-zero"
2428 "-sequence" (symbol-name seq
)
2429 (mh-coalesce-msg-list msgs
)))))
2431 (defun mh-seq-containing-msg (msg &optional include-internal-flag
)
2432 "Return a list of the sequences containing MSG.
2433 If INCLUDE-INTERNAL-FLAG non-nil, include MH-E internal sequences in list."
2434 (let ((l mh-seq-list
)
2437 (and (memq msg
(mh-seq-msgs (car l
)))
2438 (or include-internal-flag
2439 (not (mh-internal-seq (mh-seq-name (car l
)))))
2440 (setq seqs
(cons (mh-seq-name (car l
)) seqs
)))
2446 ;;; Build the folder-mode keymap:
2448 (suppress-keymap mh-folder-mode-map
)
2450 ;; Use defalias to make sure the documented primary key bindings
2451 ;; appear in menu lists.
2452 (defalias 'mh-alt-show
'mh-show
)
2453 (defalias 'mh-alt-refile-msg
'mh-refile-msg
)
2454 (defalias 'mh-alt-send
'mh-send
)
2455 (defalias 'mh-alt-visit-folder
'mh-visit-folder
)
2457 ;; Save the `b' binding for a future `back'. Maybe?
2458 (gnus-define-keys mh-folder-mode-map
2460 "!" mh-refile-or-write-again
2462 "," mh-header-display
2464 ";" mh-toggle-mh-decode-mime-flag
2465 ">" mh-write-msg-to-file
2467 "E" mh-extract-rejected-mail
2469 "\177" mh-previous-page
2470 "\C-d" mh-delete-msg-no-motion
2471 "\t" mh-index-next-folder
2472 [backtab] mh-index-previous-folder
2473 "\M-\t" mh-index-previous-folder
2476 "\ed" mh-redistribute
2478 "^" mh-alt-refile-msg
2485 "k" mh-delete-subject-or-thread
2487 "n" mh-next-undeleted-msg
2488 "\M-n" mh-next-unread-msg
2490 "p" mh-previous-undeleted-msg
2491 "\M-p" mh-previous-unread-msg
2495 "t" mh-toggle-showing
2497 "v" mh-index-visit-folder
2498 "x" mh-execute-commands
2501 (gnus-define-keys (mh-folder-map "F" mh-folder-mode-map)
2503 "'" mh-index-ticked-messages
2506 "f" mh-alt-visit-folder
2510 "n" mh-index-new-messages
2511 "o" mh-alt-visit-folder
2513 "q" mh-index-sequenced-messages
2514 "r" mh-rescan-folder
2515 "s" mh-search-folder
2517 "v" mh-visit-folder)
2519 (define-key mh-folder-mode-map "I" mh-inc-spool-map)
2521 (gnus-define-keys (mh-junk-map "J" mh-folder-mode-map)
2523 "b" mh-junk-blacklist
2524 "w" mh-junk-whitelist)
2526 (gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map)
2528 "C" mh-ps-print-toggle-color
2529 "F" mh-ps-print-toggle-faces
2530 "f" mh-ps-print-msg-file
2532 "p" mh-ps-print-msg)
2534 (gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map)
2535 "'" mh-narrow-to-tick
2537 "d" mh-delete-msg-from-seq
2539 "l" mh-list-sequences
2540 "n" mh-narrow-to-seq
2541 "p" mh-put-msg-in-seq
2542 "s" mh-msg-is-in-seq
2545 (gnus-define-keys (mh-thread-map "T" mh-folder-mode-map)
2547 "u" mh-thread-ancestor
2548 "p" mh-thread-previous-sibling
2549 "n" mh-thread-next-sibling
2550 "t" mh-toggle-threads
2551 "d" mh-thread-delete
2552 "o" mh-thread-refile)
2554 (gnus-define-keys (mh-limit-map "/" mh-folder-mode-map)
2555 "'" mh-narrow-to-tick
2558 "f" mh-narrow-to-from
2559 "r" mh-narrow-to-range
2560 "s" mh-narrow-to-subject
2564 (gnus-define-keys (mh-extract-map "X" mh-folder-mode-map)
2566 "s" mh-store-msg ;shar
2567 "u" mh-store-msg) ;uuencode
2569 (gnus-define-keys (mh-digest-map "D" mh-folder-mode-map)
2572 "\177" mh-page-digest-backwards
2573 "b" mh-burst-digest)
2575 (gnus-define-keys (mh-mime-map "K" mh-folder-mode-map)
2577 "a" mh-mime-save-parts
2578 "e" mh-display-with-external-viewer
2579 "i" mh-folder-inline-mime-part
2580 "o" mh-folder-save-mime-part
2581 "t" mh-toggle-mime-buttons
2582 "v" mh-folder-toggle-mime-part
2584 [backtab] mh-prev-button
2585 "\M-\t" mh-prev-button
)
2589 (define-key mh-folder-mode-map
[button2] 'mh-show-mouse))
2591 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse)))
2593 ;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt
2599 ;;; If you add a new prefix, add appropriate text to the nil key.
2601 ;;; In general, messages are grouped logically. Taking the main commands for
2602 ;;; example, the first line is "ways to view messages," the second line is
2603 ;;; "things you can do with messages", and the third is "composing" messages.
2605 ;;; When adding a new prefix, ensure that the help message contains "what" the
2606 ;;; prefix is for. For example, if the word "folder" were not present in the
2607 ;;; `F' entry, it would not be clear what these commands operated upon.
2608 (defvar mh-help-messages
2609 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n"
2610 "[d]elete, [o]refile, e[x]ecute,\n"
2611 "[s]end, [r]eply,\n"
2612 "[;]toggle MIME decoding.\n"
2613 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys,"
2614 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.")
2616 (?F "[l]ist; [v]isit folder;\n"
2617 "[n]ew messages; [']ticked messages; [s]earch; [i]ndexed search;\n"
2618 "[p]ack; [S]ort; [r]escan; [k]ill")
2619 (?P "[p]rint message to [f]ile; old-style [l]pr printing;\n"
2620 "Toggle printing of [C]olors, [F]aces")
2621 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n"
2622 "[s]equences, [l]ist,\n"
2623 "[d]elete message from sequence, [k]ill sequence")
2624 (?T "[t]oggle, [d]elete, [o]refile thread")
2625 (?/ "Limit to [c]c, [f]rom, [r]ange, [s]ubject, [t]o; [w]iden")
2626 (?X "un[s]har, [u]udecode message")
2627 (?D "[b]urst digest")
2628 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n"
2629 "[TAB] next; [SHIFT-TAB] previous")
2630 (?J "[b]lacklist, [w]hitelist message"))
2631 "Key binding cheat sheet.
2633 This is an associative array which is used to show the most common commands.
2634 The key is a prefix char. The value is one or more strings which are
2635 concatenated together and displayed in the minibuffer if ? is pressed after
2636 the prefix character. The special key nil is used to display the
2637 non-prefixed commands.
2639 The substitutions described in `substitute-command-keys' are performed as
2644 (dolist (mess '("^Cursor not pointing to message$"
2645 "^There is no other window$"))
2646 (add-to-list 'debug-ignored-errors mess))
2650 ;;; Local Variables:
2651 ;;; indent-tabs-mode: nil
2652 ;;; sentence-end-double-space: nil
2655 ;;; arch-tag: cce884de-bd37-4104-9963-e4439d5ed22b
2656 ;;; mh-e.el ends here