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