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