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