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