* mail/rmail.el (rmail-yank-current-message): Leave point at correct position.
[emacs.git] / lisp / mail / rmail.el
blob18f89737f199e9d83b71925564af6bf2b1f69adc
1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
3 ;; Copyright (C) 1985-1988, 1993-1998, 2000-2012
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: mail
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;;; Code:
28 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
29 ;; New features include attribute and keyword support, message
30 ;; selection by dispatch table, summary by attributes and keywords,
31 ;; expunging by dispatch table, sticky options for file commands.
33 ;; Extended by Bob Weiner of Motorola
34 ;; New features include: rmail and rmail-summary buffers remain
35 ;; synchronized and key bindings basically operate the same way in both
36 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
37 ;; variable, and a bury rmail buffer (wipe) command.
40 (require 'mail-utils)
41 (require 'rfc2047)
43 (defconst rmail-attribute-header "X-RMAIL-ATTRIBUTES"
44 "The header that stores the Rmail attribute data.")
46 (defconst rmail-keyword-header "X-RMAIL-KEYWORDS"
47 "The header that stores the Rmail keyword data.")
49 ;;; Attribute indexes
51 (defconst rmail-answered-attr-index 0
52 "The index for the `answered' attribute.")
54 (defconst rmail-deleted-attr-index 1
55 "The index for the `deleted' attribute.")
57 (defconst rmail-edited-attr-index 2
58 "The index for the `edited' attribute.")
60 (defconst rmail-filed-attr-index 3
61 "The index for the `filed' attribute.")
63 (defconst rmail-retried-attr-index 4
64 "The index for the `retried' attribute.")
66 (defconst rmail-forwarded-attr-index 5
67 "The index for the `forwarded' attribute.")
69 (defconst rmail-unseen-attr-index 6
70 "The index for the `unseen' attribute.")
72 (defconst rmail-resent-attr-index 7
73 "The index for the `resent' attribute.")
75 (defconst rmail-attr-array
76 '[(?A "answered")
77 (?D "deleted")
78 (?E "edited")
79 (?F "filed")
80 (?R "retried")
81 (?S "forwarded")
82 (?U "unseen")
83 (?r "resent")]
84 "An array that provides a mapping between an attribute index,
85 its character representation and its display representation.")
87 (defvar deleted-head)
88 (defvar font-lock-fontified)
89 (defvar mail-abbrev-syntax-table)
90 (defvar mail-abbrevs)
91 (defvar messages-head)
92 (defvar total-messages)
93 (defvar tool-bar-map)
94 (defvar mail-encode-mml)
96 (defvar rmail-header-style 'normal
97 "The current header display style choice, one of
98 'normal (selected headers) or 'full (all headers).")
100 ;; rmail-spool-directory and rmail-file-name are defined in paths.el.
102 (defgroup rmail nil
103 "Mail reader for Emacs."
104 :group 'mail)
106 (defgroup rmail-retrieve nil
107 "Rmail retrieval options."
108 :prefix "rmail-"
109 :group 'rmail)
111 (defgroup rmail-files nil
112 "Rmail files."
113 :prefix "rmail-"
114 :group 'rmail)
116 (defgroup rmail-headers nil
117 "Rmail header options."
118 :prefix "rmail-"
119 :group 'rmail)
121 (defgroup rmail-reply nil
122 "Rmail reply options."
123 :prefix "rmail-"
124 :group 'rmail)
126 (defgroup rmail-summary nil
127 "Rmail summary options."
128 :prefix "rmail-"
129 :prefix "rmail-summary-"
130 :group 'rmail)
132 (defgroup rmail-output nil
133 "Output message to a file."
134 :prefix "rmail-output-"
135 :prefix "rmail-"
136 :group 'rmail)
138 (defgroup rmail-edit nil
139 "Rmail editing."
140 :prefix "rmail-edit-"
141 :group 'rmail)
143 (defcustom rmail-movemail-program nil
144 "If non-nil, the file name of the `movemail' program."
145 :group 'rmail-retrieve
146 :type '(choice (const nil) string))
148 (define-obsolete-variable-alias 'rmail-pop-password
149 'rmail-remote-password "22.1")
151 (defcustom rmail-remote-password nil
152 "Password to use when reading mail from a remote server.
153 This setting is ignored for mailboxes whose URL already contains a password."
154 :type '(choice (string :tag "Password")
155 (const :tag "Not Required" nil))
156 :group 'rmail-retrieve
157 :version "22.1")
159 (define-obsolete-variable-alias 'rmail-pop-password-required
160 'rmail-remote-password-required "22.1")
162 (defcustom rmail-remote-password-required nil
163 "Non-nil if a password is required when reading mail from a remote server."
164 :type 'boolean
165 :group 'rmail-retrieve
166 :version "22.1")
168 (defcustom rmail-movemail-flags nil
169 "List of flags to pass to movemail.
170 Most commonly used to specify `-g' to enable GSS-API authentication
171 or `-k' to enable Kerberos authentication."
172 :type '(repeat string)
173 :group 'rmail-retrieve
174 :version "20.3")
176 (defvar rmail-remote-password-error "invalid usercode or password\\|
177 unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
178 "Regular expression matching incorrect-password POP or IMAP server error
179 messages.
180 If you get an incorrect-password error that this expression does not match,
181 please report it with \\[report-emacs-bug].")
183 (defvar rmail-encoded-remote-password nil)
185 (defcustom rmail-preserve-inbox nil
186 "Non-nil means leave incoming mail in the user's inbox--don't delete it."
187 :type 'boolean
188 :group 'rmail-retrieve)
190 (defcustom rmail-movemail-search-path nil
191 "List of directories to search for movemail (in addition to `exec-path')."
192 :group 'rmail-retrieve
193 :type '(repeat (directory)))
195 (declare-function mail-dont-reply-to "mail-utils" (destinations))
196 (declare-function rmail-update-summary "rmailsum" (&rest ignore))
197 (declare-function rmail-mime-toggle-hidden "rmailmm" ())
199 (defun rmail-probe (prog)
200 "Determine what flavor of movemail PROG is.
201 We do this by executing it with `--version' and analyzing its output."
202 (with-temp-buffer
203 (let ((tbuf (current-buffer)))
204 (buffer-disable-undo tbuf)
205 (call-process prog nil tbuf nil "--version")
206 (if (not (buffer-modified-p tbuf))
207 ;; Should not happen...
209 (goto-char (point-min))
210 (cond
211 ((looking-at ".*movemail: invalid option")
212 'emacs) ;; Possibly...
213 ((looking-at "movemail (GNU Mailutils .*)")
214 'mailutils)
216 ;; FIXME:
217 'emacs))))))
219 (defun rmail-autodetect ()
220 "Determine the file name of the `movemail' program and return its flavor.
221 If `rmail-movemail-program' is non-nil, use it.
222 Otherwise, look for `movemail' in the directories in
223 `rmail-movemail-search-path', those in `exec-path', and `exec-directory'."
224 (if rmail-movemail-program
225 (rmail-probe rmail-movemail-program)
226 (catch 'scan
227 (dolist (dir (append rmail-movemail-search-path exec-path
228 (list exec-directory)))
229 (when (and dir (file-accessible-directory-p dir))
230 ;; Previously, this didn't have to work on Windows, because
231 ;; rmail-insert-inbox-text before r1.439 fell back to using
232 ;; (expand-file-name "movemail" exec-directory) and just
233 ;; assuming it would work.
234 ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2008-02/msg00087.html
235 (let ((progname (expand-file-name
236 (concat "movemail"
237 (if (memq system-type '(ms-dos windows-nt))
238 ".exe")) dir)))
239 (when (and (not (file-directory-p progname))
240 (file-executable-p progname))
241 (let ((x (rmail-probe progname)))
242 (when x
243 (setq rmail-movemail-program progname)
244 (throw 'scan x))))))))))
246 (defvar rmail-movemail-variant-in-use nil
247 "The movemail variant currently in use. Known variants are:
249 `emacs' Means any implementation, compatible with the native Emacs one.
250 This is the default;
251 `mailutils' Means GNU mailutils implementation, capable of handling full
252 mail URLs as the source mailbox.")
254 ;;;###autoload
255 (defun rmail-movemail-variant-p (&rest variants)
256 "Return t if the current movemail variant is any of VARIANTS.
257 Currently known variants are 'emacs and 'mailutils."
258 (when (not rmail-movemail-variant-in-use)
259 ;; Autodetect
260 (setq rmail-movemail-variant-in-use (rmail-autodetect)))
261 (not (null (member rmail-movemail-variant-in-use variants))))
263 ;; Call for effect, to set rmail-movemail-program (if not set by the
264 ;; user), and rmail-movemail-variant-in-use. Used by various functions.
265 ;; I'm not sure if M-x rmail is the only entry point to this package.
266 ;; If so, this can be moved there.
267 (rmail-movemail-variant-p)
269 ;;;###autoload
270 (defcustom rmail-user-mail-address-regexp nil
271 "Regexp matching user mail addresses.
272 If non-nil, this variable is used to identify the correspondent
273 when receiving new mail. If it matches the address of the sender,
274 the recipient is taken as correspondent of a mail.
275 If nil \(default value\), your `user-login-name' and `user-mail-address'
276 are used to exclude yourself as correspondent.
278 Usually you don't have to set this variable, except if you collect mails
279 sent by you under different user names.
280 Then it should be a regexp matching your mail addresses.
282 Setting this variable has an effect only before reading a mail."
283 :type '(choice (const :tag "None" nil) regexp)
284 :group 'rmail-retrieve
285 :version "21.1")
287 ;;;###autoload
288 (define-obsolete-variable-alias 'rmail-dont-reply-to-names
289 'mail-dont-reply-to-names "24.1")
291 ;; Prior to 24.1, this used to contain "\\`info-".
292 ;;;###autoload
293 (defvar rmail-default-dont-reply-to-names nil
294 "Regexp specifying part of the default value of `mail-dont-reply-to-names'.
295 This is used when the user does not set `mail-dont-reply-to-names'
296 explicitly.")
297 ;;;###autoload
298 (make-obsolete-variable 'rmail-default-dont-reply-to-names
299 'mail-dont-reply-to-names "24.1")
301 ;;;###autoload
302 (defcustom rmail-ignored-headers
303 (purecopy
304 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
305 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
306 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
307 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
308 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
309 "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
310 "\\|^content-transfer-encoding:\\|^x-coding-system:"
311 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
312 "\\|^precedence:\\|^mime-version:"
313 "\\|^list-owner:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
314 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
315 "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
316 "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
317 "\\|^mbox-line:\\|^cancel-lock:"
318 "\\|^DomainKey-Signature:\\|^dkim-signature:"
319 "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"
320 "\\|^x-.*:"))
321 "Regexp to match header fields that Rmail should normally hide.
322 \(See also `rmail-nonignored-headers', which overrides this regexp.)
323 This variable is used for reformatting the message header,
324 which normally happens once for each message,
325 when you view the message for the first time in Rmail.
326 To make a change in this variable take effect
327 for a message that you have already viewed,
328 go to that message and type \\[rmail-toggle-header] twice."
329 :type 'regexp
330 :group 'rmail-headers)
332 (defcustom rmail-nonignored-headers "^x-spam-status:"
333 "Regexp to match X header fields that Rmail should show.
334 This regexp overrides `rmail-ignored-headers'; if both this regexp
335 and that one match a certain header field, Rmail shows the field.
336 If this is nil, ignore all header fields in `rmail-ignored-headers'.
338 This variable is used for reformatting the message header,
339 which normally happens once for each message,
340 when you view the message for the first time in Rmail.
341 To make a change in this variable take effect
342 for a message that you have already viewed,
343 go to that message and type \\[rmail-toggle-header] twice."
344 :type '(choice (const nil) (regexp))
345 :group 'rmail-headers)
347 ;;;###autoload
348 (defcustom rmail-displayed-headers nil
349 "Regexp to match Header fields that Rmail should display.
350 If nil, display all header fields except those matched by
351 `rmail-ignored-headers'."
352 :type '(choice regexp (const :tag "All"))
353 :group 'rmail-headers)
355 ;;;###autoload
356 (defcustom rmail-retry-ignored-headers (purecopy "^x-authentication-warning:\\|^x-detected-operating-system:\\|^x-spam[-a-z]*:\\|content-type:\\|content-transfer-encoding:\\|mime-version:\\|message-id:")
357 "Headers that should be stripped when retrying a failed message."
358 :type '(choice regexp (const nil :tag "None"))
359 :group 'rmail-headers
360 :version "23.2") ; added x-detected-operating-system, x-spam
362 ;;;###autoload
363 (defcustom rmail-highlighted-headers (purecopy "^From:\\|^Subject:")
364 "Regexp to match Header fields that Rmail should normally highlight.
365 A value of nil means don't highlight. Uses the face `rmail-highlight'."
366 :type 'regexp
367 :group 'rmail-headers)
369 (defface rmail-highlight
370 '((t (:inherit highlight)))
371 "Face to use for highlighting the most important header fields.
372 The variable `rmail-highlighted-headers' specifies which headers."
373 :group 'rmail-headers
374 :version "22.1")
376 ;; This was removed in Emacs 23.1 with no notification, an unnecessary
377 ;; incompatible change.
378 (defcustom rmail-highlight-face 'rmail-highlight
379 "Face used by Rmail for highlighting headers."
380 ;; Note that nil doesn't actually mean use the default face, it
381 ;; means use either bold or highlight. It's not worth fixing this
382 ;; now that this is obsolete.
383 :type '(choice (const :tag "Default" nil)
384 face)
385 :group 'rmail-headers)
386 (make-obsolete-variable 'rmail-highlight-face
387 "customize the face `rmail-highlight' instead."
388 "23.2")
390 (defface rmail-header-name
391 '((t (:inherit font-lock-function-name-face)))
392 "Face to use for highlighting the header names.
393 The variable `rmail-font-lock-keywords' specifies which headers
394 get highlighted."
395 :group 'rmail-headers
396 :version "23.1")
398 (defcustom rmail-delete-after-output nil
399 "Non-nil means automatically delete a message that is copied to a file."
400 :type 'boolean
401 :group 'rmail-files)
403 ;;;###autoload
404 (defcustom rmail-primary-inbox-list nil
405 "List of files that are inboxes for your primary mail file `rmail-file-name'.
406 If this is nil, uses the environment variable MAIL. If that is
407 unset, uses a file named by the function `user-login-name' in the
408 directory `rmail-spool-directory' (whose value depends on the
409 operating system). For example, \"/var/mail/USER\"."
410 ;; Don't use backquote here, because we don't want to need it at load time.
411 ;; (That must be an old comment - it's dumped these days.)
412 :type (list 'choice '(const :tag "Default" nil)
413 (list 'repeat ':value (list (or (getenv "MAIL")
414 (concat rmail-spool-directory
415 (user-login-name))))
416 'file))
417 :group 'rmail-retrieve
418 :group 'rmail-files)
420 (defcustom rmail-mail-new-frame nil
421 "Non-nil means Rmail makes a new frame for composing outgoing mail.
422 This is handy if you want to preserve the window configuration of
423 the frame where you have the RMAIL buffer displayed."
424 :type 'boolean
425 :group 'rmail-reply)
427 ;;;###autoload
428 (defcustom rmail-secondary-file-directory (purecopy "~/")
429 "Directory for additional secondary Rmail files."
430 :type 'directory
431 :group 'rmail-files)
432 ;;;###autoload
433 (defcustom rmail-secondary-file-regexp (purecopy "\\.xmail$")
434 "Regexp for which files are secondary Rmail files."
435 :type 'regexp
436 :group 'rmail-files)
438 (defcustom rmail-confirm-expunge 'y-or-n-p
439 "Whether and how to ask for confirmation before expunging deleted messages.
440 The value, if non-nil is a function to call with a question (string)
441 as argument, to ask the user that question."
442 :type '(choice (const :tag "No confirmation" nil)
443 (const :tag "Confirm with y-or-n-p" y-or-n-p)
444 (const :tag "Confirm with yes-or-no-p" yes-or-no-p))
445 :version "21.1"
446 :group 'rmail-files)
447 (put 'rmail-confirm-expunge 'risky-local-variable t)
449 ;;;###autoload
450 (defvar rmail-mode-hook nil
451 "List of functions to call when Rmail is invoked.")
453 (defvar rmail-get-new-mail-hook nil
454 "List of functions to call when Rmail has retrieved new mail.")
456 ;;;###autoload
457 (defcustom rmail-show-message-hook nil
458 "List of functions to call when Rmail displays a message."
459 :type 'hook
460 :options '(goto-address)
461 :group 'rmail)
463 (defvar rmail-quit-hook nil
464 "List of functions to call when quitting out of Rmail.")
466 (defvar rmail-delete-message-hook nil
467 "List of functions to call when Rmail deletes a message.
468 When the hooks are called, the message has been marked deleted but is
469 still the current message in the Rmail buffer.")
471 ;; These may be altered by site-init.el to match the format of mmdf files
472 ;; delimiting used on a given host (delim1 and delim2 from the config
473 ;; files).
475 (defvar rmail-mmdf-delim1 "^\001\001\001\001\n"
476 "Regexp marking the start of an mmdf message.")
477 (defvar rmail-mmdf-delim2 "^\001\001\001\001\n"
478 "Regexp marking the end of an mmdf message.")
480 ;; FIXME Post-mbox, this is now unused.
481 ;; In Emacs-22, this was called:
482 ;; i) the very first time a message was shown.
483 ;; ii) when toggling the headers to the normal state, every time.
484 ;; It's not clear what it should do now, since there is nothing that
485 ;; records when a message is shown for the first time (unseen is not
486 ;; necessarily the same thing).
487 ;; See http://lists.gnu.org/archive/html/emacs-devel/2009-03/msg00013.html
488 (defcustom rmail-message-filter nil
489 "If non-nil, a filter function for new messages in RMAIL.
490 Called with region narrowed to the message, including headers,
491 before obeying `rmail-ignored-headers'."
492 :group 'rmail-headers
493 :type '(choice (const nil) function))
495 (make-obsolete-variable 'rmail-message-filter
496 "it is not used (try `rmail-show-message-hook')."
497 "23.1")
499 (defcustom rmail-automatic-folder-directives nil
500 "List of directives specifying how to automatically file messages.
501 Whenever Rmail shows a message in the folder that `rmail-file-name'
502 specifies, it calls `rmail-auto-file' to maybe file the message in
503 another folder according to this list. Messages that are already
504 marked as `filed', or are in different folders, are left alone.
506 Each element of the list is of the form:
508 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
510 FOLDERNAME is the name of a folder in which to put the message.
511 If FOLDERNAME is nil then Rmail deletes the message, and moves on to
512 the next. If FOLDERNAME is \"/dev/null\", Rmail deletes the message,
513 but does not move to the next.
515 FIELD is the name of a header field in the message, such as
516 \"subject\" or \"from\". A FIELD of \"to\" includes all text
517 from both the \"to\" and \"cc\" headers.
519 REGEXP is a regular expression to match (case-sensitively) against
520 the preceding specified FIELD.
522 There may be any number of FIELD/REGEXP pairs.
523 All pairs must match for a directive to apply to a message.
524 For a given message, Rmail applies only the first matching directive.
526 Examples:
527 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
528 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS.
530 :group 'rmail
531 :version "21.1"
532 :type '(repeat (sexp :tag "Directive")))
534 (defvar rmail-reply-prefix "Re: "
535 "String to prepend to Subject line when replying to a message.")
537 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
538 ;; This pattern should catch all the common variants.
539 ;; rms: I deleted the change to delete tags in square brackets
540 ;; because they mess up RT tags.
541 (defvar rmail-reply-regexp "\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
542 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
544 (defcustom rmail-display-summary nil
545 "If non-nil, Rmail always displays the summary buffer."
546 :group 'rmail-summary
547 :type 'boolean)
549 (defvar rmail-inbox-list nil)
550 (put 'rmail-inbox-list 'permanent-local t)
552 (defvar rmail-buffer nil
553 "The RMAIL buffer related to the current buffer.
554 In an RMAIL buffer, this holds the RMAIL buffer itself.
555 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
556 (put 'rmail-buffer 'permanent-local t)
558 (defvar rmail-was-converted nil
559 "Non-nil in an Rmail buffer that was just converted from Babyl format.")
560 (put 'rmail-was-converted 'permanent-local t)
562 (defvar rmail-seriously-modified nil
563 "Non-nil in an Rmail buffer that has been modified in a major way.")
564 (put 'rmail-seriously-modified 'permanent-local t)
566 ;; Message counters and markers. Deleted flags.
568 (defvar rmail-current-message nil
569 "Integer specifying the message currently being displayed in this folder.
570 Counts messages from 1 to `rmail-total-messages'. A value of 0
571 means there are no messages in the folder.")
572 (put 'rmail-current-message 'permanent-local t)
574 (defvar rmail-total-messages nil
575 "Integer specifying the total number of messages in this folder.
576 Includes deleted messages.")
577 (put 'rmail-total-messages 'permanent-local t)
579 (defvar rmail-message-vector nil
580 "Vector of markers specifying the start and end of each message.
581 Element N and N+1 specify the start and end of message N.")
582 (put 'rmail-message-vector 'permanent-local t)
584 (defvar rmail-deleted-vector nil
585 "A string of length `rmail-total-messages' plus one.
586 Character N is either a space or \"D\", according to whether
587 message N is deleted or not.")
588 (put 'rmail-deleted-vector 'permanent-local t)
590 (defvar rmail-msgref-vector nil
591 "In an Rmail buffer, a vector whose Nth element is a list (N).
592 When expunging renumbers messages, these lists are modified
593 by substituting the new message number into the existing list.")
594 (put 'rmail-msgref-vector 'permanent-local t)
596 (defvar rmail-overlay-list nil)
597 (put 'rmail-overlay-list 'permanent-local t)
599 ;; These are used by autoloaded rmail-summary.
601 (defvar rmail-summary-buffer nil)
602 (put 'rmail-summary-buffer 'permanent-local t)
603 (defvar rmail-summary-vector nil
604 "In an Rmail buffer, vector of (newline-terminated) strings.
605 Element N specifies the summary line for message N+1.")
606 (put 'rmail-summary-vector 'permanent-local t)
608 ;; Rmail buffer swapping variables.
610 (defvar rmail-buffer-swapped nil
611 "If non-nil, `rmail-buffer' is swapped with `rmail-view-buffer'.")
612 (make-variable-buffer-local 'rmail-buffer-swapped)
613 (put 'rmail-buffer-swapped 'permanent-local t)
615 (defvar rmail-view-buffer nil
616 "Buffer which holds RMAIL message for MIME displaying.")
617 (make-variable-buffer-local 'rmail-view-buffer)
618 (put 'rmail-view-buffer 'permanent-local t)
620 ;; `Sticky' default variables.
622 ;; Last individual label specified to a or k.
623 (defvar rmail-last-label nil)
625 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
626 (defvar rmail-last-multi-labels nil)
628 (defvar rmail-last-regexp nil)
629 (put 'rmail-last-regexp 'permanent-local t)
631 (defcustom rmail-default-file "~/xmail"
632 "Default file name for \\[rmail-output]."
633 :type 'file
634 :group 'rmail-files)
635 (defcustom rmail-default-body-file "~/mailout"
636 "Default file name for \\[rmail-output-body-to-file]."
637 :type 'file
638 :group 'rmail-files
639 :version "20.3")
641 ;; Mule and MIME related variables.
643 ;;;###autoload
644 (defvar rmail-file-coding-system nil
645 "Coding system used in RMAIL file.
647 This is set to nil by default.")
649 (defcustom rmail-enable-mime t
650 "If non-nil, RMAIL automatically displays decoded MIME messages.
651 For this to work, the feature specified by `rmail-mime-feature' must
652 be available."
653 :type 'boolean
654 :version "23.3"
655 :group 'rmail)
657 (defcustom rmail-enable-mime-composing t
658 "If non-nil, use `rmail-insert-mime-forwarded-message-function' to forward."
659 :type 'boolean
660 :version "24.1" ; nil -> t
661 :group 'rmail)
663 (defvar rmail-show-mime-function nil
664 "Function of no argument called to show a decoded MIME message.
665 This function is called when `rmail-enable-mime' is non-nil.
666 The package providing MIME support should set this.")
668 ;;;###autoload
669 (defvar rmail-insert-mime-forwarded-message-function nil
670 "Function to insert a message in MIME format so it can be forwarded.
671 This function is called if `rmail-enable-mime' and
672 `rmail-enable-mime-composing' are non-nil.
673 It is called with one argument FORWARD-BUFFER, which is a
674 buffer containing the message to forward. The current buffer
675 is the outgoing mail buffer.")
677 (defvar rmail-insert-mime-resent-message-function nil
678 "Function to insert a message in MIME format so it can be resent.
679 This function is called by `rmail-resend' if `rmail-enable-mime' is non-nil.
680 It is called with one argument FORWARD-BUFFER, which is a
681 buffer containing the message to forward. The current buffer
682 is the outgoing mail buffer.")
684 ;; FIXME one might want to pass a LIMIT, as per
685 ;; rmail-search-mime-header-function.
686 (defvar rmail-search-mime-message-function nil
687 "Function to check if a regexp matches a MIME message.
688 This function is called by `rmail-search-message' if
689 `rmail-enable-mime' is non-nil. It is called (with point at the
690 start of the message) with two arguments MSG and REGEXP, where
691 MSG is the message number, REGEXP is the regular expression.")
693 (defvar rmail-search-mime-header-function nil
694 "Function to check if a regexp matches a header of MIME message.
695 This function is called by `rmail-message-regexp-p-1' if
696 `rmail-enable-mime' is non-nil. It is called (with point at the
697 start of the header) with three arguments MSG, REGEXP, and LIMIT,
698 where MSG is the message number, REGEXP is the regular
699 expression, LIMIT is the position specifying the end of header.")
701 (defvar rmail-mime-feature 'rmailmm
702 "Feature to require for MIME support in Rmail.
703 When starting Rmail, if `rmail-enable-mime' is non-nil, this
704 feature is loaded with `require'. The default value is `rmailmm'.
706 The library should set the variable `rmail-show-mime-function'
707 to an appropriate value, and optionally also set
708 `rmail-search-mime-message-function',
709 `rmail-search-mime-header-function',
710 `rmail-insert-mime-forwarded-message-function', and
711 `rmail-insert-mime-resent-message-function'.")
713 ;; FIXME this is unused since 23.1.
714 (defvar rmail-decode-mime-charset t
715 "*Non-nil means a message is decoded by MIME's charset specification.
716 If this variable is nil, or the message has not MIME specification,
717 the message is decoded as normal way.
719 If the variable `rmail-enable-mime' is non-nil, this variable is
720 ignored, and all the decoding work is done by a feature specified by
721 the variable `rmail-mime-feature'.")
723 (make-obsolete-variable 'rmail-decode-mime-charset
724 "it does nothing." "23.1")
726 (defvar rmail-mime-charset-pattern
727 (concat "^content-type:[ \t]*text/plain;"
728 "\\(?:[ \t\n]*\\(?:format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
729 "[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?")
730 "Regexp to match MIME-charset specification in a header of message.
731 The first parenthesized expression should match the MIME-charset name.")
734 (defvar rmail-unix-mail-delimiter
735 (let ((time-zone-regexp
736 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
737 "\\|[-+]?[0-9][0-9][0-9][0-9]"
738 "\\|"
739 "\\) *")))
740 (concat
741 "From "
743 ;; Many things can happen to an RFC 822 mailbox before it is put into
744 ;; a `From' line. The leading phrase can be stripped, e.g.
745 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
746 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
747 ;; can be removed, e.g.
748 ;; From: joe@y.z (Joe K
749 ;; User)
750 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
751 ;; From: Joe User
752 ;; <joe@y.z>
753 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
754 ;; The mailbox can be removed or be replaced by white space, e.g.
755 ;; From: "Joe User"{space}{tab}
756 ;; <joe@y.z>
757 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
758 ;; where {space} and {tab} represent the Ascii space and tab characters.
759 ;; We want to match the results of any of these manglings.
760 ;; The following regexp rejects names whose first characters are
761 ;; obviously bogus, but after that anything goes.
762 "\\([^\0-\b\n-\r\^?].*\\)? "
764 ;; The time the message was sent.
765 "\\([^\0-\r \^?]+\\) +" ; day of the week
766 "\\([^\0-\r \^?]+\\) +" ; month
767 "\\([0-3]?[0-9]\\) +" ; day of month
768 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
770 ;; Perhaps a time zone, specified by an abbreviation, or by a
771 ;; numeric offset.
772 time-zone-regexp
774 ;; The year.
775 " \\([0-9][0-9]+\\) *"
777 ;; On some systems the time zone can appear after the year, too.
778 time-zone-regexp
780 ;; Old uucp cruft.
781 "\\(remote from .*\\)?"
783 "\n"))
784 "Regexp matching the delimiter of messages in UNIX mail format
785 \(UNIX From lines), minus the initial ^. Note that if you change
786 this expression, you must change the code in `rmail-nuke-pinhead-header'
787 that knows the exact ordering of the \\( \\) subexpressions.")
789 ;; FIXME the rmail-header-name headers ought to be customizable.
790 ;; It seems a bit arbitrary, for example, that all of the Date: line
791 ;; gets highlighted.
792 (defvar rmail-font-lock-keywords
793 ;; These are all matched case-insensitively.
794 (eval-when-compile
795 (let* ((cite-chars "[>|}]")
796 (cite-prefix "[:alpha:]")
797 (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
798 (list '("^\\(From\\|Sender\\|Resent-From\\):"
799 . 'rmail-header-name)
800 '("^\\(Mail-\\)?Reply-To:.*$" . 'rmail-header-name)
801 ;; FIXME Mail-Followup-To should probably be here too.
802 '("^Subject:" . 'rmail-header-name)
803 '("^X-Spam-Status:" . 'rmail-header-name)
804 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
805 . 'rmail-header-name)
806 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
807 `(,cite-chars
808 (,(concat "\\=[ \t]*"
809 "\\(\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
810 "\\(" cite-chars "[ \t]*\\)\\)+\\)"
811 "\\(.*\\)")
812 (beginning-of-line) (end-of-line)
813 (1 font-lock-comment-delimiter-face nil t)
814 (5 font-lock-comment-face nil t)))
815 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
816 . 'rmail-header-name))))
817 "Additional expressions to highlight in Rmail mode.")
819 ;; Rmail does not expect horizontal splitting. (Bug#2282)
820 (defun rmail-pop-to-buffer (&rest args)
821 "Like `pop-to-buffer', but with `split-width-threshold' set to nil."
822 (let (split-width-threshold)
823 (apply 'pop-to-buffer args)))
825 ;; Perform BODY in the summary buffer
826 ;; in such a way that its cursor is properly updated in its own window.
827 (defmacro rmail-select-summary (&rest body)
828 `(let ((total rmail-total-messages))
829 (if (rmail-summary-displayed)
830 (let ((window (selected-window)))
831 (save-excursion
832 (unwind-protect
833 (progn
834 (rmail-pop-to-buffer rmail-summary-buffer)
835 ;; rmail-total-messages is a buffer-local var
836 ;; in the rmail buffer.
837 ;; This way we make it available for the body
838 ;; even tho the rmail buffer is not current.
839 (let ((rmail-total-messages total))
840 ,@body))
841 (select-window window))))
842 (with-current-buffer rmail-summary-buffer
843 (let ((rmail-total-messages total))
844 ,@body)))
845 (rmail-maybe-display-summary)))
847 ;;;; *** Rmail Mode ***
849 (defun rmail-require-mime-maybe ()
850 "Require `rmail-mime-feature' if that is non-nil.
851 Signal an error and set `rmail-mime-feature' to nil if the feature
852 isn't provided."
853 (when rmail-enable-mime
854 (condition-case err
855 (require rmail-mime-feature)
856 (error
857 (display-warning
858 'rmail
859 (format "Although MIME support is requested
860 through `rmail-enable-mime' being non-nil, the required feature
861 `%s' (the value of `rmail-mime-feature')
862 is not available in the current session.
863 So, MIME support is turned off for the moment."
864 rmail-mime-feature)
865 :warning)
866 (setq rmail-enable-mime nil)))))
869 ;;;###autoload
870 (defun rmail (&optional file-name-arg)
871 "Read and edit incoming mail.
872 Moves messages into file named by `rmail-file-name' and edits that
873 file in RMAIL Mode.
874 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
876 May be called with file name as argument; then performs rmail editing on
877 that file, but does not copy any new mail into the file.
878 Interactively, if you supply a prefix argument, then you
879 have a chance to specify a file name with the minibuffer.
881 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
882 (interactive (if current-prefix-arg
883 (list (read-file-name "Run rmail on RMAIL file: "))))
884 (rmail-require-mime-maybe)
885 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
886 ;; Use find-buffer-visiting, not get-file-buffer, for those users
887 ;; who have find-file-visit-truename set to t.
888 (existed (find-buffer-visiting file-name))
889 run-mail-hook mail-buf msg-shown)
890 ;; Determine if an existing mail file has been changed behind the
891 ;; scene...
892 (if (and existed (not (verify-visited-file-modtime existed)))
893 ;; The mail file has been changed. Revisit it and reset the
894 ;; message state variables when in rmail mode.
895 (progn
896 (find-file file-name)
897 (when (and (verify-visited-file-modtime existed)
898 (eq major-mode 'rmail-mode))
899 (rmail-swap-buffers-maybe)
900 (rmail-set-message-counters)))
901 ;; The mail file is either unchanged or not visited. Visit it.
902 (switch-to-buffer
903 (let ((enable-local-variables nil)
904 ;; Force no-conversion by default, since that's what
905 ;; pre-mbox Rmail did with BABYL files (via
906 ;; auto-coding-regexp-alist).
907 (coding-system-for-read
908 (or coding-system-for-read 'no-conversion)))
909 (find-file-noselect file-name))))
910 ;; Ensure that the collection and view buffers are in sync and
911 ;; ensure that a message is not being edited.
912 (if (eq major-mode 'rmail-mode)
913 (rmail-swap-buffers-maybe))
914 (if (eq major-mode 'rmail-edit-mode)
915 (error "Exit Rmail Edit mode before getting new mail"))
916 (or (and existed (> (buffer-size) 0))
917 (setq run-mail-hook t))
918 ;; Ensure that the Rmail file is in mbox format, the buffer is in
919 ;; Rmail mode and has been scanned to find all the messages
920 ;; (setting the global message variables in the process).
921 (rmail-convert-file-maybe)
922 (unless (eq major-mode 'rmail-mode)
923 (rmail-mode-2))
924 (goto-char (point-max))
925 (rmail-maybe-set-message-counters)
926 (setq mail-buf rmail-buffer)
927 ;; Show the first unread message and process summary mode.
928 (unwind-protect
929 ;; Only get new mail when there is not a file name argument.
930 (unless file-name-arg
931 (setq msg-shown (rmail-get-new-mail)))
932 (progn
933 (set-buffer mail-buf)
934 (or msg-shown
935 (rmail-show-message (rmail-first-unseen-message)))
936 (if rmail-display-summary (rmail-summary))
937 (rmail-construct-io-menu)
938 (if run-mail-hook
939 (run-hooks 'rmail-mode-hook))))))
941 (defun rmail-convert-file-maybe ()
942 "Determine if the file needs to be converted to mbox format."
943 (widen)
944 (goto-char (point-min))
945 ;; Detect previous Babyl format files.
946 (let ((case-fold-search nil))
947 (cond ((looking-at "BABYL OPTIONS:")
948 ;; The file is Babyl version 5. Use unrmail to convert
949 ;; it.
950 (rmail-convert-babyl-to-mbox))
951 ((looking-at "Version: 5\n")
952 ;; Losing babyl file made by old version of Rmail. Fix the
953 ;; babyl file header and use unrmail to convert to mbox
954 ;; format.
955 (let ((buffer-read-only nil))
956 (insert "BABYL OPTIONS: -*- rmail -*-\n")
957 (rmail-convert-babyl-to-mbox)))
958 ((equal (point-min) (point-max))
959 (message "Empty Rmail file."))
960 ((looking-at "From "))
961 (t (error "Invalid mbox file")))))
963 (defun rmail-error-bad-format (&optional msgnum)
964 "Report that the buffer is not in the mbox file format.
965 MSGNUM, if present, indicates the malformed message."
966 (if msgnum
967 (error "Message %d is not a valid RFC2822 message" msgnum)
968 (error "Message is not a valid RFC2822 message")))
970 (defun rmail-convert-babyl-to-mbox ()
971 "Convert the mail file from Babyl version 5 to mbox.
972 This function also reinitializes local variables used by Rmail."
973 (let ((old-file (make-temp-file "rmail"))
974 (new-file (make-temp-file "rmail")))
975 (unwind-protect
976 (progn
977 (kill-all-local-variables)
978 (write-region (point-min) (point-max) old-file)
979 (unrmail old-file new-file)
980 (message "Replacing BABYL format with mbox format...")
981 (let ((inhibit-read-only t)
982 (coding-system-for-read 'raw-text)
983 (buffer-undo-list t))
984 (erase-buffer)
985 (insert-file-contents new-file)
986 ;; Rmail buffers need to be saved with Unix EOLs, or else
987 ;; the format will not be recognized.
988 (set-buffer-file-coding-system 'raw-text-unix)
989 (rmail-mode-1)
990 (rmail-perm-variables)
991 (rmail-variables)
992 (setq rmail-was-converted t)
993 (rmail-dont-modify-format)
994 (goto-char (point-max))
995 (rmail-set-message-counters))
996 (message "Replacing BABYL format with mbox format...done"))
997 (delete-file old-file)
998 (delete-file new-file))))
1000 (defun rmail-get-coding-system ()
1001 "Return a suitable coding system to use for the current mail message.
1002 The buffer is expected to be narrowed to just the header of the message."
1003 (save-excursion
1004 (goto-char (point-min))
1005 (if (re-search-forward rmail-mime-charset-pattern nil t)
1006 (coding-system-from-name (match-string 1))
1007 'undecided)))
1009 ;;; Set up Rmail mode keymaps
1011 (defvar rmail-mode-map
1012 (let ((map (make-keymap)))
1013 (suppress-keymap map)
1014 (define-key map "a" 'rmail-add-label)
1015 (define-key map "b" 'rmail-bury)
1016 (define-key map "c" 'rmail-continue)
1017 (define-key map "d" 'rmail-delete-forward)
1018 (define-key map "\C-d" 'rmail-delete-backward)
1019 (define-key map "e" 'rmail-edit-current-message)
1020 ;; If you change this, change the rmail-resend menu-item's :keys.
1021 (define-key map "f" 'rmail-forward)
1022 (define-key map "g" 'rmail-get-new-mail)
1023 (define-key map "h" 'rmail-summary)
1024 (define-key map "i" 'rmail-input)
1025 (define-key map "j" 'rmail-show-message)
1026 (define-key map "k" 'rmail-kill-label)
1027 (define-key map "l" 'rmail-summary-by-labels)
1028 (define-key map "\e\C-h" 'rmail-summary)
1029 (define-key map "\e\C-l" 'rmail-summary-by-labels)
1030 (define-key map "\e\C-r" 'rmail-summary-by-recipients)
1031 (define-key map "\e\C-s" 'rmail-summary-by-regexp)
1032 (define-key map "\e\C-f" 'rmail-summary-by-senders)
1033 (define-key map "\e\C-t" 'rmail-summary-by-topic)
1034 (define-key map "m" 'rmail-mail)
1035 (define-key map "\em" 'rmail-retry-failure)
1036 (define-key map "n" 'rmail-next-undeleted-message)
1037 (define-key map "\en" 'rmail-next-message)
1038 (define-key map "\e\C-n" 'rmail-next-labeled-message)
1039 (define-key map "o" 'rmail-output)
1040 (define-key map "\C-o" 'rmail-output-as-seen)
1041 (define-key map "p" 'rmail-previous-undeleted-message)
1042 (define-key map "\ep" 'rmail-previous-message)
1043 (define-key map "\e\C-p" 'rmail-previous-labeled-message)
1044 (define-key map "q" 'rmail-quit)
1045 (define-key map "r" 'rmail-reply)
1046 ;; I find I can't live without the default M-r command -- rms.
1047 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
1048 (define-key map "s" 'rmail-expunge-and-save)
1049 (define-key map "\es" 'rmail-search)
1050 (define-key map "t" 'rmail-toggle-header)
1051 (define-key map "u" 'rmail-undelete-previous-message)
1052 (define-key map "v" 'rmail-mime)
1053 (define-key map "w" 'rmail-output-body-to-file)
1054 (define-key map "\C-c\C-w" 'rmail-widen)
1055 (define-key map "x" 'rmail-expunge)
1056 (define-key map "." 'rmail-beginning-of-message)
1057 (define-key map "/" 'rmail-end-of-message)
1058 (define-key map "<" 'rmail-first-message)
1059 (define-key map ">" 'rmail-last-message)
1060 (define-key map " " 'scroll-up-command)
1061 (define-key map "\177" 'scroll-down-command)
1062 (define-key map "?" 'describe-mode)
1063 (define-key map "\C-c\C-s\C-d" 'rmail-sort-by-date)
1064 (define-key map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
1065 (define-key map "\C-c\C-s\C-a" 'rmail-sort-by-author)
1066 (define-key map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
1067 (define-key map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
1068 (define-key map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
1069 (define-key map "\C-c\C-s\C-k" 'rmail-sort-by-labels)
1070 (define-key map "\C-c\C-n" 'rmail-next-same-subject)
1071 (define-key map "\C-c\C-p" 'rmail-previous-same-subject)
1074 (define-key map [menu-bar] (make-sparse-keymap))
1076 (define-key map [menu-bar classify]
1077 (cons "Classify" (make-sparse-keymap "Classify")))
1079 (define-key map [menu-bar classify input-menu]
1080 nil)
1082 (define-key map [menu-bar classify output-menu]
1083 nil)
1085 (define-key map [menu-bar classify output-body]
1086 '("Output body to file..." . rmail-output-body-to-file))
1088 (define-key map [menu-bar classify output-inbox]
1089 '("Output..." . rmail-output))
1091 (define-key map [menu-bar classify output]
1092 '("Output as seen..." . rmail-output-as-seen))
1094 (define-key map [menu-bar classify kill-label]
1095 '("Kill Label..." . rmail-kill-label))
1097 (define-key map [menu-bar classify add-label]
1098 '("Add Label..." . rmail-add-label))
1100 (define-key map [menu-bar summary]
1101 (cons "Summary" (make-sparse-keymap "Summary")))
1103 (define-key map [menu-bar summary senders]
1104 '("By Senders..." . rmail-summary-by-senders))
1106 (define-key map [menu-bar summary labels]
1107 '("By Labels..." . rmail-summary-by-labels))
1109 (define-key map [menu-bar summary recipients]
1110 '("By Recipients..." . rmail-summary-by-recipients))
1112 (define-key map [menu-bar summary topic]
1113 '("By Topic..." . rmail-summary-by-topic))
1115 (define-key map [menu-bar summary regexp]
1116 '("By Regexp..." . rmail-summary-by-regexp))
1118 (define-key map [menu-bar summary all]
1119 '("All" . rmail-summary))
1121 (define-key map [menu-bar mail]
1122 (cons "Mail" (make-sparse-keymap "Mail")))
1124 (define-key map [menu-bar mail rmail-get-new-mail]
1125 '("Get New Mail" . rmail-get-new-mail))
1127 (define-key map [menu-bar mail lambda]
1128 '("----"))
1130 (define-key map [menu-bar mail continue]
1131 '("Continue" . rmail-continue))
1133 (define-key map [menu-bar mail resend]
1134 '(menu-item "Resend..." rmail-resend :keys "C-u f"))
1136 (define-key map [menu-bar mail forward]
1137 '("Forward" . rmail-forward))
1139 (define-key map [menu-bar mail retry]
1140 '("Retry" . rmail-retry-failure))
1142 (define-key map [menu-bar mail reply]
1143 '("Reply" . rmail-reply))
1145 (define-key map [menu-bar mail mail]
1146 '("Mail" . rmail-mail))
1148 (define-key map [menu-bar delete]
1149 (cons "Delete" (make-sparse-keymap "Delete")))
1151 (define-key map [menu-bar delete expunge/save]
1152 '("Expunge/Save" . rmail-expunge-and-save))
1154 (define-key map [menu-bar delete expunge]
1155 '("Expunge" . rmail-expunge))
1157 (define-key map [menu-bar delete undelete]
1158 '("Undelete" . rmail-undelete-previous-message))
1160 (define-key map [menu-bar delete delete]
1161 '("Delete" . rmail-delete-forward))
1163 (define-key map [menu-bar move]
1164 (cons "Move" (make-sparse-keymap "Move")))
1166 (define-key map [menu-bar move search-back]
1167 '("Search Back..." . rmail-search-backwards))
1169 (define-key map [menu-bar move search]
1170 '("Search..." . rmail-search))
1172 (define-key map [menu-bar move previous]
1173 '("Previous Nondeleted" . rmail-previous-undeleted-message))
1175 (define-key map [menu-bar move next]
1176 '("Next Nondeleted" . rmail-next-undeleted-message))
1178 (define-key map [menu-bar move last]
1179 '("Last" . rmail-last-message))
1181 (define-key map [menu-bar move first]
1182 '("First" . rmail-first-message))
1184 (define-key map [menu-bar move previous]
1185 '("Previous" . rmail-previous-message))
1187 (define-key map [menu-bar move next]
1188 '("Next" . rmail-next-message))
1190 map)
1191 "Keymap used in Rmail mode.")
1193 ;; Rmail toolbar
1194 (defvar rmail-tool-bar-map
1195 (let ((map (make-sparse-keymap)))
1196 (tool-bar-local-item-from-menu 'rmail-get-new-mail "mail/inbox"
1197 map rmail-mode-map)
1198 (tool-bar-local-item-from-menu 'rmail-next-undeleted-message "right-arrow"
1199 map rmail-mode-map)
1200 (tool-bar-local-item-from-menu 'rmail-previous-undeleted-message "left-arrow"
1201 map rmail-mode-map)
1202 (tool-bar-local-item-from-menu 'rmail-search "search"
1203 map rmail-mode-map)
1204 (tool-bar-local-item-from-menu 'rmail-input "open"
1205 map rmail-mode-map)
1206 (tool-bar-local-item-from-menu 'rmail-mail "mail/compose"
1207 map rmail-mode-map)
1208 (tool-bar-local-item-from-menu 'rmail-reply "mail/reply-all"
1209 map rmail-mode-map)
1210 (tool-bar-local-item-from-menu 'rmail-forward "mail/forward"
1211 map rmail-mode-map)
1212 (tool-bar-local-item-from-menu 'rmail-delete-forward "close"
1213 map rmail-mode-map)
1214 (tool-bar-local-item-from-menu 'rmail-output "mail/move"
1215 map rmail-mode-map)
1216 (tool-bar-local-item-from-menu 'rmail-output-body-to-file "mail/save"
1217 map rmail-mode-map)
1218 (tool-bar-local-item-from-menu 'rmail-expunge "delete"
1219 map rmail-mode-map)
1220 map))
1224 ;; Rmail mode is suitable only for specially formatted data.
1225 (put 'rmail-mode 'mode-class 'special)
1227 (defun rmail-mode-kill-summary ()
1228 (if rmail-summary-buffer (kill-buffer rmail-summary-buffer)))
1230 (defvar rmail-enable-multibyte) ; dynamically bound
1232 ;;;###autoload
1233 (defun rmail-mode ()
1234 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
1235 All normal editing commands are turned off.
1236 Instead, these commands are available:
1238 \\[rmail-beginning-of-message] Move point to front of this message.
1239 \\[rmail-end-of-message] Move point to bottom of this message.
1240 \\[scroll-up] Scroll to next screen of this message.
1241 \\[scroll-down] Scroll to previous screen of this message.
1242 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
1243 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
1244 \\[rmail-next-message] Move to Next message whether deleted or not.
1245 \\[rmail-previous-message] Move to Previous message whether deleted or not.
1246 \\[rmail-first-message] Move to the first message in Rmail file.
1247 \\[rmail-last-message] Move to the last message in Rmail file.
1248 \\[rmail-show-message] Jump to message specified by numeric position in file.
1249 \\[rmail-search] Search for string and show message it is found in.
1250 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
1251 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
1252 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1253 till a deleted message is found.
1254 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
1255 \\[rmail-expunge] Expunge deleted messages.
1256 \\[rmail-expunge-and-save] Expunge and save the file.
1257 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
1258 \\[save-buffer] Save without expunging.
1259 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
1260 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
1261 \\[rmail-continue] Continue composing outgoing message started before.
1262 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
1263 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
1264 \\[rmail-forward] Forward this message to another user.
1265 \\[rmail-output] Output (append) this message to another mail file.
1266 \\[rmail-output-as-seen] Output (append) this message to file as it's displayed.
1267 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1268 \\[rmail-input] Input Rmail file. Run Rmail on that file.
1269 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
1270 \\[rmail-kill-label] Kill label. Remove a label from current message.
1271 \\[rmail-next-labeled-message] Move to Next message with specified label
1272 (label defaults to last one specified).
1273 Standard labels: filed, unseen, answered, forwarded, deleted.
1274 Any other label is present only if you add it with \\[rmail-add-label].
1275 \\[rmail-previous-labeled-message] Move to Previous message with specified label
1276 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
1277 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
1278 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1279 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1280 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1281 \\[rmail-toggle-header] Toggle display of complete header."
1282 (interactive)
1283 (let ((finding-rmail-file (not (eq major-mode 'rmail-mode))))
1284 (rmail-mode-2)
1285 (when (and finding-rmail-file
1286 (null coding-system-for-read)
1287 (default-value 'enable-multibyte-characters))
1288 (let ((rmail-enable-multibyte t))
1289 (rmail-require-mime-maybe)
1290 (rmail-convert-file-maybe)
1291 (goto-char (point-max))
1292 (set-buffer-multibyte t)))
1293 (rmail-set-message-counters)
1294 (rmail-show-message rmail-total-messages)
1295 (when finding-rmail-file
1296 (when rmail-display-summary
1297 (rmail-summary))
1298 (rmail-construct-io-menu))
1299 (run-mode-hooks 'rmail-mode-hook)))
1301 (defun rmail-mode-2 ()
1302 (kill-all-local-variables)
1303 (rmail-mode-1)
1304 (rmail-perm-variables)
1305 (rmail-variables))
1307 (defun rmail-mode-1 ()
1308 (setq major-mode 'rmail-mode)
1309 (setq mode-name "RMAIL")
1310 (setq buffer-read-only t)
1311 ;; No need to auto save RMAIL files in normal circumstances
1312 ;; because they contain no info except attribute changes
1313 ;; and deletion of messages.
1314 ;; The one exception is when messages are copied into another mbox buffer.
1315 ;; rmail-output enables auto save when you do that.
1316 (setq buffer-auto-save-file-name nil)
1317 (use-local-map rmail-mode-map)
1318 (set-syntax-table text-mode-syntax-table)
1319 (setq local-abbrev-table text-mode-abbrev-table)
1320 ;; Functions to support buffer swapping:
1321 (add-hook 'write-region-annotate-functions
1322 'rmail-write-region-annotate nil t)
1323 (add-hook 'kill-buffer-hook 'rmail-mode-kill-buffer-hook nil t)
1324 (add-hook 'change-major-mode-hook 'rmail-change-major-mode-hook nil t))
1326 (defun rmail-generate-viewer-buffer ()
1327 "Return a reusable buffer suitable for viewing messages.
1328 Create the buffer if necessary."
1329 ;; We want to reuse any existing view buffer, so as not to create an
1330 ;; endless number of them. But we must avoid clashes if we visit
1331 ;; two different rmail files with the same basename (Bug#4593).
1332 (if (and (local-variable-p 'rmail-view-buffer)
1333 (buffer-live-p rmail-view-buffer))
1334 rmail-view-buffer
1335 (let ((newbuf
1336 (generate-new-buffer
1337 (format " *message-viewer %s*"
1338 (file-name-nondirectory
1339 (or buffer-file-name (buffer-name)))))))
1340 (with-current-buffer newbuf
1341 (add-hook 'kill-buffer-hook 'rmail-view-buffer-kill-buffer-hook nil t))
1342 newbuf)))
1344 (defun rmail-swap-buffers ()
1345 "Swap text between current buffer and `rmail-view-buffer'.
1346 This function preserves the current buffer's modified flag, and also
1347 sets the current buffer's `buffer-file-coding-system' to that of
1348 `rmail-view-buffer'."
1349 (let ((modp-this (buffer-modified-p))
1350 (modp-that
1351 (with-current-buffer rmail-view-buffer (buffer-modified-p)))
1352 (coding-this buffer-file-coding-system)
1353 (coding-that
1354 (with-current-buffer rmail-view-buffer
1355 buffer-file-coding-system)))
1356 (buffer-swap-text rmail-view-buffer)
1357 (setq buffer-file-coding-system coding-that)
1358 (with-current-buffer rmail-view-buffer
1359 (setq buffer-file-coding-system coding-this)
1360 (restore-buffer-modified-p modp-that))
1361 (restore-buffer-modified-p modp-this)))
1363 (defun rmail-buffers-swapped-p ()
1364 "Return non-nil if the message collection is in `rmail-view-buffer'."
1365 ;; This is analogous to tar-data-swapped-p in tar-mode.el.
1366 rmail-buffer-swapped)
1368 (defun rmail-change-major-mode-hook ()
1369 ;; Bring the actual Rmail messages back into the main buffer.
1370 (when (rmail-buffers-swapped-p)
1371 (rmail-swap-buffers)
1372 (setq rmail-buffer-swapped nil)))
1374 (defun rmail-swap-buffers-maybe ()
1375 "Determine if the Rmail buffer is showing a message.
1376 If so restore the actual mbox message collection."
1377 (with-current-buffer rmail-buffer
1378 (when (rmail-buffers-swapped-p)
1379 (rmail-swap-buffers)
1380 (setq rmail-buffer-swapped nil))))
1382 (defun rmail-modify-format ()
1383 "Warn if important modifications would change Rmail file's format."
1384 (with-current-buffer rmail-buffer
1385 (and rmail-was-converted
1386 ;; If it's already modified, don't warn again.
1387 (not rmail-seriously-modified)
1388 (not
1389 (yes-or-no-p
1390 (message "After this, %s would be saved in mbox format. Proceed? "
1391 (buffer-name))))
1392 (error "Aborted"))
1393 (setq rmail-seriously-modified t)))
1395 (defun rmail-dont-modify-format ()
1396 (when (and rmail-was-converted (not rmail-seriously-modified))
1397 (set-buffer-modified-p nil)
1398 (message "Marking buffer unmodified to avoid rewriting Babyl file as mbox file")))
1400 (defun rmail-mode-kill-buffer-hook ()
1401 ;; Turn off the hook on the view buffer, so we can kill it, then kill it.
1402 (if (buffer-live-p rmail-view-buffer)
1403 (with-current-buffer rmail-view-buffer
1404 (setq kill-buffer-hook nil)
1405 (kill-buffer rmail-view-buffer))))
1407 (defun rmail-view-buffer-kill-buffer-hook ()
1408 (error "Can't kill Rmail view buffer `%s' by itself"
1409 (buffer-name (current-buffer))))
1411 ;; Set up the permanent locals associated with an Rmail file.
1412 (defun rmail-perm-variables ()
1413 (make-local-variable 'rmail-last-regexp)
1414 (make-local-variable 'rmail-deleted-vector)
1415 (make-local-variable 'rmail-buffer)
1416 (make-local-variable 'rmail-was-converted)
1417 (setq rmail-was-converted nil)
1418 (make-local-variable 'rmail-seriously-modified)
1419 (setq rmail-seriously-modified nil)
1420 (setq rmail-buffer (current-buffer))
1421 (set-buffer-multibyte nil)
1422 (with-current-buffer (setq rmail-view-buffer (rmail-generate-viewer-buffer))
1423 (setq buffer-undo-list t)
1424 ;; Note that this does not erase the buffer. Should it?
1425 ;; It depends on how this is called. If somehow called with the
1426 ;; rmail buffers swapped, it would erase the message collection.
1427 (set (make-local-variable 'rmail-overlay-list) nil)
1428 (set-buffer-multibyte t)
1429 ;; Force C-x C-s write Unix EOLs.
1430 (set-buffer-file-coding-system 'undecided-unix))
1431 (make-local-variable 'rmail-summary-buffer)
1432 (make-local-variable 'rmail-summary-vector)
1433 (make-local-variable 'rmail-current-message)
1434 (make-local-variable 'rmail-total-messages)
1435 (setq rmail-total-messages 0)
1436 (make-local-variable 'rmail-message-vector)
1437 (make-local-variable 'rmail-msgref-vector)
1438 (make-local-variable 'rmail-inbox-list)
1439 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1440 (and (null rmail-inbox-list)
1441 (or (equal buffer-file-name (expand-file-name rmail-file-name))
1442 (equal buffer-file-truename
1443 (abbreviate-file-name (file-truename rmail-file-name))))
1444 (setq rmail-inbox-list
1445 (or rmail-primary-inbox-list
1446 (list (or (getenv "MAIL")
1447 ;; FIXME expand-file-name?
1448 (concat rmail-spool-directory
1449 (user-login-name)))))))
1450 (set (make-local-variable 'tool-bar-map) rmail-tool-bar-map))
1452 ;; Set up the non-permanent locals associated with Rmail mode.
1453 (defun rmail-variables ()
1454 ;; Turn off undo. We turn it back on in rmail-edit.
1455 (setq buffer-undo-list t)
1456 ;; Don't let a local variables list in a message cause confusion.
1457 (make-local-variable 'local-enable-local-variables)
1458 (setq local-enable-local-variables nil)
1459 ;; Don't turn off auto-saving based on the size of the buffer
1460 ;; because that code does not understand buffer-swapping.
1461 (make-local-variable 'auto-save-include-big-deletions)
1462 (setq auto-save-include-big-deletions t)
1463 (make-local-variable 'revert-buffer-function)
1464 (setq revert-buffer-function 'rmail-revert)
1465 (make-local-variable 'font-lock-defaults)
1466 (setq font-lock-defaults
1467 '(rmail-font-lock-keywords
1468 t t nil nil
1469 (font-lock-maximum-size . nil)
1470 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function)
1471 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function)
1472 (font-lock-inhibit-thing-lock . (lazy-lock-mode fast-lock-mode))))
1473 (make-local-variable 'require-final-newline)
1474 (setq require-final-newline nil)
1475 (make-local-variable 'version-control)
1476 (setq version-control 'never)
1477 (make-local-variable 'kill-buffer-hook)
1478 (add-hook 'kill-buffer-hook 'rmail-mode-kill-summary)
1479 (make-local-variable 'file-precious-flag)
1480 (setq file-precious-flag t)
1481 (make-local-variable 'desktop-save-buffer)
1482 (setq desktop-save-buffer t)
1483 (setq next-error-move-function 'rmail-next-error-move))
1485 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1486 (defun rmail-revert (arg noconfirm)
1487 (set-buffer rmail-buffer)
1488 (let* ((revert-buffer-function (default-value 'revert-buffer-function))
1489 (rmail-enable-multibyte enable-multibyte-characters)
1490 ;; See similar code in `rmail'.
1491 ;; FIXME needs updating?
1492 (coding-system-for-read (and rmail-enable-multibyte 'raw-text))
1493 (before-revert-hook 'rmail-swap-buffers-maybe))
1494 ;; Call our caller again, but this time it does the default thing.
1495 (when (revert-buffer arg noconfirm)
1496 ;; If the user said "yes", and we changed something,
1497 ;; reparse the messages.
1498 (set-buffer rmail-buffer)
1499 (rmail-mode-2)
1500 ;; Convert all or part to Babyl file if possible.
1501 (rmail-convert-file-maybe)
1502 ;; We have read the file as raw-text, so the buffer is set to
1503 ;; unibyte. Make it multibyte if necessary.
1504 (if (and rmail-enable-multibyte
1505 (not enable-multibyte-characters))
1506 (set-buffer-multibyte t))
1507 (goto-char (point-max))
1508 (rmail-set-message-counters)
1509 (rmail-show-message rmail-total-messages)
1510 (run-hooks 'rmail-mode-hook))))
1512 (defun rmail-expunge-and-save ()
1513 "Expunge and save RMAIL file."
1514 (interactive)
1515 (set-buffer rmail-buffer)
1516 (rmail-expunge)
1517 ;; No need to swap buffers: rmail-write-region-annotate takes care of it.
1518 ;; (rmail-swap-buffers-maybe)
1519 (save-buffer)
1520 (if (rmail-summary-exists)
1521 (rmail-select-summary (set-buffer-modified-p nil))))
1523 (defun rmail-quit ()
1524 "Quit out of RMAIL.
1525 Hook `rmail-quit-hook' is run after expunging."
1526 (interactive)
1527 (set-buffer rmail-buffer)
1528 (rmail-expunge t)
1529 (save-buffer)
1530 (when (boundp 'rmail-quit-hook)
1531 (run-hooks 'rmail-quit-hook))
1532 ;; Don't switch to the summary buffer even if it was recently visible.
1533 (when rmail-summary-buffer
1534 (with-current-buffer rmail-summary-buffer
1535 (set-buffer-modified-p nil))
1536 (replace-buffer-in-windows rmail-summary-buffer)
1537 (bury-buffer rmail-summary-buffer))
1538 (let ((obuf (current-buffer)))
1539 (quit-window)
1540 (replace-buffer-in-windows obuf)))
1542 (defun rmail-bury ()
1543 "Bury current Rmail buffer and its summary buffer."
1544 (interactive)
1545 ;; This let var was called rmail-buffer, but that interfered
1546 ;; with the buffer-local var used in summary buffers.
1547 (let ((buffer-to-bury (current-buffer)))
1548 (if (rmail-summary-exists)
1549 (let (window)
1550 (while (setq window (get-buffer-window rmail-summary-buffer))
1551 (quit-window nil window))
1552 (bury-buffer rmail-summary-buffer)))
1553 (quit-window)))
1555 (defun rmail-duplicate-message ()
1556 "Create a duplicated copy of the current message.
1557 The duplicate copy goes into the Rmail file just after the original."
1558 ;; If we are in a summary buffer, switch to the Rmail buffer.
1559 ;; FIXME simpler to swap the contents, not the buffers?
1560 (set-buffer rmail-buffer)
1561 (rmail-modify-format)
1562 (let ((buff (current-buffer))
1563 (n rmail-current-message)
1564 (beg (rmail-msgbeg rmail-current-message))
1565 (end (rmail-msgend rmail-current-message)))
1566 (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
1567 (widen)
1568 (let ((buffer-read-only nil)
1569 (string (buffer-substring-no-properties beg end)))
1570 (goto-char end)
1571 (insert string))
1572 (set-buffer buff)
1573 (rmail-swap-buffers-maybe)
1574 (goto-char (point-max))
1575 (rmail-set-message-counters)
1576 (set-buffer-modified-p t)
1577 (rmail-show-message-1 n))
1578 (if (rmail-summary-exists)
1579 (rmail-select-summary (rmail-update-summary)))
1580 (message "Message duplicated"))
1582 ;;;###autoload
1583 (defun rmail-input (filename)
1584 "Run Rmail on file FILENAME."
1585 (interactive "FRun rmail on RMAIL file: ")
1586 (rmail filename))
1588 ;; This used to scan subdirectories recursively, but someone pointed out
1589 ;; that if the user wants that, person can put all the files in one dir.
1590 ;; And the recursive scan was slow. So I took it out.
1591 ;; rms, Sep 1996.
1592 (defun rmail-find-all-files (start)
1593 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1594 (if (file-accessible-directory-p start)
1595 ;; Don't sort here.
1596 (let* ((case-fold-search t)
1597 (files (directory-files start t rmail-secondary-file-regexp)))
1598 ;; Sort here instead of in directory-files
1599 ;; because this list is usually much shorter.
1600 (sort files 'string<))))
1602 (defun rmail-list-to-menu (menu-name l action &optional full-name)
1603 (let ((menu (make-sparse-keymap menu-name))
1604 name)
1605 (mapc
1606 (lambda (item)
1607 (let (command)
1608 (if (consp item)
1609 (setq command
1610 (rmail-list-to-menu
1611 (car item) (cdr item) action
1612 (if full-name
1613 (concat full-name "/"
1614 (car item))
1615 (car item)))
1616 name (car item))
1617 (setq name item)
1618 (setq command
1619 (list 'lambda () '(interactive)
1620 (list action
1621 (expand-file-name
1622 (if full-name
1623 (concat full-name "/" item)
1624 item)
1625 rmail-secondary-file-directory)))))
1626 (define-key menu (vector (intern name))
1627 (cons name command))))
1628 (reverse l))
1629 menu))
1631 ;; This command is always "disabled" when it appears in a menu.
1632 (put 'rmail-disable-menu 'menu-enable ''nil)
1634 (defun rmail-construct-io-menu ()
1635 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1636 (if files
1637 (progn
1638 (define-key rmail-mode-map [menu-bar classify input-menu]
1639 (cons "Input Rmail File"
1640 (rmail-list-to-menu "Input Rmail File"
1641 files
1642 'rmail-input)))
1643 (define-key rmail-mode-map [menu-bar classify output-menu]
1644 (cons "Output Rmail File"
1645 (rmail-list-to-menu "Output Rmail File"
1646 files
1647 'rmail-output))))
1649 (define-key rmail-mode-map [menu-bar classify input-menu]
1650 '("Input Rmail File" . rmail-disable-menu))
1651 (define-key rmail-mode-map [menu-bar classify output-menu]
1652 '("Output Rmail File" . rmail-disable-menu)))))
1655 ;;;; *** Rmail input ***
1657 (declare-function rmail-summary-goto-msg "rmailsum" (&optional n nowarn skip-rmail))
1658 (declare-function rmail-summary-mark-undeleted "rmailsum" (n))
1659 (declare-function rmail-summary-mark-deleted "rmailsum" (&optional n undel))
1660 (declare-function rfc822-addresses "rfc822" (header-text))
1661 (declare-function mail-abbrev-make-syntax-table "mailabbrev.el" ())
1663 ;; RLK feature not added in this version:
1664 ;; argument specifies inbox file or files in various ways.
1666 ;; In Babyl, the Mail: header in the preamble overrode rmail-inbox-list.
1667 ;; Mbox does not have this feature.
1668 (defun rmail-get-new-mail (&optional file-name)
1669 "Move any new mail from this Rmail file's inbox files.
1670 The buffer-local variable `rmail-inbox-list' specifies the list
1671 of inbox files. By default, this is nil, except for your primary
1672 Rmail file `rmail-file-name'. In this case, when you first visit
1673 the Rmail file it is initialized using either
1674 `rmail-primary-inbox-list', or the \"MAIL\" environment variable,
1675 or the function `user-login-name' and the directory
1676 `rmail-spool-directory' (whose value depends on the operating system).
1678 The command `set-rmail-inbox-list' sets `rmail-inbox-list' to the
1679 value you specify.
1681 You can also specify the file to get new mail from just for one
1682 instance of this command. In this case, the file of new mail is
1683 not changed or deleted. Noninteractively, you can pass the inbox
1684 file name as an argument. Interactively, a prefix argument
1685 causes us to read a file name and use that file as the inbox.
1687 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1688 always be left in inbox files rather than deleted.
1690 Before doing anything, this runs `rmail-before-get-new-mail-hook'.
1691 Just before returning, it runs `rmail-after-get-new-mail-hook',
1692 whether or not there is new mail.
1694 If there is new mail, it runs `rmail-get-new-mail-hook', saves
1695 the updated file, and shows the first unseen message (which might
1696 not be a new one). It returns non-nil if it got any new messages."
1697 (interactive
1698 (list (if current-prefix-arg
1699 (read-file-name "Get new mail from file: "))))
1700 (run-hooks 'rmail-before-get-new-mail-hook)
1701 ;; If the disk file has been changed from under us,
1702 ;; revert to it before we get new mail.
1703 (or (verify-visited-file-modtime (current-buffer))
1704 (find-file (buffer-file-name)))
1705 (set-buffer rmail-buffer)
1706 (rmail-modify-format)
1707 (rmail-swap-buffers-maybe)
1708 (rmail-maybe-set-message-counters)
1709 (widen)
1710 ;; Get rid of all undo records for this buffer.
1711 (or (eq buffer-undo-list t)
1712 (setq buffer-undo-list nil))
1713 (let ((all-files (if file-name (list file-name) rmail-inbox-list))
1714 (rmail-enable-multibyte (default-value 'enable-multibyte-characters))
1715 found)
1716 (unwind-protect
1717 (progn
1718 ;; This loops if any members of the inbox list have the same
1719 ;; basename (see "name conflict" below).
1720 (while all-files
1721 (let ((opoint (point))
1722 ;; If buffer has not changed yet, and has not been
1723 ;; saved yet, don't replace the old backup file now.
1724 (make-backup-files (and make-backup-files
1725 (buffer-modified-p)))
1726 (buffer-read-only nil)
1727 ;; Don't make undo records while getting mail.
1728 (buffer-undo-list t)
1729 delete-files success files file-last-names)
1730 ;; Pull files off all-files onto files as long as there is
1731 ;; no name conflict. A conflict happens when two inbox
1732 ;; file names have the same last component.
1733 ;; The reason this careful handling is necessary seems
1734 ;; to be that rmail-insert-inbox-text uses .newmail-BASENAME.
1735 (while (and all-files
1736 (not (member (file-name-nondirectory (car all-files))
1737 file-last-names)))
1738 (setq files (cons (car all-files) files)
1739 file-last-names
1740 (cons (file-name-nondirectory (car all-files)) files))
1741 (setq all-files (cdr all-files)))
1742 ;; Put them back in their original order.
1743 (setq files (nreverse files))
1744 (goto-char (point-max))
1745 ;; Make sure we end with a blank line unless there are
1746 ;; no messages, as required by mbox format (Bug#9974).
1747 (unless (bobp)
1748 (while (not (looking-back "\n\n"))
1749 (insert "\n")))
1750 (setq found (or
1751 (rmail-get-new-mail-1 file-name files delete-files)
1752 found))))
1753 ;; Move to the first new message unless we have other unseen
1754 ;; messages before it.
1755 (if found (rmail-show-message (rmail-first-unseen-message)))
1756 (run-hooks 'rmail-after-get-new-mail-hook)
1757 found)
1758 ;; Don't leave the buffer screwed up if we get a disk-full error.
1759 (rmail-show-message))))
1761 (defvar rmail-use-spam-filter)
1762 (declare-function rmail-get-new-mail-filter-spam "rmail-spam-filter" (nnew))
1764 (defun rmail-get-new-mail-1 (file-name files delete-files)
1765 "Return t if new messages are detected without error, nil otherwise."
1766 (save-excursion
1767 (save-restriction
1768 (let ((new-messages 0)
1769 (spam-filter-p (and (featurep 'rmail-spam-filter)
1770 rmail-use-spam-filter))
1771 (blurb "")
1772 result success suffix)
1773 (narrow-to-region (point) (point))
1774 ;; Read in the contents of the inbox files, renaming them as
1775 ;; necessary, and adding to the list of files to delete
1776 ;; eventually.
1777 (if file-name
1778 (rmail-insert-inbox-text files nil)
1779 (setq delete-files (rmail-insert-inbox-text files t)))
1780 ;; Scan the new text and convert each message to
1781 ;; Rmail/mbox format.
1782 (goto-char (point-min))
1783 (skip-chars-forward " \n")
1784 (narrow-to-region (point) (point-max))
1785 (unwind-protect
1786 (setq new-messages (rmail-add-mbox-headers)
1787 success t)
1788 ;; Try to delete the garbage just inserted.
1789 (or success (delete-region (point-min) (point-max)))
1790 ;; If we could not convert the file's inboxes, rename the
1791 ;; files we tried to read so we won't over and over again.
1792 (if (and (not file-name) (not success))
1793 (let ((delfiles delete-files)
1794 (count 0))
1795 (while delfiles
1796 (while (file-exists-p (format "RMAILOSE.%d" count))
1797 (setq count (1+ count)))
1798 (rename-file (car delfiles) (format "RMAILOSE.%d" count))
1799 (setq delfiles (cdr delfiles))))))
1800 ;; Determine if there are messages.
1801 (unless (zerop new-messages)
1802 ;; There are. Process them.
1803 (goto-char (point-min))
1804 (rmail-count-new-messages)
1805 (run-hooks 'rmail-get-new-mail-hook)
1806 (save-buffer))
1807 ;; Delete the old files, now that the Rmail file is saved.
1808 (while delete-files
1809 (condition-case ()
1810 ;; First, try deleting.
1811 (condition-case ()
1812 (delete-file (car delete-files))
1813 (file-error
1814 ;; If we can't delete it, truncate it.
1815 (write-region (point) (point) (car delete-files))))
1816 (file-error nil))
1817 (setq delete-files (cdr delete-files)))
1818 (if (zerop new-messages)
1819 (when (or file-name rmail-inbox-list)
1820 (message "(No new mail has arrived)"))
1821 (if spam-filter-p
1822 (setq blurb (rmail-get-new-mail-filter-spam new-messages))))
1823 (if (rmail-summary-exists)
1824 (rmail-select-summary (rmail-update-summary)))
1825 (setq suffix (if (= 1 new-messages) "" "s"))
1826 (message "%d new message%s read%s" new-messages suffix blurb)
1827 ;; Establish the return value.
1828 (setq result (> new-messages 0))
1829 result))))
1831 (defun rmail-parse-url (file)
1832 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1833 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1834 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1835 a remote mailbox, PASSWORD is the password if it should be
1836 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1837 is non-nil if the user has supplied the password interactively.
1839 (cond
1840 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file)
1841 (let (got-password supplied-password
1842 (proto (match-string 1 file))
1843 (user (match-string 3 file))
1844 (pass (match-string 5 file))
1845 (host (substring file (or (match-end 2)
1846 (+ 3 (match-end 1))))))
1848 (if (not pass)
1849 (when rmail-remote-password-required
1850 (setq got-password (not (rmail-have-password)))
1851 (setq supplied-password (rmail-get-remote-password
1852 (string-equal proto "imap"))))
1853 ;; The password is embedded. Strip it out since movemail
1854 ;; does not really like it, in spite of the movemail spec.
1855 (setq file (concat proto "://" user "@" host)))
1857 (if (rmail-movemail-variant-p 'emacs)
1858 (if (string-equal proto "pop")
1859 (list (concat "po:" user ":" host)
1861 (or pass supplied-password)
1862 got-password)
1863 (error "Emacs movemail does not support %s protocol" proto))
1864 (list file
1865 (or (string-equal proto "pop") (string-equal proto "imap"))
1866 (or supplied-password pass)
1867 got-password))))
1869 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file)
1870 (let (got-password supplied-password
1871 (proto "pop")
1872 (user (match-string 1 file))
1873 (host (match-string 3 file)))
1875 (when rmail-remote-password-required
1876 (setq got-password (not (rmail-have-password)))
1877 (setq supplied-password (rmail-get-remote-password nil)))
1879 (list file "pop" supplied-password got-password)))
1882 (list file nil nil nil))))
1884 (defun rmail-unrmail-new-mail (from-file)
1885 "Replace newly read mail in Babyl format with equivalent mbox format.
1887 FROM-FILE is the Babyl file from which the new mail should be read."
1888 (let ((to-file (make-temp-file "rmail"))
1889 size)
1890 (unrmail from-file to-file)
1891 (let ((inhibit-read-only t)
1892 (coding-system-for-read 'raw-text)
1893 (buffer-undo-list t))
1894 (delete-region (point) (point-max))
1895 (setq size (nth 1 (insert-file-contents to-file)))
1896 (delete-file to-file)
1897 size)))
1899 (defun rmail-unrmail-new-mail-maybe (file size)
1900 "If newly read mail from FILE is in Babyl format, convert it to mbox format.
1902 SIZE is the original size of the newly read mail.
1903 Value is the size of the newly read mail after conversion."
1904 ;; Detect previous Babyl format files.
1905 (let ((case-fold-search nil)
1906 (old-file file)
1907 new-file)
1908 (cond ((looking-at "BABYL OPTIONS:")
1909 ;; The new mail is in Babyl version 5 format. Use unrmail
1910 ;; to convert it.
1911 (setq size (rmail-unrmail-new-mail old-file)))
1912 ((looking-at "Version: 5\n")
1913 ;; New mail is in Babyl format made by old version of
1914 ;; Rmail. Fix the babyl file header and use unrmail to
1915 ;; convert it.
1916 (let ((buffer-read-only nil)
1917 (write-region-annotate-functions nil)
1918 (write-region-post-annotation-function nil)
1919 (old-file (make-temp-file "rmail")))
1920 (insert "BABYL OPTIONS: -*- rmail -*-\n")
1921 (forward-line -1)
1922 (write-region (point) (point-max) old-file)
1923 (setq size (rmail-unrmail-new-mail old-file))
1924 (delete-file old-file))))
1925 size))
1927 (defun rmail-insert-inbox-text (files renamep)
1928 ;; Detect a locked file now, so that we avoid moving mail
1929 ;; out of the real inbox file. (That could scare people.)
1930 (or (memq (file-locked-p buffer-file-name) '(nil t))
1931 (error "RMAIL file %s is locked"
1932 (file-name-nondirectory buffer-file-name)))
1933 (let (file tofile delete-files movemail popmail got-password password)
1934 (while files
1935 ;; Handle remote mailbox names specially; don't expand as filenames
1936 ;; in case the userid contains a directory separator.
1937 (setq file (car files))
1938 (let ((url-data (rmail-parse-url file)))
1939 (setq file (nth 0 url-data))
1940 (setq popmail (nth 1 url-data))
1941 (setq password (nth 2 url-data))
1942 (setq got-password (nth 3 url-data)))
1944 (if popmail
1945 (setq renamep t)
1946 (setq file (file-truename
1947 (substitute-in-file-name (expand-file-name file)))))
1948 (setq tofile (expand-file-name
1949 ;; Generate name to move to from inbox name,
1950 ;; in case of multiple inboxes that need moving.
1951 (concat ".newmail-"
1952 (file-name-nondirectory
1953 (if (memq system-type '(windows-nt cygwin ms-dos))
1954 ;; cannot have colons in file name
1955 (replace-regexp-in-string ":" "-" file)
1956 file)))
1957 ;; Use the directory of this rmail file
1958 ;; because it's a nuisance to use the homedir
1959 ;; if that is on a full disk and this rmail
1960 ;; file isn't.
1961 (file-name-directory
1962 (expand-file-name buffer-file-name))))
1963 ;; Always use movemail to rename the file,
1964 ;; since there can be mailboxes in various directories.
1965 (when (not popmail)
1966 ;; On some systems, /usr/spool/mail/foo is a directory
1967 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1968 (if (file-directory-p file)
1969 (setq file (expand-file-name (user-login-name)
1970 file))))
1971 (cond (popmail
1972 (message "Getting mail from the remote server ..."))
1973 ((and (file-exists-p tofile)
1974 (/= 0 (nth 7 (file-attributes tofile))))
1975 (message "Getting mail from %s..." tofile))
1976 ((and (file-exists-p file)
1977 (/= 0 (nth 7 (file-attributes file))))
1978 (message "Getting mail from %s..." file)))
1979 ;; Set TOFILE if have not already done so, and
1980 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1981 (cond ((not renamep)
1982 (setq tofile file))
1983 ((or (file-exists-p tofile) (and (not popmail)
1984 (not (file-exists-p file))))
1985 nil)
1987 (with-temp-buffer
1988 (let ((errors (current-buffer)))
1989 (buffer-disable-undo errors)
1990 (let ((args
1991 (append
1992 (list (or rmail-movemail-program "movemail") nil errors nil)
1993 (if rmail-preserve-inbox
1994 (list "-p")
1995 nil)
1996 (if (rmail-movemail-variant-p 'mailutils)
1997 (append (list "--emacs") rmail-movemail-flags)
1998 rmail-movemail-flags)
1999 (list file tofile)
2000 (if password (list password) nil))))
2001 (apply 'call-process args))
2002 (if (not (buffer-modified-p errors))
2003 ;; No output => movemail won
2005 (set-buffer errors)
2006 (subst-char-in-region (point-min) (point-max)
2007 ?\n ?\s)
2008 (goto-char (point-max))
2009 (skip-chars-backward " \t")
2010 (delete-region (point) (point-max))
2011 (goto-char (point-min))
2012 (if (looking-at "movemail: ")
2013 (delete-region (point-min) (match-end 0)))
2014 (beep t)
2015 ;; If we just read the password, most likely it is
2016 ;; wrong. Otherwise, see if there is a specific
2017 ;; reason to think that the problem is a wrong passwd.
2018 (if (or got-password
2019 (re-search-forward rmail-remote-password-error
2020 nil t))
2021 (rmail-set-remote-password nil))
2023 ;; If using Mailutils, remove initial error code
2024 ;; abbreviation
2025 (when (rmail-movemail-variant-p 'mailutils)
2026 (goto-char (point-min))
2027 (when (looking-at "[A-Z][A-Z0-9_]*:")
2028 (delete-region (point-min) (match-end 0))))
2030 (message "movemail: %s"
2031 (buffer-substring (point-min)
2032 (point-max)))
2034 (sit-for 3)
2035 nil)))))
2037 ;; At this point, TOFILE contains the name to read:
2038 ;; Either the alternate name (if we renamed)
2039 ;; or the actual inbox (if not renaming).
2040 (if (file-exists-p tofile)
2041 (let ((coding-system-for-read 'no-conversion)
2042 size)
2043 (goto-char (point-max))
2044 (setq size
2045 ;; If new mail is in Babyl format, convert it to mbox.
2046 (rmail-unrmail-new-mail-maybe
2047 tofile
2048 (nth 1 (insert-file-contents tofile))))
2049 (goto-char (point-max))
2050 ;; Make sure the read-in mbox data properly ends with a
2051 ;; blank line unless it is of size 0.
2052 (unless (zerop size)
2053 (while (not (looking-back "\n\n"))
2054 (insert "\n")))
2055 (if (not (and rmail-preserve-inbox (string= file tofile)))
2056 (setq delete-files (cons tofile delete-files)))))
2057 (message "")
2058 (setq files (cdr files)))
2059 delete-files))
2061 ;; Decode the region specified by FROM and TO by CODING.
2062 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
2063 (defun rmail-decode-region (from to coding &optional destination)
2064 (if (or (not coding) (not (coding-system-p coding)))
2065 (setq coding 'undecided))
2066 ;; Use -dos decoding, to remove ^M characters left from base64 or
2067 ;; rogue qp-encoded text.
2068 (decode-coding-region
2069 from to (coding-system-change-eol-conversion coding 1) destination)
2070 ;; Don't reveal the fact we used -dos decoding, as users generally
2071 ;; will not expect the RMAIL buffer to use DOS EOL format.
2072 (cond
2073 ((null destination)
2074 (setq buffer-file-coding-system
2075 (setq last-coding-system-used
2076 (coding-system-change-eol-conversion coding 0))))
2077 ((bufferp destination)
2078 (with-current-buffer destination
2079 (setq buffer-file-coding-system
2080 (setq last-coding-system-used
2081 (coding-system-change-eol-conversion coding 0)))))))
2083 (defun rmail-ensure-blank-line ()
2084 "Ensure a message ends in a blank line.
2085 Call with point at the end of the message."
2086 (unless (bolp)
2087 (insert "\n"))
2088 (unless (looking-back "\n\n")
2089 (insert "\n")))
2091 (defun rmail-add-mbox-headers ()
2092 "Validate the RFC2822 format for the new messages.
2093 Point should be at the first new message.
2094 An error is signaled if the new messages are not RFC2822
2095 compliant.
2096 Unless an Rmail attribute header already exists, add it to the
2097 new messages. Return the number of new messages."
2098 (save-excursion
2099 (save-restriction
2100 (let ((count 0)
2101 (start (point))
2102 (value "------U-")
2103 (case-fold-search nil)
2104 (delim (concat "\n\n" rmail-unix-mail-delimiter))
2105 limit stop)
2106 ;; Detect an empty inbox file.
2107 (unless (= start (point-max))
2108 ;; Scan the new messages to establish a count and to ensure that
2109 ;; an attribute header is present.
2110 (if (looking-at rmail-unix-mail-delimiter)
2111 (while (not stop)
2112 ;; Determine if a new attribute header needs to be
2113 ;; added to the message.
2114 (if (search-forward "\n\n" nil t)
2115 (progn
2116 (setq count (1+ count))
2117 (narrow-to-region start (point))
2118 (unless (mail-fetch-field rmail-attribute-header)
2119 (backward-char 1)
2120 (insert rmail-attribute-header ": " value "\n"))
2121 (widen))
2122 (rmail-error-bad-format))
2123 ;; Move to the next message.
2124 (if (not (re-search-forward delim nil 'move))
2125 (setq stop t)
2126 (goto-char (match-beginning 0))
2127 (forward-char 2))
2128 (setq start (point)))
2129 (rmail-error-bad-format)))
2130 count))))
2132 (defun rmail-get-header-1 (name)
2133 "Subroutine of `rmail-get-header'.
2134 Narrow to header, call `mail-fetch-field' to find header NAME."
2135 (if (search-forward "\n\n" nil t)
2136 (progn
2137 (narrow-to-region (point-min) (point))
2138 (mail-fetch-field name))
2139 (rmail-error-bad-format)))
2141 (defun rmail-get-header (name &optional msgnum)
2142 "Return the value of message header NAME, nil if it has none.
2143 MSGNUM specifies the message number to get it from.
2144 If MSGNUM is nil, use the current message."
2145 (rmail-apply-in-message msgnum 'rmail-get-header-1 name))
2147 (defun rmail-set-header-1 (name value)
2148 "Subroutine of `rmail-set-header'.
2149 Narrow to header, set header NAME to VALUE, replacing existing if present.
2150 VALUE nil means to remove NAME altogether."
2151 (if (search-forward "\n\n" nil t)
2152 (progn
2153 (forward-char -1)
2154 (narrow-to-region (point-min) (point))
2155 (goto-char (point-min))
2156 (if (re-search-forward (concat "^" (regexp-quote name) ":") nil 'move)
2157 (if value
2158 (progn
2159 (delete-region (point) (line-end-position))
2160 (insert " " value))
2161 (delete-region (line-beginning-position)
2162 (line-beginning-position 2)))
2163 (if value (insert name ": " value "\n"))))
2164 (rmail-error-bad-format)))
2166 (defun rmail-set-header (name &optional msgnum value)
2167 "Set message header NAME to VALUE in message number MSGNUM.
2168 If MSGNUM is nil, use the current message. NAME and VALUE are strings.
2169 VALUE may also be nil, meaning to remove the header."
2170 (rmail-apply-in-message msgnum 'rmail-set-header-1 name value)
2171 (with-current-buffer rmail-buffer
2172 ;; Ensure header changes get saved.
2173 ;; (Note replacing a header with an identical copy modifies.)
2174 (set-buffer-modified-p t)
2175 ;; However: don't save in mbox format over a Babyl file
2176 ;; merely because of this.
2177 (rmail-dont-modify-format)))
2179 ;;;; *** Rmail Attributes and Keywords ***
2181 (defun rmail-get-attr-names (&optional msg)
2182 "Return the message attributes in a comma separated string.
2183 MSG specifies the message number to get it from.
2184 If MSG is nil, use the current message."
2185 (let ((value (rmail-get-header rmail-attribute-header msg))
2186 (nmax (length rmail-attr-array))
2187 result temp)
2188 (when value
2189 (if (> (length value) nmax)
2190 (message "Warning: corrupt attribute header in message")
2191 (dotimes (index (length value))
2192 (setq temp (and (not (= ?- (aref value index)))
2193 (nth 1 (aref rmail-attr-array index)))
2194 result
2195 (cond
2196 ((and temp result) (format "%s, %s" result temp))
2197 (temp temp)
2198 (t result)))))
2199 result)))
2201 (defun rmail-get-keywords (&optional msg)
2202 "Return the message keywords in a comma separated string.
2203 MSG, if non-nil, identifies the message number to use.
2204 If nil, that means the current message."
2205 (rmail-get-header rmail-keyword-header msg))
2207 (defun rmail-get-labels (&optional msg)
2208 "Return a string with the labels (attributes and keywords) of msg MSG.
2209 It is put in comma-separated form.
2210 MSG, if non-nil, identifies the message number to use.
2211 If nil, that means the current message."
2212 (or msg (setq msg rmail-current-message))
2213 (let (attr-names keywords)
2214 ;; Combine the message attributes and keywords
2215 ;; into a comma-separated list.
2216 (setq attr-names (rmail-get-attr-names msg)
2217 keywords (rmail-get-keywords msg))
2218 (if (string= keywords "")
2219 (setq keywords nil))
2220 (cond
2221 ;; FIXME ? old rmail did not have spaces in the comma-separated lists.
2222 ((and attr-names keywords) (concat " " attr-names "; " keywords))
2223 (attr-names (concat " " attr-names))
2224 (keywords (concat " " keywords))
2225 (t ""))))
2227 (defun rmail-display-labels ()
2228 "Update the current messages's attributes and keywords in mode line."
2229 (let ((blurb (rmail-get-labels)))
2230 (setq mode-line-process
2231 (format " %d/%d%s"
2232 rmail-current-message rmail-total-messages blurb))))
2234 (defun rmail-get-attr-value (attr state)
2235 "Return the character value for ATTR.
2236 ATTR is a (numeric) index, an offset into the mbox attribute
2237 header value. STATE is one of nil, t, or a character value."
2238 (cond
2239 ((numberp state) state)
2240 ((not state) ?-)
2241 (t (nth 0 (aref rmail-attr-array attr)))))
2243 (defun rmail-set-attribute-1 (attr state)
2244 "Subroutine of `rmail-set-attribute'.
2245 Set Rmail attribute ATTR to STATE in `rmail-attribute-header',
2246 creating the header if necessary. Returns non-nil if a
2247 significant attribute change was made."
2248 (let ((limit (search-forward "\n\n" nil t))
2249 (value (rmail-get-attr-value attr state))
2250 (inhibit-read-only t)
2251 altered)
2252 (goto-char (point-min))
2253 (if (search-forward (concat rmail-attribute-header ": ") limit t)
2254 ;; If this message already records attributes, just change the
2255 ;; value for this one.
2256 (let ((missing (- (+ (point) attr) (line-end-position))))
2257 ;; Position point at this attribute, adding attributes if necessary.
2258 (if (> missing 0)
2259 (progn
2260 (end-of-line)
2261 (insert-char ?- missing)
2262 (backward-char 1))
2263 (forward-char attr))
2264 ;; Change this attribute.
2265 (when (/= value (char-after))
2266 (setq altered t)
2267 (delete-char 1)
2268 (insert value)))
2269 ;; Otherwise add a header line to record the attributes and set
2270 ;; all but this one to no.
2271 (let ((header-value "--------"))
2272 (aset header-value attr value)
2273 (goto-char (if limit (1- limit) (point-max)))
2274 (setq altered (/= value ?-))
2275 (insert rmail-attribute-header ": " header-value "\n")))
2276 altered))
2278 (defun rmail-set-attribute (attr state &optional msgnum)
2279 "Turn an attribute of a message on or off according to STATE.
2280 STATE is either nil or the character (numeric) value associated
2281 with the state (nil represents off and non-nil represents on).
2282 ATTR is either the index number of the attribute, or a string,
2283 both from `rmail-attr-array'. MSGNUM is message number to
2284 change; nil means current message."
2285 (let ((n 0)
2286 (nmax (length rmail-attr-array)))
2287 (while (and (stringp attr)
2288 (< n nmax))
2289 (if (string-equal attr (cadr (aref rmail-attr-array n)))
2290 (setq attr n))
2291 (setq n (1+ n))))
2292 (if (stringp attr)
2293 (error "Unknown attribute `%s'" attr))
2294 ;; Ask for confirmation before setting any attribute except `unseen'
2295 ;; if it would force a format change.
2296 (unless (= attr rmail-unseen-attr-index)
2297 (rmail-modify-format))
2298 (with-current-buffer rmail-buffer
2299 (or msgnum (setq msgnum rmail-current-message))
2300 (when (> msgnum 0)
2301 ;; The "deleted" attribute is also stored in a special vector so
2302 ;; update that too.
2303 (if (= attr rmail-deleted-attr-index)
2304 (rmail-set-message-deleted-p msgnum state))
2305 (if (prog1
2306 (rmail-apply-in-message msgnum 'rmail-set-attribute-1 attr state)
2307 (if (= msgnum rmail-current-message)
2308 (rmail-display-labels)))
2309 ;; Don't save in mbox format over a Babyl file
2310 ;; merely because of a change in `unseen' attribute.
2311 (if (= attr rmail-unseen-attr-index)
2312 (rmail-dont-modify-format)
2313 ;; Otherwise, if we modified the file text via the view buffer,
2314 ;; mark the main buffer modified too.
2315 (set-buffer-modified-p t))))))
2317 (defun rmail-message-attr-p (msg attrs)
2318 "Return non-nil if message number MSG has attributes matching regexp ATTRS."
2319 (let ((value (rmail-get-header rmail-attribute-header msg)))
2320 (and value (string-match attrs value))))
2322 (defun rmail-message-unseen-p (msgnum)
2323 "Return non-nil if message number MSGNUM has the unseen attribute."
2324 (rmail-message-attr-p msgnum "......U"))
2326 ;; FIXME rmail-get-labels does some formatting (eg leading space, `;'
2327 ;; between attributes and labels), so this might not do what you want.
2328 ;; Eg see rmail-sort-by-labels. rmail-get-labels could have an
2329 ;; optional `noformat' argument.
2330 (defun rmail-message-labels-p (msg labels)
2331 "Return non-nil if message number MSG has labels matching regexp LABELS."
2332 (string-match labels (rmail-get-labels msg)))
2334 ;;;; *** Rmail Message Selection And Support ***
2336 (defun rmail-msgend (n)
2337 "Return the end position for message number N."
2338 (marker-position (aref rmail-message-vector (1+ n))))
2340 (defun rmail-msgbeg (n)
2341 "Return the start position for message number N."
2342 (marker-position (aref rmail-message-vector n)))
2344 (defun rmail-apply-in-message (msgnum function &rest args)
2345 "Call FUNCTION on ARGS while narrowed to message MSGNUM.
2346 Point is at the start of the message.
2347 This returns what the call to FUNCTION returns.
2348 If MSGNUM is nil, use the current message."
2349 (with-current-buffer rmail-buffer
2350 (or msgnum (setq msgnum rmail-current-message))
2351 (when (> msgnum 0)
2352 (let (msgbeg msgend)
2353 (setq msgbeg (rmail-msgbeg msgnum))
2354 (setq msgend (rmail-msgend msgnum))
2355 ;; All access to the rmail-buffer's local variables is now finished...
2356 (save-excursion
2357 ;; ... so it is ok to go to a different buffer.
2358 (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
2359 (save-excursion
2360 (save-restriction
2361 (widen)
2362 (goto-char msgbeg)
2363 (narrow-to-region msgbeg msgend)
2364 (apply function args))))))))
2366 ;; Unused (save for commented out code in rmailedit.el).
2367 (defun rmail-widen-to-current-msgbeg (function)
2368 "Call FUNCTION with point at start of internal data of current message.
2369 Assumes that bounds were previously narrowed to display the message in Rmail.
2370 The bounds are widened enough to move point where desired, then narrowed
2371 again afterward.
2373 FUNCTION may not change the visible text of the message, but it may
2374 change the invisible header text."
2375 (save-excursion
2376 (unwind-protect
2377 (progn
2378 (narrow-to-region (rmail-msgbeg rmail-current-message)
2379 (point-max))
2380 (goto-char (point-min))
2381 (funcall function))
2382 ;; Note: we don't use save-restriction because that does not work right
2383 ;; if changes are made outside the saved restriction
2384 ;; before that restriction is restored.
2385 (narrow-to-region (rmail-msgbeg rmail-current-message)
2386 (rmail-msgend rmail-current-message)))))
2388 ;; Manage the message vectors and counters.
2390 (defun rmail-forget-messages ()
2391 (unwind-protect
2392 (if (vectorp rmail-message-vector)
2393 (let* ((v rmail-message-vector)
2394 (n (length v)))
2395 (dotimes (i n)
2396 (if (aref v i)
2397 (move-marker (aref v i) nil)))))
2398 (setq rmail-message-vector nil)
2399 (setq rmail-msgref-vector nil)
2400 (setq rmail-deleted-vector nil)))
2402 (defun rmail-maybe-set-message-counters ()
2403 (if (not (and rmail-deleted-vector
2404 rmail-message-vector
2405 rmail-current-message
2406 rmail-total-messages))
2407 (rmail-set-message-counters)))
2409 (defun rmail-count-new-messages (&optional nomsg)
2410 "Count the number of new messages.
2411 The buffer should be narrowed to include only the new messages.
2412 Output a helpful message unless NOMSG is non-nil."
2413 (let* ((case-fold-search nil)
2414 (total-messages 0)
2415 (messages-head nil)
2416 (deleted-head nil))
2417 (or nomsg (message "Counting new messages..."))
2418 (goto-char (point-max))
2419 ;; Put at the end of messages-head
2420 ;; the entry for message N+1, which marks
2421 ;; the end of message N. (N = number of messages).
2422 (setq messages-head (list (point-marker)))
2423 (rmail-set-message-counters-counter (point-min))
2424 (setq rmail-current-message (1+ rmail-total-messages))
2425 (setq rmail-total-messages
2426 (+ rmail-total-messages total-messages))
2427 (setq rmail-message-vector
2428 (vconcat rmail-message-vector (cdr messages-head)))
2429 (aset rmail-message-vector
2430 rmail-current-message (car messages-head))
2431 (setq rmail-deleted-vector
2432 (concat rmail-deleted-vector deleted-head))
2433 (setq rmail-summary-vector
2434 (vconcat rmail-summary-vector (make-vector total-messages nil)))
2435 (setq rmail-msgref-vector
2436 (vconcat rmail-msgref-vector (make-vector total-messages nil)))
2437 ;; Fill in the new elements of rmail-msgref-vector.
2438 (let ((i (1+ (- rmail-total-messages total-messages))))
2439 (while (<= i rmail-total-messages)
2440 (aset rmail-msgref-vector i (list i))
2441 (setq i (1+ i))))
2442 (goto-char (point-min))
2443 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
2445 (defun rmail-set-message-counters ()
2446 (rmail-forget-messages)
2447 (save-excursion
2448 (save-restriction
2449 (widen)
2450 (let* ((point-save (point))
2451 (total-messages 0)
2452 (messages-after-point)
2453 (case-fold-search nil)
2454 (messages-head nil)
2455 (deleted-head nil))
2456 ;; Determine how many messages follow point.
2457 (message "Counting messages...")
2458 (goto-char (point-max))
2459 ;; Put at the end of messages-head
2460 ;; the entry for message N+1, which marks
2461 ;; the end of message N. (N = number of messages).
2462 (setq messages-head (list (point-marker)))
2463 (setq messages-after-point
2464 (or (rmail-set-message-counters-counter (min (point) point-save))
2467 (setq rmail-total-messages total-messages)
2468 (setq rmail-current-message
2469 (min total-messages
2470 (max 1 (- total-messages messages-after-point))))
2472 ;; Make an element 0 in rmail-message-vector and rmail-deleted-vector
2473 ;; which will never be used.
2474 (push nil messages-head)
2475 (push ?0 deleted-head)
2476 (setq rmail-message-vector (apply 'vector messages-head)
2477 rmail-deleted-vector (concat deleted-head))
2479 (setq rmail-summary-vector (make-vector rmail-total-messages nil)
2480 rmail-msgref-vector (make-vector (1+ rmail-total-messages) nil))
2482 (let ((i 0))
2483 (while (<= i rmail-total-messages)
2484 (aset rmail-msgref-vector i (list i))
2485 (setq i (1+ i))))
2486 (let ((i 0))
2487 (while (<= i rmail-total-messages)
2488 (rmail-set-message-deleted-p i (rmail-message-attr-p i ".D"))
2489 (setq i (1+ i))))
2490 (message "Counting messages...done")))))
2493 (defsubst rmail-collect-deleted (message-end)
2494 "Collect the message deletion flags for each message.
2495 MESSAGE-END is the buffer position corresponding to the end of
2496 the message. Point is at the beginning of the message."
2497 ;; NOTE: This piece of code will be executed on a per-message basis.
2498 ;; In the face of thousands of messages, it has to be as fast as
2499 ;; possible, hence some brute force constant use is employed in
2500 ;; addition to inlining.
2501 (save-excursion
2502 (setq deleted-head
2503 (cons (if (and (search-forward (concat rmail-attribute-header ": ") message-end t)
2504 (looking-at "?D"))
2506 ?\s) deleted-head))))
2508 (defun rmail-set-message-counters-counter (&optional spot-to-find)
2509 "Collect the start positions of messages in list `messages-head'.
2510 Return the number of messages after the one containing SPOT-TO-FIND."
2511 (let ((start (point))
2512 messages-after-spot)
2513 (while (search-backward "\n\nFrom " nil t)
2514 (forward-char 2)
2515 (when (looking-at rmail-unix-mail-delimiter)
2516 (if (and (<= (point) spot-to-find)
2517 (null messages-after-spot))
2518 (setq messages-after-spot total-messages))
2519 (rmail-collect-deleted start)
2520 (setq messages-head (cons (point-marker) messages-head)
2521 total-messages (1+ total-messages)
2522 start (point))
2523 ;; Show progress after every 20 messages or so.
2524 (if (zerop (% total-messages 20))
2525 (message "Counting messages...%d" total-messages))))
2526 ;; Handle the first message, maybe.
2527 (goto-char (point-min))
2528 (unless (not (looking-at rmail-unix-mail-delimiter))
2529 (if (and (<= (point) spot-to-find)
2530 (null messages-after-spot))
2531 (setq messages-after-spot total-messages))
2532 (rmail-collect-deleted start)
2533 (setq messages-head (cons (point-marker) messages-head)
2534 total-messages (1+ total-messages)))
2535 messages-after-spot))
2537 ;; Display a message.
2539 ;;;; *** Rmail Message Formatting and Header Manipulation ***
2541 ;; This is used outside of rmail.
2542 (defun rmail-msg-is-pruned ()
2543 "Return nil if the current message is showing full headers."
2544 (with-current-buffer (if (rmail-buffers-swapped-p) rmail-view-buffer
2545 rmail-buffer)
2546 (eq rmail-header-style 'normal)))
2548 (defun rmail-toggle-header (&optional arg)
2549 "Toggle between showing full and normal message headers.
2550 With optional integer ARG, show the normal message header if ARG
2551 is greater than zero; otherwise, show it in full."
2552 (interactive "P")
2553 (let ((rmail-header-style
2554 (if (numberp arg)
2555 (if (> arg 0) 'normal 'full)
2556 (if (rmail-msg-is-pruned) 'full 'normal))))
2557 (rmail-show-message)))
2559 (defun rmail-beginning-of-message ()
2560 "Show current message starting from the beginning."
2561 (interactive)
2562 (let ((rmail-show-message-hook '((lambda () (goto-char (point-min)))))
2563 (rmail-header-style (with-current-buffer (if (rmail-buffers-swapped-p)
2564 rmail-view-buffer
2565 rmail-buffer)
2566 rmail-header-style)))
2567 (rmail-show-message rmail-current-message)))
2569 (defun rmail-end-of-message ()
2570 "Show bottom of current message."
2571 (interactive)
2572 (let ((rmail-show-message-hook '((lambda ()
2573 (goto-char (point-max))
2574 (recenter (1- (window-height))))))
2575 (rmail-header-style (with-current-buffer (if (rmail-buffers-swapped-p)
2576 rmail-view-buffer
2577 rmail-buffer)
2578 rmail-header-style)))
2579 (rmail-show-message rmail-current-message)))
2581 (defun rmail-unknown-mail-followup-to ()
2582 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2583 Ask the user whether to add that list name to `mail-mailing-lists'."
2584 ;; FIXME s-r not needed? Use rmail-get-header?
2585 ;; We have not narrowed to the headers at ths point?
2586 (save-restriction
2587 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t)))
2588 (when mail-followup-to
2589 (let ((addresses
2590 (split-string
2591 (mail-strip-quoted-names mail-followup-to)
2592 ",[[:space:]]+" t)))
2593 (dolist (addr addresses)
2594 (when (and (not (member addr mail-mailing-lists))
2595 (not
2596 ;; taken from rmailsum.el
2597 (string-match
2598 (or rmail-user-mail-address-regexp
2599 (concat "^\\("
2600 (regexp-quote (user-login-name))
2601 "\\($\\|@\\)\\|"
2602 (regexp-quote
2603 (or user-mail-address
2604 (concat (user-login-name) "@"
2605 (or mail-host-address
2606 (system-name)))))
2607 "\\>\\)"))
2608 addr))
2609 (y-or-n-p
2610 (format "Add `%s' to `mail-mailing-lists'? "
2611 addr)))
2612 (customize-save-variable 'mail-mailing-lists
2613 (cons addr mail-mailing-lists)))))))))
2615 (defun rmail-widen ()
2616 "Display the entire mailbox file."
2617 (interactive)
2618 (rmail-swap-buffers-maybe)
2619 (widen))
2621 (defun rmail-no-mail-p ()
2622 "Return nil if there is mail, else \"No mail.\"."
2623 (if (zerop rmail-total-messages)
2624 (save-excursion
2625 ;; Eg we deleted all the messages, so remove the old N/M mark.
2626 (with-current-buffer rmail-buffer (setq mode-line-process nil))
2627 (with-current-buffer rmail-view-buffer
2628 (erase-buffer)
2629 "No mail."))))
2631 (defun rmail-show-message (&optional n no-summary)
2632 "Show message number N (prefix argument), counting from start of file.
2633 If summary buffer is currently displayed, update current message there also.
2634 N defaults to the current message."
2635 (interactive "p")
2636 (or (eq major-mode 'rmail-mode)
2637 (switch-to-buffer rmail-buffer))
2638 ;; FIXME: Why do we swap the raw data back in?
2639 (rmail-swap-buffers-maybe)
2640 (rmail-maybe-set-message-counters)
2641 (widen)
2642 (let ((blurb (rmail-show-message-1 n)))
2643 (or (zerop rmail-total-messages)
2644 (progn
2645 (when mail-mailing-lists
2646 (rmail-unknown-mail-followup-to))
2647 (if transient-mark-mode (deactivate-mark))
2648 ;; If there is a summary buffer, try to move to this message
2649 ;; in that buffer. But don't complain if this message is
2650 ;; not mentioned in the summary. Don't do this at all if we
2651 ;; were called on behalf of cursor motion in the summary
2652 ;; buffer.
2653 (and (rmail-summary-exists) (not no-summary)
2654 (let ((curr-msg rmail-current-message))
2655 (rmail-select-summary
2656 (rmail-summary-goto-msg curr-msg t t))))
2657 (with-current-buffer rmail-buffer
2658 (rmail-auto-file))))
2659 (if blurb
2660 (message blurb))))
2662 (defun rmail-is-text-p ()
2663 "Return t if the region contains a text message, nil otherwise."
2664 (save-excursion
2665 (let ((text-regexp "\\(text\\|message\\)/")
2666 (content-type-header (mail-fetch-field "content-type")))
2667 ;; The message is text if either there is no content type header
2668 ;; (a default of "text/plain; charset=US-ASCII" is assumed) or
2669 ;; the base content type is either text or message.
2670 (or (not content-type-header)
2671 (string-match text-regexp content-type-header)))))
2673 (defcustom rmail-show-message-verbose-min 200000
2674 "Message size at which to show progress messages for displaying it."
2675 :type 'integer
2676 :group 'rmail
2677 :version "23.1")
2679 (defun rmail-show-message-1 (&optional msg)
2680 "Show message MSG (default: current message) using `rmail-view-buffer'.
2681 Return text to display in the minibuffer if MSG is out of
2682 range (displaying a reasonable choice as well), nil otherwise.
2683 The current mail message becomes the message displayed."
2684 (let ((mbox-buf rmail-buffer)
2685 (view-buf rmail-view-buffer)
2686 blurb beg end body-start coding-system character-coding
2687 is-text-message header-style)
2688 (if (not msg)
2689 (setq msg rmail-current-message))
2690 (unless (setq blurb (rmail-no-mail-p))
2691 (cond ((<= msg 0)
2692 (setq msg 1
2693 rmail-current-message 1
2694 blurb "No previous message"))
2695 ((> msg rmail-total-messages)
2696 (setq msg rmail-total-messages
2697 rmail-current-message rmail-total-messages
2698 blurb "No following message"))
2699 (t (setq rmail-current-message msg)))
2700 (with-current-buffer rmail-buffer
2701 (setq header-style rmail-header-style)
2702 ;; Mark the message as seen, but preserve buffer modified flag.
2703 (let ((modiff (buffer-modified-p)))
2704 (rmail-set-attribute rmail-unseen-attr-index nil)
2705 (unless modiff
2706 (restore-buffer-modified-p modiff)))
2707 ;; bracket the message in the mail
2708 ;; buffer and determine the coding system the transfer encoding.
2709 (rmail-swap-buffers-maybe)
2710 (setq beg (rmail-msgbeg msg)
2711 end (rmail-msgend msg))
2712 (when (> (- end beg) rmail-show-message-verbose-min)
2713 (message "Showing message %d" msg))
2714 (narrow-to-region beg end)
2715 (goto-char beg)
2716 (with-current-buffer rmail-view-buffer
2717 ;; We give the view buffer a buffer-local value of
2718 ;; rmail-header-style based on the binding in effect when
2719 ;; this function is called; `rmail-toggle-headers' can
2720 ;; inspect this value to determine how to toggle.
2721 (set (make-local-variable 'rmail-header-style) header-style))
2722 (if (and rmail-enable-mime
2723 rmail-show-mime-function
2724 (re-search-forward "mime-version: 1.0" nil t))
2725 (let ((rmail-buffer mbox-buf)
2726 (rmail-view-buffer view-buf))
2727 (funcall rmail-show-mime-function))
2728 (setq body-start (search-forward "\n\n" nil t))
2729 (narrow-to-region beg (point))
2730 (goto-char beg)
2731 (save-excursion
2732 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t)
2733 (setq coding-system (intern (match-string 1)))
2734 (setq coding-system (rmail-get-coding-system))))
2735 (setq character-coding (mail-fetch-field "content-transfer-encoding")
2736 is-text-message (rmail-is-text-p))
2737 (if character-coding
2738 (setq character-coding (downcase character-coding)))
2739 (narrow-to-region beg end)
2740 ;; Decode the message body into an empty view buffer using a
2741 ;; unibyte temporary buffer where the character decoding takes
2742 ;; place.
2743 (with-current-buffer rmail-view-buffer
2744 (erase-buffer))
2745 (if (null character-coding)
2746 ;; Do it directly since that is fast.
2747 (rmail-decode-region body-start end coding-system view-buf)
2748 ;; Can this be done directly, skipping the temp buffer?
2749 (with-temp-buffer
2750 (set-buffer-multibyte nil)
2751 (insert-buffer-substring mbox-buf body-start end)
2752 (cond
2753 ((string= character-coding "quoted-printable")
2754 ;; See bug#5441.
2755 (or (mail-unquote-printable-region (point-min) (point-max)
2756 nil t 'unibyte)
2757 (message "Malformed MIME quoted-printable message")))
2758 ((and (string= character-coding "base64") is-text-message)
2759 (condition-case err
2760 (base64-decode-region (point-min) (point-max))
2761 (error (message "%s" (cdr err)))))
2762 ((eq character-coding 'uuencode)
2763 (error "uuencoded messages are not supported yet"))
2764 (t))
2765 (rmail-decode-region (point-min) (point-max)
2766 coding-system view-buf)))
2767 (with-current-buffer rmail-view-buffer
2768 ;; Prepare the separator (blank line) before the body.
2769 (goto-char (point-min))
2770 (insert "\n")
2771 ;; Unquote quoted From lines
2772 (while (re-search-forward "^>+From " nil t)
2773 (beginning-of-line)
2774 (delete-char 1)
2775 (forward-line))
2776 (goto-char (point-min)))
2777 ;; Copy the headers to the front of the message view buffer.
2778 (rmail-copy-headers beg end)
2779 ;; Decode any RFC2047 encoded message headers.
2780 (if rmail-enable-mime
2781 (with-current-buffer rmail-view-buffer
2782 (rfc2047-decode-region
2783 (point-min)
2784 (progn
2785 (search-forward "\n\n" nil 'move)
2786 (point))))))
2787 ;; highlight the message, activate any URL like text and add
2788 ;; special highlighting for and quoted material.
2789 (with-current-buffer rmail-view-buffer
2790 (goto-char (point-min))
2791 (rmail-highlight-headers)
2792 ;(rmail-activate-urls)
2793 ;(rmail-process-quoted-material)
2795 ;; Update the mode-line with message status information and swap
2796 ;; the view buffer/mail buffer contents.
2797 (rmail-display-labels)
2798 (rmail-swap-buffers)
2799 (setq rmail-buffer-swapped t)
2800 (run-hooks 'rmail-show-message-hook)
2801 (when (> (- end beg) rmail-show-message-verbose-min)
2802 (message "Showing message %d...done" msg))))
2803 blurb))
2805 (defun rmail-copy-headers (beg end &optional ignored-headers)
2806 "Copy displayed header fields to the message viewer buffer.
2807 BEG and END marks the start and end positions of the message in
2808 the mbox buffer. If the optional argument IGNORED-HEADERS is
2809 non-nil, ignore all header fields whose names match that regexp.
2810 Otherwise, if `rmail-displayed-headers' is non-nil, copy only
2811 those header fields whose names match that regexp. Otherwise,
2812 copy all header fields whose names do not match
2813 `rmail-ignored-headers' (unless they also match
2814 `rmail-nonignored-headers'). Moves point in the message viewer
2815 buffer to the end of the headers."
2816 (let ((header-start-regexp "\n[^ \t]")
2817 lim)
2818 (with-current-buffer rmail-buffer
2819 (when (search-forward "\n\n" nil t)
2820 (forward-char -1)
2821 (save-restriction
2822 ;; Put point right after the From header line.
2823 (narrow-to-region beg (point))
2824 (goto-char (point-min))
2825 (unless (re-search-forward header-start-regexp nil t)
2826 (rmail-error-bad-format))
2827 (forward-char -1)
2828 (cond
2829 ;; Handle the case where all headers should be copied.
2830 ((eq rmail-header-style 'full)
2831 (prepend-to-buffer rmail-view-buffer beg (point-max))
2832 ;; rmail-show-message-1 expects this function to leave point
2833 ;; at the end of the headers.
2835 (let ((len (- (point-max) beg)))
2836 (with-current-buffer rmail-view-buffer
2837 (goto-char (1+ len)))))
2839 ;; Handle the case where the headers matching the displayed
2840 ;; headers regexp should be copied.
2841 ((and rmail-displayed-headers (null ignored-headers))
2842 (while (not (eobp))
2843 (save-excursion
2844 (setq lim (if (re-search-forward header-start-regexp nil t)
2845 (1+ (match-beginning 0))
2846 (point-max))))
2847 (when (looking-at rmail-displayed-headers)
2848 (append-to-buffer rmail-view-buffer (point) lim))
2849 (goto-char lim)))
2850 ;; Handle the ignored headers.
2851 ((or ignored-headers (setq ignored-headers rmail-ignored-headers))
2852 (while (and ignored-headers (not (eobp)))
2853 (save-excursion
2854 (setq lim (if (re-search-forward header-start-regexp nil t)
2855 (1+ (match-beginning 0))
2856 (point-max))))
2857 (if (and (looking-at ignored-headers)
2858 (not (looking-at rmail-nonignored-headers)))
2859 (goto-char lim)
2860 (append-to-buffer rmail-view-buffer (point) lim)
2861 (goto-char lim))))
2862 (t (error "No headers selected for display!"))))))))
2864 (defun rmail-redecode-body (coding)
2865 "Decode the body of the current message using coding system CODING.
2866 This is useful with mail messages that have malformed or missing
2867 charset= headers.
2869 This function assumes that the current message is already decoded
2870 and displayed in the RMAIL buffer, but the coding system used to
2871 decode it was incorrect. It then decodes the message again,
2872 using the coding system CODING."
2873 (interactive "zCoding system for re-decoding this message: ")
2874 (when (not rmail-enable-mime)
2875 (with-current-buffer rmail-buffer
2876 (rmail-swap-buffers-maybe)
2877 (save-restriction
2878 (widen)
2879 (let ((msgbeg (rmail-msgbeg rmail-current-message))
2880 (msgend (rmail-msgend rmail-current-message))
2881 (buffer-read-only nil)
2882 body-start x-coding-header old-coding)
2883 (narrow-to-region msgbeg msgend)
2884 (goto-char (point-min))
2885 (unless (setq body-start (search-forward "\n\n" (point-max) 1))
2886 (error "No message body"))
2888 (save-restriction
2889 ;; Narrow to headers
2890 (narrow-to-region (point-min) body-start)
2891 (setq x-coding-header (goto-char (point-min)))
2892 (if (not (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t))
2893 (setq old-coding (rmail-get-coding-system))
2894 (setq old-coding (intern (match-string 1)))
2895 (setq x-coding-header (point)))
2896 (check-coding-system old-coding)
2897 ;; Make sure the new coding system uses the same EOL
2898 ;; conversion, to prevent ^M characters from popping up
2899 ;; all over the place.
2900 (let ((eol-type (coding-system-eol-type old-coding)))
2901 (if (numberp eol-type)
2902 (setq coding
2903 (coding-system-change-eol-conversion coding eol-type))))
2904 (when (not (coding-system-equal
2905 (coding-system-base old-coding)
2906 (coding-system-base coding)))
2907 ;; Rewrite the coding-system header.
2908 (goto-char x-coding-header)
2909 (if (> (point) (point-min))
2910 (delete-region (line-beginning-position) (point))
2911 (forward-line)
2912 (insert "\n")
2913 (forward-line -1))
2914 (insert "X-Coding-System: "
2915 (symbol-name coding))))
2916 (rmail-show-message))))))
2918 (defun rmail-highlight-headers ()
2919 "Highlight the headers specified by `rmail-highlighted-headers'.
2920 Uses the face specified by `rmail-highlight-face'."
2921 (if rmail-highlighted-headers
2922 (save-excursion
2923 (search-forward "\n\n" nil 'move)
2924 (save-restriction
2925 (narrow-to-region (point-min) (point))
2926 (let ((case-fold-search t)
2927 (inhibit-read-only t)
2928 ;; When rmail-highlight-face is removed, just
2929 ;; use 'rmail-highlight here.
2930 (face (or rmail-highlight-face
2931 (if (face-differs-from-default-p 'bold)
2932 'bold 'highlight)))
2933 ;; List of overlays to reuse.
2934 (overlays rmail-overlay-list))
2935 (goto-char (point-min))
2936 (while (re-search-forward rmail-highlighted-headers nil t)
2937 (skip-chars-forward " \t")
2938 (let ((beg (point))
2939 overlay)
2940 (while (progn (forward-line 1)
2941 (looking-at "[ \t]")))
2942 ;; Back up over newline, then trailing spaces or tabs
2943 (forward-char -1)
2944 (while (member (preceding-char) '(? ?\t))
2945 (forward-char -1))
2946 (if overlays
2947 ;; Reuse an overlay we already have.
2948 (progn
2949 (setq overlay (car overlays)
2950 overlays (cdr overlays))
2951 (overlay-put overlay 'face face)
2952 (move-overlay overlay beg (point)))
2953 ;; Make a new overlay and add it to
2954 ;; rmail-overlay-list.
2955 (setq overlay (make-overlay beg (point)))
2956 (overlay-put overlay 'face face)
2957 (setq rmail-overlay-list
2958 (cons overlay rmail-overlay-list))))))))))
2960 (defun rmail-auto-file ()
2961 "Automatically move a message into another sfolder based on criteria.
2962 This moves messages according to `rmail-automatic-folder-directives'.
2963 It only does something in the folder that `rmail-file-name' specifies.
2964 The function `rmail-show-message' calls this whenever it shows a message.
2965 This leaves a message alone if it already has the `filed' attribute."
2966 (if (or (zerop rmail-total-messages)
2967 (rmail-message-attr-p rmail-current-message "...F")
2968 (not (string= (buffer-file-name)
2969 (expand-file-name rmail-file-name))))
2970 ;; Do nothing if the message has already been filed or if there
2971 ;; are no messages.
2973 ;; Find out some basics (common fields)
2974 (let ((from (mail-fetch-field "from"))
2975 (subj (mail-fetch-field "subject"))
2976 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
2977 (d rmail-automatic-folder-directives)
2978 (directive-loop nil)
2979 (folder nil))
2980 (while d
2981 (setq folder (car (car d))
2982 directive-loop (cdr (car d)))
2983 (while (and (car directive-loop)
2984 (let ((f (cond
2985 ((string= (downcase (car directive-loop)) "from")
2986 from)
2987 ((string= (downcase (car directive-loop)) "to")
2989 ((string= (downcase (car directive-loop))
2990 "subject") subj)
2991 (t (mail-fetch-field (car directive-loop))))))
2992 ;; FIXME - shouldn't this ignore case?
2993 (and f (string-match (car (cdr directive-loop)) f))))
2994 (setq directive-loop (cdr (cdr directive-loop))))
2995 ;; If there are no directives left, then it was a complete match.
2996 (if (null directive-loop)
2997 (if (null folder)
2998 (rmail-delete-forward)
2999 (if (string= "/dev/null" folder)
3000 (rmail-delete-message)
3001 (rmail-output folder 1)
3002 (setq d nil))))
3003 (setq d (cdr d))))))
3005 ;; Simple message motion commands.
3007 (defun rmail-next-message (n)
3008 "Show following message whether deleted or not.
3009 With prefix arg N, moves forward N messages, or backward if N is negative."
3010 (interactive "p")
3011 (set-buffer rmail-buffer)
3012 (rmail-maybe-set-message-counters)
3013 (rmail-show-message (+ rmail-current-message n)))
3015 (defun rmail-previous-message (n)
3016 "Show previous message whether deleted or not.
3017 With prefix arg N, moves backward N messages, or forward if N is negative."
3018 (interactive "p")
3019 (rmail-next-message (- n)))
3021 (defun rmail-next-undeleted-message (n)
3022 "Show following non-deleted message.
3023 With prefix arg N, moves forward N non-deleted messages,
3024 or backward if N is negative.
3026 Returns t if a new message is being shown, nil otherwise."
3027 (interactive "p")
3028 (set-buffer rmail-buffer)
3029 (rmail-maybe-set-message-counters)
3030 (let ((lastwin rmail-current-message)
3031 (current rmail-current-message))
3032 (while (and (> n 0) (< current rmail-total-messages))
3033 (setq current (1+ current))
3034 (if (not (rmail-message-deleted-p current))
3035 (setq lastwin current n (1- n))))
3036 (while (and (< n 0) (> current 1))
3037 (setq current (1- current))
3038 (if (not (rmail-message-deleted-p current))
3039 (setq lastwin current n (1+ n))))
3040 (if (/= lastwin rmail-current-message)
3041 (progn (rmail-show-message lastwin)
3043 (if (< n 0)
3044 (message "No previous nondeleted message"))
3045 (if (> n 0)
3046 (message "No following nondeleted message"))
3047 nil)))
3049 (defun rmail-previous-undeleted-message (n)
3050 "Show previous non-deleted message.
3051 With prefix argument N, moves backward N non-deleted messages,
3052 or forward if N is negative."
3053 (interactive "p")
3054 (rmail-next-undeleted-message (- n)))
3056 (defun rmail-first-message ()
3057 "Show first message in file."
3058 (interactive)
3059 (rmail-maybe-set-message-counters)
3060 (rmail-show-message 1))
3062 (defun rmail-last-message ()
3063 "Show last message in file."
3064 (interactive)
3065 (rmail-maybe-set-message-counters)
3066 (rmail-show-message rmail-total-messages))
3068 (defun rmail-next-error-move (msg-pos bad-marker)
3069 "Move to an error locus (probably grep hit) in an Rmail buffer.
3070 MSG-POS is a marker pointing at the error message in the grep buffer.
3071 BAD-MARKER is a marker that ought to point at where to move to,
3072 but probably is garbage."
3074 (let* ((message-loc (compilation--message->loc
3075 (get-text-property msg-pos 'compilation-message
3076 (marker-buffer msg-pos))))
3077 (column (car message-loc))
3078 (linenum (cadr message-loc))
3079 line-text
3081 msgnum msgbeg msgend
3082 header-field
3083 line-number-within)
3085 ;; Look at the whole Rmail file.
3086 (rmail-swap-buffers-maybe)
3088 (save-restriction
3089 (widen)
3090 (save-excursion
3091 ;; Find the line that the error message points at.
3092 (goto-char (point-min))
3093 (forward-line (1- linenum))
3094 (setq pos (point))
3096 ;; Find the text at the start of the line,
3097 ;; before the first = sign.
3098 ;; This text has a good chance of being also in the
3099 ;; decoded message.
3100 (save-excursion
3101 (skip-chars-forward "^=\n")
3102 (setq line-text (buffer-substring pos (point))))
3104 ;; Find which message this position is in,
3105 ;; and the limits of that message.
3106 (setq msgnum (rmail-what-message pos))
3107 (setq msgbeg (rmail-msgbeg msgnum))
3108 (setq msgend (rmail-msgend msgnum))
3110 ;; Find which header this locus is in,
3111 ;; or if it's in the message body,
3112 ;; and the line-based position within that.
3113 (goto-char msgbeg)
3114 (let ((header-end msgend))
3115 (if (search-forward "\n\n" nil t)
3116 (setq header-end (point)))
3117 (if (>= pos header-end)
3118 (setq line-number-within
3119 (count-lines header-end pos))
3120 (goto-char pos)
3121 (unless (looking-at "^[^ \t]")
3122 (re-search-backward "^[^ \t]"))
3123 (looking-at "[^:\n]*[:\n]")
3124 (setq header-field (match-string 0)
3125 line-number-within (count-lines (point) pos))))))
3127 ;; Display the right message.
3128 (rmail-show-message msgnum)
3130 ;; Move to the right position within the displayed message.
3131 ;; Or at least try. The decoded message's lines may not
3132 ;; correspond to the lines in the inbox file.
3133 (goto-char (point-min))
3134 (if header-field
3135 (progn
3136 (re-search-forward (concat "^" (regexp-quote header-field)) nil t)
3137 (forward-line line-number-within))
3138 (search-forward "\n\n" nil t)
3139 (if (re-search-forward (concat "^" (regexp-quote line-text)) nil t)
3140 (goto-char (match-beginning 0))))
3141 (if (eobp)
3142 ;; If the decoded message doesn't have enough lines,
3143 ;; go to the beginning rather than the end.
3144 (goto-char (point-min))
3145 ;; Otherwise, go to the right column.
3146 (if column
3147 (forward-char column)))))
3149 (defun rmail-what-message (&optional pos)
3150 "Return message number POS (or point) is in."
3151 (let* ((high rmail-total-messages)
3152 (mid (/ high 2))
3153 (low 1)
3154 (where (or pos
3155 (with-current-buffer (if (rmail-buffers-swapped-p)
3156 rmail-view-buffer
3157 (current-buffer))
3158 (point)))))
3159 (while (> (- high low) 1)
3160 (if (>= where (rmail-msgbeg mid))
3161 (setq low mid)
3162 (setq high mid))
3163 (setq mid (+ low (/ (- high low) 2))))
3164 (if (>= where (rmail-msgbeg high)) high low)))
3166 ;; Searching in Rmail file.
3168 (defun rmail-search-message (msg regexp)
3169 "Return non-nil, if for message number MSG, regexp REGEXP matches."
3170 ;; This is adequate because its only caller, rmail-search,
3171 ;; unswaps the buffers.
3172 (goto-char (rmail-msgbeg msg))
3173 (if (and rmail-enable-mime
3174 rmail-search-mime-message-function)
3175 (funcall rmail-search-mime-message-function msg regexp)
3176 (re-search-forward regexp (rmail-msgend msg) t)))
3178 (defvar rmail-search-last-regexp nil)
3179 (defun rmail-search (regexp &optional n)
3180 "Show message containing next match for REGEXP (but not the current msg).
3181 Prefix argument gives repeat count; negative argument means search
3182 backwards (through earlier messages).
3183 Interactively, empty argument means use same regexp used last time."
3184 (interactive
3185 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
3186 (prompt
3187 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
3188 regexp)
3189 (setq prompt
3190 (concat prompt
3191 (if rmail-search-last-regexp
3192 (concat ", default "
3193 rmail-search-last-regexp "): ")
3194 "): ")))
3195 (setq regexp (read-string prompt))
3196 (cond ((not (equal regexp ""))
3197 (setq rmail-search-last-regexp regexp))
3198 ((not rmail-search-last-regexp)
3199 (error "No previous Rmail search string")))
3200 (list rmail-search-last-regexp
3201 (prefix-numeric-value current-prefix-arg))))
3202 (or n (setq n 1))
3203 (message "%sRmail search for %s..."
3204 (if (< n 0) "Reverse " "")
3205 regexp)
3206 (set-buffer rmail-buffer)
3207 (let ((orig-message rmail-current-message)
3208 (msg rmail-current-message)
3209 (reversep (< n 0))
3210 (opoint (if (rmail-buffers-swapped-p) (point)))
3211 found)
3212 (rmail-swap-buffers-maybe)
3213 (rmail-maybe-set-message-counters)
3214 (widen)
3215 (unwind-protect
3216 (while (/= n 0)
3217 ;; Check messages one by one, advancing message number up or
3218 ;; down but searching forward through each message.
3219 (if reversep
3220 (while (and (null found) (> msg 1))
3221 (setq msg (1- msg)
3222 found (rmail-search-message msg regexp)))
3223 (while (and (null found) (< msg rmail-total-messages))
3224 (setq msg (1+ msg)
3225 found (rmail-search-message msg regexp))))
3226 (setq n (+ n (if reversep 1 -1))))
3227 (if found
3228 (progn
3229 (rmail-show-message msg)
3230 ;; Search forward (if this is a normal search) or backward
3231 ;; (if this is a reverse search) through this message to
3232 ;; position point. This search may fail because REGEXP
3233 ;; was found in the hidden portion of this message. In
3234 ;; that case, move point to the beginning of visible
3235 ;; portion.
3236 (if reversep
3237 (progn
3238 (goto-char (point-max))
3239 (re-search-backward regexp nil 'move))
3240 (goto-char (point-min))
3241 (re-search-forward regexp nil t))
3242 (message "%sRmail search for %s...done"
3243 (if reversep "Reverse " "")
3244 regexp))
3245 (rmail-show-message orig-message)
3246 (if opoint (goto-char opoint))
3247 (ding)
3248 (message "Search failed: %s" regexp)))))
3250 (defun rmail-search-backwards (regexp &optional n)
3251 "Show message containing previous match for REGEXP.
3252 Prefix argument gives repeat count; negative argument means search
3253 forward (through later messages).
3254 Interactively, empty argument means use same regexp used last time."
3255 (interactive
3256 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
3257 (prompt
3258 (concat (if reversep "Reverse " "") "Rmail search (regexp"))
3259 regexp)
3260 (setq prompt
3261 (concat prompt
3262 (if rmail-search-last-regexp
3263 (concat ", default "
3264 rmail-search-last-regexp "): ")
3265 "): ")))
3266 (setq regexp (read-string prompt))
3267 (cond ((not (equal regexp ""))
3268 (setq rmail-search-last-regexp regexp))
3269 ((not rmail-search-last-regexp)
3270 (error "No previous Rmail search string")))
3271 (list rmail-search-last-regexp
3272 (prefix-numeric-value current-prefix-arg))))
3273 (rmail-search regexp (- (or n 1))))
3275 ;; Scan for attributes, and compare subjects.
3277 (defun rmail-first-unseen-message ()
3278 "Return message number of first message which has `unseen' attribute."
3279 (rmail-maybe-set-message-counters)
3280 (let ((current 1)
3281 found)
3282 (save-restriction
3283 (widen)
3284 (while (and (not found) (<= current rmail-total-messages))
3285 (if (rmail-message-attr-p current "......U")
3286 (setq found current))
3287 (setq current (1+ current))))
3288 found))
3290 (defun rmail-simplified-subject (&optional msgnum)
3291 "Return the simplified subject of message MSGNUM (or current message).
3292 Simplifying the subject means stripping leading and trailing whitespace,
3293 and typical reply prefixes such as Re:."
3294 (let ((subject (or (rmail-get-header "Subject" msgnum) "")))
3295 (setq subject (rfc2047-decode-string subject))
3296 (if (string-match "\\`[ \t]+" subject)
3297 (setq subject (substring subject (match-end 0))))
3298 (if (string-match rmail-reply-regexp subject)
3299 (setq subject (substring subject (match-end 0))))
3300 (if (string-match "[ \t]+\\'" subject)
3301 (setq subject (substring subject 0 (match-beginning 0))))
3302 ;; If Subject is long, mailers will break it into several lines at
3303 ;; arbitrary places, so normalize whitespace by replacing every
3304 ;; run of whitespace characters with a single space.
3305 (setq subject (replace-regexp-in-string "[ \t\n]+" " " subject))
3306 subject))
3308 (defun rmail-simplified-subject-regexp ()
3309 "Return a regular expression matching the current simplified subject.
3310 The idea is to match it against simplified subjects of other messages."
3311 (let ((subject (rmail-simplified-subject)))
3312 (setq subject (regexp-quote subject))
3313 ;; Hide commas so it will work ok if parsed as a comma-separated list
3314 ;; of regexps.
3315 (setq subject
3316 (replace-regexp-in-string "," "\054" subject t t))
3317 (concat "\\`" subject "\\'")))
3319 (defun rmail-next-same-subject (n)
3320 "Go to the next mail message having the same subject header.
3321 With prefix argument N, do this N times.
3322 If N is negative, go backwards instead."
3323 (interactive "p")
3324 (let ((subject (rmail-simplified-subject))
3325 (forward (> n 0))
3326 (i rmail-current-message)
3327 found)
3328 (while (and (/= n 0)
3329 (if forward
3330 (< i rmail-total-messages)
3331 (> i 1)))
3332 (let (done)
3333 (while (and (not done)
3334 (if forward
3335 (< i rmail-total-messages)
3336 (> i 1)))
3337 (setq i (if forward (1+ i) (1- i)))
3338 (setq done (string-equal subject (rmail-simplified-subject i))))
3339 (if done (setq found i)))
3340 (setq n (if forward (1- n) (1+ n))))
3341 (if found
3342 (rmail-show-message found)
3343 (error "No %s message with same subject"
3344 (if forward "following" "previous")))))
3346 (defun rmail-previous-same-subject (n)
3347 "Go to the previous mail message having the same subject header.
3348 With prefix argument N, do this N times.
3349 If N is negative, go forwards instead."
3350 (interactive "p")
3351 (rmail-next-same-subject (- n)))
3353 ;;;; *** Rmail Message Deletion Commands ***
3355 (defun rmail-message-deleted-p (n)
3356 "Return non-nil if message number N is deleted (in `rmail-deleted-vector')."
3357 (= (aref rmail-deleted-vector n) ?D))
3359 (defun rmail-set-message-deleted-p (n state)
3360 "Set the deleted state of message number N (in `rmail-deleted-vector').
3361 STATE non-nil means mark as deleted."
3362 (aset rmail-deleted-vector n (if state ?D ?\s)))
3364 (defun rmail-delete-message ()
3365 "Delete this message and stay on it."
3366 (interactive)
3367 (rmail-set-attribute rmail-deleted-attr-index t)
3368 (run-hooks 'rmail-delete-message-hook))
3370 (defun rmail-undelete-previous-message ()
3371 "Back up to deleted message, select it, and undelete it."
3372 (interactive)
3373 (set-buffer rmail-buffer)
3374 (let ((msg rmail-current-message))
3375 (while (and (> msg 0)
3376 (not (rmail-message-deleted-p msg)))
3377 (setq msg (1- msg)))
3378 (if (= msg 0)
3379 (error "No previous deleted message")
3380 (if (/= msg rmail-current-message)
3381 (rmail-show-message msg))
3382 (rmail-set-attribute rmail-deleted-attr-index nil)
3383 (if (rmail-summary-exists)
3384 (with-current-buffer rmail-summary-buffer
3385 (rmail-summary-mark-undeleted msg)))
3386 (rmail-maybe-display-summary))))
3388 (defun rmail-delete-forward (&optional backward)
3389 "Delete this message and move to next nondeleted one.
3390 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
3391 With prefix argument, delete and move backward.
3393 Returns t if a new message is displayed after the delete, or nil otherwise."
3394 (interactive "P")
3395 (rmail-set-attribute rmail-deleted-attr-index t)
3396 (run-hooks 'rmail-delete-message-hook)
3397 (let ((del-msg rmail-current-message))
3398 (if (rmail-summary-exists)
3399 (rmail-select-summary
3400 (rmail-summary-mark-deleted del-msg)))
3401 (prog1 (rmail-next-undeleted-message (if backward -1 1))
3402 (rmail-maybe-display-summary))))
3404 (defun rmail-delete-backward ()
3405 "Delete this message and move to previous nondeleted one.
3406 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
3407 (interactive)
3408 (rmail-delete-forward t))
3410 ;; Expunging.
3412 ;; Compute the message number a given message would have after expunging.
3413 ;; The present number of the message is OLDNUM.
3414 ;; DELETEDVEC should be rmail-deleted-vector.
3415 ;; The value is nil for a message that would be deleted.
3416 (defun rmail-msg-number-after-expunge (deletedvec oldnum)
3417 (if (or (null oldnum) (= (aref deletedvec oldnum) ?D))
3419 (let ((i 0)
3420 (newnum 0))
3421 (while (< i oldnum)
3422 (if (/= (aref deletedvec i) ?D)
3423 (setq newnum (1+ newnum)))
3424 (setq i (1+ i)))
3425 newnum)))
3427 (defun rmail-expunge-confirmed ()
3428 "Return t if expunge is needed and desirable.
3429 If `rmail-confirm-expunge' is non-nil, ask user to confirm."
3430 (set-buffer rmail-buffer)
3431 (and (stringp rmail-deleted-vector)
3432 (string-match "D" rmail-deleted-vector)
3433 (if rmail-confirm-expunge
3434 (funcall rmail-confirm-expunge
3435 "Erase deleted messages from Rmail file? ")
3436 t)))
3438 (defun rmail-only-expunge (&optional dont-show)
3439 "Actually erase all deleted messages in the file."
3440 (interactive)
3441 (rmail-swap-buffers-maybe)
3442 (set-buffer rmail-buffer)
3443 (message "Expunging deleted messages...")
3444 ;; Discard all undo records for this buffer.
3445 (or (eq buffer-undo-list t)
3446 (setq buffer-undo-list nil))
3447 (rmail-maybe-set-message-counters)
3448 (let* ((omax (- (buffer-size) (point-max)))
3449 (omin (- (buffer-size) (point-min)))
3450 (opoint (if (and (> rmail-current-message 0)
3451 (rmail-message-deleted-p rmail-current-message))
3453 (if rmail-enable-mime
3454 (with-current-buffer rmail-view-buffer
3455 (- (point)(point-min)))
3456 (- (point) (point-min)))))
3457 (messages-head (cons (aref rmail-message-vector 0) nil))
3458 (messages-tail messages-head)
3459 ;; Don't make any undo records for the expunging.
3460 (buffer-undo-list t)
3461 (win))
3462 (unwind-protect
3463 (save-excursion
3464 (widen)
3465 (goto-char (point-min))
3466 (let ((counter 0)
3467 (number 1)
3468 new-summary
3469 (new-msgref (list (list 0)))
3470 (buffer-read-only nil)
3471 (total rmail-total-messages)
3472 (new-message-number rmail-current-message)
3473 (messages rmail-message-vector)
3474 (deleted rmail-deleted-vector)
3475 (summary rmail-summary-vector))
3476 (setq rmail-total-messages nil
3477 rmail-current-message nil
3478 rmail-message-vector nil
3479 rmail-deleted-vector nil
3480 rmail-summary-vector nil)
3482 (while (<= number total)
3483 (if (= (aref deleted number) ?D)
3484 (progn
3485 (delete-region (aref messages number)
3486 (aref messages (1+ number)))
3487 (move-marker (aref messages number) nil)
3488 (if (> new-message-number counter)
3489 (setq new-message-number (1- new-message-number))))
3490 (setq counter (1+ counter))
3491 (setq messages-tail
3492 (setcdr messages-tail
3493 (cons (aref messages number) nil)))
3494 (setq new-summary
3495 (cons (if (= counter number) (aref summary (1- number)))
3496 new-summary))
3497 (setq new-msgref
3498 (cons (aref rmail-msgref-vector number)
3499 new-msgref))
3500 (setcar (car new-msgref) counter))
3501 (if (zerop (% (setq number (1+ number)) 20))
3502 (message "Expunging deleted messages...%d" number)))
3503 (setq messages-tail
3504 (setcdr messages-tail
3505 (cons (aref messages number) nil)))
3506 (setq rmail-current-message new-message-number
3507 rmail-total-messages counter
3508 rmail-message-vector (apply 'vector messages-head)
3509 rmail-deleted-vector (make-string (1+ counter) ?\s)
3510 rmail-summary-vector (vconcat (nreverse new-summary))
3511 rmail-msgref-vector (apply 'vector (nreverse new-msgref))
3512 win t)))
3513 (message "Expunging deleted messages...done")
3514 (if (not win)
3515 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
3516 (if (not dont-show)
3517 (rmail-show-message (min rmail-current-message rmail-total-messages)))
3518 (if rmail-enable-mime
3519 (goto-char (+ (point-min) opoint))
3520 (goto-char (+ (point) opoint))))))
3522 ;; The DONT-SHOW argument is new in 23. Does not seem very important.
3523 (defun rmail-expunge (&optional dont-show)
3524 "Erase deleted messages from Rmail file and summary buffer.
3525 This always shows a message (so as not to leave the Rmail buffer
3526 unswapped), and always updates any summary (so that it remains
3527 consistent with the Rmail buffer). If DONT-SHOW is non-nil, it
3528 does not pop any summary buffer."
3529 (interactive)
3530 (when (rmail-expunge-confirmed)
3531 (rmail-modify-format)
3532 (let ((was-deleted (rmail-message-deleted-p rmail-current-message))
3533 (was-swapped (rmail-buffers-swapped-p)))
3534 (rmail-only-expunge t)
3535 ;; We always update the summary buffer, so that the contents
3536 ;; remain consistent with the rmail buffer.
3537 ;; The only difference is, in the dont-show case, we use a
3538 ;; cut-down version of rmail-select-summary that does not pop
3539 ;; the summary buffer. It's only used by rmail-quit, which is
3540 ;; just going to bury any summary immediately after. If we made
3541 ;; rmail-quit bury the summary first, dont-show could be removed.
3542 ;; But the expunge might not be confirmed...
3543 (if (rmail-summary-exists)
3544 (if dont-show
3545 (let ((total rmail-total-messages))
3546 (with-current-buffer rmail-summary-buffer
3547 (let ((rmail-total-messages total))
3548 (rmail-update-summary))))
3549 (rmail-select-summary (rmail-update-summary))))
3550 ;; We always show a message, because (rmail-only-expunge t)
3551 ;; leaves the rmail buffer unswapped.
3552 ;; If we expunged the current message, a new one is current now,
3553 ;; so show it. If we weren't showing a message, show it.
3554 (if (or was-deleted (not was-swapped))
3555 (rmail-show-message-1 rmail-current-message)
3556 ;; We can just show the same message that was being shown before.
3557 (rmail-display-labels)
3558 (rmail-swap-buffers)
3559 (setq rmail-buffer-swapped t)))))
3561 ;;;; *** Rmail Mailing Commands ***
3563 (defun rmail-yank-current-message (buffer)
3564 "Yank into the current buffer the current message of Rmail buffer BUFFER.
3565 If BUFFER is swapped with its message viewer buffer, yank out of BUFFER.
3566 If BUFFER is not swapped, yank out of its message viewer buffer."
3567 (with-current-buffer buffer
3568 (unless (rmail-buffers-swapped-p)
3569 (setq buffer rmail-view-buffer)))
3570 (insert-buffer-substring buffer)
3571 ;; If they yank the text of BUFFER, the encoding of BUFFER is a
3572 ;; better default for the reply message than the default value of
3573 ;; buffer-file-coding-system.
3574 (and (coding-system-equal (default-value 'buffer-file-coding-system)
3575 buffer-file-coding-system)
3576 (setq buffer-file-coding-system
3577 (coding-system-change-text-conversion
3578 buffer-file-coding-system (coding-system-base
3579 (with-current-buffer buffer
3580 buffer-file-coding-system))))))
3582 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
3583 replybuffer sendactions same-window
3584 other-headers)
3585 (let ((switch-function
3586 (cond (same-window nil)
3587 (rmail-mail-new-frame 'switch-to-buffer-other-frame)
3588 (t 'switch-to-buffer-other-window)))
3589 yank-action)
3590 (if replybuffer
3591 ;; The function used here must behave like insert-buffer wrt
3592 ;; point and mark (see doc of sc-cite-original).
3593 (setq yank-action
3594 `(rmail-yank-current-message ,replybuffer)))
3595 (push (cons "cc" cc) other-headers)
3596 (push (cons "in-reply-to" in-reply-to) other-headers)
3597 (setq other-headers
3598 (mapcar #'(lambda (elt)
3599 (cons (car elt) (if (stringp (cdr elt))
3600 (rfc2047-decode-string (cdr elt)))))
3601 other-headers))
3602 (if (stringp to) (setq to (rfc2047-decode-string to)))
3603 (if (stringp in-reply-to)
3604 (setq in-reply-to (rfc2047-decode-string in-reply-to)))
3605 (if (stringp cc) (setq cc (rfc2047-decode-string cc)))
3606 (if (stringp subject) (setq subject (rfc2047-decode-string subject)))
3607 (prog1
3608 (compose-mail to subject other-headers noerase
3609 switch-function yank-action sendactions
3610 (if replybuffer `(rmail-mail-return ,replybuffer)))
3611 (if (eq switch-function 'switch-to-buffer-other-frame)
3612 ;; This is not a standard frame parameter; nothing except
3613 ;; sendmail.el looks at it.
3614 (modify-frame-parameters (selected-frame)
3615 '((mail-dedicated-frame . t)))))))
3617 (defun rmail-mail-return (&optional newbuf)
3618 "Try to return to Rmail from the mail window.
3619 If optional argument NEWBUF is specified, it is the Rmail buffer
3620 to switch to."
3621 (cond
3622 ;; If there is only one visible frame with no special handling,
3623 ;; consider deleting the mail window to return to Rmail.
3624 ((or (null (delq (selected-frame) (visible-frame-list)))
3625 (not (or (window-dedicated-p (frame-selected-window))
3626 (and pop-up-frames (one-window-p))
3627 (cdr (assq 'mail-dedicated-frame
3628 (frame-parameters))))))
3629 (let (rmail-flag summary-buffer)
3630 (unless (one-window-p)
3631 (with-current-buffer
3632 (window-buffer (next-window (selected-window) 'not))
3633 (setq rmail-flag (eq major-mode 'rmail-mode))
3634 (setq summary-buffer
3635 (and (boundp 'mail-bury-selects-summary)
3636 mail-bury-selects-summary
3637 (boundp 'rmail-summary-buffer)
3638 rmail-summary-buffer
3639 (buffer-name rmail-summary-buffer)
3640 (not (get-buffer-window rmail-summary-buffer))
3641 rmail-summary-buffer))))
3642 (cond ((null rmail-flag)
3643 ;; If the Rmail buffer is not in the next window, switch
3644 ;; directly to the Rmail buffer specified by NEWBUF.
3645 (if (buffer-live-p newbuf)
3646 (switch-to-buffer newbuf)))
3647 ;; If the Rmail buffer is in the next window, switch to
3648 ;; the summary buffer if `mail-bury-selects-summary' is
3649 ;; non-nil. Otherwise just delete this window.
3650 (summary-buffer
3651 (switch-to-buffer summary-buffer))
3653 (delete-window)))))
3654 ;; If the frame was probably made for this buffer, the user
3655 ;; probably wants to delete it now.
3656 ((display-multi-frame-p)
3657 (delete-frame (selected-frame)))
3658 ;; The previous frame is where normally they have the Rmail buffer
3659 ;; displayed.
3660 (t (other-frame -1))))
3662 (defun rmail-mail ()
3663 "Send mail in another window.
3664 While composing the message, use \\[mail-yank-original] to yank the
3665 original message into it."
3666 (interactive)
3667 (rmail-start-mail nil nil nil nil nil rmail-buffer))
3669 ;; FIXME should complain if there is nothing to continue.
3670 (defun rmail-continue ()
3671 "Continue composing outgoing message previously being composed."
3672 (interactive)
3673 (rmail-start-mail t))
3675 (defun rmail-reply (just-sender)
3676 "Reply to the current message.
3677 Normally include CC: to all other recipients of original message;
3678 prefix argument means ignore them. While composing the reply,
3679 use \\[mail-yank-original] to yank the original message into it."
3680 (interactive "P")
3681 (if (zerop rmail-current-message)
3682 (error "There is no message to reply to"))
3683 (let (from reply-to cc subject date to message-id references
3684 resent-to resent-cc resent-reply-to
3685 (msgnum rmail-current-message))
3686 (rmail-apply-in-message
3687 rmail-current-message
3688 (lambda ()
3689 (search-forward "\n\n" nil 'move)
3690 (narrow-to-region (point-min) (point))
3691 (setq from (mail-fetch-field "from")
3692 reply-to (or (mail-fetch-field "mail-reply-to" nil t)
3693 (mail-fetch-field "reply-to" nil t)
3694 from)
3695 subject (mail-fetch-field "subject")
3696 date (mail-fetch-field "date")
3697 message-id (mail-fetch-field "message-id")
3698 references (mail-fetch-field "references" nil nil t)
3699 resent-reply-to (mail-fetch-field "resent-reply-to" nil t)
3700 ;; Bug#512. It's inappropriate to reply to these addresses.
3701 ;;; resent-cc (and (not just-sender)
3702 ;;; (mail-fetch-field "resent-cc" nil t))
3703 ;;; resent-to (or (mail-fetch-field "resent-to" nil t) "")
3704 ;;; resent-subject (mail-fetch-field "resent-subject")
3705 ;;; resent-date (mail-fetch-field "resent-date")
3706 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3708 (unless just-sender
3709 (if (mail-fetch-field "mail-followup-to" nil t)
3710 ;; If this header field is present, use it instead of the
3711 ;; To and CC fields.
3712 (setq to (mail-fetch-field "mail-followup-to" nil t))
3713 (setq cc (or (mail-fetch-field "cc" nil t) "")
3714 to (or (mail-fetch-field "to" nil t) ""))))))
3715 ;; Merge the resent-to and resent-cc into the to and cc.
3716 ;; Bug#512. It's inappropriate to reply to these addresses.
3717 ;;; (if (and resent-to (not (equal resent-to "")))
3718 ;;; (if (not (equal to ""))
3719 ;;; (setq to (concat to ", " resent-to))
3720 ;;; (setq to resent-to)))
3721 ;;; (if (and resent-cc (not (equal resent-cc "")))
3722 ;;; (if (not (equal cc ""))
3723 ;;; (setq cc (concat cc ", " resent-cc))
3724 ;;; (setq cc resent-cc)))
3725 ;; Add `Re: ' to subject if not there already.
3726 (and (stringp subject)
3727 (setq subject
3728 (concat rmail-reply-prefix
3729 (if (let ((case-fold-search t))
3730 (string-match rmail-reply-regexp subject))
3731 (substring subject (match-end 0))
3732 subject))))
3733 (rmail-start-mail
3735 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3736 ;; since they can handle the names unstripped.
3737 ;; I don't know whether there are other mailers that still
3738 ;; need the names to be stripped.
3739 ;;; (mail-strip-quoted-names reply-to)
3740 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3741 ;; header causes all the names in it to wind up in reply-to, not
3742 ;; in cc. But if what's left is an empty list, use the original.
3743 (let* ((reply-to-list (mail-dont-reply-to reply-to)))
3744 (if (string= reply-to-list "") reply-to reply-to-list))
3745 subject
3746 (rmail-make-in-reply-to-field from date message-id)
3747 (if just-sender
3749 ;; `mail-dont-reply-to' doesn't need `mail-strip-quoted-names'.
3750 (let* ((cc-list (mail-dont-reply-to
3751 (mail-strip-quoted-names
3752 (if (null cc) to (concat to ", " cc))))))
3753 (if (string= cc-list "") nil cc-list)))
3754 rmail-buffer
3755 (list (list 'rmail-mark-message
3756 rmail-buffer
3757 (with-current-buffer rmail-buffer
3758 (aref rmail-msgref-vector msgnum))
3759 rmail-answered-attr-index))
3761 (if (or references message-id)
3762 (list (cons "References" (if references
3763 (concat
3764 (mapconcat 'identity references " ")
3765 " " message-id)
3766 message-id)))))))
3768 (defun rmail-mark-message (buffer msgnum-list attribute)
3769 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3770 This is use in the send-actions for message buffers.
3771 MSGNUM-LIST is a list of the form (MSGNUM)
3772 which is an element of rmail-msgref-vector."
3773 (with-current-buffer buffer
3774 (if (car msgnum-list)
3775 (rmail-set-attribute attribute t (car msgnum-list)))))
3777 (defun rmail-make-in-reply-to-field (from date message-id)
3778 (cond ((not from)
3779 (if message-id
3780 message-id
3781 nil))
3782 (mail-use-rfc822
3783 (require 'rfc822)
3784 (let ((tem (car (rfc822-addresses from))))
3785 (if message-id
3786 (if (or (not tem)
3787 (string-match
3788 (regexp-quote (if (string-match "@[^@]*\\'" tem)
3789 (substring tem 0
3790 (match-beginning 0))
3791 tem))
3792 message-id))
3793 ;; missing From, or Message-ID is sufficiently informative
3794 message-id
3795 (concat message-id " (" tem ")"))
3796 ;; Copy TEM, discarding text properties.
3797 (setq tem (copy-sequence tem))
3798 (set-text-properties 0 (length tem) nil tem)
3799 (setq tem (copy-sequence tem))
3800 ;; Use prin1 to fake RFC822 quoting
3801 (let ((field (prin1-to-string tem)))
3802 (if date
3803 (concat field "'s message of " date)
3804 field)))))
3805 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3806 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3807 ;; These strings both match all non-ASCII characters.
3808 (or (string-match (concat "\\`[ \t]*\\(" bar
3809 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
3810 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3811 from)
3812 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
3813 bar "\\))[ \t]*\\'")
3814 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3815 from)))
3816 (let ((start (match-beginning 1))
3817 (end (match-end 1)))
3818 ;; Trim whitespace which above regexp match allows
3819 (while (and (< start end)
3820 (memq (aref from start) '(?\t ?\s)))
3821 (setq start (1+ start)))
3822 (while (and (< start end)
3823 (memq (aref from (1- end)) '(?\t ?\s)))
3824 (setq end (1- end)))
3825 (let ((field (substring from start end)))
3826 (if date (setq field (concat "message from " field " on " date)))
3827 (if message-id
3828 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3829 (concat message-id " (" field ")")
3830 field))))
3832 ;; If we can't kludge it simply, do it correctly
3833 (let ((mail-use-rfc822 t))
3834 (rmail-make-in-reply-to-field from date message-id)))))
3836 (defun rmail-forward (resend)
3837 "Forward the current message to another user.
3838 With prefix argument, \"resend\" the message instead of forwarding it;
3839 see the documentation of `rmail-resend'."
3840 (interactive "P")
3841 (if (zerop rmail-current-message)
3842 (error "No message to forward"))
3843 (if resend
3844 (call-interactively 'rmail-resend)
3845 (let ((forward-buffer rmail-buffer)
3846 (msgnum rmail-current-message)
3847 (subject (concat "["
3848 (let ((from (or (mail-fetch-field "From")
3849 (mail-fetch-field ">From"))))
3850 (if from
3851 (concat (mail-strip-quoted-names from) ": ")
3852 ""))
3853 (or (mail-fetch-field "Subject") "")
3854 "]")))
3855 (if (rmail-start-mail
3856 nil nil subject nil nil rmail-buffer
3857 (list (list 'rmail-mark-message
3858 forward-buffer
3859 (with-current-buffer rmail-buffer
3860 (aref rmail-msgref-vector msgnum))
3861 rmail-forwarded-attr-index))
3862 ;; If only one window, use it for the mail buffer.
3863 ;; Otherwise, use another window for the mail buffer
3864 ;; so that the Rmail buffer remains visible
3865 ;; and sending the mail will get back to it.
3866 (and (not rmail-mail-new-frame) (one-window-p t)))
3867 ;; The mail buffer is now current.
3868 (save-excursion
3869 ;; Insert after header separator--before signature if any.
3870 (rfc822-goto-eoh)
3871 (forward-line 1)
3872 (if (and rmail-enable-mime rmail-enable-mime-composing
3873 rmail-insert-mime-forwarded-message-function)
3874 (prog1
3875 (funcall rmail-insert-mime-forwarded-message-function
3876 forward-buffer)
3877 ;; rmail-insert-mime-forwarded-message-function
3878 ;; works by inserting MML tags into forward-buffer.
3879 ;; The MUA will need to convert it to MIME before
3880 ;; sending. mail-encode-mml tells them to do that.
3881 ;; message.el does that automagically.
3882 (or (eq mail-user-agent 'message-user-agent)
3883 (setq mail-encode-mml t)))
3884 (insert "------- Start of forwarded message -------\n")
3885 ;; Quote lines with `- ' if they start with `-'.
3886 (let ((beg (point)) end)
3887 (setq end (point-marker))
3888 (set-marker-insertion-type end t)
3889 (insert-buffer-substring forward-buffer)
3890 (goto-char beg)
3891 (while (re-search-forward "^-" end t)
3892 (beginning-of-line)
3893 (insert "- ")
3894 (forward-line 1))
3895 (goto-char end)
3896 (skip-chars-backward "\n")
3897 (if (< (point) end)
3898 (forward-char 1))
3899 (delete-region (point) end)
3900 (set-marker end nil))
3901 (insert "------- End of forwarded message -------\n"))
3902 (push-mark))))))
3904 (defun rmail-resend (address &optional from comment mail-alias-file)
3905 "Resend current message to ADDRESSES.
3906 ADDRESSES should be a single address, a string consisting of several
3907 addresses separated by commas, or a list of addresses.
3909 Optional FROM is the address to resend the message from, and
3910 defaults from the value of `user-mail-address'.
3911 Optional COMMENT is a string to insert as a comment in the resent message.
3912 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3913 typically for purposes of moderating a list."
3914 (interactive "sResend to: ")
3915 (require 'sendmail)
3916 (require 'mailalias)
3917 (unless (or (eq rmail-view-buffer (current-buffer))
3918 (eq rmail-buffer (current-buffer)))
3919 (error "Not an Rmail buffer"))
3920 (if (not from) (setq from user-mail-address))
3921 (let ((tembuf (generate-new-buffer " sendmail temp"))
3922 (case-fold-search nil)
3923 (mail-personal-alias-file
3924 (or mail-alias-file mail-personal-alias-file))
3925 (mailbuf rmail-buffer))
3926 (unwind-protect
3927 (with-current-buffer tembuf
3928 ;;>> Copy message into temp buffer
3929 (if (and rmail-enable-mime
3930 rmail-insert-mime-resent-message-function)
3931 (funcall rmail-insert-mime-resent-message-function mailbuf)
3932 (insert-buffer-substring mailbuf))
3933 (goto-char (point-min))
3934 ;; Delete any Sender field, since that's not specifiable.
3935 ; Only delete Sender fields in the actual header.
3936 (re-search-forward "^$" nil 'move)
3937 ; Using "while" here rather than "if" because some buggy mail
3938 ; software may have inserted multiple Sender fields.
3939 (while (re-search-backward "^Sender:" nil t)
3940 (let (beg)
3941 (setq beg (point))
3942 (forward-line 1)
3943 (while (looking-at "[ \t]")
3944 (forward-line 1))
3945 (delete-region beg (point))))
3946 ; Go back to the beginning of the buffer so the Resent- fields
3947 ; are inserted there.
3948 (goto-char (point-min))
3949 ;;>> Insert resent-from:
3950 (insert "Resent-From: " from "\n")
3951 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3952 ;;>> Insert resent-to: and bcc if need be.
3953 (let ((before (point)))
3954 (if mail-self-blind
3955 (insert "Resent-Bcc: " (user-login-name) "\n"))
3956 (insert "Resent-To: " (if (stringp address)
3957 address
3958 (mapconcat 'identity address ",\n\t"))
3959 "\n")
3960 ;; Expand abbrevs in the recipients.
3961 (save-excursion
3962 (if (featurep 'mailabbrev)
3963 (let ((end (point-marker))
3964 (local-abbrev-table mail-abbrevs)
3965 (old-syntax-table (syntax-table)))
3966 (if (and (not (vectorp mail-abbrevs))
3967 (file-exists-p mail-personal-alias-file))
3968 (build-mail-abbrevs))
3969 (unless mail-abbrev-syntax-table
3970 (mail-abbrev-make-syntax-table))
3971 (set-syntax-table mail-abbrev-syntax-table)
3972 (goto-char before)
3973 (while (and (< (point) end)
3974 (progn (forward-word 1)
3975 (<= (point) end)))
3976 (expand-abbrev))
3977 (set-syntax-table old-syntax-table))
3978 (expand-mail-aliases before (point)))))
3979 ;;>> Set up comment, if any.
3980 (if (and (sequencep comment) (not (zerop (length comment))))
3981 (let ((before (point))
3982 after)
3983 (insert comment)
3984 (or (eolp) (insert "\n"))
3985 (setq after (point))
3986 (goto-char before)
3987 (while (< (point) after)
3988 (insert "Resent-Comment: ")
3989 (forward-line 1))))
3990 ;; Don't expand aliases in the destination fields
3991 ;; of the original message.
3992 (let (mail-aliases)
3993 (funcall send-mail-function)))
3994 (kill-buffer tembuf))
3995 (with-current-buffer rmail-buffer
3996 (rmail-set-attribute rmail-resent-attr-index t rmail-current-message))))
3998 (defvar mail-unsent-separator
3999 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
4000 "^ *---+ +Returned message +---+ *$\\|"
4001 "^ *---+ *Returned mail follows *---+ *$\\|"
4002 "^Start of returned message$\\|"
4003 "^---+ Below this line is a copy of the message.$\\|"
4004 "^ *---+ +Original message +---+ *$\\|"
4005 "^ *--+ +begin message +--+ *$\\|"
4006 "^ *---+ +Original message follows +---+ *$\\|"
4007 "^ *---+ +Your message follows +---+ *$\\|"
4008 "^|? *---+ +Message text follows: +---+ *|?$\\|"
4009 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
4010 "A regexp that matches the separator before the text of a failed message.")
4012 (defvar mail-mime-unsent-header "^Content-Type: message/rfc822 *$"
4013 "A regexp that matches the header of a MIME body part with a failed message.")
4015 ;; This is a cut-down version of rmail-clear-headers from Emacs 22.
4016 ;; It doesn't have the same functionality, hence the name change.
4017 (defun rmail-delete-headers (regexp)
4018 "Delete any mail headers matching REGEXP.
4019 The message should be narrowed to just the headers."
4020 (when regexp
4021 (goto-char (point-min))
4022 (while (re-search-forward regexp nil t)
4023 (beginning-of-line)
4024 ;; This code from Emacs 22 doesn't seem right, since r-n-h is
4025 ;; just for display.
4026 ;;; (if (looking-at rmail-nonignored-headers)
4027 ;;; (forward-line 1)
4028 (delete-region (point)
4029 (save-excursion
4030 (if (re-search-forward "\n[^ \t]" nil t)
4031 (1- (point))
4032 (point-max)))))))
4034 (autoload 'mail-position-on-field "sendmail")
4036 (defun rmail-retry-failure ()
4037 "Edit a mail message which is based on the contents of the current message.
4038 For a message rejected by the mail system, extract the interesting headers and
4039 the body of the original message.
4040 If the failed message is a MIME multipart message, it is searched for a
4041 body part with a header which matches the variable `mail-mime-unsent-header'.
4042 Otherwise, the variable `mail-unsent-separator' should match the string that
4043 delimits the returned original message.
4044 The variable `rmail-retry-ignored-headers' is a regular expression
4045 specifying headers which should not be copied into the new message."
4046 (interactive)
4047 (require 'mail-utils)
4048 (let ((rmail-this-buffer (current-buffer))
4049 (msgnum rmail-current-message)
4050 bounce-start bounce-end bounce-indent resending
4051 (content-type (rmail-get-header "Content-Type")))
4052 (save-excursion
4053 (goto-char (point-min))
4054 (let ((case-fold-search t))
4055 (if (and content-type
4056 (string-match
4057 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
4058 content-type))
4059 ;; Handle a MIME multipart bounce message.
4060 (let ((codestring
4061 (concat "\n--"
4062 (substring content-type (match-beginning 1)
4063 (match-end 1)))))
4064 (unless (re-search-forward mail-mime-unsent-header nil t)
4065 (error "Cannot find beginning of header in failed message"))
4066 (unless (search-forward "\n\n" nil t)
4067 (error "Cannot find start of Mime data in failed message"))
4068 (setq bounce-start (point))
4069 (if (search-forward codestring nil t)
4070 (setq bounce-end (match-beginning 0))
4071 (setq bounce-end (point-max))))
4072 ;; Non-MIME bounce.
4073 (or (re-search-forward mail-unsent-separator nil t)
4074 (error "Cannot parse this as a failure message"))
4075 (skip-chars-forward "\n")
4076 ;; Support a style of failure message in which the original
4077 ;; message is indented, and included within lines saying
4078 ;; `Start of returned message' and `End of returned message'.
4079 (if (looking-at " +Received:")
4080 (progn
4081 (setq bounce-start (point))
4082 (skip-chars-forward " ")
4083 (setq bounce-indent (- (current-column)))
4084 (goto-char (point-max))
4085 (re-search-backward "^End of returned message$" nil t)
4086 (setq bounce-end (point)))
4087 ;; One message contained a few random lines before
4088 ;; the old message header. The first line of the
4089 ;; message started with two hyphens. A blank line
4090 ;; followed these random lines. The same line
4091 ;; beginning with two hyphens was possibly marking
4092 ;; the end of the message.
4093 (if (looking-at "^--")
4094 (let ((boundary (buffer-substring-no-properties
4095 (point)
4096 (progn (end-of-line) (point)))))
4097 (search-forward "\n\n")
4098 (skip-chars-forward "\n")
4099 (setq bounce-start (point))
4100 (goto-char (point-max))
4101 (search-backward (concat "\n\n" boundary) bounce-start t)
4102 (setq bounce-end (point)))
4103 (setq bounce-start (point)
4104 bounce-end (point-max)))
4105 (unless (search-forward "\n\n" nil t)
4106 (error "Cannot find end of header in failed message"))))))
4107 ;; We have found the message that bounced, within the current message.
4108 ;; Now start sending new message; default header fields from original.
4109 ;; Turn off the usual actions for initializing the message body
4110 ;; because we want to get only the text from the failure message.
4111 (let (mail-signature mail-setup-hook)
4112 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
4113 (list (list 'rmail-mark-message
4114 rmail-this-buffer
4115 (aref rmail-msgref-vector msgnum)
4116 rmail-retried-attr-index)))
4117 ;; Insert original text as initial text of new draft message.
4118 ;; Bind inhibit-read-only since the header delimiter
4119 ;; of the previous message was probably read-only.
4120 (let ((inhibit-read-only t)
4121 eoh)
4122 (erase-buffer)
4123 (insert-buffer-substring rmail-this-buffer
4124 bounce-start bounce-end)
4125 (goto-char (point-min))
4126 (if bounce-indent
4127 (indent-rigidly (point-min) (point-max) bounce-indent))
4128 (rfc822-goto-eoh)
4129 (setq eoh (point))
4130 (insert mail-header-separator)
4131 (save-restriction
4132 (narrow-to-region (point-min) eoh)
4133 (rmail-delete-headers rmail-retry-ignored-headers)
4134 (rmail-delete-headers "^\\(sender\\|return-path\\|received\\):")
4135 (setq resending (mail-fetch-field "resent-to"))
4136 (if mail-self-blind
4137 (if resending
4138 (insert "Resent-Bcc: " (user-login-name) "\n")
4139 (insert "BCC: " (user-login-name) "\n"))))
4140 (goto-char (point-min))
4141 (mail-position-on-field (if resending "Resent-To" "To") t))))))
4143 (defun rmail-summary-exists ()
4144 "Non-nil if in an RMAIL buffer and an associated summary buffer exists.
4145 In fact, the non-nil value returned is the summary buffer itself."
4146 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
4147 rmail-summary-buffer))
4149 (defun rmail-summary-displayed ()
4150 "t if in RMAIL buffer and an associated summary buffer is displayed."
4151 (and rmail-summary-buffer (get-buffer-window rmail-summary-buffer)))
4153 (defcustom rmail-redisplay-summary nil
4154 "Non-nil means Rmail should show the summary when it changes.
4155 This has an effect only if a summary buffer exists."
4156 :type 'boolean
4157 :group 'rmail-summary)
4159 (defcustom rmail-summary-window-size nil
4160 "Non-nil means specify the height for an Rmail summary window."
4161 :type '(choice (const :tag "Disabled" nil) integer)
4162 :group 'rmail-summary)
4164 ;; Put the summary buffer back on the screen, if user wants that.
4165 (defun rmail-maybe-display-summary ()
4166 (let ((selected (selected-window))
4167 window)
4168 ;; If requested, make sure the summary is displayed.
4169 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
4170 rmail-redisplay-summary
4171 (if (get-buffer-window rmail-summary-buffer 0)
4172 ;; It's already in some frame; show that one.
4173 (let ((frame (window-frame
4174 (get-buffer-window rmail-summary-buffer 0))))
4175 (make-frame-visible frame)
4176 (raise-frame frame))
4177 (display-buffer rmail-summary-buffer)))
4178 ;; If requested, set the height of the summary window.
4179 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
4180 rmail-summary-window-size
4181 (setq window (get-buffer-window rmail-summary-buffer))
4182 ;; Don't try to change the size if just one window in frame.
4183 (not (eq window (frame-root-window (window-frame window))))
4184 (unwind-protect
4185 (progn
4186 (select-window window)
4187 (enlarge-window (- rmail-summary-window-size (window-height))))
4188 (select-window selected)))))
4190 ;;;; *** Rmail Local Fontification ***
4192 (defun rmail-fontify-buffer-function ()
4193 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
4194 (add-hook 'rmail-show-message-hook 'rmail-fontify-message nil t)
4195 ;; If we're already showing a message, fontify it now.
4196 (if rmail-current-message (rmail-fontify-message))
4197 ;; Prevent Font Lock mode from kicking in.
4198 (setq font-lock-fontified t))
4200 (defun rmail-unfontify-buffer-function ()
4201 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
4202 (let ((modified (buffer-modified-p))
4203 (buffer-undo-list t) (inhibit-read-only t)
4204 before-change-functions after-change-functions
4205 buffer-file-name buffer-file-truename)
4206 (save-restriction
4207 (widen)
4208 (remove-hook 'rmail-show-message-hook 'rmail-fontify-message t)
4209 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil))
4210 (font-lock-default-unfontify-buffer)
4211 (and (not modified) (buffer-modified-p)
4212 (restore-buffer-modified-p nil)))))
4214 (defun rmail-fontify-message ()
4215 ;; Fontify the current message if it is not already fontified.
4216 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil)
4217 (let ((modified (buffer-modified-p))
4218 (buffer-undo-list t) (inhibit-read-only t)
4219 before-change-functions after-change-functions
4220 buffer-file-name buffer-file-truename)
4221 (save-excursion
4222 (save-match-data
4223 (add-text-properties (point-min) (point-max) '(rmail-fontified t))
4224 (font-lock-fontify-region (point-min) (point-max))
4225 (and (not modified) (buffer-modified-p)
4226 (restore-buffer-modified-p nil)))))))
4228 ;;; Speedbar support for RMAIL files.
4229 (eval-when-compile (require 'speedbar))
4231 (defvar rmail-speedbar-match-folder-regexp "^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
4232 "*This regex is used to match folder names to be displayed in speedbar.
4233 Enabling this will permit speedbar to display your folders for easy
4234 browsing, and moving of messages.")
4236 (defvar rmail-speedbar-last-user nil
4237 "The last user to be displayed in the speedbar.")
4239 (defvar rmail-speedbar-key-map nil
4240 "Keymap used when in rmail display mode.")
4242 (defun rmail-install-speedbar-variables ()
4243 "Install those variables used by speedbar to enhance rmail."
4244 (if rmail-speedbar-key-map
4246 (setq rmail-speedbar-key-map (speedbar-make-specialized-keymap))
4248 (define-key rmail-speedbar-key-map "e" 'speedbar-edit-line)
4249 (define-key rmail-speedbar-key-map "r" 'speedbar-edit-line)
4250 (define-key rmail-speedbar-key-map "\C-m" 'speedbar-edit-line)
4251 (define-key rmail-speedbar-key-map "M"
4252 'rmail-speedbar-move-message-to-folder-on-line)))
4254 ;; Mouse-3.
4255 (defvar rmail-speedbar-menu-items
4256 '(["Read Folder" speedbar-edit-line t]
4257 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
4258 (save-excursion (beginning-of-line)
4259 (looking-at "<M> "))])
4260 "Additional menu-items to add to speedbar frame.")
4262 ;; Make sure our special speedbar major mode is loaded
4263 (if (featurep 'speedbar)
4264 (rmail-install-speedbar-variables)
4265 (add-hook 'speedbar-load-hook 'rmail-install-speedbar-variables))
4267 (defun rmail-speedbar-buttons (buffer)
4268 "Create buttons for BUFFER containing rmail messages.
4269 Click on the address under Reply to: to reply to this person.
4270 Under Folders: Click a name to read it, or on the <M> to move the
4271 current message into that RMAIL folder."
4272 (let ((from nil))
4273 (with-current-buffer buffer
4274 (goto-char (point-min))
4275 (if (not (re-search-forward "^Reply-To: " nil t))
4276 (if (not (re-search-forward "^From:? " nil t))
4277 (setq from t)))
4278 (if from
4280 (setq from (buffer-substring (point) (line-end-position)))))
4281 (goto-char (point-min))
4282 (if (and (looking-at "Reply to:")
4283 (equal from rmail-speedbar-last-user))
4285 (setq rmail-speedbar-last-user from)
4286 (erase-buffer)
4287 (insert "Reply To:\n")
4288 (if (stringp from)
4289 (speedbar-insert-button from 'speedbar-directory-face 'highlight
4290 'rmail-speedbar-button 'rmail-reply))
4291 (insert "Folders:\n")
4292 (let* ((case-fold-search nil)
4293 (df (directory-files (with-current-buffer buffer
4294 default-directory)
4295 nil rmail-speedbar-match-folder-regexp)))
4296 (dolist (file df)
4297 (when (file-regular-p file)
4298 (speedbar-insert-button "<M>" 'speedbar-button-face 'highlight
4299 'rmail-speedbar-move-message file)
4300 (speedbar-insert-button file 'speedbar-file-face 'highlight
4301 'rmail-speedbar-find-file nil t)))))))
4303 (defun rmail-speedbar-button (text token indent)
4304 "Execute an rmail command specified by TEXT.
4305 The command used is TOKEN. INDENT is not used."
4306 (speedbar-with-attached-buffer
4307 (funcall token t)))
4309 (defun rmail-speedbar-find-file (text token indent)
4310 "Load in the rmail file TEXT.
4311 TOKEN and INDENT are not used."
4312 (speedbar-with-attached-buffer
4313 (message "Loading in RMAIL file %s..." text)
4314 (rmail text)))
4316 (defun rmail-speedbar-move-message-to-folder-on-line ()
4317 "If the current line is a folder, move current message to it."
4318 (interactive)
4319 (save-excursion
4320 (beginning-of-line)
4321 (if (re-search-forward "<M> " (line-end-position) t)
4322 (progn
4323 (forward-char -2)
4324 (speedbar-do-function-pointer)))))
4326 (defun rmail-speedbar-move-message (text token indent)
4327 "From button TEXT, copy current message to the rmail file specified by TOKEN.
4328 TEXT and INDENT are not used."
4329 (speedbar-with-attached-buffer
4330 (message "Moving message to %s" token)
4331 ;; expand-file-name is needed due to the unhelpful way in which
4332 ;; rmail-output expands non-absolute filenames against rmail-default-file.
4333 ;; What is the point of that, anyway?
4334 (rmail-output (expand-file-name token))))
4336 ;; Functions for setting, getting and encoding the POP password.
4337 ;; The password is encoded to prevent it from being easily accessible
4338 ;; to "prying eyes." Obviously, this encoding isn't "real security,"
4339 ;; nor is it meant to be.
4341 ;;;###autoload
4342 (defun rmail-set-remote-password (password)
4343 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
4344 (interactive "sPassword: ")
4345 (if password
4346 (setq rmail-encoded-remote-password
4347 (rmail-encode-string password (emacs-pid)))
4348 (setq rmail-remote-password nil)
4349 (setq rmail-encoded-remote-password nil)))
4351 (defun rmail-get-remote-password (imap)
4352 "Get the password for retrieving mail from a POP or IMAP server. If none
4353 has been set, then prompt the user for one."
4354 (when (not rmail-encoded-remote-password)
4355 (if (not rmail-remote-password)
4356 (setq rmail-remote-password
4357 (read-passwd (if imap
4358 "IMAP password: "
4359 "POP password: "))))
4360 (rmail-set-remote-password rmail-remote-password)
4361 (setq rmail-remote-password nil))
4362 (rmail-encode-string rmail-encoded-remote-password (emacs-pid)))
4364 (defun rmail-have-password ()
4365 (or rmail-remote-password rmail-encoded-remote-password))
4367 (defun rmail-encode-string (string mask)
4368 "Encode STRING with integer MASK, by taking the exclusive OR of the
4369 lowest byte in the mask with the first character of string, the
4370 second-lowest-byte with the second character of the string, etc.,
4371 restarting at the lowest byte of the mask whenever it runs out.
4372 Returns the encoded string. Calling the function again with an
4373 encoded string (and the same mask) will decode the string."
4374 (setq mask (abs mask)) ; doesn't work if negative
4375 (let* ((string-vector (string-to-vector string)) (i 0)
4376 (len (length string-vector)) (curmask mask) charmask)
4377 (while (< i len)
4378 (if (= curmask 0)
4379 (setq curmask mask))
4380 (setq charmask (% curmask 256))
4381 (setq curmask (lsh curmask -8))
4382 (aset string-vector i (logxor charmask (aref string-vector i)))
4383 (setq i (1+ i)))
4384 (concat string-vector)))
4386 ;; Should this have a key-binding, or be in a menu?
4387 ;; There doesn't really seem to be an appropriate menu.
4388 ;; Eg the edit command is not in a menu either.
4389 (defun rmail-epa-decrypt ()
4390 "Decrypt OpenPGP armors in current message."
4391 (interactive)
4393 ;; Save the current buffer here for cleanliness, in case we
4394 ;; change it in one of the calls to `epa-decrypt-region'.
4396 (save-excursion
4397 (let (decrypts)
4398 (goto-char (point-min))
4400 ;; In case the encrypted data is inside a mime attachment,
4401 ;; show it. This is a kludge; to be clean, it should not
4402 ;; modify the buffer, but I don't see how to do that.
4403 (when (search-forward "octet-stream" nil t)
4404 (beginning-of-line)
4405 (forward-button 1)
4406 (if (looking-at "Show")
4407 (rmail-mime-toggle-hidden)))
4409 ;; Now find all armored messages in the buffer
4410 ;; and decrypt them one by one.
4411 (goto-char (point-min))
4412 (while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t)
4413 (let ((coding-system-for-read coding-system-for-read)
4414 armor-start armor-end after-end)
4415 (setq armor-start (match-beginning 0)
4416 armor-end (re-search-forward "^-----END PGP MESSAGE-----$"
4417 nil t))
4418 (unless armor-end
4419 (error "Encryption armor beginning has no matching end"))
4420 (goto-char armor-start)
4422 ;; Because epa--find-coding-system-for-mime-charset not autoloaded.
4423 (require 'epa)
4425 ;; Use the charset specified in the armor.
4426 (unless coding-system-for-read
4427 (if (re-search-forward "^Charset: \\(.*\\)" armor-end t)
4428 (setq coding-system-for-read
4429 (epa--find-coding-system-for-mime-charset
4430 (intern (downcase (match-string 1)))))))
4432 ;; Advance over this armor.
4433 (goto-char armor-end)
4434 (setq after-end (- (point-max) armor-end))
4436 ;; Decrypt it, maybe in place, maybe making new buffer.
4437 (epa-decrypt-region
4438 armor-start armor-end
4439 ;; Call back this function to prepare the output.
4440 (lambda ()
4441 (let ((inhibit-read-only t))
4442 (delete-region armor-start armor-end)
4443 (goto-char armor-start)
4444 (current-buffer))))
4446 (push (list armor-start (- (point-max) after-end))
4447 decrypts)))
4449 (when (and decrypts (rmail-buffers-swapped-p))
4450 (when (y-or-n-p "Replace the original message? ")
4451 (setq decrypts (nreverse decrypts))
4452 (let ((beg (rmail-msgbeg rmail-current-message))
4453 (end (rmail-msgend rmail-current-message))
4454 (from-buffer (current-buffer)))
4455 (with-current-buffer rmail-view-buffer
4456 (narrow-to-region beg end)
4457 (goto-char (point-min))
4458 (dolist (d decrypts)
4459 (if (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t)
4460 (let (armor-start armor-end)
4461 (setq armor-start (match-beginning 0)
4462 armor-end (re-search-forward "^-----END PGP MESSAGE-----$"
4463 nil t))
4464 (when armor-end
4465 (delete-region armor-start armor-end)
4466 (insert-buffer-substring from-buffer (nth 0 d) (nth 1 d)))))))))))))
4468 ;;;; Desktop support
4470 (defun rmail-restore-desktop-buffer (desktop-buffer-file-name
4471 desktop-buffer-name
4472 desktop-buffer-misc)
4473 "Restore an rmail buffer specified in a desktop file."
4474 (condition-case error
4475 (progn
4476 (rmail-input desktop-buffer-file-name)
4477 (if (eq major-mode 'rmail-mode)
4478 (current-buffer)
4479 rmail-buffer))
4480 (file-locked
4481 (kill-buffer (current-buffer))
4482 nil)))
4484 (add-to-list 'desktop-buffer-mode-handlers
4485 '(rmail-mode . rmail-restore-desktop-buffer))
4487 ;; We use this to record the encoding of the current message before
4488 ;; saving the message collection.
4489 (defvar rmail-message-encoding nil)
4491 ;; Used in `write-region-annotate-functions' to write rmail files.
4492 (defun rmail-write-region-annotate (start end)
4493 (when (and (null start) rmail-buffer-swapped)
4494 (unless (buffer-live-p rmail-view-buffer)
4495 (error "Buffer `%s' with real text of `%s' has disappeared"
4496 (buffer-name rmail-view-buffer)
4497 (buffer-name (current-buffer))))
4498 (setq rmail-message-encoding buffer-file-coding-system)
4499 (set-buffer rmail-view-buffer)
4500 (widen)
4501 nil))
4503 ;; Used to restore the encoding of the buffer where we show the
4504 ;; current message, after we save the message collection. This is
4505 ;; needed because rmail-write-region-annotate switches buffers behind
4506 ;; save-file's back, with the side effect that last-coding-system-used
4507 ;; is assigned to buffer-file-coding-system of the wrong buffer.
4508 (defun rmail-after-save-hook ()
4509 (if (or (eq rmail-view-buffer (current-buffer))
4510 (eq rmail-buffer (current-buffer)))
4511 (with-current-buffer
4512 (if (rmail-buffers-swapped-p) rmail-buffer rmail-view-buffer)
4513 (setq buffer-file-coding-system rmail-message-encoding))))
4514 (add-hook 'after-save-hook 'rmail-after-save-hook)
4517 ;;; Start of automatically extracted autoloads.
4519 ;;;### (autoloads (rmail-edit-current-message) "rmailedit" "rmailedit.el"
4520 ;;;;;; "7d558f958574f6003fa474ce2f3c80a8")
4521 ;;; Generated autoloads from rmailedit.el
4523 (autoload 'rmail-edit-current-message "rmailedit" "\
4524 Edit the contents of this message.
4526 \(fn)" t nil)
4528 ;;;***
4530 ;;;### (autoloads (rmail-next-labeled-message rmail-previous-labeled-message
4531 ;;;;;; rmail-read-label rmail-kill-label rmail-add-label) "rmailkwd"
4532 ;;;;;; "rmailkwd.el" "4ae5660d86d49e524f4a6bcbc6d9a984")
4533 ;;; Generated autoloads from rmailkwd.el
4535 (autoload 'rmail-add-label "rmailkwd" "\
4536 Add LABEL to labels associated with current RMAIL message.
4537 Completes (see `rmail-read-label') over known labels when reading.
4538 LABEL may be a symbol or string. Only one label is allowed.
4540 \(fn LABEL)" t nil)
4542 (autoload 'rmail-kill-label "rmailkwd" "\
4543 Remove LABEL from labels associated with current RMAIL message.
4544 Completes (see `rmail-read-label') over known labels when reading.
4545 LABEL may be a symbol or string. Only one label is allowed.
4547 \(fn LABEL)" t nil)
4549 (autoload 'rmail-read-label "rmailkwd" "\
4550 Read a label with completion, prompting with PROMPT.
4551 Completions are chosen from `rmail-label-obarray'. The default
4552 is `rmail-last-label', if that is non-nil. Updates `rmail-last-label'
4553 according to the choice made, and returns a symbol.
4555 \(fn PROMPT)" nil nil)
4557 (autoload 'rmail-previous-labeled-message "rmailkwd" "\
4558 Show previous message with one of the labels LABELS.
4559 LABELS should be a comma-separated list of label names.
4560 If LABELS is empty, the last set of labels specified is used.
4561 With prefix argument N moves backward N messages with these labels.
4563 \(fn N LABELS)" t nil)
4565 (autoload 'rmail-next-labeled-message "rmailkwd" "\
4566 Show next message with one of the labels LABELS.
4567 LABELS should be a comma-separated list of label names.
4568 If LABELS is empty, the last set of labels specified is used.
4569 With prefix argument N moves forward N messages with these labels.
4571 \(fn N LABELS)" t nil)
4573 ;;;***
4575 ;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "cd7656f82944d0b92b0d093a5f3a4c36")
4576 ;;; Generated autoloads from rmailmm.el
4578 (autoload 'rmail-mime "rmailmm" "\
4579 Toggle the display of a MIME message.
4581 The actual behavior depends on the value of `rmail-enable-mime'.
4583 If `rmail-enable-mime' is non-nil (the default), this command toggles
4584 the display of a MIME message between decoded presentation form and
4585 raw data. With optional prefix argument ARG, it toggles the display only
4586 of the MIME entity at point, if there is one. The optional argument
4587 STATE forces a particular display state, rather than toggling.
4588 `raw' forces raw mode, any other non-nil value forces decoded mode.
4590 If `rmail-enable-mime' is nil, this creates a temporary \"*RMAIL*\"
4591 buffer holding a decoded copy of the message. Inline content-types are
4592 handled according to `rmail-mime-media-type-handlers-alist'.
4593 By default, this displays text and multipart messages, and offers to
4594 download attachments as specified by `rmail-mime-attachment-dirs-alist'.
4595 The arguments ARG and STATE have no effect in this case.
4597 \(fn &optional ARG STATE)" t nil)
4599 ;;;***
4601 ;;;### (autoloads (set-rmail-inbox-list) "rmailmsc" "rmailmsc.el"
4602 ;;;;;; "e2212ea15561d60365ffa1f7a5902939")
4603 ;;; Generated autoloads from rmailmsc.el
4605 (autoload 'set-rmail-inbox-list "rmailmsc" "\
4606 Set the inbox list of the current RMAIL file to FILE-NAME.
4607 You can specify one file name, or several names separated by commas.
4608 If FILE-NAME is empty, remove any existing inbox list.
4610 This applies only to the current session.
4612 \(fn FILE-NAME)" t nil)
4614 ;;;***
4616 ;;;### (autoloads (rmail-sort-by-labels rmail-sort-by-lines rmail-sort-by-correspondent
4617 ;;;;;; rmail-sort-by-recipient rmail-sort-by-author rmail-sort-by-subject
4618 ;;;;;; rmail-sort-by-date) "rmailsort" "rmailsort.el" "38da5f17d4ed0dcd2b09c158642cef63")
4619 ;;; Generated autoloads from rmailsort.el
4621 (autoload 'rmail-sort-by-date "rmailsort" "\
4622 Sort messages of current Rmail buffer by \"Date\" header.
4623 If prefix argument REVERSE is non-nil, sorts in reverse order.
4625 \(fn REVERSE)" t nil)
4627 (autoload 'rmail-sort-by-subject "rmailsort" "\
4628 Sort messages of current Rmail buffer by \"Subject\" header.
4629 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
4630 non-nil, sorts in reverse order.
4632 \(fn REVERSE)" t nil)
4634 (autoload 'rmail-sort-by-author "rmailsort" "\
4635 Sort messages of current Rmail buffer by author.
4636 This uses either the \"From\" or \"Sender\" header, downcased.
4637 If prefix argument REVERSE is non-nil, sorts in reverse order.
4639 \(fn REVERSE)" t nil)
4641 (autoload 'rmail-sort-by-recipient "rmailsort" "\
4642 Sort messages of current Rmail buffer by recipient.
4643 This uses either the \"To\" or \"Apparently-To\" header, downcased.
4644 If prefix argument REVERSE is non-nil, sorts in reverse order.
4646 \(fn REVERSE)" t nil)
4648 (autoload 'rmail-sort-by-correspondent "rmailsort" "\
4649 Sort messages of current Rmail buffer by other correspondent.
4650 This uses either the \"From\", \"Sender\", \"To\", or
4651 \"Apparently-To\" header, downcased. Uses the first header not
4652 excluded by `mail-dont-reply-to-names'. If prefix argument
4653 REVERSE is non-nil, sorts in reverse order.
4655 \(fn REVERSE)" t nil)
4657 (autoload 'rmail-sort-by-lines "rmailsort" "\
4658 Sort messages of current Rmail buffer by the number of lines.
4659 If prefix argument REVERSE is non-nil, sorts in reverse order.
4661 \(fn REVERSE)" t nil)
4663 (autoload 'rmail-sort-by-labels "rmailsort" "\
4664 Sort messages of current Rmail buffer by labels.
4665 LABELS is a comma-separated list of labels. The order of these
4666 labels specifies the order of messages: messages with the first
4667 label come first, messages with the second label come second, and
4668 so on. Messages that have none of these labels come last.
4669 If prefix argument REVERSE is non-nil, sorts in reverse order.
4671 \(fn REVERSE LABELS)" t nil)
4673 ;;;***
4675 ;;;### (autoloads (rmail-summary-by-senders rmail-summary-by-topic
4676 ;;;;;; rmail-summary-by-regexp rmail-summary-by-recipients rmail-summary-by-labels
4677 ;;;;;; rmail-summary) "rmailsum" "rmailsum.el" "bef21a376bd5bd59792a20dd86e6ec34")
4678 ;;; Generated autoloads from rmailsum.el
4680 (autoload 'rmail-summary "rmailsum" "\
4681 Display a summary of all messages, one line per message.
4683 \(fn)" t nil)
4685 (autoload 'rmail-summary-by-labels "rmailsum" "\
4686 Display a summary of all messages with one or more LABELS.
4687 LABELS should be a string containing the desired labels, separated by commas.
4689 \(fn LABELS)" t nil)
4691 (autoload 'rmail-summary-by-recipients "rmailsum" "\
4692 Display a summary of all messages with the given RECIPIENTS.
4693 Normally checks the To, From and Cc fields of headers;
4694 but if PRIMARY-ONLY is non-nil (prefix arg given),
4695 only look in the To and From fields.
4696 RECIPIENTS is a string of regexps separated by commas.
4698 \(fn RECIPIENTS &optional PRIMARY-ONLY)" t nil)
4700 (autoload 'rmail-summary-by-regexp "rmailsum" "\
4701 Display a summary of all messages according to regexp REGEXP.
4702 If the regular expression is found in the header of the message
4703 \(including in the date and other lines, as well as the subject line),
4704 Emacs will list the message in the summary.
4706 \(fn REGEXP)" t nil)
4708 (autoload 'rmail-summary-by-topic "rmailsum" "\
4709 Display a summary of all messages with the given SUBJECT.
4710 Normally checks just the Subject field of headers; but with prefix
4711 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
4712 SUBJECT is a string of regexps separated by commas.
4714 \(fn SUBJECT &optional WHOLE-MESSAGE)" t nil)
4716 (autoload 'rmail-summary-by-senders "rmailsum" "\
4717 Display a summary of all messages whose \"From\" field matches SENDERS.
4718 SENDERS is a string of regexps separated by commas.
4720 \(fn SENDERS)" t nil)
4722 ;;;***
4724 ;;;### (autoloads (unforward-rmail-message undigestify-rmail-message)
4725 ;;;;;; "undigest" "undigest.el" "a31a35802a2adbc51be42959c3043dbd")
4726 ;;; Generated autoloads from undigest.el
4728 (autoload 'undigestify-rmail-message "undigest" "\
4729 Break up a digest message into its constituent messages.
4730 Leaves original message, deleted, before the undigestified messages.
4732 \(fn)" t nil)
4734 (autoload 'unforward-rmail-message "undigest" "\
4735 Extract a forwarded message from the containing message.
4736 This puts the forwarded message into a separate rmail message following
4737 the containing message. This command is only useful when messages are
4738 forwarded with `rmail-enable-mime-composing' set to nil.
4740 \(fn)" t nil)
4742 ;;;***
4744 ;;; End of automatically extracted autoloads.
4747 (provide 'rmail)
4749 ;;; rmail.el ends here