mh-utils.el 104 KB
Newer Older
1
;;; mh-utils.el --- MH-E code needed for both sending and reading
Richard M. Stallman's avatar
Richard M. Stallman committed
2

Bill Wohler's avatar
Bill Wohler committed
3
;; Copyright (C) 1993, 1995, 1997,
4
;;  2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Bill Wohler's avatar
Bill Wohler committed
5 6 7 8 9

;; Author: Bill Wohler <wohler@newt.com>
;; Maintainer: Bill Wohler <wohler@newt.com>
;; Keywords: mail
;; See: mh-e.el
Richard M. Stallman's avatar
Richard M. Stallman committed
10

11
;; This file is part of GNU Emacs.
Richard M. Stallman's avatar
Richard M. Stallman committed
12

Karl Heuer's avatar
Karl Heuer committed
13
;; GNU Emacs is free software; you can redistribute it and/or modify
Richard M. Stallman's avatar
Richard M. Stallman committed
14 15 16 17
;; 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
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
Erik Naggum's avatar
Erik Naggum committed
24
;; along with GNU Emacs; see the file COPYING.  If not, write to the
Lute Kamstra's avatar
Lute Kamstra committed
25 26
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
Richard M. Stallman's avatar
Richard M. Stallman committed
27 28 29

;;; Commentary:

Bill Wohler's avatar
Bill Wohler committed
30
;; Internal support for MH-E package.
Richard M. Stallman's avatar
Richard M. Stallman committed
31

Bill Wohler's avatar
Bill Wohler committed
32 33
;;; Change Log:

Richard M. Stallman's avatar
Richard M. Stallman committed
34 35
;;; Code:

