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