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