rmail.el 154 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,
Glenn Morris's avatar
Glenn Morris committed
4 5
;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
;;   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
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 302
\(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.

303 304 305 306 307 308
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."
309 310
  :type 'regexp
  :group 'rmail-headers)
Roland McGrath's avatar
Roland McGrath committed
311

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

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

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

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

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

Roland McGrath's avatar
Roland McGrath committed
347
;;;###autoload
348 349 350 351
(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
352 353

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

369
;;;###autoload
370
(defcustom rmail-mail-new-frame nil
371 372 373
  "*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."
374 375
  :type 'boolean
  :group 'rmail-reply)
376

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

388
;;;###autoload
389
(defcustom rmail-confirm-expunge 'y-or-n-p
390 391 392 393 394 395 396
  "*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)

397 398 399 400 401 402 403 404 405
;;;###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
406 407 408
(defcustom rmail-show-message-hook nil
  "List of functions to call when Rmail displays a message."
  :type 'hook
409
  :options '(goto-address)
410
  :group 'rmail)
411

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

416 417 418 419 420 421
;;;###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.")

422 423 424
;; 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
425

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

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

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
(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
459 460 461 462
  (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
  :group 'rmail
  :version "21.1"
  :type '(repeat (sexp :tag "Directive")))
463

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

467
;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
468 469 470 471
;; 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]+\\)?: *\\)*"
472
  "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
Karl Heuer's avatar
Karl Heuer committed
473

474 475 476 477 478
(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
479
(defvar rmail-inbox-list nil)
480 481
(put 'rmail-inbox-list 'permanent-local t)

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

485 486 487 488 489 490
(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
491 492 493
;; Message counters and markers.  Deleted flags.

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

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

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

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

505 506 507 508
(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.")
509
(put 'rmail-msgref-vector 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
510

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

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

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

521 522 523 524
(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
525 526 527 528
;; `Sticky' default variables.

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

531
;; 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
532
(defvar rmail-last-multi-labels nil)
533

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

537 538 539 540 541 542 543 544
(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)
545 546 547 548 549
(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
550

551 552 553 554 555 556 557 558 559 560 561 562 563
;; 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
564 565 566 567 568
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."
569 570
  :type '(choice (const :tag "on" t)
		 (const :tag "off" nil)
571
		 (other :tag "when asked" ask))
572 573
  :group 'rmail)

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

577 578
;;;###autoload
(defvar rmail-show-mime-function nil
579 580 581 582 583 584 585
  "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.
586
This function is called if `rmail-enable-mime' or
587
`rmail-enable-mime-composing' is non-nil.
588 589 590 591
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.")

592 593 594 595 596 597 598 599
;;;###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.")

600 601 602 603 604 605 606 607 608 609 610
;;;###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.
611
It is called with three arguments MSG, REGEXP, and LIMIT, where
612 613 614
MSG is the message number,
REGEXP is the regular expression,
LIMIT is the position specifying the end of header.")
615 616 617

;;;###autoload
(defvar rmail-mime-feature 'rmail-mime
618 619
  "Feature to require to load MIME support in Rmail.
When starting Rmail, if `rmail-enable-mime' is non-nil,
620 621 622 623
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/>.")
624 625 626 627 628 629 630 631 632 633 634 635 636

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

643

Jim Blandy's avatar
Jim Blandy committed
644 645 646 647
;;; 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
648
(defvar rmail-unix-mail-delimiter
Jim Blandy's avatar
Jim Blandy committed
649
  (let ((time-zone-regexp
650
	 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
Jim Blandy's avatar
Jim Blandy committed
651 652 653 654 655 656
		 "\\|[-+]?[0-9][0-9][0-9][0-9]"
		 "\\|"
		 "\\) *")))
    (concat
     "From "

657 658 659 660 661 662 663 664 665 666 667
     ;; 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'.
668 669 670 671 672
     ;; 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.
673 674 675
     ;; 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.
676
     "\\([^\0-\b\n-\r\^?].*\\)? "
Jim Blandy's avatar
Jim Blandy committed
677 678

     ;; The time the message was sent.
679 680 681 682
     "\\([^\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
683 684 685 686 687 688

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

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

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

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

     "\n"))
  nil)

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

726 727 728
;; 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
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
  `(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
748 749 750

;;;; *** Rmail Mode ***

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

754 755
(defvar rmail-enable-multibyte nil)

756 757 758 759 760 761 762 763 764

(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
765 766 767 768 769 770 771 772
       (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))
773 774 775
       (setq rmail-enable-mime nil)))))


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

783 784 785
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
786 787 788
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
789
  (interactive (if current-prefix-arg
790
		   (list (read-file-name "Run rmail on RMAIL file: "))))
791
  (rmail-require-mime-maybe)
Roland McGrath's avatar
Roland McGrath committed
792
  (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
793 794 795
	 ;; 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))
796
	 ;; This binding is necessary because we must decide if we
797 798
	 ;; need code conversion while the buffer is unibyte
	 ;; (i.e. enable-multibyte-characters is nil).
799
         (rmail-enable-multibyte
800
          (if existed
801 802
	      (with-current-buffer existed enable-multibyte-characters)
            (default-value 'enable-multibyte-characters)))
803 804 805 806 807 808 809
	 ;; 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))
810
	 run-mail-hook msg-shown)
Roland McGrath's avatar
Roland McGrath committed
811 812
    ;; Like find-file, but in the case where a buffer existed
    ;; and the file was reverted, recompute the message-data.
813 814 815 816 817
    ;; 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
818 819
    (if (and existed (not (verify-visited-file-modtime existed)))
	(progn
820
	  (find-file file-name)
821 822
	  (if (and (verify-visited-file-modtime existed)
		   (eq major-mode 'rmail-mode))
Roland McGrath's avatar
Roland McGrath committed
823 824
	      (progn (rmail-forget-messages)
		     (rmail-set-message-counters))))
825
      (switch-to-buffer
826 827
       (let ((enable-local-variables nil))
	 (find-file-noselect file-name))))
828
    (if (eq major-mode 'rmail-edit-mode)
829
	(error "Exit Rmail Edit mode before getting new mail"))
Roland McGrath's avatar
Roland McGrath committed
830 831 832
    (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)
833 834 835
	    (progn (rmail-mode-2)
		   (setq run-mail-hook t)))
      (setq run-mail-hook t)
Roland McGrath's avatar
Roland McGrath committed
836 837 838
      (rmail-mode-2)
      ;; Convert all or part to Babyl file if possible.
      (rmail-convert-file)
839
      (goto-char (point-max)))
840 841 842 843 844
    ;; 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))
845 846
    ;; If necessary, scan to find all the messages.
    (rmail-maybe-set-message-counters)
847
    (unwind-protect
848 849 850
	(unless (and (not file-name-arg)
		     (rmail-get-new-mail))
	  (rmail-show-message (rmail-first-unseen-message)))
851 852 853 854 855
      (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
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873

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

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

Roland McGrath's avatar
Roland McGrath committed
876 877 878 879 880 881 882 883 884 885 886 887 888
(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")))
889 890 891
	  ((equal (point-min) (point-max))
	   ;; Empty RMAIL file.  Just insert the header.
	   (rmail-insert-rmail-file-header))
Roland McGrath's avatar
Roland McGrath committed
892
	  (t
893
	   ;; Non-empty file in non-RMAIL format.  Add header and convert.
Roland McGrath's avatar
Roland McGrath committed
894 895 896 897 898 899
	   (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
900 901
	    (save-excursion
	      (goto-char (point-max))
902 903
	      (search-backward "\n\^_")
	      (forward-char 2)
904
	      (looking-at "\n*From ")))
Roland McGrath's avatar
Roland McGrath committed
905 906
	(let ((buffer-read-only nil))
	  (message "Converting to Babyl format...")
907 908 909 910 911
	  ;; 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)
912
	  (narrow-to-region (point) (point-max))
Roland McGrath's avatar
Roland McGrath committed
913
	  (rmail-convert-to-babyl-format)
914 915 916 917 918
	  (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
919 920 921

(defun rmail-insert-rmail-file-header ()
  (let ((buffer-read-only nil))
922 923
    ;; -*-rmail-*- is here so that visiting the file normally
    ;; recognizes it as an Rmail file.
Roland McGrath's avatar
Roland McGrath committed
924 925 926 927 928 929 930
    (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
931
;; Decode Babyl formatted part at the head of current buffer by
932
;; rmail-file-coding-system, or if it is nil, do auto conversion.
933 934 935 936

(defun rmail-decode-babyl-format ()
  (let ((modifiedp (buffer-modified-p))
	(buffer-read-only nil)
937
	(coding-system rmail-file-coding-system)
938
	from to)
939
    (goto-char (point-min))
940
    (search-forward "\n\^_" nil t)	; Skip BABYL header.
941 942 943 944
    (setq from (point))
    (goto-char (point-max))
    (search-backward "\n\^_" from 'mv)
    (setq to (point))
945 946
    (unless (and coding-system
		 (coding-system-p coding-system))
947 948 949 950 951 952 953 954 955 956
      (setq coding-system
	    ;; Emacs 21.1 and later writes RMAIL files in emacs-mule, 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), but still allow detection of other
	    ;; encodings if emacs-mule won't fit.  The call to
	    ;; detect-coding-with-priority below achieves that.
	    (car (detect-coding-with-priority
		  from to
		  '((coding-category-emacs-mule . emacs-mule))))))
957 958
    (unless (memq coding-system
		  '(undecided undecided-unix))
959
      (set-buffer-modified-p t)		; avoid locking when decoding
960 961
      (let ((buffer-undo-list t))
	(decode-coding-region from to coding-system))
962
      (setq coding-system last-coding-system-used))
963 964 965 966
    (set-buffer-modified-p modifiedp)
    (setq buffer-file-coding-system nil)
    (setq save-buffer-coding-system
	  (or coding-system 'undecided))))
967

968
(defvar rmail-mode-map nil)
Roland McGrath's avatar
Roland McGrath committed
969 970 971 972
(if rmail-mode-map
    nil
  (setq rmail-mode-map (make-keymap))
  (suppress-keymap rmail-mode-map)
973 974 975 976 977 978 979 980 981 982 983 984 985
  (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
986 987 988 989
  (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)
990 991 992 993 994 995 996 997 998 999 1000 1001 1002
  (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)
1003
;; I find I can't live without the default M-r command -- rms.
1004 1005 1006 1007 1008
;;  (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)
1009
  (define-key rmail-mode-map "w"      'rmail-output-body-to-file)
1010 1011
  (define-key rmail-mode-map "x"      'rmail-expunge)
  (define-key rmail-mode-map "."      'rmail-beginning-of-message)
1012
  (define-key rmail-mode-map "/"      'rmail-end-of-message)
1013 1014 1015 1016 1017
  (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)
1018 1019 1020 1021 1022 1023
  (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" 'rmail-sort-by-recipient)
  (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
  (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
1024
  (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-labels)
1025 1026
  (define-key rmail-mode-map "\C-c\C-n" 'rmail-next-same-subject)
  (define-key rmail-mode-map "\C-c\C-p" 'rmail-previous-same-subject)
1027
  )
1028 1029 1030