mh-e.el 145 KB
Newer Older
Richard M. Stallman's avatar
Richard M. Stallman committed
1 2
;;; mh-e.el --- GNU Emacs interface to the MH mail system

3 4
;; Copyright (C) 1985-1988, 1990, 1992-1995, 1997, 1999-2013 Free
;; Software Foundation, Inc.
Richard M. Stallman's avatar
Richard M. Stallman committed
5

Bill Wohler's avatar
Bill Wohler committed
6
;; Author: Bill Wohler <wohler@newt.com>
Gerd Moellmann's avatar
Gerd Moellmann committed
7
;; Maintainer: Bill Wohler <wohler@newt.com>
8
;; Version: 8.4+bzr
Richard M. Stallman's avatar
Richard M. Stallman committed
9 10
;; Keywords: mail

11
;; This file is part of GNU Emacs.
Karl Heuer's avatar
Karl Heuer committed
12

13
;; GNU Emacs is free software: you can redistribute it and/or modify
Richard M. Stallman's avatar
Richard M. Stallman committed
14
;; it under the terms of the GNU General Public License as published by
15 16
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Richard M. Stallman's avatar
Richard M. Stallman committed
17

Karl Heuer's avatar
Karl Heuer committed
18
;; GNU Emacs is distributed in the hope that it will be useful,
Richard M. Stallman's avatar
Richard M. Stallman committed
19 20 21 22 23
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
24
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Richard M. Stallman's avatar
Richard M. Stallman committed
25 26 27

;;; Commentary:

Bill Wohler's avatar
Bill Wohler committed
28 29
;; MH-E is an Emacs interface to the MH mail system.

30
;; MH-E is supported in GNU Emacs 21 and higher, as well as XEmacs 21
Bill Wohler's avatar
Bill Wohler committed
31 32
;; (except for versions 21.5.9-21.5.16). It is compatible with MH
;; versions 6.8.4 and higher, all versions of nmh, and GNU mailutils
33 34
;; 1.0 and higher. Gnus is also required; version 5.10 or higher is
;; recommended.
Bill Wohler's avatar
Bill Wohler committed
35 36 37 38 39 40 41 42

;; MH (Message Handler) is a powerful mail reader. See
;; http://rand-mh.sourceforge.net/.

;; N.B. MH must have been compiled with the MHE compiler flag or several
;; features necessary for MH-E will be missing from MH commands, specifically
;; the -build switch to repl and forw.

Bill Wohler's avatar
Bill Wohler committed
43
;; How to use:
Bill Wohler's avatar
Bill Wohler committed
44 45
;;   M-x mh-rmail to read mail.  Type C-h m there for a list of commands.
;;   C-u M-x mh-rmail to visit any folder.
Bill Wohler's avatar
Bill Wohler committed
46
;;   M-x mh-smail to send mail.  From within the mail reader, "s" works, too.
Erik Naggum's avatar
Erik Naggum committed
47

