rmail.el 155 KB
Newer Older
1
;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
Eric S. Raymond's avatar
Eric S. Raymond committed
2

3
;; Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998,
Miles Bader's avatar
Miles Bader committed
4
;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
Glenn Morris's avatar
Glenn Morris committed
5
;;   Free Software Foundation, Inc.
Eric S. Raymond's avatar
Eric S. Raymond committed
6

Eric S. Raymond's avatar
Eric S. Raymond committed
7
;; Maintainer: FSF
Eric S. Raymond's avatar
Eric S. Raymond committed
8
;; Keywords: mail
Eric S. Raymond's avatar
Eric S. Raymond committed
9

Roland McGrath's avatar
Roland McGrath committed
10 11 12 13
;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
14
;; the Free Software Foundation; either version 3, or (at your option)
Roland McGrath's avatar
Roland McGrath committed
15 16 17 18 19 20 21 22
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; 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
23
;; along with GNU Emacs; see the file COPYING.  If not, write to the
Lute Kamstra's avatar
Lute Kamstra committed
24 25
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
Roland McGrath's avatar
Roland McGrath committed
26

27 28
;;; Commentary:

Eric S. Raymond's avatar
Eric S. Raymond committed
29
;;; Code:
Roland McGrath's avatar
Roland McGrath committed
30 31 32 33 34 35

;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
;;   New features include attribute and keyword support, message
;;   selection by dispatch table, summary by attributes and keywords,
;;   expunging by dispatch table, sticky options for file commands.

36 37 38 39 40 41 42
;; Extended by Bob Weiner of Motorola
;;   New features include: rmail and rmail-summary buffers remain
;;   synchronized and key bindings basically operate the same way in both
;;   buffers, summary by topic or by regular expression, rmail-reply-prefix
;;   variable, and a bury rmail buffer (wipe) command.
;;

