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