Bill Wohler's avatar
Bill Wohler committed
48 49 50 51
;; Your .emacs might benefit from these bindings:
;;   (global-set-key "\C-cr" 'mh-rmail)
;;   (global-set-key "\C-xm" 'mh-smail)
;;   (global-set-key "\C-x4m" 'mh-smail-other-window)
Erik Naggum's avatar
Erik Naggum committed
52

Bill Wohler's avatar
Bill Wohler committed
53 54 55 56 57 58
;; If Emacs can't find mh-rmail or mh-smail, add the following to ~/.emacs:
;;   (require 'mh-autoloads)

;; If you want to customize MH-E before explicitly loading it, add this:
;;   (require 'mh-cus-load)

Bill Wohler's avatar
Bill Wohler committed
59 60 61 62
;; Mailing Lists:
;;   mh-e-users@lists.sourceforge.net
;;   mh-e-announce@lists.sourceforge.net
;;   mh-e-devel@lists.sourceforge.net
Bill Wohler's avatar
Bill Wohler committed
63

Bill Wohler's avatar
Bill Wohler committed
64 65 66 67 68 69
;;   Subscribe by sending a "subscribe" message to
;;   <list>-request@lists.sourceforge.net, or by using the web interface at
;;   https://sourceforge.net/mail/?group_id=13357

;; Bug Reports:
;;   https://sourceforge.net/tracker/?group_id=13357&atid=113357
Bill Wohler's avatar
Bill Wohler committed
70 71
;;   Include the output of M-x mh-version in the bug report unless
;;   you're 110% sure we won't ask for it.
Bill Wohler's avatar
Bill Wohler committed
72 73

;; Feature Requests:
Bill Wohler's avatar
Bill Wohler committed
74
;;   https://sourceforge.net/tracker/?group_id=13357&atid=363357
Bill Wohler's avatar
Bill Wohler committed
75 76 77

;; Support:
;;   https://sourceforge.net/tracker/?group_id=13357&atid=213357
Erik Naggum's avatar
Erik Naggum committed
78

Erik Naggum's avatar
Erik Naggum committed
79
;;; Change Log:
Erik Naggum's avatar
Erik Naggum committed
80 81 82

;; Original version for Gosling emacs by Brian Reid, Stanford, 1982.
;; Modified by James Larus, BBN, July 1984 and UCB, 1984 & 1985.
Bill Wohler's avatar
Bill Wohler committed
83 84 85 86
;; Rewritten for GNU Emacs, James Larus, 1985.
;; Modified by Stephen Gildea, 1988.
;; Maintenance picked up by Bill Wohler and the
;; SourceForge Crew <http://mh-e.sourceforge.net/>, 2001.
Bill Wohler's avatar
Bill Wohler committed
87

Richard M. Stallman's avatar
Richard M. Stallman committed
88 89
;;; Code:

Bill Wohler's avatar
Bill Wohler committed
90 91 92
;; Provide functions to the rest of MH-E. However, mh-e.el must not
;; use any definitions in files that require mh-e from mh-loaddefs,
;; for if it does it will introduce a require loop.
93
(require 'mh-loaddefs)
Bill Wohler's avatar
Bill Wohler committed
94

Bill Wohler's avatar
Bill Wohler committed
95
(mh-require-cl)
Bill Wohler's avatar
Bill Wohler committed
96

97 98 99
(require 'mh-buffers)
(require 'mh-compat)

Bill Wohler's avatar
Bill Wohler committed
100 101 102
(mh-do-in-xemacs
  (require 'mh-xemacs))

103 104 105 106 107
(mh-font-lock-add-keywords
 'emacs-lisp-mode
 (eval-when-compile
   `((,(concat "(\\("
               ;; Function declarations (use font-lock-function-name-face).
108
               "\\(def\\(un\\|macro\\)-mh\\)\\|"
109
               ;; Variable declarations (use font-lock-variable-name-face).
110
               "\\(def\\(custom\\|face\\)-mh\\)\\|"
111
               ;; Group declarations (use font-lock-type-face).
112
               "\\(defgroup-mh\\)"
113 114 115 116 117 118 119 120 121 122
               "\\)\\>"
               ;; Any whitespace and defined object.
               "[ \t'\(]*"
               "\\(setf[ \t]+\\sw+)\\|\\sw+\\)?")
      (1 font-lock-keyword-face)
      (7 (cond ((match-beginning 2) font-lock-function-name-face)
               ((match-beginning 4) font-lock-variable-name-face)
               (t font-lock-type-face))
         nil t)))))

Bill Wohler's avatar
Bill Wohler committed
123

Richard M. Stallman's avatar
Richard M. Stallman committed
124

Bill Wohler's avatar
Bill Wohler committed
125
;;; Global Variables
Bill Wohler's avatar
Bill Wohler committed
126

Bill Wohler's avatar
Bill Wohler committed
127 128
;; Try to keep variables local to a single file. Provide accessors if
;; variables are shared. Use this section as a last resort.
Bill Wohler's avatar
Bill Wohler committed
129

130
(defconst mh-version "8.4+bzr" "Version number of MH-E.")
Bill Wohler's avatar
Bill Wohler committed
131

Bill Wohler's avatar
Bill Wohler committed
132
;; Variants
Bill Wohler's avatar
Bill Wohler committed
133

Bill Wohler's avatar
Bill Wohler committed
134 135 136 137 138 139 140 141 142
(defvar mh-sys-path
  '("/usr/local/nmh/bin"                ; nmh default
    "/usr/local/bin/mh/"
    "/usr/local/mh/"
    "/usr/bin/mh/"                      ; Ultrix 4.2, Linux
    "/usr/new/mh/"                      ; Ultrix < 4.2
    "/usr/contrib/mh/bin/"              ; BSDI
    "/usr/pkg/bin/"                     ; NetBSD
    "/usr/local/bin/"
143 144
    "/usr/local/bin/mu-mh/"             ; GNU mailutils MH - default
    "/usr/bin/mu-mh/")                  ; GNU mailutils MH - packaged
Bill Wohler's avatar
Bill Wohler committed
145 146 147 148
  "List of directories to search for variants of the MH variant.
The list `exec-path' is searched in addition to this list.
There's no need for users to modify this list. Instead add extra
directories to the customizable variable `mh-path'.")
Bill Wohler's avatar
Bill Wohler committed
149

Bill Wohler's avatar
Bill Wohler committed
150 151 152 153
(defvar mh-variants nil
  "List describing known MH variants.
Do not access this variable directly as it may not have yet been initialized.
Use the function `mh-variants' instead.")
Bill Wohler's avatar
Bill Wohler committed
154

Bill Wohler's avatar
Bill Wohler committed
155 156 157 158
(defvar mh-variant-in-use nil
  "The MH variant currently in use; a string with variant and version number.
This differs from `mh-variant' when the latter is set to
\"autodetect\".")
Bill Wohler's avatar
Bill Wohler committed
159

Bill Wohler's avatar
Bill Wohler committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
(defvar mh-progs nil
  "Directory containing MH commands, such as inc, repl, and rmm.")

;;;###autoload
(put 'mh-progs 'risky-local-variable t)

(defvar mh-lib nil
  "Directory containing the MH library.
This directory contains, among other things, the components file.")

;;;###autoload
(put 'mh-lib 'risky-local-variable t)

(defvar mh-lib-progs nil
  "Directory containing MH helper programs.
This directory contains, among other things, the mhl program.")

;;;###autoload
(put 'mh-lib-progs 'risky-local-variable t)
Richard M. Stallman's avatar
Richard M. Stallman committed
179

Bill Wohler's avatar
Bill Wohler committed
180
;; Profile Components
Richard M. Stallman's avatar
Richard M. Stallman committed
181

Bill Wohler's avatar
Bill Wohler committed
182 183 184
(defvar mh-draft-folder nil
  "Cached value of the \"Draft-Folder:\" MH profile component.
Name of folder containing draft messages.
185
Do not use a draft folder if nil.")
186

Bill Wohler's avatar
Bill Wohler committed
187 188 189 190
(defvar mh-inbox nil
  "Cached value of the \"Inbox:\" MH profile component.
Set to \"+inbox\" if no such component.
Name of the Inbox folder.")
191

Bill Wohler's avatar
Bill Wohler committed
192 193 194 195 196
(defvar mh-user-path nil
  "Cached value of the \"Path:\" MH profile component.
User's mail folder directory.")

;; Maps declared here so that they can be used in docstrings.
Richard M. Stallman's avatar
Richard M. Stallman committed
197 198

(defvar mh-folder-mode-map (make-keymap)
Bill Wohler's avatar
Bill Wohler committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
  "Keymap for MH-Folder mode.")

(defvar mh-folder-seq-tool-bar-map nil
  "Keymap for MH-Folder tool bar.")

(defvar mh-folder-tool-bar-map nil
  "Keymap for MH-Folder tool bar.")

(defvar mh-inc-spool-map (make-sparse-keymap)
  "Keymap for MH-E's mh-inc-spool commands.")

(defvar mh-letter-mode-map (copy-keymap text-mode-map)
  "Keymap for MH-Letter mode.")

(defvar mh-letter-tool-bar-map nil
  "Keymap for MH-Letter tool bar.")

(defvar mh-search-mode-map (make-sparse-keymap)
  "Keymap for MH-Search mode.")

(defvar mh-show-mode-map (make-sparse-keymap)
  "Keymap MH-Show mode.")

(defvar mh-show-seq-tool-bar-map nil
  "Keymap for MH-Show tool bar.")

(defvar mh-show-tool-bar-map nil
  "Keymap for MH-Show tool bar.")

;; MH-Folder Locals (alphabetical)
Richard M. Stallman's avatar
Richard M. Stallman committed
229

230 231 232
(defvar mh-arrow-marker nil
  "Marker for arrow display in fringe.")

233 234 235 236 237
(defvar mh-blacklist nil
  "List of messages to use to train the junk filter.
This variable can be used by
`mh-before-commands-processed-hook'.")

Bill Wohler's avatar
Bill Wohler committed
238 239 240 241 242 243
(defvar mh-colors-available-flag nil
  "Non-nil means colors are available.")

(defvar mh-current-folder nil
  "Name of current folder, a string.")

244 245
(defvar mh-delete-list nil
  "List of message numbers to delete.
246 247
This variable can be used by
`mh-before-commands-processed-hook'.")
Bill Wohler's avatar
Bill Wohler committed
248

Bill Wohler's avatar
Bill Wohler committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
(defvar mh-folder-view-stack nil
  "Stack of previous folder views.")

(defvar mh-index-data nil
  "Info about index search results.")

(defvar mh-index-previous-search nil)

(defvar mh-index-msg-checksum-map nil)

(defvar mh-index-checksum-origin-map nil)

(defvar mh-index-sequence-search-flag nil)

(defvar mh-mode-line-annotation nil
  "Message range displayed in buffer.")

(defvar mh-next-direction 'forward
  "Direction to move to next message.")

(defvar mh-previous-window-config nil
  "Window configuration before MH-E command.")

272 273
(defvar mh-refile-list nil
  "List of folder names in `mh-seq-list'.
274 275
This variable can be used by
`mh-before-commands-processed-hook'.")
Richard M. Stallman's avatar
Richard M. Stallman committed
276

Bill Wohler's avatar
Bill Wohler committed
277 278
(defvar mh-seen-list nil
  "List of displayed messages to be removed from the \"Unseen\" sequence.")
Richard M. Stallman's avatar
Richard M. Stallman committed
279

Bill Wohler's avatar
Bill Wohler committed
280 281 282 283 284 285 286 287 288
(defvar mh-seq-list nil
  "Alist of this folder's sequences.
Elements have the form (SEQUENCE . MESSAGES).")

(defvar mh-sequence-notation-history nil
  "Remember original notation that is overwritten by `mh-note-seq'.")

(defvar mh-show-buffer nil
  "Buffer that displays message for this folder.")
289

290 291 292 293
(define-minor-mode mh-showing-mode
  "Minor mode to show the message in a separate window."
  ;; FIXME: maybe this should be moved to mh-show.el.
  :lighter " Show")
Bill Wohler's avatar
Bill Wohler committed
294 295

(defvar mh-view-ops nil
296 297
  "Stack of operations that change the folder view.
These operations include narrowing or threading.")
Richard M. Stallman's avatar
Richard M. Stallman committed
298

299 300 301 302 303
(defvar mh-whitelist nil
  "List of messages to use to train the junk filter.
This variable can be used by
`mh-before-commands-processed-hook'.")

Bill Wohler's avatar
Bill Wohler committed
304
;; MH-Show Locals (alphabetical)
305

Bill Wohler's avatar
Bill Wohler committed
306 307
(defvar mh-globals-hash (make-hash-table)
  "Keeps track of MIME data on a per buffer basis.")
Richard M. Stallman's avatar
Richard M. Stallman committed
308

Bill Wohler's avatar
Bill Wohler committed
309 310
(defvar mh-show-folder-buffer nil
  "Keeps track of folder whose message is being displayed.")
Bill Wohler's avatar
Bill Wohler committed
311

Bill Wohler's avatar
Bill Wohler committed
312
;; MH-Letter Locals
Richard M. Stallman's avatar
Richard M. Stallman committed
313

Bill Wohler's avatar
Bill Wohler committed
314 315 316 317 318
(defvar mh-folders-changed nil
  "Lists which folders were affected by deletes and refiles.
This list will always include the current folder
`mh-current-folder'. This variable can be used by
`mh-after-commands-processed-hook'.")
Richard M. Stallman's avatar
Richard M. Stallman committed
319

Bill Wohler's avatar
Bill Wohler committed
320 321
(defvar mh-mail-header-separator "--------"
  "*Line used by MH to separate headers from text in messages being composed.
Richard M. Stallman's avatar
Richard M. Stallman committed
322

Bill Wohler's avatar
Bill Wohler committed
323 324 325 326 327
This variable should not be used directly in programs. Programs
should use `mail-header-separator' instead.
`mail-header-separator' is initialized to
`mh-mail-header-separator' in `mh-letter-mode'; in other
contexts, you may have to perform this initialization yourself.
Bill Wohler's avatar
Bill Wohler committed
328

Bill Wohler's avatar
Bill Wohler committed
329 330 331
Do not make this a regular expression as it may be the argument
to `insert' and it is passed through `regexp-quote' before being
used by functions like `re-search-forward'.")
Bill Wohler's avatar
Bill Wohler committed
332

Bill Wohler's avatar
Bill Wohler committed
333 334
(defvar mh-sent-from-folder nil
  "Folder of msg assoc with this letter.")
Bill Wohler's avatar
Bill Wohler committed
335

Bill Wohler's avatar
Bill Wohler committed
336 337
(defvar mh-sent-from-msg nil
  "Number of msg assoc with this letter.")
Bill Wohler's avatar
Bill Wohler committed
338

Bill Wohler's avatar
Bill Wohler committed
339
;; Sequences
Richard M. Stallman's avatar
Richard M. Stallman committed
340

Bill Wohler's avatar
Bill Wohler committed
341 342 343
(defvar mh-unseen-seq nil
  "Cached value of the \"Unseen-Sequence:\" MH profile component.
Name of the Unseen sequence.")
Richard M. Stallman's avatar
Richard M. Stallman committed
344

Bill Wohler's avatar
Bill Wohler committed
345 346 347
(defvar mh-previous-seq nil
  "Cached value of the \"Previous-Sequence:\" MH profile component.
Name of the Previous sequence.")
348

Bill Wohler's avatar
Bill Wohler committed
349
;; Etc. (alphabetical)
Richard M. Stallman's avatar
Richard M. Stallman committed
350

Bill Wohler's avatar
Bill Wohler committed
351 352
(defvar mh-flists-present-flag nil
  "Non-nil means that we have \"flists\".")
353

Bill Wohler's avatar
Bill Wohler committed
354
(defvar mh-index-data-file ".mhe_index"
Paul Eggert's avatar
Paul Eggert committed
355
  "MH-E specific file where index search info is stored.")
Richard M. Stallman's avatar
Richard M. Stallman committed
356

Bill Wohler's avatar
Bill Wohler committed
357
(defvar mh-letter-header-field-regexp "^\\([A-Za-z][A-Za-z0-9-]*\\):")
Richard M. Stallman's avatar
Richard M. Stallman committed
358

Bill Wohler's avatar
Bill Wohler committed
359 360
(defvar mh-page-to-next-msg-flag nil
  "Non-nil means next SPC or whatever goes to next undeleted message.")
Richard M. Stallman's avatar
Richard M. Stallman committed
361

Bill Wohler's avatar
Bill Wohler committed
362 363
(defvar mh-pgp-support-flag (not (not (locate-library "mml2015")))
  "Non-nil means PGP support is available.")
364

Bill Wohler's avatar
Bill Wohler committed
365 366
(defvar mh-signature-separator "-- \n"
  "Text of a signature separator.
Bill Wohler's avatar
Bill Wohler committed
367

Bill Wohler's avatar
Bill Wohler committed
368 369 370 371 372
A signature separator is used to separate the body of a message
from the signature. This can be used by user agents such as MH-E
to render the signature differently or to suppress the inclusion
of the signature in a reply. Use `mh-signature-separator-regexp'
when searching for a separator.")
373

Bill Wohler's avatar
Bill Wohler committed
374 375 376
(defvar mh-signature-separator-regexp "^-- $"
  "This regular expression matches the signature separator.
See `mh-signature-separator'.")
377

Bill Wohler's avatar
Bill Wohler committed
378 379 380
(defvar mh-thread-scan-line-map nil
  "Map of message index to various parts of the scan line.")
(make-variable-buffer-local 'mh-thread-scan-line-map)
Bill Wohler's avatar
Bill Wohler committed
381

Bill Wohler's avatar
Bill Wohler committed
382 383 384 385 386
(defvar mh-thread-scan-line-map-stack nil
  "Old map of message index to various parts of the scan line.
This is the original map that is stored when the folder is
narrowed.")
(make-variable-buffer-local 'mh-thread-scan-line-map-stack)
387

Bill Wohler's avatar
Bill Wohler committed
388 389 390 391
(defvar mh-x-mailer-string nil
  "*String containing the contents of the X-Mailer header field.
If nil, this variable is initialized to show the version of MH-E,
Emacs, and MH the first time a message is composed.")
392

Bill Wohler's avatar
Bill Wohler committed
393

394

Bill Wohler's avatar
Bill Wohler committed
395
;;; MH-E Entry Points
Bill Wohler's avatar
Bill Wohler committed
396 397 398 399 400

(eval-when-compile (require 'gnus))

(defmacro mh-macro-expansion-time-gnus-version ()
  "Return Gnus version available at macro expansion time.
401 402 403
The macro evaluates the Gnus version at macro expansion time. If
MH-E was compiled then macro expansion happens at compile time."
gnus-version)
Bill Wohler's avatar
Bill Wohler committed
404 405 406 407 408 409

(defun mh-run-time-gnus-version ()
  "Return Gnus version available at run time."
  (require 'gnus)
  gnus-version)

Karl Heuer's avatar
Karl Heuer committed
410
;;;###autoload
Richard M. Stallman's avatar
Richard M. Stallman committed
411
(defun mh-version ()
Bill Wohler's avatar
Bill Wohler committed
412
  "Display version information about MH-E and the MH mail handling system."
Richard M. Stallman's avatar
Richard M. Stallman committed
413
  (interactive)
Bill Wohler's avatar
Bill Wohler committed
414
  (set-buffer (get-buffer-create mh-info-buffer))
Richard M. Stallman's avatar
Richard M. Stallman committed
415
  (erase-buffer)
Bill Wohler's avatar
Bill Wohler committed
416 417 418 419 420 421 422 423 424 425 426 427 428
  ;; MH-E version.
  (insert "MH-E " mh-version "\n\n")
  ;; MH-E compilation details.
  (insert "MH-E compilation details:\n")
  (let* ((compiled-mhe (byte-code-function-p (symbol-function 'mh-version)))
         (gnus-compiled-version (if compiled-mhe
                                    (mh-macro-expansion-time-gnus-version)
                                  "N/A")))
    (insert " Byte compiled:\t\t" (if compiled-mhe "yes" "no") "\n"
            " Gnus (compile-time):\t" gnus-compiled-version "\n"
            " Gnus (run-time):\t" (mh-run-time-gnus-version) "\n\n"))
  ;; Emacs version.
  (insert (emacs-version) "\n\n")
Bill Wohler's avatar
Bill Wohler committed
429
  ;; MH version.
Bill Wohler's avatar
Bill Wohler committed
430 431 432 433 434 435
  (if mh-variant-in-use
      (insert mh-variant-in-use "\n"
              " mh-progs:\t" mh-progs "\n"
              " mh-lib:\t" mh-lib "\n"
              " mh-lib-progs:\t" mh-lib-progs "\n\n")
    (insert "No MH variant detected\n"))
Bill Wohler's avatar
Bill Wohler committed
436 437 438 439 440
  ;; Linux version.
  (condition-case ()
      (call-process "uname" nil t nil "-a")
    (file-error))
  (goto-char (point-min))
Bill Wohler's avatar
Bill Wohler committed
441
  (display-buffer mh-info-buffer))
Richard M. Stallman's avatar
Richard M. Stallman committed
442

Bill Wohler's avatar
Bill Wohler committed
443 444 445 446 447 448 449 450 451 452


;;; Support Routines

(defun mh-list-to-string (l)
  "Flatten the list L and make every element of the new list into a string."
  (nreverse (mh-list-to-string-1 l)))

(defun mh-list-to-string-1 (l)
  "Flatten the list L and make every element of the new list into a string."
453 454 455 456 457 458 459 460 461 462 463 464 465 466
  (let (new-list)
    (dolist (element l)
      (cond ((null element))
            ((symbolp element)
             (push (symbol-name element) new-list))
            ((numberp element)
             (push (int-to-string element) new-list))
            ((equal element ""))
            ((stringp element)
             (push element new-list))
            ((listp element)
             (setq new-list (nconc (mh-list-to-string-1 element) new-list)))
            (t
             (error "Bad element: %s" element))))
Bill Wohler's avatar
Bill Wohler committed
467
    new-list))
Karl Heuer's avatar
Karl Heuer committed
468

Richard M. Stallman's avatar
Richard M. Stallman committed
469 470


Bill Wohler's avatar
Bill Wohler committed
471 472 473 474
;;; MH-E Process Support

(defvar mh-index-max-cmdline-args 500
  "Maximum number of command line args.")
Richard M. Stallman's avatar
Richard M. Stallman committed
475

Bill Wohler's avatar
Bill Wohler committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
(defun mh-xargs (cmd &rest args)
  "Partial imitation of xargs.
The current buffer contains a list of strings, one on each line.
The function will execute CMD with ARGS and pass the first
`mh-index-max-cmdline-args' strings to it. This is repeated till
all the strings have been used."
  (goto-char (point-min))
  (let ((current-buffer (current-buffer)))
    (with-temp-buffer
      (let ((out (current-buffer)))
        (set-buffer current-buffer)
        (while (not (eobp))
          (let ((arg-list (reverse args))
                (count 0))
            (while (and (not (eobp)) (< count mh-index-max-cmdline-args))
491 492
              (push (buffer-substring-no-properties (point)
                                                    (mh-line-end-position))
Bill Wohler's avatar
Bill Wohler committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
                    arg-list)
              (incf count)
              (forward-line))
            (apply #'call-process cmd nil (list out nil) nil
                   (nreverse arg-list))))
        (erase-buffer)
        (insert-buffer-substring out)))))

;; XXX This should be applied anywhere MH-E calls out to /bin/sh.
(defun mh-quote-for-shell (string)
  "Quote STRING for /bin/sh.
Adds double-quotes around entire string and quotes the characters
\\, `, and $ with a backslash."
  (concat "\""
          (loop for x across string
                concat (format (if (memq x '(?\\ ?` ?$)) "\\%c" "%c") x))
          "\""))

(defun mh-exec-cmd (command &rest args)
  "Execute mh-command COMMAND with ARGS.
The side effects are what is desired. Any output is assumed to be
an error and is shown to the user. The output is not read or
parsed by MH-E."
516
  (with-current-buffer (get-buffer-create mh-log-buffer)
Bill Wohler's avatar
Bill Wohler committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
    (let* ((initial-size (mh-truncate-log-buffer))
           (start (point))
           (args (mh-list-to-string args)))
      (apply 'call-process (expand-file-name command mh-progs) nil t nil args)
      (when (> (buffer-size) initial-size)
        (save-excursion
          (goto-char start)
          (insert "Errors when executing: " command)
          (loop for arg in args do (insert " " arg))
          (insert "\n"))
        (save-window-excursion
          (switch-to-buffer-other-window mh-log-buffer)
          (sit-for 5))))))

(defun mh-exec-cmd-error (env command &rest args)
  "In environment ENV, execute mh-command COMMAND with ARGS.
ENV is nil or a string of space-separated \"var=value\" elements.
Signals an error if process does not complete successfully."
535
  (with-current-buffer (get-buffer-create mh-temp-buffer)
Bill Wohler's avatar
Bill Wohler committed
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
    (erase-buffer)
    (let ((process-environment process-environment))
      ;; XXX: We should purge the list that split-string returns of empty
      ;;  strings. This can happen in XEmacs if leading or trailing spaces
      ;;  are present.
      (dolist (elem (if (stringp env) (split-string env " ") ()))
        (push elem process-environment))
      (mh-handle-process-error
       command (apply #'call-process (expand-file-name command mh-progs)
                      nil t nil (mh-list-to-string args))))))

(defun mh-exec-cmd-daemon (command filter &rest args)
  "Execute MH command COMMAND in the background.

If FILTER is non-nil then it is used to process the output
otherwise the default filter `mh-process-daemon' is used. See
`set-process-filter' for more details of FILTER.

ARGS are passed to COMMAND as command line arguments."
555
  (with-current-buffer (get-buffer-create mh-log-buffer)
Bill Wohler's avatar
Bill Wohler committed
556 557 558 559 560 561 562 563 564 565
    (mh-truncate-log-buffer))
  (let* ((process-connection-type nil)
         (process (apply 'start-process
                         command nil
                         (expand-file-name command mh-progs)
                         (mh-list-to-string args))))
    (set-process-filter process (or filter 'mh-process-daemon))
    process))

(defun mh-exec-cmd-env-daemon (env command filter &rest args)
566
  "In environment ENV, execute mh-command COMMAND in the background.
Bill Wohler's avatar
Bill Wohler committed
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625

ENV is nil or a string of space-separated \"var=value\" elements.
Signals an error if process does not complete successfully.

If FILTER is non-nil then it is used to process the output
otherwise the default filter `mh-process-daemon' is used. See
`set-process-filter' for more details of FILTER.

ARGS are passed to COMMAND as command line arguments."
  (let ((process-environment process-environment))
    (dolist (elem (if (stringp env) (split-string env " ") ()))
      (push elem process-environment))
    (apply #'mh-exec-cmd-daemon command filter args)))

(defun mh-process-daemon (process output)
  "PROCESS daemon that puts OUTPUT into a temporary buffer.
Any output from the process is displayed in an asynchronous
pop-up window."
  (with-current-buffer (get-buffer-create mh-log-buffer)
    (insert-before-markers output)
    (display-buffer mh-log-buffer)))

(defun mh-exec-cmd-quiet (raise-error command &rest args)
  "Signal RAISE-ERROR if COMMAND with ARGS fails.
Execute MH command COMMAND with ARGS. ARGS is a list of strings.
Return at start of mh-temp buffer, where output can be parsed and
used.
Returns value of `call-process', which is 0 for success, unless
RAISE-ERROR is non-nil, in which case an error is signaled if
`call-process' returns non-0."
  (set-buffer (get-buffer-create mh-temp-buffer))
  (erase-buffer)
  (let ((value
         (apply 'call-process
                (expand-file-name command mh-progs) nil t nil
                args)))
    (goto-char (point-min))
    (if raise-error
        (mh-handle-process-error command value)
      value)))

(defun mh-exec-cmd-output (command display &rest args)
  "Execute MH command COMMAND with DISPLAY flag and ARGS.
Put the output into buffer after point.
Set mark after inserted text.
Output is expected to be shown to user, not parsed by MH-E."
  (push-mark (point) t)
  (apply 'call-process
         (expand-file-name command mh-progs) nil t display
         (mh-list-to-string args))

  ;; The following is used instead of 'exchange-point-and-mark because the
  ;; latter activates the current region (between point and mark), which
  ;; turns on highlighting.  So prior to this bug fix, doing "inc" would
  ;; highlight a region containing the new messages, which is undesirable.
  ;; The bug wasn't seen in emacs21 but still occurred in XEmacs21.4.
  (mh-exchange-point-and-mark-preserving-active-mark))

;; Shush compiler.
626 627
(mh-do-in-xemacs
  (defvar mark-active))
Bill Wohler's avatar
Bill Wohler committed
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657

(defun mh-exchange-point-and-mark-preserving-active-mark ()
  "Put the mark where point is now, and point where the mark is now.
This command works even when the mark is not active, and
preserves whether the mark is active or not."
  (interactive nil)
  (let ((is-active (and (boundp 'mark-active) mark-active)))
    (let ((omark (mark t)))
      (if (null omark)
          (error "No mark set in this buffer"))
      (set-mark (point))
      (goto-char omark)
      (if (boundp 'mark-active)
          (setq mark-active is-active))
      nil)))

(defun mh-exec-lib-cmd-output (command &rest args)
  "Execute MH library command COMMAND with ARGS.
Put the output into buffer after point.
Set mark after inserted text."
  (apply 'mh-exec-cmd-output (expand-file-name command mh-lib-progs) nil args))

(defun mh-handle-process-error (command status)
  "Raise error if COMMAND returned non-zero STATUS, otherwise return STATUS."
  (if (equal status 0)
      status
    (goto-char (point-min))
    (insert (if (integerp status)
                (format "%s: exit code %d\n" command status)
              (format "%s: %s\n" command status)))
658 659
    (let ((error-message (buffer-substring (point-min) (point-max))))
      (with-current-buffer (get-buffer-create mh-log-buffer)
Bill Wohler's avatar
Bill Wohler committed
660 661 662 663 664 665 666
        (mh-truncate-log-buffer)
        (insert error-message)))
    (error "%s failed, check buffer %s for error message"
           command mh-log-buffer)))



667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
;;; MH-E Customization Support Routines

;; Shush compiler (Emacs 21 and XEmacs).
(defvar customize-package-emacs-version-alist)

;; Temporary function and data structure used customization.
;; These will be unbound after the options are defined.
(defmacro mh-strip-package-version (args)
  "Strip :package-version keyword and its value from ARGS.
In Emacs versions that support the :package-version keyword,
ARGS is returned unchanged."
  `(if (boundp 'customize-package-emacs-version-alist)
       ,args
     (let (seen)
       (loop for keyword in ,args
             if (cond ((eq keyword ':package-version) (setq seen t) nil)
                      (seen (setq seen nil) nil)
                      (t t))
             collect keyword))))

687
(defmacro defgroup-mh (symbol members doc &rest args)
688 689 690 691 692 693 694
  "Declare SYMBOL as a customization group containing MEMBERS.
See documentation for `defgroup' for a description of the arguments
SYMBOL, MEMBERS, DOC and ARGS.
This macro is used by Emacs versions that lack the :package-version
keyword, introduced in Emacs 22."
  (declare (doc-string 3))
  `(defgroup ,symbol ,members ,doc ,@(mh-strip-package-version args)))
695
(put 'defgroup-mh 'lisp-indent-function 'defun)
696

697
(defmacro defcustom-mh (symbol value doc &rest args)
698 699 700 701 702 703 704
  "Declare SYMBOL as a customizable variable that defaults to VALUE.
See documentation for `defcustom' for a description of the arguments
SYMBOL, VALUE, DOC and ARGS.
This macro is used by Emacs versions that lack the :package-version
keyword, introduced in Emacs 22."
  (declare (doc-string 3))
  `(defcustom ,symbol ,value ,doc ,@(mh-strip-package-version args)))
705
(put 'defcustom-mh 'lisp-indent-function 'defun)
706

707
(defmacro defface-mh (face spec doc &rest args)
708 709 710 711 712 713 714
  "Declare FACE as a customizable face that defaults to SPEC.
See documentation for `defface' for a description of the arguments
FACE, SPEC, DOC and ARGS.
This macro is used by Emacs versions that lack the :package-version
keyword, introduced in Emacs 22."
  (declare (doc-string 3))
  `(defface ,face ,spec ,doc ,@(mh-strip-package-version args)))
715
(put 'defface-mh 'lisp-indent-function 'defun)
716 717 718



Bill Wohler's avatar
Bill Wohler committed
719 720
;;; Variant Support

721
(defcustom-mh mh-path nil
Bill Wohler's avatar
Bill Wohler committed
722 723 724
  "*Additional list of directories to search for MH.
See `mh-variant'."
  :group 'mh-e
725
  :type '(repeat (directory))
726
  :package-version '(MH-E . "8.0"))
Bill Wohler's avatar
Bill Wohler committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749

(defun mh-variants ()
  "Return a list of installed variants of MH on the system.
This function looks for MH in `mh-sys-path', `mh-path' and
`exec-path'. The format of the list of variants that is returned
is described by the variable `mh-variants'."
  (if mh-variants
      mh-variants
    (let ((list-unique))
      ;; Make a unique list of directories, keeping the given order.
      ;; We don't want the same MH variant to be listed multiple times.
      (loop for dir in (append mh-path mh-sys-path exec-path) do
            (setq dir (file-chase-links (directory-file-name dir)))
            (add-to-list 'list-unique dir))
      (loop for dir in (nreverse list-unique) do
            (when (and dir (file-directory-p dir) (file-readable-p dir))
              (let ((variant (mh-variant-info dir)))
                (if variant
                    (add-to-list 'mh-variants variant)))))
      mh-variants)))

(defun mh-variant-info (dir)
  "Return MH variant found in DIR, or nil if none present."
750 751
  (let ((tmp-buffer (get-buffer-create mh-temp-buffer)))
    (with-current-buffer tmp-buffer
Bill Wohler's avatar
Bill Wohler committed
752 753 754
      (cond
       ((mh-variant-mh-info dir))
       ((mh-variant-nmh-info dir))
755
       ((mh-variant-gnu-mh-info dir))))))
Bill Wohler's avatar
Bill Wohler committed
756 757

(defun mh-variant-mh-info (dir)
758
  "Return info for MH variant in DIR assuming a temporary buffer is set up."
Bill Wohler's avatar
Bill Wohler committed
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
  ;; MH does not have the -version option.
  ;; Its version number is included in the output of "-help" as:
  ;;
  ;; version: MH 6.8.4 #2[UCI] (burrito) of Fri Jan 15 20:01:39 EST 1999
  ;; options: [ATHENA] [BIND] [DUMB] [LIBLOCKFILE] [LOCALE] [MAILGROUP] [MHE]
  ;;          [MHRC] [MIME] [MORE='"/usr/bin/sensible-pager"'] [NLINK_HACK]
  ;;          [NORUSERPASS] [OVERHEAD] [POP] [POPSERVICE='"pop-3"'] [RENAME]
  ;;          [RFC1342] [RPATHS] [RPOP] [SENDMTS] [SMTP] [SOCKETS]
  ;;          [SPRINTFTYPE=int] [SVR4] [SYS5] [SYS5DIR] [TERMINFO]
  ;;          [TYPESIG=void] [UNISTD] [UTK] [VSPRINTF]
  (let ((mhparam (expand-file-name "mhparam" dir)))
    (when (mh-file-command-p mhparam)
      (erase-buffer)
      (call-process mhparam nil '(t nil) nil "-help")
      (goto-char (point-min))
      (when (search-forward-regexp "version: MH \\(\\S +\\)" nil t)
        (let ((version (format "MH %s" (match-string 1))))
          (erase-buffer)
          (call-process mhparam nil '(t nil) nil "libdir")
          (goto-char (point-min))
          (when (search-forward-regexp "^.*$" nil t)
            (let ((libdir (match-string 0)))
              `(,version
                (variant        mh)
                (mh-lib-progs   ,libdir)
                (mh-lib         ,libdir)
                (mh-progs       ,dir)
                (flists         nil)))))))))

788 789 790
(defun mh-variant-gnu-mh-info (dir)
  "Return info for GNU mailutils MH variant in DIR.
This assumes that a temporary buffer is set up."
Bill Wohler's avatar
Bill Wohler committed
791 792 793 794 795 796 797 798 799 800 801 802
  ;; 'mhparam -version' output:
  ;; mhparam (GNU mailutils 0.3.2)
  (let ((mhparam (expand-file-name "mhparam" dir)))
    (when (mh-file-command-p mhparam)
      (erase-buffer)
      (call-process mhparam nil '(t nil) nil "-version")
      (goto-char (point-min))
      (when (search-forward-regexp "mhparam (\\(GNU [Mm]ailutils \\S +\\))"
                                   nil t)
        (let ((version (match-string 1))
              (mh-progs dir))
          `(,version
803
            (variant        gnu-mh)
Bill Wohler's avatar
Bill Wohler committed
804 805 806 807 808 809 810
            (mh-lib-progs   ,(mh-profile-component "libdir"))
            (mh-lib         ,(mh-profile-component "etcdir"))
            (mh-progs       ,dir)
            (flists         ,(file-exists-p
                              (expand-file-name "flists" dir)))))))))

(defun mh-variant-nmh-info (dir)
811
  "Return info for nmh variant in DIR assuming a temporary buffer is set up."
Bill Wohler's avatar
Bill Wohler committed
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
  ;; `mhparam -version' outputs:
  ;; mhparam -- nmh-1.1-RC1 [compiled on chaak at Fri Jun 20 11:03:28 PDT 2003]
  (let ((mhparam (expand-file-name "mhparam" dir)))
    (when (mh-file-command-p mhparam)
      (erase-buffer)
      (call-process mhparam nil '(t nil) nil "-version")
      (goto-char (point-min))
      (when (search-forward-regexp "mhparam -- nmh-\\(\\S +\\)" nil t)
        (let ((version (format "nmh %s" (match-string 1)))
              (mh-progs dir))
          `(,version
            (variant        nmh)
            (mh-lib-progs   ,(mh-profile-component "libdir"))
            (mh-lib         ,(mh-profile-component "etcdir"))
            (mh-progs       ,dir)
            (flists         ,(file-exists-p
                              (expand-file-name "flists" dir)))))))))

(defun mh-file-command-p (file)
  "Return t if file FILE is the name of a executable regular file."
  (and (file-regular-p file) (file-executable-p file)))

(defun mh-variant-set-variant (variant)
835
  "Set up the system variables for the MH variant named VARIANT.
Bill Wohler's avatar
Bill Wohler committed
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
If VARIANT is a string, use that key in the alist returned by the
function `mh-variants'.
If VARIANT is a symbol, select the first entry that matches that
variant."
  (cond
   ((stringp variant)                   ;e.g. "nmh 1.1-RC1"
    (when (assoc variant (mh-variants))
      (let* ((alist (cdr (assoc variant (mh-variants))))
             (lib-progs (cadr (assoc 'mh-lib-progs alist)))
             (lib       (cadr (assoc 'mh-lib       alist)))
             (progs     (cadr (assoc 'mh-progs     alist)))
             (flists    (cadr (assoc 'flists       alist))))
        ;;(set-default mh-variant variant)
        (setq mh-x-mailer-string     nil
              mh-flists-present-flag flists
              mh-lib-progs           lib-progs
              mh-lib                 lib
              mh-progs               progs
              mh-variant-in-use      variant))))
   ((symbolp variant)                   ;e.g. 'nmh (pick the first match)
    (loop for variant-list in (mh-variants)
          when (eq variant (cadr (assoc 'variant (cdr variant-list))))
          return (let* ((version   (car variant-list))
                        (alist (cdr variant-list))
                        (lib-progs (cadr (assoc 'mh-lib-progs alist)))
                        (lib       (cadr (assoc 'mh-lib       alist)))
                        (progs     (cadr (assoc 'mh-progs     alist)))
                        (flists    (cadr (assoc 'flists       alist))))
                   ;;(set-default mh-variant flavor)
                   (setq mh-x-mailer-string     nil
                         mh-flists-present-flag flists
                         mh-lib-progs           lib-progs
                         mh-lib                 lib
                         mh-progs               progs
                         mh-variant-in-use      version)
                   t)))))

(defun mh-variant-p (&rest variants)
  "Return t if variant is any of VARIANTS.
875
Currently known variants are 'MH, 'nmh, and 'gnu-mh."
Bill Wohler's avatar
Bill Wohler committed
876 877 878 879 880 881 882
  (let ((variant-in-use
         (cadr (assoc 'variant (assoc mh-variant-in-use (mh-variants))))))
    (not (null (member variant-in-use variants)))))

(defun mh-profile-component (component)
  "Return COMPONENT value from mhparam, or nil if unset."
  (save-excursion
883 884 885
    ;; MH and nmh use -components, GNU mailutils MH uses -component.
    ;; Since MH and nmh work with an unambiguous prefix, the `s' is
    ;; dropped here.
886
    (mh-exec-cmd-quiet nil "mhparam" "-component" component)
Bill Wohler's avatar
Bill Wohler committed
887 888 889 890 891 892 893 894 895
    (mh-profile-component-value component)))

(defun mh-profile-component-value (component)
  "Find and return the value of COMPONENT in the current buffer.
Returns nil if the component is not in the buffer."
  (let ((case-fold-search t))
    (goto-char (point-min))
    (cond ((not (re-search-forward (format "^%s:" component) nil t)) nil)
          ((looking-at "[\t ]*$") nil)
Bill Wohler's avatar
Bill Wohler committed
896
          (t
Bill Wohler's avatar
Bill Wohler committed
897 898 899 900 901 902 903 904 905 906
           (re-search-forward "[\t ]*\\([^\t \n].*\\)$" nil t)
           (let ((start (match-beginning 1)))
             (end-of-line)
             (buffer-substring start (point)))))))

(defun mh-variant-set (variant)
  "Set the MH variant to VARIANT.
Sets `mh-progs', `mh-lib', `mh-lib-progs' and
`mh-flists-present-flag'.
If the VARIANT is \"autodetect\", then first try nmh, then MH and
907
finally GNU mailutils MH."
Bill Wohler's avatar
Bill Wohler committed
908 909 910 911 912
  (interactive
   (list (completing-read
          "MH variant: "
          (mapcar (lambda (x) (list (car x))) (mh-variants))
          nil t)))
913 914 915 916 917

  ;; TODO Remove mu-mh backwards compatibility in 9.0.
  (when (and (stringp variant)
             (string-match "^mu-mh"  variant))
    (message
Bill Wohler's avatar
Bill Wohler committed
918
     (format "%s\n%s; %s" "The variant name mu-mh has been renamed to gnu-mh"
919 920 921 922 923
             "and will be removed in MH-E 9.0"
             "try M-x customize-option mh-variant"))
    (sit-for 5)
    (setq variant (concat "gnu-mh" (substring variant (match-end 0)))))

Bill Wohler's avatar
Bill Wohler committed
924 925 926 927 928 929 930 931 932
  (let ((valid-list (mapcar (lambda (x) (car x)) (mh-variants))))
    (cond
     ((eq variant 'none))
     ((eq variant 'autodetect)
      (cond
       ((mh-variant-set-variant 'nmh)
        (message "%s installed as MH variant" mh-variant-in-use))
       ((mh-variant-set-variant 'mh)
        (message "%s installed as MH variant" mh-variant-in-use))
933
       ((mh-variant-set-variant 'gnu-mh)
Bill Wohler's avatar
Bill Wohler committed
934 935 936 937 938 939 940 941
        (message "%s installed as MH variant" mh-variant-in-use))
       (t
        (message "No MH variant found on the system"))))
     ((member variant valid-list)
      (when (not (mh-variant-set-variant variant))
        (message "Warning: %s variant not found. Autodetecting..." variant)
        (mh-variant-set 'autodetect)))
     (t
942 943
      (message "Unknown variant %s; use %s"
               variant
944
               (mapconcat (lambda (x) (format "%s" (car x)))
Bill Wohler's avatar
Bill Wohler committed
945 946
                          (mh-variants) " or "))))))

947
(defcustom-mh mh-variant 'autodetect
Bill Wohler's avatar
Bill Wohler committed
948 949 950 951
  "*Specifies the variant used by MH-E.

The default setting of this option is \"Auto-detect\" which means
that MH-E will automatically choose the first of nmh, MH, or GNU
952
mailutils MH that it finds in the directories listed in
Bill Wohler's avatar
Bill Wohler committed
953
`mh-path' (which you can customize), `mh-sys-path', and
954 955 956
`exec-path'. If MH-E can't find MH at all, you may have to
customize `mh-path' and add the directory in which the command
\"mhparam\" is located. If, on the other hand, you have both nmh
957 958 959
and GNU mailutils MH installed (for example) and
`mh-variant-in-use' was initialized to nmh but you want to use
GNU mailutils MH, then you can set this option to \"gnu-mh\".
Bill Wohler's avatar
Bill Wohler committed
960 961 962

When this variable is changed, MH-E resets `mh-progs', `mh-lib',
`mh-lib-progs', `mh-flists-present-flag', and `mh-variant-in-use'
963 964 965
accordingly. Prior to version 8, it was often necessary to set
some of these variables in \"~/.emacs\"; now it is no longer
necessary and can actually cause problems."
Bill Wohler's avatar
Bill Wohler committed
966 967 968 969 970 971
  :type `(radio
          (const :tag "Auto-detect" autodetect)
          ,@(mapcar (lambda (x) `(const ,(car x))) (mh-variants)))
  :set (lambda (symbol value)
         (set-default symbol value)     ;Done in mh-variant-set-variant!
         (mh-variant-set value))
972
  :group 'mh-e
973
  :package-version '(MH-E . "8.0"))
974 975 976



Bill Wohler's avatar
Bill Wohler committed
977
;;; MH-E Customization
Richard M. Stallman's avatar
Richard M. Stallman committed
978

Bill Wohler's avatar
Bill Wohler committed
979 980 981 982
;; All of the defgroups, defcustoms, and deffaces in MH-E are found
;; here. This makes it possible to customize modules that aren't
;; loaded yet. It also makes it easier to organize the customization
;; groups.
Bill Wohler's avatar
Bill Wohler committed
983

Bill Wohler's avatar
Bill Wohler committed
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
;; This section contains the following sub-sections:

;; 1. MH-E Customization Groups

;;    These are the customization group definitions. Every group has a
;;    associated manual node. The ordering is alphabetical, except for
;;    the groups mh-faces and mh-hooks which are last .

;; 2. MH-E Customization

;;    These are the actual customization variables. There is a
;;    sub-section for each group in the MH-E Customization Groups
;;    section, in the same order, separated by page breaks. Within
;;    each section, variables are sorted alphabetically.

;; 3. Hooks

;;    All hooks must be placed in the mh-hook group; in addition, add
;;    the group associated with the manual node in which the hook is
;;    described. Since the mh-hook group appears near the end of this
;;    section, the hooks will appear at the end of these other groups.

;; 4. Faces

;;    All faces must be placed in the mh-faces group; in addition, add
;;    the group associated with the manual node in which the face is
;;    described. Since the mh-faces group appears near the end of this
;;    section, the faces will appear at the end of these other groups.

(defun mh-customize (&optional delete-other-windows-flag)
  "Customize MH-E variables.
If optional argument DELETE-OTHER-WINDOWS-FLAG is non-nil, other
windows in the frame are removed."
  (interactive "P")
  (customize-group 'mh-e)
  (when delete-other-windows-flag
    (delete-other-windows)))
Richard M. Stallman's avatar
Richard M. Stallman committed
1021

1022 1023
(if (boundp 'customize-package-emacs-version-alist)
    (add-to-list 'customize-package-emacs-version-alist
1024 1025 1026
                 '(MH-E ("6.0" . "22.1") ("6.1" . "22.1") ("7.0" . "22.1")
                        ("7.1" . "22.1") ("7.2" . "22.1") ("7.3" . "22.1")
                        ("7.4" . "22.1") ("8.0" . "22.1"))))
1027

Bill Wohler's avatar
Bill Wohler committed
1028 1029


Bill Wohler's avatar
Bill Wohler committed
1030 1031
;;; MH-E Customization Groups

1032
(defgroup-mh mh-e nil
Bill Wohler's avatar
Bill Wohler committed
1033 1034 1035 1036
  "Emacs interface to the MH mail system.
MH is the Rand Mail Handler. Other implementations include nmh
and GNU mailutils."
  :link '(custom-manual "(mh-e)Top")
1037
  :group 'mail
1038
  :package-version '(MH-E . "8.0"))
Bill Wohler's avatar
Bill Wohler committed
1039

1040
(defgroup-mh mh-alias nil
Bill Wohler's avatar
Bill Wohler committed
1041 1042 1043
  "Aliases."
  :link '(custom-manual "(mh-e)Aliases")
  :prefix "mh-alias-"
1044
  :group 'mh-e
1045
  :package-version '(MH-E . "7.1"))
Bill Wohler's avatar
Bill Wohler committed
1046

1047
(defgroup-mh mh-folder nil
Bill Wohler's avatar
Bill Wohler committed
1048 1049 1050
  "Organizing your mail with folders."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Folders")
1051
  :group 'mh-e
1052
  :package-version '(MH-E . "7.1"))
Bill Wohler's avatar
Bill Wohler committed
1053

1054
(defgroup-mh mh-folder-selection nil
Bill Wohler's avatar
Bill Wohler committed
1055 1056 1057
  "Folder selection."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Folder Selection")
1058
  :group 'mh-e
1059
  :package-version '(MH-E . "8.0"))
Bill Wohler's avatar
Bill Wohler committed
1060

1061
(defgroup-mh mh-identity nil
Bill Wohler's avatar
Bill Wohler committed
1062 1063 1064
  "Identities."
  :link '(custom-manual "(mh-e)Identities")
  :prefix "mh-identity-"
1065
  :group 'mh-e
1066
  :package-version '(MH-E . "7.1"))
Bill Wohler's avatar
Bill Wohler committed
1067

1068
(defgroup-mh mh-inc nil
Bill Wohler's avatar
Bill Wohler committed
1069 1070 1071
  "Incorporating your mail."
  :prefix "mh-inc-"
  :link '(custom-manual "(mh-e)Incorporating Mail")
1072
  :group 'mh-e
1073
  :package-version '(MH-E . "8.0"))
Bill Wohler's avatar
Bill Wohler committed
1074

1075
(defgroup-mh mh-junk nil
Bill Wohler's avatar
Bill Wohler committed
1076 1077 1078
  "Dealing with junk mail."
  :link '(custom-manual "(mh-e)Junk")
  :prefix "mh-junk-"
1079
  :group 'mh-e
1080
  :package-version '(MH-E . "7.3"))
Bill Wohler's avatar
Bill Wohler committed
1081

1082
(defgroup-mh mh-letter nil
Bill Wohler's avatar
Bill Wohler committed
1083 1084 1085
  "Editing a draft."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Editing Drafts")
1086
  :group 'mh-e
1087
  :package-version '(MH-E . "7.1"))
Bill Wohler's avatar
Bill Wohler committed
1088

1089
(defgroup-mh mh-ranges nil
Bill Wohler's avatar
Bill Wohler committed
1090 1091 1092
  "Ranges."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Ranges")
1093
  :group 'mh-e
1094
  :package-version '(MH-E . "8.0"))
Bill Wohler's avatar
Bill Wohler committed
1095

1096
(defgroup-mh mh-scan-line-formats nil
Bill Wohler's avatar
Bill Wohler committed
1097 1098 1099
  "Scan line formats."
  :link '(custom-manual "(mh-e)Scan Line Formats")
  :prefix "mh-"
1100
  :group 'mh-e
1101
  :package-version '(MH-E . "8.0"))
Bill Wohler's avatar
Bill Wohler committed
1102

1103
(defgroup-mh mh-search nil
Bill Wohler's avatar
Bill Wohler committed
1104 1105 1106
  "Searching."
  :link '(custom-manual "(mh-e)Searching")
  :prefix "mh-search-"
1107
  :group 'mh-e
1108
  :package-version '(MH-E . "8.0"))
Bill Wohler's avatar
Bill Wohler committed
1109

1110
(defgroup-mh mh-sending-mail nil
Bill Wohler's avatar
Bill Wohler committed
1111 1112 1113
  "Sending mail."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Sending Mail")
1114
  :group 'mh-e
1115
  :package-version '(MH-E . "8.0"))
Bill Wohler's avatar
Bill Wohler committed
1116

1117
(defgroup-mh mh-sequences nil
Bill Wohler's avatar
Bill Wohler committed
1118 1119 1120
  "Sequences."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Sequences")
Bill Wohler's avatar