mh-e.el 123 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

Bill Wohler's avatar
Bill Wohler committed
3 4
;; Copyright (C) 1985, 1986, 1987, 1988,
;;  1990, 1992, 1993, 1994, 1995, 1997, 1999,
5
;;  2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Richard M. Stallman's avatar
Richard M. Stallman committed
6

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

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

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

Karl Heuer's avatar
Karl Heuer committed
19
;; GNU Emacs is distributed in the hope that it will be useful,
Richard M. Stallman's avatar
Richard M. Stallman committed
20 21 22 23 24
;; 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
Erik Naggum's avatar
Erik Naggum committed
25
;; along with GNU Emacs; see the file COPYING.  If not, write to the
Lute Kamstra's avatar
Lute Kamstra committed
26 27
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
Richard M. Stallman's avatar
Richard M. Stallman committed
28 29 30

;;; Commentary:

Bill Wohler's avatar
Bill Wohler committed
31
;; How to use:
Bill Wohler's avatar
Bill Wohler committed
32 33
;;   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
34
;;   M-x mh-smail to send mail.  From within the mail reader, "s" works, too.
Erik Naggum's avatar
Erik Naggum committed
35

Bill Wohler's avatar
Bill Wohler committed
36 37 38 39
;; 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
40

Bill Wohler's avatar
Bill Wohler committed
41 42 43 44 45 46
;; 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
47
;; MH (Message Handler) is a powerful mail reader.
Erik Naggum's avatar
Erik Naggum committed
48

Bill Wohler's avatar
Bill Wohler committed
49 50
;; The MH newsgroup is comp.mail.mh; the mailing list is mh-users@ics.uci.edu
;; (send to mh-users-request to be added). See the monthly Frequently Asked
Bill Wohler's avatar
Bill Wohler committed
51
;; Questions posting there for information on getting MH and MH-E:
Bill Wohler's avatar
Bill Wohler committed
52
;;   http://www.faqs.org/faqs/mail/mh-faq/part1/preamble.html
Erik Naggum's avatar
Erik Naggum committed
53

Bill Wohler's avatar
Bill Wohler committed
54
;; N.B. MH must have been compiled with the MHE compiler flag or several
Bill Wohler's avatar
Bill Wohler committed
55
;; features necessary for MH-E will be missing from MH commands, specifically
Erik Naggum's avatar
Erik Naggum committed
56 57
;; the -build switch to repl and forw.

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

60 61 62
;; MH-E is supported in GNU Emacs 21 and 22 as well as XEmacs 21
;; (except for versions 21.5.9-21.5.16), with MH 6.8.4 on, nmh 1.0.4
;; on, and GNU mailutils 0.4 on.
Bill Wohler's avatar
Bill Wohler committed
63 64 65 66 67

;; 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
68

Bill Wohler's avatar
Bill Wohler committed
69 70 71 72 73 74
;;   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
75 76
;;   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
77 78

;; Feature Requests:
Bill Wohler's avatar
Bill Wohler committed
79
;;   https://sourceforge.net/tracker/?group_id=13357&atid=363357
Bill Wohler's avatar
Bill Wohler committed
80 81 82

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

Erik Naggum's avatar
Erik Naggum committed
84
;;; Change Log:
Erik Naggum's avatar
Erik Naggum committed
85 86 87

;; 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
88 89 90 91
;; 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
92

Richard M. Stallman's avatar
Richard M. Stallman committed
93 94
;;; Code:

