rmail.el 150 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,
4
;;   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Eric S. Raymond's avatar
Eric S. Raymond committed
5

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

Roland McGrath's avatar
Roland McGrath committed
9 10 11 12
;; 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
Eric S. Raymond's avatar
Eric S. Raymond committed
13
;; the Free Software Foundation; either version 2, or (at your option)
Roland McGrath's avatar
Roland McGrath committed
14 15 16 17 18 19 20 21
;; 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
22
;; along with GNU Emacs; see the file COPYING.  If not, write to the
Lute Kamstra's avatar
Lute Kamstra committed
23 24
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
Roland McGrath's avatar
Roland McGrath committed
25

26 27
;;; Commentary:

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

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

35 36 37 38 39 40 41
;; 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
42
(require 'mail-utils)
43
(eval-when-compile (require 'mule-util)) ; for detect-coding-with-priority
44

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)

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

63 64 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
(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)

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

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

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

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

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

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

(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)
148
	   (set-default symbol
149 150 151 152 153 154 155
			(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
156
  :version "22.1")
157

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

166 167 168 169
(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.
170 171 172
If you get an incorrect-password error that this expression does not match,
please report it with \\[report-emacs-bug].")

173
(defvar rmail-encoded-remote-password nil)
174

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

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

(defun rmail-probe (prog)
186 187
  "Determine what flavor of movemail PROG is.
We do this by executing it with `--version' and analyzing its output."
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
  (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 ()
206 207 208 209
  "Determine and return the file name of the `movemail' program.
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'."
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
  (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
mail URLs as the source mailbox;")

;;;###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))))

Roland McGrath's avatar
Roland McGrath committed
241
;;;###autoload
242
(defcustom rmail-dont-reply-to-names nil "\
243 244
*A regexp specifying addresses to prune from a reply message.
A value of nil means exclude your own email address as an address
245
plus whatever is specified by `rmail-default-dont-reply-to-names'."
246 247
  :type '(choice regexp (const :tag "Your Name" nil))
  :group 'rmail-reply)
Roland McGrath's avatar
Roland McGrath committed
248 249

;;;###autoload
250 251 252
(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
253
`rmail-dont-reply-to-names' explicitly.  (The other part of the default
254
value is the user's email address and name.)
Richard M. Stallman's avatar
Richard M. Stallman committed
255
It is useful to set this variable in the site customization file.")
Roland McGrath's avatar
Roland McGrath committed
256 257

;;;###autoload
258
(defcustom rmail-ignored-headers
259
  (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
260 261 262
	  "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
	  "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
	  "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
263
	  "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
264
	  "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
265 266 267 268
	  "\\|^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:"
269 270
	  "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
	  "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
271
	  "\\|^mbox-line:\\|^cancel-lock:\\|^DomainKey-Signature:"
272 273 274
	  "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"

	  "\\|^x-.*:")
275
  "*Regexp to match header fields that Rmail should normally hide.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
\(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.

291 292 293 294 295 296
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."
297 298
  :type 'regexp
  :group 'rmail-headers)
Roland McGrath's avatar
Roland McGrath committed
299

300
;;;###autoload
301
(defcustom rmail-displayed-headers nil
302 303
  "*Regexp to match Header fields that Rmail should display.
If nil, display all header fields except those matched by
304 305 306
`rmail-ignored-headers'."
  :type '(choice regexp (const :tag "All"))
  :group 'rmail-headers)
307

308
;;;###autoload
309
(defcustom rmail-retry-ignored-headers "^x-authentication-warning:" "\
310 311 312
*Headers that should be stripped when retrying a failed message."
  :type '(choice regexp (const nil :tag "None"))
  :group 'rmail-headers)
313

314
;;;###autoload
315
(defcustom rmail-highlighted-headers "^From:\\|^Subject:" "\
316
*Regexp to match Header fields that Rmail should normally highlight.
317
A value of nil means don't highlight.
318 319 320
See also `rmail-highlight-face'."
  :type 'regexp
  :group 'rmail-headers)
321

322 323 324 325 326 327
(defface rmail-highlight
  '((t :default highlight))
  "Face to use for highlighting the most important header fields."
  :group 'rmail-headers
  :version "22.1")

328
;;;###autoload
329
(defcustom rmail-highlight-face 'rmail-highlight "\
330 331 332 333
*Face used by Rmail for highlighting headers."
  :type '(choice (const :tag "Default" nil)
		 face)
  :group 'rmail-headers)
334

Roland McGrath's avatar
Roland McGrath committed
335
;;;###autoload
336 337 338 339
(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
340 341

;;;###autoload
342
(defcustom rmail-primary-inbox-list nil "\
343
*List of files which are inboxes for user's primary mail file `~/RMAIL'.
344
nil means the default, which is (\"/usr/spool/mail/$USER\")
345
\(the name varies depending on the operating system,
346
and the value of the environment variable MAIL overrides it)."
347 348 349
  ;; Don't use backquote here, because we don't want to need it
  ;; at load time.
  :type (list 'choice '(const :tag "Default" nil)
350 351 352
	      (list 'repeat ':value (list (or (getenv "MAIL")
					      (concat "/var/spool/mail/"
						      (getenv "USER"))))
353
		    'file))
354 355
  :group 'rmail-retrieve
  :group 'rmail-files)
Roland McGrath's avatar
Roland McGrath committed
356

357
;;;###autoload
358
(defcustom rmail-mail-new-frame nil
359 360 361
  "*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."
362 363
  :type 'boolean
  :group 'rmail-reply)
364

365
;;;###autoload
366 367 368 369
(defcustom rmail-secondary-file-directory "~/"
  "*Directory for additional secondary Rmail files."
  :type 'directory
  :group 'rmail-files)
370
;;;###autoload
371 372 373 374
(defcustom rmail-secondary-file-regexp "\\.xmail$"
  "*Regexp for which files are secondary Rmail files."
  :type 'regexp
  :group 'rmail-files)
375

376
;;;###autoload
377
(defcustom rmail-confirm-expunge 'y-or-n-p
378 379 380 381 382 383 384
  "*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)

385 386 387 388 389 390 391 392 393
;;;###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
394 395 396
(defcustom rmail-show-message-hook nil
  "List of functions to call when Rmail displays a message."
  :type 'hook
397
  :options '(goto-address)
398
  :group 'rmail)
399

400 401 402 403
;;;###autoload
(defvar rmail-quit-hook nil
  "List of functions to call when quitting out of Rmail.")

404 405 406 407 408 409
;;;###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.")

410 411 412
;; 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
413

414
(defvar rmail-mmdf-delim1 "^\001\001\001\001\n"
415
  "Regexp marking the start of an mmdf message.")
416
(defvar rmail-mmdf-delim2 "^\001\001\001\001\n"
417
  "Regexp marking the end of an mmdf message.")
Roland McGrath's avatar
Roland McGrath committed
418

419
(defcustom rmail-message-filter nil
420 421
  "If non-nil, a filter function for new messages in RMAIL.
Called with region narrowed to the message, including headers,
422 423 424
before obeying `rmail-ignored-headers'."
  :group 'rmail-headers
  :type 'function)
Roland McGrath's avatar
Roland McGrath committed
425

426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
(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
447 448 449 450
  (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
  :group 'rmail
  :version "21.1"
  :type '(repeat (sexp :tag "Directive")))
451

452 453 454
(defvar rmail-reply-prefix "Re: "
  "String to prepend to Subject line when replying to a message.")

455
;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
456 457 458 459
;; 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]+\\)?: *\\)*"
460
  "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
Karl Heuer's avatar
Karl Heuer committed
461

462 463 464 465 466
(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
467
(defvar rmail-inbox-list nil)
468 469
(put 'rmail-inbox-list 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
470
(defvar rmail-keywords nil)
471
(put 'rmail-keywords 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
472

473 474 475 476 477 478
(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
479 480 481
;; Message counters and markers.  Deleted flags.

(defvar rmail-current-message nil)
482 483
(put 'rmail-current-message 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
484
(defvar rmail-total-messages nil)
485 486
(put 'rmail-total-messages 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
487
(defvar rmail-message-vector nil)
488 489
(put 'rmail-message-vector 'permanent-local t)

Roland McGrath's avatar
Roland McGrath committed
490
(defvar rmail-deleted-vector nil)
491 492
(put 'rmail-deleted-vector 'permanent-local t)

493 494 495 496
(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.")
497
(put 'rmail-msgref-vector 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
498

499
(defvar rmail-overlay-list nil)
500
(put 'rmail-overlay-list 'permanent-local t)
501

Roland McGrath's avatar
Roland McGrath committed
502 503 504
;; These are used by autoloaded rmail-summary.

(defvar rmail-summary-buffer nil)
505
(put 'rmail-summary-buffer 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
506
(defvar rmail-summary-vector nil)
507
(put 'rmail-summary-vector 'permanent-local t)
Roland McGrath's avatar
Roland McGrath committed
508

509 510 511 512
(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
513 514 515 516
;; `Sticky' default variables.

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

519
;; 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
520
(defvar rmail-last-multi-labels nil)
521

522
(defvar rmail-last-regexp nil)
523 524
(put 'rmail-last-regexp 'permanent-local t)

525 526 527 528 529 530 531 532
(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)
533 534 535 536 537
(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
538

539 540 541 542 543 544 545 546 547 548 549 550 551
;; 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
552 553 554 555 556
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."
557 558
  :type '(choice (const :tag "on" t)
		 (const :tag "off" nil)
559
		 (other :tag "when asked" ask))
560 561
  :group 'rmail)

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

565 566
;;;###autoload
(defvar rmail-show-mime-function nil
567 568 569 570 571 572 573
  "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.
574
This function is called if `rmail-enable-mime' or
575
`rmail-enable-mime-composing' is non-nil.
576 577 578 579
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.")

580 581 582 583 584 585 586 587
;;;###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.")

588 589 590 591 592 593 594 595 596 597 598
;;;###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.
599
It is called with three arguments MSG, REGEXP, and LIMIT, where
600 601 602
MSG is the message number,
REGEXP is the regular expression,
LIMIT is the position specifying the end of header.")
603 604 605

;;;###autoload
(defvar rmail-mime-feature 'rmail-mime
606 607
  "Feature to require to load MIME support in Rmail.
When starting Rmail, if `rmail-enable-mime' is non-nil,
608 609 610 611
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/>.")
612 613 614 615 616 617 618 619 620 621 622 623 624

;;;###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
625
  "^content-type:[ ]*text/plain;[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?"
626 627 628
  "Regexp to match MIME-charset specification in a header of message.
The first parenthesized expression should match the MIME-charset name.")

629

Jim Blandy's avatar
Jim Blandy committed
630 631 632 633
;;; 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
634
(defvar rmail-unix-mail-delimiter
Jim Blandy's avatar
Jim Blandy committed
635
  (let ((time-zone-regexp
636
	 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
Jim Blandy's avatar
Jim Blandy committed
637 638 639 640 641 642
		 "\\|[-+]?[0-9][0-9][0-9][0-9]"
		 "\\|"
		 "\\) *")))
    (concat
     "From "

643 644 645 646 647 648 649 650 651 652 653
     ;; 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'.
654 655 656 657 658
     ;; 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.
659 660 661
     ;; 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.
662
     "\\([^\0-\b\n-\r\^?].*\\)? "
Jim Blandy's avatar
Jim Blandy committed
663 664

     ;; The time the message was sent.
665 666 667 668
     "\\([^\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
669 670 671 672 673 674

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

     ;; The year.
675
     " \\([0-9][0-9]+\\) *"
Jim Blandy's avatar
Jim Blandy committed
676 677 678 679

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

Karl Heuer's avatar
Karl Heuer committed
680 681
     ;; Old uucp cruft.
     "\\(remote from .*\\)?"
Jim Blandy's avatar
Jim Blandy committed
682 683 684 685

     "\n"))
  nil)

686
(defvar rmail-font-lock-keywords
687
  ;; These are all matched case-insensitively.
688 689
  (eval-when-compile
    (let* ((cite-chars "[>|}]")
690
	   (cite-prefix "a-z")
691
	   (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
692 693
      (list '("^\\(From\\|Sender\\|Resent-From\\):"
	      . font-lock-function-name-face)
694 695
	    '("^Reply-To:.*$" . font-lock-function-name-face)
	    '("^Subject:" . font-lock-comment-face)
696
	    '("^X-Spam-Status:" . font-lock-keyword-face)
697 698 699 700 701
	    '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
	      . font-lock-keyword-face)
	    ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
	    `(,cite-chars
	      (,(concat "\\=[ \t]*"
702 703
			"\\(\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
			"\\(" cite-chars "[ \t]*\\)\\)+\\)"
704 705
			"\\(.*\\)")
	       (beginning-of-line) (end-of-line)
706 707
	       (1 font-lock-comment-delimiter-face nil t)
	       (5 font-lock-comment-face nil t)))
708
	    '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
709 710 711
	      . font-lock-string-face))))
  "Additional expressions to highlight in Rmail mode.")

712 713 714
;; 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
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
  `(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
734 735 736

;;;; *** Rmail Mode ***

737 738 739
;; This variable is dynamically bound.  The defvar is here to placate
;; the byte compiler.

740 741
(defvar rmail-enable-multibyte nil)

742 743 744 745 746 747 748 749 750

(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
751 752 753 754 755 756 757 758
       (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))
759 760 761
       (setq rmail-enable-mime nil)))))


Roland McGrath's avatar
Roland McGrath committed
762 763 764
;;;###autoload
(defun rmail (&optional file-name-arg)
  "Read and edit incoming mail.
765
Moves messages into file named by `rmail-file-name' (a babyl format file)
Roland McGrath's avatar
Roland McGrath committed
766 767 768
 and edits that file in RMAIL Mode.
Type \\[describe-mode] once editing that file, for a list of RMAIL commands.

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

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

860 861
;; This calls rmail-decode-babyl-format if the file is already Babyl.

Roland McGrath's avatar
Roland McGrath committed
862 863 864 865 866 867 868 869 870 871 872 873 874
(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")))
875 876 877
	  ((equal (point-min) (point-max))
	   ;; Empty RMAIL file.  Just insert the header.
	   (rmail-insert-rmail-file-header))
Roland McGrath's avatar
Roland McGrath committed
878
	  (t
879
	   ;; Non-empty file in non-RMAIL format.  Add header and convert.
Roland McGrath's avatar
Roland McGrath committed
880 881 882 883 884 885
	   (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
886 887
	    (save-excursion
	      (goto-char (point-max))
888 889
	      (search-backward "\n\^_")
	      (forward-char 2)
890
	      (looking-at "\n*From ")))
Roland McGrath's avatar
Roland McGrath committed
891 892
	(let ((buffer-read-only nil))
	  (message "Converting to Babyl format...")
893 894 895 896 897
	  ;; 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)
898
	  (narrow-to-region (point) (point-max))
Roland McGrath's avatar
Roland McGrath committed
899
	  (rmail-convert-to-babyl-format)
900 901 902 903 904
	  (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
905 906 907

(defun rmail-insert-rmail-file-header ()
  (let ((buffer-read-only nil))
908 909
    ;; -*-rmail-*- is here so that visiting the file normally
    ;; recognizes it as an Rmail file.
Roland McGrath's avatar
Roland McGrath committed
910 911 912 913 914 915 916
    (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
917
;; Decode Babyl formatted part at the head of current buffer by
918
;; rmail-file-coding-system, or if it is nil, do auto conversion.
919 920 921 922

(defun rmail-decode-babyl-format ()
  (let ((modifiedp (buffer-modified-p))
	(buffer-read-only nil)
923
	(coding-system rmail-file-coding-system)
924
	from to)
925
    (goto-char (point-min))
926
    (search-forward "\n\^_" nil t)	; Skip BABYL header.
927 928 929 930
    (setq from (point))
    (goto-char (point-max))
    (search-backward "\n\^_" from 'mv)
    (setq to (point))
931 932
    (unless (and coding-system
		 (coding-system-p coding-system))
933 934 935 936 937 938 939 940 941 942
      (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))))))
943 944
    (unless (memq coding-system
		  '(undecided undecided-unix))
945
      (set-buffer-modified-p t)		; avoid locking when decoding
946 947
      (let ((buffer-undo-list t))
	(decode-coding-region from to coding-system))
948
      (setq coding-system last-coding-system-used))
949 950 951 952
    (set-buffer-modified-p modifiedp)
    (setq buffer-file-coding-system nil)
    (setq save-buffer-coding-system
	  (or coding-system 'undecided))))
953

954
(defvar rmail-mode-map nil)
Roland McGrath's avatar
Roland McGrath committed
955 956 957 958
(if rmail-mode-map
    nil
  (setq rmail-mode-map (make-keymap))
  (suppress-keymap rmail-mode-map)
959 960 961 962 963 964 965 966 967 968 969 970 971
  (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
972 973 974 975
  (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)
976 977 978 979 980 981 982 983 984 985 986 987 988
  (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)
989
;; I find I can't live without the default M-r command -- rms.
990 991 992 993 994
;;  (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)
995
  (define-key rmail-mode-map "w"      'rmail-output-body-to-file)
996 997
  (define-key rmail-mode-map "x"      'rmail-expunge)
  (define-key rmail-mode-map "."      'rmail-beginning-of-message)
998
  (define-key rmail-mode-map "/"      'rmail-end-of-message)
999 1000 1001 1002 1003
  (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)
1004 1005 1006 1007 1008 1009
  (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)
1010
  (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-labels)
1011 1012
  (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)
1013
  )
1014 1015 1016 1017 1018 1019

(define-key rmail-mode-map [menu-bar] (make-sparse-keymap))

(define-key rmail-mode-map [menu-bar classify]
  (cons "Classify" (make-sparse-keymap "Classify")))

1020
(define-key rmail-mode-map [menu-bar classify input-menu]
1021
  nil)
1022 1023

(define-key rmail-mode-map [menu-bar classify output-menu]
1024
  nil)
1025

1026 1027 1028
(define-key rmail-mode-map [menu-bar classify output-body]
  '("Output body to file..." . rmail-output-body-to-file))

1029
(define-key rmail-mode-map [menu-bar classify output-inbox]
1030
  '("Output (inbox)..." . rmail-output))
1031 1032

(define-key rmail-mode-map [menu-bar classify output]
1033
  '("Output (Rmail)..." . rmail-output-to-rmail-file))
1034 1035

(define-key rmail-mode-map [menu-bar classify kill-label]
1036
  '("Kill Label..." . rmail-kill-label))
1037 1038

(define-key rmail-mode-map [menu-bar classify add-label]
1039
  '("Add Label..." . rmail-add-label))
1040 1041 1042 1043

(define-key rmail-mode-map [menu-bar summary]
  (cons "Summary" (make-sparse-keymap "Summary")))

1044 1045 1046
(define-key rmail-mode-map [menu-bar summary senders]
  '("By Senders..." . rmail-summary-by-senders))

1047
(define-key rmail-mode-map [menu-bar summary labels]
1048
  '("By Labels..." . rmail-summary-by-labels))
<