1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
3 ;; Copyright (C) 1985-1988, 1993-1998, 2000-2012
4 ;; Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
29 ;; New features include attribute and keyword support, message
30 ;; selection by dispatch table, summary by attributes and keywords,
31 ;; expunging by dispatch table, sticky options for file commands.
33 ;; Extended by Bob Weiner of Motorola
34 ;; New features include: rmail and rmail-summary buffers remain
35 ;; synchronized and key bindings basically operate the same way in both
36 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
37 ;; variable, and a bury rmail buffer (wipe) command.
43 (declare-function compilation--message-
>loc
"compile" (cl-x) t
)
44 (declare-function epa--find-coding-system-for-mime-charset
"epa" (mime-charset))
46 (defconst rmail-attribute-header
"X-RMAIL-ATTRIBUTES"
47 "The header that stores the Rmail attribute data.")
49 (defconst rmail-keyword-header
"X-RMAIL-KEYWORDS"
50 "The header that stores the Rmail keyword data.")
54 (defconst rmail-answered-attr-index
0
55 "The index for the `answered' attribute.")
57 (defconst rmail-deleted-attr-index
1
58 "The index for the `deleted' attribute.")
60 (defconst rmail-edited-attr-index
2
61 "The index for the `edited' attribute.")
63 (defconst rmail-filed-attr-index
3
64 "The index for the `filed' attribute.")
66 (defconst rmail-retried-attr-index
4
67 "The index for the `retried' attribute.")
69 (defconst rmail-forwarded-attr-index
5
70 "The index for the `forwarded' attribute.")
72 (defconst rmail-unseen-attr-index
6
73 "The index for the `unseen' attribute.")
75 (defconst rmail-resent-attr-index
7
76 "The index for the `resent' attribute.")
78 (defconst rmail-attr-array
87 "An array that provides a mapping between an attribute index,
88 its character representation and its display representation.")
91 (defvar font-lock-fontified
)
92 (defvar mail-abbrev-syntax-table
)
94 (defvar messages-head
)
95 (defvar total-messages
)
97 (defvar mail-encode-mml
)
99 (defvar rmail-header-style
'normal
100 "The current header display style choice, one of
101 'normal (selected headers) or 'full (all headers).")
103 (defvar rmail-mime-decoded nil
104 "Non-nil if message has been processed by `rmail-show-mime-function'.")
105 (put 'rmail-mime-decoded
'permanent-local t
) ; for rmail-edit
108 "Mail reader for Emacs."
111 (defgroup rmail-retrieve nil
112 "Rmail retrieval options."
116 (defgroup rmail-files nil
121 (defgroup rmail-headers nil
122 "Rmail header options."
126 (defgroup rmail-reply nil
127 "Rmail reply options."
131 (defgroup rmail-summary nil
132 "Rmail summary options."
134 :prefix
"rmail-summary-"
137 (defgroup rmail-output nil
138 "Output message to a file."
139 :prefix
"rmail-output-"
143 (defgroup rmail-edit nil
145 :prefix
"rmail-edit-"
149 (defcustom rmail-file-name
(purecopy "~/RMAIL")
150 "Name of user's primary mail file."
156 (put 'rmail-spool-directory
'standard-value
157 '((cond ((file-exists-p "/var/mail") "/var/mail/")
158 ((file-exists-p "/var/spool/mail") "/var/spool/mail/")
159 ((memq system-type
'(hpux usg-unix-v irix
)) "/usr/mail/")
160 (t "/usr/spool/mail/"))))
163 (defcustom rmail-spool-directory
165 (cond ((file-exists-p "/var/mail")
166 ;; SVR4 and recent BSD are said to use this.
167 ;; Rather than trying to know precisely which systems use it,
168 ;; let's assume this dir is never used for anything else.
170 ;; Many GNU/Linux systems use this name.
171 ((file-exists-p "/var/spool/mail") "/var/spool/mail/")
172 ((memq system-type
'(hpux usg-unix-v irix
)) "/usr/mail/")
173 (t "/usr/spool/mail/")))
174 "Name of directory used by system mailer for delivering new mail.
175 Its name should end with a slash."
176 :initialize
'custom-initialize-delay
180 ;;;###autoload(custom-initialize-delay 'rmail-spool-directory nil)
182 (defcustom rmail-movemail-program nil
183 "If non-nil, the file name of the `movemail' program."
184 :group
'rmail-retrieve
185 :type
'(choice (const nil
) string
))
187 (define-obsolete-variable-alias 'rmail-pop-password
188 'rmail-remote-password
"22.1")
190 (defcustom rmail-remote-password nil
191 "Password to use when reading mail from a remote server.
192 This setting is ignored for mailboxes whose URL already contains a password."
193 :type
'(choice (string :tag
"Password")
194 (const :tag
"Not Required" nil
))
195 :group
'rmail-retrieve
198 (define-obsolete-variable-alias 'rmail-pop-password-required
199 'rmail-remote-password-required
"22.1")
201 (defcustom rmail-remote-password-required nil
202 "Non-nil if a password is required when reading mail from a remote server."
204 :group
'rmail-retrieve
207 (defcustom rmail-movemail-flags nil
208 "List of flags to pass to movemail.
209 Most commonly used to specify `-g' to enable GSS-API authentication
210 or `-k' to enable Kerberos authentication."
211 :type
'(repeat string
)
212 :group
'rmail-retrieve
215 (defvar rmail-remote-password-error
"invalid usercode or password\\|
216 unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
217 "Regular expression matching incorrect-password POP or IMAP server error
219 If you get an incorrect-password error that this expression does not match,
220 please report it with \\[report-emacs-bug].")
222 (defvar rmail-encoded-remote-password nil
)
224 (defcustom rmail-preserve-inbox nil
225 "Non-nil means leave incoming mail in the user's inbox--don't delete it."
227 :group
'rmail-retrieve
)
229 (defcustom rmail-movemail-search-path nil
230 "List of directories to search for movemail (in addition to `exec-path')."
231 :group
'rmail-retrieve
232 :type
'(repeat (directory)))
234 (declare-function mail-dont-reply-to
"mail-utils" (destinations))
235 (declare-function rmail-update-summary
"rmailsum" (&rest ignore
))
236 (declare-function rmail-mime-toggle-hidden
"rmailmm" ())
238 (defun rmail-probe (prog)
239 "Determine what flavor of movemail PROG is.
240 We do this by executing it with `--version' and analyzing its output."
242 (let ((tbuf (current-buffer)))
243 (buffer-disable-undo tbuf
)
244 (call-process prog nil tbuf nil
"--version")
245 (if (not (buffer-modified-p tbuf
))
246 ;; Should not happen...
248 (goto-char (point-min))
250 ((looking-at ".*movemail: invalid option")
251 'emacs
) ;; Possibly...
252 ((looking-at "movemail (GNU Mailutils .*)")
258 (defun rmail-autodetect ()
259 "Determine the file name of the `movemail' program and return its flavor.
260 If `rmail-movemail-program' is non-nil, use it.
261 Otherwise, look for `movemail' in the directories in
262 `rmail-movemail-search-path', those in `exec-path', and `exec-directory'."
263 (if rmail-movemail-program
264 (rmail-probe rmail-movemail-program
)
266 (dolist (dir (append rmail-movemail-search-path exec-path
267 (list exec-directory
)))
268 (when (and dir
(file-accessible-directory-p dir
))
269 ;; Previously, this didn't have to work on Windows, because
270 ;; rmail-insert-inbox-text before r1.439 fell back to using
271 ;; (expand-file-name "movemail" exec-directory) and just
272 ;; assuming it would work.
273 ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2008-02/msg00087.html
274 (let ((progname (expand-file-name
276 (if (memq system-type
'(ms-dos windows-nt
))
278 (when (and (not (file-directory-p progname
))
279 (file-executable-p progname
))
280 (let ((x (rmail-probe progname
)))
282 (setq rmail-movemail-program progname
)
283 (throw 'scan x
))))))))))
285 (defvar rmail-movemail-variant-in-use nil
286 "The movemail variant currently in use. Known variants are:
288 `emacs' Means any implementation, compatible with the native Emacs one.
290 `mailutils' Means GNU mailutils implementation, capable of handling full
291 mail URLs as the source mailbox.")
294 (defun rmail-movemail-variant-p (&rest variants
)
295 "Return t if the current movemail variant is any of VARIANTS.
296 Currently known variants are 'emacs and 'mailutils."
297 (when (not rmail-movemail-variant-in-use
)
299 (setq rmail-movemail-variant-in-use
(rmail-autodetect)))
300 (not (null (member rmail-movemail-variant-in-use variants
))))
302 ;; Call for effect, to set rmail-movemail-program (if not set by the
303 ;; user), and rmail-movemail-variant-in-use. Used by various functions.
304 ;; I'm not sure if M-x rmail is the only entry point to this package.
305 ;; If so, this can be moved there.
306 (rmail-movemail-variant-p)
309 (defcustom rmail-user-mail-address-regexp nil
310 "Regexp matching user mail addresses.
311 If non-nil, this variable is used to identify the correspondent
312 when receiving new mail. If it matches the address of the sender,
313 the recipient is taken as correspondent of a mail.
314 If nil \(default value\), your `user-login-name' and `user-mail-address'
315 are used to exclude yourself as correspondent.
317 Usually you don't have to set this variable, except if you collect mails
318 sent by you under different user names.
319 Then it should be a regexp matching your mail addresses.
321 Setting this variable has an effect only before reading a mail."
322 :type
'(choice (const :tag
"None" nil
) regexp
)
323 :group
'rmail-retrieve
327 (define-obsolete-variable-alias 'rmail-dont-reply-to-names
328 'mail-dont-reply-to-names
"24.1")
330 ;; Prior to 24.1, this used to contain "\\`info-".
332 (defvar rmail-default-dont-reply-to-names nil
333 "Regexp specifying part of the default value of `mail-dont-reply-to-names'.
334 This is used when the user does not set `mail-dont-reply-to-names'
337 (make-obsolete-variable 'rmail-default-dont-reply-to-names
338 'mail-dont-reply-to-names
"24.1")
341 (defcustom rmail-ignored-headers
343 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
344 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
345 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
346 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
347 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
348 "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
349 "\\|^content-transfer-encoding:\\|^x-coding-system:"
350 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
351 "\\|^precedence:\\|^mime-version:"
352 "\\|^list-owner:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
353 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
354 "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
355 "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
356 "\\|^mbox-line:\\|^cancel-lock:"
357 "\\|^DomainKey-Signature:\\|^dkim-signature:"
358 "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"
360 "Regexp to match header fields that Rmail should normally hide.
361 \(See also `rmail-nonignored-headers', which overrides this regexp.)
362 This variable is used for reformatting the message header,
363 which normally happens once for each message,
364 when you view the message for the first time in Rmail.
365 To make a change in this variable take effect
366 for a message that you have already viewed,
367 go to that message and type \\[rmail-toggle-header] twice."
369 :group
'rmail-headers
)
371 (defcustom rmail-nonignored-headers
"^x-spam-status:"
372 "Regexp to match X header fields that Rmail should show.
373 This regexp overrides `rmail-ignored-headers'; if both this regexp
374 and that one match a certain header field, Rmail shows the field.
375 If this is nil, ignore all header fields in `rmail-ignored-headers'.
377 This variable is used for reformatting the message header,
378 which normally happens once for each message,
379 when you view the message for the first time in Rmail.
380 To make a change in this variable take effect
381 for a message that you have already viewed,
382 go to that message and type \\[rmail-toggle-header] twice."
383 :type
'(choice (const nil
) (regexp))
384 :group
'rmail-headers
)
387 (defcustom rmail-displayed-headers nil
388 "Regexp to match Header fields that Rmail should display.
389 If nil, display all header fields except those matched by
390 `rmail-ignored-headers'."
391 :type
'(choice regexp
(const :tag
"All"))
392 :group
'rmail-headers
)
395 (defcustom rmail-retry-ignored-headers
(purecopy "^x-authentication-warning:\\|^x-detected-operating-system:\\|^x-spam[-a-z]*:\\|content-type:\\|content-transfer-encoding:\\|mime-version:\\|message-id:")
396 "Headers that should be stripped when retrying a failed message."
397 :type
'(choice regexp
(const nil
:tag
"None"))
398 :group
'rmail-headers
399 :version
"23.2") ; added x-detected-operating-system, x-spam
402 (defcustom rmail-highlighted-headers
(purecopy "^From:\\|^Subject:")
403 "Regexp to match Header fields that Rmail should normally highlight.
404 A value of nil means don't highlight. Uses the face `rmail-highlight'."
406 :group
'rmail-headers
)
408 (defface rmail-highlight
409 '((t (:inherit highlight
)))
410 "Face to use for highlighting the most important header fields.
411 The variable `rmail-highlighted-headers' specifies which headers."
412 :group
'rmail-headers
415 ;; This was removed in Emacs 23.1 with no notification, an unnecessary
416 ;; incompatible change.
417 (defcustom rmail-highlight-face
'rmail-highlight
418 "Face used by Rmail for highlighting headers."
419 ;; Note that nil doesn't actually mean use the default face, it
420 ;; means use either bold or highlight. It's not worth fixing this
421 ;; now that this is obsolete.
422 :type
'(choice (const :tag
"Default" nil
)
424 :group
'rmail-headers
)
425 (make-obsolete-variable 'rmail-highlight-face
426 "customize the face `rmail-highlight' instead."
429 (defface rmail-header-name
430 '((t (:inherit font-lock-function-name-face
)))
431 "Face to use for highlighting the header names.
432 The variable `rmail-font-lock-keywords' specifies which headers
434 :group
'rmail-headers
437 (defcustom rmail-delete-after-output nil
438 "Non-nil means automatically delete a message that is copied to a file."
443 (defcustom rmail-primary-inbox-list nil
444 "List of files that are inboxes for your primary mail file `rmail-file-name'.
445 If this is nil, uses the environment variable MAIL. If that is
446 unset, uses a file named by the function `user-login-name' in the
447 directory `rmail-spool-directory' (whose value depends on the
448 operating system). For example, \"/var/mail/USER\"."
449 ;; Don't use backquote here, because we don't want to need it at load time.
450 ;; (That must be an old comment - it's dumped these days.)
451 :type
(list 'choice
'(const :tag
"Default" nil
)
452 (list 'repeat
':value
(list (or (getenv "MAIL")
453 (concat rmail-spool-directory
456 :group
'rmail-retrieve
459 (defcustom rmail-mail-new-frame nil
460 "Non-nil means Rmail makes a new frame for composing outgoing mail.
461 This is handy if you want to preserve the window configuration of
462 the frame where you have the RMAIL buffer displayed."
467 (defcustom rmail-secondary-file-directory
(purecopy "~/")
468 "Directory for additional secondary Rmail files."
472 (defcustom rmail-secondary-file-regexp
(purecopy "\\.xmail$")
473 "Regexp for which files are secondary Rmail files."
477 (defcustom rmail-confirm-expunge
'y-or-n-p
478 "Whether and how to ask for confirmation before expunging deleted messages.
479 The value, if non-nil is a function to call with a question (string)
480 as argument, to ask the user that question."
481 :type
'(choice (const :tag
"No confirmation" nil
)
482 (const :tag
"Confirm with y-or-n-p" y-or-n-p
)
483 (const :tag
"Confirm with yes-or-no-p" yes-or-no-p
))
486 (put 'rmail-confirm-expunge
'risky-local-variable t
)
489 (defvar rmail-mode-hook nil
490 "List of functions to call when Rmail is invoked.")
492 (defvar rmail-get-new-mail-hook nil
493 "List of functions to call when Rmail has retrieved new mail.")
496 (defcustom rmail-show-message-hook nil
497 "List of functions to call when Rmail displays a message."
499 :options
'(goto-address)
502 (defvar rmail-quit-hook nil
503 "List of functions to call when quitting out of Rmail.")
505 (defvar rmail-delete-message-hook nil
506 "List of functions to call when Rmail deletes a message.
507 When the hooks are called, the message has been marked deleted but is
508 still the current message in the Rmail buffer.")
510 ;; These may be altered by site-init.el to match the format of mmdf files
511 ;; delimiting used on a given host (delim1 and delim2 from the config
514 (defvar rmail-mmdf-delim1
"^\001\001\001\001\n"
515 "Regexp marking the start of an mmdf message.")
516 (defvar rmail-mmdf-delim2
"^\001\001\001\001\n"
517 "Regexp marking the end of an mmdf message.")
519 ;; FIXME Post-mbox, this is now unused.
520 ;; In Emacs-22, this was called:
521 ;; i) the very first time a message was shown.
522 ;; ii) when toggling the headers to the normal state, every time.
523 ;; It's not clear what it should do now, since there is nothing that
524 ;; records when a message is shown for the first time (unseen is not
525 ;; necessarily the same thing).
526 ;; See http://lists.gnu.org/archive/html/emacs-devel/2009-03/msg00013.html
527 (defcustom rmail-message-filter nil
528 "If non-nil, a filter function for new messages in RMAIL.
529 Called with region narrowed to the message, including headers,
530 before obeying `rmail-ignored-headers'."
531 :group
'rmail-headers
532 :type
'(choice (const nil
) function
))
534 (make-obsolete-variable 'rmail-message-filter
535 "it is not used (try `rmail-show-message-hook')."
538 (defcustom rmail-automatic-folder-directives nil
539 "List of directives specifying how to automatically file messages.
540 Whenever Rmail shows a message in the folder that `rmail-file-name'
541 specifies, it calls `rmail-auto-file' to maybe file the message in
542 another folder according to this list. Messages that are already
543 marked as `filed', or are in different folders, are left alone.
545 Each element of the list is of the form:
547 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
549 FOLDERNAME is the name of a folder in which to put the message.
550 If FOLDERNAME is nil then Rmail deletes the message, and moves on to
551 the next. If FOLDERNAME is \"/dev/null\", Rmail deletes the message,
552 but does not move to the next.
554 FIELD is the name of a header field in the message, such as
555 \"subject\" or \"from\". A FIELD of \"to\" includes all text
556 from both the \"to\" and \"cc\" headers.
558 REGEXP is a regular expression to match (case-sensitively) against
559 the preceding specified FIELD.
561 There may be any number of FIELD/REGEXP pairs.
562 All pairs must match for a directive to apply to a message.
563 For a given message, Rmail applies only the first matching directive.
566 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
567 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS.
571 :type
'(repeat (sexp :tag
"Directive")))
573 (defvar rmail-reply-prefix
"Re: "
574 "String to prepend to Subject line when replying to a message.")
576 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
577 ;; This pattern should catch all the common variants.
578 ;; rms: I deleted the change to delete tags in square brackets
579 ;; because they mess up RT tags.
580 (defvar rmail-reply-regexp
"\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
581 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
583 (defcustom rmail-display-summary nil
584 "If non-nil, Rmail always displays the summary buffer."
585 :group
'rmail-summary
588 (defvar rmail-inbox-list nil
)
589 (put 'rmail-inbox-list
'permanent-local t
)
591 (defvar rmail-buffer nil
592 "The RMAIL buffer related to the current buffer.
593 In an RMAIL buffer, this holds the RMAIL buffer itself.
594 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
595 (put 'rmail-buffer
'permanent-local t
)
597 (defvar rmail-was-converted nil
598 "Non-nil in an Rmail buffer that was just converted from Babyl format.")
599 (put 'rmail-was-converted
'permanent-local t
)
601 (defvar rmail-seriously-modified nil
602 "Non-nil in an Rmail buffer that has been modified in a major way.")
603 (put 'rmail-seriously-modified
'permanent-local t
)
605 ;; Message counters and markers. Deleted flags.
607 (defvar rmail-current-message nil
608 "Integer specifying the message currently being displayed in this folder.
609 Counts messages from 1 to `rmail-total-messages'. A value of 0
610 means there are no messages in the folder.")
611 (put 'rmail-current-message
'permanent-local t
)
613 (defvar rmail-total-messages nil
614 "Integer specifying the total number of messages in this folder.
615 Includes deleted messages.")
616 (put 'rmail-total-messages
'permanent-local t
)
618 (defvar rmail-message-vector nil
619 "Vector of markers specifying the start and end of each message.
620 Element N and N+1 specify the start and end of message N.")
621 (put 'rmail-message-vector
'permanent-local t
)
623 (defvar rmail-deleted-vector nil
624 "A string of length `rmail-total-messages' plus one.
625 Character N is either a space or \"D\", according to whether
626 message N is deleted or not.")
627 (put 'rmail-deleted-vector
'permanent-local t
)
629 (defvar rmail-msgref-vector nil
630 "In an Rmail buffer, a vector whose Nth element is a list (N).
631 When expunging renumbers messages, these lists are modified
632 by substituting the new message number into the existing list.")
633 (put 'rmail-msgref-vector
'permanent-local t
)
635 (defvar rmail-overlay-list nil
)
636 (put 'rmail-overlay-list
'permanent-local t
)
638 ;; These are used by autoloaded rmail-summary.
640 (defvar rmail-summary-buffer nil
)
641 (put 'rmail-summary-buffer
'permanent-local t
)
642 (defvar rmail-summary-vector nil
643 "In an Rmail buffer, vector of (newline-terminated) strings.
644 Element N specifies the summary line for message N+1.")
645 (put 'rmail-summary-vector
'permanent-local t
)
647 ;; Rmail buffer swapping variables.
649 (defvar rmail-buffer-swapped nil
650 "If non-nil, `rmail-buffer' is swapped with `rmail-view-buffer'.")
651 (make-variable-buffer-local 'rmail-buffer-swapped
)
652 (put 'rmail-buffer-swapped
'permanent-local t
)
654 (defvar rmail-view-buffer nil
655 "Buffer which holds RMAIL message for MIME displaying.")
656 (make-variable-buffer-local 'rmail-view-buffer
)
657 (put 'rmail-view-buffer
'permanent-local t
)
659 ;; `Sticky' default variables.
661 ;; Last individual label specified to a or k.
662 (defvar rmail-last-label nil
)
664 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
665 (defvar rmail-last-multi-labels nil
)
667 (defvar rmail-last-regexp nil
)
668 (put 'rmail-last-regexp
'permanent-local t
)
670 ;; Note that rmail-output-read-file-name modifies this.
671 (defcustom rmail-default-file
"~/xmail"
672 "Default file name for \\[rmail-output]."
675 (defcustom rmail-default-body-file
"~/mailout"
676 "Default file name for \\[rmail-output-body-to-file]."
681 ;; Mule and MIME related variables.
684 (defvar rmail-file-coding-system nil
685 "Coding system used in RMAIL file.
687 This is set to nil by default.")
689 (defcustom rmail-enable-mime t
690 "If non-nil, RMAIL automatically displays decoded MIME messages.
691 For this to work, the feature specified by `rmail-mime-feature' must
697 (defcustom rmail-enable-mime-composing t
698 "If non-nil, use `rmail-insert-mime-forwarded-message-function' to forward."
700 :version
"24.1" ; nil -> t
703 (defvar rmail-show-mime-function nil
704 "Function of no argument called to show a decoded MIME message.
705 This function is called when `rmail-enable-mime' is non-nil.
706 The package providing MIME support should set this.")
709 (defvar rmail-insert-mime-forwarded-message-function nil
710 "Function to insert a message in MIME format so it can be forwarded.
711 This function is called if `rmail-enable-mime' and
712 `rmail-enable-mime-composing' are non-nil.
713 It is called with one argument FORWARD-BUFFER, which is a
714 buffer containing the message to forward. The current buffer
715 is the outgoing mail buffer.")
717 (defvar rmail-insert-mime-resent-message-function nil
718 "Function to insert a message in MIME format so it can be resent.
719 This function is called by `rmail-resend' if `rmail-enable-mime' is non-nil.
720 It is called with one argument FORWARD-BUFFER, which is a
721 buffer containing the message to forward. The current buffer
722 is the outgoing mail buffer.")
724 ;; FIXME one might want to pass a LIMIT, as per
725 ;; rmail-search-mime-header-function.
726 (defvar rmail-search-mime-message-function nil
727 "Function to check if a regexp matches a MIME message.
728 This function is called by `rmail-search-message' if
729 `rmail-enable-mime' is non-nil. It is called (with point at the
730 start of the message) with two arguments MSG and REGEXP, where
731 MSG is the message number, REGEXP is the regular expression.")
733 (defvar rmail-search-mime-header-function nil
734 "Function to check if a regexp matches a header of MIME message.
735 This function is called by `rmail-message-regexp-p-1' if
736 `rmail-enable-mime' is non-nil. It is called (with point at the
737 start of the header) with three arguments MSG, REGEXP, and LIMIT,
738 where MSG is the message number, REGEXP is the regular
739 expression, LIMIT is the position specifying the end of header.")
741 (defvar rmail-mime-feature
'rmailmm
742 "Feature to require for MIME support in Rmail.
743 When starting Rmail, if `rmail-enable-mime' is non-nil, this
744 feature is loaded with `require'. The default value is `rmailmm'.
746 The library should set the variable `rmail-show-mime-function'
747 to an appropriate value, and optionally also set
748 `rmail-search-mime-message-function',
749 `rmail-search-mime-header-function',
750 `rmail-insert-mime-forwarded-message-function', and
751 `rmail-insert-mime-resent-message-function'.")
753 (defvar rmail-mime-charset-pattern
754 (concat "^content-type:[ \t]*text/plain;"
755 "\\(?:[ \t\n]*\\(?:format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
756 "[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?")
757 "Regexp to match MIME-charset specification in a header of message.
758 The first parenthesized expression should match the MIME-charset name.")
761 (defvar rmail-unix-mail-delimiter
762 (let ((time-zone-regexp
763 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
764 "\\|[-+]?[0-9][0-9][0-9][0-9]"
770 ;; Many things can happen to an RFC 822 mailbox before it is put into
771 ;; a `From' line. The leading phrase can be stripped, e.g.
772 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
773 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
774 ;; can be removed, e.g.
775 ;; From: joe@y.z (Joe K
777 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
780 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
781 ;; The mailbox can be removed or be replaced by white space, e.g.
782 ;; From: "Joe User"{space}{tab}
784 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
785 ;; where {space} and {tab} represent the Ascii space and tab characters.
786 ;; We want to match the results of any of these manglings.
787 ;; The following regexp rejects names whose first characters are
788 ;; obviously bogus, but after that anything goes.
789 "\\([^\0-\b\n-\r\^?].*\\)? "
791 ;; The time the message was sent.
792 "\\([^\0-\r \^?]+\\) +" ; day of the week
793 "\\([^\0-\r \^?]+\\) +" ; month
794 "\\([0-3]?[0-9]\\) +" ; day of month
795 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
797 ;; Perhaps a time zone, specified by an abbreviation, or by a
802 " \\([0-9][0-9]+\\) *"
804 ;; On some systems the time zone can appear after the year, too.
808 "\\(remote from .*\\)?"
811 "Regexp matching the delimiter of messages in UNIX mail format
812 \(UNIX From lines), minus the initial ^. Note that if you change
813 this expression, you must change the code in `rmail-nuke-pinhead-header'
814 that knows the exact ordering of the \\( \\) subexpressions.")
816 ;; FIXME the rmail-header-name headers ought to be customizable.
817 ;; It seems a bit arbitrary, for example, that all of the Date: line
819 (defvar rmail-font-lock-keywords
820 ;; These are all matched case-insensitively.
822 (let* ((cite-chars "[>|}]")
823 (cite-prefix "[:alpha:]")
824 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
825 (list '("^\\(From\\|Sender\\|Resent-From\\):"
826 .
'rmail-header-name
)
827 '("^\\(Mail-\\)?Reply-To:.*$" .
'rmail-header-name
)
828 ;; FIXME Mail-Followup-To should probably be here too.
829 '("^Subject:" .
'rmail-header-name
)
830 '("^X-Spam-Status:" .
'rmail-header-name
)
831 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
832 .
'rmail-header-name
)
833 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
835 (,(concat "\\=[ \t]*"
836 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
837 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
839 (beginning-of-line) (end-of-line)
840 (1 font-lock-comment-delimiter-face nil t
)
841 (5 font-lock-comment-face nil t
)))
842 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
843 .
'rmail-header-name
))))
844 "Additional expressions to highlight in Rmail mode.")
846 ;; Rmail does not expect horizontal splitting. (Bug#2282)
847 (defun rmail-pop-to-buffer (&rest args
)
848 "Like `pop-to-buffer', but with `split-width-threshold' set to nil."
849 (let (split-width-threshold)
850 (apply 'pop-to-buffer args
)))
852 ;; Perform BODY in the summary buffer
853 ;; in such a way that its cursor is properly updated in its own window.
854 (defmacro rmail-select-summary
(&rest body
)
855 `(let ((total rmail-total-messages
))
856 (if (rmail-summary-displayed)
857 (let ((window (selected-window)))
861 (rmail-pop-to-buffer rmail-summary-buffer
)
862 ;; rmail-total-messages is a buffer-local var
863 ;; in the rmail buffer.
864 ;; This way we make it available for the body
865 ;; even tho the rmail buffer is not current.
866 (let ((rmail-total-messages total
))
868 (select-window window
))))
869 (with-current-buffer rmail-summary-buffer
870 (let ((rmail-total-messages total
))
872 (rmail-maybe-display-summary)))
874 ;;;; *** Rmail Mode ***
876 (defun rmail-require-mime-maybe ()
877 "Require `rmail-mime-feature' if that is non-nil.
878 Signal an error and set `rmail-mime-feature' to nil if the feature
880 (when rmail-enable-mime
882 (require rmail-mime-feature
)
886 (format "Although MIME support is requested
887 through `rmail-enable-mime' being non-nil, the required feature
888 `%s' (the value of `rmail-mime-feature')
889 is not available in the current session.
890 So, MIME support is turned off for the moment."
893 (setq rmail-enable-mime nil
)))))
897 (defun rmail (&optional file-name-arg
)
898 "Read and edit incoming mail.
899 Moves messages into file named by `rmail-file-name' and edits that
901 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
903 May be called with file name as argument; then performs rmail editing on
904 that file, but does not copy any new mail into the file.
905 Interactively, if you supply a prefix argument, then you
906 have a chance to specify a file name with the minibuffer.
908 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
909 (interactive (if current-prefix-arg
910 (list (read-file-name "Run rmail on RMAIL file: "))))
911 (rmail-require-mime-maybe)
912 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
913 ;; Use find-buffer-visiting, not get-file-buffer, for those users
914 ;; who have find-file-visit-truename set to t.
915 (existed (find-buffer-visiting file-name
))
916 run-mail-hook mail-buf msg-shown
)
917 ;; Determine if an existing mail file has been changed behind the
919 (if (and existed
(not (verify-visited-file-modtime existed
)))
920 ;; The mail file has been changed. Revisit it and reset the
921 ;; message state variables when in rmail mode.
923 (find-file file-name
)
924 (when (and (verify-visited-file-modtime existed
)
925 (eq major-mode
'rmail-mode
))
926 (rmail-swap-buffers-maybe)
927 (rmail-set-message-counters)))
928 ;; The mail file is either unchanged or not visited. Visit it.
930 (let ((enable-local-variables nil
)
931 ;; Force no-conversion by default, since that's what
932 ;; pre-mbox Rmail did with BABYL files (via
933 ;; auto-coding-regexp-alist).
934 (coding-system-for-read
935 (or coding-system-for-read
'no-conversion
)))
936 (find-file-noselect file-name
))))
937 ;; Ensure that the collection and view buffers are in sync and
938 ;; ensure that a message is not being edited.
939 (if (eq major-mode
'rmail-mode
)
940 (rmail-swap-buffers-maybe))
941 (if (eq major-mode
'rmail-edit-mode
)
942 (error "Exit Rmail Edit mode before getting new mail"))
943 (or (and existed
(> (buffer-size) 0))
944 (setq run-mail-hook t
))
945 ;; Ensure that the Rmail file is in mbox format, the buffer is in
946 ;; Rmail mode and has been scanned to find all the messages
947 ;; (setting the global message variables in the process).
948 (rmail-convert-file-maybe)
949 (unless (eq major-mode
'rmail-mode
)
951 (goto-char (point-max))
952 (rmail-maybe-set-message-counters)
953 (setq mail-buf rmail-buffer
)
954 ;; Show the first unread message and process summary mode.
956 ;; Only get new mail when there is not a file name argument.
957 (unless file-name-arg
958 (setq msg-shown
(rmail-get-new-mail)))
960 (set-buffer mail-buf
)
962 (rmail-show-message (rmail-first-unseen-message)))
963 (if rmail-display-summary
(rmail-summary))
964 (rmail-construct-io-menu)
966 (run-hooks 'rmail-mode-hook
))))))
968 (defun rmail-convert-file-maybe ()
969 "Determine if the file needs to be converted to mbox format."
971 (goto-char (point-min))
972 ;; Detect previous Babyl format files.
973 (let ((case-fold-search nil
))
974 (cond ((looking-at "BABYL OPTIONS:")
975 ;; The file is Babyl version 5. Use unrmail to convert
977 (rmail-convert-babyl-to-mbox))
978 ((looking-at "Version: 5\n")
979 ;; Losing babyl file made by old version of Rmail. Fix the
980 ;; babyl file header and use unrmail to convert to mbox
982 (let ((buffer-read-only nil
))
983 (insert "BABYL OPTIONS: -*- rmail -*-\n")
984 (rmail-convert-babyl-to-mbox)))
985 ((equal (point-min) (point-max))
986 (message "Empty Rmail file."))
987 ((looking-at "From "))
988 (t (error "Invalid mbox file")))))
990 (defun rmail-error-bad-format (&optional msgnum
)
991 "Report that the buffer is not in the mbox file format.
992 MSGNUM, if present, indicates the malformed message."
994 (error "Message %d is not a valid RFC2822 message" msgnum
)
995 (error "Message is not a valid RFC2822 message")))
997 (defun rmail-convert-babyl-to-mbox ()
998 "Convert the mail file from Babyl version 5 to mbox.
999 This function also reinitializes local variables used by Rmail."
1000 (let ((old-file (make-temp-file "rmail"))
1001 (new-file (make-temp-file "rmail")))
1004 (kill-all-local-variables)
1005 (write-region (point-min) (point-max) old-file
)
1006 (unrmail old-file new-file
)
1007 (message "Replacing BABYL format with mbox format...")
1008 (let ((inhibit-read-only t
)
1009 (coding-system-for-read 'raw-text
)
1010 (buffer-undo-list t
))
1012 (insert-file-contents new-file
)
1013 ;; Rmail buffers need to be saved with Unix EOLs, or else
1014 ;; the format will not be recognized.
1015 (set-buffer-file-coding-system 'raw-text-unix
)
1017 (rmail-perm-variables)
1019 (setq rmail-was-converted t
)
1020 (rmail-dont-modify-format)
1021 (goto-char (point-max))
1022 (rmail-set-message-counters))
1023 (message "Replacing BABYL format with mbox format...done"))
1024 (delete-file old-file
)
1025 (delete-file new-file
))))
1027 (defun rmail-get-coding-system ()
1028 "Return a suitable coding system to use for the current mail message.
1029 The buffer is expected to be narrowed to just the header of the message."
1031 (goto-char (point-min))
1032 (if (re-search-forward rmail-mime-charset-pattern nil t
)
1033 (coding-system-from-name (match-string 1))
1036 ;;; Set up Rmail mode keymaps
1038 (defvar rmail-mode-map
1039 (let ((map (make-keymap)))
1040 (suppress-keymap map
)
1041 (define-key map
"a" 'rmail-add-label
)
1042 (define-key map
"b" 'rmail-bury
)
1043 (define-key map
"c" 'rmail-continue
)
1044 (define-key map
"d" 'rmail-delete-forward
)
1045 (define-key map
"\C-d" 'rmail-delete-backward
)
1046 (define-key map
"e" 'rmail-edit-current-message
)
1047 ;; If you change this, change the rmail-resend menu-item's :keys.
1048 (define-key map
"f" 'rmail-forward
)
1049 (define-key map
"g" 'rmail-get-new-mail
)
1050 (define-key map
"h" 'rmail-summary
)
1051 (define-key map
"i" 'rmail-input
)
1052 (define-key map
"j" 'rmail-show-message
)
1053 (define-key map
"k" 'rmail-kill-label
)
1054 (define-key map
"l" 'rmail-summary-by-labels
)
1055 (define-key map
"\e\C-h" 'rmail-summary
)
1056 (define-key map
"\e\C-l" 'rmail-summary-by-labels
)
1057 (define-key map
"\e\C-r" 'rmail-summary-by-recipients
)
1058 (define-key map
"\e\C-s" 'rmail-summary-by-regexp
)
1059 (define-key map
"\e\C-f" 'rmail-summary-by-senders
)
1060 (define-key map
"\e\C-t" 'rmail-summary-by-topic
)
1061 (define-key map
"m" 'rmail-mail
)
1062 (define-key map
"\em" 'rmail-retry-failure
)
1063 (define-key map
"n" 'rmail-next-undeleted-message
)
1064 (define-key map
"\en" 'rmail-next-message
)
1065 (define-key map
"\e\C-n" 'rmail-next-labeled-message
)
1066 (define-key map
"o" 'rmail-output
)
1067 (define-key map
"\C-o" 'rmail-output-as-seen
)
1068 (define-key map
"p" 'rmail-previous-undeleted-message
)
1069 (define-key map
"\ep" 'rmail-previous-message
)
1070 (define-key map
"\e\C-p" 'rmail-previous-labeled-message
)
1071 (define-key map
"q" 'rmail-quit
)
1072 (define-key map
"r" 'rmail-reply
)
1073 ;; I find I can't live without the default M-r command -- rms.
1074 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
1075 (define-key map
"s" 'rmail-expunge-and-save
)
1076 (define-key map
"\es" 'rmail-search
)
1077 (define-key map
"t" 'rmail-toggle-header
)
1078 (define-key map
"u" 'rmail-undelete-previous-message
)
1079 (define-key map
"v" 'rmail-mime
)
1080 (define-key map
"w" 'rmail-output-body-to-file
)
1081 (define-key map
"\C-c\C-w" 'rmail-widen
)
1082 (define-key map
"x" 'rmail-expunge
)
1083 (define-key map
"." 'rmail-beginning-of-message
)
1084 (define-key map
"/" 'rmail-end-of-message
)
1085 (define-key map
"<" 'rmail-first-message
)
1086 (define-key map
">" 'rmail-last-message
)
1087 (define-key map
" " 'scroll-up-command
)
1088 (define-key map
"\177" 'scroll-down-command
)
1089 (define-key map
"?" 'describe-mode
)
1090 (define-key map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
1091 (define-key map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
1092 (define-key map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
1093 (define-key map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
1094 (define-key map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
1095 (define-key map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
1096 (define-key map
"\C-c\C-s\C-k" 'rmail-sort-by-labels
)
1097 (define-key map
"\C-c\C-n" 'rmail-next-same-subject
)
1098 (define-key map
"\C-c\C-p" 'rmail-previous-same-subject
)
1101 (define-key map
[menu-bar
] (make-sparse-keymap))
1103 (define-key map
[menu-bar classify
]
1104 (cons "Classify" (make-sparse-keymap "Classify")))
1106 (define-key map
[menu-bar classify input-menu
]
1109 (define-key map
[menu-bar classify output-menu
]
1112 (define-key map
[menu-bar classify output-body
]
1113 '("Output body to file..." . rmail-output-body-to-file
))
1115 (define-key map
[menu-bar classify output-inbox
]
1116 '("Output..." . rmail-output
))
1118 (define-key map
[menu-bar classify output
]
1119 '("Output as seen..." . rmail-output-as-seen
))
1121 (define-key map
[menu-bar classify kill-label
]
1122 '("Kill Label..." . rmail-kill-label
))
1124 (define-key map
[menu-bar classify add-label
]
1125 '("Add Label..." . rmail-add-label
))
1127 (define-key map
[menu-bar summary
]
1128 (cons "Summary" (make-sparse-keymap "Summary")))
1130 (define-key map
[menu-bar summary senders
]
1131 '("By Senders..." . rmail-summary-by-senders
))
1133 (define-key map
[menu-bar summary labels
]
1134 '("By Labels..." . rmail-summary-by-labels
))
1136 (define-key map
[menu-bar summary recipients
]
1137 '("By Recipients..." . rmail-summary-by-recipients
))
1139 (define-key map
[menu-bar summary topic
]
1140 '("By Topic..." . rmail-summary-by-topic
))
1142 (define-key map
[menu-bar summary regexp
]
1143 '("By Regexp..." . rmail-summary-by-regexp
))
1145 (define-key map
[menu-bar summary all
]
1146 '("All" . rmail-summary
))
1148 (define-key map
[menu-bar mail
]
1149 (cons "Mail" (make-sparse-keymap "Mail")))
1151 (define-key map
[menu-bar mail rmail-get-new-mail
]
1152 '("Get New Mail" . rmail-get-new-mail
))
1154 (define-key map
[menu-bar mail lambda
]
1157 (define-key map
[menu-bar mail continue
]
1158 '("Continue" . rmail-continue
))
1160 (define-key map
[menu-bar mail resend
]
1161 '(menu-item "Resend..." rmail-resend
:keys
"C-u f"))
1163 (define-key map
[menu-bar mail forward
]
1164 '("Forward" . rmail-forward
))
1166 (define-key map
[menu-bar mail retry
]
1167 '("Retry" . rmail-retry-failure
))
1169 (define-key map
[menu-bar mail reply
]
1170 '("Reply" . rmail-reply
))
1172 (define-key map
[menu-bar mail mail
]
1173 '("Mail" . rmail-mail
))
1175 (define-key map
[menu-bar delete
]
1176 (cons "Delete" (make-sparse-keymap "Delete")))
1178 (define-key map
[menu-bar delete expunge
/save
]
1179 '("Expunge/Save" . rmail-expunge-and-save
))
1181 (define-key map
[menu-bar delete expunge
]
1182 '("Expunge" . rmail-expunge
))
1184 (define-key map
[menu-bar delete undelete
]
1185 '("Undelete" . rmail-undelete-previous-message
))
1187 (define-key map
[menu-bar delete delete
]
1188 '("Delete" . rmail-delete-forward
))
1190 (define-key map
[menu-bar move
]
1191 (cons "Move" (make-sparse-keymap "Move")))
1193 (define-key map
[menu-bar move search-back
]
1194 '("Search Back..." . rmail-search-backwards
))
1196 (define-key map
[menu-bar move search
]
1197 '("Search..." . rmail-search
))
1199 (define-key map
[menu-bar move previous
]
1200 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
1202 (define-key map
[menu-bar move next
]
1203 '("Next Nondeleted" . rmail-next-undeleted-message
))
1205 (define-key map
[menu-bar move last
]
1206 '("Last" . rmail-last-message
))
1208 (define-key map
[menu-bar move first
]
1209 '("First" . rmail-first-message
))
1211 (define-key map
[menu-bar move previous
]
1212 '("Previous" . rmail-previous-message
))
1214 (define-key map
[menu-bar move next
]
1215 '("Next" . rmail-next-message
))
1218 "Keymap used in Rmail mode.")
1221 (defvar rmail-tool-bar-map
1222 (let ((map (make-sparse-keymap)))
1223 (tool-bar-local-item-from-menu 'rmail-get-new-mail
"mail/inbox"
1225 (tool-bar-local-item-from-menu 'rmail-next-undeleted-message
"right-arrow"
1227 (tool-bar-local-item-from-menu 'rmail-previous-undeleted-message
"left-arrow"
1229 (tool-bar-local-item-from-menu 'rmail-search
"search"
1231 (tool-bar-local-item-from-menu 'rmail-input
"open"
1233 (tool-bar-local-item-from-menu 'rmail-mail
"mail/compose"
1235 (tool-bar-local-item-from-menu 'rmail-reply
"mail/reply-all"
1237 (tool-bar-local-item-from-menu 'rmail-forward
"mail/forward"
1239 (tool-bar-local-item-from-menu 'rmail-delete-forward
"close"
1241 (tool-bar-local-item-from-menu 'rmail-output
"mail/move"
1243 (tool-bar-local-item-from-menu 'rmail-output-body-to-file
"mail/save"
1245 (tool-bar-local-item-from-menu 'rmail-expunge
"delete"
1251 ;; Rmail mode is suitable only for specially formatted data.
1252 (put 'rmail-mode
'mode-class
'special
)
1254 (defun rmail-mode-kill-summary ()
1255 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
1257 (defvar rmail-enable-multibyte
) ; dynamically bound
1260 (defun rmail-mode ()
1261 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
1262 All normal editing commands are turned off.
1263 Instead, these commands are available:
1265 \\[rmail-beginning-of-message] Move point to front of this message.
1266 \\[rmail-end-of-message] Move point to bottom of this message.
1267 \\[scroll-up] Scroll to next screen of this message.
1268 \\[scroll-down] Scroll to previous screen of this message.
1269 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
1270 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
1271 \\[rmail-next-message] Move to Next message whether deleted or not.
1272 \\[rmail-previous-message] Move to Previous message whether deleted or not.
1273 \\[rmail-first-message] Move to the first message in Rmail file.
1274 \\[rmail-last-message] Move to the last message in Rmail file.
1275 \\[rmail-show-message] Jump to message specified by numeric position in file.
1276 \\[rmail-search] Search for string and show message it is found in.
1277 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
1278 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
1279 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1280 till a deleted message is found.
1281 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
1282 \\[rmail-expunge] Expunge deleted messages.
1283 \\[rmail-expunge-and-save] Expunge and save the file.
1284 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
1285 \\[save-buffer] Save without expunging.
1286 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
1287 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
1288 \\[rmail-continue] Continue composing outgoing message started before.
1289 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
1290 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
1291 \\[rmail-forward] Forward this message to another user.
1292 \\[rmail-output] Output (append) this message to another mail file.
1293 \\[rmail-output-as-seen] Output (append) this message to file as it's displayed.
1294 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1295 \\[rmail-input] Input Rmail file. Run Rmail on that file.
1296 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
1297 \\[rmail-kill-label] Kill label. Remove a label from current message.
1298 \\[rmail-next-labeled-message] Move to Next message with specified label
1299 (label defaults to last one specified).
1300 Standard labels: filed, unseen, answered, forwarded, deleted.
1301 Any other label is present only if you add it with \\[rmail-add-label].
1302 \\[rmail-previous-labeled-message] Move to Previous message with specified label
1303 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
1304 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
1305 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1306 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1307 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1308 \\[rmail-toggle-header] Toggle display of complete header."
1310 (let ((finding-rmail-file (not (eq major-mode
'rmail-mode
))))
1312 (when (and finding-rmail-file
1313 (null coding-system-for-read
)
1314 (default-value 'enable-multibyte-characters
))
1315 (let ((rmail-enable-multibyte t
))
1316 (rmail-require-mime-maybe)
1317 (rmail-convert-file-maybe)
1318 (goto-char (point-max))
1319 (set-buffer-multibyte t
)))
1320 (rmail-set-message-counters)
1321 (rmail-show-message rmail-total-messages
)
1322 (when finding-rmail-file
1323 (when rmail-display-summary
1325 (rmail-construct-io-menu))
1326 (run-mode-hooks 'rmail-mode-hook
)))
1328 (defun rmail-mode-2 ()
1329 (kill-all-local-variables)
1331 (rmail-perm-variables)
1334 (defun rmail-mode-1 ()
1335 (setq major-mode
'rmail-mode
)
1336 (setq mode-name
"RMAIL")
1337 (setq buffer-read-only t
)
1338 ;; No need to auto save RMAIL files in normal circumstances
1339 ;; because they contain no info except attribute changes
1340 ;; and deletion of messages.
1341 ;; The one exception is when messages are copied into another mbox buffer.
1342 ;; rmail-output enables auto save when you do that.
1343 (setq buffer-auto-save-file-name nil
)
1344 (use-local-map rmail-mode-map
)
1345 (set-syntax-table text-mode-syntax-table
)
1346 (setq local-abbrev-table text-mode-abbrev-table
)
1347 ;; Functions to support buffer swapping:
1348 (add-hook 'write-region-annotate-functions
1349 'rmail-write-region-annotate nil t
)
1350 (add-hook 'kill-buffer-hook
'rmail-mode-kill-buffer-hook nil t
)
1351 (add-hook 'change-major-mode-hook
'rmail-change-major-mode-hook nil t
))
1353 (defun rmail-generate-viewer-buffer ()
1354 "Return a reusable buffer suitable for viewing messages.
1355 Create the buffer if necessary."
1356 ;; We want to reuse any existing view buffer, so as not to create an
1357 ;; endless number of them. But we must avoid clashes if we visit
1358 ;; two different rmail files with the same basename (Bug#4593).
1359 (if (and (local-variable-p 'rmail-view-buffer
)
1360 (buffer-live-p rmail-view-buffer
))
1363 (generate-new-buffer
1364 (format " *message-viewer %s*"
1365 (file-name-nondirectory
1366 (or buffer-file-name
(buffer-name)))))))
1367 (with-current-buffer newbuf
1368 (add-hook 'kill-buffer-hook
'rmail-view-buffer-kill-buffer-hook nil t
))
1371 (defun rmail-swap-buffers ()
1372 "Swap text between current buffer and `rmail-view-buffer'.
1373 This function preserves the current buffer's modified flag, and also
1374 sets the current buffer's `buffer-file-coding-system' to that of
1375 `rmail-view-buffer'."
1376 (let ((modp-this (buffer-modified-p))
1378 (with-current-buffer rmail-view-buffer
(buffer-modified-p)))
1379 (coding-this buffer-file-coding-system
)
1381 (with-current-buffer rmail-view-buffer
1382 buffer-file-coding-system
)))
1383 (buffer-swap-text rmail-view-buffer
)
1384 (setq buffer-file-coding-system coding-that
)
1385 (with-current-buffer rmail-view-buffer
1386 (setq buffer-file-coding-system coding-this
)
1387 (restore-buffer-modified-p modp-that
))
1388 (restore-buffer-modified-p modp-this
)))
1390 (defun rmail-buffers-swapped-p ()
1391 "Return non-nil if the message collection is in `rmail-view-buffer'."
1392 ;; This is analogous to tar-data-swapped-p in tar-mode.el.
1393 rmail-buffer-swapped
)
1395 (defun rmail-change-major-mode-hook ()
1396 ;; Bring the actual Rmail messages back into the main buffer.
1397 (when (rmail-buffers-swapped-p)
1398 (rmail-swap-buffers)
1399 (setq rmail-buffer-swapped nil
)))
1401 (defun rmail-swap-buffers-maybe ()
1402 "Determine if the Rmail buffer is showing a message.
1403 If so restore the actual mbox message collection."
1404 (with-current-buffer rmail-buffer
1405 (when (rmail-buffers-swapped-p)
1406 (rmail-swap-buffers)
1407 (setq rmail-buffer-swapped nil
))))
1409 (defun rmail-modify-format ()
1410 "Warn if important modifications would change Rmail file's format."
1411 (with-current-buffer rmail-buffer
1412 (and rmail-was-converted
1413 ;; If it's already modified, don't warn again.
1414 (not rmail-seriously-modified
)
1417 (message "After this, %s would be saved in mbox format. Proceed? "
1420 (setq rmail-seriously-modified t
)))
1422 (defun rmail-dont-modify-format ()
1423 (when (and rmail-was-converted
(not rmail-seriously-modified
))
1424 (set-buffer-modified-p nil
)
1425 (message "Marking buffer unmodified to avoid rewriting Babyl file as mbox file")))
1427 (defun rmail-mode-kill-buffer-hook ()
1428 ;; Turn off the hook on the view buffer, so we can kill it, then kill it.
1429 (if (buffer-live-p rmail-view-buffer
)
1430 (with-current-buffer rmail-view-buffer
1431 (setq kill-buffer-hook nil
)
1432 (kill-buffer rmail-view-buffer
))))
1434 (defun rmail-view-buffer-kill-buffer-hook ()
1435 (error "Can't kill Rmail view buffer `%s' by itself"
1436 (buffer-name (current-buffer))))
1438 ;; Set up the permanent locals associated with an Rmail file.
1439 (defun rmail-perm-variables ()
1440 (make-local-variable 'rmail-last-regexp
)
1441 (make-local-variable 'rmail-deleted-vector
)
1442 (make-local-variable 'rmail-buffer
)
1443 (make-local-variable 'rmail-was-converted
)
1444 (setq rmail-was-converted nil
)
1445 (make-local-variable 'rmail-seriously-modified
)
1446 (setq rmail-seriously-modified nil
)
1447 (setq rmail-buffer
(current-buffer))
1448 (set-buffer-multibyte nil
)
1449 (with-current-buffer (setq rmail-view-buffer
(rmail-generate-viewer-buffer))
1450 (setq buffer-undo-list t
)
1451 ;; Note that this does not erase the buffer. Should it?
1452 ;; It depends on how this is called. If somehow called with the
1453 ;; rmail buffers swapped, it would erase the message collection.
1454 (set (make-local-variable 'rmail-overlay-list
) nil
)
1455 (set-buffer-multibyte t
)
1456 ;; Force C-x C-s write Unix EOLs.
1457 (set-buffer-file-coding-system 'undecided-unix
))
1458 (make-local-variable 'rmail-summary-buffer
)
1459 (make-local-variable 'rmail-summary-vector
)
1460 (make-local-variable 'rmail-current-message
)
1461 (make-local-variable 'rmail-total-messages
)
1462 (setq rmail-total-messages
0)
1463 (make-local-variable 'rmail-message-vector
)
1464 (make-local-variable 'rmail-msgref-vector
)
1465 (make-local-variable 'rmail-inbox-list
)
1466 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1467 (and (null rmail-inbox-list
)
1468 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
1469 (equal buffer-file-truename
1470 (abbreviate-file-name (file-truename rmail-file-name
))))
1471 (setq rmail-inbox-list
1472 (or rmail-primary-inbox-list
1473 (list (or (getenv "MAIL")
1474 ;; FIXME expand-file-name?
1475 (concat rmail-spool-directory
1476 (user-login-name)))))))
1477 (set (make-local-variable 'tool-bar-map
) rmail-tool-bar-map
))
1479 ;; Set up the non-permanent locals associated with Rmail mode.
1480 (defun rmail-variables ()
1481 ;; Turn off undo. We turn it back on in rmail-edit.
1482 (setq buffer-undo-list t
)
1483 ;; Don't let a local variables list in a message cause confusion.
1484 (make-local-variable 'local-enable-local-variables
)
1485 (setq local-enable-local-variables nil
)
1486 ;; Don't turn off auto-saving based on the size of the buffer
1487 ;; because that code does not understand buffer-swapping.
1488 (make-local-variable 'auto-save-include-big-deletions
)
1489 (setq auto-save-include-big-deletions t
)
1490 (make-local-variable 'revert-buffer-function
)
1491 (setq revert-buffer-function
'rmail-revert
)
1492 (make-local-variable 'font-lock-defaults
)
1493 (setq font-lock-defaults
1494 '(rmail-font-lock-keywords
1496 (font-lock-maximum-size . nil
)
1497 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
1498 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
1499 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
1500 (make-local-variable 'require-final-newline
)
1501 (setq require-final-newline nil
)
1502 (make-local-variable 'version-control
)
1503 (setq version-control
'never
)
1504 (make-local-variable 'kill-buffer-hook
)
1505 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
1506 (make-local-variable 'file-precious-flag
)
1507 (setq file-precious-flag t
)
1508 (make-local-variable 'desktop-save-buffer
)
1509 (setq desktop-save-buffer t
)
1510 (setq next-error-move-function
'rmail-next-error-move
))
1512 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1513 (defun rmail-revert (arg noconfirm
)
1514 (set-buffer rmail-buffer
)
1515 (let* ((revert-buffer-function (default-value 'revert-buffer-function
))
1516 (rmail-enable-multibyte enable-multibyte-characters
)
1517 ;; See similar code in `rmail'.
1518 ;; FIXME needs updating?
1519 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
))
1520 (before-revert-hook 'rmail-swap-buffers-maybe
))
1521 ;; Call our caller again, but this time it does the default thing.
1522 (when (revert-buffer arg noconfirm
)
1523 ;; If the user said "yes", and we changed something,
1524 ;; reparse the messages.
1525 (set-buffer rmail-buffer
)
1527 ;; Convert all or part to Babyl file if possible.
1528 (rmail-convert-file-maybe)
1529 ;; We have read the file as raw-text, so the buffer is set to
1530 ;; unibyte. Make it multibyte if necessary.
1531 (if (and rmail-enable-multibyte
1532 (not enable-multibyte-characters
))
1533 (set-buffer-multibyte t
))
1534 (goto-char (point-max))
1535 (rmail-set-message-counters)
1536 (rmail-show-message rmail-total-messages
)
1537 (run-hooks 'rmail-mode-hook
))))
1539 (defun rmail-expunge-and-save ()
1540 "Expunge and save RMAIL file."
1542 (set-buffer rmail-buffer
)
1544 ;; No need to swap buffers: rmail-write-region-annotate takes care of it.
1545 ;; (rmail-swap-buffers-maybe)
1547 (if (rmail-summary-exists)
1548 (rmail-select-summary (set-buffer-modified-p nil
))))
1550 (defun rmail-quit ()
1552 Hook `rmail-quit-hook' is run after expunging."
1554 (set-buffer rmail-buffer
)
1557 (when (boundp 'rmail-quit-hook
)
1558 (run-hooks 'rmail-quit-hook
))
1559 ;; Don't switch to the summary buffer even if it was recently visible.
1560 (when rmail-summary-buffer
1561 (with-current-buffer rmail-summary-buffer
1562 (set-buffer-modified-p nil
))
1563 (replace-buffer-in-windows rmail-summary-buffer
)
1564 (bury-buffer rmail-summary-buffer
))
1565 (let ((obuf (current-buffer)))
1567 (replace-buffer-in-windows obuf
)))
1569 (defun rmail-bury ()
1570 "Bury current Rmail buffer and its summary buffer."
1572 ;; This let var was called rmail-buffer, but that interfered
1573 ;; with the buffer-local var used in summary buffers.
1574 (let ((buffer-to-bury (current-buffer)))
1575 (if (rmail-summary-exists)
1577 (while (setq window
(get-buffer-window rmail-summary-buffer
))
1578 (quit-window nil window
))
1579 (bury-buffer rmail-summary-buffer
)))
1582 (defun rmail-duplicate-message ()
1583 "Create a duplicated copy of the current message.
1584 The duplicate copy goes into the Rmail file just after the original."
1585 ;; If we are in a summary buffer, switch to the Rmail buffer.
1586 ;; FIXME simpler to swap the contents, not the buffers?
1587 (set-buffer rmail-buffer
)
1588 (rmail-modify-format)
1589 (let ((buff (current-buffer))
1590 (n rmail-current-message
)
1591 (beg (rmail-msgbeg rmail-current-message
))
1592 (end (rmail-msgend rmail-current-message
)))
1593 (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer
))
1595 (let ((buffer-read-only nil
)
1596 (string (buffer-substring-no-properties beg end
)))
1600 (rmail-swap-buffers-maybe)
1601 (goto-char (point-max))
1602 (rmail-set-message-counters)
1603 (set-buffer-modified-p t
)
1604 (rmail-show-message-1 n
))
1605 (if (rmail-summary-exists)
1606 (rmail-select-summary (rmail-update-summary)))
1607 (message "Message duplicated"))
1610 (defun rmail-input (filename)
1611 "Run Rmail on file FILENAME."
1612 (interactive "FRun rmail on RMAIL file: ")
1615 ;; This used to scan subdirectories recursively, but someone pointed out
1616 ;; that if the user wants that, person can put all the files in one dir.
1617 ;; And the recursive scan was slow. So I took it out.
1619 (defun rmail-find-all-files (start)
1620 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1621 (if (file-accessible-directory-p start
)
1623 (let* ((case-fold-search t
)
1624 (files (directory-files start t rmail-secondary-file-regexp
)))
1625 ;; Sort here instead of in directory-files
1626 ;; because this list is usually much shorter.
1627 (sort files
'string
<))))
1629 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
1630 (let ((menu (make-sparse-keymap menu-name
))
1638 (car item
) (cdr item
) action
1640 (concat full-name
"/"
1646 (list 'lambda
() '(interactive)
1650 (concat full-name
"/" item
)
1652 rmail-secondary-file-directory
)))))
1653 (define-key menu
(vector (intern name
))
1654 (cons name command
))))
1658 ;; This command is always "disabled" when it appears in a menu.
1659 (put 'rmail-disable-menu
'menu-enable
''nil
)
1661 (defun rmail-construct-io-menu ()
1662 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1665 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1666 (cons "Input Rmail File"
1667 (rmail-list-to-menu "Input Rmail File"
1670 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1671 (cons "Output Rmail File"
1672 (rmail-list-to-menu "Output Rmail File"
1676 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1677 '("Input Rmail File" . rmail-disable-menu
))
1678 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1679 '("Output Rmail File" . rmail-disable-menu
)))))
1682 ;;;; *** Rmail input ***
1684 (declare-function rmail-summary-goto-msg
"rmailsum" (&optional n nowarn skip-rmail
))
1685 (declare-function rmail-summary-mark-undeleted
"rmailsum" (n))
1686 (declare-function rmail-summary-mark-deleted
"rmailsum" (&optional n undel
))
1687 (declare-function rfc822-addresses
"rfc822" (header-text))
1688 (declare-function mail-abbrev-make-syntax-table
"mailabbrev.el" ())
1690 ;; RLK feature not added in this version:
1691 ;; argument specifies inbox file or files in various ways.
1693 ;; In Babyl, the Mail: header in the preamble overrode rmail-inbox-list.
1694 ;; Mbox does not have this feature.
1695 (defun rmail-get-new-mail (&optional file-name
)
1696 "Move any new mail from this Rmail file's inbox files.
1697 The buffer-local variable `rmail-inbox-list' specifies the list
1698 of inbox files. By default, this is nil, except for your primary
1699 Rmail file `rmail-file-name'. In this case, when you first visit
1700 the Rmail file it is initialized using either
1701 `rmail-primary-inbox-list', or the \"MAIL\" environment variable,
1702 or the function `user-login-name' and the directory
1703 `rmail-spool-directory' (whose value depends on the operating system).
1705 The command `set-rmail-inbox-list' sets `rmail-inbox-list' to the
1708 You can also specify the file to get new mail from just for one
1709 instance of this command. In this case, the file of new mail is
1710 not changed or deleted. Noninteractively, you can pass the inbox
1711 file name as an argument. Interactively, a prefix argument
1712 causes us to read a file name and use that file as the inbox.
1714 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1715 always be left in inbox files rather than deleted.
1717 Before doing anything, this runs `rmail-before-get-new-mail-hook'.
1718 Just before returning, it runs `rmail-after-get-new-mail-hook',
1719 whether or not there is new mail.
1721 If there is new mail, it runs `rmail-get-new-mail-hook', saves
1722 the updated file, and shows the first unseen message (which might
1723 not be a new one). It returns non-nil if it got any new messages."
1725 (list (if current-prefix-arg
1726 (read-file-name "Get new mail from file: "))))
1727 (run-hooks 'rmail-before-get-new-mail-hook
)
1728 ;; If the disk file has been changed from under us,
1729 ;; revert to it before we get new mail.
1730 (or (verify-visited-file-modtime (current-buffer))
1731 (find-file (buffer-file-name)))
1732 (set-buffer rmail-buffer
)
1733 (rmail-modify-format)
1734 (rmail-swap-buffers-maybe)
1735 (rmail-maybe-set-message-counters)
1737 ;; Get rid of all undo records for this buffer.
1738 (or (eq buffer-undo-list t
)
1739 (setq buffer-undo-list nil
))
1740 (let ((all-files (if file-name
(list file-name
) rmail-inbox-list
))
1741 (rmail-enable-multibyte (default-value 'enable-multibyte-characters
))
1745 ;; This loops if any members of the inbox list have the same
1746 ;; basename (see "name conflict" below).
1748 (let ((opoint (point))
1749 ;; If buffer has not changed yet, and has not been
1750 ;; saved yet, don't replace the old backup file now.
1751 (make-backup-files (and make-backup-files
1752 (buffer-modified-p)))
1753 (buffer-read-only nil
)
1754 ;; Don't make undo records while getting mail.
1755 (buffer-undo-list t
)
1756 delete-files success files file-last-names
)
1757 ;; Pull files off all-files onto files as long as there is
1758 ;; no name conflict. A conflict happens when two inbox
1759 ;; file names have the same last component.
1760 ;; The reason this careful handling is necessary seems
1761 ;; to be that rmail-insert-inbox-text uses .newmail-BASENAME.
1762 (while (and all-files
1763 (not (member (file-name-nondirectory (car all-files
))
1765 (setq files
(cons (car all-files
) files
)
1767 (cons (file-name-nondirectory (car all-files
)) files
))
1768 (setq all-files
(cdr all-files
)))
1769 ;; Put them back in their original order.
1770 (setq files
(nreverse files
))
1771 (goto-char (point-max))
1772 ;; Make sure we end with a blank line unless there are
1773 ;; no messages, as required by mbox format (Bug#9974).
1775 (while (not (looking-back "\n\n"))
1778 (rmail-get-new-mail-1 file-name files delete-files
)
1780 ;; Move to the first new message unless we have other unseen
1781 ;; messages before it.
1782 (if found
(rmail-show-message (rmail-first-unseen-message)))
1783 (run-hooks 'rmail-after-get-new-mail-hook
)
1785 ;; Don't leave the buffer screwed up if we get a disk-full error.
1786 (rmail-show-message))))
1788 (defvar rmail-use-spam-filter
)
1789 (declare-function rmail-get-new-mail-filter-spam
"rmail-spam-filter" (nnew))
1791 (defun rmail-get-new-mail-1 (file-name files delete-files
)
1792 "Return t if new messages are detected without error, nil otherwise."
1795 (let ((new-messages 0)
1796 (spam-filter-p (and (featurep 'rmail-spam-filter
)
1797 rmail-use-spam-filter
))
1799 result success suffix
)
1800 (narrow-to-region (point) (point))
1801 ;; Read in the contents of the inbox files, renaming them as
1802 ;; necessary, and adding to the list of files to delete
1805 (rmail-insert-inbox-text files nil
)
1806 (setq delete-files
(rmail-insert-inbox-text files t
)))
1807 ;; Scan the new text and convert each message to
1808 ;; Rmail/mbox format.
1809 (goto-char (point-min))
1810 (skip-chars-forward " \n")
1811 (narrow-to-region (point) (point-max))
1813 (setq new-messages
(rmail-add-mbox-headers)
1815 ;; Try to delete the garbage just inserted.
1816 (or success
(delete-region (point-min) (point-max)))
1817 ;; If we could not convert the file's inboxes, rename the
1818 ;; files we tried to read so we won't over and over again.
1819 (if (and (not file-name
) (not success
))
1820 (let ((delfiles delete-files
)
1823 (while (file-exists-p (format "RMAILOSE.%d" count
))
1824 (setq count
(1+ count
)))
1825 (rename-file (car delfiles
) (format "RMAILOSE.%d" count
))
1826 (setq delfiles
(cdr delfiles
))))))
1827 ;; Determine if there are messages.
1828 (unless (zerop new-messages
)
1829 ;; There are. Process them.
1830 (goto-char (point-min))
1831 (rmail-count-new-messages)
1832 (run-hooks 'rmail-get-new-mail-hook
)
1834 ;; Delete the old files, now that the Rmail file is saved.
1837 ;; First, try deleting.
1839 (delete-file (car delete-files
))
1841 ;; If we can't delete it, truncate it.
1842 (write-region (point) (point) (car delete-files
))))
1844 (setq delete-files
(cdr delete-files
)))
1845 (if (zerop new-messages
)
1846 (when (or file-name rmail-inbox-list
)
1847 (message "(No new mail has arrived)"))
1849 (setq blurb
(rmail-get-new-mail-filter-spam new-messages
))))
1850 (if (rmail-summary-exists)
1851 (rmail-select-summary (rmail-update-summary)))
1852 (setq suffix
(if (= 1 new-messages
) "" "s"))
1853 (message "%d new message%s read%s" new-messages suffix blurb
)
1854 ;; Establish the return value.
1855 (setq result
(> new-messages
0))
1858 (defun rmail-parse-url (file)
1859 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1860 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1861 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1862 a remote mailbox, PASSWORD is the password if it should be
1863 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1864 is non-nil if the user has supplied the password interactively.
1867 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file
)
1868 (let (got-password supplied-password
1869 (proto (match-string 1 file
))
1870 (user (match-string 3 file
))
1871 (pass (match-string 5 file
))
1872 (host (substring file
(or (match-end 2)
1873 (+ 3 (match-end 1))))))
1876 (when rmail-remote-password-required
1877 (setq got-password
(not (rmail-have-password)))
1878 (setq supplied-password
(rmail-get-remote-password
1879 (string-equal proto
"imap"))))
1880 ;; The password is embedded. Strip it out since movemail
1881 ;; does not really like it, in spite of the movemail spec.
1882 (setq file
(concat proto
"://" user
"@" host
)))
1884 (if (rmail-movemail-variant-p 'emacs
)
1885 (if (string-equal proto
"pop")
1886 (list (concat "po:" user
":" host
)
1888 (or pass supplied-password
)
1890 (error "Emacs movemail does not support %s protocol" proto
))
1892 (or (string-equal proto
"pop") (string-equal proto
"imap"))
1893 (or supplied-password pass
)
1896 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file
)
1897 (let (got-password supplied-password
1899 (user (match-string 1 file
))
1900 (host (match-string 3 file
)))
1902 (when rmail-remote-password-required
1903 (setq got-password
(not (rmail-have-password)))
1904 (setq supplied-password
(rmail-get-remote-password nil
)))
1906 (list file
"pop" supplied-password got-password
)))
1909 (list file nil nil nil
))))
1911 (defun rmail-unrmail-new-mail (from-file)
1912 "Replace newly read mail in Babyl format with equivalent mbox format.
1914 FROM-FILE is the Babyl file from which the new mail should be read."
1915 (let ((to-file (make-temp-file "rmail"))
1917 (unrmail from-file to-file
)
1918 (let ((inhibit-read-only t
)
1919 (coding-system-for-read 'raw-text
)
1920 (buffer-undo-list t
))
1921 (delete-region (point) (point-max))
1922 (setq size
(nth 1 (insert-file-contents to-file
)))
1923 (delete-file to-file
)
1926 (defun rmail-unrmail-new-mail-maybe (file size
)
1927 "If newly read mail from FILE is in Babyl format, convert it to mbox format.
1929 SIZE is the original size of the newly read mail.
1930 Value is the size of the newly read mail after conversion."
1931 ;; Detect previous Babyl format files.
1932 (let ((case-fold-search nil
)
1935 (cond ((looking-at "BABYL OPTIONS:")
1936 ;; The new mail is in Babyl version 5 format. Use unrmail
1938 (setq size
(rmail-unrmail-new-mail old-file
)))
1939 ((looking-at "Version: 5\n")
1940 ;; New mail is in Babyl format made by old version of
1941 ;; Rmail. Fix the babyl file header and use unrmail to
1943 (let ((buffer-read-only nil
)
1944 (write-region-annotate-functions nil
)
1945 (write-region-post-annotation-function nil
)
1946 (old-file (make-temp-file "rmail")))
1947 (insert "BABYL OPTIONS: -*- rmail -*-\n")
1949 (write-region (point) (point-max) old-file
)
1950 (setq size
(rmail-unrmail-new-mail old-file
))
1951 (delete-file old-file
))))
1954 (defun rmail-insert-inbox-text (files renamep
)
1955 ;; Detect a locked file now, so that we avoid moving mail
1956 ;; out of the real inbox file. (That could scare people.)
1957 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1958 (error "RMAIL file %s is locked"
1959 (file-name-nondirectory buffer-file-name
)))
1960 (let (file tofile delete-files movemail popmail got-password password
)
1962 ;; Handle remote mailbox names specially; don't expand as filenames
1963 ;; in case the userid contains a directory separator.
1964 (setq file
(car files
))
1965 (let ((url-data (rmail-parse-url file
)))
1966 (setq file
(nth 0 url-data
))
1967 (setq popmail
(nth 1 url-data
))
1968 (setq password
(nth 2 url-data
))
1969 (setq got-password
(nth 3 url-data
)))
1973 (setq file
(file-truename
1974 (substitute-in-file-name (expand-file-name file
)))))
1975 (setq tofile
(expand-file-name
1976 ;; Generate name to move to from inbox name,
1977 ;; in case of multiple inboxes that need moving.
1979 (file-name-nondirectory
1980 (if (memq system-type
'(windows-nt cygwin ms-dos
))
1981 ;; cannot have colons in file name
1982 (replace-regexp-in-string ":" "-" file
)
1984 ;; Use the directory of this rmail file
1985 ;; because it's a nuisance to use the homedir
1986 ;; if that is on a full disk and this rmail
1988 (file-name-directory
1989 (expand-file-name buffer-file-name
))))
1990 ;; Always use movemail to rename the file,
1991 ;; since there can be mailboxes in various directories.
1993 ;; On some systems, /usr/spool/mail/foo is a directory
1994 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1995 (if (file-directory-p file
)
1996 (setq file
(expand-file-name (user-login-name)
1999 (message "Getting mail from the remote server ..."))
2000 ((and (file-exists-p tofile
)
2001 (/= 0 (nth 7 (file-attributes tofile
))))
2002 (message "Getting mail from %s..." tofile
))
2003 ((and (file-exists-p file
)
2004 (/= 0 (nth 7 (file-attributes file
))))
2005 (message "Getting mail from %s..." file
)))
2006 ;; Set TOFILE if have not already done so, and
2007 ;; rename or copy the file FILE to TOFILE if and as appropriate.
2008 (cond ((not renamep
)
2010 ((or (file-exists-p tofile
) (and (not popmail
)
2011 (not (file-exists-p file
))))
2015 (let ((errors (current-buffer)))
2016 (buffer-disable-undo errors
)
2019 (list (or rmail-movemail-program
"movemail") nil errors nil
)
2020 (if rmail-preserve-inbox
2023 (if (rmail-movemail-variant-p 'mailutils
)
2024 (append (list "--emacs") rmail-movemail-flags
)
2025 rmail-movemail-flags
)
2027 (if password
(list password
) nil
))))
2028 (apply 'call-process args
))
2029 (if (not (buffer-modified-p errors
))
2030 ;; No output => movemail won
2033 (subst-char-in-region (point-min) (point-max)
2035 (goto-char (point-max))
2036 (skip-chars-backward " \t")
2037 (delete-region (point) (point-max))
2038 (goto-char (point-min))
2039 (if (looking-at "movemail: ")
2040 (delete-region (point-min) (match-end 0)))
2042 ;; If we just read the password, most likely it is
2043 ;; wrong. Otherwise, see if there is a specific
2044 ;; reason to think that the problem is a wrong passwd.
2045 (if (or got-password
2046 (re-search-forward rmail-remote-password-error
2048 (rmail-set-remote-password nil
))
2050 ;; If using Mailutils, remove initial error code
2052 (when (rmail-movemail-variant-p 'mailutils
)
2053 (goto-char (point-min))
2054 (when (looking-at "[A-Z][A-Z0-9_]*:")
2055 (delete-region (point-min) (match-end 0))))
2057 (message "movemail: %s"
2058 (buffer-substring (point-min)
2064 ;; At this point, TOFILE contains the name to read:
2065 ;; Either the alternate name (if we renamed)
2066 ;; or the actual inbox (if not renaming).
2067 (if (file-exists-p tofile
)
2068 (let ((coding-system-for-read 'no-conversion
)
2070 (goto-char (point-max))
2072 ;; If new mail is in Babyl format, convert it to mbox.
2073 (rmail-unrmail-new-mail-maybe
2075 (nth 1 (insert-file-contents tofile
))))
2076 (goto-char (point-max))
2077 ;; Make sure the read-in mbox data properly ends with a
2078 ;; blank line unless it is of size 0.
2079 (unless (zerop size
)
2080 (while (not (looking-back "\n\n"))
2082 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
2083 (setq delete-files
(cons tofile delete-files
)))))
2085 (setq files
(cdr files
)))
2088 ;; Decode the region specified by FROM and TO by CODING.
2089 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
2090 (defun rmail-decode-region (from to coding
&optional destination
)
2091 (if (or (not coding
) (not (coding-system-p coding
)))
2092 (setq coding
'undecided
))
2093 ;; Use -dos decoding, to remove ^M characters left from base64 or
2094 ;; rogue qp-encoded text.
2095 (decode-coding-region
2096 from to
(coding-system-change-eol-conversion coding
1) destination
)
2097 ;; Don't reveal the fact we used -dos decoding, as users generally
2098 ;; will not expect the RMAIL buffer to use DOS EOL format.
2101 (setq buffer-file-coding-system
2102 (setq last-coding-system-used
2103 (coding-system-change-eol-conversion coding
0))))
2104 ((bufferp destination
)
2105 (with-current-buffer destination
2106 (setq buffer-file-coding-system
2107 (setq last-coding-system-used
2108 (coding-system-change-eol-conversion coding
0)))))))
2110 (defun rmail-ensure-blank-line ()
2111 "Ensure a message ends in a blank line.
2112 Call with point at the end of the message."
2115 (unless (looking-back "\n\n")
2118 (defun rmail-add-mbox-headers ()
2119 "Validate the RFC2822 format for the new messages.
2120 Point should be at the first new message.
2121 An error is signaled if the new messages are not RFC2822
2123 Unless an Rmail attribute header already exists, add it to the
2124 new messages. Return the number of new messages."
2130 (case-fold-search nil
)
2131 (delim (concat "\n\n" rmail-unix-mail-delimiter
))
2133 ;; Detect an empty inbox file.
2134 (unless (= start
(point-max))
2135 ;; Scan the new messages to establish a count and to ensure that
2136 ;; an attribute header is present.
2137 (if (looking-at rmail-unix-mail-delimiter
)
2139 ;; Determine if a new attribute header needs to be
2140 ;; added to the message.
2141 (if (search-forward "\n\n" nil t
)
2143 (setq count
(1+ count
))
2144 (narrow-to-region start
(point))
2145 (unless (mail-fetch-field rmail-attribute-header
)
2147 (insert rmail-attribute-header
": " value
"\n"))
2149 (rmail-error-bad-format))
2150 ;; Move to the next message.
2151 (if (not (re-search-forward delim nil
'move
))
2153 (goto-char (match-beginning 0))
2155 (setq start
(point)))
2156 (rmail-error-bad-format)))
2159 (defun rmail-get-header-1 (name)
2160 "Subroutine of `rmail-get-header'.
2161 Narrow to header, call `mail-fetch-field' to find header NAME."
2162 (if (search-forward "\n\n" nil t
)
2164 (narrow-to-region (point-min) (point))
2165 (mail-fetch-field name
))
2166 (rmail-error-bad-format)))
2168 (defun rmail-get-header (name &optional msgnum
)
2169 "Return the value of message header NAME, nil if it has none.
2170 MSGNUM specifies the message number to get it from.
2171 If MSGNUM is nil, use the current message."
2172 (rmail-apply-in-message msgnum
'rmail-get-header-1 name
))
2174 (defun rmail-set-header-1 (name value
)
2175 "Subroutine of `rmail-set-header'.
2176 Narrow to header, set header NAME to VALUE, replacing existing if present.
2177 VALUE nil means to remove NAME altogether."
2178 (if (search-forward "\n\n" nil t
)
2181 (narrow-to-region (point-min) (point))
2182 (goto-char (point-min))
2183 (if (re-search-forward (concat "^" (regexp-quote name
) ":") nil
'move
)
2186 (delete-region (point) (line-end-position))
2188 (delete-region (line-beginning-position)
2189 (line-beginning-position 2)))
2190 (if value
(insert name
": " value
"\n"))))
2191 (rmail-error-bad-format)))
2193 (defun rmail-set-header (name &optional msgnum value
)
2194 "Set message header NAME to VALUE in message number MSGNUM.
2195 If MSGNUM is nil, use the current message. NAME and VALUE are strings.
2196 VALUE may also be nil, meaning to remove the header."
2197 (rmail-apply-in-message msgnum
'rmail-set-header-1 name value
)
2198 (with-current-buffer rmail-buffer
2199 ;; Ensure header changes get saved.
2200 ;; (Note replacing a header with an identical copy modifies.)
2201 (set-buffer-modified-p t
)
2202 ;; However: don't save in mbox format over a Babyl file
2203 ;; merely because of this.
2204 (rmail-dont-modify-format)))
2206 ;;;; *** Rmail Attributes and Keywords ***
2208 (defun rmail-get-attr-names (&optional msg
)
2209 "Return the message attributes in a comma separated string.
2210 MSG specifies the message number to get it from.
2211 If MSG is nil, use the current message."
2212 (let ((value (rmail-get-header rmail-attribute-header msg
))
2213 (nmax (length rmail-attr-array
))
2216 (if (> (length value
) nmax
)
2217 (message "Warning: corrupt attribute header in message")
2218 (dotimes (index (length value
))
2219 (setq temp
(and (not (= ?-
(aref value index
)))
2220 (nth 1 (aref rmail-attr-array index
)))
2223 ((and temp result
) (format "%s, %s" result temp
))
2228 (defun rmail-get-keywords (&optional msg
)
2229 "Return the message keywords in a comma separated string.
2230 MSG, if non-nil, identifies the message number to use.
2231 If nil, that means the current message."
2232 (rmail-get-header rmail-keyword-header msg
))
2234 (defun rmail-get-labels (&optional msg
)
2235 "Return a string with the labels (attributes and keywords) of msg MSG.
2236 It is put in comma-separated form.
2237 MSG, if non-nil, identifies the message number to use.
2238 If nil, that means the current message."
2239 (or msg
(setq msg rmail-current-message
))
2240 (let (attr-names keywords
)
2241 ;; Combine the message attributes and keywords
2242 ;; into a comma-separated list.
2243 (setq attr-names
(rmail-get-attr-names msg
)
2244 keywords
(rmail-get-keywords msg
))
2245 (if (string= keywords
"")
2246 (setq keywords nil
))
2248 ;; FIXME ? old rmail did not have spaces in the comma-separated lists.
2249 ((and attr-names keywords
) (concat " " attr-names
"; " keywords
))
2250 (attr-names (concat " " attr-names
))
2251 (keywords (concat " " keywords
))
2254 (defun rmail-display-labels ()
2255 "Update the current messages's attributes and keywords in mode line."
2256 (let ((blurb (rmail-get-labels)))
2257 (setq mode-line-process
2259 rmail-current-message rmail-total-messages blurb
))))
2261 (defun rmail-get-attr-value (attr state
)
2262 "Return the character value for ATTR.
2263 ATTR is a (numeric) index, an offset into the mbox attribute
2264 header value. STATE is one of nil, t, or a character value."
2266 ((numberp state
) state
)
2268 (t (nth 0 (aref rmail-attr-array attr
)))))
2270 (defun rmail-set-attribute-1 (attr state
)
2271 "Subroutine of `rmail-set-attribute'.
2272 Set Rmail attribute ATTR to STATE in `rmail-attribute-header',
2273 creating the header if necessary. Returns non-nil if a
2274 significant attribute change was made."
2275 (let ((limit (search-forward "\n\n" nil t
))
2276 (value (rmail-get-attr-value attr state
))
2277 (inhibit-read-only t
)
2279 (goto-char (point-min))
2280 (if (search-forward (concat rmail-attribute-header
": ") limit t
)
2281 ;; If this message already records attributes, just change the
2282 ;; value for this one.
2283 (let ((missing (- (+ (point) attr
) (line-end-position))))
2284 ;; Position point at this attribute, adding attributes if necessary.
2288 (insert-char ?- missing
)
2290 (forward-char attr
))
2291 ;; Change this attribute.
2292 (when (/= value
(char-after))
2296 ;; Otherwise add a header line to record the attributes and set
2297 ;; all but this one to no.
2298 (let ((header-value "--------"))
2299 (aset header-value attr value
)
2300 (goto-char (if limit
(1- limit
) (point-max)))
2301 (setq altered
(/= value ?-
))
2302 (insert rmail-attribute-header
": " header-value
"\n")))
2305 (defun rmail-set-attribute (attr state
&optional msgnum
)
2306 "Turn an attribute of a message on or off according to STATE.
2307 STATE is either nil or the character (numeric) value associated
2308 with the state (nil represents off and non-nil represents on).
2309 ATTR is either the index number of the attribute, or a string,
2310 both from `rmail-attr-array'. MSGNUM is message number to
2311 change; nil means current message."
2313 (nmax (length rmail-attr-array
)))
2314 (while (and (stringp attr
)
2316 (if (string-equal attr
(cadr (aref rmail-attr-array n
)))
2320 (error "Unknown attribute `%s'" attr
))
2321 ;; Ask for confirmation before setting any attribute except `unseen'
2322 ;; if it would force a format change.
2323 (unless (= attr rmail-unseen-attr-index
)
2324 (rmail-modify-format))
2325 (with-current-buffer rmail-buffer
2326 (or msgnum
(setq msgnum rmail-current-message
))
2328 ;; The "deleted" attribute is also stored in a special vector so
2330 (if (= attr rmail-deleted-attr-index
)
2331 (rmail-set-message-deleted-p msgnum state
))
2333 (rmail-apply-in-message msgnum
'rmail-set-attribute-1 attr state
)
2334 (if (= msgnum rmail-current-message
)
2335 (rmail-display-labels)))
2336 ;; Don't save in mbox format over a Babyl file
2337 ;; merely because of a change in `unseen' attribute.
2338 (if (= attr rmail-unseen-attr-index
)
2339 (rmail-dont-modify-format)
2340 ;; Otherwise, if we modified the file text via the view buffer,
2341 ;; mark the main buffer modified too.
2342 (set-buffer-modified-p t
))))))
2344 (defun rmail-message-attr-p (msg attrs
)
2345 "Return non-nil if message number MSG has attributes matching regexp ATTRS."
2346 (let ((value (rmail-get-header rmail-attribute-header msg
)))
2347 (and value
(string-match attrs value
))))
2349 (defun rmail-message-unseen-p (msgnum)
2350 "Return non-nil if message number MSGNUM has the unseen attribute."
2351 (rmail-message-attr-p msgnum
"......U"))
2353 ;; FIXME rmail-get-labels does some formatting (eg leading space, `;'
2354 ;; between attributes and labels), so this might not do what you want.
2355 ;; Eg see rmail-sort-by-labels. rmail-get-labels could have an
2356 ;; optional `noformat' argument.
2357 (defun rmail-message-labels-p (msg labels
)
2358 "Return non-nil if message number MSG has labels matching regexp LABELS."
2359 (string-match labels
(rmail-get-labels msg
)))
2361 ;;;; *** Rmail Message Selection And Support ***
2363 (defun rmail-msgend (n)
2364 "Return the end position for message number N."
2365 (marker-position (aref rmail-message-vector
(1+ n
))))
2367 (defun rmail-msgbeg (n)
2368 "Return the start position for message number N."
2369 (marker-position (aref rmail-message-vector n
)))
2371 (defun rmail-apply-in-message (msgnum function
&rest args
)
2372 "Call FUNCTION on ARGS while narrowed to message MSGNUM.
2373 Point is at the start of the message.
2374 This returns what the call to FUNCTION returns.
2375 If MSGNUM is nil, use the current message."
2376 (with-current-buffer rmail-buffer
2377 (or msgnum
(setq msgnum rmail-current-message
))
2379 (let (msgbeg msgend
)
2380 (setq msgbeg
(rmail-msgbeg msgnum
))
2381 (setq msgend
(rmail-msgend msgnum
))
2382 ;; All access to the rmail-buffer's local variables is now finished...
2384 ;; ... so it is ok to go to a different buffer.
2385 (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer
))
2390 (narrow-to-region msgbeg msgend
)
2391 (apply function args
))))))))
2393 ;; Unused (save for commented out code in rmailedit.el).
2394 (defun rmail-widen-to-current-msgbeg (function)
2395 "Call FUNCTION with point at start of internal data of current message.
2396 Assumes that bounds were previously narrowed to display the message in Rmail.
2397 The bounds are widened enough to move point where desired, then narrowed
2400 FUNCTION may not change the visible text of the message, but it may
2401 change the invisible header text."
2405 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2407 (goto-char (point-min))
2409 ;; Note: we don't use save-restriction because that does not work right
2410 ;; if changes are made outside the saved restriction
2411 ;; before that restriction is restored.
2412 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2413 (rmail-msgend rmail-current-message
)))))
2415 ;; Manage the message vectors and counters.
2417 (defun rmail-forget-messages ()
2419 (if (vectorp rmail-message-vector
)
2420 (let* ((v rmail-message-vector
)
2424 (move-marker (aref v i
) nil
)))))
2425 (setq rmail-message-vector nil
)
2426 (setq rmail-msgref-vector nil
)
2427 (setq rmail-deleted-vector nil
)))
2429 (defun rmail-maybe-set-message-counters ()
2430 (if (not (and rmail-deleted-vector
2431 rmail-message-vector
2432 rmail-current-message
2433 rmail-total-messages
))
2434 (rmail-set-message-counters)))
2436 (defun rmail-count-new-messages (&optional nomsg
)
2437 "Count the number of new messages.
2438 The buffer should be narrowed to include only the new messages.
2439 Output a helpful message unless NOMSG is non-nil."
2440 (let* ((case-fold-search nil
)
2444 (or nomsg
(message "Counting new messages..."))
2445 (goto-char (point-max))
2446 ;; Put at the end of messages-head
2447 ;; the entry for message N+1, which marks
2448 ;; the end of message N. (N = number of messages).
2449 (setq messages-head
(list (point-marker)))
2450 (rmail-set-message-counters-counter (point-min))
2451 (setq rmail-current-message
(1+ rmail-total-messages
))
2452 (setq rmail-total-messages
2453 (+ rmail-total-messages total-messages
))
2454 (setq rmail-message-vector
2455 (vconcat rmail-message-vector
(cdr messages-head
)))
2456 (aset rmail-message-vector
2457 rmail-current-message
(car messages-head
))
2458 (setq rmail-deleted-vector
2459 (concat rmail-deleted-vector deleted-head
))
2460 (setq rmail-summary-vector
2461 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
2462 (setq rmail-msgref-vector
2463 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
2464 ;; Fill in the new elements of rmail-msgref-vector.
2465 (let ((i (1+ (- rmail-total-messages total-messages
))))
2466 (while (<= i rmail-total-messages
)
2467 (aset rmail-msgref-vector i
(list i
))
2469 (goto-char (point-min))
2470 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
2472 (defun rmail-set-message-counters ()
2473 (rmail-forget-messages)
2477 (let* ((point-save (point))
2479 (messages-after-point)
2480 (case-fold-search nil
)
2483 ;; Determine how many messages follow point.
2484 (message "Counting messages...")
2485 (goto-char (point-max))
2486 ;; Put at the end of messages-head
2487 ;; the entry for message N+1, which marks
2488 ;; the end of message N. (N = number of messages).
2489 (setq messages-head
(list (point-marker)))
2490 (setq messages-after-point
2491 (or (rmail-set-message-counters-counter (min (point) point-save
))
2494 (setq rmail-total-messages total-messages
)
2495 (setq rmail-current-message
2497 (max 1 (- total-messages messages-after-point
))))
2499 ;; Make an element 0 in rmail-message-vector and rmail-deleted-vector
2500 ;; which will never be used.
2501 (push nil messages-head
)
2502 (push ?
0 deleted-head
)
2503 (setq rmail-message-vector
(apply 'vector messages-head
)
2504 rmail-deleted-vector
(concat deleted-head
))
2506 (setq rmail-summary-vector
(make-vector rmail-total-messages nil
)
2507 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
2510 (while (<= i rmail-total-messages
)
2511 (aset rmail-msgref-vector i
(list i
))
2514 (while (<= i rmail-total-messages
)
2515 (rmail-set-message-deleted-p i
(rmail-message-attr-p i
".D"))
2517 (message "Counting messages...done")))))
2520 (defsubst rmail-collect-deleted
(message-end)
2521 "Collect the message deletion flags for each message.
2522 MESSAGE-END is the buffer position corresponding to the end of
2523 the message. Point is at the beginning of the message."
2524 ;; NOTE: This piece of code will be executed on a per-message basis.
2525 ;; In the face of thousands of messages, it has to be as fast as
2526 ;; possible, hence some brute force constant use is employed in
2527 ;; addition to inlining.
2530 (cons (if (and (search-forward (concat rmail-attribute-header
": ") message-end t
)
2533 ?\s
) deleted-head
))))
2535 (defun rmail-set-message-counters-counter (&optional spot-to-find
)
2536 "Collect the start positions of messages in list `messages-head'.
2537 Return the number of messages after the one containing SPOT-TO-FIND."
2538 (let ((start (point))
2539 messages-after-spot
)
2540 (while (search-backward "\n\nFrom " nil t
)
2542 (when (looking-at rmail-unix-mail-delimiter
)
2543 (if (and (<= (point) spot-to-find
)
2544 (null messages-after-spot
))
2545 (setq messages-after-spot total-messages
))
2546 (rmail-collect-deleted start
)
2547 (setq messages-head
(cons (point-marker) messages-head
)
2548 total-messages
(1+ total-messages
)
2550 ;; Show progress after every 20 messages or so.
2551 (if (zerop (% total-messages
20))
2552 (message "Counting messages...%d" total-messages
))))
2553 ;; Handle the first message, maybe.
2554 (goto-char (point-min))
2555 (unless (not (looking-at rmail-unix-mail-delimiter
))
2556 (if (and (<= (point) spot-to-find
)
2557 (null messages-after-spot
))
2558 (setq messages-after-spot total-messages
))
2559 (rmail-collect-deleted start
)
2560 (setq messages-head
(cons (point-marker) messages-head
)
2561 total-messages
(1+ total-messages
)))
2562 messages-after-spot
))
2564 ;; Display a message.
2566 ;;;; *** Rmail Message Formatting and Header Manipulation ***
2568 ;; This is used outside of rmail.
2569 (defun rmail-msg-is-pruned ()
2570 "Return nil if the current message is showing full headers."
2571 (with-current-buffer (if (rmail-buffers-swapped-p) rmail-view-buffer
2573 (eq rmail-header-style
'normal
)))
2575 (defun rmail-toggle-header (&optional arg
)
2576 "Toggle between showing full and normal message headers.
2577 With optional integer ARG, show the normal message header if ARG
2578 is greater than zero; otherwise, show it in full."
2580 (let ((rmail-header-style
2582 (if (> arg
0) 'normal
'full
)
2583 (if (rmail-msg-is-pruned) 'full
'normal
))))
2584 (rmail-show-message)))
2586 (defun rmail-beginning-of-message ()
2587 "Show current message starting from the beginning."
2589 (let ((rmail-show-message-hook '((lambda () (goto-char (point-min)))))
2590 (rmail-header-style (with-current-buffer (if (rmail-buffers-swapped-p)
2593 rmail-header-style
)))
2594 (rmail-show-message rmail-current-message
)))
2596 (defun rmail-end-of-message ()
2597 "Show bottom of current message."
2599 (let ((rmail-show-message-hook '((lambda ()
2600 (goto-char (point-max))
2601 (recenter (1- (window-height))))))
2602 (rmail-header-style (with-current-buffer (if (rmail-buffers-swapped-p)
2605 rmail-header-style
)))
2606 (rmail-show-message rmail-current-message
)))
2608 (defun rmail-unknown-mail-followup-to ()
2609 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2610 Ask the user whether to add that list name to `mail-mailing-lists'."
2611 ;; FIXME s-r not needed? Use rmail-get-header?
2612 ;; We have not narrowed to the headers at ths point?
2614 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t
)))
2615 (when mail-followup-to
2618 (mail-strip-quoted-names mail-followup-to
)
2619 ",[[:space:]]+" t
)))
2620 (dolist (addr addresses
)
2621 (when (and (not (member addr mail-mailing-lists
))
2623 ;; taken from rmailsum.el
2625 (or rmail-user-mail-address-regexp
2627 (regexp-quote (user-login-name))
2630 (or user-mail-address
2631 (concat (user-login-name) "@"
2632 (or mail-host-address
2637 (format "Add `%s' to `mail-mailing-lists'? "
2639 (customize-save-variable 'mail-mailing-lists
2640 (cons addr mail-mailing-lists
)))))))))
2642 (defun rmail-widen ()
2643 "Display the entire mailbox file."
2645 (rmail-swap-buffers-maybe)
2648 (defun rmail-no-mail-p ()
2649 "Return nil if there is mail, else \"No mail.\"."
2650 (if (zerop rmail-total-messages
)
2652 ;; Eg we deleted all the messages, so remove the old N/M mark.
2653 (with-current-buffer rmail-buffer
(setq mode-line-process nil
))
2654 (with-current-buffer rmail-view-buffer
2658 (defun rmail-show-message (&optional n no-summary
)
2659 "Show message number N (prefix argument), counting from start of file.
2660 If summary buffer is currently displayed, update current message there also.
2661 N defaults to the current message."
2663 (or (eq major-mode
'rmail-mode
)
2664 (switch-to-buffer rmail-buffer
))
2665 ;; FIXME: Why do we swap the raw data back in?
2666 (rmail-swap-buffers-maybe)
2667 (rmail-maybe-set-message-counters)
2669 (let ((blurb (rmail-show-message-1 n
)))
2670 (or (zerop rmail-total-messages
)
2672 (when mail-mailing-lists
2673 (rmail-unknown-mail-followup-to))
2674 (if transient-mark-mode
(deactivate-mark))
2675 ;; If there is a summary buffer, try to move to this message
2676 ;; in that buffer. But don't complain if this message is
2677 ;; not mentioned in the summary. Don't do this at all if we
2678 ;; were called on behalf of cursor motion in the summary
2680 (and (rmail-summary-exists) (not no-summary
)
2681 (let ((curr-msg rmail-current-message
))
2682 (rmail-select-summary
2683 (rmail-summary-goto-msg curr-msg t t
))))
2684 (with-current-buffer rmail-buffer
2685 (rmail-auto-file))))
2689 (defun rmail-is-text-p ()
2690 "Return t if the region contains a text message, nil otherwise."
2692 (let ((text-regexp "\\(text\\|message\\)/")
2693 (content-type-header (mail-fetch-field "content-type")))
2694 ;; The message is text if either there is no content type header
2695 ;; (a default of "text/plain; charset=US-ASCII" is assumed) or
2696 ;; the base content type is either text or message.
2697 (or (not content-type-header
)
2698 (string-match text-regexp content-type-header
)))))
2700 (defcustom rmail-show-message-verbose-min
200000
2701 "Message size at which to show progress messages for displaying it."
2707 ;; rmail-show-mime-function does not unquote >From lines. Should it?
2708 (defcustom rmail-mbox-format
'mboxrd
2709 "The mbox format that your system uses.
2710 There is no way to determine this, so you should set the appropriate value.
2711 The formats quote lines containing \"From \" differently.
2713 `mboxo' : lines that start with \"From \" quoted as \">From \"
2714 `mboxrd': lines that start with \">*From \" quoted with another \">\"
2715 The `mboxo' format is ambiguous, in that one cannot know whether
2716 a line starting with \">From \" originally had a \">\" or not.
2718 It is not critical to set this to the correct value; it only affects
2719 how Rmail displays lines starting with \">*From \" in non-MIME messages.
2721 See also `unrmail-mbox-format'."
2722 :type
'(choice (const mboxrd
)
2725 :group
'rmail-files
)
2727 (defun rmail-show-message-1 (&optional msg
)
2728 "Show message MSG (default: current message) using `rmail-view-buffer'.
2729 Return text to display in the minibuffer if MSG is out of
2730 range (displaying a reasonable choice as well), nil otherwise.
2731 The current mail message becomes the message displayed."
2732 (let ((mbox-buf rmail-buffer
)
2733 (view-buf rmail-view-buffer
)
2734 blurb beg end body-start coding-system character-coding
2735 is-text-message header-style
)
2737 (setq msg rmail-current-message
))
2738 (unless (setq blurb
(rmail-no-mail-p))
2741 rmail-current-message
1
2742 blurb
"No previous message"))
2743 ((> msg rmail-total-messages
)
2744 (setq msg rmail-total-messages
2745 rmail-current-message rmail-total-messages
2746 blurb
"No following message"))
2747 (t (setq rmail-current-message msg
)))
2748 (with-current-buffer rmail-buffer
2749 (setq header-style rmail-header-style
)
2750 ;; Mark the message as seen, but preserve buffer modified flag.
2751 (let ((modiff (buffer-modified-p)))
2752 (rmail-set-attribute rmail-unseen-attr-index nil
)
2754 (restore-buffer-modified-p modiff
)))
2755 ;; bracket the message in the mail
2756 ;; buffer and determine the coding system the transfer encoding.
2757 (rmail-swap-buffers-maybe)
2758 (setq beg
(rmail-msgbeg msg
)
2759 end
(rmail-msgend msg
))
2760 (when (> (- end beg
) rmail-show-message-verbose-min
)
2761 (message "Showing message %d" msg
))
2762 (narrow-to-region beg end
)
2764 (with-current-buffer rmail-view-buffer
2765 ;; We give the view buffer a buffer-local value of
2766 ;; rmail-header-style based on the binding in effect when
2767 ;; this function is called; `rmail-toggle-headers' can
2768 ;; inspect this value to determine how to toggle.
2769 (set (make-local-variable 'rmail-header-style
) header-style
))
2770 (if (and rmail-enable-mime
2771 rmail-show-mime-function
2772 (re-search-forward "mime-version: 1.0" nil t
))
2773 (let ((rmail-buffer mbox-buf
)
2774 (rmail-view-buffer view-buf
))
2775 (set (make-local-variable 'rmail-mime-decoded
) t
)
2776 (funcall rmail-show-mime-function
))
2777 (setq body-start
(search-forward "\n\n" nil t
))
2778 (narrow-to-region beg
(point))
2781 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2782 (setq coding-system
(intern (match-string 1)))
2783 (setq coding-system
(rmail-get-coding-system))))
2784 (setq character-coding
(mail-fetch-field "content-transfer-encoding")
2785 is-text-message
(rmail-is-text-p))
2786 (if character-coding
2787 (setq character-coding
(downcase character-coding
)))
2788 (narrow-to-region beg end
)
2789 ;; Decode the message body into an empty view buffer using a
2790 ;; unibyte temporary buffer where the character decoding takes
2792 (with-current-buffer rmail-view-buffer
2794 (if (null character-coding
)
2795 ;; Do it directly since that is fast.
2796 (rmail-decode-region body-start end coding-system view-buf
)
2797 ;; Can this be done directly, skipping the temp buffer?
2799 (set-buffer-multibyte nil
)
2800 (insert-buffer-substring mbox-buf body-start end
)
2802 ((string= character-coding
"quoted-printable")
2804 (or (mail-unquote-printable-region (point-min) (point-max)
2806 (message "Malformed MIME quoted-printable message")))
2807 ((and (string= character-coding
"base64") is-text-message
)
2809 (base64-decode-region (point-min) (point-max))
2810 (error (message "%s" (cdr err
)))))
2811 ((eq character-coding
'uuencode
)
2812 (error "uuencoded messages are not supported yet"))
2814 (rmail-decode-region (point-min) (point-max)
2815 coding-system view-buf
)))
2816 (with-current-buffer rmail-view-buffer
2817 ;; Prepare the separator (blank line) before the body.
2818 (goto-char (point-min))
2820 ;; Unquote quoted From lines.
2821 (let ((fromline (if (eq 'mboxrd rmail-mbox-format
)
2825 (while (re-search-forward fromline nil t
)
2829 (goto-char (point-min)))
2830 ;; Copy the headers to the front of the message view buffer.
2831 (rmail-copy-headers beg end
)
2832 ;; Decode any RFC2047 encoded message headers.
2833 (if rmail-enable-mime
2834 (with-current-buffer rmail-view-buffer
2835 (rfc2047-decode-region
2838 (search-forward "\n\n" nil
'move
)
2840 ;; highlight the message, activate any URL like text and add
2841 ;; special highlighting for and quoted material.
2842 (with-current-buffer rmail-view-buffer
2843 (goto-char (point-min))
2844 (rmail-highlight-headers)
2845 ;(rmail-activate-urls)
2846 ;(rmail-process-quoted-material)
2848 ;; Update the mode-line with message status information and swap
2849 ;; the view buffer/mail buffer contents.
2850 (rmail-display-labels)
2851 (rmail-swap-buffers)
2852 (setq rmail-buffer-swapped t
)
2853 (run-hooks 'rmail-show-message-hook
)
2854 (when (> (- end beg
) rmail-show-message-verbose-min
)
2855 (message "Showing message %d...done" msg
))))
2858 (defun rmail-copy-headers (beg end
&optional ignored-headers
)
2859 "Copy displayed header fields to the message viewer buffer.
2860 BEG and END marks the start and end positions of the message in
2861 the mbox buffer. If the optional argument IGNORED-HEADERS is
2862 non-nil, ignore all header fields whose names match that regexp.
2863 Otherwise, if `rmail-displayed-headers' is non-nil, copy only
2864 those header fields whose names match that regexp. Otherwise,
2865 copy all header fields whose names do not match
2866 `rmail-ignored-headers' (unless they also match
2867 `rmail-nonignored-headers'). Moves point in the message viewer
2868 buffer to the end of the headers."
2869 (let ((header-start-regexp "\n[^ \t]")
2871 (with-current-buffer rmail-buffer
2872 (when (search-forward "\n\n" nil t
)
2875 ;; Put point right after the From header line.
2876 (narrow-to-region beg
(point))
2877 (goto-char (point-min))
2878 (unless (re-search-forward header-start-regexp nil t
)
2879 (rmail-error-bad-format))
2882 ;; Handle the case where all headers should be copied.
2883 ((eq rmail-header-style
'full
)
2884 (prepend-to-buffer rmail-view-buffer beg
(point-max))
2885 ;; rmail-show-message-1 expects this function to leave point
2886 ;; at the end of the headers.
2888 (let ((len (- (point-max) beg
)))
2889 (with-current-buffer rmail-view-buffer
2890 (goto-char (1+ len
)))))
2892 ;; Handle the case where the headers matching the displayed
2893 ;; headers regexp should be copied.
2894 ((and rmail-displayed-headers
(null ignored-headers
))
2897 (setq lim
(if (re-search-forward header-start-regexp nil t
)
2898 (1+ (match-beginning 0))
2900 (when (looking-at rmail-displayed-headers
)
2901 (append-to-buffer rmail-view-buffer
(point) lim
))
2903 ;; Handle the ignored headers.
2904 ((or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
2905 (while (and ignored-headers
(not (eobp)))
2907 (setq lim
(if (re-search-forward header-start-regexp nil t
)
2908 (1+ (match-beginning 0))
2910 (if (and (looking-at ignored-headers
)
2911 (not (looking-at rmail-nonignored-headers
)))
2913 (append-to-buffer rmail-view-buffer
(point) lim
)
2915 (t (error "No headers selected for display!"))))))))
2917 (defun rmail-redecode-body (coding)
2918 "Decode the body of the current message using coding system CODING.
2919 This is useful with mail messages that have malformed or missing
2922 This function assumes that the current message is already decoded
2923 and displayed in the RMAIL buffer, but the coding system used to
2924 decode it was incorrect. It then decodes the message again,
2925 using the coding system CODING."
2926 (interactive "zCoding system for re-decoding this message: ")
2927 (when (not rmail-enable-mime
)
2928 (with-current-buffer rmail-buffer
2929 (rmail-swap-buffers-maybe)
2932 (let ((msgbeg (rmail-msgbeg rmail-current-message
))
2933 (msgend (rmail-msgend rmail-current-message
))
2934 (buffer-read-only nil
)
2935 body-start x-coding-header old-coding
)
2936 (narrow-to-region msgbeg msgend
)
2937 (goto-char (point-min))
2938 (unless (setq body-start
(search-forward "\n\n" (point-max) 1))
2939 (error "No message body"))
2942 ;; Narrow to headers
2943 (narrow-to-region (point-min) body-start
)
2944 (setq x-coding-header
(goto-char (point-min)))
2945 (if (not (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
))
2946 (setq old-coding
(rmail-get-coding-system))
2947 (setq old-coding
(intern (match-string 1)))
2948 (setq x-coding-header
(point)))
2949 (check-coding-system old-coding
)
2950 ;; Make sure the new coding system uses the same EOL
2951 ;; conversion, to prevent ^M characters from popping up
2952 ;; all over the place.
2953 (let ((eol-type (coding-system-eol-type old-coding
)))
2954 (if (numberp eol-type
)
2956 (coding-system-change-eol-conversion coding eol-type
))))
2957 (when (not (coding-system-equal
2958 (coding-system-base old-coding
)
2959 (coding-system-base coding
)))
2960 ;; Rewrite the coding-system header.
2961 (goto-char x-coding-header
)
2962 (if (> (point) (point-min))
2963 (delete-region (line-beginning-position) (point))
2967 (insert "X-Coding-System: "
2968 (symbol-name coding
))))
2969 (rmail-show-message))))))
2971 (defun rmail-highlight-headers ()
2972 "Highlight the headers specified by `rmail-highlighted-headers'.
2973 Uses the face specified by `rmail-highlight-face'."
2974 (if rmail-highlighted-headers
2976 (search-forward "\n\n" nil
'move
)
2978 (narrow-to-region (point-min) (point))
2979 (let ((case-fold-search t
)
2980 (inhibit-read-only t
)
2981 ;; When rmail-highlight-face is removed, just
2982 ;; use 'rmail-highlight here.
2983 (face (or rmail-highlight-face
2984 (if (face-differs-from-default-p 'bold
)
2986 ;; List of overlays to reuse.
2987 (overlays rmail-overlay-list
))
2988 (goto-char (point-min))
2989 (while (re-search-forward rmail-highlighted-headers nil t
)
2990 (skip-chars-forward " \t")
2993 (while (progn (forward-line 1)
2994 (looking-at "[ \t]")))
2995 ;; Back up over newline, then trailing spaces or tabs
2997 (while (member (preceding-char) '(? ?
\t))
3000 ;; Reuse an overlay we already have.
3002 (setq overlay
(car overlays
)
3003 overlays
(cdr overlays
))
3004 (overlay-put overlay
'face face
)
3005 (move-overlay overlay beg
(point)))
3006 ;; Make a new overlay and add it to
3007 ;; rmail-overlay-list.
3008 (setq overlay
(make-overlay beg
(point)))
3009 (overlay-put overlay
'face face
)
3010 (setq rmail-overlay-list
3011 (cons overlay rmail-overlay-list
))))))))))
3013 (defun rmail-auto-file ()
3014 "Automatically move a message into another sfolder based on criteria.
3015 This moves messages according to `rmail-automatic-folder-directives'.
3016 It only does something in the folder that `rmail-file-name' specifies.
3017 The function `rmail-show-message' calls this whenever it shows a message.
3018 This leaves a message alone if it already has the `filed' attribute."
3019 (if (or (zerop rmail-total-messages
)
3020 (rmail-message-attr-p rmail-current-message
"...F")
3021 (not (string= (buffer-file-name)
3022 (expand-file-name rmail-file-name
))))
3023 ;; Do nothing if the message has already been filed or if there
3026 ;; Find out some basics (common fields)
3027 (let ((from (mail-fetch-field "from"))
3028 (subj (mail-fetch-field "subject"))
3029 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
3030 (d rmail-automatic-folder-directives
)
3031 (directive-loop nil
)
3034 (setq folder
(car (car d
))
3035 directive-loop
(cdr (car d
)))
3036 (while (and (car directive-loop
)
3038 ((string= (downcase (car directive-loop
)) "from")
3040 ((string= (downcase (car directive-loop
)) "to")
3042 ((string= (downcase (car directive-loop
))
3044 (t (mail-fetch-field (car directive-loop
))))))
3045 ;; FIXME - shouldn't this ignore case?
3046 (and f
(string-match (car (cdr directive-loop
)) f
))))
3047 (setq directive-loop
(cdr (cdr directive-loop
))))
3048 ;; If there are no directives left, then it was a complete match.
3049 (if (null directive-loop
)
3051 (rmail-delete-forward)
3052 (if (string= "/dev/null" folder
)
3053 (rmail-delete-message)
3054 (rmail-output folder
1)
3056 (setq d
(cdr d
))))))
3058 ;; Simple message motion commands.
3060 (defun rmail-next-message (n)
3061 "Show following message whether deleted or not.
3062 With prefix arg N, moves forward N messages, or backward if N is negative."
3064 (set-buffer rmail-buffer
)
3065 (rmail-maybe-set-message-counters)
3066 (rmail-show-message (+ rmail-current-message n
)))
3068 (defun rmail-previous-message (n)
3069 "Show previous message whether deleted or not.
3070 With prefix arg N, moves backward N messages, or forward if N is negative."
3072 (rmail-next-message (- n
)))
3074 (defun rmail-next-undeleted-message (n)
3075 "Show following non-deleted message.
3076 With prefix arg N, moves forward N non-deleted messages,
3077 or backward if N is negative.
3079 Returns t if a new message is being shown, nil otherwise."
3081 (set-buffer rmail-buffer
)
3082 (rmail-maybe-set-message-counters)
3083 (let ((lastwin rmail-current-message
)
3084 (current rmail-current-message
))
3085 (while (and (> n
0) (< current rmail-total-messages
))
3086 (setq current
(1+ current
))
3087 (if (not (rmail-message-deleted-p current
))
3088 (setq lastwin current n
(1- n
))))
3089 (while (and (< n
0) (> current
1))
3090 (setq current
(1- current
))
3091 (if (not (rmail-message-deleted-p current
))
3092 (setq lastwin current n
(1+ n
))))
3093 (if (/= lastwin rmail-current-message
)
3094 (progn (rmail-show-message lastwin
)
3097 (message "No previous nondeleted message"))
3099 (message "No following nondeleted message"))
3102 (defun rmail-previous-undeleted-message (n)
3103 "Show previous non-deleted message.
3104 With prefix argument N, moves backward N non-deleted messages,
3105 or forward if N is negative."
3107 (rmail-next-undeleted-message (- n
)))
3109 (defun rmail-first-message ()
3110 "Show first message in file."
3112 (rmail-maybe-set-message-counters)
3113 (rmail-show-message 1))
3115 (defun rmail-last-message ()
3116 "Show last message in file."
3118 (rmail-maybe-set-message-counters)
3119 (rmail-show-message rmail-total-messages
))
3121 (defun rmail-next-error-move (msg-pos bad-marker
)
3122 "Move to an error locus (probably grep hit) in an Rmail buffer.
3123 MSG-POS is a marker pointing at the error message in the grep buffer.
3124 BAD-MARKER is a marker that ought to point at where to move to,
3125 but probably is garbage."
3127 (let* ((message-loc (compilation--message->loc
3128 (get-text-property msg-pos
'compilation-message
3129 (marker-buffer msg-pos
))))
3130 (column (car message-loc
))
3131 (linenum (cadr message-loc
))
3134 msgnum msgbeg msgend
3138 ;; Look at the whole Rmail file.
3139 (rmail-swap-buffers-maybe)
3144 ;; Find the line that the error message points at.
3145 (goto-char (point-min))
3146 (forward-line (1- linenum
))
3149 ;; Find the text at the start of the line,
3150 ;; before the first = sign.
3151 ;; This text has a good chance of being also in the
3154 (skip-chars-forward "^=\n")
3155 (setq line-text
(buffer-substring pos
(point))))
3157 ;; Find which message this position is in,
3158 ;; and the limits of that message.
3159 (setq msgnum
(rmail-what-message pos
))
3160 (setq msgbeg
(rmail-msgbeg msgnum
))
3161 (setq msgend
(rmail-msgend msgnum
))
3163 ;; Find which header this locus is in,
3164 ;; or if it's in the message body,
3165 ;; and the line-based position within that.
3167 (let ((header-end msgend
))
3168 (if (search-forward "\n\n" nil t
)
3169 (setq header-end
(point)))
3170 (if (>= pos header-end
)
3171 (setq line-number-within
3172 (count-lines header-end pos
))
3174 (unless (looking-at "^[^ \t]")
3175 (re-search-backward "^[^ \t]"))
3176 (looking-at "[^:\n]*[:\n]")
3177 (setq header-field
(match-string 0)
3178 line-number-within
(count-lines (point) pos
))))))
3180 ;; Display the right message.
3181 (rmail-show-message msgnum
)
3183 ;; Move to the right position within the displayed message.
3184 ;; Or at least try. The decoded message's lines may not
3185 ;; correspond to the lines in the inbox file.
3186 (goto-char (point-min))
3189 (re-search-forward (concat "^" (regexp-quote header-field
)) nil t
)
3190 (forward-line line-number-within
))
3191 (search-forward "\n\n" nil t
)
3192 (if (re-search-forward (concat "^" (regexp-quote line-text
)) nil t
)
3193 (goto-char (match-beginning 0))))
3195 ;; If the decoded message doesn't have enough lines,
3196 ;; go to the beginning rather than the end.
3197 (goto-char (point-min))
3198 ;; Otherwise, go to the right column.
3200 (forward-char column
)))))
3202 (defun rmail-what-message (&optional pos
)
3203 "Return message number POS (or point) is in."
3204 (let* ((high rmail-total-messages
)
3208 (with-current-buffer (if (rmail-buffers-swapped-p)
3212 (while (> (- high low
) 1)
3213 (if (>= where
(rmail-msgbeg mid
))
3216 (setq mid
(+ low
(/ (- high low
) 2))))
3217 (if (>= where
(rmail-msgbeg high
)) high low
)))
3219 ;; Searching in Rmail file.
3221 (defun rmail-search-message (msg regexp
)
3222 "Return non-nil, if for message number MSG, regexp REGEXP matches."
3223 ;; This is adequate because its only caller, rmail-search,
3224 ;; unswaps the buffers.
3225 (goto-char (rmail-msgbeg msg
))
3226 (if (and rmail-enable-mime
3227 rmail-search-mime-message-function
)
3228 (funcall rmail-search-mime-message-function msg regexp
)
3229 (re-search-forward regexp
(rmail-msgend msg
) t
)))
3231 (defvar rmail-search-last-regexp nil
)
3232 (defun rmail-search (regexp &optional n
)
3233 "Show message containing next match for REGEXP (but not the current msg).
3234 Prefix argument gives repeat count; negative argument means search
3235 backwards (through earlier messages).
3236 Interactively, empty argument means use same regexp used last time."
3238 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
3240 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3244 (if rmail-search-last-regexp
3245 (concat ", default "
3246 rmail-search-last-regexp
"): ")
3248 (setq regexp
(read-string prompt
))
3249 (cond ((not (equal regexp
""))
3250 (setq rmail-search-last-regexp regexp
))
3251 ((not rmail-search-last-regexp
)
3252 (error "No previous Rmail search string")))
3253 (list rmail-search-last-regexp
3254 (prefix-numeric-value current-prefix-arg
))))
3256 (message "%sRmail search for %s..."
3257 (if (< n
0) "Reverse " "")
3259 (set-buffer rmail-buffer
)
3260 (let ((orig-message rmail-current-message
)
3261 (msg rmail-current-message
)
3263 (opoint (if (rmail-buffers-swapped-p) (point)))
3265 (rmail-swap-buffers-maybe)
3266 (rmail-maybe-set-message-counters)
3270 ;; Check messages one by one, advancing message number up or
3271 ;; down but searching forward through each message.
3273 (while (and (null found
) (> msg
1))
3275 found
(rmail-search-message msg regexp
)))
3276 (while (and (null found
) (< msg rmail-total-messages
))
3278 found
(rmail-search-message msg regexp
))))
3279 (setq n
(+ n
(if reversep
1 -
1))))
3282 (rmail-show-message msg
)
3283 ;; Search forward (if this is a normal search) or backward
3284 ;; (if this is a reverse search) through this message to
3285 ;; position point. This search may fail because REGEXP
3286 ;; was found in the hidden portion of this message. In
3287 ;; that case, move point to the beginning of visible
3291 (goto-char (point-max))
3292 (re-search-backward regexp nil
'move
))
3293 (goto-char (point-min))
3294 (re-search-forward regexp nil t
))
3295 (message "%sRmail search for %s...done"
3296 (if reversep
"Reverse " "")
3298 (rmail-show-message orig-message
)
3299 (if opoint
(goto-char opoint
))
3301 (message "Search failed: %s" regexp
)))))
3303 (defun rmail-search-backwards (regexp &optional n
)
3304 "Show message containing previous match for REGEXP.
3305 Prefix argument gives repeat count; negative argument means search
3306 forward (through later messages).
3307 Interactively, empty argument means use same regexp used last time."
3309 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
3311 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3315 (if rmail-search-last-regexp
3316 (concat ", default "
3317 rmail-search-last-regexp
"): ")
3319 (setq regexp
(read-string prompt
))
3320 (cond ((not (equal regexp
""))
3321 (setq rmail-search-last-regexp regexp
))
3322 ((not rmail-search-last-regexp
)
3323 (error "No previous Rmail search string")))
3324 (list rmail-search-last-regexp
3325 (prefix-numeric-value current-prefix-arg
))))
3326 (rmail-search regexp
(- (or n
1))))
3328 ;; Scan for attributes, and compare subjects.
3330 (defun rmail-first-unseen-message ()
3331 "Return message number of first message which has `unseen' attribute."
3332 (rmail-maybe-set-message-counters)
3337 (while (and (not found
) (<= current rmail-total-messages
))
3338 (if (rmail-message-attr-p current
"......U")
3339 (setq found current
))
3340 (setq current
(1+ current
))))
3343 (defun rmail-simplified-subject (&optional msgnum
)
3344 "Return the simplified subject of message MSGNUM (or current message).
3345 Simplifying the subject means stripping leading and trailing whitespace,
3346 and typical reply prefixes such as Re:."
3347 (let ((subject (or (rmail-get-header "Subject" msgnum
) "")))
3348 (setq subject
(rfc2047-decode-string subject
))
3349 (if (string-match "\\`[ \t]+" subject
)
3350 (setq subject
(substring subject
(match-end 0))))
3351 (if (string-match rmail-reply-regexp subject
)
3352 (setq subject
(substring subject
(match-end 0))))
3353 (if (string-match "[ \t]+\\'" subject
)
3354 (setq subject
(substring subject
0 (match-beginning 0))))
3355 ;; If Subject is long, mailers will break it into several lines at
3356 ;; arbitrary places, so normalize whitespace by replacing every
3357 ;; run of whitespace characters with a single space.
3358 (setq subject
(replace-regexp-in-string "[ \t\n]+" " " subject
))
3361 (defun rmail-simplified-subject-regexp ()
3362 "Return a regular expression matching the current simplified subject.
3363 The idea is to match it against simplified subjects of other messages."
3364 (let ((subject (rmail-simplified-subject)))
3365 (setq subject
(regexp-quote subject
))
3366 ;; Hide commas so it will work ok if parsed as a comma-separated list
3369 (replace-regexp-in-string "," "\054" subject t t
))
3370 (concat "\\`" subject
"\\'")))
3372 (defun rmail-next-same-subject (n)
3373 "Go to the next mail message having the same subject header.
3374 With prefix argument N, do this N times.
3375 If N is negative, go backwards instead."
3377 (let ((subject (rmail-simplified-subject))
3379 (i rmail-current-message
)
3381 (while (and (/= n
0)
3383 (< i rmail-total-messages
)
3386 (while (and (not done
)
3388 (< i rmail-total-messages
)
3390 (setq i
(if forward
(1+ i
) (1- i
)))
3391 (setq done
(string-equal subject
(rmail-simplified-subject i
))))
3392 (if done
(setq found i
)))
3393 (setq n
(if forward
(1- n
) (1+ n
))))
3395 (rmail-show-message found
)
3396 (error "No %s message with same subject"
3397 (if forward
"following" "previous")))))
3399 (defun rmail-previous-same-subject (n)
3400 "Go to the previous mail message having the same subject header.
3401 With prefix argument N, do this N times.
3402 If N is negative, go forwards instead."
3404 (rmail-next-same-subject (- n
)))
3406 ;;;; *** Rmail Message Deletion Commands ***
3408 (defun rmail-message-deleted-p (n)
3409 "Return non-nil if message number N is deleted (in `rmail-deleted-vector')."
3410 (= (aref rmail-deleted-vector n
) ?D
))
3412 (defun rmail-set-message-deleted-p (n state
)
3413 "Set the deleted state of message number N (in `rmail-deleted-vector').
3414 STATE non-nil means mark as deleted."
3415 (aset rmail-deleted-vector n
(if state ?D ?\s
)))
3417 (defun rmail-delete-message ()
3418 "Delete this message and stay on it."
3420 (rmail-set-attribute rmail-deleted-attr-index t
)
3421 (run-hooks 'rmail-delete-message-hook
))
3423 (defun rmail-undelete-previous-message ()
3424 "Back up to deleted message, select it, and undelete it."
3426 (set-buffer rmail-buffer
)
3427 (let ((msg rmail-current-message
))
3428 (while (and (> msg
0)
3429 (not (rmail-message-deleted-p msg
)))
3430 (setq msg
(1- msg
)))
3432 (error "No previous deleted message")
3433 (if (/= msg rmail-current-message
)
3434 (rmail-show-message msg
))
3435 (rmail-set-attribute rmail-deleted-attr-index nil
)
3436 (if (rmail-summary-exists)
3437 (with-current-buffer rmail-summary-buffer
3438 (rmail-summary-mark-undeleted msg
)))
3439 (rmail-maybe-display-summary))))
3441 (defun rmail-delete-forward (&optional backward
)
3442 "Delete this message and move to next nondeleted one.
3443 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
3444 With prefix argument, delete and move backward.
3446 Returns t if a new message is displayed after the delete, or nil otherwise."
3448 (rmail-set-attribute rmail-deleted-attr-index t
)
3449 (run-hooks 'rmail-delete-message-hook
)
3450 (let ((del-msg rmail-current-message
))
3451 (if (rmail-summary-exists)
3452 (rmail-select-summary
3453 (rmail-summary-mark-deleted del-msg
)))
3454 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
3455 (rmail-maybe-display-summary))))
3457 (defun rmail-delete-backward ()
3458 "Delete this message and move to previous nondeleted one.
3459 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
3461 (rmail-delete-forward t
))
3465 ;; Compute the message number a given message would have after expunging.
3466 ;; The present number of the message is OLDNUM.
3467 ;; DELETEDVEC should be rmail-deleted-vector.
3468 ;; The value is nil for a message that would be deleted.
3469 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
3470 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
3475 (if (/= (aref deletedvec i
) ?D
)
3476 (setq newnum
(1+ newnum
)))
3480 (defun rmail-expunge-confirmed ()
3481 "Return t if expunge is needed and desirable.
3482 If `rmail-confirm-expunge' is non-nil, ask user to confirm."
3483 (set-buffer rmail-buffer
)
3484 (and (stringp rmail-deleted-vector
)
3485 (string-match "D" rmail-deleted-vector
)
3486 (if rmail-confirm-expunge
3487 (funcall rmail-confirm-expunge
3488 "Erase deleted messages from Rmail file? ")
3491 (defun rmail-only-expunge (&optional dont-show
)
3492 "Actually erase all deleted messages in the file."
3494 (rmail-swap-buffers-maybe)
3495 (set-buffer rmail-buffer
)
3496 (message "Expunging deleted messages...")
3497 ;; Discard all undo records for this buffer.
3498 (or (eq buffer-undo-list t
)
3499 (setq buffer-undo-list nil
))
3500 (rmail-maybe-set-message-counters)
3501 (let* ((omax (- (buffer-size) (point-max)))
3502 (omin (- (buffer-size) (point-min)))
3503 (opoint (if (and (> rmail-current-message
0)
3504 (rmail-message-deleted-p rmail-current-message
))
3506 (if rmail-enable-mime
3507 (with-current-buffer rmail-view-buffer
3508 (- (point)(point-min)))
3509 (- (point) (point-min)))))
3510 (messages-head (cons (aref rmail-message-vector
0) nil
))
3511 (messages-tail messages-head
)
3512 ;; Don't make any undo records for the expunging.
3513 (buffer-undo-list t
)
3518 (goto-char (point-min))
3522 (new-msgref (list (list 0)))
3523 (buffer-read-only nil
)
3524 (total rmail-total-messages
)
3525 (new-message-number rmail-current-message
)
3526 (messages rmail-message-vector
)
3527 (deleted rmail-deleted-vector
)
3528 (summary rmail-summary-vector
))
3529 (setq rmail-total-messages nil
3530 rmail-current-message nil
3531 rmail-message-vector nil
3532 rmail-deleted-vector nil
3533 rmail-summary-vector nil
)
3535 (while (<= number total
)
3536 (if (= (aref deleted number
) ?D
)
3538 (delete-region (aref messages number
)
3539 (aref messages
(1+ number
)))
3540 (move-marker (aref messages number
) nil
)
3541 (if (> new-message-number counter
)
3542 (setq new-message-number
(1- new-message-number
))))
3543 (setq counter
(1+ counter
))
3545 (setcdr messages-tail
3546 (cons (aref messages number
) nil
)))
3548 (cons (if (= counter number
) (aref summary
(1- number
)))
3551 (cons (aref rmail-msgref-vector number
)
3553 (setcar (car new-msgref
) counter
))
3554 (if (zerop (%
(setq number
(1+ number
)) 20))
3555 (message "Expunging deleted messages...%d" number
)))
3557 (setcdr messages-tail
3558 (cons (aref messages number
) nil
)))
3559 (setq rmail-current-message new-message-number
3560 rmail-total-messages counter
3561 rmail-message-vector
(apply 'vector messages-head
)
3562 rmail-deleted-vector
(make-string (1+ counter
) ?\s
)
3563 rmail-summary-vector
(vconcat (nreverse new-summary
))
3564 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
3566 (message "Expunging deleted messages...done")
3568 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
3570 (rmail-show-message (min rmail-current-message rmail-total-messages
)))
3571 (if rmail-enable-mime
3572 (goto-char (+ (point-min) opoint
))
3573 (goto-char (+ (point) opoint
))))))
3575 ;; The DONT-SHOW argument is new in 23. Does not seem very important.
3576 (defun rmail-expunge (&optional dont-show
)
3577 "Erase deleted messages from Rmail file and summary buffer.
3578 This always shows a message (so as not to leave the Rmail buffer
3579 unswapped), and always updates any summary (so that it remains
3580 consistent with the Rmail buffer). If DONT-SHOW is non-nil, it
3581 does not pop any summary buffer."
3583 (when (rmail-expunge-confirmed)
3584 (rmail-modify-format)
3585 (let ((was-deleted (rmail-message-deleted-p rmail-current-message
))
3586 (was-swapped (rmail-buffers-swapped-p)))
3587 (rmail-only-expunge t
)
3588 ;; We always update the summary buffer, so that the contents
3589 ;; remain consistent with the rmail buffer.
3590 ;; The only difference is, in the dont-show case, we use a
3591 ;; cut-down version of rmail-select-summary that does not pop
3592 ;; the summary buffer. It's only used by rmail-quit, which is
3593 ;; just going to bury any summary immediately after. If we made
3594 ;; rmail-quit bury the summary first, dont-show could be removed.
3595 ;; But the expunge might not be confirmed...
3596 (if (rmail-summary-exists)
3598 (let ((total rmail-total-messages
))
3599 (with-current-buffer rmail-summary-buffer
3600 (let ((rmail-total-messages total
))
3601 (rmail-update-summary))))
3602 (rmail-select-summary (rmail-update-summary))))
3603 ;; We always show a message, because (rmail-only-expunge t)
3604 ;; leaves the rmail buffer unswapped.
3605 ;; If we expunged the current message, a new one is current now,
3606 ;; so show it. If we weren't showing a message, show it.
3607 (if (or was-deleted
(not was-swapped
))
3608 (rmail-show-message-1 rmail-current-message
)
3609 ;; We can just show the same message that was being shown before.
3610 (rmail-display-labels)
3611 (rmail-swap-buffers)
3612 (setq rmail-buffer-swapped t
)))))
3614 ;;;; *** Rmail Mailing Commands ***
3616 (defun rmail-yank-current-message (buffer)
3617 "Yank into the current buffer the current message of Rmail buffer BUFFER.
3618 If BUFFER is swapped with its message viewer buffer, yank out of BUFFER.
3619 If BUFFER is not swapped, yank out of its message viewer buffer."
3620 (with-current-buffer buffer
3621 (unless (rmail-buffers-swapped-p)
3622 (setq buffer rmail-view-buffer
)))
3623 (insert-buffer-substring buffer
)
3624 ;; If they yank the text of BUFFER, the encoding of BUFFER is a
3625 ;; better default for the reply message than the default value of
3626 ;; buffer-file-coding-system.
3627 (and (coding-system-equal (default-value 'buffer-file-coding-system
)
3628 buffer-file-coding-system
)
3629 (setq buffer-file-coding-system
3630 (coding-system-change-text-conversion
3631 buffer-file-coding-system
(coding-system-base
3632 (with-current-buffer buffer
3633 buffer-file-coding-system
))))))
3635 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
3636 replybuffer sendactions same-window
3638 (let ((switch-function
3639 (cond (same-window nil
)
3640 (rmail-mail-new-frame 'switch-to-buffer-other-frame
)
3641 (t 'switch-to-buffer-other-window
)))
3644 ;; The function used here must behave like insert-buffer wrt
3645 ;; point and mark (see doc of sc-cite-original).
3647 `(rmail-yank-current-message ,replybuffer
)))
3648 (push (cons "cc" cc
) other-headers
)
3649 (push (cons "in-reply-to" in-reply-to
) other-headers
)
3651 (mapcar #'(lambda (elt)
3652 (cons (car elt
) (if (stringp (cdr elt
))
3653 (rfc2047-decode-string (cdr elt
)))))
3655 (if (stringp to
) (setq to
(rfc2047-decode-string to
)))
3656 (if (stringp in-reply-to
)
3657 (setq in-reply-to
(rfc2047-decode-string in-reply-to
)))
3658 (if (stringp cc
) (setq cc
(rfc2047-decode-string cc
)))
3659 (if (stringp subject
) (setq subject
(rfc2047-decode-string subject
)))
3661 (compose-mail to subject other-headers noerase
3662 switch-function yank-action sendactions
3663 (if replybuffer
`(rmail-mail-return ,replybuffer
)))
3664 (if (eq switch-function
'switch-to-buffer-other-frame
)
3665 ;; This is not a standard frame parameter; nothing except
3666 ;; sendmail.el looks at it.
3667 (modify-frame-parameters (selected-frame)
3668 '((mail-dedicated-frame . t
)))))))
3670 (defun rmail-mail-return (&optional newbuf
)
3671 "Try to return to Rmail from the mail window.
3672 If optional argument NEWBUF is specified, it is the Rmail buffer
3675 ;; If there is only one visible frame with no special handling,
3676 ;; consider deleting the mail window to return to Rmail.
3677 ((or (null (delq (selected-frame) (visible-frame-list)))
3678 (not (or (window-dedicated-p (frame-selected-window))
3679 (and pop-up-frames
(one-window-p))
3680 (cdr (assq 'mail-dedicated-frame
3681 (frame-parameters))))))
3682 (let (rmail-flag summary-buffer
)
3683 (unless (one-window-p)
3684 (with-current-buffer
3685 (window-buffer (next-window (selected-window) 'not
))
3686 (setq rmail-flag
(eq major-mode
'rmail-mode
))
3687 (setq summary-buffer
3688 (and (boundp 'mail-bury-selects-summary
)
3689 mail-bury-selects-summary
3690 (boundp 'rmail-summary-buffer
)
3691 rmail-summary-buffer
3692 (buffer-name rmail-summary-buffer
)
3693 (not (get-buffer-window rmail-summary-buffer
))
3694 rmail-summary-buffer
))))
3695 (cond ((null rmail-flag
)
3696 ;; If the Rmail buffer is not in the next window, switch
3697 ;; directly to the Rmail buffer specified by NEWBUF.
3698 (if (buffer-live-p newbuf
)
3699 (switch-to-buffer newbuf
)))
3700 ;; If the Rmail buffer is in the next window, switch to
3701 ;; the summary buffer if `mail-bury-selects-summary' is
3702 ;; non-nil. Otherwise just delete this window.
3704 (switch-to-buffer summary-buffer
))
3707 ;; If the frame was probably made for this buffer, the user
3708 ;; probably wants to delete it now.
3709 ((display-multi-frame-p)
3710 (delete-frame (selected-frame)))
3711 ;; The previous frame is where normally they have the Rmail buffer
3713 (t (other-frame -
1))))
3715 (defun rmail-mail ()
3716 "Send mail in another window.
3717 While composing the message, use \\[mail-yank-original] to yank the
3718 original message into it."
3720 (rmail-start-mail nil nil nil nil nil rmail-buffer
))
3722 ;; FIXME should complain if there is nothing to continue.
3723 (defun rmail-continue ()
3724 "Continue composing outgoing message previously being composed."
3726 (rmail-start-mail t
))
3728 (defun rmail-reply (just-sender)
3729 "Reply to the current message.
3730 Normally include CC: to all other recipients of original message;
3731 prefix argument means ignore them. While composing the reply,
3732 use \\[mail-yank-original] to yank the original message into it."
3734 (if (zerop rmail-current-message
)
3735 (error "There is no message to reply to"))
3736 (let (from reply-to cc subject date to message-id references
3737 resent-to resent-cc resent-reply-to
3738 (msgnum rmail-current-message
))
3739 (rmail-apply-in-message
3740 rmail-current-message
3742 (search-forward "\n\n" nil
'move
)
3743 (narrow-to-region (point-min) (point))
3744 (setq from
(mail-fetch-field "from")
3745 reply-to
(or (mail-fetch-field "mail-reply-to" nil t
)
3746 (mail-fetch-field "reply-to" nil t
)
3748 subject
(mail-fetch-field "subject")
3749 date
(mail-fetch-field "date")
3750 message-id
(mail-fetch-field "message-id")
3751 references
(mail-fetch-field "references" nil nil t
)
3752 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
3753 ;; Bug#512. It's inappropriate to reply to these addresses.
3754 ;;; resent-cc (and (not just-sender)
3755 ;;; (mail-fetch-field "resent-cc" nil t))
3756 ;;; resent-to (or (mail-fetch-field "resent-to" nil t) "")
3757 ;;; resent-subject (mail-fetch-field "resent-subject")
3758 ;;; resent-date (mail-fetch-field "resent-date")
3759 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3762 (if (mail-fetch-field "mail-followup-to" nil t
)
3763 ;; If this header field is present, use it instead of the
3764 ;; To and CC fields.
3765 (setq to
(mail-fetch-field "mail-followup-to" nil t
))
3766 (setq cc
(or (mail-fetch-field "cc" nil t
) "")
3767 to
(or (mail-fetch-field "to" nil t
) ""))))))
3768 ;; Merge the resent-to and resent-cc into the to and cc.
3769 ;; Bug#512. It's inappropriate to reply to these addresses.
3770 ;;; (if (and resent-to (not (equal resent-to "")))
3771 ;;; (if (not (equal to ""))
3772 ;;; (setq to (concat to ", " resent-to))
3773 ;;; (setq to resent-to)))
3774 ;;; (if (and resent-cc (not (equal resent-cc "")))
3775 ;;; (if (not (equal cc ""))
3776 ;;; (setq cc (concat cc ", " resent-cc))
3777 ;;; (setq cc resent-cc)))
3778 ;; Add `Re: ' to subject if not there already.
3779 (and (stringp subject
)
3781 (concat rmail-reply-prefix
3782 (if (let ((case-fold-search t
))
3783 (string-match rmail-reply-regexp subject
))
3784 (substring subject
(match-end 0))
3788 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3789 ;; since they can handle the names unstripped.
3790 ;; I don't know whether there are other mailers that still
3791 ;; need the names to be stripped.
3792 ;;; (mail-strip-quoted-names reply-to)
3793 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3794 ;; header causes all the names in it to wind up in reply-to, not
3795 ;; in cc. But if what's left is an empty list, use the original.
3796 (let* ((reply-to-list (mail-dont-reply-to reply-to
)))
3797 (if (string= reply-to-list
"") reply-to reply-to-list
))
3799 (rmail-make-in-reply-to-field from date message-id
)
3802 ;; `mail-dont-reply-to' doesn't need `mail-strip-quoted-names'.
3803 (let* ((cc-list (mail-dont-reply-to
3804 (mail-strip-quoted-names
3805 (if (null cc
) to
(concat to
", " cc
))))))
3806 (if (string= cc-list
"") nil cc-list
)))
3808 (list (list 'rmail-mark-message
3810 (with-current-buffer rmail-buffer
3811 (aref rmail-msgref-vector msgnum
))
3812 rmail-answered-attr-index
))
3814 (if (or references message-id
)
3815 (list (cons "References" (if references
3817 (mapconcat 'identity references
" ")
3821 (defun rmail-mark-message (buffer msgnum-list attribute
)
3822 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3823 This is use in the send-actions for message buffers.
3824 MSGNUM-LIST is a list of the form (MSGNUM)
3825 which is an element of rmail-msgref-vector."
3826 (with-current-buffer buffer
3827 (if (car msgnum-list
)
3828 (rmail-set-attribute attribute t
(car msgnum-list
)))))
3830 (defun rmail-make-in-reply-to-field (from date message-id
)
3837 (let ((tem (car (rfc822-addresses from
))))
3841 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
3843 (match-beginning 0))
3846 ;; missing From, or Message-ID is sufficiently informative
3848 (concat message-id
" (" tem
")"))
3849 ;; Copy TEM, discarding text properties.
3850 (setq tem
(copy-sequence tem
))
3851 (set-text-properties 0 (length tem
) nil tem
)
3852 (setq tem
(copy-sequence tem
))
3853 ;; Use prin1 to fake RFC822 quoting
3854 (let ((field (prin1-to-string tem
)))
3856 (concat field
"'s message of " date
)
3858 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3859 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3860 ;; These strings both match all non-ASCII characters.
3861 (or (string-match (concat "\\`[ \t]*\\(" bar
3862 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
3863 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3865 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
3866 bar
"\\))[ \t]*\\'")
3867 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3869 (let ((start (match-beginning 1))
3870 (end (match-end 1)))
3871 ;; Trim whitespace which above regexp match allows
3872 (while (and (< start end
)
3873 (memq (aref from start
) '(?
\t ?\s
)))
3874 (setq start
(1+ start
)))
3875 (while (and (< start end
)
3876 (memq (aref from
(1- end
)) '(?
\t ?\s
)))
3877 (setq end
(1- end
)))
3878 (let ((field (substring from start end
)))
3879 (if date
(setq field
(concat "message from " field
" on " date
)))
3881 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3882 (concat message-id
" (" field
")")
3885 ;; If we can't kludge it simply, do it correctly
3886 (let ((mail-use-rfc822 t
))
3887 (rmail-make-in-reply-to-field from date message-id
)))))
3889 (defun rmail-forward (resend)
3890 "Forward the current message to another user.
3891 With prefix argument, \"resend\" the message instead of forwarding it;
3892 see the documentation of `rmail-resend'."
3894 (if (zerop rmail-current-message
)
3895 (error "No message to forward"))
3897 (call-interactively 'rmail-resend
)
3898 (let ((forward-buffer rmail-buffer
)
3899 (msgnum rmail-current-message
)
3900 (subject (concat "["
3901 (let ((from (or (mail-fetch-field "From")
3903 (mail-fetch-field ">From"))))
3905 (concat (mail-strip-quoted-names from
) ": ")
3907 (or (mail-fetch-field "Subject") "")
3909 (if (rmail-start-mail
3910 nil nil subject nil nil rmail-buffer
3911 (list (list 'rmail-mark-message
3913 (with-current-buffer rmail-buffer
3914 (aref rmail-msgref-vector msgnum
))
3915 rmail-forwarded-attr-index
))
3916 ;; If only one window, use it for the mail buffer.
3917 ;; Otherwise, use another window for the mail buffer
3918 ;; so that the Rmail buffer remains visible
3919 ;; and sending the mail will get back to it.
3920 (and (not rmail-mail-new-frame
) (one-window-p t
)))
3921 ;; The mail buffer is now current.
3923 ;; Insert after header separator--before signature if any.
3926 (if (and rmail-enable-mime rmail-enable-mime-composing
3927 rmail-insert-mime-forwarded-message-function
)
3929 (funcall rmail-insert-mime-forwarded-message-function
3931 ;; rmail-insert-mime-forwarded-message-function
3932 ;; works by inserting MML tags into forward-buffer.
3933 ;; The MUA will need to convert it to MIME before
3934 ;; sending. mail-encode-mml tells them to do that.
3935 ;; message.el does that automagically.
3936 (or (eq mail-user-agent
'message-user-agent
)
3937 (setq mail-encode-mml t
)))
3938 (insert "------- Start of forwarded message -------\n")
3939 ;; Quote lines with `- ' if they start with `-'.
3940 (let ((beg (point)) end
)
3941 (setq end
(point-marker))
3942 (set-marker-insertion-type end t
)
3943 (insert-buffer-substring forward-buffer
)
3945 (while (re-search-forward "^-" end t
)
3950 (skip-chars-backward "\n")
3953 (delete-region (point) end
)
3954 (set-marker end nil
))
3955 (insert "------- End of forwarded message -------\n"))
3958 (defun rmail-resend (address &optional from comment mail-alias-file
)
3959 "Resend current message to ADDRESSES.
3960 ADDRESSES should be a single address, a string consisting of several
3961 addresses separated by commas, or a list of addresses.
3963 Optional FROM is the address to resend the message from, and
3964 defaults from the value of `user-mail-address'.
3965 Optional COMMENT is a string to insert as a comment in the resent message.
3966 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3967 typically for purposes of moderating a list."
3968 (interactive "sResend to: ")
3970 (require 'mailalias
)
3971 (unless (or (eq rmail-view-buffer
(current-buffer))
3972 (eq rmail-buffer
(current-buffer)))
3973 (error "Not an Rmail buffer"))
3974 (if (not from
) (setq from user-mail-address
))
3975 (let ((tembuf (generate-new-buffer " sendmail temp"))
3976 (case-fold-search nil
)
3977 (mail-personal-alias-file
3978 (or mail-alias-file mail-personal-alias-file
))
3979 (mailbuf rmail-buffer
))
3981 (with-current-buffer tembuf
3982 ;;>> Copy message into temp buffer
3983 (if (and rmail-enable-mime
3984 rmail-insert-mime-resent-message-function
)
3985 (funcall rmail-insert-mime-resent-message-function mailbuf
)
3986 (insert-buffer-substring mailbuf
))
3987 (goto-char (point-min))
3988 ;; Delete any Sender field, since that's not specifiable.
3989 ; Only delete Sender fields in the actual header.
3990 (re-search-forward "^$" nil
'move
)
3991 ; Using "while" here rather than "if" because some buggy mail
3992 ; software may have inserted multiple Sender fields.
3993 (while (re-search-backward "^Sender:" nil t
)
3997 (while (looking-at "[ \t]")
3999 (delete-region beg
(point))))
4000 ; Go back to the beginning of the buffer so the Resent- fields
4001 ; are inserted there.
4002 (goto-char (point-min))
4003 ;;>> Insert resent-from:
4004 (insert "Resent-From: " from
"\n")
4005 (insert "Resent-Date: " (mail-rfc822-date) "\n")
4006 ;;>> Insert resent-to: and bcc if need be.
4007 (let ((before (point)))
4009 (insert "Resent-Bcc: " (user-login-name) "\n"))
4010 (insert "Resent-To: " (if (stringp address
)
4012 (mapconcat 'identity address
",\n\t"))
4014 ;; Expand abbrevs in the recipients.
4016 (if (featurep 'mailabbrev
)
4017 (let ((end (point-marker))
4018 (local-abbrev-table mail-abbrevs
)
4019 (old-syntax-table (syntax-table)))
4020 (if (and (not (vectorp mail-abbrevs
))
4021 (file-exists-p mail-personal-alias-file
))
4022 (build-mail-abbrevs))
4023 (unless mail-abbrev-syntax-table
4024 (mail-abbrev-make-syntax-table))
4025 (set-syntax-table mail-abbrev-syntax-table
)
4027 (while (and (< (point) end
)
4028 (progn (forward-word 1)
4031 (set-syntax-table old-syntax-table
))
4032 (expand-mail-aliases before
(point)))))
4033 ;;>> Set up comment, if any.
4034 (if (and (sequencep comment
) (not (zerop (length comment
))))
4035 (let ((before (point))
4038 (or (eolp) (insert "\n"))
4039 (setq after
(point))
4041 (while (< (point) after
)
4042 (insert "Resent-Comment: ")
4044 ;; Don't expand aliases in the destination fields
4045 ;; of the original message.
4047 (funcall send-mail-function
)))
4048 (kill-buffer tembuf
))
4049 (with-current-buffer rmail-buffer
4050 (rmail-set-attribute rmail-resent-attr-index t rmail-current-message
))))
4052 (defvar mail-unsent-separator
4053 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
4054 "^ *---+ +Returned message +---+ *$\\|"
4055 "^ *---+ *Returned mail follows *---+ *$\\|"
4056 "^Start of returned message$\\|"
4057 "^---+ Below this line is a copy of the message.$\\|"
4058 "^ *---+ +Original message +---+ *$\\|"
4059 "^ *--+ +begin message +--+ *$\\|"
4060 "^ *---+ +Original message follows +---+ *$\\|"
4061 "^ *---+ +Your message follows +---+ *$\\|"
4062 "^|? *---+ +Message text follows: +---+ *|?$\\|"
4063 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
4064 "A regexp that matches the separator before the text of a failed message.")
4066 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
4067 "A regexp that matches the header of a MIME body part with a failed message.")
4069 ;; This is a cut-down version of rmail-clear-headers from Emacs 22.
4070 ;; It doesn't have the same functionality, hence the name change.
4071 (defun rmail-delete-headers (regexp)
4072 "Delete any mail headers matching REGEXP.
4073 The message should be narrowed to just the headers."
4075 (goto-char (point-min))
4076 (while (re-search-forward regexp nil t
)
4078 ;; This code from Emacs 22 doesn't seem right, since r-n-h is
4079 ;; just for display.
4080 ;;; (if (looking-at rmail-nonignored-headers)
4081 ;;; (forward-line 1)
4082 (delete-region (point)
4084 (if (re-search-forward "\n[^ \t]" nil t
)
4088 (autoload 'mail-position-on-field
"sendmail")
4090 (defun rmail-retry-failure ()
4091 "Edit a mail message which is based on the contents of the current message.
4092 For a message rejected by the mail system, extract the interesting headers and
4093 the body of the original message.
4094 If the failed message is a MIME multipart message, it is searched for a
4095 body part with a header which matches the variable `mail-mime-unsent-header'.
4096 Otherwise, the variable `mail-unsent-separator' should match the string that
4097 delimits the returned original message.
4098 The variable `rmail-retry-ignored-headers' is a regular expression
4099 specifying headers which should not be copied into the new message."
4101 (require 'mail-utils
)
4102 (if rmail-enable-mime
4103 (with-current-buffer rmail-buffer
4104 (if (rmail-mime-message-p)
4105 (let ((rmail-mime-mbox-buffer rmail-view-buffer
)
4106 (rmail-mime-view-buffer rmail-buffer
))
4107 (rmail-mime-toggle-raw 'raw
)))))
4109 (let ((rmail-this-buffer (current-buffer))
4110 (msgnum rmail-current-message
)
4111 bounce-start bounce-end bounce-indent resending
4112 (content-type (rmail-get-header "Content-Type")))
4114 (goto-char (point-min))
4115 (let ((case-fold-search t
))
4116 (if (and content-type
4118 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
4120 ;; Handle a MIME multipart bounce message.
4123 (substring content-type
(match-beginning 1)
4125 (unless (re-search-forward mail-mime-unsent-header nil t
)
4126 (error "Cannot find beginning of header in failed message"))
4127 (unless (search-forward "\n\n" nil t
)
4128 (error "Cannot find start of Mime data in failed message"))
4129 (setq bounce-start
(point))
4130 (if (search-forward codestring nil t
)
4131 (setq bounce-end
(match-beginning 0))
4132 (setq bounce-end
(point-max))))
4134 (or (re-search-forward mail-unsent-separator nil t
)
4135 (error "Cannot parse this as a failure message"))
4136 (skip-chars-forward "\n")
4137 ;; Support a style of failure message in which the original
4138 ;; message is indented, and included within lines saying
4139 ;; `Start of returned message' and `End of returned message'.
4140 (if (looking-at " +Received:")
4142 (setq bounce-start
(point))
4143 (skip-chars-forward " ")
4144 (setq bounce-indent
(- (current-column)))
4145 (goto-char (point-max))
4146 (re-search-backward "^End of returned message$" nil t
)
4147 (setq bounce-end
(point)))
4148 ;; One message contained a few random lines before
4149 ;; the old message header. The first line of the
4150 ;; message started with two hyphens. A blank line
4151 ;; followed these random lines. The same line
4152 ;; beginning with two hyphens was possibly marking
4153 ;; the end of the message.
4154 (if (looking-at "^--")
4155 (let ((boundary (buffer-substring-no-properties
4157 (progn (end-of-line) (point)))))
4158 (search-forward "\n\n")
4159 (skip-chars-forward "\n")
4160 (setq bounce-start
(point))
4161 (goto-char (point-max))
4162 (search-backward (concat "\n\n" boundary
) bounce-start t
)
4163 (setq bounce-end
(point)))
4164 (setq bounce-start
(point)
4165 bounce-end
(point-max)))
4166 (unless (search-forward "\n\n" nil t
)
4167 (error "Cannot find end of header in failed message"))))))
4168 ;; We have found the message that bounced, within the current message.
4169 ;; Now start sending new message; default header fields from original.
4170 ;; Turn off the usual actions for initializing the message body
4171 ;; because we want to get only the text from the failure message.
4172 (let (mail-signature mail-setup-hook
)
4173 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
4174 (list (list 'rmail-mark-message
4176 (aref rmail-msgref-vector msgnum
)
4177 rmail-retried-attr-index
)))
4178 ;; Insert original text as initial text of new draft message.
4179 ;; Bind inhibit-read-only since the header delimiter
4180 ;; of the previous message was probably read-only.
4181 (let ((inhibit-read-only t
)
4184 (insert-buffer-substring rmail-this-buffer
4185 bounce-start bounce-end
)
4186 (goto-char (point-min))
4188 (indent-rigidly (point-min) (point-max) bounce-indent
))
4191 (insert mail-header-separator
)
4193 (narrow-to-region (point-min) eoh
)
4194 (rmail-delete-headers rmail-retry-ignored-headers
)
4195 (rmail-delete-headers "^\\(sender\\|return-path\\|received\\):")
4196 (setq resending
(mail-fetch-field "resent-to"))
4199 (insert "Resent-Bcc: " (user-login-name) "\n")
4200 (insert "BCC: " (user-login-name) "\n"))))
4201 (goto-char (point-min))
4202 (mail-position-on-field (if resending
"Resent-To" "To") t
))))))
4204 (defun rmail-summary-exists ()
4205 "Non-nil if in an RMAIL buffer and an associated summary buffer exists.
4206 In fact, the non-nil value returned is the summary buffer itself."
4207 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4208 rmail-summary-buffer
))
4210 (defun rmail-summary-displayed ()
4211 "t if in RMAIL buffer and an associated summary buffer is displayed."
4212 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
4214 (defcustom rmail-redisplay-summary nil
4215 "Non-nil means Rmail should show the summary when it changes.
4216 This has an effect only if a summary buffer exists."
4218 :group
'rmail-summary
)
4220 (defcustom rmail-summary-window-size nil
4221 "Non-nil means specify the height for an Rmail summary window."
4222 :type
'(choice (const :tag
"Disabled" nil
) integer
)
4223 :group
'rmail-summary
)
4225 ;; Put the summary buffer back on the screen, if user wants that.
4226 (defun rmail-maybe-display-summary ()
4227 (let ((selected (selected-window))
4228 (buffer (current-buffer))
4230 ;; If requested, make sure the summary is displayed.
4231 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4232 rmail-redisplay-summary
4233 (if (get-buffer-window rmail-summary-buffer
0)
4234 ;; It's already in some frame; show that one.
4235 (let ((frame (window-frame
4236 (get-buffer-window rmail-summary-buffer
0))))
4237 (make-frame-visible frame
)
4238 (raise-frame frame
))
4239 (display-buffer rmail-summary-buffer
)))
4240 ;; If requested, set the height of the summary window.
4241 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4242 rmail-summary-window-size
4243 (setq window
(get-buffer-window rmail-summary-buffer
))
4244 ;; Don't try to change the size if just one window in frame.
4245 (not (eq window
(frame-root-window (window-frame window
))))
4248 (select-window window
)
4249 (enlarge-window (- rmail-summary-window-size
(window-height))))
4250 (select-window selected
)
4251 (set-buffer buffer
)))))
4253 ;;;; *** Rmail Local Fontification ***
4255 (defun rmail-fontify-buffer-function ()
4256 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
4257 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
4258 ;; If we're already showing a message, fontify it now.
4259 (if rmail-current-message
(rmail-fontify-message))
4260 ;; Prevent Font Lock mode from kicking in.
4261 (setq font-lock-fontified t
))
4263 (defun rmail-unfontify-buffer-function ()
4264 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
4265 (let ((modified (buffer-modified-p))
4266 (buffer-undo-list t
) (inhibit-read-only t
)
4267 before-change-functions after-change-functions
4268 buffer-file-name buffer-file-truename
)
4271 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
4272 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
4273 (font-lock-default-unfontify-buffer)
4274 (and (not modified
) (buffer-modified-p)
4275 (restore-buffer-modified-p nil
)))))
4277 (defun rmail-fontify-message ()
4278 ;; Fontify the current message if it is not already fontified.
4279 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
4280 (let ((modified (buffer-modified-p))
4281 (buffer-undo-list t
) (inhibit-read-only t
)
4282 before-change-functions after-change-functions
4283 buffer-file-name buffer-file-truename
)
4286 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
4287 (font-lock-fontify-region (point-min) (point-max))
4288 (and (not modified
) (buffer-modified-p)
4289 (restore-buffer-modified-p nil
)))))))
4291 ;;; Speedbar support for RMAIL files.
4292 (eval-when-compile (require 'speedbar
))
4294 (defcustom rmail-speedbar-match-folder-regexp
"^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
4295 "Regexp matching Rmail folder names to be displayed in Speedbar.
4296 Enabling this permits Speedbar to display your folders for easy
4297 browsing, and moving of messages."
4302 (defvar rmail-speedbar-last-user nil
4303 "The last user to be displayed in the speedbar.")
4305 (defvar rmail-speedbar-key-map nil
4306 "Keymap used when in rmail display mode.")
4308 (defun rmail-install-speedbar-variables ()
4309 "Install those variables used by speedbar to enhance rmail."
4310 (if rmail-speedbar-key-map
4312 (setq rmail-speedbar-key-map
(speedbar-make-specialized-keymap))
4314 (define-key rmail-speedbar-key-map
"e" 'speedbar-edit-line
)
4315 (define-key rmail-speedbar-key-map
"r" 'speedbar-edit-line
)
4316 (define-key rmail-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
4317 (define-key rmail-speedbar-key-map
"M"
4318 'rmail-speedbar-move-message-to-folder-on-line
)))
4321 (defvar rmail-speedbar-menu-items
4322 '(["Read Folder" speedbar-edit-line t
]
4323 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
4324 (save-excursion (beginning-of-line)
4325 (looking-at "<M> "))])
4326 "Additional menu-items to add to speedbar frame.")
4328 ;; Make sure our special speedbar major mode is loaded
4329 (if (featurep 'speedbar
)
4330 (rmail-install-speedbar-variables)
4331 (add-hook 'speedbar-load-hook
'rmail-install-speedbar-variables
))
4333 (defun rmail-speedbar-buttons (buffer)
4334 "Create buttons for BUFFER containing rmail messages.
4335 Click on the address under Reply to: to reply to this person.
4336 Under Folders: Click a name to read it, or on the <M> to move the
4337 current message into that RMAIL folder."
4339 (with-current-buffer buffer
4340 (goto-char (point-min))
4341 (if (not (re-search-forward "^Reply-To: " nil t
))
4342 (if (not (re-search-forward "^From:? " nil t
))
4346 (setq from
(buffer-substring (point) (line-end-position)))))
4347 (goto-char (point-min))
4348 (if (and (looking-at "Reply to:")
4349 (equal from rmail-speedbar-last-user
))
4351 (setq rmail-speedbar-last-user from
)
4353 (insert "Reply To:\n")
4355 (speedbar-insert-button from
'speedbar-directory-face
'highlight
4356 'rmail-speedbar-button
'rmail-reply
))
4357 (insert "Folders:\n")
4358 (let* ((case-fold-search nil
)
4359 (df (directory-files (with-current-buffer buffer
4361 nil rmail-speedbar-match-folder-regexp
)))
4363 (when (file-regular-p file
)
4364 (speedbar-insert-button "<M>" 'speedbar-button-face
'highlight
4365 'rmail-speedbar-move-message file
)
4366 (speedbar-insert-button file
'speedbar-file-face
'highlight
4367 'rmail-speedbar-find-file nil t
)))))))
4369 (defun rmail-speedbar-button (text token indent
)
4370 "Execute an rmail command specified by TEXT.
4371 The command used is TOKEN. INDENT is not used."
4372 (speedbar-with-attached-buffer
4375 (defun rmail-speedbar-find-file (text token indent
)
4376 "Load in the rmail file TEXT.
4377 TOKEN and INDENT are not used."
4378 (speedbar-with-attached-buffer
4379 (message "Loading in RMAIL file %s..." text
)
4382 (defun rmail-speedbar-move-message-to-folder-on-line ()
4383 "If the current line is a folder, move current message to it."
4387 (if (re-search-forward "<M> " (line-end-position) t
)
4390 (speedbar-do-function-pointer)))))
4392 (defun rmail-speedbar-move-message (text token indent
)
4393 "From button TEXT, copy current message to the rmail file specified by TOKEN.
4394 TEXT and INDENT are not used."
4395 (speedbar-with-attached-buffer
4396 (message "Moving message to %s" token
)
4397 ;; expand-file-name is needed due to the unhelpful way in which
4398 ;; rmail-output expands non-absolute filenames against rmail-default-file.
4399 ;; What is the point of that, anyway?
4400 (rmail-output (expand-file-name token
))))
4402 ;; Functions for setting, getting and encoding the POP password.
4403 ;; The password is encoded to prevent it from being easily accessible
4404 ;; to "prying eyes." Obviously, this encoding isn't "real security,"
4405 ;; nor is it meant to be.
4408 (defun rmail-set-remote-password (password)
4409 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
4410 (interactive "sPassword: ")
4412 (setq rmail-encoded-remote-password
4413 (rmail-encode-string password
(emacs-pid)))
4414 (setq rmail-remote-password nil
)
4415 (setq rmail-encoded-remote-password nil
)))
4417 (defun rmail-get-remote-password (imap)
4418 "Get the password for retrieving mail from a POP or IMAP server. If none
4419 has been set, then prompt the user for one."
4420 (when (not rmail-encoded-remote-password
)
4421 (if (not rmail-remote-password
)
4422 (setq rmail-remote-password
4423 (read-passwd (if imap
4425 "POP password: "))))
4426 (rmail-set-remote-password rmail-remote-password
)
4427 (setq rmail-remote-password nil
))
4428 (rmail-encode-string rmail-encoded-remote-password
(emacs-pid)))
4430 (defun rmail-have-password ()
4431 (or rmail-remote-password rmail-encoded-remote-password
))
4433 (defun rmail-encode-string (string mask
)
4434 "Encode STRING with integer MASK, by taking the exclusive OR of the
4435 lowest byte in the mask with the first character of string, the
4436 second-lowest-byte with the second character of the string, etc.,
4437 restarting at the lowest byte of the mask whenever it runs out.
4438 Returns the encoded string. Calling the function again with an
4439 encoded string (and the same mask) will decode the string."
4440 (setq mask
(abs mask
)) ; doesn't work if negative
4441 (let* ((string-vector (string-to-vector string
)) (i 0)
4442 (len (length string-vector
)) (curmask mask
) charmask
)
4445 (setq curmask mask
))
4446 (setq charmask
(% curmask
256))
4447 (setq curmask
(lsh curmask -
8))
4448 (aset string-vector i
(logxor charmask
(aref string-vector i
)))
4450 (concat string-vector
)))
4452 ;; Should this have a key-binding, or be in a menu?
4453 ;; There doesn't really seem to be an appropriate menu.
4454 ;; Eg the edit command is not in a menu either.
4455 (defun rmail-epa-decrypt ()
4456 "Decrypt OpenPGP armors in current message."
4459 ;; Save the current buffer here for cleanliness, in case we
4460 ;; change it in one of the calls to `epa-decrypt-region'.
4464 (goto-char (point-min))
4466 ;; In case the encrypted data is inside a mime attachment,
4467 ;; show it. This is a kludge; to be clean, it should not
4468 ;; modify the buffer, but I don't see how to do that.
4469 (when (search-forward "octet-stream" nil t
)
4472 (if (looking-at "Show")
4473 (rmail-mime-toggle-hidden)))
4475 ;; Now find all armored messages in the buffer
4476 ;; and decrypt them one by one.
4477 (goto-char (point-min))
4478 (while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t
)
4479 (let ((coding-system-for-read coding-system-for-read
)
4480 armor-start armor-end after-end
)
4481 (setq armor-start
(match-beginning 0)
4482 armor-end
(re-search-forward "^-----END PGP MESSAGE-----$"
4485 (error "Encryption armor beginning has no matching end"))
4486 (goto-char armor-start
)
4488 ;; Because epa--find-coding-system-for-mime-charset not autoloaded.
4491 ;; Use the charset specified in the armor.
4492 (unless coding-system-for-read
4493 (if (re-search-forward "^Charset: \\(.*\\)" armor-end t
)
4494 (setq coding-system-for-read
4495 (epa--find-coding-system-for-mime-charset
4496 (intern (downcase (match-string 1)))))))
4498 ;; Advance over this armor.
4499 (goto-char armor-end
)
4500 (setq after-end
(- (point-max) armor-end
))
4502 ;; Decrypt it, maybe in place, maybe making new buffer.
4504 armor-start armor-end
4505 ;; Call back this function to prepare the output.
4507 (let ((inhibit-read-only t
))
4508 (delete-region armor-start armor-end
)
4509 (goto-char armor-start
)
4512 (push (list armor-start
(- (point-max) after-end
))
4515 (when (and decrypts
(rmail-buffers-swapped-p))
4516 (when (y-or-n-p "Replace the original message? ")
4517 (setq decrypts
(nreverse decrypts
))
4518 (let ((beg (rmail-msgbeg rmail-current-message
))
4519 (end (rmail-msgend rmail-current-message
))
4520 (from-buffer (current-buffer)))
4521 (with-current-buffer rmail-view-buffer
4522 (narrow-to-region beg end
)
4523 (goto-char (point-min))
4524 (dolist (d decrypts
)
4525 (if (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t
)
4526 (let (armor-start armor-end
)
4527 (setq armor-start
(match-beginning 0)
4528 armor-end
(re-search-forward "^-----END PGP MESSAGE-----$"
4531 (delete-region armor-start armor-end
)
4532 (insert-buffer-substring from-buffer
(nth 0 d
) (nth 1 d
)))))))))))))
4534 ;;;; Desktop support
4536 (defun rmail-restore-desktop-buffer (desktop-buffer-file-name
4538 desktop-buffer-misc
)
4539 "Restore an rmail buffer specified in a desktop file."
4540 (condition-case error
4542 (rmail-input desktop-buffer-file-name
)
4543 (if (eq major-mode
'rmail-mode
)
4547 (kill-buffer (current-buffer))
4550 (add-to-list 'desktop-buffer-mode-handlers
4551 '(rmail-mode . rmail-restore-desktop-buffer
))
4553 ;; We use this to record the encoding of the current message before
4554 ;; saving the message collection.
4555 (defvar rmail-message-encoding nil
)
4557 ;; Used in `write-region-annotate-functions' to write rmail files.
4558 (defun rmail-write-region-annotate (start end
)
4559 (when (and (null start
) rmail-buffer-swapped
)
4560 (unless (buffer-live-p rmail-view-buffer
)
4561 (error "Buffer `%s' with real text of `%s' has disappeared"
4562 (buffer-name rmail-view-buffer
)
4563 (buffer-name (current-buffer))))
4564 (setq rmail-message-encoding buffer-file-coding-system
)
4565 (set-buffer rmail-view-buffer
)
4569 ;; Used to restore the encoding of the buffer where we show the
4570 ;; current message, after we save the message collection. This is
4571 ;; needed because rmail-write-region-annotate switches buffers behind
4572 ;; save-file's back, with the side effect that last-coding-system-used
4573 ;; is assigned to buffer-file-coding-system of the wrong buffer.
4574 (defun rmail-after-save-hook ()
4575 (if (or (eq rmail-view-buffer
(current-buffer))
4576 (eq rmail-buffer
(current-buffer)))
4577 (with-current-buffer
4578 (if (rmail-buffers-swapped-p) rmail-buffer rmail-view-buffer
)
4579 (setq buffer-file-coding-system rmail-message-encoding
))))
4580 (add-hook 'after-save-hook
'rmail-after-save-hook
)
4583 ;;; Start of automatically extracted autoloads.
4585 ;;;### (autoloads (rmail-edit-current-message) "rmailedit" "rmailedit.el"
4586 ;;;;;; "791ea184628feb6335fe3e29f7234934")
4587 ;;; Generated autoloads from rmailedit.el
4589 (autoload 'rmail-edit-current-message
"rmailedit" "\
4590 Edit the contents of this message.
4596 ;;;### (autoloads (rmail-next-labeled-message rmail-previous-labeled-message
4597 ;;;;;; rmail-read-label rmail-kill-label rmail-add-label) "rmailkwd"
4598 ;;;;;; "rmailkwd.el" "4ae5660d86d49e524f4a6bcbc6d9a984")
4599 ;;; Generated autoloads from rmailkwd.el
4601 (autoload 'rmail-add-label
"rmailkwd" "\
4602 Add LABEL to labels associated with current RMAIL message.
4603 Completes (see `rmail-read-label') over known labels when reading.
4604 LABEL may be a symbol or string. Only one label is allowed.
4608 (autoload 'rmail-kill-label
"rmailkwd" "\
4609 Remove LABEL from labels associated with current RMAIL message.
4610 Completes (see `rmail-read-label') over known labels when reading.
4611 LABEL may be a symbol or string. Only one label is allowed.
4615 (autoload 'rmail-read-label
"rmailkwd" "\
4616 Read a label with completion, prompting with PROMPT.
4617 Completions are chosen from `rmail-label-obarray'. The default
4618 is `rmail-last-label', if that is non-nil. Updates `rmail-last-label'
4619 according to the choice made, and returns a symbol.
4621 \(fn PROMPT)" nil nil
)
4623 (autoload 'rmail-previous-labeled-message
"rmailkwd" "\
4624 Show previous message with one of the labels LABELS.
4625 LABELS should be a comma-separated list of label names.
4626 If LABELS is empty, the last set of labels specified is used.
4627 With prefix argument N moves backward N messages with these labels.
4629 \(fn N LABELS)" t nil
)
4631 (autoload 'rmail-next-labeled-message
"rmailkwd" "\
4632 Show next message with one of the labels LABELS.
4633 LABELS should be a comma-separated list of label names.
4634 If LABELS is empty, the last set of labels specified is used.
4635 With prefix argument N moves forward N messages with these labels.
4637 \(fn N LABELS)" t nil
)
4641 ;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "f1937f85a1258de8880a089fa5ae5621")
4642 ;;; Generated autoloads from rmailmm.el
4644 (autoload 'rmail-mime
"rmailmm" "\
4645 Toggle the display of a MIME message.
4647 The actual behavior depends on the value of `rmail-enable-mime'.
4649 If `rmail-enable-mime' is non-nil (the default), this command toggles
4650 the display of a MIME message between decoded presentation form and
4651 raw data. With optional prefix argument ARG, it toggles the display only
4652 of the MIME entity at point, if there is one. The optional argument
4653 STATE forces a particular display state, rather than toggling.
4654 `raw' forces raw mode, any other non-nil value forces decoded mode.
4656 If `rmail-enable-mime' is nil, this creates a temporary \"*RMAIL*\"
4657 buffer holding a decoded copy of the message. Inline content-types are
4658 handled according to `rmail-mime-media-type-handlers-alist'.
4659 By default, this displays text and multipart messages, and offers to
4660 download attachments as specified by `rmail-mime-attachment-dirs-alist'.
4661 The arguments ARG and STATE have no effect in this case.
4663 \(fn &optional ARG STATE)" t nil
)
4667 ;;;### (autoloads (set-rmail-inbox-list) "rmailmsc" "rmailmsc.el"
4668 ;;;;;; "e2212ea15561d60365ffa1f7a5902939")
4669 ;;; Generated autoloads from rmailmsc.el
4671 (autoload 'set-rmail-inbox-list
"rmailmsc" "\
4672 Set the inbox list of the current RMAIL file to FILE-NAME.
4673 You can specify one file name, or several names separated by commas.
4674 If FILE-NAME is empty, remove any existing inbox list.
4676 This applies only to the current session.
4678 \(fn FILE-NAME)" t nil
)
4682 ;;;### (autoloads (rmail-sort-by-labels rmail-sort-by-lines rmail-sort-by-correspondent
4683 ;;;;;; rmail-sort-by-recipient rmail-sort-by-author rmail-sort-by-subject
4684 ;;;;;; rmail-sort-by-date) "rmailsort" "rmailsort.el" "38da5f17d4ed0dcd2b09c158642cef63")
4685 ;;; Generated autoloads from rmailsort.el
4687 (autoload 'rmail-sort-by-date
"rmailsort" "\
4688 Sort messages of current Rmail buffer by \"Date\" header.
4689 If prefix argument REVERSE is non-nil, sorts in reverse order.
4691 \(fn REVERSE)" t nil
)
4693 (autoload 'rmail-sort-by-subject
"rmailsort" "\
4694 Sort messages of current Rmail buffer by \"Subject\" header.
4695 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
4696 non-nil, sorts in reverse order.
4698 \(fn REVERSE)" t nil
)
4700 (autoload 'rmail-sort-by-author
"rmailsort" "\
4701 Sort messages of current Rmail buffer by author.
4702 This uses either the \"From\" or \"Sender\" header, downcased.
4703 If prefix argument REVERSE is non-nil, sorts in reverse order.
4705 \(fn REVERSE)" t nil
)
4707 (autoload 'rmail-sort-by-recipient
"rmailsort" "\
4708 Sort messages of current Rmail buffer by recipient.
4709 This uses either the \"To\" or \"Apparently-To\" header, downcased.
4710 If prefix argument REVERSE is non-nil, sorts in reverse order.
4712 \(fn REVERSE)" t nil
)
4714 (autoload 'rmail-sort-by-correspondent
"rmailsort" "\
4715 Sort messages of current Rmail buffer by other correspondent.
4716 This uses either the \"From\", \"Sender\", \"To\", or
4717 \"Apparently-To\" header, downcased. Uses the first header not
4718 excluded by `mail-dont-reply-to-names'. If prefix argument
4719 REVERSE is non-nil, sorts in reverse order.
4721 \(fn REVERSE)" t nil
)
4723 (autoload 'rmail-sort-by-lines
"rmailsort" "\
4724 Sort messages of current Rmail buffer by the number of lines.
4725 If prefix argument REVERSE is non-nil, sorts in reverse order.
4727 \(fn REVERSE)" t nil
)
4729 (autoload 'rmail-sort-by-labels
"rmailsort" "\
4730 Sort messages of current Rmail buffer by labels.
4731 LABELS is a comma-separated list of labels. The order of these
4732 labels specifies the order of messages: messages with the first
4733 label come first, messages with the second label come second, and
4734 so on. Messages that have none of these labels come last.
4735 If prefix argument REVERSE is non-nil, sorts in reverse order.
4737 \(fn REVERSE LABELS)" t nil
)
4741 ;;;### (autoloads (rmail-summary-by-senders rmail-summary-by-topic
4742 ;;;;;; rmail-summary-by-regexp rmail-summary-by-recipients rmail-summary-by-labels
4743 ;;;;;; rmail-summary) "rmailsum" "rmailsum.el" "856fc6e337d5398b302c448ee7a2315e")
4744 ;;; Generated autoloads from rmailsum.el
4746 (autoload 'rmail-summary
"rmailsum" "\
4747 Display a summary of all messages, one line per message.
4751 (autoload 'rmail-summary-by-labels
"rmailsum" "\
4752 Display a summary of all messages with one or more LABELS.
4753 LABELS should be a string containing the desired labels, separated by commas.
4755 \(fn LABELS)" t nil
)
4757 (autoload 'rmail-summary-by-recipients
"rmailsum" "\
4758 Display a summary of all messages with the given RECIPIENTS.
4759 Normally checks the To, From and Cc fields of headers;
4760 but if PRIMARY-ONLY is non-nil (prefix arg given),
4761 only look in the To and From fields.
4762 RECIPIENTS is a string of regexps separated by commas.
4764 \(fn RECIPIENTS &optional PRIMARY-ONLY)" t nil
)
4766 (autoload 'rmail-summary-by-regexp
"rmailsum" "\
4767 Display a summary of all messages according to regexp REGEXP.
4768 If the regular expression is found in the header of the message
4769 \(including in the date and other lines, as well as the subject line),
4770 Emacs will list the message in the summary.
4772 \(fn REGEXP)" t nil
)
4774 (autoload 'rmail-summary-by-topic
"rmailsum" "\
4775 Display a summary of all messages with the given SUBJECT.
4776 Normally checks just the Subject field of headers; but with prefix
4777 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
4778 SUBJECT is a string of regexps separated by commas.
4780 \(fn SUBJECT &optional WHOLE-MESSAGE)" t nil
)
4782 (autoload 'rmail-summary-by-senders
"rmailsum" "\
4783 Display a summary of all messages whose \"From\" field matches SENDERS.
4784 SENDERS is a string of regexps separated by commas.
4786 \(fn SENDERS)" t nil
)
4790 ;;;### (autoloads (unforward-rmail-message undigestify-rmail-message)
4791 ;;;;;; "undigest" "undigest.el" "9f270a2571bbbbfabc27498a8d4089c7")
4792 ;;; Generated autoloads from undigest.el
4794 (autoload 'undigestify-rmail-message
"undigest" "\
4795 Break up a digest message into its constituent messages.
4796 Leaves original message, deleted, before the undigestified messages.
4800 (autoload 'unforward-rmail-message
"undigest" "\
4801 Extract a forwarded message from the containing message.
4802 This puts the forwarded message into a separate rmail message following
4803 the containing message. This command is only useful when messages are
4804 forwarded with `rmail-enable-mime-composing' set to nil.
4810 ;;; End of automatically extracted autoloads.
4815 ;;; rmail.el ends here