* mh-init.el (mh-image-load-path-called-flag): New variable which
[bpt/emacs.git] / lisp / mh-e / mh-e.el
CommitLineData
c26cf6c8
RS
1;;; mh-e.el --- GNU Emacs interface to the MH mail system
2
e495eaec
BW
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.
c26cf6c8 6
a1b4049d 7;; Author: Bill Wohler <wohler@newt.com>
6e65a812 8;; Maintainer: Bill Wohler <wohler@newt.com>
a9954630 9;; Version: 7.85+cvs
c26cf6c8
RS
10;; Keywords: mail
11
60370d40 12;; This file is part of GNU Emacs.
9b7bc076
KH
13
14;; GNU Emacs is free software; you can redistribute it and/or modify
c26cf6c8
RS
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)
17;; any later version.
18
9b7bc076 19;; GNU Emacs is distributed in the hope that it will be useful,
c26cf6c8
RS
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.
23
24;; You should have received a copy of the GNU General Public License
b578f267 25;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
26;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27;; Boston, MA 02110-1301, USA.
c26cf6c8
RS
28
29;;; Commentary:
30
a1b4049d
BW
31;; How to Use:
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.
b578f267 35
a1b4049d
BW
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)
b578f267 40
a1b4049d 41;; MH (Message Handler) is a powerful mail reader.
b578f267 42
a1b4049d
BW
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
bdcfe844 45;; Questions posting there for information on getting MH and MH-E:
a1b4049d 46;; http://www.faqs.org/faqs/mail/mh-faq/part1/preamble.html
b578f267 47
a1b4049d 48;; N.B. MH must have been compiled with the MHE compiler flag or several
bdcfe844 49;; features necessary for MH-E will be missing from MH commands, specifically
b578f267
EN
50;; the -build switch to repl and forw.
51
bdcfe844 52;; MH-E is an Emacs interface to the MH mail system.
a1b4049d 53
bdcfe844 54;; MH-E is supported in GNU Emacs 20 and 21, with MH 6.8.4 and nmh 1.0.4.
a1b4049d
BW
55
56;; Mailing Lists:
57;; mh-e-users@lists.sourceforge.net
58;; mh-e-announce@lists.sourceforge.net
59;; mh-e-devel@lists.sourceforge.net
60;;
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
64
65;; Bug Reports:
66;; https://sourceforge.net/tracker/?group_id=13357&atid=113357
67;; Include the output of M-x mh-version in any bug report.
68
69;; Feature Requests:
70;; https://sourceforge.net/tracker/?atid=363357&group_id=13357&func=browse
71
72;; Support:
73;; https://sourceforge.net/tracker/?group_id=13357&atid=213357
b578f267 74
717e06e5 75;;; Change Log:
b578f267
EN
76
77;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
78;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
f0d73c14
BW
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.
a1b4049d 83
c26cf6c8
RS
84;;; Code:
85
a66894d8 86(provide 'mh-e)
c3d9274a 87
f0d73c14
BW
88(eval-when-compile (require 'mh-acros))
89(mh-require-cl)
90(require 'mh-utils)
91(require 'mh-init)
924df208 92(require 'mh-inc)
eccf9613 93(require 'mh-seq)
a1b4049d
BW
94(require 'gnus-util)
95(require 'easymenu)
a1b4049d 96
bdcfe844
BW
97;; Shush the byte-compiler
98(defvar font-lock-auto-fontify)
99(defvar font-lock-defaults)
a1b4049d 100
a9954630 101(defconst mh-version "7.85+cvs" "Version number of MH-E.")
c26cf6c8 102
c26cf6c8
RS
103(defvar mh-partial-folder-mode-line-annotation "select"
104 "Annotation when displaying part of a folder.
bdcfe844 105The string is displayed after the folder's name. nil for no annotation.")
a1b4049d 106
f0d73c14
BW
107\f
108;;; Scan Line Formats
109
bdcfe844 110;;; Parameterize MH-E to work with different scan formats. The defaults work
a1b4049d
BW
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.
113
f0d73c14
BW
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 width of the msg number, use the `mh-set-cmd-note'
118;; function.
a1b4049d
BW
119
120(defvar mh-scan-format-mh
121 (concat
122 "%4(msg)"
123 "%<(cur)+%| %>"
124 "%<{replied}-"
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%>"
129 "%<(zero) %>"
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, provided to the scan program via the -format arg.
135This format is identical to the default except that additional hints for
bdcfe844
BW
136fontification have been added to the fifth column (remember that in Emacs, the
137first column is 0).
a1b4049d 138
f0d73c14
BW
139The values of the fifth column, in priority order, are: `-' if the message has
140been replied to, t if an address on the To: line matches one of the
141mailboxes of the current user, `c' if the Cc: line matches, `b' if the Bcc:
142line matches, and `n' if a non-empty Newsgroups: header is present.")
a1b4049d
BW
143
144(defvar mh-scan-format-nmh
145 (concat
146 "%4(msg)"
147 "%<(cur)+%| %>"
148 "%<{replied}-"
149 "%?(nonnull(comp{to}))%<(mymbox{to})t%>"
150 "%?(nonnull(comp{cc}))%<(mymbox{cc})c%>"
151 "%?(nonnull(comp{bcc}))%<(mymbox{bcc})b%>"
152 "%?(nonnull(comp{newsgroups}))n%>"
153 "%<(zero) %>"
154 "%02(mon{date})/%02(mday{date})%<{date} %|*%>"
155 "%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>"
156 "%<(zero)%17(decode(friendly{from}))%> "
157 "%(decode{subject})%<{body}<<%{body}%>")
bdcfe844
BW
158 "*Scan format string for nmh.
159This string is passed to the scan program via the -format arg.
a1b4049d 160This format is identical to the default except that additional hints for
bdcfe844
BW
161fontification have been added to the fifth column (remember that in Emacs, the
162first column is 0).
a1b4049d 163
f0d73c14
BW
164The values of the fifth column, in priority order, are: `-' if the message has
165been replied to, t if an address on the To: field matches one of the
166mailboxes of the current user, `c' if the Cc: field matches, `b' if the Bcc:
167field matches, and `n' if a non-empty Newsgroups: field is present.")
168
169(defvar mh-note-deleted ?D
170 "Deleted messages are marked by this character.
171See also `mh-scan-deleted-msg-regexp'.")
172
173(defvar mh-note-refiled ?^
174 "Refiled messages are marked by this character.
175See also `mh-scan-refiled-msg-regexp'.")
176
177(defvar mh-note-cur ?+
178 "The current message (in MH) is marked by this character.
179See also `mh-scan-cur-msg-number-regexp'.")
a1b4049d 180
bdcfe844 181(defvar mh-scan-good-msg-regexp "^\\( *[0-9]+\\)[^D^0-9]"
f0d73c14
BW
182 "This regexp specifies the scan lines that are 'good' messages.
183Note that the default setting of `mh-folder-font-lock-keywords' expects this
184expression to contain at least one parenthesized expression which matches the
185message number as in the default of \"^\\\\( *[0-9]+\\\\)[^D^0-9]\".")
a1b4049d 186
bdcfe844 187(defvar mh-scan-deleted-msg-regexp "^\\( *[0-9]+\\)D"
f0d73c14
BW
188 "This regexp matches deleted messages.
189Note that the default setting of `mh-folder-font-lock-keywords' expects this
190expression to contain at least one parenthesized expression which matches the
191message number as in the default of \"^\\\\( *[0-9]+\\\\)D\".
192See also `mh-note-deleted'.")
a1b4049d 193
bdcfe844 194(defvar mh-scan-refiled-msg-regexp "^\\( *[0-9]+\\)\\^"
f0d73c14
BW
195 "This regexp matches refiled messages.
196Note that the default setting of `mh-folder-font-lock-keywords' expects this
197expression to contain at least one parenthesized expression which matches the
198message number as in the default of \"^\\\\( *[0-9]+\\\\)\\\\^\".
199See also `mh-note-refiled'.")
a1b4049d
BW
200
201(defvar mh-scan-valid-regexp "^ *[0-9]"
f0d73c14 202 "This regexp matches scan lines for messages (not error messages).")
a1b4049d 203
bdcfe844 204(defvar mh-scan-cur-msg-number-regexp "^\\( *[0-9]+\\+\\).*"
f0d73c14
BW
205 "This regexp matches the current message.
206Note that the default setting of `mh-folder-font-lock-keywords' expects this
207expression to contain at least one parenthesized expression which matches the
208message number as in the default of \"^\\\\( *[0-9]+\\\\+\\\\).*\". Don't
209disable this regexp as it's needed by non-fontifying functions.
210See also `mh-note-cur'.")
a1b4049d
BW
211
212(defvar mh-scan-date-regexp "\\([0-9][0-9]/[0-9][0-9]\\)"
f0d73c14
BW
213 "This regexp matches a valid date.
214Note that the default setting of `mh-folder-font-lock-keywords' expects this
215expression to contain only one parenthesized expression which matches the date
216field as in the default of \"\\\\([0-9][0-9]/[0-9][0-9]\\\\)\"}.
217See also `mh-scan-format-regexp'.")
a1b4049d
BW
218
219(defvar mh-scan-rcpt-regexp "\\(To:\\)\\(..............\\)"
f0d73c14
BW
220 "This regexp specifies the recipient in messages you sent.
221Note that the default setting of `mh-folder-font-lock-keywords'
222expects this expression to contain two parenthesized expressions. The
223first is expected to match the `To:' that the default scan format
224file generates. The second is expected to match the recipient's name
225as in the default of \"\\\\(To:\\\\)\\\\(..............\\\\)\".")
a1b4049d
BW
226
227(defvar mh-scan-body-regexp "\\(<<\\([^\n]+\\)?\\)"
f0d73c14
BW
228 "This regexp matches the message body fragment displayed in scan lines.
229Note that the default setting of `mh-folder-font-lock-keywords' expects this
230expression to contain at least one parenthesized expression which matches the
231body text as in the default of \"\\\\(<<\\\\([^\\n]+\\\\)?\\\\)\".")
a1b4049d
BW
232
233(defvar mh-scan-subject-regexp
bdcfe844 234 "^ *[0-9]+........[ ]*...................\\([Rr][Ee]\\(\\[[0-9]+\\]\\)?:\\s-*\\)*\\([^<\n]*\\)"
f0d73c14
BW
235 "This regexp matches the subject.
236Note that the default setting of `mh-folder-font-lock-keywords' expects this
237expression to contain at least three parenthesized expressions. The first is
238expected to match the `Re:' string, if any. The second matches an optional
239bracketed number after `Re:', such as in `Re[2]:' (and is thus a
240sub-expression of the first expression) and the third is expected to match
241the subject line itself as in the default of \"^ *[0-9]+........[ ]*...................\\\\([Rr][Ee]\\\\(\\\\\\=[[0-9]+\\\\]\\\\)?:\\\\s-*\\\\)*\\\\([^<\\n]*\\\\)\".")
a1b4049d
BW
242
243(defvar mh-scan-format-regexp
bdcfe844 244 (concat "\\([bct]\\)" mh-scan-date-regexp " *\\(..................\\)")
f0d73c14
BW
245 "This regexp matches the output of scan.
246Note that the default setting of `mh-folder-font-lock-keywords' expects this
247expression to contain at least three parenthesized expressions. The first
248should match the fontification hint, the second is found in
249`mh-scan-date-regexp', and the third should match the user name as in the
250default of \"(concat \"\\\\([bct]\\\\)\" mh-scan-date-regexp
251 \"*\\\\(..................\\\\)\")\".")
a1b4049d 252
c3d9274a
BW
253\f
254
bdcfe844
BW
255(defvar mh-folder-font-lock-keywords
256 (list
c3d9274a
BW
257 ;; Folders when displaying index buffer
258 (list "^\\+.*"
259 '(0 mh-index-folder-face))
bdcfe844
BW
260 ;; Marked for deletion
261 (list (concat mh-scan-deleted-msg-regexp ".*")
262 '(0 mh-folder-deleted-face))
263 ;; Marked for refile
264 (list (concat mh-scan-refiled-msg-regexp ".*")
265 '(0 mh-folder-refiled-face))
266 ;;after subj
267 (list mh-scan-body-regexp '(1 mh-folder-body-face nil t))
268 '(mh-folder-font-lock-subject
269 (1 mh-folder-followup-face append t)
270 (2 mh-folder-subject-face append t))
271 ;;current msg
272 (list mh-scan-cur-msg-number-regexp
273 '(1 mh-folder-cur-msg-number-face))
274 (list mh-scan-good-msg-regexp
c3d9274a
BW
275 '(1 mh-folder-msg-number-face)) ;; Msg number
276 (list mh-scan-date-regexp '(1 mh-folder-date-face)) ;; Date
bdcfe844 277 (list mh-scan-rcpt-regexp
c3d9274a
BW
278 '(1 mh-folder-to-face) ;; To:
279 '(2 mh-folder-address-face)) ;; address
bdcfe844
BW
280 ;; scan font-lock name
281 (list mh-scan-format-regexp
282 '(1 mh-folder-date-face)
f0d73c14 283 '(3 mh-folder-scan-format-face)))
bdcfe844
BW
284 "Regexp keywords used to fontify the MH-Folder buffer.")
285
286(defvar mh-scan-cmd-note-width 1
287 "Number of columns consumed by the cmd-note field in `mh-scan-format'.
288This column will have one of the values: ` ', `D', `^', `+' and where
289` ' is the default value,
290`D' is the `mh-note-deleted' character,
291`^' is the `mh-note-refiled' character, and
292`+' is the `mh-note-cur' character.")
293
294(defvar mh-scan-destination-width 1
295 "Number of columns consumed by the destination field in `mh-scan-format'.
296This column will have one of ' ', '%', '-', 't', 'c', 'b', or `n' in it.
297A ' ' blank space is the default character.
298A '%' indicates that the message in in a named MH sequence.
299A '-' indicates that the message has been annotated with a replied field.
300A 't' indicates that the message contains mymbox in the To: field.
301A 'c' indicates that the message contains mymbox in the Cc: field.
302A 'b' indicates that the message contains mymbox in the Bcc: field.
303A 'n' indicates that the message contains a Newsgroups: field.")
304
305(defvar mh-scan-date-width 5
306 "Number of columns consumed by the date field in `mh-scan-format'.
307This column will typically be of the form mm/dd.")
308
309(defvar mh-scan-date-flag-width 1
310 "Number of columns consumed to flag (in)valid dates in `mh-scan-format'.
311This column will have ` ' for valid and `*' for invalid or missing dates.")
312
313(defvar mh-scan-from-mbox-width 17
314 "Number of columns consumed with the \"From:\" line in `mh-scan-format'.
315This column will have a friendly name or e-mail address of the
316originator, or a \"To: address\" for outgoing e-mail messages.")
317
318(defvar mh-scan-from-mbox-sep-width 2
319 "Number of columns consumed by whitespace after from-mbox in `mh-scan-format'.
320This column will only ever have spaces in it.")
321
322(defvar mh-scan-field-from-start-offset
c3d9274a
BW
323 (+ mh-scan-cmd-note-width
324 mh-scan-destination-width
325 mh-scan-date-width
326 mh-scan-date-flag-width)
327 "The offset from the `mh-cmd-note' to find the start of \"From:\" address.")
bdcfe844
BW
328
329(defvar mh-scan-field-from-end-offset
c3d9274a
BW
330 (+ mh-scan-field-from-start-offset mh-scan-from-mbox-width)
331 "The offset from the `mh-cmd-note' to find the end of \"From:\" address.")
bdcfe844
BW
332
333(defvar mh-scan-field-subject-start-offset
334 (+ mh-scan-cmd-note-width
335 mh-scan-destination-width
336 mh-scan-date-width
337 mh-scan-date-flag-width
338 mh-scan-from-mbox-width
339 mh-scan-from-mbox-sep-width)
340 "The offset from the `mh-cmd-note' to find the start of the subject.")
a1b4049d
BW
341
342(defun mh-folder-font-lock-subject (limit)
bdcfe844 343 "Return MH-E scan subject strings to font-lock between point and LIMIT."
a1b4049d
BW
344 (if (not (re-search-forward mh-scan-subject-regexp limit t))
345 nil
346 (if (match-beginning 1)
bdcfe844
BW
347 (set-match-data (list (match-beginning 1) (match-end 3)
348 (match-beginning 1) (match-end 3) nil nil))
349 (set-match-data (list (match-beginning 3) (match-end 3)
350 nil nil (match-beginning 3) (match-end 3))))
a1b4049d
BW
351 t))
352
bdcfe844
BW
353\f
354
355;; Fontifify unseen mesages in bold.
356
a66894d8
BW
357(defmacro mh-generate-sequence-font-lock (seq prefix face)
358 "Generate the appropriate code to fontify messages in SEQ.
359PREFIX is used to generate unique names for the variables and functions
360defined by the macro. So a different prefix should be provided for every
361invocation.
362FACE is the font-lock face used to display the matching scan lines."
363 (let ((cache (intern (format "mh-folder-%s-seq-cache" prefix)))
364 (func (intern (format "mh-folder-font-lock-%s" prefix))))
365 `(progn
366 (defvar ,cache nil
367 "Internal cache variable used for font-lock in MH-E.
a1b4049d
BW
368Should only be non-nil through font-lock stepping, and nil once font-lock
369is done highlighting.")
a66894d8
BW
370 (make-variable-buffer-local ',cache)
371
372 (defun ,func (limit)
373 "Return unseen message lines to font-lock between point and LIMIT."
374 (if (not ,cache) (setq ,cache (mh-seq-msgs (mh-find-seq ,seq))))
375 (let ((cur-msg (mh-get-msg-num nil)))
376 (cond ((not ,cache)
377 nil)
378 ((>= (point) limit) ;Presumably at end of buffer
379 (setq ,cache nil)
380 nil)
381 ((member cur-msg ,cache)
382 (let ((bpoint (progn (beginning-of-line)(point)))
383 (epoint (progn (forward-line 1)(point))))
384 (if (<= limit (point)) (setq ,cache nil))
385 (set-match-data (list bpoint epoint bpoint epoint))
386 t))
387 (t
388 ;; move forward one line at a time, checking each message
389 (while (and (= 0 (forward-line 1))
390 (> limit (point))
391 (not (member (mh-get-msg-num nil) ,cache))))
392 ;; Examine how we must have exited the loop...
393 (let ((cur-msg (mh-get-msg-num nil)))
394 (cond ((or (<= limit (point))
395 (not (member cur-msg ,cache)))
396 (setq ,cache nil)
397 nil)
398 ((member cur-msg ,cache)
399 (let ((bpoint (progn (beginning-of-line) (point)))
400 (epoint (progn (forward-line 1) (point))))
401 (if (<= limit (point)) (setq ,cache nil))
402 (set-match-data
403 (list bpoint epoint bpoint epoint))
404 t))))))))
405
406 (setq mh-folder-font-lock-keywords
407 (append mh-folder-font-lock-keywords
408 (list (list ',func (list 1 '',face 'prepend t))))))))
409
410(mh-generate-sequence-font-lock mh-unseen-seq unseen bold)
5b004a34 411(mh-generate-sequence-font-lock mh-tick-seq tick mh-folder-tick)
bdcfe844
BW
412
413\f
c26cf6c8
RS
414
415;;; Internal variables:
416
c3d9274a
BW
417(defvar mh-last-destination nil) ;Destination of last refile or write
418 ;command.
bdcfe844
BW
419(defvar mh-last-destination-folder nil) ;Destination of last refile command.
420(defvar mh-last-destination-write nil) ;Destination of last write command.
c26cf6c8
RS
421
422(defvar mh-folder-mode-map (make-keymap)
423 "Keymap for MH folders.")
424
3d7ca223
BW
425(defvar mh-arrow-marker nil) ;Marker for arrow display in fringe.
426
c3d9274a 427(defvar mh-delete-list nil) ;List of msg numbers to delete.
c26cf6c8 428
c3d9274a 429(defvar mh-refile-list nil) ;List of folder names in mh-seq-list.
c26cf6c8 430
c3d9274a 431(defvar mh-next-direction 'forward) ;Direction to move to next message.
c26cf6c8 432
bdcfe844
BW
433(defvar mh-view-ops ()) ;Stack of ops that change the folder
434 ;view (such as narrowing or threading).
a66894d8 435(defvar mh-folder-view-stack ()) ;Stack of previous folder views.
c26cf6c8 436
c3d9274a
BW
437(defvar mh-index-data nil) ;Info about index search results
438(defvar mh-index-previous-search nil)
439(defvar mh-index-msg-checksum-map nil)
440(defvar mh-index-checksum-origin-map nil)
a66894d8 441(defvar mh-index-sequence-search-flag nil)
c3d9274a
BW
442
443(defvar mh-first-msg-num nil) ;Number of first msg in buffer.
c26cf6c8 444
c3d9274a 445(defvar mh-last-msg-num nil) ;Number of last msg in buffer.
c26cf6c8 446
c3d9274a 447(defvar mh-mode-line-annotation nil) ;Message range displayed in buffer.
c26cf6c8 448
a66894d8
BW
449(defvar mh-sequence-notation-history nil)
450 ;Rememeber original notation that
451 ;is overwritten by `mh-note-seq'.
452
f0d73c14
BW
453(defvar mh-colors-available-flag nil) ;Are colors available?
454
c26cf6c8
RS
455;;; Macros and generic functions:
456
bdcfe844
BW
457(defun mh-mapc (function list)
458 "Apply FUNCTION to each element of LIST for side effects only."
c26cf6c8 459 (while list
bdcfe844 460 (funcall function (car list))
c26cf6c8
RS
461 (setq list (cdr list))))
462
a1b4049d 463(defun mh-scan-format ()
a66894d8 464 "Return the output format argument for the scan program."
a1b4049d 465 (if (equal mh-scan-format-file t)
f0d73c14 466 (list "-format" (if (mh-variant-p 'nmh 'mu-mh)
c3d9274a
BW
467 (list (mh-update-scan-format
468 mh-scan-format-nmh mh-cmd-note))
469 (list (mh-update-scan-format
470 mh-scan-format-mh mh-cmd-note))))
a1b4049d 471 (if (not (equal mh-scan-format-file nil))
a66894d8 472 (list "-form" mh-scan-format-file))))
a1b4049d 473
c26cf6c8
RS
474\f
475
476;;; Entry points:
477
478;;;###autoload
479(defun mh-rmail (&optional arg)
a1b4049d 480 "Inc(orporate) new mail with MH.
bdcfe844 481Scan an MH folder if ARG is non-nil. This function is an entry point to MH-E,
f0d73c14 482the Emacs interface to the MH mail system."
c26cf6c8
RS
483 (interactive "P")
484 (mh-find-path)
485 (if arg
486 (call-interactively 'mh-visit-folder)
3d7ca223
BW
487 (unless (get-buffer mh-inbox)
488 (mh-visit-folder mh-inbox (symbol-name mh-unseen-seq)))
c3d9274a 489 (mh-inc-folder)))
c26cf6c8 490
a1b4049d
BW
491;;;###autoload
492(defun mh-nmail (&optional arg)
493 "Check for new mail in inbox folder.
bdcfe844 494Scan an MH folder if ARG is non-nil. This function is an entry point to MH-E,
f0d73c14 495the Emacs interface to the MH mail system."
a1b4049d 496 (interactive "P")
c3d9274a 497 (mh-find-path) ; init mh-inbox
a1b4049d
BW
498 (if arg
499 (call-interactively 'mh-visit-folder)
500 (mh-visit-folder mh-inbox)))
c26cf6c8
RS
501
502\f
503
bdcfe844 504;;; User executable MH-E commands:
c26cf6c8 505
a66894d8
BW
506(defun mh-delete-msg (range)
507 "Mark the specified RANGE for subsequent deletion and move to the next.
924df208 508Default is the displayed message.
a66894d8
BW
509
510Check the documentation of `mh-interactive-range' to see how RANGE is read in
511interactive use."
512 (interactive (list (mh-interactive-range "Delete")))
513 (mh-delete-msg-no-motion range)
514 (if (looking-at mh-scan-deleted-msg-regexp) (mh-next-msg)))
515
516(defun mh-delete-msg-no-motion (range)
517 "Mark the specified RANGE for subsequent deletion.
518
519Check the documentation of `mh-interactive-range' to see how RANGE is read in
520interactive use."
521 (interactive (list (mh-interactive-range "Delete")))
522 (mh-iterate-on-range () range
924df208 523 (mh-delete-a-msg nil)))
c26cf6c8 524
c26cf6c8
RS
525(defun mh-execute-commands ()
526 "Process outstanding delete and refile requests."
527 (interactive)
a66894d8 528 (if mh-folder-view-stack (mh-widen t))
c26cf6c8
RS
529 (mh-process-commands mh-current-folder)
530 (mh-set-scan-mode)
c3d9274a 531 (mh-goto-cur-msg) ; after mh-set-scan-mode for efficiency
c26cf6c8 532 (mh-make-folder-mode-line)
c3d9274a 533 t) ; return t for write-file-functions
c26cf6c8
RS
534
535(defun mh-first-msg ()
536 "Move to the first message."
537 (interactive)
847b8219 538 (goto-char (point-min))
a1b4049d 539 (while (and (not (eobp)) (not (looking-at mh-scan-valid-regexp)))
847b8219 540 (forward-line 1)))
c26cf6c8 541
c26cf6c8
RS
542(defun mh-header-display ()
543 "Show the current message with all its headers.
86a32538 544Displays headers that might have been suppressed by setting the
bdcfe844 545variables `mh-clean-message-header-flag' or `mhl-formfile', or by the fallback
86a32538
RS
546behavior of scrolling uninteresting headers off the top of the window.
547Type \"\\[mh-show]\" to show the message normally again."
c26cf6c8
RS
548 (interactive)
549 (and (not mh-showing-with-headers)
bdcfe844 550 (or mhl-formfile mh-clean-message-header-flag)
c26cf6c8 551 (mh-invalidate-show-buffer))
bdcfe844
BW
552 (let ((mh-decode-mime-flag nil)
553 (mhl-formfile nil)
c3d9274a 554 (mh-clean-message-header-flag nil))
c26cf6c8
RS
555 (mh-show-msg nil)
556 (mh-in-show-buffer (mh-show-buffer)
557 (goto-char (point-min))
558 (mh-recenter 0))
559 (setq mh-showing-with-headers t)))
560
924df208 561(defun mh-inc-folder (&optional maildrop-name folder)
847b8219 562 "Inc(orporate)s new mail into the Inbox folder.
a1b4049d 563Optional argument MAILDROP-NAME specifies an alternate maildrop from the
924df208
BW
564default. The optional argument FOLDER specifies where to incorporate mail
565instead of the default named by `mh-inbox'.
bdcfe844
BW
566The value of `mh-inc-folder-hook' is a list of functions to be called, with no
567arguments, after incorporating new mail.
568Do not call this function from outside MH-E; use \\[mh-rmail] instead."
c26cf6c8 569 (interactive (list (if current-prefix-arg
c3d9274a
BW
570 (expand-file-name
571 (read-file-name "inc mail from file: "
924df208
BW
572 mh-user-path)))
573 (if current-prefix-arg
574 (mh-prompt-for-folder "inc mail into" mh-inbox t))))
575 (if (not folder)
576 (setq folder mh-inbox))
c3d9274a
BW
577 (let ((threading-needed-flag nil))
578 (let ((config (current-window-configuration)))
e495eaec
BW
579 (when (and mh-show-buffer (get-buffer mh-show-buffer))
580 (delete-windows-on mh-show-buffer))
924df208
BW
581 (cond ((not (get-buffer folder))
582 (mh-make-folder folder)
583 (setq threading-needed-flag mh-show-threads-flag)
584 (setq mh-previous-window-config config))
585 ((not (eq (current-buffer) (get-buffer folder)))
586 (switch-to-buffer folder)
587 (setq mh-previous-window-config config))))
c3d9274a
BW
588 (mh-get-new-mail maildrop-name)
589 (when (and threading-needed-flag
590 (save-excursion
591 (goto-char (point-min))
592 (or (null mh-large-folder)
a66894d8 593 (not (equal (forward-line (1+ mh-large-folder)) 0))
c3d9274a
BW
594 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
595 nil))))
596 (mh-toggle-threads))
924df208
BW
597 (beginning-of-line)
598 (if (and mh-showing-mode (looking-at mh-scan-valid-regexp)) (mh-show))
c3d9274a 599 (run-hooks 'mh-inc-folder-hook)))
c26cf6c8 600
c26cf6c8
RS
601(defun mh-last-msg ()
602 "Move to the last message."
603 (interactive)
604 (goto-char (point-max))
c3d9274a 605 (while (and (not (bobp)) (not (looking-at mh-scan-valid-regexp)))
bdcfe844
BW
606 (forward-line -1))
607 (mh-recenter nil))
c26cf6c8 608
924df208
BW
609(defun mh-next-undeleted-msg (&optional arg wait-after-complaining-flag)
610 "Move to the next undeleted message ARG in window.
611If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and we are at the
612last undeleted message then pause for a second after printing message."
847b8219 613 (interactive "p")
c26cf6c8 614 (setq mh-next-direction 'forward)
847b8219 615 (forward-line 1)
bdcfe844 616 (cond ((re-search-forward mh-scan-good-msg-regexp nil t arg)
c3d9274a
BW
617 (beginning-of-line)
618 (mh-maybe-show))
619 (t (forward-line -1)
924df208
BW
620 (message "No more undeleted messages")
621 (if wait-after-complaining-flag (sit-for 1)))))
c26cf6c8 622
3d7ca223 623(defun mh-folder-from-address ()
f0d73c14
BW
624 "Derive folder name from sender.
625
626The name of the folder is derived as follows:
3d7ca223 627
f0d73c14
BW
628 a) The folder name associated with the first address found in the list
629 `mh-default-folder-list' is used. Each element in this list contains a
630 `Check Recipient' item. If this item is turned on, then the address is
631 checked against the recipient instead of the sender. This is useful for
632 mailing lists.
3d7ca223 633
f0d73c14
BW
634 b) An alias prefixed by `mh-default-folder-prefix' corresponding to the
635 address is used. The prefix is used to prevent clutter in your mail
636 directory.
3d7ca223 637
f0d73c14
BW
638Return nil if a folder name was not derived, or if the variable
639`mh-default-folder-must-exist-flag' is t and the folder does not exist."
924df208 640 ;; Loop for all entries in mh-default-folder-list
a66894d8
BW
641 (save-restriction
642 (goto-char (point-min))
f0d73c14 643 (re-search-forward "\n\n" nil 'limit)
a66894d8
BW
644 (narrow-to-region (point-min) (point))
645 (let ((to/cc (concat (or (message-fetch-field "to") "") ", "
646 (or (message-fetch-field "cc") "")))
647 (from (or (message-fetch-field "from") ""))
648 folder-name)
649 (setq folder-name
650 (loop for list in mh-default-folder-list
651 when (string-match (nth 0 list) (if (nth 2 list) to/cc from))
652 return (nth 1 list)
653 finally return nil))
924df208
BW
654
655 ;; Make sure a result from `mh-default-folder-list' begins with "+"
656 ;; since 'mh-expand-file-name below depends on it
657 (when (and folder-name (not (eq (aref folder-name 0) ?+)))
658 (setq folder-name (concat "+" folder-name)))
659
660 ;; If not, is there an alias for the address?
661 (when (not folder-name)
662 (let* ((from-header (mh-extract-from-header-value))
663 (address (and from-header
664 (nth 1 (mail-extract-address-components
665 from-header))))
666 (alias (and address (mh-alias-address-to-alias address))))
667 (when alias
668 (setq folder-name
669 (and alias (concat "+" mh-default-folder-prefix alias))))))
670
671 ;; If mh-default-folder-must-exist-flag set, check that folder exists.
672 (if (and folder-name
673 (or (not mh-default-folder-must-exist-flag)
674 (file-exists-p (mh-expand-file-name folder-name))))
675 folder-name))))
3d7ca223
BW
676
677(defun mh-prompt-for-refile-folder ()
678 "Prompt the user for a folder in which the message should be filed.
679The folder is returned as a string.
680
f0d73c14
BW
681The default folder name is generated by the option
682`mh-default-folder-for-message-function' if it is non-nil or
683`mh-folder-from-address'."
3d7ca223
BW
684 (mh-prompt-for-folder
685 "Destination"
f0d73c14
BW
686 (let ((refile-file (ignore-errors (mh-msg-filename (mh-get-msg-num t)))))
687 (if (null refile-file) ""
688 (save-excursion
689 (set-buffer (get-buffer-create mh-temp-buffer))
690 (erase-buffer)
691 (insert-file-contents refile-file)
692 (or (and mh-default-folder-for-message-function
693 (let ((buffer-file-name refile-file))
694 (funcall mh-default-folder-for-message-function)))
695 (mh-folder-from-address)
696 (and (eq 'refile (car mh-last-destination-folder))
697 (symbol-name (cdr mh-last-destination-folder)))
698 ""))))
3d7ca223
BW
699 t))
700
a66894d8
BW
701(defun mh-refile-msg (range folder &optional dont-update-last-destination-flag)
702 "Refile RANGE into FOLDER.
703
704Check the documentation of `mh-interactive-range' to see how RANGE is read in
705interactive use.
924df208
BW
706
707If optional argument DONT-UPDATE-LAST-DESTINATION-FLAG is non-nil then the
708variables `mh-last-destination' and `mh-last-destination-folder' are not
709updated."
a66894d8 710 (interactive (list (mh-interactive-range "Refile")
924df208
BW
711 (intern (mh-prompt-for-refile-folder))))
712 (unless dont-update-last-destination-flag
713 (setq mh-last-destination (cons 'refile folder)
714 mh-last-destination-folder mh-last-destination))
a66894d8 715 (mh-iterate-on-range () range
924df208 716 (mh-refile-a-msg nil folder))
a66894d8 717 (when (looking-at mh-scan-refiled-msg-regexp) (mh-next-msg)))
c26cf6c8 718
e495eaec
BW
719(defun mh-refile-or-write-again (range &optional interactive-flag)
720 "Re-execute the last refile or write command on the given RANGE.
bdcfe844 721Default is the displayed message. Use the same folder or file as the previous
e495eaec
BW
722refile or write command.
723If INTERACTIVE-FLAG is non-nil then the function was called interactively."
724 (interactive (list (mh-interactive-range "Redo") t))
c26cf6c8
RS
725 (if (null mh-last-destination)
726 (error "No previous refile or write"))
924df208
BW
727 (let (output)
728 (setq output
729 (cond ((eq (car mh-last-destination) 'refile)
e495eaec 730 (mh-refile-msg range (cdr mh-last-destination))
924df208
BW
731 (format "Destination folder: %s" (cdr mh-last-destination)))
732 (t
e495eaec
BW
733 (mh-iterate-on-range msg range
734 (apply 'mh-write-msg-to-file msg (cdr mh-last-destination)))
735 (mh-next-msg interactive-flag)
924df208 736 (format "Destination: %s" (cdr mh-last-destination)))))
47570699 737 (message "%s" output)))
c26cf6c8 738
c26cf6c8 739(defun mh-quit ()
bdcfe844
BW
740 "Quit the current MH-E folder.
741Restore the previous window configuration, if one exists.
742The value of `mh-before-quit-hook' is a list of functions to be called, with
743no arguments, immediately upon entry to this function.
744The value of `mh-quit-hook' is a list of functions to be called, with no
3d7ca223
BW
745arguments, upon exit of this function.
746MH-E working buffers (whose name begins with \" *mh-\" or \"*MH-E \") are
747killed."
c26cf6c8 748 (interactive)
a1b4049d 749 (run-hooks 'mh-before-quit-hook)
bdcfe844
BW
750 (let ((show-buffer (get-buffer mh-show-buffer)))
751 (when show-buffer
752 (kill-buffer show-buffer)))
847b8219 753 (mh-update-sequences)
bdcfe844 754 (mh-destroy-postponed-handles)
6d4de1a7 755 (bury-buffer (current-buffer))
3d7ca223
BW
756
757 ;; Delete all MH-E temporary and working buffers.
758 (dolist (buffer (buffer-list))
759 (when (or (string-match "^ \\*mh-" (buffer-name buffer))
760 (string-match "^\\*MH-E " (buffer-name buffer)))
761 (kill-buffer buffer)))
762
c26cf6c8
RS
763 (if mh-previous-window-config
764 (set-window-configuration mh-previous-window-config))
765 (run-hooks 'mh-quit-hook))
766
767(defun mh-page-msg (&optional arg)
768 "Page the displayed message forwards.
a1b4049d
BW
769Scrolls ARG lines or a full screen if no argument is supplied. Show buffer
770first if not displayed. Show the next undeleted message if looking at the
771bottom of the current message."
c26cf6c8 772 (interactive "P")
a1b4049d 773 (if mh-showing-mode
bdcfe844 774 (if mh-page-to-next-msg-flag
c3d9274a
BW
775 (if (equal mh-next-direction 'backward)
776 (mh-previous-undeleted-msg)
777 (mh-next-undeleted-msg))
778 (if (mh-in-show-buffer (mh-show-buffer)
779 (pos-visible-in-window-p (point-max)))
780 (progn
deceef67 781 (message
47570699
DG
782 "End of message (Type %s to read %s undeleted message)"
783 (single-key-description last-input-event)
784 (if (equal mh-next-direction 'backward)
785 "previous"
786 "next"))
c3d9274a
BW
787 (setq mh-page-to-next-msg-flag t))
788 (scroll-other-window arg)))
a1b4049d 789 (mh-show)))
c26cf6c8 790
c26cf6c8
RS
791(defun mh-previous-page (&optional arg)
792 "Page the displayed message backwards.
793Scrolls ARG lines or a full screen if no argument is supplied."
794 (interactive "P")
795 (mh-in-show-buffer (mh-show-buffer)
796 (scroll-down arg)))
797
924df208
BW
798(defun mh-previous-undeleted-msg (&optional arg wait-after-complaining-flag)
799 "Move to the previous undeleted message ARG in window.
800If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and we are at the
801first undeleted message then pause for a second after printing message."
c26cf6c8
RS
802 (interactive "p")
803 (setq mh-next-direction 'backward)
804 (beginning-of-line)
bdcfe844 805 (cond ((re-search-backward mh-scan-good-msg-regexp nil t arg)
c3d9274a 806 (mh-maybe-show))
924df208
BW
807 (t (message "No previous undeleted message")
808 (if wait-after-complaining-flag (sit-for 1)))))
c3d9274a
BW
809
810(defun mh-previous-unread-msg (&optional count)
811 "Move to previous unread message.
812With optional argument COUNT, COUNT-1 unread messages before current message
813are skipped."
814 (interactive "p")
815 (unless (> count 0)
816 (error "The function mh-previous-unread-msg expects positive argument"))
817 (setq count (1- count))
818 (let ((unread-sequence (cdr (assoc mh-unseen-seq mh-seq-list)))
819 (cur-msg (mh-get-msg-num nil)))
820 (cond ((and (not cur-msg) (not (bobp))
821 ;; If we are at the end of the buffer back up one line and go
822 ;; to unread message after that.
823 (progn
824 (forward-line -1)
825 (setq cur-msg (mh-get-msg-num nil)))
826 nil))
827 ((or (null unread-sequence) (not cur-msg))
828 ;; No unread message or there aren't any messages in buffer...
829 (message "No more unread messages"))
830 ((progn
831 ;; Skip count messages...
832 (while (and unread-sequence (>= (car unread-sequence) cur-msg))
833 (setq unread-sequence (cdr unread-sequence)))
834 (while (> count 0)
835 (setq unread-sequence (cdr unread-sequence))
836 (setq count (1- count)))
837 (not (car unread-sequence)))
838 (message "No more unread messages"))
f0d73c14
BW
839 (t (loop for msg in unread-sequence
840 when (mh-goto-msg msg t) return nil
841 finally (message "No more unread messages"))))))
bdcfe844
BW
842
843(defun mh-goto-next-button (backward-flag &optional criterion)
844 "Search for next button satisfying criterion.
845If BACKWARD-FLAG is non-nil search backward in the buffer for a mime button. If
846CRITERION is a function or a symbol which has a function binding then that
847function must return non-nil at the button we stop."
848 (unless (or (and (symbolp criterion) (fboundp criterion))
849 (functionp criterion))
850 (setq criterion (lambda (x) t)))
851 ;; Move to the next button in the buffer satisfying criterion
852 (goto-char (or (save-excursion
853 (beginning-of-line)
854 ;; Find point before current button
855 (let ((point-before-current-button
c3d9274a
BW
856 (save-excursion
857 (while (get-text-property (point) 'mh-data)
858 (unless (= (forward-line
859 (if backward-flag 1 -1))
860 0)
861 (if backward-flag
862 (goto-char (point-min))
863 (goto-char (point-max)))))
864 (point))))
865 ;; Skip over current button
866 (while (and (get-text-property (point) 'mh-data)
867 (not (if backward-flag (bobp) (eobp))))
868 (forward-line (if backward-flag -1 1)))
869 ;; Stop at next MIME button if any exists.
870 (block loop
871 (while (/= (progn
872 (unless (= (forward-line
873 (if backward-flag -1 1))
874 0)
875 (if backward-flag
876 (goto-char (point-max))
877 (goto-char (point-min)))
878 (beginning-of-line))
879 (point))
880 point-before-current-button)
881 (when (and (get-text-property (point) 'mh-data)
882 (funcall criterion (point)))
883 (return-from loop (point))))
884 nil)))
bdcfe844
BW
885 (point))))
886
887(defun mh-next-button (&optional backward-flag)
888 "Go to the next MIME button.
889Advance point to the next MIME button in the show buffer. If the end
890of buffer is reached then the search wraps over to the start of the
891buffer. With prefix argument, BACKWARD-FLAG the point will move to the
892previous MIME button."
893 (interactive (list current-prefix-arg))
894 (unless mh-showing-mode
895 (mh-show))
896 (mh-in-show-buffer (mh-show-buffer)
897 (mh-goto-next-button backward-flag)))
c26cf6c8 898
bdcfe844
BW
899(defun mh-prev-button ()
900 "Go to the prev MIME button.
901Move point to the previous MIME button in the show buffer. If the beginning
902of the buffer is reached then the search wraps over to the end of the
903buffer."
904 (interactive)
905 (mh-next-button t))
906
907(defun mh-folder-mime-action (part-index action include-security-flag)
908 "Go to PART-INDEX and carry out ACTION.
909If PART-INDEX is nil then go to the next part in the buffer. The search for
910the next buffer wraps around if end of buffer is reached. If argument
911INCLUDE-SECURITY-FLAG is non-nil then include security info buttons when
912searching for a suitable parts."
913 (unless mh-showing-mode
914 (mh-show))
915 (mh-in-show-buffer (mh-show-buffer)
916 (let ((criterion
c3d9274a
BW
917 (cond (part-index
918 (lambda (p)
919 (let ((part (get-text-property p 'mh-part)))
920 (and (integerp part) (= part part-index)))))
921 (t (lambda (p)
922 (if include-security-flag
923 (get-text-property p 'mh-data)
924 (integerp (get-text-property p 'mh-part)))))))
bdcfe844
BW
925 (point (point)))
926 (cond ((and (get-text-property point 'mh-part)
927 (or (null part-index)
928 (= (get-text-property point 'mh-part) part-index)))
929 (funcall action))
930 ((and (get-text-property point 'mh-data)
931 include-security-flag
932 (null part-index))
933 (funcall action))
934 (t
935 (mh-goto-next-button nil criterion)
936 (if (= (point) point)
937 (message "No matching MIME part found")
938 (funcall action)))))))
939
940(defun mh-folder-toggle-mime-part (part-index)
941 "Toggle display of button.
942If point in show buffer is at a button then that part is toggled.
943If not at a button and PART-INDEX is non-nil point is moved to that part.
944With nil PART-INDEX find the first button after point (search wraps around if
945end of buffer is reached) and toggle it."
946 (interactive "P")
947 (when (consp part-index) (setq part-index (car part-index)))
948 (mh-folder-mime-action part-index #'mh-press-button t))
949
950(defun mh-folder-inline-mime-part (part-index)
951 "Show the raw bytes of MIME part inline.
952If point in show buffer is at a mime part then that part is inlined.
953If not at a mime-part and PART-INDEX is non-nil point is moved to that part.
954With nil PART-INDEX find the first button after point (search wraps around if
955end of buffer is reached) and inline it."
956 (interactive "P")
957 (when (consp part-index) (setq part-index (car part-index)))
958 (mh-folder-mime-action part-index #'mh-mime-inline-part nil))
959
960(defun mh-folder-save-mime-part (part-index)
961 "Save MIME part.
962If point in show buffer is at a mime part then that part is saved.
963If not at a mime-part and PART-INDEX is non-nil point is moved to that part.
964With nil PART-INDEX find the first button after point (search wraps around if
965end of buffer is reached) and save it."
966 (interactive "P")
967 (when (consp part-index) (setq part-index (car part-index)))
968 (mh-folder-mime-action part-index #'mh-mime-save-part nil))
969
a66894d8
BW
970(defvar mh-thread-scan-line-map-stack)
971
bdcfe844
BW
972(defun mh-reset-threads-and-narrowing ()
973 "Reset all variables pertaining to threads and narrowing.
974Also removes all content from the folder buffer."
975 (setq mh-view-ops ())
a66894d8
BW
976 (setq mh-folder-view-stack ())
977 (setq mh-thread-scan-line-map-stack ())
bdcfe844 978 (let ((buffer-read-only nil)) (erase-buffer)))
c26cf6c8 979
bdcfe844 980(defun mh-rescan-folder (&optional range dont-exec-pending)
c26cf6c8 981 "Rescan a folder after optionally processing the outstanding commands.
a1b4049d 982If optional prefix argument RANGE is provided, prompt for the range of
bdcfe844
BW
983messages to display. Otherwise show the entire folder.
984If optional argument DONT-EXEC-PENDING is non-nil then pending deletes and
985refiles aren't carried out."
c26cf6c8 986 (interactive (list (if current-prefix-arg
a66894d8
BW
987 (mh-read-range "Rescan" mh-current-folder t nil t
988 mh-interpret-number-as-range-flag)
c3d9274a 989 nil)))
c26cf6c8 990 (setq mh-next-direction 'forward)
c3d9274a 991 (let ((threaded-flag (memq 'unthread mh-view-ops)))
c3d9274a
BW
992 (mh-scan-folder mh-current-folder (or range "all") dont-exec-pending)
993 (cond (threaded-flag (mh-toggle-threads))
994 (mh-index-data (mh-index-insert-folder-headers)))))
c26cf6c8
RS
995
996(defun mh-write-msg-to-file (msg file no-headers)
a1b4049d
BW
997 "Append MSG to the end of a FILE.
998If prefix argument NO-HEADERS is provided, write only the message body.
c26cf6c8
RS
999Otherwise send the entire message including the headers."
1000 (interactive
1001 (list (mh-get-msg-num t)
c3d9274a
BW
1002 (let ((default-dir (if (eq 'write (car mh-last-destination-write))
1003 (file-name-directory
1004 (car (cdr mh-last-destination-write)))
1005 default-directory)))
1006 (read-file-name (format "Save message%s in file: "
1007 (if current-prefix-arg " body" ""))
1008 default-dir
1009 (if (eq 'write (car mh-last-destination-write))
1010 (car (cdr mh-last-destination-write))
1011 (expand-file-name "mail.out" default-dir))))
1012 current-prefix-arg))
847b8219 1013 (let ((msg-file-to-output (mh-msg-filename msg))
c3d9274a 1014 (output-file (mh-expand-file-name file)))
bdcfe844 1015 (setq mh-last-destination (list 'write file (if no-headers 'no-headers))
c3d9274a 1016 mh-last-destination-write mh-last-destination)
c26cf6c8 1017 (save-excursion
847b8219 1018 (set-buffer (get-buffer-create mh-temp-buffer))
c26cf6c8 1019 (erase-buffer)
847b8219 1020 (insert-file-contents msg-file-to-output)
c26cf6c8
RS
1021 (goto-char (point-min))
1022 (if no-headers (search-forward "\n\n"))
1023 (append-to-file (point) (point-max) output-file))))
1024
c26cf6c8
RS
1025(defun mh-toggle-showing ()
1026 "Toggle the scanning mode/showing mode of displaying messages."
1027 (interactive)
a1b4049d 1028 (if mh-showing-mode
c26cf6c8 1029 (mh-set-scan-mode)
a1b4049d 1030 (mh-show)))
c26cf6c8 1031
a66894d8
BW
1032(defun mh-undo (range)
1033 "Undo the pending deletion or refile of the specified RANGE.
1034
1035Check the documentation of `mh-interactive-range' to see how RANGE is read in
1036interactive use."
1037 (interactive (list (mh-interactive-range "Undo")))
1038 (cond ((numberp range)
c3d9274a
BW
1039 (let ((original-position (point)))
1040 (beginning-of-line)
1041 (while (not (or (looking-at mh-scan-deleted-msg-regexp)
1042 (looking-at mh-scan-refiled-msg-regexp)
1043 (and (eq mh-next-direction 'forward) (bobp))
1044 (and (eq mh-next-direction 'backward)
1045 (save-excursion (forward-line) (eobp)))))
1046 (forward-line (if (eq mh-next-direction 'forward) -1 1)))
1047 (if (or (looking-at mh-scan-deleted-msg-regexp)
1048 (looking-at mh-scan-refiled-msg-regexp))
1049 (progn
1050 (mh-undo-msg (mh-get-msg-num t))
1051 (mh-maybe-show))
1052 (goto-char original-position)
1053 (error "Nothing to undo"))))
a66894d8 1054 (t (mh-iterate-on-range () range
924df208 1055 (mh-undo-msg nil))))
c26cf6c8
RS
1056 (if (not (mh-outstanding-commands-p))
1057 (mh-set-folder-modified-p nil)))
1058
f0d73c14 1059
c3d9274a
BW
1060(defun mh-folder-line-matches-show-buffer-p ()
1061 "Return t if the message under point in folder-mode is in the show buffer.
1062Return nil in any other circumstance (no message under point, no show buffer,
1063the message in the show buffer doesn't match."
1064 (and (eq major-mode 'mh-folder-mode)
1065 (mh-get-msg-num nil)
1066 mh-show-buffer
1067 (get-buffer mh-show-buffer)
1068 (buffer-file-name (get-buffer mh-show-buffer))
1069 (string-match ".*/\\([0-9]+\\)$"
1070 (buffer-file-name (get-buffer mh-show-buffer)))
1071 (string-equal
1072 (match-string 1 (buffer-file-name (get-buffer mh-show-buffer)))
1073 (int-to-string (mh-get-msg-num nil)))))
1074
1075(eval-when-compile (require 'gnus))
1076
1077(defmacro mh-macro-expansion-time-gnus-version ()
1078 "Return Gnus version available at macro expansion time.
1079The macro evaluates the Gnus version at macro expansion time. If MH-E was
1080compiled then macro expansion happens at compile time."
1081 gnus-version)
1082
1083(defun mh-run-time-gnus-version ()
1084 "Return Gnus version available at run time."
1085 (require 'gnus)
1086 gnus-version)
1087
847b8219 1088;;;###autoload
c26cf6c8 1089(defun mh-version ()
bdcfe844 1090 "Display version information about MH-E and the MH mail handling system."
c26cf6c8 1091 (interactive)
3d7ca223 1092 (set-buffer (get-buffer-create mh-info-buffer))
c26cf6c8 1093 (erase-buffer)
c3d9274a
BW
1094 ;; MH-E version.
1095 (insert "MH-E " mh-version "\n\n")
1096 ;; MH-E compilation details.
1097 (insert "MH-E compilation details:\n")
1098 (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version)))
1099 (gnus-compiled-version (if compiled-mhe
1100 (mh-macro-expansion-time-gnus-version)
1101 "N/A")))
1102 (insert " Byte compiled:\t\t" (if compiled-mhe "yes" "no") "\n"
1103 " Gnus (compile-time):\t" gnus-compiled-version "\n"
1104 " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
1105 ;; Emacs version.
1106 (insert (emacs-version) "\n\n")
a1b4049d 1107 ;; MH version.
f0d73c14
BW
1108 (if mh-variant-in-use
1109 (insert mh-variant-in-use "\n"
1110 " mh-progs:\t" mh-progs "\n"
1111 " mh-lib:\t" mh-lib "\n"
1112 " mh-lib-progs:\t" mh-lib-progs "\n\n")
1113 (insert "No MH variant detected\n"))
a1b4049d
BW
1114 ;; Linux version.
1115 (condition-case ()
1116 (call-process "uname" nil t nil "-a")
1117 (file-error))
1118 (goto-char (point-min))
3d7ca223 1119 (display-buffer mh-info-buffer))
c26cf6c8 1120
3d7ca223
BW
1121(defun mh-parse-flist-output-line (line &optional current-folder)
1122 "Parse LINE to generate folder name, unseen messages and total messages.
1123If CURRENT-FOLDER is non-nil then it contains the current folder name and it is
1124used to avoid problems in corner cases involving folders whose names end with a
1125'+' character."
c3d9274a
BW
1126 (with-temp-buffer
1127 (insert line)
1128 (goto-char (point-max))
1129 (let (folder unseen total p)
1130 (when (search-backward " out of " (point-min) t)
1131 (setq total (read-from-string
1132 (buffer-substring-no-properties
1133 (match-end 0) (line-end-position))))
1134 (when (search-backward " in sequence " (point-min) t)
1135 (setq p (point))
1136 (when (search-backward " has " (point-min) t)
1137 (setq unseen (read-from-string (buffer-substring-no-properties
1138 (match-end 0) p)))
3d7ca223 1139 (while (eq (char-after) ? )
c3d9274a
BW
1140 (backward-char))
1141 (setq folder (buffer-substring-no-properties
1142 (point-min) (1+ (point))))
3d7ca223
BW
1143 (when (and (equal (aref folder (1- (length folder))) ?+)
1144 (equal current-folder folder))
1145 (setq folder (substring folder 0 (1- (length folder)))))
c3d9274a
BW
1146 (values (format "+%s" folder) (car unseen) (car total))))))))
1147
a66894d8
BW
1148(defun mh-folder-size-folder (folder)
1149 "Find size of FOLDER using `folder'."
1150 (with-temp-buffer
1151 (let ((u (length (cdr (assoc mh-unseen-seq
1152 (mh-read-folder-sequences folder nil))))))
1153 (call-process (expand-file-name "folder" mh-progs) nil t nil
1154 "-norecurse" folder)
1155 (goto-char (point-min))
1156 (if (re-search-forward " has \\([0-9]+\\) " nil t)
1157 (values (car (read-from-string (match-string 1))) u folder)
1158 (values 0 u folder)))))
1159
1160(defun mh-folder-size-flist (folder)
1161 "Find size of FOLDER using `flist'."
c3d9274a 1162 (with-temp-buffer
f0d73c14 1163 (call-process (expand-file-name "flist" mh-progs) nil t nil "-showzero"
3d7ca223 1164 "-norecurse" folder "-sequence" (symbol-name mh-unseen-seq))
c3d9274a 1165 (goto-char (point-min))
924df208 1166 (multiple-value-bind (folder unseen total)
c3d9274a
BW
1167 (mh-parse-flist-output-line
1168 (buffer-substring (point) (line-end-position)))
924df208 1169 (values total unseen folder))))
c3d9274a 1170
a66894d8
BW
1171(defun mh-folder-size (folder)
1172 "Find size of FOLDER."
1173 (if mh-flists-present-flag
1174 (mh-folder-size-flist folder)
1175 (mh-folder-size-folder folder)))
1176
c3d9274a 1177(defun mh-visit-folder (folder &optional range index-data)
847b8219 1178 "Visit FOLDER and display RANGE of messages.
c3d9274a
BW
1179Do not call this function from outside MH-E; see \\[mh-rmail] instead.
1180
1181If RANGE is nil (the default if it is omitted when called non-interactively),
1182then all messages in FOLDER are displayed.
1183
1184If an index buffer is being created then INDEX-DATA is used to initialize the
3d7ca223
BW
1185index buffer specific data structures.
1186
1187A prefix argument will cause a prompt for the RANGE of messages
1188regardless of the size of the `mh-large-folder' variable."
c3d9274a 1189 (interactive (let ((folder-name (mh-prompt-for-folder "Visit" mh-inbox t)))
3d7ca223 1190 (list folder-name
a66894d8
BW
1191 (mh-read-range "Scan" folder-name t nil
1192 current-prefix-arg
1193 mh-interpret-number-as-range-flag))))
c3d9274a 1194 (let ((config (current-window-configuration))
924df208 1195 (current-buffer (current-buffer))
c3d9274a 1196 (threaded-view-flag mh-show-threads-flag))
f0d73c14 1197 (delete-other-windows)
c3d9274a
BW
1198 (save-excursion
1199 (when (get-buffer folder)
1200 (set-buffer folder)
924df208 1201 (setq threaded-view-flag (memq 'unthread mh-view-ops))))
c3d9274a
BW
1202 (when index-data
1203 (mh-make-folder folder)
1204 (setq mh-index-data (car index-data)
1205 mh-index-msg-checksum-map (make-hash-table :test #'equal)
1206 mh-index-checksum-origin-map (make-hash-table :test #'equal))
a66894d8
BW
1207 (mh-index-update-maps folder (cadr index-data))
1208 (mh-index-create-sequences))
c26cf6c8 1209 (mh-scan-folder folder (or range "all"))
c3d9274a
BW
1210 (cond ((and threaded-view-flag
1211 (save-excursion
1212 (goto-char (point-min))
1213 (or (null mh-large-folder)
a66894d8 1214 (not (equal (forward-line (1+ mh-large-folder)) 0))
c3d9274a
BW
1215 (and (message "Not threading since the number of messages exceeds `mh-large-folder'")
1216 nil))))
1217 (mh-toggle-threads))
1218 (mh-index-data
1219 (mh-index-insert-folder-headers)))
924df208
BW
1220 (unless (eq current-buffer (current-buffer))
1221 (setq mh-previous-window-config config)))
c26cf6c8
RS
1222 nil)
1223
f0d73c14 1224
847b8219 1225(defun mh-update-sequences ()
bdcfe844
BW
1226 "Update MH's Unseen-Sequence and current folder and message.
1227Flush MH-E's state out to MH. The message at the cursor becomes current."
847b8219
KH
1228 (interactive)
1229 ;; mh-update-sequences is the opposite of mh-read-folder-sequences,
bdcfe844 1230 ;; which updates MH-E's state from MH.
847b8219 1231 (let ((folder-set (mh-update-unseen))
c3d9274a 1232 (new-cur (mh-get-msg-num nil)))
847b8219 1233 (if new-cur
c3d9274a
BW
1234 (let ((seq-entry (mh-find-seq 'cur)))
1235 (mh-remove-cur-notation)
1236 (setcdr seq-entry
1237 (list new-cur)) ;delete-seq-locally, add-msgs-to-seq
1238 (mh-define-sequence 'cur (list new-cur))
1239 (beginning-of-line)
1240 (if (looking-at mh-scan-good-msg-regexp)
3d7ca223 1241 (mh-notate-cur)))
847b8219 1242 (or folder-set
c3d9274a 1243 (save-excursion
a1b4049d
BW
1244 ;; psg - mh-current-folder is nil if mh-summary-height < 4 !
1245 ;; So I added this sanity check.
1246 (if (stringp mh-current-folder)
1247 (mh-exec-cmd-quiet t "folder" mh-current-folder "-fast")
1248 (mh-exec-cmd-quiet t "folder" "-fast")))))))
847b8219 1249
c26cf6c8
RS
1250\f
1251
1252;;; Support routines.
1253
1254(defun mh-delete-a-msg (msg)
bdcfe844 1255 "Delete the MSG.
3d7ca223
BW
1256If MSG is nil then the message at point is deleted.
1257
bdcfe844
BW
1258The value of `mh-delete-msg-hook' is a list of functions to be called, with no
1259arguments, after the message has been deleted."
c26cf6c8 1260 (save-excursion
3d7ca223
BW
1261 (if (numberp msg)
1262 (mh-goto-msg msg nil t)
1263 (beginning-of-line)
1264 (setq msg (mh-get-msg-num t)))
a1b4049d 1265 (if (looking-at mh-scan-refiled-msg-regexp)
c3d9274a 1266 (error "Message %d is refiled. Undo refile before deleting" msg))
a1b4049d 1267 (if (looking-at mh-scan-deleted-msg-regexp)
c3d9274a
BW
1268 nil
1269 (mh-set-folder-modified-p t)
1270 (setq mh-delete-list (cons msg mh-delete-list))
3d7ca223 1271 (mh-notate nil mh-note-deleted mh-cmd-note)
c3d9274a 1272 (run-hooks 'mh-delete-msg-hook))))
c26cf6c8 1273
bdcfe844
BW
1274(defun mh-refile-a-msg (msg folder)
1275 "Refile MSG in FOLDER.
3d7ca223
BW
1276If MSG is nil then the message at point is refiled.
1277
bdcfe844
BW
1278Folder is a symbol, not a string.
1279The value of `mh-refile-msg-hook' is a list of functions to be called, with no
1280arguments, after the message has been refiled."
c26cf6c8 1281 (save-excursion
3d7ca223
BW
1282 (if (numberp msg)
1283 (mh-goto-msg msg nil t)
1284 (beginning-of-line)
1285 (setq msg (mh-get-msg-num t)))
a1b4049d 1286 (cond ((looking-at mh-scan-deleted-msg-regexp)
c3d9274a
BW
1287 (error "Message %d is deleted. Undo delete before moving" msg))
1288 ((looking-at mh-scan-refiled-msg-regexp)
1289 (if (y-or-n-p
1290 (format "Message %d already refiled. Copy to %s as well? "
1291 msg folder))
1292 (mh-exec-cmd "refile" (mh-get-msg-num t) "-link"
1293 "-src" mh-current-folder
1294 (symbol-name folder))
f0d73c14 1295 (message "Message not copied")))
c3d9274a
BW
1296 (t
1297 (mh-set-folder-modified-p t)
1298 (cond ((null (assoc folder mh-refile-list))
1299 (push (list folder msg) mh-refile-list))
1300 ((not (member msg (cdr (assoc folder mh-refile-list))))
1301 (push msg (cdr (assoc folder mh-refile-list)))))
3d7ca223 1302 (mh-notate nil mh-note-refiled mh-cmd-note)
c3d9274a 1303 (run-hooks 'mh-refile-msg-hook)))))
c26cf6c8 1304
924df208
BW
1305(defun mh-next-msg (&optional wait-after-complaining-flag)
1306 "Move backward or forward to the next undeleted message in the buffer.
1307If optional argument WAIT-AFTER-COMPLAINING-FLAG is non-nil and we are at the
1308last message, then wait for a second after telling the user that there aren't
1309any more unread messages."
c26cf6c8 1310 (if (eq mh-next-direction 'forward)
924df208
BW
1311 (mh-next-undeleted-msg 1 wait-after-complaining-flag)
1312 (mh-previous-undeleted-msg 1 wait-after-complaining-flag)))
c3d9274a
BW
1313
1314(defun mh-next-unread-msg (&optional count)
1315 "Move to next unread message.
1316With optional argument COUNT, COUNT-1 unread messages are skipped."
1317 (interactive "p")
1318 (unless (> count 0)
1319 (error "The function mh-next-unread-msg expects positive argument"))
1320 (setq count (1- count))
1321 (let ((unread-sequence (reverse (cdr (assoc mh-unseen-seq mh-seq-list))))
1322 (cur-msg (mh-get-msg-num nil)))
1323 (cond ((and (not cur-msg) (not (bobp))
1324 ;; If we are at the end of the buffer back up one line and go
1325 ;; to unread message after that.
1326 (progn
1327 (forward-line -1)
1328 (setq cur-msg (mh-get-msg-num nil)))
1329 nil))
1330 ((or (null unread-sequence) (not cur-msg))
1331 ;; No unread message or there aren't any messages in buffer...
1332 (message "No more unread messages"))
1333 ((progn
1334 ;; Skip messages
1335 (while (and unread-sequence (>= cur-msg (car unread-sequence)))
1336 (setq unread-sequence (cdr unread-sequence)))
1337 (while (> count 0)
1338 (setq unread-sequence (cdr unread-sequence))
1339 (setq count (1- count)))
1340 (not (car unread-sequence)))
1341 (message "No more unread messages"))
f0d73c14
BW
1342 (t (loop for msg in unread-sequence
1343 when (mh-goto-msg msg t) return nil
1344 finally (message "No more unread messages"))))))
c26cf6c8 1345
c26cf6c8 1346(defun mh-set-scan-mode ()
bdcfe844 1347 "Display the scan listing buffer, but do not show a message."
c26cf6c8
RS
1348 (if (get-buffer mh-show-buffer)
1349 (delete-windows-on mh-show-buffer))
a1b4049d 1350 (mh-showing-mode 0)
dc9bdc98 1351 (force-mode-line-update)
bdcfe844 1352 (if mh-recenter-summary-flag
c26cf6c8
RS
1353 (mh-recenter nil)))
1354
c26cf6c8 1355(defun mh-undo-msg (msg)
3d7ca223
BW
1356 "Undo the deletion or refile of one MSG.
1357If MSG is nil then act on the message at point"
1358 (save-excursion
1359 (if (numberp msg)
1360 (mh-goto-msg msg t t)
1361 (beginning-of-line)
1362 (setq msg (mh-get-msg-num t)))
1363 (cond ((memq msg mh-delete-list)
1364 (setq mh-delete-list (delq msg mh-delete-list)))
1365 (t
1366 (dolist (folder-msg-list mh-refile-list)
1367 (setf (cdr folder-msg-list) (remove msg (cdr folder-msg-list))))
1368 (setq mh-refile-list (loop for x in mh-refile-list
1369 unless (null (cdr x)) collect x))))
1370 (mh-notate nil ? mh-cmd-note)))
c26cf6c8 1371
c26cf6c8
RS
1372\f
1373
1374;;; The folder data abstraction.
1375
a66894d8
BW
1376(defvar mh-index-data-file ".mhe_index"
1377 "MH-E specific file where index seach info is stored.")
1378
c26cf6c8 1379(defun mh-make-folder (name)
bdcfe844
BW
1380 "Create a new mail folder called NAME.
1381Make it the current folder."
c26cf6c8
RS
1382 (switch-to-buffer name)
1383 (setq buffer-read-only nil)
1384 (erase-buffer)
bdcfe844
BW
1385 (if mh-adaptive-cmd-note-flag
1386 (mh-set-cmd-note (mh-message-number-width name)))
c26cf6c8
RS
1387 (setq buffer-read-only t)
1388 (mh-folder-mode)
1389 (mh-set-folder-modified-p nil)
847b8219 1390 (setq buffer-file-name mh-folder-filename)
a66894d8
BW
1391 (when (and (not mh-index-data)
1392 (file-exists-p (concat buffer-file-name mh-index-data-file)))
1393 (mh-index-read-data))
847b8219 1394 (mh-make-folder-mode-line))
c26cf6c8 1395
c26cf6c8
RS
1396;;; Ensure new buffers won't get this mode if default-major-mode is nil.
1397(put 'mh-folder-mode 'mode-class 'special)
1398
bdcfe844
BW
1399\f
1400
1401;;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
1402;;; Menus for folder mode: folder, message, sequence (in that order)
1403;;; folder-mode "Sequence" menu
1404(easy-menu-define
1405 mh-folder-sequence-menu mh-folder-mode-map "Menu for MH-E folder-sequence."
1406 '("Sequence"
1407 ["Add Message to Sequence..." mh-put-msg-in-seq (mh-get-msg-num nil)]
1408 ["List Sequences for Message" mh-msg-is-in-seq (mh-get-msg-num nil)]
1409 ["Delete Message from Sequence..." mh-delete-msg-from-seq
1410 (mh-get-msg-num nil)]
1411 ["List Sequences in Folder..." mh-list-sequences t]
1412 ["Delete Sequence..." mh-delete-seq t]
1413 ["Narrow to Sequence..." mh-narrow-to-seq t]
a66894d8 1414 ["Widen from Sequence" mh-widen mh-folder-view-stack]
bdcfe844
BW
1415 "--"
1416 ["Narrow to Subject Sequence" mh-narrow-to-subject t]
924df208
BW
1417 ["Narrow to Tick Sequence" mh-narrow-to-tick
1418 (and mh-tick-seq (mh-seq-msgs (mh-find-seq mh-tick-seq)))]
bdcfe844 1419 ["Delete Rest of Same Subject" mh-delete-subject t]
924df208 1420 ["Toggle Tick Mark" mh-toggle-tick t]
bdcfe844
BW
1421 "--"
1422 ["Push State Out to MH" mh-update-sequences t]))
1423
1424;;; folder-mode "Message" menu
1425(easy-menu-define
1426 mh-folder-message-menu mh-folder-mode-map "Menu for MH-E folder-message."
1427 '("Message"
1428 ["Show Message" mh-show (mh-get-msg-num nil)]
1429 ["Show Message with Header" mh-header-display (mh-get-msg-num nil)]
1430 ["Next Message" mh-next-undeleted-msg t]
1431 ["Previous Message" mh-previous-undeleted-msg t]
1432 ["Go to First Message" mh-first-msg t]
1433 ["Go to Last Message" mh-last-msg t]
1434 ["Go to Message by Number..." mh-goto-msg t]
f0d73c14 1435 ["Modify Message" mh-modify t]
bdcfe844
BW
1436 ["Delete Message" mh-delete-msg (mh-get-msg-num nil)]
1437 ["Refile Message" mh-refile-msg (mh-get-msg-num nil)]
f0d73c14
BW
1438 ["Undo Delete/Refile" mh-undo (mh-outstanding-commands-p)]
1439 ["Execute Delete/Refile" mh-execute-commands
1440 (mh-outstanding-commands-p)]
bdcfe844
BW
1441 "--"
1442 ["Compose a New Message" mh-send t]
1443 ["Reply to Message..." mh-reply (mh-get-msg-num nil)]
1444 ["Forward Message..." mh-forward (mh-get-msg-num nil)]
1445 ["Redistribute Message..." mh-redistribute (mh-get-msg-num nil)]
1446 ["Edit Message Again" mh-edit-again (mh-get-msg-num nil)]
1447 ["Re-edit a Bounced Message" mh-extract-rejected-mail t]
1448 "--"
1449 ["Copy Message to Folder..." mh-copy-msg (mh-get-msg-num nil)]
1450 ["Print Message" mh-print-msg (mh-get-msg-num nil)]
1451 ["Write Message to File..." mh-write-msg-to-file
1452 (mh-get-msg-num nil)]
1453 ["Pipe Message to Command..." mh-pipe-msg (mh-get-msg-num nil)]
1454 ["Unpack Uuencoded Message..." mh-store-msg (mh-get-msg-num nil)]
1455 ["Burst Digest Message" mh-burst-digest (mh-get-msg-num nil)]))
1456
1457;;; folder-mode "Folder" menu
1458(easy-menu-define
1459 mh-folder-folder-menu mh-folder-mode-map "Menu for MH-E folder."
1460 '("Folder"
1461 ["Incorporate New Mail" mh-inc-folder t]
1462 ["Toggle Show/Folder" mh-toggle-showing t]
1463 ["Execute Delete/Refile" mh-execute-commands
f0d73c14 1464 (mh-outstanding-commands-p)]
bdcfe844
BW
1465 ["Rescan Folder" mh-rescan-folder t]
1466 ["Thread Folder" mh-toggle-threads
1467 (not (memq 'unthread mh-view-ops))]
1468 ["Pack Folder" mh-pack-folder t]
1469 ["Sort Folder" mh-sort-folder t]
1470 "--"
1471 ["List Folders" mh-list-folders t]
1472 ["Visit a Folder..." mh-visit-folder t]
924df208 1473 ["View New Messages" mh-index-new-messages t]
bdcfe844
BW
1474 ["Search a Folder..." mh-search-folder t]
1475 ["Indexed Search..." mh-index-search t]
1476 "--"
1477 ["Quit MH-E" mh-quit t]))
1478
1479\f
1480
bdcfe844
BW
1481(defmacro mh-remove-xemacs-horizontal-scrollbar ()
1482 "Get rid of the horizontal scrollbar that XEmacs insists on putting in."
1483 (when mh-xemacs-flag
1484 `(if (and (featurep 'scrollbar)
1485 (fboundp 'set-specifier))
1486 (set-specifier horizontal-scrollbar-visible-p nil
1487 (cons (current-buffer) nil)))))
1488
1489(defmacro mh-write-file-functions-compat ()
1490 "Return `write-file-functions' if it exists.
1491Otherwise return `local-write-file-hooks'. This macro exists purely for
1492compatibility. The former symbol is used in Emacs 21.4 onward while the latter
1493is used in previous versions and XEmacs."
1494 (if (boundp 'write-file-functions)
c3d9274a
BW
1495 ''write-file-functions ;Emacs 21.4
1496 ''local-write-file-hooks)) ;<Emacs 21.4, XEmacs
bdcfe844 1497
a66894d8
BW
1498;; Avoid compiler warnings in non-bleeding edge versions of Emacs.
1499(eval-when-compile
1500 (defvar tool-bar-mode)
1501 (defvar tool-bar-map)
1502 (defvar desktop-save-buffer)) ;Emacs 21.4
924df208 1503
f0d73c14
BW
1504;; Register mh-folder-mode as supporting which-function-mode...
1505(load "which-func" t t)
1506(when (and (boundp 'which-func-modes)
1507 (not (member 'mh-folder-mode which-func-modes)))
1508 (push 'mh-folder-mode which-func-modes))
1509
e6de37c5
LH
1510;; Autoload cookie needed by desktop.el
1511;;;###autoload
a1b4049d 1512(define-derived-mode mh-folder-mode fundamental-mode "MH-Folder"
bdcfe844 1513 "Major MH-E mode for \"editing\" an MH folder scan listing.\\<mh-folder-mode-map>
a1b4049d 1514
c26cf6c8
RS
1515You can show the message the cursor is pointing to, and step through the
1516messages. Messages can be marked for deletion or refiling into another
1517folder; these commands are executed all at once with a separate command.
1518
a1b4049d
BW
1519Options that control this mode can be changed with \\[customize-group];
1520specify the \"mh\" group. In particular, please see the `mh-scan-format-file'
1521option if you wish to modify scan's format.
c26cf6c8 1522
a1b4049d 1523When a folder is visited, the hook `mh-folder-mode-hook' is run.
c26cf6c8 1524
f0d73c14
BW
1525Ranges
1526======
1527Many commands that operate on individual messages, such as `mh-forward' or
1528`mh-refile-msg' take a RANGE argument. This argument can be used in several
1529ways.
1530
1531If you provide the prefix argument (\\[universal-argument]) to these commands,
88a34f43 1532then you will be prompted for the message range. This can be any valid MH
f0d73c14
BW
1533range which can include messages, sequences, and the abbreviations (described
1534in the mh(1) man page):
1535
1536<num1>-<num2>
1537 Indicates all messages in the range <num1> to <num2>, inclusive. The range
1538 must be nonempty.
1539
1540`<num>:N'
1541`<num>:+N'
1542`<num>:-N'
1543 Up to N messages beginning with (or ending with) message num. Num may be
1544 any of the pre-defined symbols: first, prev, cur, next or last.
1545
1546`first:N'
1547`prev:N'
1548`next:N'
1549`last:N'
1550 The first, previous, next or last messages, if they exist.
1551
1552`all'
1553 All of the messages.
1554
1555For example, a range that shows all of these things is `1 2 3 5-10 last:5
1556unseen'.
1557
1558If the option `transient-mark-mode' is set to t and you set a region in the
1559MH-Folder buffer, then the MH-E command will perform the operation on all
1560messages in that region.
1561
a1b4049d 1562\\{mh-folder-mode-map}"
c26cf6c8 1563
2416ec64 1564 (mh-image-load-path)
a1b4049d 1565 (make-local-variable 'font-lock-defaults)
c3d9274a 1566 (setq font-lock-defaults '(mh-folder-font-lock-keywords t))
1983467e
LH
1567 (make-local-variable 'desktop-save-buffer)
1568 (setq desktop-save-buffer t)
847b8219 1569 (mh-make-local-vars
f0d73c14
BW
1570 'mh-colors-available-flag (mh-colors-available-p)
1571 ; Do we have colors available
c3d9274a 1572 'mh-current-folder (buffer-name) ; Name of folder, a string
c26cf6c8 1573 'mh-show-buffer (format "show-%s" (buffer-name)) ; Buffer that displays msgs
c3d9274a 1574 'mh-folder-filename ; e.g. "/usr/foobar/Mail/inbox/"
c26cf6c8 1575 (file-name-as-directory (mh-expand-file-name (buffer-name)))
f0d73c14
BW
1576 'mh-display-buttons-for-inline-parts-flag
1577 mh-display-buttons-for-inline-parts-flag ; Allow for display of buttons to
1578 ; be toggled.
3d7ca223
BW
1579 'mh-arrow-marker (make-marker) ; Marker where arrow is displayed
1580 'overlay-arrow-position nil ; Allow for simultaneous display in
1581 'overlay-arrow-string ">" ; different MH-E buffers.
c3d9274a
BW
1582 'mh-showing-mode nil ; Show message also?
1583 'mh-delete-list nil ; List of msgs nums to delete
1584 'mh-refile-list nil ; List of folder names in mh-seq-list
1585 'mh-seq-list nil ; Alist of (seq . msgs) nums
1586 'mh-seen-list nil ; List of displayed messages
1587 'mh-next-direction 'forward ; Direction to move to next message
bdcfe844
BW
1588 'mh-view-ops () ; Stack that keeps track of the order
1589 ; in which narrowing/threading has been
1590 ; carried out.
a66894d8
BW
1591 'mh-folder-view-stack () ; Stack of previous views of the
1592 ; folder.
c3d9274a
BW
1593 'mh-index-data nil ; If the folder was created by a call
1594 ; to mh-index-search this contains info
1595 ; about the search results.
1596 'mh-index-previous-search nil ; Previous folder and search-regexp
1597 'mh-index-msg-checksum-map nil ; msg -> checksum map
1598 'mh-index-checksum-origin-map nil ; checksum -> ( orig-folder, orig-msg )
a66894d8 1599 'mh-index-sequence-search-flag nil ; folder resulted from sequence search
c3d9274a
BW
1600 'mh-first-msg-num nil ; Number of first msg in buffer
1601 'mh-last-msg-num nil ; Number of last msg in buffer
1602 'mh-msg-count nil ; Number of msgs in buffer
1603 'mh-mode-line-annotation nil ; Indicates message range
a66894d8
BW
1604 'mh-sequence-notation-history (make-hash-table)
1605 ; Remember what is overwritten by
1606 ; mh-note-seq.
f0d73c14
BW
1607 'imenu-create-index-function 'mh-index-create-imenu-index
1608 ; Setup imenu support
c3d9274a 1609 'mh-previous-window-config nil) ; Previous window configuration
bdcfe844 1610 (mh-remove-xemacs-horizontal-scrollbar)
c26cf6c8
RS
1611 (setq truncate-lines t)
1612 (auto-save-mode -1)
1613 (setq buffer-offer-save t)
924df208 1614 (mh-make-local-hook (mh-write-file-functions-compat))
bdcfe844 1615 (add-hook (mh-write-file-functions-compat) 'mh-execute-commands nil t)
c26cf6c8 1616 (make-local-variable 'revert-buffer-function)
c3d9274a 1617 (make-local-variable 'hl-line-mode) ; avoid pollution
924df208 1618 (mh-funcall-if-exists hl-line-mode 1)
c26cf6c8 1619 (setq revert-buffer-function 'mh-undo-folder)
a1b4049d 1620 (or (assq 'mh-showing-mode minor-mode-alist)
c26cf6c8 1621 (setq minor-mode-alist
c3d9274a 1622 (cons '(mh-showing-mode " Show") minor-mode-alist)))
a1b4049d
BW
1623 (easy-menu-add mh-folder-sequence-menu)
1624 (easy-menu-add mh-folder-message-menu)
1625 (easy-menu-add mh-folder-folder-menu)
a66894d8 1626 (set (make-local-variable 'tool-bar-map) mh-folder-tool-bar-map)
924df208 1627 (mh-funcall-if-exists mh-toolbar-init :folder)
bdcfe844 1628 (if (and mh-xemacs-flag
c3d9274a
BW
1629 font-lock-auto-fontify)
1630 (turn-on-font-lock))) ; Force font-lock in XEmacs.
c26cf6c8 1631
f0d73c14
BW
1632(defun mh-toggle-mime-buttons ()
1633 "Toggle display of buttons for inline MIME parts."
1634 (interactive)
1635 (setq mh-display-buttons-for-inline-parts-flag
1636 (not mh-display-buttons-for-inline-parts-flag))
1637 (mh-show nil t))
1638
1639(defun mh-colors-available-p ()
1640 "Check if colors are available in the Emacs being used."
1641 (or mh-xemacs-flag
1642 (let ((color-cells
1643 (or (ignore-errors (mh-funcall-if-exists display-color-cells))
1644 (ignore-errors (mh-funcall-if-exists
1645 x-display-color-cells)))))
1646 (and (numberp color-cells) (>= color-cells 8)))))
1647
1648(defun mh-colors-in-use-p ()
1649 "Check if colors are being used in the folder buffer."
1650 (and mh-colors-available-flag font-lock-mode))
1651
847b8219 1652(defun mh-make-local-vars (&rest pairs)
bdcfe844
BW
1653 "Initialize local variables according to the variable-value PAIRS."
1654
c26cf6c8 1655 (while pairs
1e495fc7 1656 (set (make-local-variable (car pairs)) (car (cdr pairs)))
c26cf6c8
RS
1657 (setq pairs (cdr (cdr pairs)))))
1658
a66894d8
BW
1659(defun mh-restore-desktop-buffer (desktop-buffer-file-name
1660 desktop-buffer-name
1661 desktop-buffer-misc)
f0d73c14
BW
1662 "Restore an MH folder buffer specified in a desktop file.
1663When desktop creates a buffer, DESKTOP-BUFFER-FILE-NAME holds the file name to
1664visit, DESKTOP-BUFFER-NAME holds the desired buffer name, and
1665DESKTOP-BUFFER-MISC holds a list of miscellaneous info used by the
1666`desktop-buffer-handlers' functions."
a66894d8
BW
1667 (mh-find-path)
1668 (mh-visit-folder desktop-buffer-name)
1669 (current-buffer))
1670
a05fcb7d
BW
1671;;; desktop-buffer-mode-handlers appeared in Emacs 22.
1672(if (fboundp 'desktop-buffer-mode-handlers)
1673 (add-to-list 'desktop-buffer-mode-handlers
1674 '(mh-folder-mode . mh-restore-desktop-buffer)))
e6de37c5 1675
bdcfe844
BW
1676(defun mh-scan-folder (folder range &optional dont-exec-pending)
1677 "Scan the FOLDER over the RANGE.
1678If the optional argument DONT-EXEC-PENDING is non-nil then pending deletes and
1679refiles aren't carried out.
1680Return in the folder's buffer."
f0d73c14
BW
1681 (when (stringp range)
1682 (setq range (delete "" (split-string range "[ \t\n]"))))
c26cf6c8 1683 (cond ((null (get-buffer folder))
c3d9274a
BW
1684 (mh-make-folder folder))
1685 (t
924df208
BW
1686 (unless dont-exec-pending
1687 (mh-process-or-undo-commands folder)
1688 (mh-reset-threads-and-narrowing))
c3d9274a 1689 (switch-to-buffer folder)))
c26cf6c8 1690 (mh-regenerate-headers range)
a1b4049d 1691 (if (zerop (buffer-size))
bdcfe844 1692 (if (equal range "all")
c3d9274a
BW
1693 (message "Folder %s is empty" folder)
1694 (message "No messages in %s, range %s" folder range))
bdcfe844 1695 (mh-goto-cur-msg))
924df208 1696 (when (mh-outstanding-commands-p)
3d7ca223 1697 (mh-notate-deleted-and-refiled)))
c26cf6c8 1698
c3d9274a
BW
1699(defun mh-set-cmd-note (width)
1700 "Set `mh-cmd-note' to WIDTH characters (minimum of 2).
1701
1702If `mh-scan-format-file' specifies nil or a filename, then this function
1703will NOT update `mh-cmd-note'."
1704 ;; Add one to the width to always have whitespace in column zero.
1705 (setq width (max (1+ width) 2))
1706 (if (and (equal mh-scan-format-file t)
1707 (not (eq mh-cmd-note width)))
1708 (setq mh-cmd-note width))
1709 mh-cmd-note)
1710
847b8219 1711(defun mh-regenerate-headers (range &optional update)
bdcfe844
BW
1712 "Scan folder over range RANGE.
1713If UPDATE, append the scan lines, otherwise replace."
847b8219 1714 (let ((folder mh-current-folder)
bdcfe844 1715 (range (if (and range (atom range)) (list range) range))
c3d9274a 1716 scan-start)
c26cf6c8 1717 (message "Scanning %s..." folder)
a66894d8 1718 (mh-remove-all-notation)
c26cf6c8 1719 (with-mh-folder-updating (nil)
847b8219 1720 (if update
c3d9274a
BW
1721 (goto-char (point-max))
1722 (delete-region (point-min) (point-max))
1723 (if mh-adaptive-cmd-note-flag
1724 (mh-set-cmd-note (mh-message-number-width folder))))
847b8219 1725 (setq scan-start (point))
bdcfe844
BW
1726 (apply #'mh-exec-cmd-output
1727 mh-scan-prog nil
1728 (mh-scan-format)
1729 "-noclear" "-noheader"
1730 "-width" (window-width)
1731 folder range)
847b8219 1732 (goto-char scan-start)
c26cf6c8 1733 (cond ((looking-at "scan: no messages in")
c3d9274a 1734 (keep-lines mh-scan-valid-regexp)) ; Flush random scan lines
f0d73c14
BW
1735 ((looking-at (if (mh-variant-p 'mu-mh)
1736 "scan: message set .* does not exist"
1737 "scan: bad message list "))
c3d9274a
BW
1738 (keep-lines mh-scan-valid-regexp))
1739 ((looking-at "scan: ")) ; Keep error messages
1740 (t
1741 (keep-lines mh-scan-valid-regexp))) ; Flush random scan lines
c26cf6c8
RS
1742 (setq mh-seq-list (mh-read-folder-sequences folder nil))
1743 (mh-notate-user-sequences)
847b8219 1744 (or update
c3d9274a
BW
1745 (setq mh-mode-line-annotation
1746 (if (equal range '("all"))
1747 nil
1748 mh-partial-folder-mode-line-annotation)))
847b8219 1749 (mh-make-folder-mode-line))
c26cf6c8
RS
1750 (message "Scanning %s...done" folder)))
1751
bdcfe844
BW
1752(defun mh-generate-new-cmd-note (folder)
1753 "Fix the `mh-cmd-note' value for this FOLDER.
1754
1755After doing an `mh-get-new-mail' operation in this FOLDER, at least
1756one line that looks like a truncated message number was found.
1757
1758Remove the text added by the last `mh-inc' command. It should be the
1759messages cur-last. Call `mh-set-cmd-note' with the widest message number
1760in FOLDER.
1761
1762Reformat the message number width on each line in the buffer and trim
1763the line length to fit in the window.
1764
1765Rescan the FOLDER in the range cur-last in order to display the
1766messages that were removed earlier. They should all fit in the scan
1767line now with no message truncation."
1768 (save-excursion
1769 (let ((maxcol (1- (window-width)))
1770 (old-cmd-note mh-cmd-note)
c3d9274a
BW
1771 mh-cmd-note-fmt
1772 msgnum)
bdcfe844
BW
1773 ;; Nuke all of the lines just added by the last inc
1774 (delete-char (- (point-max) (point)))
1775 ;; Update the current buffer to reflect the new mh-cmd-note
1776 ;; value needed to display messages.
1777 (mh-set-cmd-note (mh-message-number-width folder))
1778 (setq mh-cmd-note-fmt (concat "%" (format "%d" mh-cmd-note) "d"))
1779 ;; Cleanup the messages that are in the buffer right now
1780 (goto-char (point-min))
1781 (cond ((memq 'unthread mh-view-ops)
1782 (mh-thread-add-spaces (- mh-cmd-note old-cmd-note)))
1783 (t (while (re-search-forward mh-scan-msg-number-regexp nil 0 1)
1784 ;; reformat the number to fix in mh-cmd-note columns
1785 (setq msgnum (string-to-number
1786 (buffer-substring
1787 (match-beginning 1) (match-end 1))))
1788 (replace-match (format mh-cmd-note-fmt msgnum))
1789 ;; trim the line to fix in the window
1790 (end-of-line)
1791 (let ((eol (point)))
1792 (move-to-column maxcol)
1793 (if (<= (point) eol)
c3d9274a 1794 (delete-char (- eol (point))))))))
bdcfe844
BW
1795 ;; now re-read the lost messages
1796 (goto-char (point-max))
1797 (prog1 (point)
1798 (mh-regenerate-headers "cur-last" t)))))
c26cf6c8
RS
1799
1800(defun mh-get-new-mail (maildrop-name)
bdcfe844
BW
1801 "Read new mail from MAILDROP-NAME into the current buffer.
1802Return in the current buffer."
c26cf6c8 1803 (let ((point-before-inc (point))
c3d9274a
BW
1804 (folder mh-current-folder)
1805 (new-mail-flag nil))
c26cf6c8 1806 (with-mh-folder-updating (t)
f965c3d7 1807 (if maildrop-name
c3d9274a
BW
1808 (message "inc %s -file %s..." folder maildrop-name)
1809 (message "inc %s..." folder))
c26cf6c8
RS
1810 (setq mh-next-direction 'forward)
1811 (goto-char (point-max))
e495eaec 1812 (mh-remove-cur-notation)
c26cf6c8 1813 (let ((start-of-inc (point)))
c3d9274a
BW
1814 (if maildrop-name
1815 ;; I think MH 5 used "-ms-file" instead of "-file",
1816 ;; which would make inc'ing from maildrops fail.
1817 (mh-exec-cmd-output mh-inc-prog nil folder
1818 (mh-scan-format)
1819 "-file" (expand-file-name maildrop-name)
1820 "-width" (window-width)
1821 "-truncate")
bdcfe844
BW
1822 (mh-exec-cmd-output mh-inc-prog nil
1823 (mh-scan-format)
1824 "-width" (window-width)))
c3d9274a
BW
1825 (if maildrop-name
1826 (message "inc %s -file %s...done" folder maildrop-name)
1827 (message "inc %s...done" folder))
1828 (goto-char start-of-inc)
1829 (cond ((save-excursion
1830 (re-search-forward "^inc: no mail" nil t))
1831 (message "No new mail%s%s" (if maildrop-name " in " "")
1832 (if maildrop-name maildrop-name "")))
a66894d8 1833 ((and (when mh-folder-view-stack
bdcfe844
BW
1834 (let ((saved-text (buffer-substring-no-properties
1835 start-of-inc (point-max))))
1836 (delete-region start-of-inc (point-max))
a66894d8 1837 (unwind-protect (mh-widen t)
e495eaec 1838 (mh-remove-cur-notation)
bdcfe844
BW
1839 (goto-char (point-max))
1840 (setq start-of-inc (point))
1841 (insert saved-text)
1842 (goto-char start-of-inc))))
1843 nil))
1844 ((re-search-forward "^inc:" nil t) ; Error messages
c3d9274a
BW
1845 (error "Error incorporating mail"))
1846 ((and
1847 (equal mh-scan-format-file t)
1848 mh-adaptive-cmd-note-flag
1849 ;; Have we reached an edge condition?
1850 (save-excursion
1851 (re-search-forward mh-scan-msg-overflow-regexp nil 0 1))
1852 (setq start-of-inc (mh-generate-new-cmd-note folder))
1853 nil))
1854 (t
1855 (setq new-mail-flag t)))
1856 (keep-lines mh-scan-valid-regexp) ; Flush random scan lines
e495eaec
BW
1857 (let* ((sequences (mh-read-folder-sequences folder t))
1858 (new-cur (assoc 'cur sequences))
1859 (new-unseen (assoc mh-unseen-seq sequences)))
1860 (unless (assoc 'cur mh-seq-list)
1861 (push (list 'cur) mh-seq-list))
1862 (unless (assoc mh-unseen-seq mh-seq-list)
1863 (push (list mh-unseen-seq) mh-seq-list))
1864 (setcdr (assoc 'cur mh-seq-list) (cdr new-cur))
1865 (setcdr (assoc mh-unseen-seq mh-seq-list) (cdr new-unseen)))
c3d9274a 1866 (when (equal (point-max) start-of-inc)
3d7ca223 1867 (mh-notate-cur))
c3d9274a
BW
1868 (if new-mail-flag
1869 (progn
1870 (mh-make-folder-mode-line)
924df208
BW
1871 (when (mh-speed-flists-active-p)
1872 (mh-speed-flists t mh-current-folder))
bdcfe844
BW
1873 (when (memq 'unthread mh-view-ops)
1874 (mh-thread-inc folder start-of-inc))
c3d9274a 1875 (mh-goto-cur-msg))
a66894d8 1876 (goto-char point-before-inc))
e495eaec 1877 (mh-notate-user-sequences (cons start-of-inc (point-max)))))))
c26cf6c8 1878
847b8219 1879(defun mh-make-folder-mode-line (&optional ignored)
bdcfe844
BW
1880 "Set the fields of the mode line for a folder buffer.
1881The optional argument is now obsolete and IGNORED. It used to be used to pass
1882in what is now stored in the buffer-local variable `mh-mode-line-annotation'."
c26cf6c8 1883 (save-excursion
bdcfe844
BW
1884 (save-window-excursion
1885 (mh-first-msg)
1886 (let ((new-first-msg-num (mh-get-msg-num nil)))
c3d9274a
BW
1887 (when (or (not (memq 'unthread mh-view-ops))
1888 (null mh-first-msg-num)
1889 (null new-first-msg-num)
1890 (< new-first-msg-num mh-first-msg-num))
1891 (setq mh-first-msg-num new-first-msg-num)))
bdcfe844
BW
1892 (mh-last-msg)
1893 (let ((new-last-msg-num (mh-get-msg-num nil)))
c3d9274a
BW
1894 (when (or (not (memq 'unthread mh-view-ops))
1895 (null mh-last-msg-num)
1896 (null new-last-msg-num)
1897 (> new-last-msg-num mh-last-msg-num))
1898 (setq mh-last-msg-num new-last-msg-num)))
bdcfe844 1899 (setq mh-msg-count (if mh-first-msg-num
c3d9274a
BW
1900 (count-lines (point-min) (point-max))
1901 0))
bdcfe844 1902 (setq mode-line-buffer-identification
3d7ca223 1903 (list (format " {%%b%s} %s msg%s"
c3d9274a
BW
1904 (if mh-mode-line-annotation
1905 (format "/%s" mh-mode-line-annotation)
1906 "")
1907 (if (zerop mh-msg-count)
1908 "no"
1909 (format "%d" mh-msg-count))
1910 (if (zerop mh-msg-count)
1911 "s"
1912 (cond ((> mh-msg-count 1)
1913 (format "s (%d-%d)" mh-first-msg-num
1914 mh-last-msg-num))
1915 (mh-first-msg-num
1916 (format " (%d)" mh-first-msg-num))
3d7ca223
BW
1917 (""))))))
1918 (mh-logo-display))))
c26cf6c8 1919
a66894d8
BW
1920(defun mh-add-sequence-notation (msg internal-seq-flag)
1921 "Add sequence notation to the MSG on the current line.
f0d73c14
BW
1922If INTERNAL-SEQ-FLAG is non-nil, then refontify the scan line if font-lock is
1923turned on."
a66894d8
BW
1924 (with-mh-folder-updating (t)
1925 (save-excursion
1926 (beginning-of-line)
1927 (if internal-seq-flag
f0d73c14
BW
1928 (progn
1929 ;; Change the buffer so that if transient-mark-mode is active
1930 ;; and there is an active region it will get deactivated as in
1931 ;; the case of user sequences.
1932 (mh-notate nil nil mh-cmd-note)
1933 (when font-lock-mode
1934 (font-lock-fontify-region (point) (line-end-position))))
a66894d8
BW
1935 (forward-char (1+ mh-cmd-note))
1936 (let ((stack (gethash msg mh-sequence-notation-history)))
1937 (setf (gethash msg mh-sequence-notation-history)
1938 (cons (char-after) stack)))
1939 (mh-notate nil mh-note-seq (1+ mh-cmd-note))))))
1940
1941(defun mh-remove-sequence-notation (msg internal-seq-flag &optional all)
1942 "Remove sequence notation from the MSG on the current line.
1943If INTERNAL-SEQ-FLAG is non-nil, then `font-lock' was used to highlight the
1944sequence. In that case, no notation needs to be removed. Otherwise the effect
1945of inserting `mh-note-seq' needs to be reversed.
1946If ALL is non-nil, then all sequence marks on the scan line are removed."
1947 (with-mh-folder-updating (t)
1948 ;; This takes care of internal sequences...
1949 (mh-notate nil nil mh-cmd-note)
1950 (unless internal-seq-flag
1951 ;; ... and this takes care of user sequences.
1952 (let ((stack (gethash msg mh-sequence-notation-history)))
1953 (while (and all (cdr stack))
1954 (setq stack (cdr stack)))
1955 (when stack
f0d73c14
BW
1956 (save-excursion
1957 (beginning-of-line)
1958 (forward-char (1+ mh-cmd-note))
1959 (delete-char 1)
1960 (insert (car stack))))
a66894d8
BW
1961 (setf (gethash msg mh-sequence-notation-history) (cdr stack))))))
1962
847b8219 1963(defun mh-remove-cur-notation ()
bdcfe844 1964 "Remove old cur notation."
847b8219
KH
1965 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
1966 (save-excursion
3d7ca223
BW
1967 (when (and cur-msg
1968 (mh-goto-msg cur-msg t t)
1969 (looking-at mh-scan-cur-msg-number-regexp))
1970 (mh-notate nil ? mh-cmd-note)
1971 (setq overlay-arrow-position nil)))))
847b8219 1972
bdcfe844
BW
1973(defun mh-remove-all-notation ()
1974 "Remove all notations on all scan lines that MH-E introduces."
1975 (save-excursion
3d7ca223 1976 (setq overlay-arrow-position nil)
bdcfe844 1977 (goto-char (point-min))
a66894d8
BW
1978 (mh-iterate-on-range msg (cons (point-min) (point-max))
1979 (mh-notate nil ? mh-cmd-note)
1980 (mh-remove-sequence-notation msg nil t))
1981 (clrhash mh-sequence-notation-history)))
bdcfe844 1982
f0d73c14 1983
bdcfe844
BW
1984(defun mh-goto-cur-msg (&optional minimal-changes-flag)
1985 "Position the cursor at the current message.
1986When optional argument MINIMAL-CHANGES-FLAG is non-nil, the function doesn't
1987recenter the folder buffer."
c26cf6c8
RS
1988 (let ((cur-msg (car (mh-seq-to-msgs 'cur))))
1989 (cond ((and cur-msg
c3d9274a
BW
1990 (mh-goto-msg cur-msg t t))
1991 (unless minimal-changes-flag
3d7ca223 1992 (mh-notate-cur)
bdcfe844
BW
1993 (mh-recenter 0)
1994 (mh-maybe-show cur-msg)))
c3d9274a 1995 (t
3d7ca223 1996 (setq overlay-arrow-position nil)
c3d9274a 1997 (message "No current message")))))
c26cf6c8 1998
c26cf6c8 1999(defun mh-process-or-undo-commands (folder)
bdcfe844
BW
2000 "If FOLDER has outstanding commands, then either process or discard them.
2001Called by functions like `mh-sort-folder', so also invalidate show buffer."
c26cf6c8
RS
2002 (set-buffer folder)
2003 (if (mh-outstanding-commands-p)
bdcfe844 2004 (if (or mh-do-not-confirm-flag
c3d9274a 2005 (y-or-n-p
924df208 2006 "Process outstanding deletes and refiles? "))
c3d9274a 2007 (mh-process-commands folder)
924df208 2008 (set-buffer folder)
c3d9274a 2009 (mh-undo-folder)))
c26cf6c8
RS
2010 (mh-update-unseen)
2011 (mh-invalidate-show-buffer))
2012
c26cf6c8 2013(defun mh-process-commands (folder)
bdcfe844
BW
2014 "Process outstanding commands for FOLDER.
2015The value of `mh-folder-updated-hook' is a list of functions to be called,
2016with no arguments, before the commands are processed."
c26cf6c8
RS
2017 (message "Processing deletes and refiles for %s..." folder)
2018 (set-buffer folder)
2019 (with-mh-folder-updating (nil)
a1b4049d
BW
2020 ;; Run the hook while the lists are still valid
2021 (run-hooks 'mh-folder-updated-hook)
2022
c26cf6c8
RS
2023 ;; Update the unseen sequence if it exists
2024 (mh-update-unseen)
2025
a66894d8
BW
2026 (let ((redraw-needed-flag mh-index-data)
2027 (folders-changed (list mh-current-folder))
2028 (seq-map (and mh-refile-list mh-refile-preserves-sequences-flag
2029 (mh-create-sequence-map mh-seq-list)))
2030 (dest-map (and mh-refile-list mh-refile-preserves-sequences-flag
2031 (make-hash-table))))
c3d9274a
BW
2032 ;; Remove invalid scan lines if we are in an index folder and then remove
2033 ;; the real messages
2034 (when mh-index-data
2035 (mh-index-delete-folder-headers)
a66894d8
BW
2036 (setq folders-changed
2037 (append folders-changed (mh-index-execute-commands))))
c3d9274a 2038
bdcfe844
BW
2039 ;; Then refile messages
2040 (mh-mapc #'(lambda (folder-msg-list)
a66894d8
BW
2041 (let* ((dest-folder (symbol-name (car folder-msg-list)))
2042 (last (car (mh-translate-range dest-folder "last")))
2043 (msgs (cdr folder-msg-list)))
2044 (push dest-folder folders-changed)
bdcfe844
BW
2045 (setq redraw-needed-flag t)
2046 (apply #'mh-exec-cmd
2047 "refile" "-src" folder dest-folder
2048 (mh-coalesce-msg-list msgs))
a66894d8
BW
2049 (mh-delete-scan-msgs msgs)
2050 ;; Preserve sequences in destination folder...
e495eaec 2051 (when mh-refile-preserves-sequences-flag
a66894d8 2052 (clrhash dest-map)
e495eaec 2053 (loop for i from (1+ (or last 0))
a66894d8
BW
2054 for msg in (sort (copy-sequence msgs) #'<)
2055 do (loop for seq-name in (gethash msg seq-map)
2056 do (push i (gethash seq-name dest-map))))
2057 (maphash
2058 #'(lambda (seq msgs)
e495eaec
BW
2059 ;; Can't be run in the background, since the
2060 ;; current folder is changed by mark this could
2061 ;; lead to a race condition with the next refile.
2062 (apply #'mh-exec-cmd "mark"
a66894d8
BW
2063 "-sequence" (symbol-name seq) dest-folder
2064 "-add" (mapcar #'(lambda (x) (format "%s" x))
2065 (mh-coalesce-msg-list msgs))))
2066 dest-map))))
bdcfe844
BW
2067 mh-refile-list)
2068 (setq mh-refile-list ())
2069
2070 ;; Now delete messages
2071 (cond (mh-delete-list
2072 (setq redraw-needed-flag t)
2073 (apply 'mh-exec-cmd "rmm" folder
2074 (mh-coalesce-msg-list mh-delete-list))
2075 (mh-delete-scan-msgs mh-delete-list)
2076 (setq mh-delete-list nil)))
2077
2078 ;; Don't need to remove sequences since delete and refile do so.
2079 ;; Mark cur message
2080 (if (> (buffer-size) 0)
c3d9274a 2081 (mh-define-sequence 'cur (list (or (mh-get-msg-num nil) "last"))))
bdcfe844 2082
c3d9274a
BW
2083 ;; Redraw folder buffer if needed
2084 (when (and redraw-needed-flag)
924df208 2085 (when (mh-speed-flists-active-p)
a66894d8 2086 (apply #'mh-speed-flists t folders-changed))
c3d9274a
BW
2087 (cond ((memq 'unthread mh-view-ops) (mh-thread-inc folder (point-max)))
2088 (mh-index-data (mh-index-insert-folder-headers)))))
c26cf6c8
RS
2089
2090 (and (buffer-file-name (get-buffer mh-show-buffer))
c3d9274a
BW
2091 (not (file-exists-p (buffer-file-name (get-buffer mh-show-buffer))))
2092 ;; If "inc" were to put a new msg in this file,
2093 ;; we would not notice, so mark it invalid now.
2094 (mh-invalidate-show-buffer))
c26cf6c8
RS
2095
2096 (setq mh-seq-list (mh-read-folder-sequences mh-current-folder nil))
a66894d8 2097 (mh-remove-all-notation)
c26cf6c8
RS
2098 (mh-notate-user-sequences)
2099 (message "Processing deletes and refiles for %s...done" folder)))
2100
c26cf6c8 2101(defun mh-update-unseen ()
bdcfe844
BW
2102 "Synchronize the unseen sequence with MH.
2103Return non-nil iff the MH folder was set.
2104The value of `mh-unseen-updated-hook' is a list of functions to be called,
2105with no arguments, after the unseen sequence is updated."
c26cf6c8 2106 (if mh-seen-list
847b8219 2107 (let* ((unseen-seq (mh-find-seq mh-unseen-seq))
c3d9274a
BW
2108 (unseen-msgs (mh-seq-msgs unseen-seq)))
2109 (if unseen-msgs
2110 (progn
2111 (mh-undefine-sequence mh-unseen-seq mh-seen-list)
2112 (run-hooks 'mh-unseen-updated-hook)
2113 (while mh-seen-list
2114 (setq unseen-msgs (delq (car mh-seen-list) unseen-msgs))
2115 (setq mh-seen-list (cdr mh-seen-list)))
2116 (setcdr unseen-seq unseen-msgs)
2117 t) ;since we set the folder
2118 (setq mh-seen-list nil)))))
c26cf6c8 2119
c26cf6c8 2120(defun mh-delete-scan-msgs (msgs)
bdcfe844 2121 "Delete the scan listing lines for MSGS."
c26cf6c8 2122 (save-excursion
942fc772 2123 (while msgs
bdcfe844
BW
2124 (when (mh-goto-msg (car msgs) t t)
2125 (when (memq 'unthread mh-view-ops)
2126 (mh-thread-forget-message (car msgs)))
2127 (mh-delete-line 1))
942fc772 2128 (setq msgs (cdr msgs)))))
c26cf6c8 2129
c26cf6c8 2130(defun mh-outstanding-commands-p ()
bdcfe844 2131 "Return non-nil if there are outstanding deletes or refiles."
f0d73c14
BW
2132 (save-excursion
2133 (when (eq major-mode 'mh-show-mode)
2134 (set-buffer mh-show-folder-buffer))
2135 (or mh-delete-list mh-refile-list)))
c26cf6c8 2136
847b8219 2137(defun mh-coalesce-msg-list (messages)
924df208
BW
2138 "Given a list of MESSAGES, return a list of message number ranges.
2139This is the inverse of `mh-read-msg-list', which expands ranges.
2140Message lists passed to MH programs should be processed by this function
2141to avoid exceeding system command line argument limits."
847b8219 2142 (let ((msgs (sort (copy-sequence messages) 'mh-greaterp))
c3d9274a
BW
2143 (range-high nil)
2144 (prev -1)
2145 (ranges nil))
847b8219
KH
2146 (while prev
2147 (if range-high
c3d9274a
BW
2148 (if (or (not (numberp prev))
2149 (not (equal (car msgs) (1- prev))))
2150 (progn ;non-sequential, flush old range
2151 (if (eq prev range-high)
2152 (setq ranges (cons range-high ranges))
2153 (setq ranges (cons (format "%s-%s" prev range-high) ranges)))
2154 (setq range-high nil))))
847b8219 2155 (or range-high
c3d9274a 2156 (setq range-high (car msgs))) ;start new or first range
847b8219
KH
2157 (setq prev (car msgs))
2158 (setq msgs (cdr msgs)))
2159 ranges))
2160
2161(defun mh-greaterp (msg1 msg2)
bdcfe844
BW
2162 "Return the greater of two message indicators MSG1 and MSG2.
2163Strings are \"smaller\" than numbers.
88a34f43 2164Valid values are things like \"cur\", \"last\", 1, and 1820."
847b8219 2165 (if (numberp msg1)
c3d9274a
BW
2166 (if (numberp msg2)
2167 (> msg1 msg2)
2168 t)
847b8219 2169 (if (numberp msg2)
c3d9274a 2170 nil
847b8219
KH
2171 (string-lessp msg2 msg1))))
2172
a1b4049d 2173(defun mh-lessp (msg1 msg2)
bdcfe844
BW
2174 "Return the lesser of two message indicators MSG1 and MSG2.
2175Strings are \"smaller\" than numbers.
88a34f43 2176Valid values are things like \"cur\", \"last\", 1, and 1820."
a1b4049d 2177 (not (mh-greaterp msg1 msg2)))
bdcfe844 2178
c26cf6c8
RS
2179\f
2180
2181;;; Basic sequence handling
2182
2183(defun mh-delete-seq-locally (seq)
bdcfe844 2184 "Remove MH-E's record of SEQ."
c26cf6c8
RS
2185 (let ((entry (mh-find-seq seq)))
2186 (setq mh-seq-list (delq entry mh-seq-list))))
2187
2188(defun mh-read-folder-sequences (folder save-refiles)
bdcfe844
BW
2189 "Read and return the predefined sequences for a FOLDER.
2190If SAVE-REFILES is non-nil, then keep the sequences
2191that note messages to be refiled."
c26cf6c8
RS
2192 (let ((seqs ()))
2193 (cond (save-refiles
c3d9274a
BW
2194 (mh-mapc (function (lambda (seq) ; Save the refiling sequences
2195 (if (mh-folder-name-p (mh-seq-name seq))
2196 (setq seqs (cons seq seqs)))))
2197 mh-seq-list)))
c26cf6c8
RS
2198 (save-excursion
2199 (if (eq 0 (mh-exec-cmd-quiet nil "mark" folder "-list"))
c3d9274a
BW
2200 (progn
2201 ;; look for name in line of form "cur: 4" or "myseq (private): 23"
2202 (while (re-search-forward "^[^: ]+" nil t)
2203 (setq seqs (cons (mh-make-seq (intern (buffer-substring
2204 (match-beginning 0)
2205 (match-end 0)))
2206 (mh-read-msg-list))
2207 seqs)))
2208 (delete-region (point-min) (point))))) ; avoid race with
2209 ; mh-process-daemon
c26cf6c8
RS
2210 seqs))
2211
2212(defun mh-read-msg-list ()
bdcfe844
BW
2213 "Return a list of message numbers from point to the end of the line.
2214Expands ranges into set of individual numbers."
c26cf6c8 2215 (let ((msgs ())
c3d9274a
BW
2216 (end-of-line (save-excursion (end-of-line) (point)))
2217 num)
c26cf6c8 2218 (while (re-search-forward "[0-9]+" end-of-line t)
e495eaec
BW
2219 (setq num (string-to-number (buffer-substring (match-beginning 0)
2220 (match-end 0))))
c3d9274a
BW
2221 (cond ((looking-at "-") ; Message range
2222 (forward-char 1)
2223 (re-search-forward "[0-9]+" end-of-line t)
e495eaec
BW
2224 (let ((num2 (string-to-number
2225 (buffer-substring (match-beginning 0)
2226 (match-end 0)))))
c3d9274a
BW
2227 (if (< num2 num)
2228 (error "Bad message range: %d-%d" num num2))
2229 (while (<= num num2)
2230 (setq msgs (cons num msgs))
2231 (setq num (1+ num)))))
2232 ((not (zerop num)) ;"pick" outputs "0" to mean no match
2233 (setq msgs (cons num msgs)))))
c26cf6c8
RS
2234 msgs))
2235
a66894d8
BW
2236(defun mh-notate-user-sequences (&optional range)
2237 "Mark user-defined sequences in the messages specified by RANGE.
2238The optional argument RANGE can be a message number, a list of message
2239numbers, a sequence, a region in a cons cell. If nil all messages are notated."
2240 (unless range
2241 (setq range (cons (point-min) (point-max))))
c26cf6c8 2242 (let ((seqs mh-seq-list)
a66894d8 2243 (msg-hash (make-hash-table)))
3d7ca223 2244 (dolist (seq seqs)
a66894d8
BW
2245 (dolist (msg (mh-seq-msgs seq))
2246 (push (car seq) (gethash msg msg-hash))))
2247 (mh-iterate-on-range msg range
2248 (loop for seq in (gethash msg msg-hash)
2249 do (mh-add-sequence-notation msg (mh-internal-seq seq))))))
2250
2251(defvar mh-internal-seqs '(answered cur deleted forwarded printed))
c26cf6c8 2252
c26cf6c8 2253(defun mh-internal-seq (name)
bdcfe844 2254 "Return non-nil if NAME is the name of an internal MH-E sequence."
a66894d8 2255 (or (memq name mh-internal-seqs)
c26cf6c8 2256 (eq name mh-unseen-seq)
f0d73c14 2257 (and (mh-colors-in-use-p) mh-tick-seq (eq name mh-tick-seq))
c26cf6c8
RS
2258 (eq name mh-previous-seq)
2259 (mh-folder-name-p name)))
2260
a66894d8
BW
2261(defun mh-valid-seq-p (name)
2262 "Return non-nil if NAME is a valid MH sequence name."
2263 (and (symbolp name)
2264 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" (symbol-name name))))
2265
2266(defun mh-delete-msg-from-seq (range sequence &optional internal-flag)
2267 "Delete RANGE from SEQUENCE.
2268
2269Check the documentation of `mh-interactive-range' to see how RANGE is read in
2270interactive use.
2271
2272Optional third arg INTERNAL-FLAG non-nil means do not inform MH of the
2273change."
2274 (interactive (list (mh-interactive-range "Delete")
c3d9274a
BW
2275 (mh-read-seq-default "Delete from" t)
2276 nil))
a66894d8
BW
2277 (let ((entry (mh-find-seq sequence))
2278 (user-sequence-flag (not (mh-internal-seq sequence)))
2279 (folders-changed (list mh-current-folder))
2280 (msg-list ()))
924df208 2281 (when entry
a66894d8
BW
2282 (mh-iterate-on-range msg range
2283 (push msg msg-list)
2284 ;; Calling "mark" repeatedly takes too long. So we will pretend here
2285 ;; that we are just modifying an internal sequence...
2286 (when (memq msg (cdr entry))
2287 (mh-remove-sequence-notation msg (not user-sequence-flag)))
2288 (mh-delete-a-msg-from-seq msg sequence t))
2289 ;; ... and here we will "mark" all the messages at one go.
2290 (unless internal-flag (mh-undefine-sequence sequence msg-list))
2291 (when (and mh-index-data (not internal-flag))
2292 (setq folders-changed
2293 (append folders-changed
2294 (mh-index-delete-from-sequence sequence msg-list))))
924df208 2295 (when (and (eq sequence mh-unseen-seq) (mh-speed-flists-active-p))
a66894d8 2296 (apply #'mh-speed-flists t folders-changed)))))
924df208 2297
f0d73c14
BW
2298(defun mh-catchup (range)
2299 "Delete RANGE from the `mh-unseen-seq' sequence.
2300
2301Check the document of `mh-interactive-range' to see how RANGE is read in
2302interactive use."
2303 (interactive (list (mh-interactive-range "Catchup"
2304 (cons (point-min) (point-max)))))
2305 (mh-delete-msg-from-seq range mh-unseen-seq))
2306
924df208
BW
2307(defun mh-delete-a-msg-from-seq (msg sequence internal-flag)
2308 "Delete MSG from SEQUENCE.
2309If INTERNAL-FLAG is non-nil, then do not inform MH of the change."
2310 (let ((entry (mh-find-seq sequence)))
2311 (when (and entry (memq msg (mh-seq-msgs entry)))
2312 (if (not internal-flag)
2313 (mh-undefine-sequence sequence (list msg)))
2314 (setcdr entry (delq msg (mh-seq-msgs entry))))))
2315
c26cf6c8 2316(defun mh-undefine-sequence (seq msgs)
bdcfe844 2317 "Remove from the SEQ the list of MSGS."
a66894d8
BW
2318 (when (and (mh-valid-seq-p seq) msgs)
2319 (apply #'mh-exec-cmd "mark" mh-current-folder "-delete"
2320 "-sequence" (symbol-name seq) (mh-coalesce-msg-list msgs))))
c26cf6c8 2321
c26cf6c8 2322(defun mh-define-sequence (seq msgs)
bdcfe844
BW
2323 "Define the SEQ to contain the list of MSGS.
2324Do not mark pseudo-sequences or empty sequences.
7bd10db5 2325Signals an error if SEQ is an invalid name."
c26cf6c8 2326 (if (and msgs
a66894d8 2327 (mh-valid-seq-p seq)
c3d9274a 2328 (not (mh-folder-name-p seq)))
c26cf6c8 2329 (save-excursion
c3d9274a
BW
2330 (mh-exec-cmd-error nil "mark" mh-current-folder "-add" "-zero"
2331 "-sequence" (symbol-name seq)
2332 (mh-coalesce-msg-list msgs)))))
c26cf6c8 2333
bdcfe844
BW
2334(defun mh-seq-containing-msg (msg &optional include-internal-flag)
2335 "Return a list of the sequences containing MSG.
2336If INCLUDE-INTERNAL-FLAG non-nil, include MH-E internal sequences in list."
c26cf6c8 2337 (let ((l mh-seq-list)
c3d9274a 2338 (seqs ()))
c26cf6c8 2339 (while l
847b8219 2340 (and (memq msg (mh-seq-msgs (car l)))
c3d9274a
BW
2341 (or include-internal-flag
2342 (not (mh-internal-seq (mh-seq-name (car l)))))
2343 (setq seqs (cons (mh-seq-name (car l)) seqs)))
c26cf6c8
RS
2344 (setq l (cdr l)))
2345 seqs))
2346
c26cf6c8
RS
2347\f
2348
c26cf6c8
RS
2349;;; Build the folder-mode keymap:
2350
2351(suppress-keymap mh-folder-mode-map)
a1b4049d 2352
bdcfe844
BW
2353;; Use defalias to make sure the documented primary key bindings
2354;; appear in menu lists.
2355(defalias 'mh-alt-show 'mh-show)
2356(defalias 'mh-alt-refile-msg 'mh-refile-msg)
2357(defalias 'mh-alt-send 'mh-send)
2358(defalias 'mh-alt-visit-folder 'mh-visit-folder)
2359
a1b4049d
BW
2360;; Save the `b' binding for a future `back'. Maybe?
2361(gnus-define-keys mh-folder-mode-map
c3d9274a
BW
2362 " " mh-page-msg
2363 "!" mh-refile-or-write-again
924df208 2364 "'" mh-toggle-tick
c3d9274a
BW
2365 "," mh-header-display
2366 "." mh-alt-show
d103d8b3 2367 ";" mh-toggle-mh-decode-mime-flag
c3d9274a
BW
2368 ">" mh-write-msg-to-file
2369 "?" mh-help
2370 "E" mh-extract-rejected-mail
bdcfe844 2371 "M" mh-modify
c3d9274a
BW
2372 "\177" mh-previous-page
2373 "\C-d" mh-delete-msg-no-motion
2374 "\t" mh-index-next-folder
2375 [backtab] mh-index-previous-folder
2376 "\M-\t" mh-index-previous-folder
2377 "\e<" mh-first-msg
2378 "\e>" mh-last-msg
2379 "\ed" mh-redistribute
2380 "\r" mh-show
2381 "^" mh-alt-refile-msg
2382 "c" mh-copy-msg
2383 "d" mh-delete-msg
2384 "e" mh-edit-again
2385 "f" mh-forward
2386 "g" mh-goto-msg
2387 "i" mh-inc-folder
2388 "k" mh-delete-subject-or-thread
c3d9274a
BW
2389 "m" mh-alt-send
2390 "n" mh-next-undeleted-msg
2391 "\M-n" mh-next-unread-msg
2392 "o" mh-refile-msg
2393 "p" mh-previous-undeleted-msg
2394 "\M-p" mh-previous-unread-msg
2395 "q" mh-quit
2396 "r" mh-reply
2397 "s" mh-send
2398 "t" mh-toggle-showing
2399 "u" mh-undo
2400 "v" mh-index-visit-folder
2401 "x" mh-execute-commands
2402 "|" mh-pipe-msg)
a1b4049d
BW
2403
2404(gnus-define-keys (mh-folder-map "F" mh-folder-mode-map)
c3d9274a 2405 "?" mh-prefix-help
a66894d8 2406 "'" mh-index-ticked-messages
c3d9274a 2407 "S" mh-sort-folder
f0d73c14 2408 "c" mh-catchup
c3d9274a 2409 "f" mh-alt-visit-folder
bdcfe844 2410 "i" mh-index-search
c3d9274a
BW
2411 "k" mh-kill-folder
2412 "l" mh-list-folders
924df208 2413 "n" mh-index-new-messages
c3d9274a
BW
2414 "o" mh-alt-visit-folder
2415 "p" mh-pack-folder
a66894d8 2416 "q" mh-index-sequenced-messages
c3d9274a
BW
2417 "r" mh-rescan-folder
2418 "s" mh-search-folder
2419 "u" mh-undo-folder
2420 "v" mh-visit-folder)
a1b4049d 2421
924df208
BW
2422(define-key mh-folder-mode-map "I" mh-inc-spool-map)
2423
2424(gnus-define-keys (mh-junk-map "J" mh-folder-mode-map)
2425 "?" mh-prefix-help
2426 "b" mh-junk-blacklist
2427 "w" mh-junk-whitelist)
2428
f0d73c14
BW
2429(gnus-define-keys (mh-ps-print-map "P" mh-folder-mode-map)
2430 "?" mh-prefix-help
2431 "A" mh-ps-print-toggle-mime
2432 "C" mh-ps-print-toggle-color
2433 "F" mh-ps-print-toggle-faces
2434 "M" mh-ps-print-toggle-mime
2435 "f" mh-ps-print-msg-file
2436 "l" mh-print-msg
2437 "p" mh-ps-print-msg
2438 "s" mh-ps-print-msg-show)
2439
a1b4049d 2440(gnus-define-keys (mh-sequence-map "S" mh-folder-mode-map)
a66894d8 2441 "'" mh-narrow-to-tick
c3d9274a
BW
2442 "?" mh-prefix-help
2443 "d" mh-delete-msg-from-seq
2444 "k" mh-delete-seq
2445 "l" mh-list-sequences
2446 "n" mh-narrow-to-seq
2447 "p" mh-put-msg-in-seq
2448 "s" mh-msg-is-in-seq
2449 "w" mh-widen)
a1b4049d
BW
2450
2451(gnus-define-keys (mh-thread-map "T" mh-folder-mode-map)
c3d9274a
BW
2452 "?" mh-prefix-help
2453 "u" mh-thread-ancestor
2454 "p" mh-thread-previous-sibling
2455 "n" mh-thread-next-sibling
2456 "t" mh-toggle-threads
2457 "d" mh-thread-delete
2458 "o" mh-thread-refile)
bdcfe844
BW
2459
2460(gnus-define-keys (mh-limit-map "/" mh-folder-mode-map)
924df208 2461 "'" mh-narrow-to-tick
c3d9274a 2462 "?" mh-prefix-help
a66894d8
BW
2463 "c" mh-narrow-to-cc
2464 "f" mh-narrow-to-from
2465 "r" mh-narrow-to-range
c3d9274a 2466 "s" mh-narrow-to-subject
a66894d8 2467 "t" mh-narrow-to-to
c3d9274a 2468 "w" mh-widen)
a1b4049d
BW
2469
2470(gnus-define-keys (mh-extract-map "X" mh-folder-mode-map)
c3d9274a
BW
2471 "?" mh-prefix-help
2472 "s" mh-store-msg ;shar
2473 "u" mh-store-msg) ;uuencode
a1b4049d
BW
2474
2475(gnus-define-keys (mh-digest-map "D" mh-folder-mode-map)
c3d9274a
BW
2476 " " mh-page-digest
2477 "?" mh-prefix-help
2478 "\177" mh-page-digest-backwards
2479 "b" mh-burst-digest)
a1b4049d 2480
bdcfe844 2481(gnus-define-keys (mh-mime-map "K" mh-folder-mode-map)
c3d9274a
BW
2482 "?" mh-prefix-help
2483 "a" mh-mime-save-parts
f0d73c14 2484 "e" mh-display-with-external-viewer
bdcfe844
BW
2485 "i" mh-folder-inline-mime-part
2486 "o" mh-folder-save-mime-part
f0d73c14 2487 "t" mh-toggle-mime-buttons
bdcfe844
BW
2488 "v" mh-folder-toggle-mime-part
2489 "\t" mh-next-button
2490 [backtab] mh-prev-button
2491 "\M-\t" mh-prev-button)
2492
a1b4049d 2493(cond
bdcfe844 2494 (mh-xemacs-flag
a1b4049d
BW
2495 (define-key mh-folder-mode-map [button2] 'mh-show-mouse))
2496 (t
2497 (define-key mh-folder-mode-map [mouse-2] 'mh-show-mouse)))
c26cf6c8 2498
942fc772
KH
2499;; "C-c /" prefix is used in mh-folder-mode by pgp.el and mailcrypt
2500
c26cf6c8
RS
2501\f
2502
bdcfe844
BW
2503;;; Help Messages
2504
2505;;; If you add a new prefix, add appropriate text to the nil key.
2506;;;
2507;;; In general, messages are grouped logically. Taking the main commands for
2508;;; example, the first line is "ways to view messages," the second line is
2509;;; "things you can do with messages", and the third is "composing" messages.
2510;;;
2511;;; When adding a new prefix, ensure that the help message contains "what" the
2512;;; prefix is for. For example, if the word "folder" were not present in the
2513;;; `F' entry, it would not be clear what these commands operated upon.
2514(defvar mh-help-messages
2515 '((nil "[i]nc, [.]show, [,]show all, [n]ext, [p]revious,\n"
c3d9274a 2516 "[d]elete, [o]refile, e[x]ecute,\n"
d103d8b3
BW
2517 "[s]end, [r]eply,\n"
2518 "[;]toggle MIME decoding.\n"
924df208 2519 "Prefix characters:\n [F]older, [S]equence, [J]unk, MIME [K]eys,"
a66894d8 2520 "\n [T]hread, [/]limit, e[X]tract, [D]igest, [I]nc spools.")
bdcfe844 2521
a66894d8
BW
2522 (?F "[l]ist; [v]isit folder;\n"
2523 "[n]ew messages; [']ticked messages; [s]earch; [i]ndexed search;\n"
c3d9274a 2524 "[p]ack; [S]ort; [r]escan; [k]ill")
f0d73c14
BW
2525 (?P "PS [p]rint message; [l]non-PS print;\n"
2526 "PS Print [s]how window, message to [f]ile;\n"
2527 "Toggle printing of [M]IME parts, [C]olor, [F]aces")
a66894d8 2528 (?S "[p]ut message in sequence, [n]arrow, [']narrow to ticked, [w]iden,\n"
c3d9274a
BW
2529 "[s]equences, [l]ist,\n"
2530 "[d]elete message from sequence, [k]ill sequence")
2531 (?T "[t]oggle, [d]elete, [o]refile thread")
a66894d8 2532 (?/ "Limit to [c]c, [f]rom, [r]ange, [s]ubject, [t]o; [w]iden")
bdcfe844
BW
2533 (?X "un[s]har, [u]udecode message")
2534 (?D "[b]urst digest")
2535 (?K "[v]iew, [i]nline, [o]utput/save MIME part; save [a]ll parts; \n"
924df208
BW
2536 "[TAB] next; [SHIFT-TAB] previous")
2537 (?J "[b]lacklist, [w]hitelist message"))
bdcfe844
BW
2538 "Key binding cheat sheet.
2539
2540This is an associative array which is used to show the most common commands.
2541The key is a prefix char. The value is one or more strings which are
2542concatenated together and displayed in the minibuffer if ? is pressed after
2543the prefix character. The special key nil is used to display the
2544non-prefixed commands.
2545
2546The substitutions described in `substitute-command-keys' are performed as
2547well.")
a1b4049d 2548
bdcfe844 2549\f
a1b4049d 2550
f1ed9461 2551(dolist (mess '("^Cursor not pointing to message$"
c3d9274a 2552 "^There is no other window$"))
f1ed9461
DL
2553 (add-to-list 'debug-ignored-errors mess))
2554
bdcfe844
BW
2555(provide 'mh-e)
2556
2557;;; Local Variables:
c3d9274a 2558;;; indent-tabs-mode: nil
bdcfe844
BW
2559;;; sentence-end-double-space: nil
2560;;; End:
2561
ab5796a9 2562;;; arch-tag: cce884de-bd37-4104-9963-e4439d5ed22b
c26cf6c8 2563;;; mh-e.el ends here