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