Bill Wohler's avatar
Bill Wohler committed
95 96 97 98
;; 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.
(require 'mh-loaddefs)
Bill Wohler's avatar
Bill Wohler committed
99

Bill Wohler's avatar
Bill Wohler committed
100
(mh-require-cl)
Bill Wohler's avatar
Bill Wohler committed
101

Bill Wohler's avatar
Bill Wohler committed
102 103
(eval-and-compile
  (defvar mh-xemacs-flag (featurep 'xemacs)
104
    "Non-nil means the current Emacs is XEmacs."))
105

Bill Wohler's avatar
Bill Wohler committed
106 107 108
(mh-do-in-xemacs
  (require 'mh-xemacs))

109
(require 'mh-buffers)
Bill Wohler's avatar
Bill Wohler committed
110
(require 'mh-compat)
Bill Wohler's avatar
Bill Wohler committed
111

Bill Wohler's avatar
Bill Wohler committed
112

Richard M. Stallman's avatar
Richard M. Stallman committed
113

Bill Wohler's avatar
Bill Wohler committed
114
;;; Global Variables
Bill Wohler's avatar
Bill Wohler committed
115

Bill Wohler's avatar
Bill Wohler committed
116 117
;; 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
118

119
(defconst mh-version "7.93+cvs" "Version number of MH-E.")
Bill Wohler's avatar
Bill Wohler committed
120

Bill Wohler's avatar
Bill Wohler committed
121
;; Variants
Bill Wohler's avatar
Bill Wohler committed
122

Bill Wohler's avatar
Bill Wohler committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
(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/"
    "/usr/local/bin/mu-mh/"             ; GNU mailutils - default
    "/usr/bin/mu-mh/")                  ; GNU mailutils - packaged
  "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
138

Bill Wohler's avatar
Bill Wohler committed
139 140 141 142
(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
143

Bill Wohler's avatar
Bill Wohler committed
144 145 146 147
(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
148

Bill Wohler's avatar
Bill Wohler committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
(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
168

Bill Wohler's avatar
Bill Wohler committed
169
;; Profile Components
Richard M. Stallman's avatar
Richard M. Stallman committed
170

Bill Wohler's avatar
Bill Wohler committed
171 172 173 174
(defvar mh-draft-folder nil
  "Cached value of the \"Draft-Folder:\" MH profile component.
Name of folder containing draft messages.
Nil means do not use a draft folder.")
175

Bill Wohler's avatar
Bill Wohler committed
176 177 178 179
(defvar mh-inbox nil
  "Cached value of the \"Inbox:\" MH profile component.
Set to \"+inbox\" if no such component.
Name of the Inbox folder.")
180

Bill Wohler's avatar
Bill Wohler committed
181 182 183 184 185
(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
186 187

(defvar mh-folder-mode-map (make-keymap)
Bill Wohler's avatar
Bill Wohler committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
  "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
218

219 220 221
(defvar mh-arrow-marker nil
  "Marker for arrow display in fringe.")

Bill Wohler's avatar
Bill Wohler committed
222 223 224 225 226 227
(defvar mh-colors-available-flag nil
  "Non-nil means colors are available.")

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

228 229
(defvar mh-delete-list nil
  "List of message numbers to delete.
230 231
This variable can be used by
`mh-before-commands-processed-hook'.")
Bill Wohler's avatar
Bill Wohler committed
232

Bill Wohler's avatar
Bill Wohler committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
(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.")

256 257
(defvar mh-refile-list nil
  "List of folder names in `mh-seq-list'.
258 259
This variable can be used by
`mh-before-commands-processed-hook'.")
Richard M. Stallman's avatar
Richard M. Stallman committed
260

Bill Wohler's avatar
Bill Wohler committed
261 262
(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
263

Bill Wohler's avatar
Bill Wohler committed
264 265 266 267 268 269 270 271 272
(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.")
273

Bill Wohler's avatar
Bill Wohler committed
274 275 276 277
(defvar mh-showing-mode nil
  "If non-nil, show the message in a separate window.")

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

Bill Wohler's avatar
Bill Wohler committed
281
;; MH-Show Locals (alphabetical)
282

Bill Wohler's avatar
Bill Wohler committed
283 284
(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
285

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

Bill Wohler's avatar
Bill Wohler committed
289
;; MH-Letter Locals
Richard M. Stallman's avatar
Richard M. Stallman committed
290

Bill Wohler's avatar
Bill Wohler committed
291 292 293 294 295
(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
296

Bill Wohler's avatar
Bill Wohler committed
297 298
(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
299

Bill Wohler's avatar
Bill Wohler committed
300 301 302 303 304
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
305

Bill Wohler's avatar
Bill Wohler committed
306 307 308
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
309

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

Bill Wohler's avatar
Bill Wohler committed
313 314
(defvar mh-sent-from-msg nil
  "Number of msg assoc with this letter.")
Bill Wohler's avatar
Bill Wohler committed
315

Bill Wohler's avatar
Bill Wohler committed
316
;; Sequences
Richard M. Stallman's avatar
Richard M. Stallman committed
317

Bill Wohler's avatar
Bill Wohler committed
318 319 320
(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
321

Bill Wohler's avatar
Bill Wohler committed
322 323 324
(defvar mh-previous-seq nil
  "Cached value of the \"Previous-Sequence:\" MH profile component.
Name of the Previous sequence.")
325

Bill Wohler's avatar
Bill Wohler committed
326
;; Etc. (alphabetical)
Richard M. Stallman's avatar
Richard M. Stallman committed
327

Bill Wohler's avatar
Bill Wohler committed
328 329
(defvar mh-flists-present-flag nil
  "Non-nil means that we have \"flists\".")
330

Bill Wohler's avatar
Bill Wohler committed
331 332
(defvar mh-index-data-file ".mhe_index"
  "MH-E specific file where index seach info is stored.")
Richard M. Stallman's avatar
Richard M. Stallman committed
333

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

Bill Wohler's avatar
Bill Wohler committed
336 337
(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
338

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

Bill Wohler's avatar
Bill Wohler committed
342 343
(defvar mh-signature-separator "-- \n"
  "Text of a signature separator.
Bill Wohler's avatar
Bill Wohler committed
344

Bill Wohler's avatar
Bill Wohler committed
345 346 347 348 349
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.")
350

Bill Wohler's avatar
Bill Wohler committed
351 352 353
(defvar mh-signature-separator-regexp "^-- $"
  "This regular expression matches the signature separator.
See `mh-signature-separator'.")
354

Bill Wohler's avatar
Bill Wohler committed
355 356 357
(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
358

Bill Wohler's avatar
Bill Wohler committed
359 360 361 362 363
(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)
364

Bill Wohler's avatar
Bill Wohler committed
365 366 367 368
(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.")
369

Bill Wohler's avatar
Bill Wohler committed
370

371

Bill Wohler's avatar
Bill Wohler committed
372
;;; MH-E Entry Points
Bill Wohler's avatar
Bill Wohler committed
373 374 375 376 377

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

(defmacro mh-macro-expansion-time-gnus-version ()
  "Return Gnus version available at macro expansion time.
378 379 380
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
381 382 383 384 385 386

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

Karl Heuer's avatar
Karl Heuer committed
387
;;;###autoload
Richard M. Stallman's avatar
Richard M. Stallman committed
388
(defun mh-version ()
Bill Wohler's avatar
Bill Wohler committed
389
  "Display version information about MH-E and the MH mail handling system."
Richard M. Stallman's avatar
Richard M. Stallman committed
390
  (interactive)
Bill Wohler's avatar
Bill Wohler committed
391
  (set-buffer (get-buffer-create mh-info-buffer))
Richard M. Stallman's avatar
Richard M. Stallman committed
392
  (erase-buffer)
Bill Wohler's avatar
Bill Wohler committed
393 394 395 396 397 398 399 400 401 402 403 404 405
  ;; 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
406
  ;; MH version.
Bill Wohler's avatar
Bill Wohler committed
407 408 409 410 411 412
  (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
413 414 415 416 417
  ;; Linux version.
  (condition-case ()
      (call-process "uname" nil t nil "-a")
    (file-error))
  (goto-char (point-min))
Bill Wohler's avatar
Bill Wohler committed
418
  (display-buffer mh-info-buffer))
Richard M. Stallman's avatar
Richard M. Stallman committed
419

Bill Wohler's avatar
Bill Wohler committed
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444


;;; 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."
  (let ((new-list nil))
    (while l
      (cond ((null (car l)))
            ((symbolp (car l))
             (setq new-list (cons (symbol-name (car l)) new-list)))
            ((numberp (car l))
             (setq new-list (cons (int-to-string (car l)) new-list)))
            ((equal (car l) ""))
            ((stringp (car l)) (setq new-list (cons (car l) new-list)))
            ((listp (car l))
             (setq new-list (nconc (mh-list-to-string-1 (car l))
                                   new-list)))
            (t (error "Bad element in `mh-list-to-string': %s" (car l))))
      (setq l (cdr l)))
    new-list))
Karl Heuer's avatar
Karl Heuer committed
445

Richard M. Stallman's avatar
Richard M. Stallman committed
446 447


Bill Wohler's avatar
Bill Wohler committed
448 449 450 451
;;; 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
452

Bill Wohler's avatar
Bill Wohler committed
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
(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))
468 469
              (push (buffer-substring-no-properties (point)
                                                    (mh-line-end-position))
Bill Wohler's avatar
Bill Wohler committed
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
                    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."
Richard M. Stallman's avatar
Richard M. Stallman committed
493
  (save-excursion
Bill Wohler's avatar
Bill Wohler committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
    (set-buffer (get-buffer-create mh-log-buffer))
    (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."
Richard M. Stallman's avatar
Richard M. Stallman committed
513
  (save-excursion
Bill Wohler's avatar
Bill Wohler committed
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 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 626 627 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 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
    (set-buffer (get-buffer-create mh-temp-buffer))
    (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."
  (save-excursion
    (set-buffer (get-buffer-create mh-log-buffer))
    (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)
  "In ennvironment ENV, execute mh-command COMMAND in the background.

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.
(eval-when-compile (mh-do-in-xemacs (defvar mark-active)))

(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)))
    (save-excursion
      (let ((error-message (buffer-substring (point-min) (point-max))))
        (set-buffer (get-buffer-create mh-log-buffer))
        (mh-truncate-log-buffer)
        (insert error-message)))
    (error "%s failed, check buffer %s for error message"
           command mh-log-buffer)))



;;; Variant Support

(defcustom mh-path nil
  "*Additional list of directories to search for MH.
See `mh-variant'."
  :group 'mh-e
  :type '(repeat (directory)))

(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."
Bill Wohler's avatar
Bill Wohler committed
677
  (save-excursion
Bill Wohler's avatar
Bill Wohler committed
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 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 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
    (let ((tmp-buffer (get-buffer-create mh-temp-buffer)))
      (set-buffer tmp-buffer)
      (cond
       ((mh-variant-mh-info dir))
       ((mh-variant-nmh-info dir))
       ((mh-variant-mu-mh-info dir))))))

(defun mh-variant-mh-info (dir)
  "Return info for MH variant in DIR assuming a temporary buffer is setup."
  ;; 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)))))))))

(defun mh-variant-mu-mh-info (dir)
  "Return info for GNU mailutils variant in DIR.
This assumes that a temporary buffer is setup."
  ;; '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
            (variant        mu-mh)
            (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)
  "Return info for nmh variant in DIR assuming a temporary buffer is setup."
  ;; `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)
  "Setup the system variables for the MH variant named VARIANT.
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.
Currently known variants are 'MH, 'nmh, and 'mu-mh."
  (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
    (mh-exec-cmd-quiet nil "mhparam" "-components" component)
    (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
821
          (t
Bill Wohler's avatar
Bill Wohler committed
822 823 824 825 826 827 828 829 830 831 832 833 834 835 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
           (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
finally GNU mailutils."
  (interactive
   (list (completing-read
          "MH variant: "
          (mapcar (lambda (x) (list (car x))) (mh-variants))
          nil t)))
  (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))
       ((mh-variant-set-variant 'mu-mh)
        (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
      (message "Unknown variant; use %s"
               (mapconcat '(lambda (x) (format "%s" (car x)))
                          (mh-variants) " or "))))))

(defcustom mh-variant 'autodetect
  "*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
mailutils that it finds in the directories listed in
`mh-path' (which you can customize), `mh-sys-path', and
867 868 869 870 871 872
`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
and mailutils installed (for example) and `mh-variant-in-use' was
initialized to nmh but you want to use mailutils, then you can
set this option to \"mailutils\".
Bill Wohler's avatar
Bill Wohler committed
873 874 875

When this variable is changed, MH-E resets `mh-progs', `mh-lib',
`mh-lib-progs', `mh-flists-present-flag', and `mh-variant-in-use'
876 877 878
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
879 880 881 882 883 884 885
  :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))
  :group 'mh-e)
Richard M. Stallman's avatar
Richard M. Stallman committed
886 887 888



Bill Wohler's avatar
Bill Wohler committed
889
;;; MH-E Customization
Richard M. Stallman's avatar
Richard M. Stallman committed
890

Bill Wohler's avatar
Bill Wohler committed
891 892 893 894
;; 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
895

Bill Wohler's avatar
Bill Wohler committed
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
;; 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
933

Bill Wohler's avatar
Bill Wohler committed
934 935


Bill Wohler's avatar
Bill Wohler committed
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 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 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
;;; MH-E Customization Groups

(defgroup mh-e nil
  "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")
  :group 'mail)

(defgroup mh-alias nil
  "Aliases."
  :link '(custom-manual "(mh-e)Aliases")
  :prefix "mh-alias-"
  :group 'mh-e)

(defgroup mh-folder nil
  "Organizing your mail with folders."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Folders")
  :group 'mh-e)

(defgroup mh-folder-selection nil
  "Folder selection."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Folder Selection")
  :group 'mh-e)

(defgroup mh-identity nil
  "Identities."
  :link '(custom-manual "(mh-e)Identities")
  :prefix "mh-identity-"
  :group 'mh-e)

(defgroup mh-inc nil
  "Incorporating your mail."
  :prefix "mh-inc-"
  :link '(custom-manual "(mh-e)Incorporating Mail")
  :group 'mh-e)

(defgroup mh-junk nil
  "Dealing with junk mail."
  :link '(custom-manual "(mh-e)Junk")
  :prefix "mh-junk-"
  :group 'mh-e)

(defgroup mh-letter nil
  "Editing a draft."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Editing Drafts")
  :group 'mh-e)

(defgroup mh-ranges nil
  "Ranges."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Ranges")
  :group 'mh-e)

(defgroup mh-scan-line-formats nil
  "Scan line formats."
  :link '(custom-manual "(mh-e)Scan Line Formats")
  :prefix "mh-"
  :group 'mh-e)

(defgroup mh-search nil
  "Searching."
  :link '(custom-manual "(mh-e)Searching")
  :prefix "mh-search-"
  :group 'mh-e)

(defgroup mh-sending-mail nil
  "Sending mail."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Sending Mail")
  :group 'mh-e)

(defgroup mh-sequences nil
  "Sequences."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Sequences")
  :group 'mh-e)

(defgroup mh-show nil
  "Reading your mail."
  :prefix "mh-"
  :link '(custom-manual "(mh-e)Reading Mail")
  :group 'mh-e)

(defgroup mh-speedbar nil
  "The speedbar."
  :prefix "mh-speed-"
  :link '(custom-manual "(mh-e)Speedbar")
  :group 'mh-e)

(defgroup mh-thread nil
  "Threading."
  :prefix "mh-thread-"
  :link '(custom-manual "(mh-e)Threading")
  :group 'mh-e)

(defgroup mh-tool-bar nil
  "The tool bar"
  :link '(custom-manual "(mh-e)Tool Bar")
  :prefix "mh-"
  :group 'mh-e)

(defgroup mh-hooks nil
  "MH-E hooks."
  :link '(custom-manual "(mh-e)Top")
  :prefix "mh-"
  :group 'mh-e)

(defgroup mh-faces nil
  "Faces used in MH-E."
  :link '(custom-manual "(mh-e)Top")
  :prefix "mh-"
  :group 'faces
  :group 'mh-e)
Bill Wohler's avatar
Bill Wohler committed
1053 1054 1055



Bill Wohler's avatar
Bill Wohler committed
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
;;; Emacs Interface to the MH Mail System (:group mh-e)

;; See Variant Support, above.

;;; Aliases (:group 'mh-alias)

(defcustom mh-alias-completion-ignore-case-flag t
  "*Non-nil means don't consider case significant in MH alias completion.

As MH ignores case in the aliases, so too does MH-E. However, you
may turn off this option to make case significant which can be
used to segregate completion of your aliases. You might use
lowercase for mailing lists and uppercase for people."
  :type 'boolean
  :group 'mh-alias)

(defcustom mh-alias-expand-aliases-flag nil
  "*Non-nil means to expand aliases entered in the minibuffer.

In other words, aliases entered in the minibuffer will be
expanded to the full address in the message draft. By default,
this expansion is not performed."
  :type 'boolean
  :group 'mh-alias)

(defcustom mh-alias-flash-on-comma t
  "*Specify whether to flash address or warn on translation.

This option controls the behavior when a [comma] is pressed while
entering aliases or addresses. The default setting flashes the
address associated with an address in the minibuffer briefly, but
does not display a warning if the alias is not found."
  :type '(choice (const :tag "Flash but Don't Warn If No Alias" t)
                 (const :tag "Flash and Warn If No Alias" 1)
                 (const :tag "Don't Flash Nor Warn If No Alias" nil))
  :group 'mh-alias)

(defcustom mh-alias-insert-file nil
  "*Filename used to store a new MH-E alias.

The default setting of this option is \"Use Aliasfile Profile
Component\". This option can also hold the name of a file or a
list a file names. If this option is set to a list of file names,
or the \"Aliasfile:\" profile component contains more than one file
name, MH-E will prompt for one of them when MH-E adds an alias."
  :type '(choice (const :tag "Use Aliasfile Profile Component" nil)
                 (file :tag "Alias File")
                 (repeat :tag "List of Alias Files" file))
  :group 'mh-alias)

(defcustom mh-alias-insertion-location 'sorted
  "Specifies where new aliases are entered in alias files.

This option is set to \"Alphabetical\" by default. If you organize
your alias file in other ways, then adding aliases to the \"Top\"
or \"Bottom\" of your alias file might be more appropriate."
  :type '(choice (const :tag "Alphabetical" sorted)
                 (const :tag "Top" top)
                 (const :tag "Bottom" bottom))
  :group 'mh-alias)

(defcustom mh-alias-local-users t
  "*If on, local users are added to alias completion.

Aliases are created from \"/etc/passwd\" entries with a user ID
larger than a magical number, typically 200. This can be a handy
tool on a machine where you and co-workers exchange messages.
These aliases have the form \"local.first.last\" if a real name is
present in the password file. Otherwise, the alias will have the
form \"local.login\".

If you're on a system with thousands of users you don't know, and
the loading of local aliases slows MH-E down noticeably, then
turn this option off.

This option also takes a string which is executed to generate the
password file. For example, use \"ypcat passwd\" to obtain the
NIS password file."
  :type '(choice (boolean) (string))
  :group 'mh-alias)

(defcustom mh-alias-local-users-prefix "local."
  "*String prefixed to the real names of users from the password file.
This option can also be set to \"Use Login\".

For example, consider the following password file entry:

    psg:x:1000:1000:Peter S Galbraith,,,:/home/psg:/bin/tcsh

The following settings of this option will produce the associated
aliases:

    \"local.\"                  local.peter.galbraith
    \"\"                        peter.galbraith
    Use Login                   psg

This option has no effect if variable `mh-alias-local-users' is
turned off."
  :type '(choice (const :tag "Use Login" nil)
                 (string))
  :group 'mh-alias)

(defcustom mh-alias-passwd-gecos-comma-separator-flag t
  "*Non-nil means the gecos field in the password file uses a comma separator.

In the example in `mh-alias-local-users-prefix', commas are used
to separate different values within the so-called gecos field.
This is a fairly common usage. However, in the rare case that the
gecos field in your password file is not separated by commas and
whose contents may contain commas, you can turn this option off."
  :type 'boolean
  :group 'mh-alias)
Bill Wohler's avatar
Bill Wohler committed
1168

Bill Wohler's avatar
Bill Wohler committed
1169

1170

Bill Wohler's avatar
Bill Wohler committed
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
;;; Organizing Your Mail with Folders (:group 'mh-folder)

(defcustom mh-new-messages-folders t
  "Folders searched for the \"unseen\" sequence.

Set this option to \"Inbox\" to search the \"+inbox\" folder or
\"All\" to search all of the top level folders. Otherwise, list
the folders that should be searched with the \"Choose Folders\"
menu item.

See also `mh-recursive-folders-flag'."
  :type '(choice (const :tag "Inbox" t)
                 (const :tag "All" nil)
                 (repeat :tag "Choose Folders" (string :tag "Folder")))
  :group 'mh-folder)

(defcustom mh-ticked-messages-folders t
  "Folders searched for `mh-tick-seq'.

Set this option to \"Inbox\" to search the \"+inbox\" folder or
\"All\" to search all of the top level folders. Otherwise, list
the folders that should be searched with the \"Choose Folders\"
menu item.

See also `mh-recursive-folders-flag'."
  :type '(choice (const :tag "Inbox" t)
                 (const :tag "All" nil)
                 (repeat :tag "Choose Folders" (string :tag "Folder")))
  :group 'mh-folder)

(defcustom mh-large-folder 200
  "The number of messages that indicates a large folder.

If a folder is deemed to be large, that is the number of messages
in it exceed this value, then confirmation is needed when it is
visited. Even when `mh-show-threads-flag' is non-nil, the folder
is not automatically threaded, if it is large. If set to nil all
folders are treated as if they are small."
  :type '(choice (const :tag "No Limit") integer)
  :group 'mh-folder)

(defcustom mh-recenter-summary-flag nil
  "*Non-nil means to recenter the summary window.

If this option is turned on, recenter the summary window when the
show window is toggled off."
  :type 'boolean
  :group 'mh-folder)

(defcustom mh-recursive-folders-flag nil
  "*Non-nil means that commands which operate on folders do so recursively."
  :type 'boolean
  :group 'mh-folder)

(defcustom mh-sortm-args nil
  "*Additional arguments for \"sortm\"\\<mh-folder-mode-map>.

This option is consulted when a prefix argument is used with
\\[mh-sort-folder]. Normally default arguments to \"sortm\" are
specified in the MH profile. This option may be used to provide
an alternate view. For example, \"'(\"-nolimit\" \"-textfield\"
\"subject\")\" is a useful setting."
  :type 'string
  :group 'mh-folder)
1235

Bill Wohler's avatar
Bill Wohler committed
1236 1237 1238 1239 1240 1241 1242


;;; Folder Selection (:group 'mh-folder-selection)

(defcustom mh-default-folder-for-message-function nil
  "Function to select a default folder for refiling or \"Fcc:\".

1243 1244 1245 1246 1247
When this function is called, the current buffer contains the message
being refiled and point is at the start of the message. This function
should return the default folder as a string with a leading \"+\"
sign. It can also return nil so that the last folder name is used as
the default, or an empty string to suppress the default entirely."
Bill Wohler's avatar
Bill Wohler committed
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
  :type 'function
  :group 'mh-folder-selection)

(defcustom mh-default-folder-list nil
  "*List of addresses and folders.

The folder name associated with the first address found in this
list is used as the default for `mh-refile-msg' and similar
functions. Each element in this list contains a \"Check Recipient\"
item. If this item is turned on, then the address is checked
against the recipient instead of the sender. This is useful for
mailing lists.

See `mh-prompt-for-refile-folder' and `mh-folder-from-address'
for more information."
  :type '(repeat (list (regexp :tag "Address")
                       (string :tag "Folder")
                       (boolean :tag "Check Recipient")))
  :group 'mh-folder-selection)

(defcustom mh-default-folder-must-exist-flag t
  "*Non-nil means guessed folder name must exist to be used.

If the derived folder does not exist, and this option is on, then
the last folder name used is suggested. This is useful if you get
mail from various people for whom you have an alias, but file
them all in the same project folder.

See `mh-prompt-for-refile-folder' and `mh-folder-from-address'
for more information."
  :type 'boolean
  :group 'mh-folder-selection)

(defcustom mh-default-folder-prefix ""
  "*Prefix used for folder names generated from aliases.
The prefix is used to prevent clutter in your mail directory.

See `mh-prompt-for-refile-folder' and `mh-folder-from-address'
for more information."
  :type 'string
  :group 'mh-folder-selection)
Bill Wohler's avatar
Bill Wohler committed
1289

Richard M. Stallman's avatar
Richard M. Stallman committed
1290 1291


Bill Wohler's avatar
Bill Wohler committed
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
;;; Identities (:group 'mh-identity)

(eval-and-compile
  (unless (fboundp 'mh-identity-make-menu-no-autoload)
    (defun mh-identity-make-menu-no-autoload ()
      "Temporary definition.
Real definition will take effect when mh-identity is loaded."
      nil)))

(defcustom mh-identity-list nil
  "*List of identities.

To customize this option, click on the \"INS\" button and enter a label
such as \"Home\" or \"Work\". Then click on the \"INS\" button with the
label \"Add at least one item below\". Then choose one of the items in
the \"Value Menu\".

You can specify an alternate \"From:\" header field using the \"From
Field\" menu item. You must include a valid email address. A standard
format is \"First Last <login@@host.domain>\". If you use an initial
with a period, then you must quote your name as in '\"First I. Last\"
<login@@host.domain>'. People usually list the name of the company
where they work using the \"Organization Field\" menu item. Set any
arbitrary header field and value in the \"Other Field\" menu item.
Unless the header field is a standard one, precede the name of your
field's label with \"X-\", as in \"X-Fruit-of-the-Day:\". The value of
\"Attribution Verb\" overrides the setting of
`mh-extract-from-attribution-verb'. Set your signature with the
\"Signature\" menu item. You can specify the contents of
`mh-signature-file-name', a file, or a function. Specify a different
key to sign or encrypt messages with the \"GPG Key ID\" menu item.

You can select the identities you have added via the menu called
\"Identity\" in the MH-Letter buffer. You can also use
\\[mh-insert-identity]. To clear the fields and signature added by the
identity, select the \"None\" identity.

The \"Identity\" menu contains two other items to save you from having
to set the identity on every message. The menu item \"Set Default for
Session\" can be used to set the default identity to the current
identity until you exit Emacs. The menu item \"Save as Default\" sets
the option `mh-identity-default' to the current identity setting. You
can also customize the `mh-identity-default' option in the usual
fashion."
  :type '(repeat (list :tag ""
                       (string :tag "Label")
                       (repeat :tag "Add at least one item below"
                               (choice
                                (cons :tag "From Field"
                                      (const "From")
                                      (string :tag "Value"))
                                (cons :tag "Organization Field"
                                      (const "Organization")
                                      (string :tag "Value"))
                                (cons :tag "Other Field"
                                      (string :tag "Field")
                                      (string :tag "Value"))
                                (cons :tag "Attribution Verb"
                                      (const ":attribution-verb")
                                      (string :tag "Value"))
                                (cons :tag "Signature"
                                      (const :tag "Signature"
                                             ":signature")
                                      (choice
                                       (const :tag "mh-signature-file-name"
                                              nil)
                                       (file)
                                       (function)))
                                (cons :tag "GPG Key ID"
                                      (const :tag "GPG Key ID"
                                             ":pgg-default-user-id")
                                      (string :tag "Value"))))))
  :set (lambda (symbol value)
         (set-default symbol value)
         (mh-identity-make-menu-no-autoload))
  :group 'mh-identity)

(defcustom mh-auto-fields-list nil
  "List of recipients for which header lines are automatically inserted.

This option can be used to set the identity depending on the
recipient. To customize this option, click on the \"INS\" button and
enter a regular expression for the recipient's address. Click on the
\"INS\" button with the \"Add at least one item below\" label. Then choose
one of the items in the \"Value Menu\".

The \"Identity\" menu item is used to select an identity from those
configured in `mh-identity-list'. All of the information for that
identity will be added if the recipient matches. The \"Fcc Field\" menu
item is used to select a folder that is used in the \"Fcc:\" header.
When you send the message, MH will put a copy of your message in this
folder. The \"Mail-Followup-To Field\" menu item is used to insert an
\"Mail-Followup-To:\" header field with the recipients you provide. If
the recipient's mail user agent supports this header field (as nmh
does), then their replies will go to the addresses listed. This is
useful if their replies go both to the list and to you and you don't
have a mechanism to suppress duplicates. If you reply to someone not
on the list, you must either remove the \"Mail-Followup-To:\" field, or
ensure the recipient is also listed there so that he receives replies
to your reply. Other header fields may be added using the \"Other
Field\" menu item.

These fields can only be added after the recipient is known. Once the
header contains one or more recipients, run the
\\[mh-insert-auto-fields] command or choose the \"Identity -> Insert
Auto Fields\" menu item to insert these fields manually. However, you
can just send the message and the fields will be added automatically.
You are given a chance to see these fields and to confirm them before
the message is actually sent. You can do away with this confirmation
by turning off the option `mh-auto-fields-prompt-flag'.

You should avoid using the same header field in `mh-auto-fields-list'
and `mh-identity-list' definitions that may apply to the same message
as the result is undefined."
  :type `(repeat
          (list :tag ""
                (string :tag "Recipient")
                (repeat :tag "Add at least one item below"
                        (choice
                         (cons :tag "Identity"
                               (const ":identity")
                               ,(append
                                 '(radio)
                                 (mapcar
                                  (function (lambda (arg) `(const ,arg)))
                                  (mapcar 'car mh-identity-list))))
                         (cons :tag "Fcc Field"
                               (const "fcc")
                               (string :tag "Value"))
                         (cons :tag "Mail-Followup-To Field"
                               (const "Mail-Followup-To")
                               (string :tag "Value"))
                         (cons :tag "Other Field"
                                 (string :tag "Field")
                                 (string :tag "Value"))))))
  :group 'mh-identity)

(defcustom mh-auto-fields-prompt-flag t
  "*Non-nil means to prompt before sending if fields inserted.
See `mh-auto-fields-list'."
  :type 'boolean
  :group 'mh-identity)

(defcustom mh-identity-default nil
  "Default identity to use when `mh-letter-mode' is called.
See `mh-identity-list'."
  :type (append
         '(radio)
         (cons '(const :tag "None" nil)
               (mapcar (function (lambda (arg) `(const ,arg)))
                       (mapcar 'car mh-identity-list))))
  :group 'mh-identity)

(defcustom mh-identity-handlers
  '(("From" . mh-identity-handler-top)
    (":default" . mh-identity-handler-bottom)
    (":attribution-verb" . mh-identity-handler-attribution-verb)
    (":signature" . mh-identity-handler-signature)
    (":pgg-default-user-id" . mh-identity-handler-gpg-identity))
  "Handler functions for fields in `mh-identity-list'.

This option is used to change the way that fields, signatures,
and attributions in `mh-identity-list' are added. To customize
`mh-identity-handlers', replace the name of an existing handler
function associated with the field you want to change with the
name of a function you have written. You can also click on an
\"INS\" button and insert a field of your choice and the name of
the function you have written to handle it.

The \"Field\" field can be any field that you've used in your
`mh-identity-list'. The special fields \":attribution-verb\",
\":signature\", or \":pgg-default-user-id\" are used for the
`mh-identity-list' choices \"Attribution Verb\", \"Signature\", and
\"GPG Key ID\" respectively.

The handler associated with the \":default\" field is used when no
other field matches.

The handler functions are passed two or three arguments: the
FIELD itself (for example, \"From\"), or one of the special
fields (for example, \":signature\"), and the ACTION 'remove or
'add. If the action is 'add, an additional argument
containing the VALUE for the field is given."
  :type '(repeat (cons (string :tag "Field") function))
  :group 'mh-identity)



;;; Incorporating Your Mail (:group 'mh-inc)

(defcustom mh-inc-prog "inc"
  "*Program to incorporate new mail into a folder.

This program generates a one-line summary for each of the new
messages. Unless it is an absolute pathname, the file is assumed
to be in the `mh-progs' directory. You may also link a file to
\"inc\" that uses a different format. You'll then need to modify
several scan line format variables appropriately."
  :type 'string
  :group 'mh-inc)

(eval-and-compile
  (unless (fboundp 'mh-inc-spool-make-no-autoload)
    (defun mh-inc-spool-make-no-autoload ()
      "Temporary definition.
Real definition will take effect when mh-inc is loaded."
      nil)))

(defcustom mh-inc-spool-list nil
  "*Alternate spool files.

You can use the `mh-inc-spool-list' variable to direct MH-E to
retrieve mail from arbitrary spool files other than your system
mailbox, file it in folders other than your \"+inbox\", and assign
key bindings to incorporate this mail.

Suppose you are subscribed to the \"mh-e-devel\" mailing list and
you use \"procmail\" to filter this mail into \"~/mail/mh-e\" with
the following recipe in \".procmailrc\":

    MAILDIR=$HOME/mail
    :0:
    * ^From mh-e-devel-admin@stop.mail-abuse.org
    mh-e

In order to incorporate \"~/mail/mh-e\" into \"+mh-e\" with an
\"I m\" (mh-inc-spool-mh-e) command, customize this option, and click
on the \"INS\" button. Enter a \"Spool File\" of \"~/mail/mh-e\", a
\"Folder\" of \"mh-e\", and a \"Key Binding\" of \"m\".

You can use \"xbuffy\" to automate the incorporation of this mail
1523
using the Emacs 22 command \"emacsclient\" as follows:
Bill Wohler's avatar
Bill Wohler committed
1524 1525 1526 1527 1528 1529

    box ~/mail/mh-e
        title mh-e
        origMode
        polltime 10
        headertime 0
1530 1531 1532