Roland McGrath's avatar
Roland McGrath committed
43
(require 'mail-utils)
44
(eval-when-compile (require 'mule-util)) ; for detect-coding-with-priority
45

46 47 48 49 50 51 52 53 54
(defvar deleted-head)
(defvar font-lock-fontified)
(defvar mail-abbrev-syntax-table)
(defvar mail-abbrevs)
(defvar messages-head)
(defvar rmail-use-spam-filter)
(defvar rsf-beep)
(defvar rsf-sleep-after-message)
(defvar total-messages)
Eli Zaretskii's avatar
Eli Zaretskii committed
55
(defvar tool-bar-map)
56

57
; These variables now declared in paths.el.
Roland McGrath's avatar
Roland McGrath committed
58 59
;(defvar rmail-spool-directory "/usr/spool/mail/"
;  "This is the name of the directory used by the system mailer for\n\
60
;delivering new mail.  Its name should end with a slash.")
Roland McGrath's avatar
Roland McGrath committed
61 62 63 64
;(defvar rmail-file-name
;  (expand-file-name "~/RMAIL")
;  "")

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
(defgroup rmail nil
  "Mail reader for Emacs."
  :group 'mail)

(defgroup rmail-retrieve nil
  "Rmail retrieval options."
  :prefix "rmail-"
  :group 'rmail)

(defgroup rmail-files nil
  "Rmail files."
  :prefix "rmail-"
  :group 'rmail)

(defgroup rmail-headers nil
  "Rmail header options."
  :prefix "rmail-"
  :group 'rmail)

(defgroup rmail-reply nil
  "Rmail reply options."
  :prefix "rmail-"
  :group 'rmail)

(defgroup rmail-summary nil
  "Rmail summary options."
  :prefix "rmail-"
  :prefix "rmail-summary-"
  :group 'rmail)

(defgroup rmail-output nil
  "Output message to a file."
  :prefix "rmail-output-"
  :prefix "rmail-"
  :group 'rmail)

101 102 103 104 105
(defgroup rmail-edit nil
  "Rmail editing."
  :prefix "rmail-edit-"
  :group 'rmail)

106 107 108
(defgroup rmail-obsolete nil
  "Rmail obsolete customization variables."
  :group 'rmail)
109

110
(defcustom rmail-movemail-program nil
111
  "If non-nil, the file name of the `movemail' program."
112
  :group 'rmail-retrieve
113
  :type '(choice (const nil) string))
114

115
(defcustom rmail-pop-password nil
116 117
  "*Password to use when reading mail from POP server.
Please use `rmail-remote-password' instead."
118 119
  :type '(choice (string :tag "Password")
		 (const :tag "Not Required" nil))
120
  :group 'rmail-obsolete)
121

122
(defcustom rmail-pop-password-required nil
123
  "*Non-nil if a password is required when reading mail from a POP server.
124
Please use rmail-remote-password-required instead."
125
  :type 'boolean
126 127 128
  :group 'rmail-obsolete)

(defcustom rmail-remote-password nil
129 130
  "*Password to use when reading mail from a remote server.
This setting is ignored for mailboxes whose URL already contains a password."
131 132 133 134
  :type '(choice (string :tag "Password")
		 (const :tag "Not Required" nil))
  :set-after '(rmail-pop-password)
  :set #'(lambda (symbol value)
135
	   (set-default symbol
136 137 138 139 140 141 142
			(if (and (not value)
                                 (boundp 'rmail-pop-password)
				 rmail-pop-password)
			    rmail-pop-password
			  value))
	   (setq rmail-pop-password nil))
  :group 'rmail-retrieve
143
  :version "22.1")
144 145 146 147 148 149

(defcustom rmail-remote-password-required nil
  "*Non-nil if a password is required when reading mail from a remote server."
  :type 'boolean
  :set-after '(rmail-pop-password-required)
  :set #'(lambda (symbol value)
150
	   (set-default symbol
151 152 153 154 155 156 157
			(if (and (not value)
                                 (boundp 'rmail-pop-password-required)
				 rmail-pop-password-required)
			    rmail-pop-password-required
			  value))
	   (setq rmail-pop-password-required nil))
  :group 'rmail-retrieve
158
  :version "22.1")
159

160
(defcustom rmail-movemail-flags nil
Karl Heuer's avatar
Karl Heuer committed
161 162 163
  "*List of flags to pass to movemail.
Most commonly used to specify `-g' to enable GSS-API authentication
or `-k' to enable Kerberos authentication."
164
  :type '(repeat string)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
165 166
  :group 'rmail-retrieve
  :version "20.3")
167

168 169 170 171
(defvar rmail-remote-password-error "invalid usercode or password\\|
unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
  "Regular expression matching incorrect-password POP or IMAP server error
messages.
172 173 174
If you get an incorrect-password error that this expression does not match,
please report it with \\[report-emacs-bug].")

175
(defvar rmail-encoded-remote-password nil)
176

177
(defcustom rmail-preserve-inbox nil
178
  "*Non-nil means leave incoming mail in the user's inbox--don't delete it."
179 180
  :type 'boolean
  :group 'rmail-retrieve)
181

182 183 184 185 186
(defcustom rmail-movemail-search-path nil
    "*List of directories to search for movemail (in addition to `exec-path')."
    :group 'rmail-retrieve
    :type '(repeat (directory)))

187 188 189 190
(declare-function mail-position-on-field "sendmail" (field &optional soft))
(declare-function mail-text-start "sendmail" ())
(declare-function rmail-update-summary "rmailsum" (&rest ignore))

191
(defun rmail-probe (prog)
192 193
  "Determine what flavor of movemail PROG is.
We do this by executing it with `--version' and analyzing its output."
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
  (with-temp-buffer
    (let ((tbuf (current-buffer)))
      (buffer-disable-undo tbuf)
      (call-process prog nil tbuf nil "--version")
      (if (not (buffer-modified-p tbuf))
	  ;; Should not happen...
	  nil
	(goto-char (point-min))
	(cond
	 ((looking-at ".*movemail: invalid option")
	  'emacs)    ;; Possibly...
	 ((looking-at "movemail (GNU Mailutils .*)")
	  'mailutils)
	 (t
	  ;; FIXME:
	  'emacs))))))

(defun rmail-autodetect ()
Andreas Schwab's avatar
Andreas Schwab committed
212
  "Determine the file name of the `movemail' program and return its flavor.
213 214 215
If `rmail-movemail-program' is non-nil, use it.
Otherwise, look for `movemail' in the directories in
`rmail-movemail-search-path', those in `exec-path', and `exec-directory'."
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
  (if rmail-movemail-program
      (rmail-probe rmail-movemail-program)
    (catch 'scan
      (dolist (dir (append rmail-movemail-search-path exec-path
			   (list exec-directory)))
	(when (and dir (file-accessible-directory-p dir))
	  (let ((progname (expand-file-name "movemail" dir)))
	    (when (and (not (file-directory-p progname))
		       (file-executable-p progname))
	      (let ((x (rmail-probe progname)))
		(when x
		  (setq rmail-movemail-program progname)
		  (throw 'scan x))))))))))

(defvar rmail-movemail-variant-in-use nil
  "The movemail variant currently in use. Known variants are:

  `emacs'     Means any implementation, compatible with the native Emacs one.
              This is the default;
  `mailutils' Means GNU mailutils implementation, capable of handling full
236
mail URLs as the source mailbox.")
237 238 239 240 241 242 243 244 245 246

;;;###autoload
(defun rmail-movemail-variant-p (&rest variants)
  "Return t if the current movemail variant is any of VARIANTS.
Currently known variants are 'emacs and 'mailutils."
  (when (not rmail-movemail-variant-in-use)
    ;; Autodetect
    (setq rmail-movemail-variant-in-use (rmail-autodetect)))
  (not (null (member rmail-movemail-variant-in-use variants))))

247 248 249 250 251 252
;; Call for effect, to set rmail-movemail-program (if not set by the
;; user), and rmail-movemail-variant-in-use. Used by various functions.
;; I'm not sure if M-x rmail is the only entry point to this package.
;; If so, this can be moved there.
(rmail-movemail-variant-p)

Roland McGrath's avatar
Roland McGrath committed
253
;;;###autoload
254
(defcustom rmail-dont-reply-to-names nil "\
255 256
*A regexp specifying addresses to prune from a reply message.
A value of nil means exclude your own email address as an address
257
plus whatever is specified by `rmail-default-dont-reply-to-names'."
258 259
  :type '(choice regexp (const :tag "Your Name" nil))
  :group 'rmail-reply)
Roland McGrath's avatar
Roland McGrath committed
260 261

;;;###autoload
Kenichi Handa's avatar
Kenichi Handa committed
262 263 264
(defvar rmail-default-dont-reply-to-names "\\`info-" "\
A regular expression specifying part of the default value of the
variable `rmail-dont-reply-to-names', for when the user does not set
Roland McGrath's avatar
Roland McGrath committed
265
`rmail-dont-reply-to-names' explicitly.  (The other part of the default
266
value is the user's email address and name.)
Richard M. Stallman's avatar
Richard M. Stallman committed
267
It is useful to set this variable in the site customization file.")
Roland McGrath's avatar
Roland McGrath committed
268 269

;;;###autoload
270
(defcustom rmail-ignored-headers
271
  (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
272 273 274
	  "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
	  "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
	  "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
275
	  "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
276
	  "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
277 278 279 280
	  "\\|^content-transfer-encoding:\\|^x-coding-system:"
	  "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
	  "\\|^precedence:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
	  "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
281 282
	  "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
	  "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
283
	  "\\|^mbox-line:\\|^cancel-lock:\\|^DomainKey-Signature:"
284 285 286
	  "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"

	  "\\|^x-.*:")
287
  "*Regexp to match header fields that Rmail should normally hide.
288 289 290 291 292 293 294 295 296 297 298 299 300 301
\(See also `rmail-nonignored-headers', which overrides this regexp.)
This variable is used for reformatting the message header,
which normally happens once for each message,
when you view the message for the first time in Rmail.
To make a change in this variable take effect
for a message that you have already viewed,
go to that message and type \\[rmail-toggle-header] twice."
  :type 'regexp
  :group 'rmail-headers)

(defcustom rmail-nonignored-headers "^x-spam-status:"
  "*Regexp to match X header fields that Rmail should show.
This regexp overrides `rmail-ignored-headers'; if both this regexp
and that one match a certain header field, Rmail shows the field.
302
If this is nil, ignore all header fields in `rmail-ignored-headers'.
303

304 305 306 307 308 309
This variable is used for reformatting the message header,
which normally happens once for each message,
when you view the message for the first time in Rmail.
To make a change in this variable take effect
for a message that you have already viewed,
go to that message and type \\[rmail-toggle-header] twice."
310
  :type '(choice (const nil) (regexp))
311
  :group 'rmail-headers)
Roland McGrath's avatar
Roland McGrath committed
312

313
;;;###autoload
314
(defcustom rmail-displayed-headers nil
315 316
  "*Regexp to match Header fields that Rmail should display.
If nil, display all header fields except those matched by
317 318 319
`rmail-ignored-headers'."
  :type '(choice regexp (const :tag "All"))
  :group 'rmail-headers)
320

321
;;;###autoload
322
(defcustom rmail-retry-ignored-headers "^x-authentication-warning:" "\
323 324 325
*Headers that should be stripped when retrying a failed message."
  :type '(choice regexp (const nil :tag "None"))
  :group 'rmail-headers)
326

327
;;;###autoload
328
(defcustom rmail-highlighted-headers "^From:\\|^Subject:" "\
329
*Regexp to match Header fields that Rmail should normally highlight.
330
A value of nil means don't highlight.
331 332 333
See also `rmail-highlight-face'."
  :type 'regexp
  :group 'rmail-headers)
334

335
(defface rmail-highlight
336
  '((t (:inherit highlight)))
337 338 339 340
  "Face to use for highlighting the most important header fields."
  :group 'rmail-headers
  :version "22.1")

341
;;;###autoload
342
(defcustom rmail-highlight-face 'rmail-highlight "\
343 344 345 346
*Face used by Rmail for highlighting headers."
  :type '(choice (const :tag "Default" nil)
		 face)
  :group 'rmail-headers)
347

Roland McGrath's avatar
Roland McGrath committed
348
;;;###autoload
349 350 351 352
(defcustom rmail-delete-after-output nil "\
*Non-nil means automatically delete a message that is copied to a file."
  :type 'boolean
  :group 'rmail-files)
Roland McGrath's avatar
Roland McGrath committed
353 354

;;;###autoload
355
(defcustom rmail-primary-inbox-list nil "\
356
*List of files which are inboxes for user's primary mail file `~/RMAIL'.
357
nil means the default, which is (\"/usr/spool/mail/$USER\")
358
\(the name varies depending on the operating system,
359
and the value of the environment variable MAIL overrides it)."
360 361 362
  ;; Don't use backquote here, because we don't want to need it
  ;; at load time.
  :type (list 'choice '(const :tag "Default" nil)
363 364 365
	      (list 'repeat ':value (list (or (getenv "MAIL")
					      (concat "/var/spool/mail/"
						      (getenv "USER"))))
366
		    'file))
367 368
  :group 'rmail-retrieve
  :group 'rmail-files)
Roland McGrath's avatar
Roland McGrath committed
369

370
;;;###autoload
371
(defcustom rmail-mail-new-frame nil
372 373 374
  "*Non-nil means Rmail makes a new frame for composing outgoing mail.
This is handy if you want to preserve the window configuration of
the frame where you have the RMAIL buffer displayed."
375 376
  :type 'boolean
  :group 'rmail-reply)
377

378
;;;###autoload
379 380 381 382
(defcustom rmail-secondary-file-directory "~/"
  "*Directory for additional secondary Rmail files."
  :type 'directory
  :group 'rmail-files)
383
;;;###autoload
384 385 386 387
(defcustom rmail-secondary-file-regexp "\\.xmail$"
  "*Regexp for which files are secondary Rmail files."
  :type 'regexp
  :group 'rmail-files)
388

389
;;;###autoload
390
(defcustom rmail-confirm-expunge 'y-or-n-p
391 392 393 394 395 396 397
  "*Whether and how to ask for confirmation before expunging deleted messages."
  :type '(choice (const :tag "No confirmation" nil)
		 (const :tag "Confirm with y-or-n-p" y-or-n-p)
		 (const :tag "Confirm with yes-or-no-p" yes-or-no-p))
  :version "21.1"
  :group 'rmail-files)

398 399 400 401 402 403 404 405 406
;;;###autoload
(defvar rmail-mode-hook nil
  "List of functions to call when Rmail is invoked.")

;;;###autoload
(defvar rmail-get-new-mail-hook nil
  "List of functions to call when Rmail has retrieved new mail.")

;;;###autoload
407 408 409
(defcustom rmail-show-message-hook nil
  "List of functions to call when Rmail displays a message."
  :type 'hook
410
  :options '(goto-address)
411
  :group 'rmail)
412

413 414 415 416
;;;###autoload
(defvar rmail-quit-hook nil
  "List of functions to call when quitting out of Rmail.")

417 418 419 420 421 422
;;;###autoload
(defvar rmail-delete-message-hook nil
  "List of functions to call when Rmail deletes a message.
When the hooks are called, the message has been marked deleted but is
still the current message in the Rmail buffer.")

423 424 425
;; These may be altered by site-init.el to match the format of mmdf files
;;  delimiting used on a given host (delim1 and delim2 from the config
;;  files).
Roland McGrath's avatar
Roland McGrath committed
426

427
(defvar rmail-mmdf-delim1 "^\001\001\001\001\n"
428
  "Regexp marking the start of an mmdf message.")
429
(defvar rmail-mmdf-delim2 "^\001\001\001\001\n"
430
  "Regexp marking the end of an mmdf message.")
Roland McGrath's avatar
Roland McGrath committed
431

432
(defcustom rmail-message-filter nil
433 434
  "If non-nil, a filter function for new messages in RMAIL.
Called with region narrowed to the message, including headers,
435 436
before obeying `rmail-ignored-headers'."
  :group 'rmail-headers
437
  :type '(choice (const nil) function))
Roland McGrath's avatar
Roland McGrath committed
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
(defcustom rmail-automatic-folder-directives nil
  "List of directives specifying where to put a message.
Each element of the list is of the form:

  (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )

Where FOLDERNAME is the name of a BABYL format folder to put the
message.  If any of the field regexp's are nil, then it is ignored.

If FOLDERNAME is \"/dev/null\", it is deleted.
If FOLDERNAME is nil then it is deleted, and skipped.

FIELD is the plain text name of a field in the message, such as
\"subject\" or \"from\".  A FIELD of \"to\" will automatically include
all text from the \"cc\" field as well.

REGEXP is an expression to match in the preceeding specified FIELD.
FIELD/REGEXP pairs continue in the list.

examples:
  (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
460 461 462 463
  (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
  :group 'rmail
  :version "21.1"
  :type '(repeat (sexp :tag "Directive")))
464

465 466 467
(defvar rmail-reply-prefix "Re: "
  "String to prepend to Subject line when replying to a message.")

468
;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
469 470 471 472
;; This pattern should catch all the common variants.
;; rms: I deleted the change to delete tags in square brackets
;; because they mess up RT tags.
(defvar rmail-reply-regexp "\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
473
  "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
Karl Heuer's avatar
Karl Heuer committed
474

475 476 477 478 479
(defcustom rmail-display-summary nil
  "*If non-nil, Rmail always displays the summary buffer."
  :group 'rmail-summary
  :type 'boolean)

Roland McGrath's avatar
Roland McGrath committed
480
(defvar rmail-inbox-list nil)
481 482
(put 'rmail-inbox-list 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
483
(defvar rmail-keywords nil)
484
(put 'rmail-keywords 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
485

486 487 488 489 490 491
(defvar rmail-buffer nil
  "The RMAIL buffer related to the current buffer.
In an RMAIL buffer, this holds the RMAIL buffer itself.
In a summary buffer, this holds the RMAIL buffer it is a summary for.")
(put 'rmail-buffer 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
492 493 494
;; Message counters and markers.  Deleted flags.

(defvar rmail-current-message nil)
495 496
(put 'rmail-current-message 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
497
(defvar rmail-total-messages nil)
498 499
(put 'rmail-total-messages 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
500
(defvar rmail-message-vector nil)
501 502
(put 'rmail-message-vector 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
503
(defvar rmail-deleted-vector nil)
504 505
(put 'rmail-deleted-vector 'permanent-local t)

506 507 508 509
(defvar rmail-msgref-vector nil
  "In an Rmail buffer, a vector whose Nth element is a list (N).
When expunging renumbers messages, these lists are modified
by substituting the new message number into the existing list.")
510
(put 'rmail-msgref-vector 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
511

512
(defvar rmail-overlay-list nil)
513
(put 'rmail-overlay-list 'permanent-local t)
514

Roland McGrath's avatar
Roland McGrath committed
515 516 517
;; These are used by autoloaded rmail-summary.

(defvar rmail-summary-buffer nil)
518
(put 'rmail-summary-buffer 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
519
(defvar rmail-summary-vector nil)
520
(put 'rmail-summary-vector 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
521

522 523 524 525
(defvar rmail-view-buffer nil
  "Buffer which holds RMAIL message for MIME displaying.")
(put 'rmail-view-buffer 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
526 527 528 529
;; `Sticky' default variables.

;; Last individual label specified to a or k.
(defvar rmail-last-label nil)
530 531
(put 'rmail-last-label 'permanent-local t)

532
;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
Roland McGrath's avatar
Roland McGrath committed
533
(defvar rmail-last-multi-labels nil)
534

535
(defvar rmail-last-regexp nil)
536 537
(put 'rmail-last-regexp 'permanent-local t)

538 539 540 541 542 543 544 545
(defcustom rmail-default-file "~/xmail"
  "*Default file name for \\[rmail-output]."
  :type 'file
  :group 'rmail-files)
(defcustom rmail-default-rmail-file "~/XMAIL"
  "*Default file name for \\[rmail-output-to-rmail-file]."
  :type 'file
  :group 'rmail-files)
546 547 548 549 550
(defcustom rmail-default-body-file "~/mailout"
  "*Default file name for \\[rmail-output-body-to-file]."
  :type 'file
  :group 'rmail-files
  :version "20.3")
Jim Blandy's avatar
Jim Blandy committed
551

552 553 554 555 556 557 558 559 560 561 562 563 564
;; Mule and MIME related variables.

;;;###autoload
(defvar rmail-file-coding-system nil
  "Coding system used in RMAIL file.

This is set to nil by default.")

;;;###autoload
(defcustom rmail-enable-mime nil
  "*If non-nil, RMAIL uses MIME feature.
If the value is t, RMAIL automatically shows MIME decoded message.
If the value is neither t nor nil, RMAIL does not show MIME decoded message
565 566 567 568 569
until a user explicitly requires it.

Even if the value is non-nil, you can't use MIME feature
if the feature specified by `rmail-mime-feature' is not available
in your session."
570 571
  :type '(choice (const :tag "on" t)
		 (const :tag "off" nil)
572
		 (other :tag "when asked" ask))
573 574
  :group 'rmail)

575 576 577
(defvar rmail-enable-mime-composing nil
  "*If non-nil, RMAIL uses `rmail-insert-mime-forwarded-message-function' to forward.")

578 579
;;;###autoload
(defvar rmail-show-mime-function nil
580 581 582 583 584 585 586
  "Function to show MIME decoded message of RMAIL file.
This function is called when `rmail-enable-mime' is non-nil.
It is called with no argument.")

;;;###autoload
(defvar rmail-insert-mime-forwarded-message-function nil
  "Function to insert a message in MIME format so it can be forwarded.
587
This function is called if `rmail-enable-mime' or
588
`rmail-enable-mime-composing' is non-nil.
589 590 591 592
It is called with one argument FORWARD-BUFFER, which is a
buffer containing the message to forward.  The current buffer
is the outgoing mail buffer.")

593 594 595 596 597 598 599 600
;;;###autoload
(defvar rmail-insert-mime-resent-message-function nil
  "Function to insert a message in MIME format so it can be resent.
This function is called if `rmail-enable-mime' is non-nil.
It is called with one argument FORWARD-BUFFER, which is a
buffer containing the message to forward.  The current buffer
is the outgoing mail buffer.")

601 602 603 604 605 606 607 608 609 610 611
;;;###autoload
(defvar rmail-search-mime-message-function nil
  "Function to check if a regexp matches a MIME message.
This function is called if `rmail-enable-mime' is non-nil.
It is called with two arguments MSG and REGEXP, where
MSG is the message number, REGEXP is the regular expression.")

;;;###autoload
(defvar rmail-search-mime-header-function nil
  "Function to check if a regexp matches a header of MIME message.
This function is called if `rmail-enable-mime' is non-nil.
612
It is called with three arguments MSG, REGEXP, and LIMIT, where
613 614 615
MSG is the message number,
REGEXP is the regular expression,
LIMIT is the position specifying the end of header.")
616 617 618

;;;###autoload
(defvar rmail-mime-feature 'rmail-mime
619 620
  "Feature to require to load MIME support in Rmail.
When starting Rmail, if `rmail-enable-mime' is non-nil,
621 622 623 624
this feature is required with `require'.

The default value is `rmail-mime'.  This feature is provided by
the rmail-mime package available at <http://www.m17n.org/rmail-mime/>.")
625 626 627 628 629 630 631 632 633 634 635 636 637

;;;###autoload
(defvar rmail-decode-mime-charset t
  "*Non-nil means a message is decoded by MIME's charset specification.
If this variable is nil, or the message has not MIME specification,
the message is decoded as normal way.

If the variable `rmail-enable-mime' is non-nil, this variables is
ignored, and all the decoding work is done by a feature specified by
the variable `rmail-mime-feature'.")

;;;###autoload
(defvar rmail-mime-charset-pattern
638
  (concat "^content-type:[ \t]*text/plain;"
639
	  "\\(?:[ \t\n]*\\(?:format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
640
	  "[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?")
641 642 643
  "Regexp to match MIME-charset specification in a header of message.
The first parenthesized expression should match the MIME-charset name.")

644

Jim Blandy's avatar
Jim Blandy committed
645 646 647 648
;;; Regexp matching the delimiter of messages in UNIX mail format
;;; (UNIX From lines), minus the initial ^.  Note that if you change
;;; this expression, you must change the code in rmail-nuke-pinhead-header
;;; that knows the exact ordering of the \\( \\) subexpressions.
Jim Blandy's avatar
Jim Blandy committed
649
(defvar rmail-unix-mail-delimiter
Jim Blandy's avatar
Jim Blandy committed
650
  (let ((time-zone-regexp
651
	 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
Jim Blandy's avatar
Jim Blandy committed
652 653 654 655 656 657
		 "\\|[-+]?[0-9][0-9][0-9][0-9]"
		 "\\|"
		 "\\) *")))
    (concat
     "From "

658 659 660 661 662 663 664 665 666 667 668
     ;; Many things can happen to an RFC 822 mailbox before it is put into
     ;; a `From' line.  The leading phrase can be stripped, e.g.
     ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'.  The <> can be stripped, e.g.
     ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'.  Everything starting with a CRLF
     ;; can be removed, e.g.
     ;;		From: joe@y.z (Joe	K
     ;;			User)
     ;; can yield `From joe@y.z (Joe 	K Fri Mar 22 08:11:15 1996', and
     ;;		From: Joe User
     ;;			<joe@y.z>
     ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
669 670 671 672 673
     ;; The mailbox can be removed or be replaced by white space, e.g.
     ;;		From: "Joe User"{space}{tab}
     ;;			<joe@y.z>
     ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
     ;; where {space} and {tab} represent the Ascii space and tab characters.
674 675 676
     ;; We want to match the results of any of these manglings.
     ;; The following regexp rejects names whose first characters are
     ;; obviously bogus, but after that anything goes.
677
     "\\([^\0-\b\n-\r\^?].*\\)? "
Jim Blandy's avatar
Jim Blandy committed
678 679

     ;; The time the message was sent.
680 681 682 683
     "\\([^\0-\r \^?]+\\) +"				; day of the week
     "\\([^\0-\r \^?]+\\) +"				; month
     "\\([0-3]?[0-9]\\) +"				; day of month
     "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *"	; time of day
Jim Blandy's avatar
Jim Blandy committed
684 685 686 687 688 689

     ;; Perhaps a time zone, specified by an abbreviation, or by a
     ;; numeric offset.
     time-zone-regexp

     ;; The year.
690
     " \\([0-9][0-9]+\\) *"
Jim Blandy's avatar
Jim Blandy committed
691 692 693 694

     ;; On some systems the time zone can appear after the year, too.
     time-zone-regexp

Karl Heuer's avatar
Karl Heuer committed
695 696
     ;; Old uucp cruft.
     "\\(remote from .*\\)?"
Jim Blandy's avatar
Jim Blandy committed
697 698 699 700

     "\n"))
  nil)

701
(defvar rmail-font-lock-keywords
702
  ;; These are all matched case-insensitively.
703 704
  (eval-when-compile
    (let* ((cite-chars "[>|}]")
705
	   (cite-prefix "a-z")
706
	   (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
707 708
      (list '("^\\(From\\|Sender\\|Resent-From\\):"
	      . font-lock-function-name-face)
709 710
	    '("^Reply-To:.*$" . font-lock-function-name-face)
	    '("^Subject:" . font-lock-comment-face)
711
	    '("^X-Spam-Status:" . font-lock-keyword-face)
712 713 714 715 716
	    '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
	      . font-lock-keyword-face)
	    ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
	    `(,cite-chars
	      (,(concat "\\=[ \t]*"
717 718
			"\\(\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
			"\\(" cite-chars "[ \t]*\\)\\)+\\)"
719 720
			"\\(.*\\)")
	       (beginning-of-line) (end-of-line)
721 722
	       (1 font-lock-comment-delimiter-face nil t)
	       (5 font-lock-comment-face nil t)))
723
	    '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
724 725 726
	      . font-lock-string-face))))
  "Additional expressions to highlight in Rmail mode.")

727 728 729
;; Perform BODY in the summary buffer
;; in such a way that its cursor is properly updated in its own window.
(defmacro rmail-select-summary (&rest body)
Gerd Moellmann's avatar
Gerd Moellmann committed
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
  `(let ((total rmail-total-messages))
     (if (rmail-summary-displayed)
	 (let ((window (selected-window)))
	   (save-excursion
	     (unwind-protect
		 (progn
		   (pop-to-buffer rmail-summary-buffer)
		   ;; rmail-total-messages is a buffer-local var
		   ;; in the rmail buffer.
		   ;; This way we make it available for the body
		   ;; even tho the rmail buffer is not current.
		   (let ((rmail-total-messages total))
		     ,@body))
	       (select-window window))))
       (save-excursion
	 (set-buffer rmail-summary-buffer)
	 (let ((rmail-total-messages total))
	   ,@body)))
     (rmail-maybe-display-summary)))
Roland McGrath's avatar
Roland McGrath committed
749 750 751

;;;; *** Rmail Mode ***

752 753 754
;; This variable is dynamically bound.  The defvar is here to placate
;; the byte compiler.

755 756
(defvar rmail-enable-multibyte nil)

757 758 759 760 761 762 763 764 765

(defun rmail-require-mime-maybe ()
  "Require `rmail-mime-feature' if that is non-nil.
Signal an error and set `rmail-mime-feature' to nil if the feature
isn't provided."
  (when rmail-enable-mime
    (condition-case err
	(require rmail-mime-feature)
      (error
766 767 768 769 770 771 772 773
       (display-warning
	:warning
	(format "Although MIME support is requested
by setting `rmail-enable-mime' to non-nil, the required feature
`%s' (the value of `rmail-mime-feature')
is not available in the current session.
So, the MIME support is turned off for the moment." 
		rmail-mime-feature))
774 775 776
       (setq rmail-enable-mime nil)))))


Roland McGrath's avatar
Roland McGrath committed
777 778 779
;;;###autoload
(defun rmail (&optional file-name-arg)
  "Read and edit incoming mail.
780
Moves messages into file named by `rmail-file-name' (a babyl format file)
Roland McGrath's avatar
Roland McGrath committed
781 782 783
 and edits that file in RMAIL Mode.
Type \\[describe-mode] once editing that file, for a list of RMAIL commands.

784 785 786
May be called with file name as argument; then performs rmail editing on
that file, but does not copy any new mail into the file.
Interactively, if you supply a prefix argument, then you
787 788 789
have a chance to specify a file name with the minibuffer.

If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
Roland McGrath's avatar
Roland McGrath committed
790
  (interactive (if current-prefix-arg
791
		   (list (read-file-name "Run rmail on RMAIL file: "))))
792
  (rmail-require-mime-maybe)
Roland McGrath's avatar
Roland McGrath committed
793
  (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
794 795 796
	 ;; Use find-buffer-visiting, not get-file-buffer, for those users
	 ;; who have find-file-visit-truename set to t.
	 (existed (find-buffer-visiting file-name))
797
	 ;; This binding is necessary because we must decide if we
798 799
	 ;; need code conversion while the buffer is unibyte
	 ;; (i.e. enable-multibyte-characters is nil).
800
         (rmail-enable-multibyte
801
          (if existed
802 803
	      (with-current-buffer existed enable-multibyte-characters)
            (default-value 'enable-multibyte-characters)))
804 805 806 807 808 809 810
	 ;; Since the file may contain messages of different encodings
	 ;; at the tail (non-BYBYL part), we can't decode them at once
	 ;; on reading.  So, at first, we read the file without text
	 ;; code conversion, then decode the messages one by one by
	 ;; rmail-decode-babyl-format or
	 ;; rmail-convert-to-babyl-format.
	 (coding-system-for-read (and rmail-enable-multibyte 'raw-text))
811
	 run-mail-hook msg-shown)
Roland McGrath's avatar
Roland McGrath committed
812 813
    ;; Like find-file, but in the case where a buffer existed
    ;; and the file was reverted, recompute the message-data.
814 815 816 817 818
    ;; We used to bind enable-local-variables to nil here,
    ;; but that should not be needed now that rmail-mode
    ;; sets it locally to nil.
    ;; (Binding a variable locally with let is not safe if it has
    ;; buffer-local bindings.)
Roland McGrath's avatar
Roland McGrath committed
819 820
    (if (and existed (not (verify-visited-file-modtime existed)))
	(progn
821
	  (find-file file-name)
822 823
	  (if (and (verify-visited-file-modtime existed)
		   (eq major-mode 'rmail-mode))
Roland McGrath's avatar
Roland McGrath committed
824 825
	      (progn (rmail-forget-messages)
		     (rmail-set-message-counters))))
826
      (switch-to-buffer
827 828
       (let ((enable-local-variables nil))
	 (find-file-noselect file-name))))
829
    (if (eq major-mode 'rmail-edit-mode)
830
	(error "Exit Rmail Edit mode before getting new mail"))
Roland McGrath's avatar
Roland McGrath committed
831 832 833
    (if (and existed (> (buffer-size) 0))
	;; Buffer not new and not empty; ensure in proper mode, but that's all.
	(or (eq major-mode 'rmail-mode)
834 835 836
	    (progn (rmail-mode-2)
		   (setq run-mail-hook t)))
      (setq run-mail-hook t)
Roland McGrath's avatar
Roland McGrath committed
837 838 839
      (rmail-mode-2)
      ;; Convert all or part to Babyl file if possible.
      (rmail-convert-file)
840
      (goto-char (point-max)))
841 842 843 844 845
    ;; As we have read a file by raw-text, the buffer is set to
    ;; unibyte.  We must make it multibyte if necessary.
    (if (and rmail-enable-multibyte
	     (not enable-multibyte-characters))
	(set-buffer-multibyte t))
846 847
    ;; If necessary, scan to find all the messages.
    (rmail-maybe-set-message-counters)
848
    (unwind-protect
849 850 851
	(unless (and (not file-name-arg)
		     (rmail-get-new-mail))
	  (rmail-show-message (rmail-first-unseen-message)))
852 853 854 855 856
      (progn
	(if rmail-display-summary (rmail-summary))
	(rmail-construct-io-menu)
	(if run-mail-hook
	    (run-hooks 'rmail-mode-hook))))))
Roland McGrath's avatar
Roland McGrath committed
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874

;; Given the value of MAILPATH, return a list of inbox file names.
;; This is turned off because it is not clear that the user wants
;; all these inboxes to feed into the primary rmail file.
; (defun rmail-convert-mailpath (string)
;   (let (idx list)
;     (while (setq idx (string-match "[%:]" string))
;       (let ((this (substring string 0 idx)))
; 	(setq string (substring string (1+ idx)))
; 	(setq list (cons (if (string-match "%" this)
; 			     (substring this 0 (string-match "%" this))
; 			   this)
; 			 list))))
;     list))

; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
; will not cause emacs 18.55 problems.

875 876
;; This calls rmail-decode-babyl-format if the file is already Babyl.

Roland McGrath's avatar
Roland McGrath committed
877 878 879 880 881 882 883 884 885 886 887 888 889
(defun rmail-convert-file ()
  (let (convert)
    (widen)
    (goto-char (point-min))
    ;; If file doesn't start like a Babyl file,
    ;; convert it to one, by adding a header and converting each message.
    (cond ((looking-at "BABYL OPTIONS:"))
	  ((looking-at "Version: 5\n")
	   ;; Losing babyl file made by old version of Rmail.
	   ;; Just fix the babyl file header; don't make a new one,
	   ;; so we don't lose the Labels: file attribute, etc.
	   (let ((buffer-read-only nil))
	     (insert "BABYL OPTIONS: -*- rmail -*-\n")))
890 891 892
	  ((equal (point-min) (point-max))
	   ;; Empty RMAIL file.  Just insert the header.
	   (rmail-insert-rmail-file-header))
Roland McGrath's avatar
Roland McGrath committed
893
	  (t
894
	   ;; Non-empty file in non-RMAIL format.  Add header and convert.
Roland McGrath's avatar
Roland McGrath committed
895 896 897 898 899 900
	   (setq convert t)
	   (rmail-insert-rmail-file-header)))
    ;; If file was not a Babyl file or if there are
    ;; Unix format messages added at the end,
    ;; convert file as necessary.
    (if (or convert
901 902
	    (save-excursion
	      (goto-char (point-max))
903 904
	      (search-backward "\n\^_")
	      (forward-char 2)
905
	      (looking-at "\n*From ")))
Roland McGrath's avatar
Roland McGrath committed
906 907
	(let ((buffer-read-only nil))
	  (message "Converting to Babyl format...")
908 909 910 911 912
	  ;; If file needs conversion, convert it all,
	  ;; except for the BABYL header.
	  ;; (rmail-convert-to-babyl-format would delete the header.)
	  (goto-char (point-min))
	  (search-forward "\n\^_" nil t)
913
	  (narrow-to-region (point) (point-max))
Roland McGrath's avatar
Roland McGrath committed
914
	  (rmail-convert-to-babyl-format)
915 916 917 918 919
	  (message "Converting to Babyl format...done"))
      (if (and (not rmail-enable-mime)
	       rmail-enable-multibyte)
	  ;; We still have to decode BABYL part.
	  (rmail-decode-babyl-format)))))
Roland McGrath's avatar
Roland McGrath committed
920 921 922

(defun rmail-insert-rmail-file-header ()
  (let ((buffer-read-only nil))
923 924
    ;; -*-rmail-*- is here so that visiting the file normally
    ;; recognizes it as an Rmail file.
Roland McGrath's avatar
Roland McGrath committed
925 926 927 928 929 930 931
    (insert "BABYL OPTIONS: -*- rmail -*-
Version: 5
Labels:
Note:   This is the header of an rmail file.
Note:   If you are seeing it in rmail,
Note:    it means the file has no messages in it.\n\^_")))

Juanma Barranquero's avatar
Juanma Barranquero committed
932
;; Decode Babyl formatted part at the head of current buffer by
933
;; rmail-file-coding-system, or if it is nil, do auto conversion.
934 935 936 937

(defun rmail-decode-babyl-format ()
  (let ((modifiedp (buffer-modified-p))
	(buffer-read-only nil)
938
	(coding-system rmail-file-coding-system)
939
	from to)
940
    (goto-char (point-min))
941
    (search-forward "\n\^_" nil t)	; Skip BABYL header.
942 943 944 945
    (setq from (point))
    (goto-char (point-max))
    (search-backward "\n\^_" from 'mv)
    (setq to (point))
946 947
    (unless (and coding-system
		 (coding-system-p coding-system))
948
      (setq coding-system
949 950 951 952 953 954 955 956 957 958 959
	    ;; If rmail-file-coding-system is nil, Emacs 21 writes
	    ;; RMAIL files in emacs-mule, Emacs 22 in utf-8, but
	    ;; earlier versions did that with the current buffer's
	    ;; encoding.  So we want to favor detection of emacs-mule
	    ;; (whose normal priority is quite low) and utf-8, but
	    ;; still allow detection of other encodings if they won't
	    ;; fit.  The call to with-coding-priority below achieves
	    ;; that.
	    (with-coding-priority '(emacs-mule utf-8)
	      (detect-coding-region from to 'highest))))
    (unless (eq (coding-system-type coding-system) 'undecided)
960
      (set-buffer-modified-p t)		; avoid locking when decoding
961 962
      (let ((buffer-undo-list t))
	(decode-coding-region from to coding-system))
963
      (setq coding-system last-coding-system-used))
964 965 966 967
    (set-buffer-modified-p modifiedp)
    (setq buffer-file-coding-system nil)
    (setq save-buffer-coding-system
	  (or coding-system 'undecided))))
968

969
(defvar rmail-mode-map nil)
Roland McGrath's avatar
Roland McGrath committed
970 971 972 973
(if rmail-mode-map
    nil
  (setq rmail-mode-map (make-keymap))
  (suppress-keymap rmail-mode-map)
974 975 976 977 978 979 980 981 982 983 984 985 986
  (define-key rmail-mode-map "a"      'rmail-add-label)
  (define-key rmail-mode-map "b"      'rmail-bury)
  (define-key rmail-mode-map "c"      'rmail-continue)
  (define-key rmail-mode-map "d"      'rmail-delete-forward)
  (define-key rmail-mode-map "\C-d"   'rmail-delete-backward)
  (define-key rmail-mode-map "e"      'rmail-edit-current-message)
  (define-key rmail-mode-map "f"      'rmail-forward)
  (define-key rmail-mode-map "g"      'rmail-get-new-mail)
  (define-key rmail-mode-map "h"      'rmail-summary)
  (define-key rmail-mode-map "i"      'rmail-input)
  (define-key rmail-mode-map "j"      'rmail-show-message)
  (define-key rmail-mode-map "k"      'rmail-kill-label)
  (define-key rmail-mode-map "l"      'rmail-summary-by-labels)
Roland McGrath's avatar
Roland McGrath committed
987 988 989 990
  (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
  (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
  (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
  (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
  (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
  (define-key rmail-mode-map "m"      'rmail-mail)
  (define-key rmail-mode-map "\em"    'rmail-retry-failure)
  (define-key rmail-mode-map "n"      'rmail-next-undeleted-message)
  (define-key rmail-mode-map "\en"    'rmail-next-message)
  (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
  (define-key rmail-mode-map "o"      'rmail-output-to-rmail-file)
  (define-key rmail-mode-map "\C-o"   'rmail-output)
  (define-key rmail-mode-map "p"      'rmail-previous-undeleted-message)
  (define-key rmail-mode-map "\ep"    'rmail-previous-message)
  (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
  (define-key rmail-mode-map "q"      'rmail-quit)
  (define-key rmail-mode-map "r"      'rmail-reply)
1004
;; I find I can't live without the default M-r command -- rms.
1005 1006 1007 1008 1009
;;  (define-key rmail-mode-map "\er"  'rmail-search-backwards)
  (define-key rmail-mode-map "s"      'rmail-expunge-and-save)
  (define-key rmail-mode-map "\es"    'rmail-search)
  (define-key rmail-mode-map "t"      'rmail-toggle-header)
  (define-key rmail-mode-map "u"      'rmail-undelete-previous-message)
1010
  (define-key rmail-mode-map "w"      'rmail-output-body-to-file)
1011 1012
  (define-key rmail-mode-map "x"      'rmail-expunge)
  (define-key rmail-mode-map "."      'rmail-beginning-of-message)
1013
  (define-key rmail-mode-map "/"      'rmail-end-of-message)
1014 1015 1016 1017 1018
  (define-key rmail-mode-map "<"      'rmail-first-message)
  (define-key rmail-mode-map ">"      'rmail-last-message)
  (define-key rmail-mode-map " "      'scroll-up)
  (define-key rmail-mode-map "\177"   'scroll-down)
  (define-key rmail-mode-map "?"      'describe-mode)
1019 1020 1021 1022 1023 1024
  (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
  (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
  (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
  (define-key rmail-mode-map "\C-c\C-s\C-r"