Bill Wohler's avatar
Bill Wohler committed
36
(eval-and-compile
37
  (defvar recursive-load-depth-limit)
Bill Wohler's avatar
Bill Wohler committed
38 39
  (if (and (boundp 'recursive-load-depth-limit)
           (integerp recursive-load-depth-limit)
40
           (< recursive-load-depth-limit 50))
Bill Wohler's avatar
Bill Wohler committed
41
      (setq recursive-load-depth-limit 50)))
Bill Wohler's avatar
Bill Wohler committed
42

Bill Wohler's avatar
Bill Wohler committed
43
(eval-when-compile (require 'mh-acros))
Bill Wohler's avatar
Bill Wohler committed
44
(mh-require-cl)
45

Bill Wohler's avatar
Bill Wohler committed
46
(require 'font-lock)
47
(require 'gnus-util)
Bill Wohler's avatar
Bill Wohler committed
48
(require 'mh-customize)
Bill Wohler's avatar
Bill Wohler committed
49
(require 'mh-inc)
50 51
(require 'mouse)
(require 'sendmail)
Bill Wohler's avatar
Bill Wohler committed
52

53 54 55 56 57 58
;; Non-fatal dependencies
(load "hl-line" t t)
(load "mm-decode" t t)
(load "mm-view" t t)
(load "tool-bar" t t)
(load "vcard" t t)
Bill Wohler's avatar
Bill Wohler committed
59

Bill Wohler's avatar
Bill Wohler committed
60 61


Bill Wohler's avatar
Bill Wohler committed
62
;;; Autoloads
Bill Wohler's avatar
Bill Wohler committed
63

Bill Wohler's avatar
Bill Wohler committed
64
(autoload 'gnus-article-highlight-citation "gnus-cite")
Bill Wohler's avatar
Bill Wohler committed
65 66
(autoload 'message-fetch-field "message")
(autoload 'message-tokenize-header "message")
Bill Wohler's avatar
Bill Wohler committed
67 68 69
(unless (fboundp 'make-hash-table)
  (autoload 'make-hash-table "cl"))

Bill Wohler's avatar
Bill Wohler committed
70 71


Bill Wohler's avatar
Bill Wohler committed
72
;;; CL Replacements
Bill Wohler's avatar
Bill Wohler committed
73

Bill Wohler's avatar
Bill Wohler committed
74 75
(defun mh-search-from-end (char string)
  "Return the position of last occurrence of CHAR in STRING.
76 77
If CHAR is not present in STRING then return nil. The function is
used in lieu of `search' in the CL package."
Bill Wohler's avatar
Bill Wohler committed
78 79 80 81
  (loop for index from (1- (length string)) downto 0
        when (equal (aref string index) char) return index
        finally return nil))

Bill Wohler's avatar
Bill Wohler committed
82 83
;; Additional header fields that might someday be added:
;; "Sender: " "Reply-to: "
Bill Wohler's avatar
Bill Wohler committed
84

Bill Wohler's avatar
Bill Wohler committed
85

Bill Wohler's avatar
Bill Wohler committed
86

Bill Wohler's avatar
Bill Wohler committed
87 88
;;; Scan Line Formats

Bill Wohler's avatar
Bill Wohler committed
89
(defvar mh-scan-msg-number-regexp "^ *\\([0-9]+\\)"
90
  "This regular expression extracts the message number.
91 92 93 94

It must match from the beginning of the line. Note that the
message number must be placed in a parenthesized expression as in
the default of \"^ *\\\\([0-9]+\\\\)\".")
Richard M. Stallman's avatar
Richard M. Stallman committed
95

Bill Wohler's avatar
Bill Wohler committed
96
(defvar mh-scan-msg-overflow-regexp "^[?0-9][0-9]"
97
  "This regular expression matches overflowed message numbers.")
Bill Wohler's avatar
Bill Wohler committed
98 99

(defvar mh-scan-msg-format-regexp "%\\([0-9]*\\)(msg)"
100
  "This regular expression finds the message number width in a scan format.
101 102 103 104 105

Note that the message number must be placed in a parenthesized
expression as in the default of \"%\\\\([0-9]*\\\\)(msg)\". This
variable is only consulted if `mh-scan-format-file' is set to
\"Use MH-E scan Format\".")
Bill Wohler's avatar
Bill Wohler committed
106 107

(defvar mh-scan-msg-format-string "%d"
Bill Wohler's avatar
Bill Wohler committed
108
  "This is a format string for width of the message number in a scan format.
109

110
Use \"0%d\" for zero-filled message numbers. This variable is only
111 112
consulted if `mh-scan-format-file' is set to \"Use MH-E scan
Format\".")
Bill Wohler's avatar
Bill Wohler committed
113

Bill Wohler's avatar
Bill Wohler committed
114
(defvar mh-scan-msg-search-regexp "^[^0-9]*%d[^0-9]"
115
  "This regular expression matches a particular message.
116

117
It is a format string; use \"%d\" to represent the location of the
118 119
message number within the expression as in the default of
\"^[^0-9]*%d[^0-9]\".")
Bill Wohler's avatar
Bill Wohler committed
120 121

(defvar mh-cmd-note 4
122
  "Column for notations.
123 124 125 126

This variable should be set with the function `mh-set-cmd-note'.
This variable may be updated dynamically if
`mh-adaptive-cmd-note-flag' is on.
127 128

Note that columns in Emacs start with 0.")
Bill Wohler's avatar
Bill Wohler committed
129 130 131 132
(make-variable-buffer-local 'mh-cmd-note)

(defvar mh-note-seq ?%
  "Messages in a user-defined sequence are marked by this character.
133

134
Messages in the \"search\" sequence are marked by this character as
135
well.")
Bill Wohler's avatar
Bill Wohler committed
136 137


Karl Heuer's avatar
Karl Heuer committed
138

Bill Wohler's avatar
Bill Wohler committed
139
(defvar mh-show-buffer-mode-line-buffer-id "    {show-%s} %d"
Karl Heuer's avatar
Karl Heuer committed
140
  "Format string to produce `mode-line-buffer-identification' for show buffers.
141 142

First argument is folder name. Second is message number.")
Richard M. Stallman's avatar
Richard M. Stallman committed
143

Bill Wohler's avatar
Bill Wohler committed
144

Karl Heuer's avatar
Karl Heuer committed
145

Bill Wohler's avatar
Bill Wohler committed
146 147 148
(defvar mh-mail-header-separator "--------"
  "*Line used by MH to separate headers from text in messages being composed.

149 150 151 152 153 154 155 156 157
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.

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
158

Bill Wohler's avatar
Bill Wohler committed
159
(defvar mh-signature-separator-regexp "^-- $"
160
  "This regular expression matches the signature separator.
Bill Wohler's avatar
Bill Wohler committed
161 162 163 164
See `mh-signature-separator'.")

(defvar mh-signature-separator "-- \n"
  "Text of a signature separator.
165 166 167 168 169 170

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.")
Bill Wohler's avatar
Bill Wohler committed
171 172 173 174 175 176 177

(defun mh-signature-separator-p ()
  "Return non-nil if buffer includes \"^-- $\"."
  (save-excursion
    (goto-char (point-min))
    (re-search-forward mh-signature-separator-regexp nil t)))

Bill Wohler's avatar
Bill Wohler committed
178
;; Variables for MIME display
Bill Wohler's avatar
Bill Wohler committed
179

Bill Wohler's avatar
Bill Wohler committed
180
;; Structure to keep track of MIME handles on a per buffer basis.
Bill Wohler's avatar
Bill Wohler committed
181 182
(mh-defstruct (mh-buffer-data (:conc-name mh-mime-)
                              (:constructor mh-make-buffer-data))
Bill Wohler's avatar
Bill Wohler committed
183 184 185 186 187 188 189
  (handles ())                          ; List of MIME handles
  (handles-cache (make-hash-table))     ; Cache to avoid multiple decodes of
                                        ; nested messages
  (parts-count 0)                       ; The button number is generated from
                                        ; this number
  (part-index-hash (make-hash-table)))  ; Avoid incrementing the part number
                                        ; for nested messages
Bill Wohler's avatar
Bill Wohler committed
190 191

;; This has to be a macro, since we do: (setf (mh-buffer-data) ...)
Bill Wohler's avatar
Bill Wohler committed
192 193 194
(defmacro mh-buffer-data ()
  "Convenience macro to get the MIME data structures of the current buffer."
  `(gethash (current-buffer) mh-globals-hash))
Bill Wohler's avatar
Bill Wohler committed
195 196 197 198

(defvar mh-globals-hash (make-hash-table)
  "Keeps track of MIME data on a per buffer basis.")

199 200
(defvar mh-pgp-support-flag (not (not (locate-library "mml2015")))
  "Non-nil means PGP support is available.")
Bill Wohler's avatar
Bill Wohler committed
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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263

(defvar mh-mm-inline-media-tests
  `(("image/jpeg"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'jpeg handle)))
    ("image/png"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'png handle)))
    ("image/gif"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'gif handle)))
    ("image/tiff"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'tiff handle)) )
    ("image/xbm"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'xbm handle)))
    ("image/x-xbitmap"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'xbm handle)))
    ("image/xpm"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'xpm handle)))
    ("image/x-pixmap"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'xpm handle)))
    ("image/bmp"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'bmp handle)))
    ("image/x-portable-bitmap"
     mm-inline-image
     (lambda (handle)
       (mm-valid-and-fit-image-p 'pbm handle)))
    ("text/plain" mm-inline-text identity)
    ("text/enriched" mm-inline-text identity)
    ("text/richtext" mm-inline-text identity)
    ("text/x-patch" mm-display-patch-inline
     (lambda (handle)
       (locate-library "diff-mode")))
    ("application/emacs-lisp" mm-display-elisp-inline identity)
    ("application/x-emacs-lisp" mm-display-elisp-inline identity)
    ("text/html"
     ,(if (fboundp 'mm-inline-text-html) 'mm-inline-text-html 'mm-inline-text)
     (lambda (handle)
       (or (and (boundp 'mm-inline-text-html-renderer)
                mm-inline-text-html-renderer)
           (and (boundp 'mm-text-html-renderer) mm-text-html-renderer))))
    ("text/x-vcard"
     mm-inline-text-vcard
     (lambda (handle)
       (or (featurep 'vcard)
           (locate-library "vcard"))))
    ("message/delivery-status" mm-inline-text identity)
    ("message/rfc822" mh-mm-inline-message identity)
Bill Wohler's avatar
Bill Wohler committed
264 265
    ;;("message/partial" mm-inline-partial identity)
    ;;("message/external-body" mm-inline-external-body identity)
Bill Wohler's avatar
Bill Wohler committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
    ("text/.*" mm-inline-text identity)
    ("audio/wav" mm-inline-audio
     (lambda (handle)
       (and (or (featurep 'nas-sound) (featurep 'native-sound))
            (device-sound-enabled-p))))
    ("audio/au"
     mm-inline-audio
     (lambda (handle)
       (and (or (featurep 'nas-sound) (featurep 'native-sound))
            (device-sound-enabled-p))))
    ("application/pgp-signature" ignore identity)
    ("application/x-pkcs7-signature" ignore identity)
    ("application/pkcs7-signature" ignore identity)
    ("application/x-pkcs7-mime" ignore identity)
    ("application/pkcs7-mime" ignore identity)
    ("multipart/alternative" ignore identity)
    ("multipart/mixed" ignore identity)
    ("multipart/related" ignore identity)
    ;; Disable audio and image
    ("audio/.*" ignore ignore)
    ("image/.*" ignore ignore)
    ;; Default to displaying as text
    (".*" mm-inline-text mm-readable-p))
  "Alist of media types/tests saying whether types can be displayed inline.")

Bill Wohler's avatar
Bill Wohler committed
291 292
;; Copy of `goto-address-mail-regexp'
(defvar mh-address-mail-regexp
Bill Wohler's avatar
Bill Wohler committed
293
  "[-a-zA-Z0-9._]+@\\([-a-zA-z0-9_]+\\.\\)+[a-zA-Z0-9]+"
Bill Wohler's avatar
Bill Wohler committed
294 295 296
  "A regular expression probably matching an e-mail address.")

;; From goto-addr.el, which we don't want to force-load on users.
Bill Wohler's avatar
Bill Wohler committed
297

Bill Wohler's avatar
Bill Wohler committed
298 299
(defun mh-goto-address-find-address-at-point ()
  "Find e-mail address around or before point.
300 301 302

Then search backwards to beginning of line for the start of an
e-mail address. If no e-mail address found, return nil."
Bill Wohler's avatar
Bill Wohler committed
303 304 305 306 307 308 309
  (re-search-backward "[^-_A-z0-9.@]" (line-beginning-position) 'lim)
  (if (or (looking-at mh-address-mail-regexp)	; already at start
	  (and (re-search-forward mh-address-mail-regexp
				  (line-end-position) 'lim)
	       (goto-char (match-beginning 0))))
      (match-string-no-properties 0)))

Bill Wohler's avatar
Bill Wohler committed
310 311
(defun mh-mail-header-end ()
  "Substitute for `mail-header-end' that doesn't widen the buffer.
312 313 314 315

In MH-E we frequently need to find the end of headers in nested
messages, where the buffer has been narrowed. This function works
in this situation."
Bill Wohler's avatar
Bill Wohler committed
316
  (save-excursion
Bill Wohler's avatar
Bill Wohler committed
317 318 319 320 321 322 323 324 325 326 327 328
    ;; XXX: The following replaces a call to rfc822-goto-eoh. Occasionally,
    ;; mail headers that MH-E has to read contains lines of the form:
    ;;    From xxx@yyy Mon May 10 11:48:07 2004
    ;; In this situation, rfc822-goto-eoh doesn't go to the end of the
    ;; header. The replacement allows From_ lines in the mail header.
    (goto-char (point-min))
    (loop for p = (re-search-forward
                   "^\\([:\n]\\|[^: \t\n]+[ \t\n]\\)" nil 'move)
          do (cond ((null p) (return))
                   (t (goto-char (match-beginning 0))
                      (unless (looking-at "From ") (return))
                      (goto-char p))))
Bill Wohler's avatar
Bill Wohler committed
329 330
    (point)))

Bill Wohler's avatar
Bill Wohler committed
331
(defun mh-in-header-p ()
Bill Wohler's avatar
Bill Wohler committed
332
  "Return non-nil if the point is in the header of a draft message."
Bill Wohler's avatar
Bill Wohler committed
333
  (< (point) (mh-mail-header-end)))
Bill Wohler's avatar
Bill Wohler committed
334

Bill Wohler's avatar
Bill Wohler committed
335 336 337 338 339 340 341
(defun mh-header-field-beginning ()
  "Move to the beginning of the current header field.
Handles RFC 822 continuation lines."
  (beginning-of-line)
  (while (looking-at "^[ \t]")
    (forward-line -1)))

Bill Wohler's avatar
Bill Wohler committed
342
(defun mh-header-field-end ()
Bill Wohler's avatar
Bill Wohler committed
343 344
  "Move to the end of the current header field.
Handles RFC 822 continuation lines."
Bill Wohler's avatar
Bill Wohler committed
345 346 347
  (forward-line 1)
  (while (looking-at "^[ \t]")
    (forward-line 1))
Bill Wohler's avatar
Bill Wohler committed
348
  (backward-char 1))                    ;to end of previous line
Bill Wohler's avatar
Bill Wohler committed
349 350 351 352 353 354

(defun mh-letter-header-font-lock (limit)
  "Return the entire mail header to font-lock.
Argument LIMIT limits search."
  (if (= (point) limit)
      nil
Bill Wohler's avatar
Bill Wohler committed
355
    (let* ((mail-header-end (save-match-data (mh-mail-header-end)))
Bill Wohler's avatar
Bill Wohler committed
356 357 358 359 360 361 362 363 364 365 366
           (lesser-limit (if (< mail-header-end limit) mail-header-end limit)))
      (when (mh-in-header-p)
        (set-match-data (list 1 lesser-limit))
        (goto-char lesser-limit)
        t))))

(defun mh-header-field-font-lock (field limit)
  "Return the value of a header field FIELD to font-lock.
Argument LIMIT limits search."
  (if (= (point) limit)
      nil
Bill Wohler's avatar
Bill Wohler committed
367
    (let* ((mail-header-end (mh-mail-header-end))
Bill Wohler's avatar
Bill Wohler committed
368 369
           (lesser-limit (if (< mail-header-end limit) mail-header-end limit))
           (case-fold-search t))
Bill Wohler's avatar
Bill Wohler committed
370
      (when (and (< (point) mail-header-end) ;Only within header
Bill Wohler's avatar
Bill Wohler committed
371 372 373 374
                 (re-search-forward (format "^%s" field) lesser-limit t))
        (let ((match-one-b (match-beginning 0))
              (match-one-e (match-end 0)))
          (mh-header-field-end)
Bill Wohler's avatar
Bill Wohler committed
375
          (if (> (point) limit)         ;Don't search for end beyond limit
Bill Wohler's avatar
Bill Wohler committed
376 377 378 379 380 381
              (goto-char limit))
          (set-match-data (list match-one-b match-one-e
                                (1+ match-one-e) (point)))
          t)))))

(defun mh-header-to-font-lock (limit)
Bill Wohler's avatar
Bill Wohler committed
382 383
  "Return the value of a header field To to font-lock.
Argument LIMIT limits search."
Bill Wohler's avatar
Bill Wohler committed
384 385 386
  (mh-header-field-font-lock "To:" limit))

(defun mh-header-cc-font-lock (limit)
Bill Wohler's avatar
Bill Wohler committed
387 388
  "Return the value of a header field cc to font-lock.
Argument LIMIT limits search."
Bill Wohler's avatar
Bill Wohler committed
389 390 391
  (mh-header-field-font-lock "cc:" limit))

(defun mh-header-subject-font-lock (limit)
Bill Wohler's avatar
Bill Wohler committed
392 393
  "Return the value of a header field Subject to font-lock.
Argument LIMIT limits search."
Bill Wohler's avatar
Bill Wohler committed
394 395
  (mh-header-field-font-lock "Subject:" limit))

Bill Wohler's avatar
Bill Wohler committed
396 397 398
(eval-and-compile
  ;; Otherwise byte-compilation fails on `mh-show-font-lock-keywords-with-cite'
  (defvar mh-show-font-lock-keywords
399 400 401 402 403 404 405 406 407
    '(("^\\(From:\\|Sender:\\)\\(.*\\)"
       (1 'default)
       (2 'mh-show-from))
      (mh-header-to-font-lock
       (0 'default)
       (1 'mh-show-to))
      (mh-header-cc-font-lock
       (0 'default)
       (1 'mh-show-cc))
Bill Wohler's avatar
Bill Wohler committed
408
      ("^\\(Reply-To:\\|Return-Path:\\)\\(.*\\)$"
409 410 411 412 413
       (1 'default)
       (2 'mh-show-from))
      (mh-header-subject-font-lock
       (0 'default)
       (1 'mh-show-subject))
Bill Wohler's avatar
Bill Wohler committed
414
      ("^\\(Apparently-To:\\|Newsgroups:\\)\\(.*\\)"
415 416
       (1 'default)
       (2 'mh-show-cc))
Bill Wohler's avatar
Bill Wohler committed
417
      ("^\\(In-reply-to\\|Date\\):\\(.*\\)$"
418 419 420 421 422
       (1 'default)
       (2 'mh-show-date))
      (mh-letter-header-font-lock
       (0 'mh-show-header append t)))
    "Additional expressions to highlight in MH-Show buffers."))
Bill Wohler's avatar
Bill Wohler committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440

(defvar mh-show-font-lock-keywords-with-cite
  (eval-when-compile
    (let* ((cite-chars "[>|}]")
           (cite-prefix "A-Za-z")
           (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
      (append
       mh-show-font-lock-keywords
       (list
        ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
        `(,cite-chars
          (,(concat "\\=[ \t]*"
                    "\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
                    "\\(" cite-chars "[ \t]*\\)\\)+"
                    "\\(.*\\)")
           (beginning-of-line) (end-of-line)
           (2 font-lock-constant-face nil t)
           (4 font-lock-comment-face nil t)))))))
441
  "Additional expressions to highlight in MH-Show buffers.")
Bill Wohler's avatar
Bill Wohler committed
442

Bill Wohler's avatar
Bill Wohler committed
443 444
(defvar mh-letter-font-lock-keywords
  `(,@mh-show-font-lock-keywords-with-cite
445 446 447
    (mh-font-lock-field-data
     (1 'mh-letter-header-field prepend t)))
  "Additional expressions to highlight in MH-Letter buffers.")
Bill Wohler's avatar
Bill Wohler committed
448

Bill Wohler's avatar
Bill Wohler committed
449 450
(defun mh-show-font-lock-fontify-region (beg end loudly)
  "Limit font-lock in `mh-show-mode' to the header.
451

452 453 454 455 456
Used when the option `mh-highlight-citation-style' is set to
\"Gnus\", leaving the body to be dealt with by Gnus highlighting.
The region between BEG and END is given over to be fontified and
LOUDLY controls if a user sees a message about the fontification
operation."
Bill Wohler's avatar
Bill Wohler committed
457
  (let ((header-end (mh-mail-header-end)))
Bill Wohler's avatar
Bill Wohler committed
458 459 460 461 462 463 464 465
    (cond
     ((and (< beg header-end)(< end header-end))
      (font-lock-default-fontify-region beg end loudly))
     ((and (< beg header-end)(>= end header-end))
      (font-lock-default-fontify-region beg header-end loudly))
     (t
      nil))))

466
;; Shush compiler.
Bill Wohler's avatar
Bill Wohler committed
467
(if mh-xemacs-flag
468 469 470 471
    (eval-and-compile
      (require 'gnus)
      (require 'gnus-art)
      (require 'gnus-cite)))
Bill Wohler's avatar
Bill Wohler committed
472 473

(defun mh-gnus-article-highlight-citation ()
474
  "Highlight cited text in current buffer using Gnus."
Bill Wohler's avatar
Bill Wohler committed
475
  (interactive)
Bill Wohler's avatar
Bill Wohler committed
476 477 478 479 480 481 482 483 484 485 486 487
  ;; Requiring gnus-cite should have been sufficient. However for Emacs21.1,
  ;; recursive-load-depth-limit is only 10, so an error occurs. Also it may be
  ;; better to have an autoload at top-level (though that won't work because
  ;; of recursive-load-depth-limit). That gets rid of a compiler warning as
  ;; well.
  (unless mh-xemacs-flag
    (require 'gnus-art)
    (require 'gnus-cite))
  ;; Don't allow Gnus to create buttons while highlighting, maybe this is bad
  ;; style?
  (flet ((gnus-article-add-button (&rest args) nil))
    (let* ((modified (buffer-modified-p))
Bill Wohler's avatar
Bill Wohler committed
488 489 490
           (gnus-article-buffer (buffer-name))
           (gnus-cite-face-list `(,@(cdr gnus-cite-face-list)
                                    ,(car gnus-cite-face-list))))
Bill Wohler's avatar
Bill Wohler committed
491 492
      (gnus-article-highlight-citation t)
      (set-buffer-modified-p modified))))
Bill Wohler's avatar
Bill Wohler committed
493

Bill Wohler's avatar
Bill Wohler committed
494 495


Karl Heuer's avatar
Karl Heuer committed
496 497
;;; Internal bookkeeping variables:

498 499 500
(defvar mh-user-path nil
  "Cached value of the \"Path:\" MH profile component.
User's mail folder directory.")
Richard M. Stallman's avatar
Richard M. Stallman committed
501

502 503 504 505
(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.")
Richard M. Stallman's avatar
Richard M. Stallman committed
506

507 508 509
(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
510

511 512 513
(defvar mh-previous-seq nil
  "Cached value of the \"Previous-Sequence:\" MH profile component.
Name of the Previous sequence.")
Richard M. Stallman's avatar
Richard M. Stallman committed
514

515 516 517 518
(defvar mh-inbox nil
  "Cached value of the \"Inbox:\" MH profile component.
Set to \"+inbox\" if no such component.
Name of the Inbox folder.")
Richard M. Stallman's avatar
Richard M. Stallman committed
519

Bill Wohler's avatar
Bill Wohler committed
520 521 522 523
;; The names of ephemeral buffers have a " *mh-" prefix (so that they are
;; hidden and can be programmatically removed in mh-quit), and the variable
;; names have the form mh-temp-.*-buffer.
(defconst mh-temp-buffer " *mh-temp*")  ;scratch
Bill Wohler's avatar
Bill Wohler committed
524
(defconst mh-temp-fetch-buffer " *mh-fetch*")  ;wget/curl/fetch output
Bill Wohler's avatar
Bill Wohler committed
525 526 527 528 529

;; The names of MH-E buffers that are not ephemeral and can be used by the
;; user (and deleted by the user when no longer needed) have a "*MH-E " prefix
;; (so they can be programmatically removed in mh-quit), and the variable
;; names have the form mh-.*-buffer.
Bill Wohler's avatar
Bill Wohler committed
530
(defconst mh-aliases-buffer "*MH-E Aliases*") ;alias lookups
Bill Wohler's avatar
Bill Wohler committed
531
(defconst mh-folders-buffer "*MH-E Folders*") ;folder list
Bill Wohler's avatar
Bill Wohler committed
532
(defconst mh-help-buffer "*MH-E Help*") ;quick help
Bill Wohler's avatar
Bill Wohler committed
533 534
(defconst mh-info-buffer "*MH-E Info*") ;version information buffer
(defconst mh-log-buffer "*MH-E Log*") ;output of MH commands and so on
Bill Wohler's avatar
Bill Wohler committed
535
(defconst mh-mail-delivery-buffer "*MH-E Mail Delivery*") ;mail delivery log
Bill Wohler's avatar
Bill Wohler committed
536 537
(defconst mh-recipients-buffer "*MH-E Recipients*") ;killed when draft sent
(defconst mh-sequences-buffer "*MH-E Sequences*") ;sequences list
Bill Wohler's avatar
Bill Wohler committed
538

539 540
(defvar mh-log-buffer-lines 100
  "Number of lines to keep in `mh-log-buffer'.")
Bill Wohler's avatar
Bill Wohler committed
541

542 543
(defvar mh-previous-window-config nil
  "Window configuration before MH-E command.")
Bill Wohler's avatar
Bill Wohler committed
544

545 546
(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
547

Bill Wohler's avatar
Bill Wohler committed
548 549


Karl Heuer's avatar
Karl Heuer committed
550
;;; Internal variables local to a folder.
Richard M. Stallman's avatar
Richard M. Stallman committed
551

552 553
(defvar mh-current-folder nil
  "Name of current folder, a string.")
Richard M. Stallman's avatar
Richard M. Stallman committed
554

555 556
(defvar mh-show-buffer nil
  "Buffer that displays message for this folder.")
Richard M. Stallman's avatar
Richard M. Stallman committed
557

558 559
(defvar mh-folder-filename nil
  "Full path of directory for this folder.")
560

561 562
(defvar mh-msg-count nil
  "Number of msgs in buffer.")
Richard M. Stallman's avatar
Richard M. Stallman committed
563

564 565
(defvar mh-showing-mode nil
  "If non-nil, show the message in a separate window.")
Richard M. Stallman's avatar
Richard M. Stallman committed
566

Bill Wohler's avatar
Bill Wohler committed
567 568 569 570 571 572
(defvar mh-show-mode-map (make-sparse-keymap)
  "Keymap used by the show buffer.")

(defvar mh-show-folder-buffer nil
  "Keeps track of folder whose message is being displayed.")

Bill Wohler's avatar
Bill Wohler committed
573 574 575 576
(defvar mh-logo-cache nil)

(defun mh-logo-display ()
  "Modify mode line to display MH-E logo."
Bill Wohler's avatar
Bill Wohler committed
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
  (mh-do-in-gnu-emacs
   (add-text-properties
    0 2
    `(display ,(or mh-logo-cache
                   (setq mh-logo-cache
                         (mh-funcall-if-exists
                          find-image '((:type xpm :ascent center
                                              :file "mh-logo.xpm"))))))
    (car mode-line-buffer-identification)))
  (mh-do-in-xemacs
   (setq modeline-buffer-identification
         (list
          (if mh-modeline-glyph
              (cons modeline-buffer-id-left-extent mh-modeline-glyph)
            (cons modeline-buffer-id-left-extent "XEmacs%N:"))
          (cons modeline-buffer-id-right-extent " %17b")))))

Bill Wohler's avatar
Bill Wohler committed
594 595
(defun mh-showing-mode (&optional arg)
  "Change whether messages should be displayed.
596 597

With ARG, display messages iff ARG is positive."
Bill Wohler's avatar
Bill Wohler committed
598
  (setq mh-showing-mode
Bill Wohler's avatar
Bill Wohler committed
599 600 601
        (if (null arg)
            (not mh-showing-mode)
          (> (prefix-numeric-value arg) 0))))
Karl Heuer's avatar
Karl Heuer committed
602

603 604 605
(defvar mh-seq-list nil
  "Alist of this folder's sequences.
Elements have the form (SEQUENCE . MESSAGES).")
Karl Heuer's avatar
Karl Heuer committed
606

607 608
(defvar mh-seen-list nil
  "List of displayed messages to be removed from the \"Unseen\" sequence.")
Karl Heuer's avatar
Karl Heuer committed
609

610 611 612
(defvar mh-showing-with-headers nil
  "If non-nil, MH-Show buffer contains message with all header fields.
If nil, MH-Show buffer contains message processed normally.")
Richard M. Stallman's avatar
Richard M. Stallman committed
613

Bill Wohler's avatar
Bill Wohler committed
614 615


Bill Wohler's avatar
Bill Wohler committed
616
;;; MH-E macros
617

Bill Wohler's avatar
Bill Wohler committed
618 619 620 621
(defmacro with-mh-folder-updating (save-modification-flag &rest body)
  "Format is (with-mh-folder-updating (SAVE-MODIFICATION-FLAG) &body BODY).
Execute BODY, which can modify the folder buffer without having to
worry about file locking or the read-only flag, and return its result.
622 623
If SAVE-MODIFICATION-FLAG is non-nil, the buffer's modification flag
is unchanged, otherwise it is cleared."
Bill Wohler's avatar
Bill Wohler committed
624
  (setq save-modification-flag (car save-modification-flag)) ; CL style
Gerd Moellmann's avatar
Gerd Moellmann committed
625 626
  `(prog1
       (let ((mh-folder-updating-mod-flag (buffer-modified-p))
Bill Wohler's avatar
Bill Wohler committed
627 628 629 630 631 632
             (buffer-read-only nil)
             (buffer-file-name nil))    ;don't let the buffer get locked
         (prog1
             (progn
               ,@body)
           (mh-set-folder-modified-p mh-folder-updating-mod-flag)))
Bill Wohler's avatar
Bill Wohler committed
633
     ,@(if (not save-modification-flag)
Bill Wohler's avatar
Bill Wohler committed
634
           '((mh-set-folder-modified-p nil)))))
635

Bill Wohler's avatar
Bill Wohler committed
636
(put 'with-mh-folder-updating 'lisp-indent-hook 'defun)
637 638

(defmacro mh-in-show-buffer (show-buffer &rest body)
Bill Wohler's avatar
Bill Wohler committed
639 640 641
  "Format is (mh-in-show-buffer (SHOW-BUFFER) &body BODY).
Display buffer SHOW-BUFFER in other window and execute BODY in it.
Stronger than `save-excursion', weaker than `save-window-excursion'."
Bill Wohler's avatar
Bill Wohler committed
642
  (setq show-buffer (car show-buffer))  ; CL style
Gerd Moellmann's avatar
Gerd Moellmann committed
643 644
  `(let ((mh-in-show-buffer-saved-window (selected-window)))
     (switch-to-buffer-other-window ,show-buffer)
Bill Wohler's avatar
Bill Wohler committed
645
     (if mh-bury-show-buffer-flag (bury-buffer (current-buffer)))
Gerd Moellmann's avatar
Gerd Moellmann committed
646
     (unwind-protect
Bill Wohler's avatar
Bill Wohler committed
647
         (progn
Gerd Moellmann's avatar
Gerd Moellmann committed
648 649
           ,@body)
       (select-window mh-in-show-buffer-saved-window))))
650

Bill Wohler's avatar
Bill Wohler committed
651
(put 'mh-in-show-buffer 'lisp-indent-hook 'defun)
652

Bill Wohler's avatar
Bill Wohler committed
653 654
(defmacro mh-do-at-event-location (event &rest body)
  "Switch to the location of EVENT and execute BODY.
655 656 657
After BODY has been executed return to original window. The
modification flag of the buffer in the event window is
preserved."
Bill Wohler's avatar
Bill Wohler committed
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
  (let ((event-window (make-symbol "event-window"))
        (event-position (make-symbol "event-position"))
        (original-window (make-symbol "original-window"))
        (original-position (make-symbol "original-position"))
        (modified-flag (make-symbol "modified-flag")))
    `(save-excursion
       (let* ((,event-window
               (or (mh-funcall-if-exists posn-window (event-start ,event))
                   (mh-funcall-if-exists event-window ,event)))
              (,event-position
               (or (mh-funcall-if-exists posn-point (event-start ,event))
                   (mh-funcall-if-exists event-closest-point ,event)))
              (,original-window (selected-window))
              (,original-position (progn
                                   (set-buffer (window-buffer ,event-window))
                                   (set-marker (make-marker) (point))))
              (,modified-flag (buffer-modified-p))
              (buffer-read-only nil))
         (unwind-protect (progn
                           (select-window ,event-window)
                           (goto-char ,event-position)
                           ,@body)
           (set-buffer-modified-p ,modified-flag)
           (goto-char ,original-position)
           (set-marker ,original-position nil)
           (select-window ,original-window))))))

(put 'mh-do-at-event-location 'lisp-indent-hook 'defun)

Bill Wohler's avatar
Bill Wohler committed
687 688 689 690 691 692 693 694 695 696 697 698 699 700
(defmacro mh-make-seq (name msgs)
  "Create sequence NAME with the given MSGS."
  (list 'cons name msgs))

(defmacro mh-seq-name (sequence)
  "Extract sequence name from the given SEQUENCE."
  (list 'car sequence))

(defmacro mh-seq-msgs (sequence)
  "Extract messages from the given SEQUENCE."
  (list 'cdr sequence))

(defun mh-recenter (arg)
  "Like recenter but with three improvements:
701

Bill Wohler's avatar
Bill Wohler committed
702
- At the end of the buffer it tries to show fewer empty lines.
703

Bill Wohler's avatar
Bill Wohler committed
704 705
- operates only if the current buffer is in the selected window.
  (Commands like `save-some-buffers' can make this false.)
706

Bill Wohler's avatar
Bill Wohler committed
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
- nil ARG means recenter as if prefix argument had been given."
  (cond ((not (eq (get-buffer-window (current-buffer)) (selected-window)))
         nil)
        ((= (point-max) (save-excursion
                          (forward-line (- (/ (window-height) 2) 2))
                          (point)))
         (let ((lines-from-end 2))
           (save-excursion
             (while (> (point-max) (progn (forward-line) (point)))
               (incf lines-from-end)))
           (recenter (- lines-from-end))))
        ;; '(4) is the same as C-u prefix argument.
        (t (recenter (or arg '(4))))))

(defun mh-start-of-uncleaned-message ()
  "Position uninteresting headers off the top of the window."
  (let ((case-fold-search t))
    (re-search-forward
     "^To:\\|^Cc:\\|^From:\\|^Subject:\\|^Date:" nil t)
    (beginning-of-line)
    (mh-recenter 0)))

(defun mh-invalidate-show-buffer ()
  "Invalidate the show buffer so we must update it to use it."
  (if (get-buffer mh-show-buffer)
      (save-excursion
Bill Wohler's avatar
Bill Wohler committed
733 734
        (set-buffer mh-show-buffer)
        (mh-unvisit-file))))
Bill Wohler's avatar
Bill Wohler committed
735 736 737 738

(defun mh-unvisit-file ()
  "Separate current buffer from the message file it was visiting."
  (or (not (buffer-modified-p))
Bill Wohler's avatar
Bill Wohler committed
739
      (null buffer-file-name)           ;we've been here before
Bill Wohler's avatar
Bill Wohler committed
740
      (yes-or-no-p (format "Message %s modified; flush changes? "
Bill Wohler's avatar
Bill Wohler committed
741
                           (file-name-nondirectory buffer-file-name)))
Bill Wohler's avatar
Bill Wohler committed
742 743 744 745
      (error "Flushing changes not confirmed"))
  (clear-visited-file-modtime)
  (unlock-buffer)
  (setq buffer-file-name nil))
746

Bill Wohler's avatar
Bill Wohler committed
747 748
(defun mh-get-msg-num (error-if-no-message)
  "Return the message number of the displayed message.
749 750
If the argument ERROR-IF-NO-MESSAGE is non-nil, then complain if
the cursor is not pointing to a message."
Bill Wohler's avatar
Bill Wohler committed
751 752 753
  (save-excursion
    (beginning-of-line)
    (cond ((looking-at mh-scan-msg-number-regexp)
Bill Wohler's avatar
Bill Wohler committed
754 755
           (string-to-number (buffer-substring (match-beginning 1)
                                               (match-end 1))))
Bill Wohler's avatar
Bill Wohler committed
756 757 758
          (error-if-no-message
           (error "Cursor not pointing to message"))
          (t nil))))
Bill Wohler's avatar
Bill Wohler committed
759 760 761

(defun mh-folder-name-p (name)
  "Return non-nil if NAME is the name of a folder.
762 763
A name (a string or symbol) can be a folder name if it begins
with \"+\"."
Bill Wohler's avatar
Bill Wohler committed
764 765 766
  (if (symbolp name)
      (eq (aref (symbol-name name) 0) ?+)
    (and (> (length name) 0)
Bill Wohler's avatar
Bill Wohler committed
767
         (eq (aref name 0) ?+))))
Bill Wohler's avatar
Bill Wohler committed
768 769 770 771 772

(defun mh-expand-file-name (filename &optional default)
  "Expand FILENAME like `expand-file-name', but also handle MH folder names.
Any filename that starts with '+' is treated as a folder name.
See `expand-file-name' for description of DEFAULT."
Bill Wohler's avatar
Bill Wohler committed
773 774 775
  (if (mh-folder-name-p filename)
      (expand-file-name (substring filename 1) mh-user-path)
    (expand-file-name filename default)))
Karl Heuer's avatar
Karl Heuer committed
776

Bill Wohler's avatar
Bill Wohler committed
777 778 779
(defun mh-msg-filename (msg &optional folder)
  "Return the file name of MSG in FOLDER (default current folder)."
  (expand-file-name (int-to-string msg)
Bill Wohler's avatar
Bill Wohler committed
780 781 782
                    (if folder
                        (mh-expand-file-name folder)
                      mh-folder-filename)))
783

Bill Wohler's avatar
Bill Wohler committed
784 785 786 787
;; Infrastructure to generate show-buffer functions from folder functions
;; XEmacs does not have deactivate-mark? What is the equivalent of
;; transient-mark-mode for XEmacs? Should we be restoring the mark in the
;; folder buffer after the operation has been carried out.
Bill Wohler's avatar
Bill Wohler committed
788
(defmacro mh-defun-show-buffer (function original-function
Bill Wohler's avatar
Bill Wohler committed
789
                                         &optional dont-return)
Bill Wohler's avatar
Bill Wohler committed
790
  "Define FUNCTION to run ORIGINAL-FUNCTION in folder buffer.
791 792
If the buffer we start in is still visible and DONT-RETURN is nil
then switch to it after that."
Bill Wohler's avatar
Bill Wohler committed
793
  `(defun ,function ()
794
     ,(format "Calls %s from the message's folder.\n%s\nSee \"%s\" for more info.\n"
Bill Wohler's avatar
Bill Wohler committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
              original-function
              (if dont-return ""
                "When function completes, returns to the show buffer if it is
still visible.\n")
              original-function)
     (interactive)
     (when (buffer-live-p (get-buffer mh-show-folder-buffer))
       (let ((config (current-window-configuration))
             (folder-buffer mh-show-folder-buffer)
             (normal-exit nil)
             ,@(if dont-return () '((cur-buffer-name (buffer-name)))))
         (pop-to-buffer mh-show-folder-buffer nil)
         (unless (equal (buffer-name
                         (window-buffer (frame-first-window (selected-frame))))
                        folder-buffer)
           (delete-other-windows))
         (mh-goto-cur-msg t)
Bill Wohler's avatar
Bill Wohler committed
812
         (mh-funcall-if-exists deactivate-mark)
Bill Wohler's avatar
Bill Wohler committed
813 814 815
         (unwind-protect
             (prog1 (call-interactively (function ,original-function))
               (setq normal-exit t))
Bill Wohler's avatar
Bill Wohler committed
816
           (mh-funcall-if-exists deactivate-mark)
Bill Wohler's avatar
Bill Wohler committed
817 818
           (when (eq major-mode 'mh-folder-mode)
             (mh-funcall-if-exists hl-line-highlight))
Bill Wohler's avatar
Bill Wohler committed
819 820 821 822 823 824 825 826 827
           (cond ((not normal-exit)
                  (set-window-configuration config))
                 ,(if dont-return
                      `(t (setq mh-previous-window-config config))
                    `((and (get-buffer cur-buffer-name)
                           (window-live-p (get-buffer-window
                                           (get-buffer cur-buffer-name))))
                      (pop-to-buffer (get-buffer cur-buffer-name) nil)))))))))

Bill Wohler's avatar
Bill Wohler committed
828 829
;; Generate interactive functions for the show buffer from the corresponding
;; folder functions.
Bill Wohler's avatar
Bill Wohler committed
830
(mh-defun-show-buffer mh-show-previous-undeleted-msg
Bill Wohler's avatar
Bill Wohler committed
831
                      mh-previous-undeleted-msg)
Bill Wohler's avatar
Bill Wohler committed
832
(mh-defun-show-buffer mh-show-next-undeleted-msg
Bill Wohler's avatar
Bill Wohler committed
833
                      mh-next-undeleted-msg)
Bill Wohler's avatar
Bill Wohler committed
834 835 836 837 838 839 840 841 842 843
(mh-defun-show-buffer mh-show-quit mh-quit)
(mh-defun-show-buffer mh-show-delete-msg mh-delete-msg)
(mh-defun-show-buffer mh-show-refile-msg mh-refile-msg)
(mh-defun-show-buffer mh-show-undo mh-undo)
(mh-defun-show-buffer mh-show-execute-commands mh-execute-commands)
(mh-defun-show-buffer mh-show-reply mh-reply t)
(mh-defun-show-buffer mh-show-redistribute mh-redistribute)
(mh-defun-show-buffer mh-show-forward mh-forward t)
(mh-defun-show-buffer mh-show-header-display mh-header-display)
(mh-defun-show-buffer mh-show-refile-or-write-again
Bill Wohler's avatar
Bill Wohler committed
844
                      mh-refile-or-write-again)
Bill Wohler's avatar
Bill Wohler committed
845 846
(mh-defun-show-buffer mh-show-show mh-show)
(mh-defun-show-buffer mh-show-write-message-to-file
Bill Wohler's avatar
Bill Wohler committed
847
                      mh-write-msg-to-file)
Bill Wohler's avatar
Bill Wohler committed
848
(mh-defun-show-buffer mh-show-extract-rejected-mail
Bill Wohler's avatar
Bill Wohler committed
849
                      mh-extract-rejected-mail t)
Bill Wohler's avatar
Bill Wohler committed
850
(mh-defun-show-buffer mh-show-delete-msg-no-motion
Bill Wohler's avatar
Bill Wohler committed
851
                      mh-delete-msg-no-motion)
Bill Wohler's avatar
Bill Wohler committed
852 853 854 855 856 857
(mh-defun-show-buffer mh-show-first-msg mh-first-msg)
(mh-defun-show-buffer mh-show-last-msg mh-last-msg)
(mh-defun-show-buffer mh-show-copy-msg mh-copy-msg)
(mh-defun-show-buffer mh-show-edit-again mh-edit-again t)
(mh-defun-show-buffer mh-show-goto-msg mh-goto-msg)
(mh-defun-show-buffer mh-show-inc-folder mh-inc-folder)
Bill Wohler's avatar
Bill Wohler committed
858 859 860
(mh-defun-show-buffer mh-show-delete-subject-or-thread
                      mh-delete-subject-or-thread)
(mh-defun-show-buffer mh-show-delete-subject mh-delete-subject)
Bill Wohler's avatar
Bill Wohler committed
861 862 863 864 865 866 867 868 869 870 871 872 873
(mh-defun-show-buffer mh-show-print-msg mh-print-msg)
(mh-defun-show-buffer mh-show-send mh-send t)
(mh-defun-show-buffer mh-show-toggle-showing mh-toggle-showing t)
(mh-defun-show-buffer mh-show-pipe-msg mh-pipe-msg t)
(mh-defun-show-buffer mh-show-sort-folder mh-sort-folder)
(mh-defun-show-buffer mh-show-visit-folder mh-visit-folder t)
(mh-defun-show-buffer mh-show-rescan-folder mh-rescan-folder)
(mh-defun-show-buffer mh-show-pack-folder mh-pack-folder)
(mh-defun-show-buffer mh-show-kill-folder mh-kill-folder t)
(mh-defun-show-buffer mh-show-list-folders mh-list-folders t)
(mh-defun-show-buffer mh-show-search-folder mh-search-folder t)
(mh-defun-show-buffer mh-show-undo-folder mh-undo-folder)
(mh-defun-show-buffer mh-show-delete-msg-from-seq
Bill Wohler's avatar
Bill Wohler committed
874
                      mh-delete-msg-from-seq)
Bill Wohler's avatar
Bill Wohler committed
875 876 877 878 879 880
(mh-defun-show-buffer mh-show-delete-seq mh-delete-seq)
(mh-defun-show-buffer mh-show-list-sequences mh-list-sequences)
(mh-defun-show-buffer mh-show-narrow-to-seq mh-narrow-to-seq)
(mh-defun-show-buffer mh-show-put-msg-in-seq mh-put-msg-in-seq)
(mh-defun-show-buffer mh-show-msg-is-in-seq mh-msg-is-in-seq)
(mh-defun-show-buffer mh-show-widen mh-widen)
Bill Wohler's avatar
Bill Wohler committed
881 882 883 884 885
(mh-defun-show-buffer mh-show-narrow-to-subject mh-narrow-to-subject)
(mh-defun-show-buffer mh-show-narrow-to-from mh-narrow-to-from)
(mh-defun-show-buffer mh-show-narrow-to-cc mh-narrow-to-cc)
(mh-defun-show-buffer mh-show-narrow-to-range mh-narrow-to-range)
(mh-defun-show-buffer mh-show-narrow-to-to mh-narrow-to-to)
Bill Wohler's avatar
Bill Wohler committed
886 887 888
(mh-defun-show-buffer mh-show-store-msg mh-store-msg)
(mh-defun-show-buffer mh-show-page-digest mh-page-digest)
(mh-defun-show-buffer mh-show-page-digest-backwards
Bill Wohler's avatar
Bill Wohler committed
889
                      mh-page-digest-backwards)
Bill Wohler's avatar
Bill Wohler committed
890 891 892 893 894 895 896 897 898 899
(mh-defun-show-buffer mh-show-burst-digest mh-burst-digest)
(mh-defun-show-buffer mh-show-page-msg mh-page-msg)
(mh-defun-show-buffer mh-show-previous-page mh-previous-page)
(mh-defun-show-buffer mh-show-modify mh-modify t)
(mh-defun-show-buffer mh-show-next-button mh-next-button)
(mh-defun-show-buffer mh-show-prev-button mh-prev-button)
(mh-defun-show-buffer mh-show-toggle-mime-part mh-folder-toggle-mime-part)
(mh-defun-show-buffer mh-show-save-mime-part mh-folder-save-mime-part)
(mh-defun-show-buffer mh-show-inline-mime-part mh-folder-inline-mime-part)
(mh-defun-show-buffer mh-show-toggle-threads mh-toggle-threads)
Bill Wohler's avatar
Bill Wohler committed
900 901
(mh-defun-show-buffer mh-show-thread-delete mh-thread-delete)
(mh-defun-show-buffer mh-show-thread-refile mh-thread-refile)
Bill Wohler's avatar
Bill Wohler committed
902
(mh-defun-show-buffer mh-show-update-sequences mh-update-sequences)
Bill Wohler's avatar
Bill Wohler committed
903 904 905 906 907 908 909
(mh-defun-show-buffer mh-show-next-unread-msg mh-next-unread-msg)
(mh-defun-show-buffer mh-show-previous-unread-msg mh-previous-unread-msg)
(mh-defun-show-buffer mh-show-thread-ancestor mh-thread-ancestor)
(mh-defun-show-buffer mh-show-thread-next-sibling mh-thread-next-sibling)
(mh-defun-show-buffer mh-show-thread-previous-sibling
                      mh-thread-previous-sibling)
(mh-defun-show-buffer mh-show-index-visit-folder mh-index-visit-folder t)
Bill Wohler's avatar
Bill Wohler committed
910 911 912 913 914
(mh-defun-show-buffer mh-show-toggle-tick mh-toggle-tick)
(mh-defun-show-buffer mh-show-narrow-to-tick mh-narrow-to-tick)
(mh-defun-show-buffer mh-show-junk-blacklist mh-junk-blacklist)
(mh-defun-show-buffer mh-show-junk-whitelist mh-junk-whitelist)
(mh-defun-show-buffer mh-show-index-new-messages mh-index-new-messages)
Bill Wohler's avatar
Bill Wohler committed
915 916 917
(mh-defun-show-buffer mh-show-index-ticked-messages mh-index-ticked-messages)
(mh-defun-show-buffer mh-show-index-sequenced-messages
                      mh-index-sequenced-messages)
Bill Wohler's avatar
Bill Wohler committed
918 919 920 921 922 923 924 925
(mh-defun-show-buffer mh-show-catchup mh-catchup)
(mh-defun-show-buffer mh-show-ps-print-toggle-color mh-ps-print-toggle-color)
(mh-defun-show-buffer mh-show-ps-print-toggle-faces mh-ps-print-toggle-faces)
(mh-defun-show-buffer mh-show-ps-print-msg-file mh-ps-print-msg-file)
(mh-defun-show-buffer mh-show-ps-print-msg mh-ps-print-msg)
(mh-defun-show-buffer mh-show-toggle-mime-buttons mh-toggle-mime-buttons)
(mh-defun-show-buffer mh-show-display-with-external-viewer
                      mh-display-with-external-viewer)
Bill Wohler's avatar
Bill Wohler committed
926

Bill Wohler's avatar
Bill Wohler committed
927 928 929 930


;;; Build mh-show-mode keymaps

Bill Wohler's avatar
Bill Wohler committed
931 932 933
(gnus-define-keys mh-show-mode-map
  " "    mh-show-page-msg
  "!"    mh-show-refile-or-write-again
Bill Wohler's avatar
Bill Wohler committed
934
  "'"    mh-show-toggle-tick
Bill Wohler's avatar
Bill Wohler committed
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
  ","    mh-show-header-display
  "."    mh-show-show
  ">"    mh-show-write-message-to-file
  "?"    mh-help
  "E"    mh-show-extract-rejected-mail
  "M"    mh-show-modify
  "\177" mh-show-previous-page
  "\C-d" mh-show-delete-msg-no-motion
  "\t"   mh-show-next-button
  [backtab] mh-show-prev-button
  "\M-\t" mh-show-prev-button
  "\ed"  mh-show-redistribute
  "^"    mh-show-refile-msg
  "c"    mh-show-copy-msg
  "d"    mh-show-delete-msg
  "e"    mh-show-edit-again
  "f"    mh-show-forward
  "g"    mh-show-goto-msg
  "i"    mh-show-inc-folder
Bill Wohler's avatar
Bill Wohler committed
954
  "k"    mh-show-delete-subject-or-thread
Bill Wohler's avatar
Bill Wohler committed
955 956
  "m"    mh-show-send
  "n"    mh-show-next-undeleted-msg
Bill Wohler's avatar
Bill Wohler committed
957
  "\M-n" mh-show-next-unread-msg
Bill Wohler's avatar
Bill Wohler committed
958 959
  "o"    mh-show-refile-msg
  "p"    mh-show-previous-undeleted-msg
Bill Wohler's avatar
Bill Wohler committed
960
  "\M-p" mh-show-previous-unread-msg
Bill Wohler's avatar
Bill Wohler committed
961 962 963 964 965 966
  "q"    mh-show-quit
  "r"    mh-show-reply
  "s"    mh-show-send
  "t"    mh-show-toggle-showing
  "u"    mh-show-undo
  "x"    mh-show-execute-commands
Bill Wohler's avatar
Bill Wohler committed
967
  "v"    mh-show-index-visit-folder
Bill Wohler's avatar
Bill Wohler committed
968 969 970 971
  "|"    mh-show-pipe-msg)

(gnus-define-keys (mh-show-folder-map "F" mh-show-mode-map)
  "?"    mh-prefix-help
Bill Wohler's avatar
Bill Wohler committed
972
  "'"    mh-index-ticked-messages
Bill Wohler's avatar
Bill Wohler committed
973
  "S"    mh-show-sort-folder
Bill Wohler's avatar
Bill Wohler committed
974
  "c"    mh-show-catchup
Bill Wohler's avatar
Bill Wohler committed
975 976 977 978
  "f"    mh-show-visit-folder
  "i"    mh-index-search
  "k"    mh-show-kill-folder
  "l"    mh-show-list-folders
Bill Wohler's avatar
Bill Wohler committed
979
  "n"    mh-index-new-messages
Bill Wohler's avatar
Bill Wohler committed
980
  "o"    mh-show-visit-folder
Bill Wohler's avatar
Bill Wohler committed
981
  "q"    mh-show-index-sequenced-messages
Bill Wohler's avatar
Bill Wohler committed
982 983 984 985 986 987 988
  "r"    mh-show-rescan-folder
  "s"    mh-show-search-folder
  "t"    mh-show-toggle-threads
  "u"    mh-show-undo-folder
  "v"    mh-show-visit-folder)

(gnus-define-keys (mh-show-sequence-map "S" mh-show-mode-map)
Bill Wohler's avatar
Bill Wohler committed
989
  "'"    mh-show-narrow-to-tick
Bill Wohler's avatar
Bill Wohler committed
990 991 992 993 994 995 996 997 998
  "?"    mh-prefix-help
  "d"    mh-show-delete-msg-from-seq
  "k"    mh-show-delete-seq
  "l"    mh-show-list-sequences
  "n"    mh-show-narrow-to-seq
  "p"    mh-show-put-msg-in-seq
  "s"    mh-show-msg-is-in-seq
  "w"    mh-show-widen)

Bill Wohler's avatar
Bill Wohler committed
999 1000 1001 1002 1003 1004 1005
(define-key mh-show-mode-map "I" mh-inc-spool-map)

(gnus-define-keys (mh-show-junk-map "J" mh-show-mode-map)
  "?"    mh-prefix-help
  "b"    mh-show-junk-blacklist
  "w"    mh-show-junk-whitelist)

Bill Wohler's avatar
Bill Wohler committed
1006 1007 1008 1009 1010 1011
(gnus-define-keys (mh-show-ps-print-map "P" mh-show-mode-map)
  "?"	mh-prefix-help
  "C"	mh-show-ps-print-toggle-color
  "F"	mh-show-ps-print-toggle-faces
  "f"	mh-show-ps-print-msg-file
  "l"   mh-show-print-msg
1012
  "p"	mh-show-ps-print-msg)
Bill Wohler's avatar
Bill Wohler committed
1013

Bill Wohler's avatar
Bill Wohler committed
1014 1015
(gnus-define-keys (mh-show-thread-map "T" mh-show-mode-map)
  "?"    mh-prefix-help
Bill Wohler's avatar
Bill Wohler committed
1016 1017 1018 1019 1020 1021
  "u"    mh-show-thread-ancestor
  "p"    mh-show-thread-previous-sibling
  "n"    mh-show-thread-next-sibling
  "t"    mh-show-toggle-threads
  "d"    mh-show-thread-delete
  "o"    mh-show-thread-refile)
Bill Wohler's avatar
Bill Wohler committed
1022 1023

(gnus-define-keys (mh-show-limit-map "/" mh-show-mode-map)
Bill Wohler's avatar
Bill Wohler committed
1024
  "'"    mh-show-narrow-to-tick