1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006 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 2, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
31 ;; New features include attribute and keyword support, message
32 ;; selection by dispatch table, summary by attributes and keywords,
33 ;; expunging by dispatch table, sticky options for file commands.
35 ;; Extended by Bob Weiner of Motorola
36 ;; New features include: rmail and rmail-summary buffers remain
37 ;; synchronized and key bindings basically operate the same way in both
38 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
39 ;; variable, and a bury rmail buffer (wipe) command.
43 (eval-when-compile (require 'mule-util
)) ; for detect-coding-with-priority
46 (defvar font-lock-fontified
)
47 (defvar mail-abbrev-syntax-table
)
49 (defvar messages-head
)
50 (defvar rmail-use-spam-filter
)
52 (defvar rsf-sleep-after-message
)
53 (defvar total-messages
)
56 ; These variables now declared in paths.el.
57 ;(defvar rmail-spool-directory "/usr/spool/mail/"
58 ; "This is the name of the directory used by the system mailer for\n\
59 ;delivering new mail. Its name should end with a slash.")
60 ;(defvar rmail-file-name
61 ; (expand-file-name "~/RMAIL")
65 "Mail reader for Emacs."
68 (defgroup rmail-retrieve nil
69 "Rmail retrieval options."
73 (defgroup rmail-files nil
78 (defgroup rmail-headers nil
79 "Rmail header options."
83 (defgroup rmail-reply nil
84 "Rmail reply options."
88 (defgroup rmail-summary nil
89 "Rmail summary options."
91 :prefix
"rmail-summary-"
94 (defgroup rmail-output nil
95 "Output message to a file."
96 :prefix
"rmail-output-"
100 (defgroup rmail-edit nil
102 :prefix
"rmail-edit-"
105 (defgroup rmail-obsolete nil
106 "Rmail obsolete customization variables."
109 (defcustom rmail-movemail-program nil
110 "If non-nil, the file name of the `movemail' program."
111 :group
'rmail-retrieve
112 :type
'(choice (const nil
) string
))
114 (defcustom rmail-pop-password nil
115 "*Password to use when reading mail from POP server.
116 Please use `rmail-remote-password' instead."
117 :type
'(choice (string :tag
"Password")
118 (const :tag
"Not Required" nil
))
119 :group
'rmail-obsolete
)
121 (defcustom rmail-pop-password-required nil
122 "*Non-nil if a password is required when reading mail from a POP server.
123 Please use rmail-remote-password-required instead."
125 :group
'rmail-obsolete
)
127 (defcustom rmail-remote-password nil
128 "*Password to use when reading mail from a remote server.
129 This setting is ignored for mailboxes whose URL already contains a password."
130 :type
'(choice (string :tag
"Password")
131 (const :tag
"Not Required" nil
))
132 :set-after
'(rmail-pop-password)
133 :set
#'(lambda (symbol value
)
136 (boundp 'rmail-pop-password
)
140 (setq rmail-pop-password nil
))
141 :group
'rmail-retrieve
144 (defcustom rmail-remote-password-required nil
145 "*Non-nil if a password is required when reading mail from a remote server."
147 :set-after
'(rmail-pop-password-required)
148 :set
#'(lambda (symbol value
)
151 (boundp 'rmail-pop-password-required
)
152 rmail-pop-password-required
)
153 rmail-pop-password-required
155 (setq rmail-pop-password-required nil
))
156 :group
'rmail-retrieve
159 (defcustom rmail-movemail-flags nil
160 "*List of flags to pass to movemail.
161 Most commonly used to specify `-g' to enable GSS-API authentication
162 or `-k' to enable Kerberos authentication."
163 :type
'(repeat string
)
164 :group
'rmail-retrieve
167 (defvar rmail-remote-password-error
"invalid usercode or password\\|
168 unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
169 "Regular expression matching incorrect-password POP or IMAP server error
171 If you get an incorrect-password error that this expression does not match,
172 please report it with \\[report-emacs-bug].")
174 (defvar rmail-encoded-remote-password nil
)
176 (defcustom rmail-preserve-inbox nil
177 "*Non-nil means leave incoming mail in the user's inbox--don't delete it."
179 :group
'rmail-retrieve
)
181 (defcustom rmail-movemail-search-path nil
182 "*List of directories to search for movemail (in addition to `exec-path')."
183 :group
'rmail-retrieve
184 :type
'(repeat (directory)))
186 (defun rmail-probe (prog)
187 "Determine what flavor of movemail PROG is.
188 We do this by executing it with `--version' and analyzing its output."
190 (let ((tbuf (current-buffer)))
191 (buffer-disable-undo tbuf
)
192 (call-process prog nil tbuf nil
"--version")
193 (if (not (buffer-modified-p tbuf
))
194 ;; Should not happen...
196 (goto-char (point-min))
198 ((looking-at ".*movemail: invalid option")
199 'emacs
) ;; Possibly...
200 ((looking-at "movemail (GNU Mailutils .*)")
206 (defun rmail-autodetect ()
207 "Determine and return the file name of the `movemail' program.
208 If `rmail-movemail-program' is non-nil, use it.
209 Otherwise, look for `movemail' in the directories in
210 `rmail-movemail-search-path', those in `exec-path', and `exec-directory'."
211 (if rmail-movemail-program
212 (rmail-probe rmail-movemail-program
)
214 (dolist (dir (append rmail-movemail-search-path exec-path
215 (list exec-directory
)))
216 (when (and dir
(file-accessible-directory-p dir
))
217 (let ((progname (expand-file-name "movemail" dir
)))
218 (when (and (not (file-directory-p progname
))
219 (file-executable-p progname
))
220 (let ((x (rmail-probe progname
)))
222 (setq rmail-movemail-program progname
)
223 (throw 'scan x
))))))))))
225 (defvar rmail-movemail-variant-in-use nil
226 "The movemail variant currently in use. Known variants are:
228 `emacs' Means any implementation, compatible with the native Emacs one.
230 `mailutils' Means GNU mailutils implementation, capable of handling full
231 mail URLs as the source mailbox;")
234 (defun rmail-movemail-variant-p (&rest variants
)
235 "Return t if the current movemail variant is any of VARIANTS.
236 Currently known variants are 'emacs and 'mailutils."
237 (when (not rmail-movemail-variant-in-use
)
239 (setq rmail-movemail-variant-in-use
(rmail-autodetect)))
240 (not (null (member rmail-movemail-variant-in-use variants
))))
243 (defcustom rmail-dont-reply-to-names nil
"\
244 *A regexp specifying addresses to prune from a reply message.
245 A value of nil means exclude your own email address as an address
246 plus whatever is specified by `rmail-default-dont-reply-to-names'."
247 :type
'(choice regexp
(const :tag
"Your Name" nil
))
251 (defvar rmail-default-dont-reply-to-names
"\\`info-" "\
252 A regular expression specifying part of the default value of the
253 variable `rmail-dont-reply-to-names', for when the user does not set
254 `rmail-dont-reply-to-names' explicitly. (The other part of the default
255 value is the user's email address and name.)
256 It is useful to set this variable in the site customization file.")
259 (defcustom rmail-ignored-headers
260 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
261 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
262 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
263 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
264 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
265 "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
266 "\\|^content-transfer-encoding:\\|^x-coding-system:"
267 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
268 "\\|^precedence:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
269 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
270 "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
271 "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
272 "\\|^mbox-line:\\|^cancel-lock:\\|^DomainKey-Signature:"
273 "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"
276 "*Regexp to match header fields that Rmail should normally hide.
277 \(See also `rmail-nonignored-headers', which overrides this regexp.)
278 This variable is used for reformatting the message header,
279 which normally happens once for each message,
280 when you view the message for the first time in Rmail.
281 To make a change in this variable take effect
282 for a message that you have already viewed,
283 go to that message and type \\[rmail-toggle-header] twice."
285 :group
'rmail-headers
)
287 (defcustom rmail-nonignored-headers
"^x-spam-status:"
288 "*Regexp to match X header fields that Rmail should show.
289 This regexp overrides `rmail-ignored-headers'; if both this regexp
290 and that one match a certain header field, Rmail shows the field.
292 This variable is used for reformatting the message header,
293 which normally happens once for each message,
294 when you view the message for the first time in Rmail.
295 To make a change in this variable take effect
296 for a message that you have already viewed,
297 go to that message and type \\[rmail-toggle-header] twice."
299 :group
'rmail-headers
)
302 (defcustom rmail-displayed-headers nil
303 "*Regexp to match Header fields that Rmail should display.
304 If nil, display all header fields except those matched by
305 `rmail-ignored-headers'."
306 :type
'(choice regexp
(const :tag
"All"))
307 :group
'rmail-headers
)
310 (defcustom rmail-retry-ignored-headers
"^x-authentication-warning:" "\
311 *Headers that should be stripped when retrying a failed message."
312 :type
'(choice regexp
(const nil
:tag
"None"))
313 :group
'rmail-headers
)
316 (defcustom rmail-highlighted-headers
"^From:\\|^Subject:" "\
317 *Regexp to match Header fields that Rmail should normally highlight.
318 A value of nil means don't highlight.
319 See also `rmail-highlight-face'."
321 :group
'rmail-headers
)
323 (defface rmail-highlight
324 '((t :default highlight
))
325 "Face to use for highlighting the most important header fields."
326 :group
'rmail-headers
330 (defcustom rmail-highlight-face
'rmail-highlight
"\
331 *Face used by Rmail for highlighting headers."
332 :type
'(choice (const :tag
"Default" nil
)
334 :group
'rmail-headers
)
337 (defcustom rmail-delete-after-output nil
"\
338 *Non-nil means automatically delete a message that is copied to a file."
343 (defcustom rmail-primary-inbox-list nil
"\
344 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
345 nil means the default, which is (\"/usr/spool/mail/$USER\")
346 \(the name varies depending on the operating system,
347 and the value of the environment variable MAIL overrides it)."
348 ;; Don't use backquote here, because we don't want to need it
350 :type
(list 'choice
'(const :tag
"Default" nil
)
351 (list 'repeat
':value
(list (or (getenv "MAIL")
352 (concat "/var/spool/mail/"
355 :group
'rmail-retrieve
359 (defcustom rmail-mail-new-frame nil
360 "*Non-nil means Rmail makes a new frame for composing outgoing mail.
361 This is handy if you want to preserve the window configuration of
362 the frame where you have the RMAIL buffer displayed."
367 (defcustom rmail-secondary-file-directory
"~/"
368 "*Directory for additional secondary Rmail files."
372 (defcustom rmail-secondary-file-regexp
"\\.xmail$"
373 "*Regexp for which files are secondary Rmail files."
378 (defcustom rmail-confirm-expunge
'y-or-n-p
379 "*Whether and how to ask for confirmation before expunging deleted messages."
380 :type
'(choice (const :tag
"No confirmation" nil
)
381 (const :tag
"Confirm with y-or-n-p" y-or-n-p
)
382 (const :tag
"Confirm with yes-or-no-p" yes-or-no-p
))
387 (defvar rmail-mode-hook nil
388 "List of functions to call when Rmail is invoked.")
391 (defvar rmail-get-new-mail-hook nil
392 "List of functions to call when Rmail has retrieved new mail.")
395 (defcustom rmail-show-message-hook nil
396 "List of functions to call when Rmail displays a message."
398 :options
'(goto-address)
402 (defvar rmail-quit-hook nil
403 "List of functions to call when quitting out of Rmail.")
406 (defvar rmail-delete-message-hook nil
407 "List of functions to call when Rmail deletes a message.
408 When the hooks are called, the message has been marked deleted but is
409 still the current message in the Rmail buffer.")
411 ;; These may be altered by site-init.el to match the format of mmdf files
412 ;; delimiting used on a given host (delim1 and delim2 from the config
415 (defvar rmail-mmdf-delim1
"^\001\001\001\001\n"
416 "Regexp marking the start of an mmdf message.")
417 (defvar rmail-mmdf-delim2
"^\001\001\001\001\n"
418 "Regexp marking the end of an mmdf message.")
420 (defcustom rmail-message-filter nil
421 "If non-nil, a filter function for new messages in RMAIL.
422 Called with region narrowed to the message, including headers,
423 before obeying `rmail-ignored-headers'."
424 :group
'rmail-headers
427 (defcustom rmail-automatic-folder-directives nil
428 "List of directives specifying where to put a message.
429 Each element of the list is of the form:
431 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
433 Where FOLDERNAME is the name of a BABYL format folder to put the
434 message. If any of the field regexp's are nil, then it is ignored.
436 If FOLDERNAME is \"/dev/null\", it is deleted.
437 If FOLDERNAME is nil then it is deleted, and skipped.
439 FIELD is the plain text name of a field in the message, such as
440 \"subject\" or \"from\". A FIELD of \"to\" will automatically include
441 all text from the \"cc\" field as well.
443 REGEXP is an expression to match in the preceeding specified FIELD.
444 FIELD/REGEXP pairs continue in the list.
447 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
448 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
451 :type
'(repeat (sexp :tag
"Directive")))
453 (defvar rmail-reply-prefix
"Re: "
454 "String to prepend to Subject line when replying to a message.")
456 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
457 ;; This pattern should catch all the common variants.
458 ;; rms: I deleted the change to delete tags in square brackets
459 ;; because they mess up RT tags.
460 (defvar rmail-reply-regexp
"\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
461 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
463 (defcustom rmail-display-summary nil
464 "*If non-nil, Rmail always displays the summary buffer."
465 :group
'rmail-summary
468 (defvar rmail-inbox-list nil
)
469 (put 'rmail-inbox-list
'permanent-local t
)
471 (defvar rmail-keywords nil
)
472 (put 'rmail-keywords
'permanent-local t
)
474 (defvar rmail-buffer nil
475 "The RMAIL buffer related to the current buffer.
476 In an RMAIL buffer, this holds the RMAIL buffer itself.
477 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
478 (put 'rmail-buffer
'permanent-local t
)
480 ;; Message counters and markers. Deleted flags.
482 (defvar rmail-current-message nil
)
483 (put 'rmail-current-message
'permanent-local t
)
485 (defvar rmail-total-messages nil
)
486 (put 'rmail-total-messages
'permanent-local t
)
488 (defvar rmail-message-vector nil
)
489 (put 'rmail-message-vector
'permanent-local t
)
491 (defvar rmail-deleted-vector nil
)
492 (put 'rmail-deleted-vector
'permanent-local t
)
494 (defvar rmail-msgref-vector nil
495 "In an Rmail buffer, a vector whose Nth element is a list (N).
496 When expunging renumbers messages, these lists are modified
497 by substituting the new message number into the existing list.")
498 (put 'rmail-msgref-vector
'permanent-local t
)
500 (defvar rmail-overlay-list nil
)
501 (put 'rmail-overlay-list
'permanent-local t
)
503 ;; These are used by autoloaded rmail-summary.
505 (defvar rmail-summary-buffer nil
)
506 (put 'rmail-summary-buffer
'permanent-local t
)
507 (defvar rmail-summary-vector nil
)
508 (put 'rmail-summary-vector
'permanent-local t
)
510 (defvar rmail-view-buffer nil
511 "Buffer which holds RMAIL message for MIME displaying.")
512 (put 'rmail-view-buffer
'permanent-local t
)
514 ;; `Sticky' default variables.
516 ;; Last individual label specified to a or k.
517 (defvar rmail-last-label nil
)
518 (put 'rmail-last-label
'permanent-local t
)
520 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
521 (defvar rmail-last-multi-labels nil
)
523 (defvar rmail-last-regexp nil
)
524 (put 'rmail-last-regexp
'permanent-local t
)
526 (defcustom rmail-default-file
"~/xmail"
527 "*Default file name for \\[rmail-output]."
530 (defcustom rmail-default-rmail-file
"~/XMAIL"
531 "*Default file name for \\[rmail-output-to-rmail-file]."
534 (defcustom rmail-default-body-file
"~/mailout"
535 "*Default file name for \\[rmail-output-body-to-file]."
540 ;; Mule and MIME related variables.
543 (defvar rmail-file-coding-system nil
544 "Coding system used in RMAIL file.
546 This is set to nil by default.")
549 (defcustom rmail-enable-mime nil
550 "*If non-nil, RMAIL uses MIME feature.
551 If the value is t, RMAIL automatically shows MIME decoded message.
552 If the value is neither t nor nil, RMAIL does not show MIME decoded message
553 until a user explicitly requires it.
555 Even if the value is non-nil, you can't use MIME feature
556 if the feature specified by `rmail-mime-feature' is not available
558 :type
'(choice (const :tag
"on" t
)
559 (const :tag
"off" nil
)
560 (other :tag
"when asked" ask
))
563 (defvar rmail-enable-mime-composing nil
564 "*If non-nil, RMAIL uses `rmail-insert-mime-forwarded-message-function' to forward.")
567 (defvar rmail-show-mime-function nil
568 "Function to show MIME decoded message of RMAIL file.
569 This function is called when `rmail-enable-mime' is non-nil.
570 It is called with no argument.")
573 (defvar rmail-insert-mime-forwarded-message-function nil
574 "Function to insert a message in MIME format so it can be forwarded.
575 This function is called if `rmail-enable-mime' or
576 `rmail-enable-mime-composing' is non-nil.
577 It is called with one argument FORWARD-BUFFER, which is a
578 buffer containing the message to forward. The current buffer
579 is the outgoing mail buffer.")
582 (defvar rmail-insert-mime-resent-message-function nil
583 "Function to insert a message in MIME format so it can be resent.
584 This function is called if `rmail-enable-mime' is non-nil.
585 It is called with one argument FORWARD-BUFFER, which is a
586 buffer containing the message to forward. The current buffer
587 is the outgoing mail buffer.")
590 (defvar rmail-search-mime-message-function nil
591 "Function to check if a regexp matches a MIME message.
592 This function is called if `rmail-enable-mime' is non-nil.
593 It is called with two arguments MSG and REGEXP, where
594 MSG is the message number, REGEXP is the regular expression.")
597 (defvar rmail-search-mime-header-function nil
598 "Function to check if a regexp matches a header of MIME message.
599 This function is called if `rmail-enable-mime' is non-nil.
600 It is called with three arguments MSG, REGEXP, and LIMIT, where
601 MSG is the message number,
602 REGEXP is the regular expression,
603 LIMIT is the position specifying the end of header.")
606 (defvar rmail-mime-feature
'rmail-mime
607 "Feature to require to load MIME support in Rmail.
608 When starting Rmail, if `rmail-enable-mime' is non-nil,
609 this feature is required with `require'.
611 The default value is `rmail-mime'. This feature is provided by
612 the rmail-mime package available at <http://www.m17n.org/rmail-mime/>.")
615 (defvar rmail-decode-mime-charset t
616 "*Non-nil means a message is decoded by MIME's charset specification.
617 If this variable is nil, or the message has not MIME specification,
618 the message is decoded as normal way.
620 If the variable `rmail-enable-mime' is non-nil, this variables is
621 ignored, and all the decoding work is done by a feature specified by
622 the variable `rmail-mime-feature'.")
625 (defvar rmail-mime-charset-pattern
626 (concat "^content-type:[ ]*text/plain;"
627 "\\(?:[ \t\n]*\\(format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
628 "[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?")
629 "Regexp to match MIME-charset specification in a header of message.
630 The first parenthesized expression should match the MIME-charset name.")
633 ;;; Regexp matching the delimiter of messages in UNIX mail format
634 ;;; (UNIX From lines), minus the initial ^. Note that if you change
635 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
636 ;;; that knows the exact ordering of the \\( \\) subexpressions.
637 (defvar rmail-unix-mail-delimiter
638 (let ((time-zone-regexp
639 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
640 "\\|[-+]?[0-9][0-9][0-9][0-9]"
646 ;; Many things can happen to an RFC 822 mailbox before it is put into
647 ;; a `From' line. The leading phrase can be stripped, e.g.
648 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
649 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
650 ;; can be removed, e.g.
651 ;; From: joe@y.z (Joe K
653 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
656 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
657 ;; The mailbox can be removed or be replaced by white space, e.g.
658 ;; From: "Joe User"{space}{tab}
660 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
661 ;; where {space} and {tab} represent the Ascii space and tab characters.
662 ;; We want to match the results of any of these manglings.
663 ;; The following regexp rejects names whose first characters are
664 ;; obviously bogus, but after that anything goes.
665 "\\([^\0-\b\n-\r\^?].*\\)? "
667 ;; The time the message was sent.
668 "\\([^\0-\r \^?]+\\) +" ; day of the week
669 "\\([^\0-\r \^?]+\\) +" ; month
670 "\\([0-3]?[0-9]\\) +" ; day of month
671 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
673 ;; Perhaps a time zone, specified by an abbreviation, or by a
678 " \\([0-9][0-9]+\\) *"
680 ;; On some systems the time zone can appear after the year, too.
684 "\\(remote from .*\\)?"
689 (defvar rmail-font-lock-keywords
690 ;; These are all matched case-insensitively.
692 (let* ((cite-chars "[>|}]")
694 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
695 (list '("^\\(From\\|Sender\\|Resent-From\\):"
696 . font-lock-function-name-face
)
697 '("^Reply-To:.*$" . font-lock-function-name-face
)
698 '("^Subject:" . font-lock-comment-face
)
699 '("^X-Spam-Status:" . font-lock-keyword-face
)
700 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
701 . font-lock-keyword-face
)
702 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
704 (,(concat "\\=[ \t]*"
705 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
706 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
708 (beginning-of-line) (end-of-line)
709 (1 font-lock-comment-delimiter-face nil t
)
710 (5 font-lock-comment-face nil t
)))
711 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
712 . font-lock-string-face
))))
713 "Additional expressions to highlight in Rmail mode.")
715 ;; Perform BODY in the summary buffer
716 ;; in such a way that its cursor is properly updated in its own window.
717 (defmacro rmail-select-summary
(&rest body
)
718 `(let ((total rmail-total-messages
))
719 (if (rmail-summary-displayed)
720 (let ((window (selected-window)))
724 (pop-to-buffer rmail-summary-buffer
)
725 ;; rmail-total-messages is a buffer-local var
726 ;; in the rmail buffer.
727 ;; This way we make it available for the body
728 ;; even tho the rmail buffer is not current.
729 (let ((rmail-total-messages total
))
731 (select-window window
))))
733 (set-buffer rmail-summary-buffer
)
734 (let ((rmail-total-messages total
))
736 (rmail-maybe-display-summary)))
738 ;;;; *** Rmail Mode ***
740 ;; This variable is dynamically bound. The defvar is here to placate
741 ;; the byte compiler.
743 (defvar rmail-enable-multibyte nil
)
746 (defun rmail-require-mime-maybe ()
747 "Require `rmail-mime-feature' if that is non-nil.
748 Signal an error and set `rmail-mime-feature' to nil if the feature
750 (when rmail-enable-mime
752 (require rmail-mime-feature
)
756 (format "Although MIME support is requested
757 by setting `rmail-enable-mime' to non-nil, the required feature
758 `%s' (the value of `rmail-mime-feature')
759 is not available in the current session.
760 So, the MIME support is turned off for the moment."
762 (setq rmail-enable-mime nil
)))))
766 (defun rmail (&optional file-name-arg
)
767 "Read and edit incoming mail.
768 Moves messages into file named by `rmail-file-name' (a babyl format file)
769 and edits that file in RMAIL Mode.
770 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
772 May be called with file name as argument; then performs rmail editing on
773 that file, but does not copy any new mail into the file.
774 Interactively, if you supply a prefix argument, then you
775 have a chance to specify a file name with the minibuffer.
777 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
778 (interactive (if current-prefix-arg
779 (list (read-file-name "Run rmail on RMAIL file: "))))
780 (rmail-require-mime-maybe)
781 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
782 ;; Use find-buffer-visiting, not get-file-buffer, for those users
783 ;; who have find-file-visit-truename set to t.
784 (existed (find-buffer-visiting file-name
))
785 ;; This binding is necessary because we must decide if we
786 ;; need code conversion while the buffer is unibyte
787 ;; (i.e. enable-multibyte-characters is nil).
788 (rmail-enable-multibyte
790 (with-current-buffer existed enable-multibyte-characters
)
791 (default-value 'enable-multibyte-characters
)))
792 ;; Since the file may contain messages of different encodings
793 ;; at the tail (non-BYBYL part), we can't decode them at once
794 ;; on reading. So, at first, we read the file without text
795 ;; code conversion, then decode the messages one by one by
796 ;; rmail-decode-babyl-format or
797 ;; rmail-convert-to-babyl-format.
798 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
))
799 run-mail-hook msg-shown
)
800 ;; Like find-file, but in the case where a buffer existed
801 ;; and the file was reverted, recompute the message-data.
802 ;; We used to bind enable-local-variables to nil here,
803 ;; but that should not be needed now that rmail-mode
804 ;; sets it locally to nil.
805 ;; (Binding a variable locally with let is not safe if it has
806 ;; buffer-local bindings.)
807 (if (and existed
(not (verify-visited-file-modtime existed
)))
809 (find-file file-name
)
810 (if (and (verify-visited-file-modtime existed
)
811 (eq major-mode
'rmail-mode
))
812 (progn (rmail-forget-messages)
813 (rmail-set-message-counters))))
815 (let ((enable-local-variables nil
))
816 (find-file-noselect file-name
))))
817 (if (eq major-mode
'rmail-edit-mode
)
818 (error "Exit Rmail Edit mode before getting new mail"))
819 (if (and existed
(> (buffer-size) 0))
820 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
821 (or (eq major-mode
'rmail-mode
)
822 (progn (rmail-mode-2)
823 (setq run-mail-hook t
)))
824 (setq run-mail-hook t
)
826 ;; Convert all or part to Babyl file if possible.
828 (goto-char (point-max)))
829 ;; As we have read a file by raw-text, the buffer is set to
830 ;; unibyte. We must make it multibyte if necessary.
831 (if (and rmail-enable-multibyte
832 (not enable-multibyte-characters
))
833 (set-buffer-multibyte t
))
834 ;; If necessary, scan to find all the messages.
835 (rmail-maybe-set-message-counters)
837 (unless (and (not file-name-arg
)
838 (rmail-get-new-mail))
839 (rmail-show-message (rmail-first-unseen-message)))
841 (if rmail-display-summary
(rmail-summary))
842 (rmail-construct-io-menu)
844 (run-hooks 'rmail-mode-hook
))))))
846 ;; Given the value of MAILPATH, return a list of inbox file names.
847 ;; This is turned off because it is not clear that the user wants
848 ;; all these inboxes to feed into the primary rmail file.
849 ; (defun rmail-convert-mailpath (string)
851 ; (while (setq idx (string-match "[%:]" string))
852 ; (let ((this (substring string 0 idx)))
853 ; (setq string (substring string (1+ idx)))
854 ; (setq list (cons (if (string-match "%" this)
855 ; (substring this 0 (string-match "%" this))
860 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
861 ; will not cause emacs 18.55 problems.
863 ;; This calls rmail-decode-babyl-format if the file is already Babyl.
865 (defun rmail-convert-file ()
868 (goto-char (point-min))
869 ;; If file doesn't start like a Babyl file,
870 ;; convert it to one, by adding a header and converting each message.
871 (cond ((looking-at "BABYL OPTIONS:"))
872 ((looking-at "Version: 5\n")
873 ;; Losing babyl file made by old version of Rmail.
874 ;; Just fix the babyl file header; don't make a new one,
875 ;; so we don't lose the Labels: file attribute, etc.
876 (let ((buffer-read-only nil
))
877 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
878 ((equal (point-min) (point-max))
879 ;; Empty RMAIL file. Just insert the header.
880 (rmail-insert-rmail-file-header))
882 ;; Non-empty file in non-RMAIL format. Add header and convert.
884 (rmail-insert-rmail-file-header)))
885 ;; If file was not a Babyl file or if there are
886 ;; Unix format messages added at the end,
887 ;; convert file as necessary.
890 (goto-char (point-max))
891 (search-backward "\n\^_")
893 (looking-at "\n*From ")))
894 (let ((buffer-read-only nil
))
895 (message "Converting to Babyl format...")
896 ;; If file needs conversion, convert it all,
897 ;; except for the BABYL header.
898 ;; (rmail-convert-to-babyl-format would delete the header.)
899 (goto-char (point-min))
900 (search-forward "\n\^_" nil t
)
901 (narrow-to-region (point) (point-max))
902 (rmail-convert-to-babyl-format)
903 (message "Converting to Babyl format...done"))
904 (if (and (not rmail-enable-mime
)
905 rmail-enable-multibyte
)
906 ;; We still have to decode BABYL part.
907 (rmail-decode-babyl-format)))))
909 (defun rmail-insert-rmail-file-header ()
910 (let ((buffer-read-only nil
))
911 ;; -*-rmail-*- is here so that visiting the file normally
912 ;; recognizes it as an Rmail file.
913 (insert "BABYL OPTIONS: -*- rmail -*-
916 Note: This is the header of an rmail file.
917 Note: If you are seeing it in rmail,
918 Note: it means the file has no messages in it.\n\^_")))
920 ;; Decode Babyl formatted part at the head of current buffer by
921 ;; rmail-file-coding-system, or if it is nil, do auto conversion.
923 (defun rmail-decode-babyl-format ()
924 (let ((modifiedp (buffer-modified-p))
925 (buffer-read-only nil
)
926 (coding-system rmail-file-coding-system
)
928 (goto-char (point-min))
929 (search-forward "\n\^_" nil t
) ; Skip BABYL header.
931 (goto-char (point-max))
932 (search-backward "\n\^_" from
'mv
)
934 (unless (and coding-system
935 (coding-system-p coding-system
))
937 ;; If rmail-file-coding-system is nil, Emacs 21 writes
938 ;; RMAIL files in emacs-mule, Emacs 22 in utf-8, but
939 ;; earlier versions did that with the current buffer's
940 ;; encoding. So we want to favor detection of emacs-mule
941 ;; (whose normal priority is quite low) and utf-8, but
942 ;; still allow detection of other encodings if they won't
943 ;; fit. The call to with-coding-priority below achieves
945 (with-coding-priority '(emacs-mule utf-8
)
946 (detect-coding-region from to
'highest
))))
947 (unless (eq (coding-system-type coding-system
) 'undecided
)
948 (set-buffer-modified-p t
) ; avoid locking when decoding
949 (let ((buffer-undo-list t
))
950 (decode-coding-region from to coding-system
))
951 (setq coding-system last-coding-system-used
))
952 (set-buffer-modified-p modifiedp
)
953 (setq buffer-file-coding-system nil
)
954 (setq save-buffer-coding-system
955 (or coding-system
'undecided
))))
957 (defvar rmail-mode-map nil
)
960 (setq rmail-mode-map
(make-keymap))
961 (suppress-keymap rmail-mode-map
)
962 (define-key rmail-mode-map
"a" 'rmail-add-label
)
963 (define-key rmail-mode-map
"b" 'rmail-bury
)
964 (define-key rmail-mode-map
"c" 'rmail-continue
)
965 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
966 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
)
967 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
968 (define-key rmail-mode-map
"f" 'rmail-forward
)
969 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
970 (define-key rmail-mode-map
"h" 'rmail-summary
)
971 (define-key rmail-mode-map
"i" 'rmail-input
)
972 (define-key rmail-mode-map
"j" 'rmail-show-message
)
973 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
974 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
975 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
976 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
977 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
978 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
979 (define-key rmail-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
980 (define-key rmail-mode-map
"m" 'rmail-mail
)
981 (define-key rmail-mode-map
"\em" 'rmail-retry-failure
)
982 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
983 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
984 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
985 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
986 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
987 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
988 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
989 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
990 (define-key rmail-mode-map
"q" 'rmail-quit
)
991 (define-key rmail-mode-map
"r" 'rmail-reply
)
992 ;; I find I can't live without the default M-r command -- rms.
993 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
994 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
995 (define-key rmail-mode-map
"\es" 'rmail-search
)
996 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
997 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
998 (define-key rmail-mode-map
"w" 'rmail-output-body-to-file
)
999 (define-key rmail-mode-map
"x" 'rmail-expunge
)
1000 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
1001 (define-key rmail-mode-map
"/" 'rmail-end-of-message
)
1002 (define-key rmail-mode-map
"<" 'rmail-first-message
)
1003 (define-key rmail-mode-map
">" 'rmail-last-message
)
1004 (define-key rmail-mode-map
" " 'scroll-up
)
1005 (define-key rmail-mode-map
"\177" 'scroll-down
)
1006 (define-key rmail-mode-map
"?" 'describe-mode
)
1007 (define-key rmail-mode-map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
1008 (define-key rmail-mode-map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
1009 (define-key rmail-mode-map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
1010 (define-key rmail-mode-map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
1011 (define-key rmail-mode-map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
1012 (define-key rmail-mode-map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
1013 (define-key rmail-mode-map
"\C-c\C-s\C-k" 'rmail-sort-by-labels
)
1014 (define-key rmail-mode-map
"\C-c\C-n" 'rmail-next-same-subject
)
1015 (define-key rmail-mode-map
"\C-c\C-p" 'rmail-previous-same-subject
)
1018 (define-key rmail-mode-map
[menu-bar
] (make-sparse-keymap))
1020 (define-key rmail-mode-map
[menu-bar classify
]
1021 (cons "Classify" (make-sparse-keymap "Classify")))
1023 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1026 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1029 (define-key rmail-mode-map
[menu-bar classify output-body
]
1030 '("Output body to file..." . rmail-output-body-to-file
))
1032 (define-key rmail-mode-map
[menu-bar classify output-inbox
]
1033 '("Output (inbox)..." . rmail-output
))
1035 (define-key rmail-mode-map
[menu-bar classify output
]
1036 '("Output (Rmail)..." . rmail-output-to-rmail-file
))
1038 (define-key rmail-mode-map
[menu-bar classify kill-label
]
1039 '("Kill Label..." . rmail-kill-label
))
1041 (define-key rmail-mode-map
[menu-bar classify add-label
]
1042 '("Add Label..." . rmail-add-label
))
1044 (define-key rmail-mode-map
[menu-bar summary
]
1045 (cons "Summary" (make-sparse-keymap "Summary")))
1047 (define-key rmail-mode-map
[menu-bar summary senders
]
1048 '("By Senders..." . rmail-summary-by-senders
))
1050 (define-key rmail-mode-map
[menu-bar summary labels
]
1051 '("By Labels..." . rmail-summary-by-labels
))
1053 (define-key rmail-mode-map
[menu-bar summary recipients
]
1054 '("By Recipients..." . rmail-summary-by-recipients
))
1056 (define-key rmail-mode-map
[menu-bar summary topic
]
1057 '("By Topic..." . rmail-summary-by-topic
))
1059 (define-key rmail-mode-map
[menu-bar summary regexp
]
1060 '("By Regexp..." . rmail-summary-by-regexp
))
1062 (define-key rmail-mode-map
[menu-bar summary all
]
1063 '("All" . rmail-summary
))
1065 (define-key rmail-mode-map
[menu-bar mail
]
1066 (cons "Mail" (make-sparse-keymap "Mail")))
1068 (define-key rmail-mode-map
[menu-bar mail rmail-get-new-mail
]
1069 '("Get New Mail" . rmail-get-new-mail
))
1071 (define-key rmail-mode-map
[menu-bar mail lambda
]
1074 (define-key rmail-mode-map
[menu-bar mail continue
]
1075 '("Continue" . rmail-continue
))
1077 (define-key rmail-mode-map
[menu-bar mail resend
]
1078 '("Re-send..." . rmail-resend
))
1080 (define-key rmail-mode-map
[menu-bar mail forward
]
1081 '("Forward" . rmail-forward
))
1083 (define-key rmail-mode-map
[menu-bar mail retry
]
1084 '("Retry" . rmail-retry-failure
))
1086 (define-key rmail-mode-map
[menu-bar mail reply
]
1087 '("Reply" . rmail-reply
))
1089 (define-key rmail-mode-map
[menu-bar mail mail
]
1090 '("Mail" . rmail-mail
))
1092 (define-key rmail-mode-map
[menu-bar delete
]
1093 (cons "Delete" (make-sparse-keymap "Delete")))
1095 (define-key rmail-mode-map
[menu-bar delete expunge
/save
]
1096 '("Expunge/Save" . rmail-expunge-and-save
))
1098 (define-key rmail-mode-map
[menu-bar delete expunge
]
1099 '("Expunge" . rmail-expunge
))
1101 (define-key rmail-mode-map
[menu-bar delete undelete
]
1102 '("Undelete" . rmail-undelete-previous-message
))
1104 (define-key rmail-mode-map
[menu-bar delete delete
]
1105 '("Delete" . rmail-delete-forward
))
1107 (define-key rmail-mode-map
[menu-bar move
]
1108 (cons "Move" (make-sparse-keymap "Move")))
1110 (define-key rmail-mode-map
[menu-bar move search-back
]
1111 '("Search Back..." . rmail-search-backwards
))
1113 (define-key rmail-mode-map
[menu-bar move search
]
1114 '("Search..." . rmail-search
))
1116 (define-key rmail-mode-map
[menu-bar move previous
]
1117 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
1119 (define-key rmail-mode-map
[menu-bar move next
]
1120 '("Next Nondeleted" . rmail-next-undeleted-message
))
1122 (define-key rmail-mode-map
[menu-bar move last
]
1123 '("Last" . rmail-last-message
))
1125 (define-key rmail-mode-map
[menu-bar move first
]
1126 '("First" . rmail-first-message
))
1128 (define-key rmail-mode-map
[menu-bar move previous
]
1129 '("Previous" . rmail-previous-message
))
1131 (define-key rmail-mode-map
[menu-bar move next
]
1132 '("Next" . rmail-next-message
))
1135 (defvar rmail-tool-bar-map
1136 (if (display-graphic-p)
1137 (let ((map (make-sparse-keymap)))
1138 (tool-bar-local-item-from-menu 'rmail-get-new-mail
"mail/inbox"
1140 (tool-bar-local-item-from-menu 'rmail-next-undeleted-message
"right-arrow"
1142 (tool-bar-local-item-from-menu 'rmail-previous-undeleted-message
"left-arrow"
1144 (tool-bar-local-item-from-menu 'rmail-search
"search"
1146 (tool-bar-local-item-from-menu 'rmail-input
"open"
1148 (tool-bar-local-item-from-menu 'rmail-mail
"mail/compose"
1150 (tool-bar-local-item-from-menu 'rmail-reply
"mail/reply-all"
1152 (tool-bar-local-item-from-menu 'rmail-forward
"mail/forward"
1154 (tool-bar-local-item-from-menu 'rmail-delete-forward
"close"
1156 (tool-bar-local-item-from-menu 'rmail-output
"mail/move"
1158 (tool-bar-local-item-from-menu 'rmail-output-body-to-file
"mail/save"
1160 (tool-bar-local-item-from-menu 'rmail-expunge
"delete"
1166 ;; Rmail mode is suitable only for specially formatted data.
1167 (put 'rmail-mode
'mode-class
'special
)
1169 (defun rmail-mode-kill-summary ()
1170 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
1173 (defun rmail-mode ()
1174 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
1175 All normal editing commands are turned off.
1176 Instead, these commands are available:
1178 \\[rmail-beginning-of-message] Move point to front of this message.
1179 \\[rmail-end-of-message] Move point to bottom of this message.
1180 \\[scroll-up] Scroll to next screen of this message.
1181 \\[scroll-down] Scroll to previous screen of this message.
1182 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
1183 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
1184 \\[rmail-next-message] Move to Next message whether deleted or not.
1185 \\[rmail-previous-message] Move to Previous message whether deleted or not.
1186 \\[rmail-first-message] Move to the first message in Rmail file.
1187 \\[rmail-last-message] Move to the last message in Rmail file.
1188 \\[rmail-show-message] Jump to message specified by numeric position in file.
1189 \\[rmail-search] Search for string and show message it is found in.
1190 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
1191 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
1192 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1193 till a deleted message is found.
1194 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
1195 \\[rmail-expunge] Expunge deleted messages.
1196 \\[rmail-expunge-and-save] Expunge and save the file.
1197 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
1198 \\[save-buffer] Save without expunging.
1199 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
1200 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
1201 \\[rmail-continue] Continue composing outgoing message started before.
1202 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
1203 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
1204 \\[rmail-forward] Forward this message to another user.
1205 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
1206 \\[rmail-output] Output this message to a Unix-format mail file (append it).
1207 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1208 \\[rmail-input] Input Rmail file. Run Rmail on that file.
1209 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
1210 \\[rmail-kill-label] Kill label. Remove a label from current message.
1211 \\[rmail-next-labeled-message] Move to Next message with specified label
1212 (label defaults to last one specified).
1213 Standard labels: filed, unseen, answered, forwarded, deleted.
1214 Any other label is present only if you add it with \\[rmail-add-label].
1215 \\[rmail-previous-labeled-message] Move to Previous message with specified label
1216 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
1217 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
1218 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1219 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1220 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1221 \\[rmail-toggle-header] Toggle display of complete header."
1223 (let ((finding-rmail-file (not (eq major-mode
'rmail-mode
))))
1225 (when (and finding-rmail-file
1226 (null coding-system-for-read
)
1227 default-enable-multibyte-characters
)
1228 (let ((rmail-enable-multibyte t
))
1229 (rmail-require-mime-maybe)
1230 (rmail-convert-file)
1231 (goto-char (point-max))
1232 (set-buffer-multibyte t
)))
1233 (rmail-set-message-counters)
1234 (rmail-show-message rmail-total-messages
)
1235 (when finding-rmail-file
1236 (when rmail-display-summary
1238 (rmail-construct-io-menu))
1239 (run-mode-hooks 'rmail-mode-hook
)))
1241 (defun rmail-mode-2 ()
1242 (kill-all-local-variables)
1244 (rmail-perm-variables)
1247 (defun rmail-mode-1 ()
1248 (setq major-mode
'rmail-mode
)
1249 (setq mode-name
"RMAIL")
1250 (setq buffer-read-only t
)
1251 ;; No need to auto save RMAIL files in normal circumstances
1252 ;; because they contain no info except attribute changes
1253 ;; and deletion of messages.
1254 ;; The one exception is when messages are copied into an Rmail mode buffer.
1255 ;; rmail-output-to-rmail-file enables auto save when you do that.
1256 (setq buffer-auto-save-file-name nil
)
1257 (setq mode-line-modified
"--")
1258 (use-local-map rmail-mode-map
)
1259 (set-syntax-table text-mode-syntax-table
)
1260 (setq local-abbrev-table text-mode-abbrev-table
))
1262 ;; Set up the permanent locals associated with an Rmail file.
1263 (defun rmail-perm-variables ()
1264 (make-local-variable 'rmail-last-label
)
1265 (make-local-variable 'rmail-last-regexp
)
1266 (make-local-variable 'rmail-deleted-vector
)
1267 (make-local-variable 'rmail-buffer
)
1268 (setq rmail-buffer
(current-buffer))
1269 (make-local-variable 'rmail-view-buffer
)
1270 (setq rmail-view-buffer rmail-buffer
)
1271 (make-local-variable 'rmail-summary-buffer
)
1272 (make-local-variable 'rmail-summary-vector
)
1273 (make-local-variable 'rmail-current-message
)
1274 (make-local-variable 'rmail-total-messages
)
1275 (make-local-variable 'rmail-overlay-list
)
1276 (setq rmail-overlay-list nil
)
1277 (make-local-variable 'rmail-message-vector
)
1278 (make-local-variable 'rmail-msgref-vector
)
1279 (make-local-variable 'rmail-inbox-list
)
1280 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
1281 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1282 (and (null rmail-inbox-list
)
1283 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
1284 (equal buffer-file-truename
1285 (abbreviate-file-name (file-truename rmail-file-name
))))
1286 (setq rmail-inbox-list
1287 (or rmail-primary-inbox-list
1288 (list (or (getenv "MAIL")
1289 (concat rmail-spool-directory
1290 (user-login-name)))))))
1291 (make-local-variable 'rmail-keywords
)
1292 (set (make-local-variable 'tool-bar-map
) rmail-tool-bar-map
)
1293 ;; this gets generated as needed
1294 (setq rmail-keywords nil
))
1296 ;; Set up the non-permanent locals associated with Rmail mode.
1297 (defun rmail-variables ()
1298 (make-local-variable 'save-buffer-coding-system
)
1299 ;; If we don't already have a value for save-buffer-coding-system,
1300 ;; get it from buffer-file-coding-system, and clear that
1301 ;; because it should be determined in rmail-show-message.
1302 (unless save-buffer-coding-system
1303 (setq save-buffer-coding-system
(or buffer-file-coding-system
'undecided
))
1304 (setq buffer-file-coding-system nil
))
1305 ;; Don't let a local variables list in a message cause confusion.
1306 (make-local-variable 'local-enable-local-variables
)
1307 (setq local-enable-local-variables nil
)
1308 (make-local-variable 'revert-buffer-function
)
1309 (setq revert-buffer-function
'rmail-revert
)
1310 (make-local-variable 'font-lock-defaults
)
1311 (setq font-lock-defaults
1312 '(rmail-font-lock-keywords
1314 (font-lock-maximum-size . nil
)
1315 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
1316 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
1317 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
1318 (make-local-variable 'require-final-newline
)
1319 (setq require-final-newline nil
)
1320 (make-local-variable 'version-control
)
1321 (setq version-control
'never
)
1322 (make-local-variable 'kill-buffer-hook
)
1323 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
1324 (make-local-variable 'file-precious-flag
)
1325 (setq file-precious-flag t
)
1326 (make-local-variable 'desktop-save-buffer
)
1327 (setq desktop-save-buffer t
))
1329 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1330 (defun rmail-revert (arg noconfirm
)
1331 (set-buffer rmail-buffer
)
1332 (let* ((revert-buffer-function (default-value 'revert-buffer-function
))
1333 (rmail-enable-multibyte enable-multibyte-characters
)
1334 ;; See similar code in `rmail'.
1335 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
)))
1336 ;; Call our caller again, but this time it does the default thing.
1337 (if (revert-buffer arg noconfirm
)
1338 ;; If the user said "yes", and we changed something,
1339 ;; reparse the messages.
1341 (set-buffer rmail-buffer
)
1343 ;; Convert all or part to Babyl file if possible.
1344 (rmail-convert-file)
1345 ;; We have read the file as raw-text, so the buffer is set to
1346 ;; unibyte. Make it multibyte if necessary.
1347 (if (and rmail-enable-multibyte
1348 (not enable-multibyte-characters
))
1349 (set-buffer-multibyte t
))
1350 (goto-char (point-max))
1351 (rmail-set-message-counters)
1352 (rmail-show-message rmail-total-messages
)
1353 (run-hooks 'rmail-mode-hook
)))))
1355 ;; Return a list of files from this buffer's Mail: option.
1356 ;; Does not assume that messages have been parsed.
1357 ;; Just returns nil if buffer does not look like Babyl format.
1358 (defun rmail-parse-file-inboxes ()
1363 (cond ((looking-at "BABYL OPTIONS:")
1364 (search-forward "\n\^_" nil
'move
)
1365 (narrow-to-region 1 (point))
1367 (if (search-forward "\nMail:" nil t
)
1369 (narrow-to-region (point) (progn (end-of-line) (point)))
1370 (goto-char (point-min))
1371 (mail-parse-comma-list))))))))
1373 (defun rmail-expunge-and-save ()
1374 "Expunge and save RMAIL file."
1377 (set-buffer rmail-buffer
)
1379 (if (rmail-summary-exists)
1380 (rmail-select-summary (set-buffer-modified-p nil
))))
1382 (defun rmail-quit ()
1384 Hook `rmail-quit-hook' is run after expunging."
1386 (rmail-expunge-and-save)
1387 (when (boundp 'rmail-quit-hook
)
1388 (run-hooks 'rmail-quit-hook
))
1389 ;; Don't switch to the summary buffer even if it was recently visible.
1390 (when rmail-summary-buffer
1391 (replace-buffer-in-windows rmail-summary-buffer
)
1392 (bury-buffer rmail-summary-buffer
))
1393 (if rmail-enable-mime
1394 (let ((obuf rmail-buffer
)
1395 (ovbuf rmail-view-buffer
))
1396 (set-buffer rmail-view-buffer
)
1398 (replace-buffer-in-windows ovbuf
)
1399 (replace-buffer-in-windows obuf
)
1401 (let ((obuf (current-buffer)))
1403 (replace-buffer-in-windows obuf
))))
1405 (defun rmail-bury ()
1406 "Bury current Rmail buffer and its summary buffer."
1408 ;; This let var was called rmail-buffer, but that interfered
1409 ;; with the buffer-local var used in summary buffers.
1410 (let ((buffer-to-bury (current-buffer)))
1411 (if (rmail-summary-exists)
1413 (while (setq window
(get-buffer-window rmail-summary-buffer
))
1414 (quit-window nil window
))
1415 (bury-buffer rmail-summary-buffer
)))
1418 (defun rmail-duplicate-message ()
1419 "Create a duplicated copy of the current message.
1420 The duplicate copy goes into the Rmail file just after the
1424 (let ((buffer-read-only nil
)
1425 (number rmail-current-message
)
1426 (string (buffer-substring (rmail-msgbeg rmail-current-message
)
1427 (rmail-msgend rmail-current-message
))))
1428 (goto-char (rmail-msgend rmail-current-message
))
1430 (rmail-forget-messages)
1431 (rmail-show-message number
)
1432 (message "Message duplicated")))
1435 (defun rmail-input (filename)
1436 "Run Rmail on file FILENAME."
1437 (interactive "FRun rmail on RMAIL file: ")
1441 ;; This used to scan subdirectories recursively, but someone pointed out
1442 ;; that if the user wants that, person can put all the files in one dir.
1443 ;; And the recursive scan was slow. So I took it out.
1445 (defun rmail-find-all-files (start)
1446 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1447 (if (file-accessible-directory-p start
)
1449 (let* ((case-fold-search t
)
1450 (files (directory-files start t rmail-secondary-file-regexp
)))
1451 ;; Sort here instead of in directory-files
1452 ;; because this list is usually much shorter.
1453 (sort files
'string
<))))
1455 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
1456 (let ((menu (make-sparse-keymap menu-name
)))
1458 (function (lambda (item)
1463 (rmail-list-to-menu (car item
) (cdr item
)
1466 (concat full-name
"/"
1469 (setq name
(car item
)))
1473 (list 'lambda
() '(interactive)
1477 (concat full-name
"/" item
)
1479 rmail-secondary-file-directory
))))))
1480 (define-key menu
(vector (intern name
))
1481 (cons name command
)))))
1485 ;; This command is always "disabled" when it appears in a menu.
1486 (put 'rmail-disable-menu
'menu-enable
''nil
)
1488 (defun rmail-construct-io-menu ()
1489 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1492 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1493 (cons "Input Rmail File"
1494 (rmail-list-to-menu "Input Rmail File"
1497 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1498 (cons "Output Rmail File"
1499 (rmail-list-to-menu "Output Rmail File"
1501 'rmail-output-to-rmail-file
))))
1503 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1504 '("Input Rmail File" . rmail-disable-menu
))
1505 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1506 '("Output Rmail File" . rmail-disable-menu
)))))
1509 ;;;; *** Rmail input ***
1511 ;; RLK feature not added in this version:
1512 ;; argument specifies inbox file or files in various ways.
1514 (defun rmail-get-new-mail (&optional file-name
)
1515 "Move any new mail from this RMAIL file's inbox files.
1516 The inbox files can be specified with the file's Mail: option. The
1517 variable `rmail-primary-inbox-list' specifies the inboxes for your
1518 primary RMAIL file if it has no Mail: option. By default, this is
1519 your /usr/spool/mail/$USER.
1521 You can also specify the file to get new mail from. In this case, the
1522 file of new mail is not changed or deleted. Noninteractively, you can
1523 pass the inbox file name as an argument. Interactively, a prefix
1524 argument causes us to read a file name and use that file as the inbox.
1526 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1527 always be left in inbox files rather than deleted.
1529 This function runs `rmail-get-new-mail-hook' before saving the updated file.
1530 It returns t if it got any new messages."
1532 (list (if current-prefix-arg
1533 (read-file-name "Get new mail from file: "))))
1534 (run-hooks 'rmail-before-get-new-mail-hook
)
1535 ;; If the disk file has been changed from under us,
1536 ;; revert to it before we get new mail.
1537 (or (verify-visited-file-modtime (current-buffer))
1538 (find-file (buffer-file-name)))
1539 (set-buffer rmail-buffer
)
1540 (rmail-maybe-set-message-counters)
1542 ;; Get rid of all undo records for this buffer.
1543 (or (eq buffer-undo-list t
)
1544 (setq buffer-undo-list nil
))
1545 (let ((all-files (if file-name
(list file-name
)
1547 (rmail-enable-multibyte (default-value 'enable-multibyte-characters
))
1552 (let ((opoint (point))
1554 (rsf-number-of-spam 0)
1556 ;; If buffer has not changed yet, and has not been saved yet,
1557 ;; don't replace the old backup file now.
1558 (make-backup-files (and make-backup-files
(buffer-modified-p)))
1559 (buffer-read-only nil
)
1560 ;; Don't make undo records for what we do in getting mail.
1561 (buffer-undo-list t
)
1563 ;; Files to insert this time around.
1565 ;; Last names of those files.
1567 ;; Pull files off all-files onto files
1568 ;; as long as there is no name conflict.
1569 ;; A conflict happens when two inbox file names
1570 ;; have the same last component.
1571 (while (and all-files
1572 (not (member (file-name-nondirectory (car all-files
))
1574 (setq files
(cons (car all-files
) files
)
1576 (cons (file-name-nondirectory (car all-files
)) files
))
1577 (setq all-files
(cdr all-files
)))
1578 ;; Put them back in their original order.
1579 (setq files
(nreverse files
))
1581 (goto-char (point-max))
1582 (skip-chars-backward " \t\n") ; just in case of brain damage
1583 (delete-region (point) (point-max)) ; caused by require-final-newline
1586 (narrow-to-region (point) (point))
1587 ;; Read in the contents of the inbox files,
1588 ;; renaming them as necessary,
1589 ;; and adding to the list of files to delete eventually.
1591 (rmail-insert-inbox-text files nil
)
1592 (setq delete-files
(rmail-insert-inbox-text files t
)))
1593 ;; Scan the new text and convert each message to babyl format.
1594 (goto-char (point-min))
1597 (setq new-messages
(rmail-convert-to-babyl-format)
1599 ;; Try to delete the garbage just inserted.
1600 (or success
(delete-region (point-min) (point-max)))
1601 ;; If we could not convert the file's inboxes,
1602 ;; rename the files we tried to read
1603 ;; so we won't over and over again.
1604 (if (and (not file-name
) (not success
))
1605 (let ((delfiles delete-files
)
1608 (while (file-exists-p (format "RMAILOSE.%d" count
))
1609 (setq count
(1+ count
)))
1610 (rename-file (car delfiles
)
1611 (format "RMAILOSE.%d" count
))
1612 (setq delfiles
(cdr delfiles
))))))
1613 (or (zerop new-messages
)
1616 (search-backward "\n\^_" nil t
)
1617 (narrow-to-region (point) (point-max))
1618 (goto-char (1+ (point-min)))
1619 (rmail-count-new-messages)
1620 (run-hooks 'rmail-get-new-mail-hook
)
1622 ;; Delete the old files, now that babyl file is saved.
1625 ;; First, try deleting.
1627 (delete-file (car delete-files
))
1629 ;; If we can't delete it, truncate it.
1630 (write-region (point) (point) (car delete-files
))))
1632 (setq delete-files
(cdr delete-files
)))))
1633 (if (= new-messages
0)
1634 (progn (goto-char opoint
)
1635 (if (or file-name rmail-inbox-list
)
1636 (message "(No new mail has arrived)")))
1637 ;; check new messages to see if any of them is spam:
1638 (if (and (featurep 'rmail-spam-filter
)
1639 rmail-use-spam-filter
)
1641 ((old-messages (- rmail-total-messages new-messages
))
1642 (rsf-scanned-message-number (1+ old-messages
))
1643 ;; save deletion flags of old messages: vector starts
1644 ;; at zero (is one longer that no of messages),
1645 ;; therefore take 1+ old-messages
1647 (substring rmail-deleted-vector
0 (1+
1649 ;; set all messages to undeleted
1650 (setq rmail-deleted-vector
1651 (make-string (1+ rmail-total-messages
) ?\
))
1652 (while (<= rsf-scanned-message-number
1653 rmail-total-messages
)
1655 (if (not (rmail-spam-filter rsf-scanned-message-number
))
1656 (progn (setq rsf-number-of-spam
(1+ rsf-number-of-spam
)))
1658 (setq rsf-scanned-message-number
(1+ rsf-scanned-message-number
))
1660 (if (> rsf-number-of-spam
0)
1662 (when (rmail-expunge-confirmed)
1663 (rmail-only-expunge t
))
1665 (setq rmail-deleted-vector
1668 (make-string (- rmail-total-messages old-messages
)
1671 (if (rmail-summary-exists)
1672 (rmail-select-summary
1673 (rmail-update-summary)))
1674 (message "%d new message%s read%s"
1675 new-messages
(if (= 1 new-messages
) "" "s")
1676 ;; print out a message on number of spam messages found:
1677 (if (and (featurep 'rmail-spam-filter
)
1678 rmail-use-spam-filter
1679 (> rsf-number-of-spam
0))
1680 (if (= 1 new-messages
)
1681 ", and found to be a spam message"
1682 (if (> rsf-number-of-spam
1)
1683 (format ", %d of which found to be spam messages"
1685 ", one of which found to be a spam message"))
1687 (if (and (featurep 'rmail-spam-filter
)
1688 rmail-use-spam-filter
1689 (> rsf-number-of-spam
0))
1690 (progn (if rsf-beep
(beep t
))
1691 (sleep-for rsf-sleep-after-message
)))
1693 ;; Move to the first new message
1694 ;; unless we have other unseen messages before it.
1695 (rmail-show-message (rmail-first-unseen-message))
1696 (run-hooks 'rmail-after-get-new-mail-hook
)
1699 ;; Don't leave the buffer screwed up if we get a disk-full error.
1700 (or found
(rmail-show-message)))))
1702 (defun rmail-parse-url (file)
1703 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1704 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1705 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1706 a remote mailbox, PASSWORD is the password if it should be
1707 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1708 is non-nil if the user has supplied the password interactively.
1711 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file
)
1712 (let (got-password supplied-password
1713 (proto (match-string 1 file
))
1714 (user (match-string 3 file
))
1715 (pass (match-string 5 file
))
1716 (host (substring file
(or (match-end 2)
1717 (+ 3 (match-end 1))))))
1720 (when rmail-remote-password-required
1721 (setq got-password
(not (rmail-have-password)))
1722 (setq supplied-password
(rmail-get-remote-password
1723 (string-equal proto
"imap")))))
1725 (if (rmail-movemail-variant-p 'emacs
)
1726 (if (string-equal proto
"pop")
1727 (list (concat "po:" user
":" host
)
1729 (or pass supplied-password
)
1731 (error "Emacs movemail does not support %s protocol" proto
))
1733 (or (string-equal proto
"pop") (string-equal proto
"imap"))
1737 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file
)
1738 (let (got-password supplied-password
1740 (user (match-string 1 file
))
1741 (host (match-string 3 file
)))
1743 (when rmail-remote-password-required
1744 (setq got-password
(not (rmail-have-password)))
1745 (setq supplied-password
(rmail-get-remote-password nil
)))
1747 (list file
"pop" supplied-password got-password
)))
1750 (list file nil nil nil
))))
1752 (defun rmail-insert-inbox-text (files renamep
)
1753 ;; Detect a locked file now, so that we avoid moving mail
1754 ;; out of the real inbox file. (That could scare people.)
1755 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1756 (error "RMAIL file %s is locked"
1757 (file-name-nondirectory buffer-file-name
)))
1758 (let (file tofile delete-files movemail popmail got-password password
)
1760 ;; Handle remote mailbox names specially; don't expand as filenames
1761 ;; in case the userid contains a directory separator.
1762 (setq file
(car files
))
1763 (let ((url-data (rmail-parse-url file
)))
1764 (setq file
(nth 0 url-data
))
1765 (setq popmail
(nth 1 url-data
))
1766 (setq password
(nth 2 url-data
))
1767 (setq got-password
(nth 3 url-data
)))
1771 (setq file
(file-truename
1772 (substitute-in-file-name (expand-file-name file
)))))
1773 (setq tofile
(expand-file-name
1774 ;; Generate name to move to from inbox name,
1775 ;; in case of multiple inboxes that need moving.
1777 (file-name-nondirectory
1778 (if (memq system-type
'(windows-nt cygwin
))
1779 ;; cannot have "po:" in file name
1782 ;; Use the directory of this rmail file
1783 ;; because it's a nuisance to use the homedir
1784 ;; if that is on a full disk and this rmail
1786 (file-name-directory
1787 (expand-file-name buffer-file-name
))))
1788 ;; Always use movemail to rename the file,
1789 ;; since there can be mailboxes in various directories.
1792 ;; On some systems, /usr/spool/mail/foo is a directory
1793 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1794 (if (file-directory-p file
)
1795 (setq file
(expand-file-name (user-login-name)
1798 (message "Getting mail from the remote server ..."))
1799 ((and (file-exists-p tofile
)
1800 (/= 0 (nth 7 (file-attributes tofile
))))
1801 (message "Getting mail from %s..." tofile
))
1802 ((and (file-exists-p file
)
1803 (/= 0 (nth 7 (file-attributes file
))))
1804 (message "Getting mail from %s..." file
)))
1805 ;; Set TOFILE if have not already done so, and
1806 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1807 (cond ((not renamep
)
1809 ((or (file-exists-p tofile
) (and (not popmail
)
1810 (not (file-exists-p file
))))
1814 (let ((errors (current-buffer)))
1815 (buffer-disable-undo errors
)
1818 (list (or rmail-movemail-program
1819 (expand-file-name "movemail"
1822 (if rmail-preserve-inbox
1825 (if (rmail-movemail-variant-p 'mailutils
)
1826 (append (list "--emacs") rmail-movemail-flags
)
1827 rmail-movemail-flags
)
1829 (if password
(list password
) nil
))))
1830 (apply 'call-process args
))
1831 (if (not (buffer-modified-p errors
))
1832 ;; No output => movemail won
1835 (subst-char-in-region (point-min) (point-max)
1837 (goto-char (point-max))
1838 (skip-chars-backward " \t")
1839 (delete-region (point) (point-max))
1840 (goto-char (point-min))
1841 (if (looking-at "movemail: ")
1842 (delete-region (point-min) (match-end 0)))
1844 ;; If we just read the password, most likely it is
1845 ;; wrong. Otherwise, see if there is a specific
1846 ;; reason to think that the problem is a wrong passwd.
1847 (if (or got-password
1848 (re-search-forward rmail-remote-password-error
1850 (rmail-set-remote-password nil
))
1852 ;; If using Mailutils, remove initial error code
1854 (when (rmail-movemail-variant-p 'mailutils
)
1855 (goto-char (point-min))
1856 (when (looking-at "[A-Z][A-Z0-9_]*:")
1857 (delete-region (point-min) (match-end 0))))
1859 (message "movemail: %s"
1860 (buffer-substring (point-min)
1866 ;; At this point, TOFILE contains the name to read:
1867 ;; Either the alternate name (if we renamed)
1868 ;; or the actual inbox (if not renaming).
1869 (if (file-exists-p tofile
)
1870 (let ((coding-system-for-read 'no-conversion
)
1872 (goto-char (point-max))
1873 (setq size
(nth 1 (insert-file-contents tofile
)))
1874 (goto-char (point-max))
1875 (or (= (preceding-char) ?
\n)
1878 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
1879 (setq delete-files
(cons tofile delete-files
)))))
1881 (setq files
(cdr files
)))
1884 ;; Decode the region specified by FROM and TO by CODING.
1885 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
1886 (defun rmail-decode-region (from to coding
)
1887 (if (or (not coding
) (not (coding-system-p coding
)))
1888 (setq coding
'undecided
))
1889 ;; Use -dos decoding, to remove ^M characters left from base64 or
1890 ;; rogue qp-encoded text.
1891 (decode-coding-region from to
1892 (coding-system-change-eol-conversion coding
1))
1893 ;; Don't reveal the fact we used -dos decoding, as users generally
1894 ;; will not expect the RMAIL buffer to use DOS EOL format.
1895 (setq buffer-file-coding-system
1896 (setq last-coding-system-used
1897 (coding-system-change-eol-conversion coding
0))))
1899 ;; the rmail-break-forwarded-messages feature is not implemented
1900 (defun rmail-convert-to-babyl-format ()
1901 (let ((count 0) start
1902 (case-fold-search nil
)
1903 (invalid-input-resync
1904 (function (lambda ()
1905 (message "Invalid Babyl format in inbox!")
1907 ;; Try to get back in sync with a real message.
1908 (if (re-search-forward
1909 (concat rmail-mmdf-delim1
"\\|^From") nil t
)
1911 (goto-char (point-max)))))))
1912 (goto-char (point-min))
1915 (setq start
(point))
1916 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1917 (if (search-forward "\n\^_" nil t
)
1918 ;; If we find the proper terminator, delete through there.
1919 (delete-region (point-min) (point))
1920 (funcall invalid-input-resync
)
1921 (delete-region (point-min) (point))))
1922 ;; Babyl format message
1924 (or (search-forward "\n\^_" nil t
)
1925 (funcall invalid-input-resync
))
1926 (setq count
(1+ count
))
1927 ;; Make sure there is no extra white space after the ^_
1928 ;; at the end of the message.
1929 ;; Narrowing will make sure that whatever follows the junk
1930 ;; will be treated properly.
1931 (delete-region (point)
1933 (skip-chars-forward " \t\n")
1941 (if (looking-at "0")
1945 (narrow-to-region (point) (point-max))
1948 (case-fold-search t
)
1949 (quoted-printable-header-field-end
1953 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
1955 (base64-header-field-end
1959 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
1961 (if quoted-printable-header-field-end
1964 (mail-unquote-printable-region header-end
(point) nil t t
)
1965 (message "Malformed MIME quoted-printable message"))
1966 ;; Change "quoted-printable" to "8bit",
1967 ;; to reflect the decoding we just did.
1968 (goto-char quoted-printable-header-field-end
)
1969 (delete-region (point) (search-backward ":"))
1971 (if base64-header-field-end
1976 (base64-decode-region (1+ header-end
)
1980 ;; Change "base64" to "8bit", to reflect the
1981 ;; decoding we just did.
1982 (goto-char base64-header-field-end
)
1983 (delete-region (point) (search-backward ":"))
1984 (insert ": 8bit"))))
1985 (setq last-coding-system-used nil
)
1986 (or rmail-enable-mime
1987 (not rmail-enable-multibyte
)
1989 (if (and rmail-decode-mime-charset
1992 (search-forward "\n\n" nil t
)
1993 (let ((case-fold-search t
))
1995 rmail-mime-charset-pattern
1997 (intern (downcase (match-string 1))))))
1998 (rmail-decode-region start
(point) mime-charset
)))))
1999 ;; Add an X-Coding-System: header if we don't have one.
2003 (if (looking-at "0")
2006 (or (save-restriction
2007 (narrow-to-region (point) (point-max))
2009 (goto-char (point-min))
2010 (re-search-forward "^X-Coding-System:" nil t
))
2011 (insert "X-Coding-System: "
2012 (symbol-name last-coding-system-used
)
2014 (narrow-to-region (point) (point-max))
2015 (and (= 0 (% count
10))
2016 (message "Converting to Babyl format...%d" count
)))
2018 ((let ((case-fold-search t
))
2019 (looking-at rmail-mmdf-delim1
))
2020 (let ((case-fold-search t
))
2021 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
2022 (re-search-forward rmail-mmdf-delim2 nil t
)
2023 (replace-match "\^_"))
2026 (narrow-to-region start
(1- (point)))
2027 (goto-char (point-min))
2028 (while (search-forward "\n\^_" nil t
); single char "\^_"
2029 (replace-match "\n^_")))); 2 chars: "^" and "_"
2030 (setq last-coding-system-used nil
)
2031 (or rmail-enable-mime
2032 (not rmail-enable-multibyte
)
2033 (decode-coding-region start
(point) 'undecided
))
2037 (insert "X-Coding-System: "
2038 (symbol-name last-coding-system-used
)
2040 (narrow-to-region (point) (point-max))
2041 (setq count
(1+ count
))
2042 (and (= 0 (% count
10))
2043 (message "Converting to Babyl format...%d" count
)))
2045 ((looking-at "^From ")
2046 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
2047 (rmail-nuke-pinhead-header)
2048 ;; If this message has a Content-Length field,
2049 ;; skip to the end of the contents.
2050 (let* ((header-end (save-excursion
2051 (and (re-search-forward "\n\n" nil t
)
2053 (case-fold-search t
)
2054 (quoted-printable-header-field-end
2057 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
2059 (base64-header-field-end
2062 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
2065 ;; Get the numeric value from the Content-Length field.
2067 ;; Back up to end of prev line,
2068 ;; in case the Content-Length field comes first.
2070 (and (search-forward "\ncontent-length: "
2073 (eol (progn (end-of-line) (point))))
2074 (string-to-number (buffer-substring beg eol
)))))))
2076 (if (and (natnump size
)
2077 (<= (+ header-end size
) (point-max))
2078 ;; Make sure this would put us at a position
2079 ;; that we could continue from.
2081 (goto-char (+ header-end size
))
2082 (skip-chars-forward "\n")
2084 (and (looking-at "BABYL OPTIONS:")
2085 (search-forward "\n\^_" nil t
))
2086 (and (looking-at "\^L")
2087 (search-forward "\n\^_" nil t
))
2088 (let ((case-fold-search t
))
2089 (looking-at rmail-mmdf-delim1
))
2090 (looking-at "From "))))
2091 (goto-char (+ header-end size
))
2092 (message "Ignoring invalid Content-Length field")
2094 (if (let ((case-fold-search nil
))
2096 (concat "^[\^_]?\\("
2097 rmail-unix-mail-delimiter
2099 rmail-mmdf-delim1
"\\|"
2100 "^BABYL OPTIONS:\\|"
2101 "\^L\n[01],\\)") nil t
))
2102 (goto-char (match-beginning 1))
2103 (goto-char (point-max)))
2104 (setq count
(1+ count
))
2105 (if quoted-printable-header-field-end
2108 (mail-unquote-printable-region header-end
(point) nil t t
)
2109 (message "Malformed MIME quoted-printable message"))
2110 ;; Change "quoted-printable" to "8bit",
2111 ;; to reflect the decoding we just did.
2112 (goto-char quoted-printable-header-field-end
)
2113 (delete-region (point) (search-backward ":"))
2115 (if base64-header-field-end
2120 (base64-decode-region
2123 ;; Prevent base64-decode-region
2124 ;; from removing newline characters.
2125 (skip-chars-backward "\n\t ")
2129 ;; Change "base64" to "8bit", to reflect the
2130 ;; decoding we just did.
2131 (goto-char base64-header-field-end
)
2132 (delete-region (point) (search-backward ":"))
2133 (insert ": 8bit")))))
2137 (narrow-to-region start
(point))
2138 (goto-char (point-min))
2139 (while (search-forward "\n\^_" nil t
); single char
2140 (replace-match "\n^_")))); 2 chars: "^" and "_"
2141 ;; This is for malformed messages that don't end in newline.
2142 ;; There shouldn't be any, but some users say occasionally
2144 (or (bolp) (newline))
2146 (setq last-coding-system-used nil
)
2147 (or rmail-enable-mime
2148 (not rmail-enable-multibyte
)
2150 (if (and rmail-decode-mime-charset
2153 (search-forward "\n\n" nil t
)
2154 (let ((case-fold-search t
))
2156 rmail-mime-charset-pattern
2158 (intern (downcase (match-string 1))))))
2159 (rmail-decode-region start
(point) mime-charset
)))
2163 (insert "X-Coding-System: "
2164 (symbol-name last-coding-system-used
)
2166 (narrow-to-region (point) (point-max))
2167 (and (= 0 (% count
10))
2168 (message "Converting to Babyl format...%d" count
)))
2170 ;; This kludge is because some versions of sendmail.el
2171 ;; insert an extra newline at the beginning that shouldn't
2172 ;; be there. sendmail.el has been fixed, but old versions
2173 ;; may still be in use. -- rms, 7 May 1993.
2174 ((eolp) (delete-char 1))
2175 (t (error "Cannot convert to babyl format")))))
2178 ;; Delete the "From ..." line, creating various other headers with
2179 ;; information from it if they don't already exist. Now puts the
2180 ;; original line into a mail-from: header line for debugging and for
2181 ;; use by the rmail-output function.
2182 (defun rmail-nuke-pinhead-header ()
2185 (let ((start (point))
2188 (search-forward "\n\n")
2190 (goto-char (point-max))
2194 (narrow-to-region start end
)
2195 (let ((case-fold-search t
))
2197 (setq has-from
(search-forward "\nFrom:" nil t
))
2199 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
2201 (let ((case-fold-search nil
))
2202 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
2206 ;; Keep and reformat the date if we don't
2207 ;; have a Date: field.
2211 "Date: \\2, \\4 \\3 \\9 \\5 "
2213 ;; The timezone could be matched by group 7 or group 10.
2214 ;; If neither of them matched, assume EST, since only
2215 ;; Easterners would be so sloppy.
2216 ;; It's a shame the substitution can't use "\\10".
2218 ((/= (match-beginning 7) (match-end 7)) "\\7")
2219 ((/= (match-beginning 10) (match-end 10))
2220 (buffer-substring (match-beginning 10)
2224 ;; Keep and reformat the sender if we don't
2225 ;; have a From: field.
2231 ;;;; *** Rmail Message Formatting and Header Manipulation ***
2233 (defun rmail-reformat-message (beg end
)
2236 (if (/= (following-char) ?
0)
2237 (error "Bad format in RMAIL file"))
2238 (let ((inhibit-read-only t
)
2239 (delta (- (buffer-size) end
)))
2243 (let ((case-fold-search t
))
2244 (while (looking-at "Summary-line:\\|Mail-From:")
2246 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
2247 (delete-region (point)
2248 (progn (forward-line 1) (point))))
2249 (let ((str (buffer-substring (point)
2250 (save-excursion (search-forward "\n\n" end
'move
)
2252 (insert str
"*** EOOH ***\n")
2253 (narrow-to-region (point) (- (buffer-size) delta
)))
2254 (goto-char (point-min))
2255 (if rmail-message-filter
(funcall rmail-message-filter
))
2256 (if (or rmail-displayed-headers rmail-ignored-headers
)
2257 (rmail-clear-headers))))
2259 (defun rmail-clear-headers (&optional ignored-headers
)
2260 "Delete all header fields that Rmail should not show.
2261 If the optional argument IGNORED-HEADERS is non-nil,
2262 delete all header fields whose names match that regexp.
2263 Otherwise, if `rmail-displayed-headers' is non-nil,
2264 delete all header fields *except* those whose names match that regexp.
2265 Otherwise, delete all header fields whose names match `rmail-ignored-headers'
2266 unless they also match `rmail-nonignored-headers'."
2267 (when (search-forward "\n\n" nil t
)
2269 (let ((case-fold-search t
)
2270 (buffer-read-only nil
))
2271 (if (and rmail-displayed-headers
(null ignored-headers
))
2273 (narrow-to-region (point-min) (point))
2275 (goto-char (point-min))
2276 (while (and (not (eobp))
2278 (if (re-search-forward "\n[^ \t]" nil t
)
2279 (setq lim
(match-beginning 0)
2281 (setq lim nil next
(point-max)))))
2283 (re-search-forward rmail-displayed-headers lim t
))
2285 (delete-region (point) next
))))
2286 (goto-char (point-min)))
2287 (or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
2289 (narrow-to-region (point-min) (point))
2290 (goto-char (point-min))
2291 (while (and ignored-headers
2292 (re-search-forward ignored-headers nil t
))
2294 (if (looking-at rmail-nonignored-headers
)
2296 (delete-region (point)
2298 (if (re-search-forward "\n[^ \t]" nil t
)
2300 (point-max)))))))))))
2302 (defun rmail-msg-is-pruned ()
2303 (rmail-maybe-set-message-counters)
2305 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2307 (goto-char (point-min))
2309 (= (following-char) ?
1))))
2311 (defun rmail-msg-restore-non-pruned-header ()
2312 (let ((old-point (point))
2315 (inhibit-read-only t
))
2317 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2318 (goto-char (point-min))
2323 ;; Insert new EOOH line at the proper place.
2325 (let ((case-fold-search t
))
2326 (while (looking-at "Summary-Line:\\|Mail-From:")
2328 (insert "*** EOOH ***\n")
2329 (setq new-start
(point))
2330 ;; Delete the old reformatted header.
2332 (search-forward "\n*** EOOH ***\n")
2334 (let ((start (point)))
2335 (search-forward "\n\n")
2336 (if (and (<= start old-point
)
2337 (<= old-point
(point)))
2338 (setq new-point new-start
))
2339 (delete-region start
(point)))
2340 ;; Narrow to after the new EOOH line.
2341 (narrow-to-region new-start
(point-max)))
2343 (goto-char new-point
))))
2345 (defun rmail-msg-prune-header ()
2347 (= (point) (point-min))))
2349 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2350 (rmail-reformat-message (point-min) (point-max)))
2352 (goto-char (point-min)))))
2354 (defun rmail-toggle-header (&optional arg
)
2355 "Show original message header if pruned header currently shown, or vice versa.
2356 With argument ARG, show the message header pruned if ARG is greater than zero;
2357 otherwise, show it in full."
2359 (let* ((pruned (with-current-buffer rmail-buffer
2360 (rmail-msg-is-pruned)))
2362 (> (prefix-numeric-value arg
) 0)
2364 (if (eq pruned prune
)
2366 (set-buffer rmail-buffer
)
2367 (rmail-maybe-set-message-counters)
2368 (if rmail-enable-mime
2369 (let ((buffer-read-only nil
))
2371 (rmail-msg-restore-non-pruned-header)
2372 (rmail-msg-prune-header))
2373 (funcall rmail-show-mime-function
))
2374 (let* ((buffer-read-only nil
)
2375 (window (get-buffer-window (current-buffer)))
2376 (at-point-min (= (point) (point-min)))
2377 (all-headers-visible (= (window-start window
) (point-min)))
2380 (and (not (search-backward "\n\n" nil t
))
2383 (re-search-backward "^[-A-Za-z0-9]+:" nil t
))
2386 (rmail-count-screen-lines (window-start window
) (point))))
2388 (rmail-msg-restore-non-pruned-header)
2389 (rmail-msg-prune-header))
2391 (goto-char (point-min)))
2393 (goto-char (point-min))
2394 (search-forward "\n\n")
2395 (or (re-search-backward
2396 (concat "^" (regexp-quote on-header
)) nil t
)
2397 (goto-char (point-min))))
2399 (save-selected-window
2400 (select-window window
)
2401 (recenter old-screen-line
)
2402 (if (and all-headers-visible
2403 (not (= (window-start) (point-min))))
2404 (recenter (- (window-height) 2))))))))
2405 (rmail-highlight-headers))))
2407 (defun rmail-narrow-to-non-pruned-header ()
2408 "Narrow to the whole (original) header of the current message."
2410 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2411 (goto-char (point-min))
2413 (if (= (following-char) ?
1)
2416 (setq start
(point))
2417 (search-forward "*** EOOH ***\n")
2418 (setq end
(match-beginning 0)))
2420 (setq start
(point))
2421 (search-forward "\n\n")
2422 (setq end
(1- (point))))
2423 (narrow-to-region start end
)
2426 ;; Lifted from repos-count-screen-lines.
2427 ;; Return number of screen lines between START and END.
2428 (defun rmail-count-screen-lines (start end
)
2431 (narrow-to-region start end
)
2432 (goto-char (point-min))
2433 (vertical-motion (- (point-max) (point-min))))))
2435 ;;;; *** Rmail Attributes and Keywords ***
2437 ;; Make a string describing current message's attributes and keywords
2438 ;; and set it up as the name of a minor mode
2439 ;; so it will appear in the mode line.
2440 (defun rmail-display-labels ()
2441 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
2446 (goto-char (rmail-msgbeg rmail-current-message
))
2448 (if (looking-at "[01],")
2450 (narrow-to-region (point) (progn (end-of-line) (point)))
2451 ;; Truly valid BABYL format requires a space before each
2452 ;; attribute or keyword name. Put them in if missing.
2453 (let (buffer-read-only)
2454 (goto-char (point-min))
2455 (while (search-forward "," nil t
)
2456 (or (looking-at "[ ,]") (eobp)
2458 (goto-char (point-max))
2459 (if (search-backward ",," nil
'move
)
2461 (if (> (point) (1+ (point-min)))
2462 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
2463 (if (> (- (point-max) (point)) 2)
2467 (buffer-substring (+ (point) 3)
2468 (1- (point-max)))))))))))
2469 ;; Note: we don't use save-restriction because that does not work right
2470 ;; if changes are made outside the saved restriction
2471 ;; before that restriction is restored.
2472 (narrow-to-region beg end
)
2473 (set-marker beg nil
)
2474 (set-marker end nil
)))
2475 (while (string-match " +," blurb
)
2476 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2477 (substring blurb
(match-end 0)))))
2478 (while (string-match ", +" blurb
)
2479 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2480 (substring blurb
(match-end 0)))))
2481 (setq mode-line-process
2483 rmail-current-message rmail-total-messages blurb
))
2484 ;; If rmail-enable-mime is non-nil, we may have to update
2485 ;; `mode-line-process' of rmail-view-buffer too.
2486 (if (and rmail-enable-mime
2487 (not (eq (current-buffer) rmail-view-buffer
))
2488 (buffer-live-p rmail-view-buffer
))
2489 (let ((mlp mode-line-process
))
2490 (with-current-buffer rmail-view-buffer
2491 (setq mode-line-process mlp
))))))
2493 ;; Turn an attribute of a message on or off according to STATE.
2494 ;; ATTR is the name of the attribute, as a string.
2495 ;; MSGNUM is message number to change; nil means current message.
2496 (defun rmail-set-attribute (attr state
&optional msgnum
)
2497 (set-buffer rmail-buffer
)
2498 (let ((omax (point-max-marker))
2499 (omin (point-min-marker))
2500 (buffer-read-only nil
))
2501 (or msgnum
(setq msgnum rmail-current-message
))
2506 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
2509 (null (search-backward (concat ", " attr
",")
2510 (prog1 (point) (end-of-line)) t
)))))
2511 (or (eq curstate
(not (not state
)))
2513 (delete-region (point) (1- (match-end 0)))
2516 (insert " " attr
","))))
2517 (if (string= attr
"deleted")
2518 (rmail-set-message-deleted-p msgnum state
)))
2519 ;; Note: we don't use save-restriction because that does not work right
2520 ;; if changes are made outside the saved restriction
2521 ;; before that restriction is restored.
2522 (narrow-to-region omin omax
)
2523 (set-marker omin nil
)
2524 (set-marker omax nil
)
2525 (if (= msgnum rmail-current-message
)
2526 (rmail-display-labels))))))
2528 ;; Return t if the attributes/keywords line of msg number MSG
2529 ;; contains a match for the regexp LABELS.
2530 (defun rmail-message-labels-p (msg labels
)
2534 (goto-char (rmail-msgbeg msg
))
2536 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
2538 ;;;; *** Rmail Message Selection And Support ***
2540 (defun rmail-msgend (n)
2541 (marker-position (aref rmail-message-vector
(1+ n
))))
2543 (defun rmail-msgbeg (n)
2544 (marker-position (aref rmail-message-vector n
)))
2546 (defun rmail-widen-to-current-msgbeg (function)
2547 "Call FUNCTION with point at start of internal data of current message.
2548 Assumes that bounds were previously narrowed to display the message in Rmail.
2549 The bounds are widened enough to move point where desired, then narrowed
2552 FUNCTION may not change the visible text of the message, but it may
2553 change the invisible header text."
2557 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2559 (goto-char (point-min))
2561 ;; Note: we don't use save-restriction because that does not work right
2562 ;; if changes are made outside the saved restriction
2563 ;; before that restriction is restored.
2564 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2565 (rmail-msgend rmail-current-message
)))))
2567 (defun rmail-forget-messages ()
2569 (if (vectorp rmail-message-vector
)
2571 (v rmail-message-vector
)
2574 (move-marker (aref v i
) nil
)
2576 (setq rmail-message-vector nil
)
2577 (setq rmail-msgref-vector nil
)
2578 (setq rmail-deleted-vector nil
)))
2580 (defun rmail-maybe-set-message-counters ()
2581 (if (not (and rmail-deleted-vector
2582 rmail-message-vector
2583 rmail-current-message
2584 rmail-total-messages
))
2585 (rmail-set-message-counters)))
2587 (defun rmail-count-new-messages (&optional nomsg
)
2588 (let* ((case-fold-search nil
)
2592 (or nomsg
(message "Counting new messages..."))
2593 (goto-char (point-max))
2594 ;; Put at the end of messages-head
2595 ;; the entry for message N+1, which marks
2596 ;; the end of message N. (N = number of messages).
2597 (search-backward "\n\^_")
2599 (setq messages-head
(list (point-marker)))
2600 (rmail-set-message-counters-counter (point-min))
2601 (setq rmail-current-message
(1+ rmail-total-messages
))
2602 (setq rmail-total-messages
2603 (+ rmail-total-messages total-messages
))
2604 (setq rmail-message-vector
2605 (vconcat rmail-message-vector
(cdr messages-head
)))
2606 (aset rmail-message-vector
2607 rmail-current-message
(car messages-head
))
2608 (setq rmail-deleted-vector
2609 (concat rmail-deleted-vector deleted-head
))
2610 (setq rmail-summary-vector
2611 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
2612 (setq rmail-msgref-vector
2613 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
2614 ;; Fill in the new elements of rmail-msgref-vector.
2615 (let ((i (1+ (- rmail-total-messages total-messages
))))
2616 (while (<= i rmail-total-messages
)
2617 (aset rmail-msgref-vector i
(list i
))
2619 (goto-char (point-min))
2620 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
2622 (defun rmail-set-message-counters ()
2623 (rmail-forget-messages)
2627 (let* ((point-save (point))
2629 (messages-after-point)
2630 (case-fold-search nil
)
2633 (message "Counting messages...")
2634 (goto-char (point-max))
2635 ;; Put at the end of messages-head
2636 ;; the entry for message N+1, which marks
2637 ;; the end of message N. (N = number of messages).
2638 (search-backward "\n\^_" nil t
)
2639 (if (/= (point) (point-max)) (forward-char 1))
2640 (setq messages-head
(list (point-marker)))
2641 (rmail-set-message-counters-counter (min (point) point-save
))
2642 (setq messages-after-point total-messages
)
2643 (rmail-set-message-counters-counter)
2644 (setq rmail-total-messages total-messages
)
2645 (setq rmail-current-message
2647 (max 1 (- total-messages messages-after-point
))))
2648 (setq rmail-message-vector
2649 (apply 'vector
(cons (point-min-marker) messages-head
))
2650 rmail-deleted-vector
(concat "0" deleted-head
)
2651 rmail-summary-vector
(make-vector rmail-total-messages nil
)
2652 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
2654 (while (<= i rmail-total-messages
)
2655 (aset rmail-msgref-vector i
(list i
))
2657 (message "Counting messages...done")))))
2659 (defun rmail-set-message-counters-counter (&optional stop
)
2660 (let ((start (point))
2662 (while (search-backward "\n\^_\^L" stop t
)
2663 ;; Detect messages that have been added with DOS line endings and
2664 ;; convert the line endings for such messages.
2666 (if (looking-at "\n\^_\^L\r\n")
2667 (let ((buffer-read-only nil
)
2669 (message "Counting messages...(converting line endings)")
2672 (while (search-backward "\r\n" next t
)
2676 (setq messages-head
(cons (point-marker) messages-head
))
2679 (cons (if (search-backward ", deleted,"
2685 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
2686 (message "Counting messages...%d" total-messages
)))))
2688 (defun rmail-beginning-of-message ()
2689 "Show current message starting from the beginning."
2691 (let ((rmail-show-message-hook
2692 (list (function (lambda ()
2693 (goto-char (point-min)))))))
2694 (rmail-show-message rmail-current-message
)))
2696 (defun rmail-end-of-message ()
2697 "Show bottom of current message."
2699 (let ((rmail-show-message-hook
2700 (list (function (lambda ()
2701 (goto-char (point-max))
2702 (recenter (1- (window-height))))))))
2703 (rmail-show-message rmail-current-message
)))
2705 (defun rmail-unknown-mail-followup-to ()
2706 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2707 Ask the user whether to add that list name to `mail-mailing-lists'."
2709 (rmail-narrow-to-non-pruned-header)
2710 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t
)))
2711 (when mail-followup-to
2714 (mail-strip-quoted-names mail-followup-to
)
2715 ",[[:space:]]+" t
)))
2716 (dolist (addr addresses
)
2717 (when (and (not (member addr mail-mailing-lists
))
2719 ;; taken from rmailsum.el
2721 (or rmail-user-mail-address-regexp
2723 (regexp-quote (user-login-name))
2726 (or user-mail-address
2727 (concat (user-login-name) "@"
2728 (or mail-host-address
2733 (format "Add `%s' to `mail-mailing-lists'? "
2735 (customize-save-variable 'mail-mailing-lists
2736 (cons addr mail-mailing-lists
)))))))))
2738 (defun rmail-show-message (&optional n no-summary
)
2739 "Show message number N (prefix argument), counting from start of file.
2740 If summary buffer is currently displayed, update current message there also."
2742 (or (eq major-mode
'rmail-mode
)
2743 (switch-to-buffer rmail-buffer
))
2744 (rmail-maybe-set-message-counters)
2746 (if (zerop rmail-total-messages
)
2747 (progn (narrow-to-region (point-min) (1- (point-max)))
2748 (goto-char (point-min))
2749 (setq mode-line-process nil
))
2750 (let (blurb coding-system
)
2752 (setq n rmail-current-message
)
2755 rmail-current-message
1
2756 blurb
"No previous message"))
2757 ((> n rmail-total-messages
)
2758 (setq n rmail-total-messages
2759 rmail-current-message rmail-total-messages
2760 blurb
"No following message"))
2762 (setq rmail-current-message n
))))
2763 (let ((beg (rmail-msgbeg n
)))
2767 (let ((end (rmail-msgend n
)))
2769 (if (prog1 (= (following-char) ?
0)
2771 ;; If there's a Summary-line in the (otherwise empty)
2772 ;; header, we didn't yet get past the EOOH line.
2773 (if (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
2775 (narrow-to-region (point) end
))
2777 (search-forward "\n*** EOOH ***\n" end t
))
2778 (narrow-to-region beg
(point))
2779 (goto-char (point-min))
2780 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2781 (let ((coding-system (intern (match-string 1))))
2784 (check-coding-system coding-system
)
2785 (setq buffer-file-coding-system coding-system
))
2787 (setq buffer-file-coding-system nil
))))
2788 (setq buffer-file-coding-system nil
)))))
2789 ;; Clear the "unseen" attribute when we show a message.
2790 (rmail-set-attribute "unseen" nil
)
2791 (let ((end (rmail-msgend n
)))
2792 ;; Reformat the header, or else find the reformatted header.
2793 (if (= (following-char) ?
0)
2794 (rmail-reformat-message beg end
)
2795 (search-forward "\n*** EOOH ***\n" end t
)
2796 (narrow-to-region (point) end
)))
2797 (goto-char (point-min))
2799 (function (lambda (window)
2800 (if (eq (window-buffer window
) (current-buffer))
2801 (set-window-point window
(point)))))
2803 (rmail-display-labels)
2804 (if (eq rmail-enable-mime t
)
2805 (funcall rmail-show-mime-function
)
2806 (setq rmail-view-buffer rmail-buffer
))
2807 (when mail-mailing-lists
2808 (rmail-unknown-mail-followup-to))
2809 (rmail-highlight-headers)
2810 (if transient-mark-mode
(deactivate-mark))
2811 (run-hooks 'rmail-show-message-hook
)
2812 ;; If there is a summary buffer, try to move to this message
2813 ;; in that buffer. But don't complain if this message
2814 ;; is not mentioned in the summary.
2815 ;; Don't do this at all if we were called on behalf
2816 ;; of cursor motion in the summary buffer.
2817 (and (rmail-summary-exists) (not no-summary
)
2818 (let ((curr-msg rmail-current-message
))
2819 (rmail-select-summary
2820 (rmail-summary-goto-msg curr-msg t t
))))
2821 (with-current-buffer rmail-buffer
2824 (message blurb
))))))
2826 (defun rmail-redecode-body (coding)
2827 "Decode the body of the current message using coding system CODING.
2828 This is useful with mail messages that have malformed or missing
2831 This function assumes that the current message is already decoded
2832 and displayed in the RMAIL buffer, but the coding system used to
2833 decode it was incorrect. It then encodes the message back to its
2834 original form, and decodes it again, using the coding system CODING.
2836 Note that if Emacs erroneously auto-detected one of the iso-2022
2837 encodings in the message, this function might fail because the escape
2838 sequences that switch between character sets and also single-shift and
2839 locking-shift codes are impossible to recover. This function is meant
2840 to be used to fix messages encoded with 8-bit encodings, such as
2841 iso-8859, koi8-r, etc."
2842 (interactive "zCoding system for re-decoding this message: ")
2843 (when (not rmail-enable-mime
)
2844 (or (eq major-mode
'rmail-mode
)
2845 (switch-to-buffer rmail-buffer
))
2847 (let ((pruned (rmail-msg-is-pruned)))
2849 (let ((msgbeg (rmail-msgbeg rmail-current-message
))
2850 (msgend (rmail-msgend rmail-current-message
))
2852 ;; We need the message headers pruned (we later restore
2853 ;; the pruned stat to what it was, see the end of
2854 ;; unwind-protect form).
2856 (rmail-toggle-header 1))
2857 (narrow-to-region msgbeg msgend
)
2858 (goto-char (point-min))
2859 (when (search-forward "\n*** EOOH ***\n" (point-max) t
)
2860 (narrow-to-region msgbeg
(point)))
2861 (goto-char (point-min))
2862 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2863 (let ((old-coding (intern (match-string 1)))
2864 (buffer-read-only nil
))
2865 (check-coding-system old-coding
)
2866 ;; Make sure the new coding system uses the same EOL
2867 ;; conversion, to prevent ^M characters from popping
2868 ;; up all over the place.
2870 (coding-system-change-eol-conversion
2872 (coding-system-eol-type old-coding
)))
2873 (setq x-coding-header
(point-marker))
2874 (narrow-to-region msgbeg msgend
)
2875 (encode-coding-region (point) msgend old-coding
)
2876 (decode-coding-region (point) msgend coding
)
2877 (setq last-coding-system-used coding
)
2878 ;; Rewrite the coding-system header according
2880 (goto-char x-coding-header
)
2881 (delete-region (point)
2885 (insert "X-Coding-System: "
2886 (symbol-name last-coding-system-used
))
2887 (set-marker x-coding-header nil
)
2888 (rmail-show-message))
2889 (error "No X-Coding-System header found")))
2891 (rmail-toggle-header 0)))))))
2893 ;; Find all occurrences of certain fields, and highlight them.
2894 (defun rmail-highlight-headers ()
2895 ;; Do this only if the system supports faces.
2896 (if (and (fboundp 'internal-find-face
)
2897 rmail-highlighted-headers
)
2899 (search-forward "\n\n" nil
'move
)
2901 (narrow-to-region (point-min) (point))
2902 (let ((case-fold-search t
)
2903 (inhibit-read-only t
)
2904 ;; Highlight with boldface if that is available.
2905 ;; Otherwise use the `highlight' face.
2906 (face (or rmail-highlight-face
2907 (if (face-differs-from-default-p 'bold
)
2909 ;; List of overlays to reuse.
2910 (overlays rmail-overlay-list
))
2911 (goto-char (point-min))
2912 (while (re-search-forward rmail-highlighted-headers nil t
)
2913 (skip-chars-forward " \t")
2916 (while (progn (forward-line 1)
2917 (looking-at "[ \t]")))
2918 ;; Back up over newline, then trailing spaces or tabs
2920 (while (member (preceding-char) '(? ?
\t))
2923 ;; Reuse an overlay we already have.
2925 (setq overlay
(car overlays
)
2926 overlays
(cdr overlays
))
2927 (overlay-put overlay
'face face
)
2928 (move-overlay overlay beg
(point)))
2929 ;; Make a new overlay and add it to
2930 ;; rmail-overlay-list.
2931 (setq overlay
(make-overlay beg
(point)))
2932 (overlay-put overlay
'face face
)
2933 (setq rmail-overlay-list
2934 (cons overlay rmail-overlay-list
))))))))))
2936 (defun rmail-auto-file ()
2937 "Automatically move a message into a sub-folder based on criteria.
2938 Called when a new message is displayed."
2939 (if (or (rmail-message-labels-p rmail-current-message
"filed")
2940 (not (string= (buffer-file-name)
2941 (expand-file-name rmail-file-name
))))
2942 ;; Do nothing if it's already been filed.
2944 ;; Find out some basics (common fields)
2945 (let ((from (mail-fetch-field "from"))
2946 (subj (mail-fetch-field "subject"))
2947 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
2948 (d rmail-automatic-folder-directives
)
2949 (directive-loop nil
)
2952 (setq folder
(car (car d
))
2953 directive-loop
(cdr (car d
)))
2954 (while (and (car directive-loop
)
2956 ((string= (car directive-loop
) "from") from
)
2957 ((string= (car directive-loop
) "to") to
)
2958 ((string= (car directive-loop
) "subject") subj
)
2959 (t (mail-fetch-field (car directive-loop
))))))
2960 (and f
(string-match (car (cdr directive-loop
)) f
))))
2961 (setq directive-loop
(cdr (cdr directive-loop
))))
2962 ;; If there are no directives left, then it was a complete match.
2963 (if (null directive-loop
)
2965 (rmail-delete-forward)
2966 (if (string= "/dev/null" folder
)
2967 (rmail-delete-message)
2968 (rmail-output-to-rmail-file folder
1 t
)
2970 (setq d
(cdr d
))))))
2972 (defun rmail-next-message (n)
2973 "Show following message whether deleted or not.
2974 With prefix arg N, moves forward N messages, or backward if N is negative."
2976 (set-buffer rmail-buffer
)
2977 (rmail-maybe-set-message-counters)
2978 (rmail-show-message (+ rmail-current-message n
)))
2980 (defun rmail-previous-message (n)
2981 "Show previous message whether deleted or not.
2982 With prefix arg N, moves backward N messages, or forward if N is negative."
2984 (rmail-next-message (- n
)))
2986 (defun rmail-next-undeleted-message (n)
2987 "Show following non-deleted message.
2988 With prefix arg N, moves forward N non-deleted messages,
2989 or backward if N is negative.
2991 Returns t if a new message is being shown, nil otherwise."
2993 (set-buffer rmail-buffer
)
2994 (rmail-maybe-set-message-counters)
2995 (let ((lastwin rmail-current-message
)
2996 (current rmail-current-message
))
2997 (while (and (> n
0) (< current rmail-total-messages
))
2998 (setq current
(1+ current
))
2999 (if (not (rmail-message-deleted-p current
))
3000 (setq lastwin current n
(1- n
))))
3001 (while (and (< n
0) (> current
1))
3002 (setq current
(1- current
))
3003 (if (not (rmail-message-deleted-p current
))
3004 (setq lastwin current n
(1+ n
))))
3005 (if (/= lastwin rmail-current-message
)
3006 (progn (rmail-show-message lastwin
)
3009 (message "No previous nondeleted message"))
3011 (message "No following nondeleted message"))
3014 (defun rmail-previous-undeleted-message (n)
3015 "Show previous non-deleted message.
3016 With prefix argument N, moves backward N non-deleted messages,
3017 or forward if N is negative."
3019 (rmail-next-undeleted-message (- n
)))
3021 (defun rmail-first-message ()
3022 "Show first message in file."
3024 (rmail-maybe-set-message-counters)
3025 (rmail-show-message 1))
3027 (defun rmail-last-message ()
3028 "Show last message in file."
3030 (rmail-maybe-set-message-counters)
3031 (rmail-show-message rmail-total-messages
))
3033 (defun rmail-what-message ()
3034 (let ((where (point))
3036 (high rmail-total-messages
)
3037 (mid (/ rmail-total-messages
2)))
3038 (while (> (- high low
) 1)
3039 (if (>= where
(rmail-msgbeg mid
))
3042 (setq mid
(+ low
(/ (- high low
) 2))))
3043 (if (>= where
(rmail-msgbeg high
)) high low
)))
3045 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
3047 (goto-char (rmail-msgbeg msg
))
3048 (search-forward "\n*** EOOH ***\n")
3049 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
3050 (or (string-match recipients
(or (mail-fetch-field "To") ""))
3051 (string-match recipients
(or (mail-fetch-field "From") ""))
3052 (if (not primary-only
)
3053 (string-match recipients
(or (mail-fetch-field "Cc") ""))))))
3055 (defun rmail-message-regexp-p (n regexp
)
3056 "Return t, if for message number N, regexp REGEXP matches in the header."
3057 (let ((beg (rmail-msgbeg n
))
3058 (end (rmail-msgend n
)))
3063 (if (prog1 (= (following-char) ?
0)
3065 ;; If there's a Summary-line in the (otherwise empty)
3066 ;; header, we didn't yet get past the EOOH line.
3067 (when (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
3070 (narrow-to-region (point) end
))
3075 (search-forward "\n*** EOOH ***\n" end t
)
3076 (setq end
(1+ (match-beginning 0)))))
3078 (if rmail-enable-mime
3079 (funcall rmail-search-mime-header-function n regexp end
)
3080 (re-search-forward regexp end t
)))))
3082 (defun rmail-search-message (msg regexp
)
3083 "Return non-nil, if for message number MSG, regexp REGEXP matches."
3084 (goto-char (rmail-msgbeg msg
))
3085 (if rmail-enable-mime
3086 (funcall rmail-search-mime-message-function msg regexp
)
3087 (re-search-forward regexp
(rmail-msgend msg
) t
)))
3089 (defvar rmail-search-last-regexp nil
)
3090 (defun rmail-search (regexp &optional n
)
3091 "Show message containing next match for REGEXP (but not the current msg).
3092 Prefix argument gives repeat count; negative argument means search
3093 backwards (through earlier messages).
3094 Interactively, empty argument means use same regexp used last time."
3096 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
3098 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3102 (if rmail-search-last-regexp
3103 (concat ", default "
3104 rmail-search-last-regexp
"): ")
3106 (setq regexp
(read-string prompt
))
3107 (cond ((not (equal regexp
""))
3108 (setq rmail-search-last-regexp regexp
))
3109 ((not rmail-search-last-regexp
)
3110 (error "No previous Rmail search string")))
3111 (list rmail-search-last-regexp
3112 (prefix-numeric-value current-prefix-arg
))))
3114 (message "%sRmail search for %s..."
3115 (if (< n
0) "Reverse " "")
3117 (set-buffer rmail-buffer
)
3118 (rmail-maybe-set-message-counters)
3119 (let ((omin (point-min))
3124 (msg rmail-current-message
))
3129 ;; Check messages one by one, advancing message number up or down
3130 ;; but searching forward through each message.
3132 (while (and (null win
) (> msg
1))
3134 win
(rmail-search-message msg regexp
)))
3135 (while (and (null win
) (< msg rmail-total-messages
))
3137 win
(rmail-search-message msg regexp
))))
3138 (setq n
(+ n
(if reversep
1 -
1)))))
3141 (rmail-show-message msg
)
3142 ;; Search forward (if this is a normal search) or backward
3143 ;; (if this is a reverse search) through this message to
3144 ;; position point. This search may fail because REGEXP
3145 ;; was found in the hidden portion of this message. In
3146 ;; that case, move point to the beginning of visible
3150 (goto-char (point-max))
3151 (re-search-backward regexp nil
'move
))
3152 (goto-char (point-min))
3153 (re-search-forward regexp nil t
))
3154 (message "%sRmail search for %s...done"
3155 (if reversep
"Reverse " "")
3158 (narrow-to-region omin omax
)
3160 (message "Search failed: %s" regexp
)))))
3162 (defun rmail-search-backwards (regexp &optional n
)
3163 "Show message containing previous match for REGEXP.
3164 Prefix argument gives repeat count; negative argument means search
3165 forward (through later messages).
3166 Interactively, empty argument means use same regexp used last time."
3168 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
3170 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3174 (if rmail-search-last-regexp
3175 (concat ", default "
3176 rmail-search-last-regexp
"): ")
3178 (setq regexp
(read-string prompt
))
3179 (cond ((not (equal regexp
""))
3180 (setq rmail-search-last-regexp regexp
))
3181 ((not rmail-search-last-regexp
)
3182 (error "No previous Rmail search string")))
3183 (list rmail-search-last-regexp
3184 (prefix-numeric-value current-prefix-arg
))))
3185 (rmail-search regexp
(- (or n
1))))
3187 ;; Show the first message which has the `unseen' attribute.
3188 (defun rmail-first-unseen-message ()
3189 (rmail-maybe-set-message-counters)
3194 (while (and (not found
) (<= current rmail-total-messages
))
3195 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
3196 (setq found current
))
3197 (setq current
(1+ current
))))
3198 ;; Let the caller show the message.
3200 ;; (rmail-show-message found))
3203 (defun rmail-current-subject ()
3204 "Return the current subject.
3205 The subject is stripped of leading and trailing whitespace, and
3206 of typical reply prefixes such as Re:."
3207 (let ((subject (or (mail-fetch-field "Subject") "")))
3208 (if (string-match "\\`[ \t]+" subject
)
3209 (setq subject
(substring subject
(match-end 0))))
3210 (if (string-match rmail-reply-regexp subject
)
3211 (setq subject
(substring subject
(match-end 0))))
3212 (if (string-match "[ \t]+\\'" subject
)
3213 (setq subject
(substring subject
0 (match-beginning 0))))
3216 (defun rmail-current-subject-regexp ()
3217 "Return a regular expression matching the current subject.
3218 The regular expression matches the subject header line of
3219 messages about the same subject. The subject itself is stripped
3220 of leading and trailing whitespace, of typical reply prefixes
3221 such as Re: and whitespace within the subject is replaced by a
3222 regular expression matching whitespace in general in order to
3223 take into account that subject header lines may include newlines
3224 and more whitespace. The returned regular expressions contains
3225 `rmail-reply-regexp' and ends with a newline."
3226 (let ((subject (rmail-current-subject)))
3227 ;; If Subject is long, mailers will break it into several lines at
3228 ;; arbitrary places, so replace whitespace with a regexp that will
3229 ;; match any sequence of spaces, TABs, and newlines.
3230 (setq subject
(regexp-quote subject
))
3232 (replace-regexp-in-string "[ \t\n]+" "[ \t\n]+" subject t t
))
3233 (concat "^Subject: "
3234 (if (string= "\\`" (substring rmail-reply-regexp
0 2))
3235 (substring rmail-reply-regexp
2)
3237 subject
"[ \t]*\n")))
3239 (defun rmail-next-same-subject (n)
3240 "Go to the next mail message having the same subject header.
3241 With prefix argument N, do this N times.
3242 If N is negative, go backwards instead."
3244 (let ((search-regexp (rmail-current-subject-regexp))
3246 (i rmail-current-message
)
3247 (case-fold-search t
)
3252 (while (and (/= n
0)
3254 (< i rmail-total-messages
)
3257 (while (and (not done
)
3259 (< i rmail-total-messages
)
3261 (setq i
(if forward
(1+ i
) (1- i
)))
3262 (goto-char (rmail-msgbeg i
))
3263 (search-forward "\n*** EOOH ***\n")
3264 (let ((beg (point)) end
)
3265 (search-forward "\n\n")
3268 (setq done
(re-search-forward search-regexp end t
))))
3269 (if done
(setq found i
)))
3270 (setq n
(if forward
(1- n
) (1+ n
))))))
3272 (rmail-show-message found
)
3273 (error "No %s message with same subject"
3274 (if forward
"following" "previous")))))
3276 (defun rmail-previous-same-subject (n)
3277 "Go to the previous mail message having the same subject header.
3278 With prefix argument N, do this N times.
3279 If N is negative, go forwards instead."
3281 (rmail-next-same-subject (- n
)))
3283 ;;;; *** Rmail Message Deletion Commands ***
3285 (defun rmail-message-deleted-p (n)
3286 (= (aref rmail-deleted-vector n
) ?D
))
3288 (defun rmail-set-message-deleted-p (n state
)
3289 (aset rmail-deleted-vector n
(if state ?D ?\
)))
3291 (defun rmail-delete-message ()
3292 "Delete this message and stay on it."
3294 (rmail-set-attribute "deleted" t
)
3295 (run-hooks 'rmail-delete-message-hook
))
3297 (defun rmail-undelete-previous-message ()
3298 "Back up to deleted message, select it, and undelete it."
3300 (set-buffer rmail-buffer
)
3301 (let ((msg rmail-current-message
))
3302 (while (and (> msg
0)
3303 (not (rmail-message-deleted-p msg
)))
3304 (setq msg
(1- msg
)))
3306 (error "No previous deleted message")
3307 (if (/= msg rmail-current-message
)
3308 (rmail-show-message msg
))
3309 (rmail-set-attribute "deleted" nil
)
3310 (if (rmail-summary-exists)
3312 (set-buffer rmail-summary-buffer
)
3313 (rmail-summary-mark-undeleted msg
)))
3314 (rmail-maybe-display-summary))))
3316 (defun rmail-delete-forward (&optional backward
)
3317 "Delete this message and move to next nondeleted one.
3318 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
3319 With prefix argument, delete and move backward.
3321 Returns t if a new message is displayed after the delete, or nil otherwise."
3323 (rmail-set-attribute "deleted" t
)
3324 (run-hooks 'rmail-delete-message-hook
)
3325 (let ((del-msg rmail-current-message
))
3326 (if (rmail-summary-exists)
3327 (rmail-select-summary
3328 (rmail-summary-mark-deleted del-msg
)))
3329 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
3330 (rmail-maybe-display-summary))))
3332 (defun rmail-delete-backward ()
3333 "Delete this message and move to previous nondeleted one.
3334 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
3336 (rmail-delete-forward t
))
3338 ;; Compute the message number a given message would have after expunging.
3339 ;; The present number of the message is OLDNUM.
3340 ;; DELETEDVEC should be rmail-deleted-vector.
3341 ;; The value is nil for a message that would be deleted.
3342 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
3343 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
3348 (if (/= (aref deletedvec i
) ?D
)
3349 (setq newnum
(1+ newnum
)))
3353 (defun rmail-expunge-confirmed ()
3354 "Return t if deleted message should be expunged. If necessary, ask the user.
3355 See also user-option `rmail-confirm-expunge'."
3356 (set-buffer rmail-buffer
)
3357 (or (not (stringp rmail-deleted-vector
))
3358 (not (string-match "D" rmail-deleted-vector
))
3359 (null rmail-confirm-expunge
)
3360 (funcall rmail-confirm-expunge
3361 "Erase deleted messages from Rmail file? ")))
3363 (defun rmail-only-expunge (&optional dont-show
)
3364 "Actually erase all deleted messages in the file."
3366 (set-buffer rmail-buffer
)
3367 (message "Expunging deleted messages...")
3368 ;; Discard all undo records for this buffer.
3369 (or (eq buffer-undo-list t
)
3370 (setq buffer-undo-list nil
))
3371 (rmail-maybe-set-message-counters)
3372 (let* ((omax (- (buffer-size) (point-max)))
3373 (omin (- (buffer-size) (point-min)))
3374 (opoint (if (and (> rmail-current-message
0)
3375 (rmail-message-deleted-p rmail-current-message
))
3377 (if rmail-enable-mime
3378 (with-current-buffer rmail-view-buffer
3379 (- (point)(point-min)))
3380 (- (point) (point-min)))))
3381 (messages-head (cons (aref rmail-message-vector
0) nil
))
3382 (messages-tail messages-head
)
3383 ;; Don't make any undo records for the expunging.
3384 (buffer-undo-list t
)
3389 (goto-char (point-min))
3392 (total rmail-total-messages
)
3393 (new-message-number rmail-current-message
)
3395 (new-msgref (list (list 0)))
3396 (rmailbuf (current-buffer))
3397 (buffer-read-only nil
)
3398 (messages rmail-message-vector
)
3399 (deleted rmail-deleted-vector
)
3400 (summary rmail-summary-vector
))
3401 (setq rmail-total-messages nil
3402 rmail-current-message nil
3403 rmail-message-vector nil
3404 rmail-deleted-vector nil
3405 rmail-summary-vector nil
)
3407 (while (<= number total
)
3408 (if (= (aref deleted number
) ?D
)
3411 (marker-position (aref messages number
))
3412 (marker-position (aref messages
(1+ number
))))
3413 (move-marker (aref messages number
) nil
)
3414 (if (> new-message-number counter
)
3415 (setq new-message-number
(1- new-message-number
))))
3416 (setq counter
(1+ counter
))
3418 (setcdr messages-tail
3419 (cons (aref messages number
) nil
)))
3421 (cons (if (= counter number
) (aref summary
(1- number
)))
3424 (cons (aref rmail-msgref-vector number
)
3426 (setcar (car new-msgref
) counter
))
3427 (if (zerop (%
(setq number
(1+ number
)) 20))
3428 (message "Expunging deleted messages...%d" number
)))
3430 (setcdr messages-tail
3431 (cons (aref messages number
) nil
)))
3432 (setq rmail-current-message new-message-number
3433 rmail-total-messages counter
3434 rmail-message-vector
(apply 'vector messages-head
)
3435 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
3436 rmail-summary-vector
(vconcat (nreverse new-summary
))
3437 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
3439 (message "Expunging deleted messages...done")
3441 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
3444 (if (zerop rmail-current-message
) 1 nil
)))
3445 (if rmail-enable-mime
3446 (goto-char (+ (point-min) opoint
))
3447 (goto-char (+ (point) opoint
))))))
3449 (defun rmail-expunge ()
3450 "Erase deleted messages from Rmail file and summary buffer."
3452 (when (rmail-expunge-confirmed)
3453 (rmail-only-expunge)
3454 (if (rmail-summary-exists)
3455 (rmail-select-summary (rmail-update-summary)))))
3457 ;;;; *** Rmail Mailing Commands ***
3459 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
3460 replybuffer sendactions same-window others
)
3463 (setq yank-action
(list 'insert-buffer replybuffer
)))
3464 (setq others
(cons (cons "cc" cc
) others
))
3465 (setq others
(cons (cons "in-reply-to" in-reply-to
) others
))
3467 (compose-mail to subject others
3469 yank-action sendactions
)
3470 (if rmail-mail-new-frame
3472 (compose-mail to subject others
3473 noerase
'switch-to-buffer-other-frame
3474 yank-action sendactions
)
3475 ;; This is not a standard frame parameter;
3476 ;; nothing except sendmail.el looks at it.
3477 (modify-frame-parameters (selected-frame)
3478 '((mail-dedicated-frame . t
))))
3479 (compose-mail to subject others
3480 noerase
'switch-to-buffer-other-window
3481 yank-action sendactions
)))))
3483 (defun rmail-mail ()
3484 "Send mail in another window.
3485 While composing the message, use \\[mail-yank-original] to yank the
3486 original message into it."
3488 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
3490 (defun rmail-continue ()
3491 "Continue composing outgoing message previously being composed."
3493 (rmail-start-mail t
))
3495 (defun rmail-reply (just-sender)
3496 "Reply to the current message.
3497 Normally include CC: to all other recipients of original message;
3498 prefix argument means ignore them. While composing the reply,
3499 use \\[mail-yank-original] to yank the original message into it."
3501 (let (from reply-to cc subject date to message-id references
3502 resent-to resent-cc resent-reply-to
3503 (msgnum rmail-current-message
))
3506 (if rmail-enable-mime
3508 (goto-char (point-min))
3509 (if (search-forward "\n\n" nil
'move
)
3510 (1+ (match-beginning 0))
3513 (goto-char (rmail-msgbeg rmail-current-message
))
3515 (if (= (following-char) ?
0)
3517 (progn (forward-line 2)
3519 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
3522 (narrow-to-region (point)
3523 (progn (search-forward "\n*** EOOH ***\n")
3524 (beginning-of-line) (point)))))
3525 (setq from
(mail-fetch-field "from")
3526 reply-to
(or (mail-fetch-field "mail-reply-to" nil t
)
3527 (mail-fetch-field "reply-to" nil t
)
3529 subject
(mail-fetch-field "subject")
3530 date
(mail-fetch-field "date")
3531 message-id
(mail-fetch-field "message-id")
3532 references
(mail-fetch-field "references" nil nil t
)
3533 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
3534 resent-cc
(and (not just-sender
)
3535 (mail-fetch-field "resent-cc" nil t
))
3536 resent-to
(or (mail-fetch-field "resent-to" nil t
) "")
3537 ;;; resent-subject (mail-fetch-field "resent-subject")
3538 ;;; resent-date (mail-fetch-field "resent-date")
3539 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3542 (if (mail-fetch-field "mail-followup-to" nil t
)
3543 ;; If this header field is present, use it instead of the To and CC fields.
3544 (setq to
(mail-fetch-field "mail-followup-to" nil t
))
3545 (setq cc
(or (mail-fetch-field "cc" nil t
) "")
3546 to
(or (mail-fetch-field "to" nil t
) ""))))
3550 ;; Merge the resent-to and resent-cc into the to and cc.
3551 (if (and resent-to
(not (equal resent-to
"")))
3552 (if (not (equal to
""))
3553 (setq to
(concat to
", " resent-to
))
3554 (setq to resent-to
)))
3555 (if (and resent-cc
(not (equal resent-cc
"")))
3556 (if (not (equal cc
""))
3557 (setq cc
(concat cc
", " resent-cc
))
3558 (setq cc resent-cc
)))
3559 ;; Add `Re: ' to subject if not there already.
3560 (and (stringp subject
)
3562 (concat rmail-reply-prefix
3563 (if (let ((case-fold-search t
))
3564 (string-match rmail-reply-regexp subject
))
3565 (substring subject
(match-end 0))
3569 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3570 ;; since they can handle the names unstripped.
3571 ;; I don't know whether there are other mailers that still
3572 ;; need the names to be stripped.
3573 ;;; (mail-strip-quoted-names reply-to)
3574 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3575 ;; header causes all the names in it to wind up in reply-to, not
3576 ;; in cc. But if what's left is an empty list, use the original.
3577 (let* ((reply-to-list (rmail-dont-reply-to reply-to
)))
3578 (if (string= reply-to-list
"") reply-to reply-to-list
))
3580 (rmail-make-in-reply-to-field from date message-id
)
3583 ;; mail-strip-quoted-names is NOT necessary for rmail-dont-reply-to
3585 (let* ((cc-list (rmail-dont-reply-to
3586 (mail-strip-quoted-names
3587 (if (null cc
) to
(concat to
", " cc
))))))
3588 (if (string= cc-list
"") nil cc-list
)))
3590 (list (list 'rmail-mark-message
3592 (with-current-buffer rmail-buffer
3593 (aref rmail-msgref-vector msgnum
))
3596 (list (cons "References" (concat (mapconcat 'identity references
" ")
3597 " " message-id
))))))
3599 (defun rmail-mark-message (buffer msgnum-list attribute
)
3600 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3601 This is use in the send-actions for message buffers.
3602 MSGNUM-LIST is a list of the form (MSGNUM)
3603 which is an element of rmail-msgref-vector."
3606 (if (car msgnum-list
)
3607 (rmail-set-attribute attribute t
(car msgnum-list
)))))
3609 (defun rmail-make-in-reply-to-field (from date message-id
)
3616 (let ((tem (car (rfc822-addresses from
))))
3620 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
3622 (match-beginning 0))
3625 ;; missing From, or Message-ID is sufficiently informative
3627 (concat message-id
" (" tem
")"))
3628 ;; Copy TEM, discarding text properties.
3629 (setq tem
(copy-sequence tem
))
3630 (set-text-properties 0 (length tem
) nil tem
)
3631 (setq tem
(copy-sequence tem
))
3632 ;; Use prin1 to fake RFC822 quoting
3633 (let ((field (prin1-to-string tem
)))
3635 (concat field
"'s message of " date
)
3637 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3638 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3639 ;; These strings both match all non-ASCII characters.
3640 (or (string-match (concat "\\`[ \t]*\\(" bar
3641 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
3642 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3644 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
3645 bar
"\\))[ \t]*\\'")
3646 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3648 (let ((start (match-beginning 1))
3649 (end (match-end 1)))
3650 ;; Trim whitespace which above regexp match allows
3651 (while (and (< start end
)
3652 (memq (aref from start
) '(?
\t ?\
)))
3653 (setq start
(1+ start
)))
3654 (while (and (< start end
)
3655 (memq (aref from
(1- end
)) '(?
\t ?\
)))
3656 (setq end
(1- end
)))
3657 (let ((field (substring from start end
)))
3658 (if date
(setq field
(concat "message from " field
" on " date
)))
3660 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3661 (concat message-id
" (" field
")")
3664 ;; If we can't kludge it simply, do it correctly
3665 (let ((mail-use-rfc822 t
))
3666 (rmail-make-in-reply-to-field from date message-id
)))))
3668 (defun rmail-forward (resend)
3669 "Forward the current message to another user.
3670 With prefix argument, \"resend\" the message instead of forwarding it;
3671 see the documentation of `rmail-resend'."
3674 (call-interactively 'rmail-resend
)
3675 (let ((forward-buffer rmail-buffer
)
3676 (msgnum rmail-current-message
)
3677 (subject (concat "["
3678 (let ((from (or (mail-fetch-field "From")
3679 (mail-fetch-field ">From"))))
3681 (concat (mail-strip-quoted-names from
) ": ")
3683 (or (mail-fetch-field "Subject") "")
3685 (if (rmail-start-mail
3686 nil nil subject nil nil nil
3687 (list (list 'rmail-mark-message
3689 (with-current-buffer rmail-buffer
3690 (aref rmail-msgref-vector msgnum
))
3692 ;; If only one window, use it for the mail buffer.
3693 ;; Otherwise, use another window for the mail buffer
3694 ;; so that the Rmail buffer remains visible
3695 ;; and sending the mail will get back to it.
3696 (and (not rmail-mail-new-frame
) (one-window-p t
)))
3697 ;; The mail buffer is now current.
3699 ;; Insert after header separator--before signature if any.
3700 (goto-char (mail-text-start))
3701 (if (or rmail-enable-mime rmail-enable-mime-composing
)
3702 (funcall rmail-insert-mime-forwarded-message-function
3704 (insert "------- Start of forwarded message -------\n")
3705 ;; Quote lines with `- ' if they start with `-'.
3706 (let ((beg (point)) end
)
3707 (setq end
(point-marker))
3708 (set-marker-insertion-type end t
)
3709 (insert-buffer-substring forward-buffer
)
3711 (while (re-search-forward "^-" end t
)
3716 (skip-chars-backward "\n")
3719 (delete-region (point) end
)
3720 (set-marker end nil
))
3721 (insert "------- End of forwarded message -------\n"))
3724 (defun rmail-resend (address &optional from comment mail-alias-file
)
3725 "Resend current message to ADDRESSES.
3726 ADDRESSES should be a single address, a string consisting of several
3727 addresses separated by commas, or a list of addresses.
3729 Optional FROM is the address to resend the message from, and
3730 defaults from the value of `user-mail-address'.
3731 Optional COMMENT is a string to insert as a comment in the resent message.
3732 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3733 typically for purposes of moderating a list."
3734 (interactive "sResend to: ")
3736 (require 'mailalias
)
3737 (unless (or (eq rmail-view-buffer
(current-buffer))
3738 (eq rmail-buffer
(current-buffer)))
3739 (error "Not an Rmail buffer"))
3740 (if (not from
) (setq from user-mail-address
))
3741 (let ((tembuf (generate-new-buffer " sendmail temp"))
3742 (case-fold-search nil
)
3743 (mail-personal-alias-file
3744 (or mail-alias-file mail-personal-alias-file
))
3745 (mailbuf rmail-buffer
))
3747 (with-current-buffer tembuf
3748 ;;>> Copy message into temp buffer
3749 (if rmail-enable-mime
3750 (funcall rmail-insert-mime-resent-message-function mailbuf
)
3751 (insert-buffer-substring mailbuf
))
3752 (goto-char (point-min))
3753 ;; Delete any Sender field, since that's not specifiable.
3754 ; Only delete Sender fields in the actual header.
3755 (re-search-forward "^$" nil
'move
)
3756 ; Using "while" here rather than "if" because some buggy mail
3757 ; software may have inserted multiple Sender fields.
3758 (while (re-search-backward "^Sender:" nil t
)
3762 (while (looking-at "[ \t]")
3764 (delete-region beg
(point))))
3765 ; Go back to the beginning of the buffer so the Resent- fields
3766 ; are inserted there.
3767 (goto-char (point-min))
3768 ;;>> Insert resent-from:
3769 (insert "Resent-From: " from
"\n")
3770 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3771 ;;>> Insert resent-to: and bcc if need be.
3772 (let ((before (point)))
3774 (insert "Resent-Bcc: " (user-login-name) "\n"))
3775 (insert "Resent-To: " (if (stringp address
)
3777 (mapconcat 'identity address
",\n\t"))
3779 ;; Expand abbrevs in the recipients.
3781 (if (featurep 'mailabbrev
)
3782 (let ((end (point-marker))
3783 (local-abbrev-table mail-abbrevs
)
3784 (old-syntax-table (syntax-table)))
3785 (if (and (not (vectorp mail-abbrevs
))
3786 (file-exists-p mail-personal-alias-file
))
3787 (build-mail-abbrevs))
3788 (unless mail-abbrev-syntax-table
3789 (mail-abbrev-make-syntax-table))
3790 (set-syntax-table mail-abbrev-syntax-table
)
3792 (while (and (< (point) end
)
3793 (progn (forward-word 1)
3796 (set-syntax-table old-syntax-table
))
3797 (expand-mail-aliases before
(point)))))
3798 ;;>> Set up comment, if any.
3799 (if (and (sequencep comment
) (not (zerop (length comment
))))
3800 (let ((before (point))
3803 (or (eolp) (insert "\n"))
3804 (setq after
(point))
3806 (while (< (point) after
)
3807 (insert "Resent-Comment: ")
3809 ;; Don't expand aliases in the destination fields
3810 ;; of the original message.
3812 (funcall send-mail-function
)))
3813 (kill-buffer tembuf
))
3814 (with-current-buffer rmail-buffer
3815 (rmail-set-attribute "resent" t rmail-current-message
))))
3817 (defvar mail-unsent-separator
3818 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3819 "^ *---+ +Returned message +---+ *$\\|"
3820 "^ *---+ *Returned mail follows *---+ *$\\|"
3821 "^Start of returned message$\\|"
3822 "^---+ Below this line is a copy of the message.$\\|"
3823 "^ *---+ +Original message +---+ *$\\|"
3824 "^ *--+ +begin message +--+ *$\\|"
3825 "^ *---+ +Original message follows +---+ *$\\|"
3826 "^ *---+ +Your message follows +---+ *$\\|"
3827 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3828 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
3829 "A regexp that matches the separator before the text of a failed message.")
3831 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
3832 "A regexp that matches the header of a MIME body part with a failed message.")
3834 (defun rmail-retry-failure ()
3835 "Edit a mail message which is based on the contents of the current message.
3836 For a message rejected by the mail system, extract the interesting headers and
3837 the body of the original message.
3838 If the failed message is a MIME multipart message, it is searched for a
3839 body part with a header which matches the variable `mail-mime-unsent-header'.
3840 Otherwise, the variable `mail-unsent-separator' should match the string that
3841 delimits the returned original message.
3842 The variable `rmail-retry-ignored-headers' is a regular expression
3843 specifying headers which should not be copied into the new message."
3845 (require 'mail-utils
)
3846 (let ((rmail-this-buffer (current-buffer))
3847 (msgnum rmail-current-message
)
3848 bounce-start bounce-end bounce-indent resending
3849 ;; Fetch any content-type header in current message
3850 ;; Must search thru the whole unpruned header.
3854 (rmail-narrow-to-non-pruned-header)
3855 (mail-fetch-field "Content-Type") ))))
3857 (goto-char (point-min))
3858 (let ((case-fold-search t
))
3859 (if (and content-type
3861 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3863 ;; Handle a MIME multipart bounce message.
3866 (substring content-type
(match-beginning 1)
3868 (unless (re-search-forward mail-mime-unsent-header nil t
)
3869 (error "Cannot find beginning of header in failed message"))
3870 (unless (search-forward "\n\n" nil t
)
3871 (error "Cannot find start of Mime data in failed message"))
3872 (setq bounce-start
(point))
3873 (if (search-forward codestring nil t
)
3874 (setq bounce-end
(match-beginning 0))
3875 (setq bounce-end
(point-max))))
3877 (or (re-search-forward mail-unsent-separator nil t
)
3878 (error "Cannot parse this as a failure message"))
3879 (skip-chars-forward "\n")
3880 ;; Support a style of failure message in which the original
3881 ;; message is indented, and included within lines saying
3882 ;; `Start of returned message' and `End of returned message'.
3883 (if (looking-at " +Received:")
3885 (setq bounce-start
(point))
3886 (skip-chars-forward " ")
3887 (setq bounce-indent
(- (current-column)))
3888 (goto-char (point-max))
3889 (re-search-backward "^End of returned message$" nil t
)
3890 (setq bounce-end
(point)))
3891 ;; One message contained a few random lines before
3892 ;; the old message header. The first line of the
3893 ;; message started with two hyphens. A blank line
3894 ;; followed these random lines. The same line
3895 ;; beginning with two hyphens was possibly marking
3896 ;; the end of the message.
3897 (if (looking-at "^--")
3898 (let ((boundary (buffer-substring-no-properties
3900 (progn (end-of-line) (point)))))
3901 (search-forward "\n\n")
3902 (skip-chars-forward "\n")
3903 (setq bounce-start
(point))
3904 (goto-char (point-max))
3905 (search-backward (concat "\n\n" boundary
) bounce-start t
)
3906 (setq bounce-end
(point)))
3907 (setq bounce-start
(point)
3908 bounce-end
(point-max)))
3909 (unless (search-forward "\n\n" nil t
)
3910 (error "Cannot find end of header in failed message"))))))
3911 ;; We have found the message that bounced, within the current message.
3912 ;; Now start sending new message; default header fields from original.
3913 ;; Turn off the usual actions for initializing the message body
3914 ;; because we want to get only the text from the failure message.
3915 (let (mail-signature mail-setup-hook
)
3916 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
3917 (list (list 'rmail-mark-message
3919 (aref rmail-msgref-vector msgnum
)
3921 ;; Insert original text as initial text of new draft message.
3922 ;; Bind inhibit-read-only since the header delimiter
3923 ;; of the previous message was probably read-only.
3924 (let ((inhibit-read-only t
)
3925 rmail-displayed-headers
3926 rmail-ignored-headers
)
3928 (insert-buffer-substring rmail-this-buffer
3929 bounce-start bounce-end
)
3930 (goto-char (point-min))
3932 (indent-rigidly (point-min) (point-max) bounce-indent
))
3933 (rmail-clear-headers rmail-retry-ignored-headers
)
3934 (rmail-clear-headers "^sender:\\|^return-path:\\|^received:")
3935 (mail-sendmail-delimit-header)
3937 (narrow-to-region (point-min) (mail-header-end))
3938 (setq resending
(mail-fetch-field "resent-to"))
3941 (insert "Resent-Bcc: " (user-login-name) "\n")
3942 (insert "BCC: " (user-login-name) "\n"))))
3943 (goto-char (point-min))
3944 (mail-position-on-field (if resending
"Resent-To" "To") t
))))))
3946 (defun rmail-summary-exists ()
3947 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
3948 In fact, the non-nil value returned is the summary buffer itself."
3949 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3950 rmail-summary-buffer
))
3952 (defun rmail-summary-displayed ()
3953 "t iff in RMAIL buffer and an associated summary buffer is displayed."
3954 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
3956 (defcustom rmail-redisplay-summary nil
3957 "*Non-nil means Rmail should show the summary when it changes.
3958 This has an effect only if a summary buffer exists."
3960 :group
'rmail-summary
)
3962 (defcustom rmail-summary-window-size nil
3963 "*Non-nil means specify the height for an Rmail summary window."
3964 :type
'(choice (const :tag
"Disabled" nil
) integer
)
3965 :group
'rmail-summary
)
3967 ;; Put the summary buffer back on the screen, if user wants that.
3968 (defun rmail-maybe-display-summary ()
3969 (let ((selected (selected-window))
3971 ;; If requested, make sure the summary is displayed.
3972 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3973 rmail-redisplay-summary
3974 (if (get-buffer-window rmail-summary-buffer
0)
3975 ;; It's already in some frame; show that one.
3976 (let ((frame (window-frame
3977 (get-buffer-window rmail-summary-buffer
0))))
3978 (make-frame-visible frame
)
3979 (raise-frame frame
))
3980 (display-buffer rmail-summary-buffer
)))
3981 ;; If requested, set the height of the summary window.
3982 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3983 rmail-summary-window-size
3984 (setq window
(get-buffer-window rmail-summary-buffer
))
3985 ;; Don't try to change the size if just one window in frame.
3986 (not (eq window
(frame-root-window (window-frame window
))))
3989 (select-window window
)
3990 (enlarge-window (- rmail-summary-window-size
(window-height))))
3991 (select-window selected
)))))
3993 ;;;; *** Rmail Local Fontification ***
3995 (defun rmail-fontify-buffer-function ()
3996 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
3997 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
3998 ;; If we're already showing a message, fontify it now.
3999 (if rmail-current-message
(rmail-fontify-message))
4000 ;; Prevent Font Lock mode from kicking in.
4001 (setq font-lock-fontified t
))
4003 (defun rmail-unfontify-buffer-function ()
4004 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
4005 (let ((modified (buffer-modified-p))
4006 (buffer-undo-list t
) (inhibit-read-only t
)
4007 before-change-functions after-change-functions
4008 buffer-file-name buffer-file-truename
)
4011 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
4012 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
4013 (font-lock-default-unfontify-buffer)
4014 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))
4016 (defun rmail-fontify-message ()
4017 ;; Fontify the current message if it is not already fontified.
4018 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
4019 (let ((modified (buffer-modified-p))
4020 (buffer-undo-list t
) (inhibit-read-only t
)
4021 before-change-functions after-change-functions
4022 buffer-file-name buffer-file-truename
)
4025 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
4026 (font-lock-fontify-region (point-min) (point-max))
4027 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))))
4029 ;;; Speedbar support for RMAIL files.
4030 (eval-when-compile (require 'speedbar
))
4032 (defvar rmail-speedbar-match-folder-regexp
"^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
4033 "*This regex is used to match folder names to be displayed in speedbar.
4034 Enabling this will permit speedbar to display your folders for easy
4035 browsing, and moving of messages.")
4037 (defvar rmail-speedbar-last-user nil
4038 "The last user to be displayed in the speedbar.")
4040 (defvar rmail-speedbar-key-map nil
4041 "Keymap used when in rmail display mode.")
4043 (defun rmail-install-speedbar-variables ()
4044 "Install those variables used by speedbar to enhance rmail."
4045 (if rmail-speedbar-key-map
4047 (setq rmail-speedbar-key-map
(speedbar-make-specialized-keymap))
4049 (define-key rmail-speedbar-key-map
"e" 'speedbar-edit-line
)
4050 (define-key rmail-speedbar-key-map
"r" 'speedbar-edit-line
)
4051 (define-key rmail-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
4052 (define-key rmail-speedbar-key-map
"M"
4053 'rmail-speedbar-move-message-to-folder-on-line
)))
4055 (defvar rmail-speedbar-menu-items
4056 '(["Read Folder" speedbar-edit-line t
]
4057 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
4058 (save-excursion (beginning-of-line)
4059 (looking-at "<M> "))])
4060 "Additional menu-items to add to speedbar frame.")
4062 ;; Make sure our special speedbar major mode is loaded
4063 (if (featurep 'speedbar
)
4064 (rmail-install-speedbar-variables)
4065 (add-hook 'speedbar-load-hook
'rmail-install-speedbar-variables
))
4067 (defun rmail-speedbar-buttons (buffer)
4068 "Create buttons for BUFFER containing rmail messages.
4069 Click on the address under Reply to: to reply to this person.
4070 Under Folders: Click a name to read it, or on the <M> to move the
4071 current message into that RMAIL folder."
4075 (goto-char (point-min))
4076 (if (not (re-search-forward "^Reply-To: " nil t
))
4077 (if (not (re-search-forward "^From:? " nil t
))
4081 (setq from
(buffer-substring (point) (save-excursion
4084 (goto-char (point-min))
4085 (if (and (looking-at "Reply to:")
4086 (equal from rmail-speedbar-last-user
))
4088 (setq rmail-speedbar-last-user from
)
4090 (insert "Reply To:\n")
4092 (speedbar-insert-button from
'speedbar-directory-face
'highlight
4093 'rmail-speedbar-button
'rmail-reply
))
4094 (insert "Folders:\n")
4095 (let* ((case-fold-search nil
)
4096 (df (directory-files (save-excursion (set-buffer buffer
)
4098 nil rmail-speedbar-match-folder-regexp
)))
4100 (speedbar-insert-button "<M>" 'speedbar-button-face
'highlight
4101 'rmail-speedbar-move-message
(car df
))
4102 (speedbar-insert-button (car df
) 'speedbar-file-face
'highlight
4103 'rmail-speedbar-find-file nil t
)
4104 (setq df
(cdr df
)))))))
4106 (defun rmail-speedbar-button (text token indent
)
4107 "Execute an rmail command specified by TEXT.
4108 The command used is TOKEN. INDENT is not used."
4109 (speedbar-with-attached-buffer
4112 (defun rmail-speedbar-find-file (text token indent
)
4113 "Load in the rmail file TEXT.
4114 TOKEN and INDENT are not used."
4115 (speedbar-with-attached-buffer
4116 (message "Loading in RMAIL file %s..." text
)
4119 (defun rmail-speedbar-move-message-to-folder-on-line ()
4120 "If the current line is a folder, move current message to it."
4124 (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t
)
4127 (speedbar-do-function-pointer)))))
4129 (defun rmail-speedbar-move-message (text token indent
)
4130 "From button TEXT, copy current message to the rmail file specified by TOKEN.
4131 TEXT and INDENT are not used."
4132 (speedbar-with-attached-buffer
4133 (message "Moving message to %s" token
)
4134 (rmail-output-to-rmail-file token
)))
4136 ; Functions for setting, getting and encoding the POP password.
4137 ; The password is encoded to prevent it from being easily accessible
4138 ; to "prying eyes." Obviously, this encoding isn't "real security,"
4139 ; nor is it meant to be.
4142 (defun rmail-set-remote-password (password)
4143 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
4144 (interactive "sPassword: ")
4146 (setq rmail-encoded-remote-password
4147 (rmail-encode-string password
(emacs-pid)))
4148 (setq rmail-remote-password nil
)
4149 (setq rmail-encoded-remote-password nil
)))
4151 (defun rmail-get-remote-password (imap)
4152 "Get the password for retrieving mail from a POP or IMAP server. If none
4153 has been set, then prompt the user for one."
4154 (when (not rmail-encoded-remote-password
)
4155 (if (not rmail-remote-password
)
4156 (setq rmail-remote-password
4157 (read-passwd (if imap
4159 "POP password: "))))
4160 (rmail-set-remote-password rmail-remote-password
)
4161 (setq rmail-remote-password nil
))
4162 (rmail-encode-string rmail-encoded-remote-password
(emacs-pid)))
4164 (defun rmail-have-password ()
4165 (or rmail-remote-password rmail-encoded-remote-password
))
4167 (defun rmail-encode-string (string mask
)
4168 "Encode STRING with integer MASK, by taking the exclusive OR of the
4169 lowest byte in the mask with the first character of string, the
4170 second-lowest-byte with the second character of the string, etc.,
4171 restarting at the lowest byte of the mask whenever it runs out.
4172 Returns the encoded string. Calling the function again with an
4173 encoded string (and the same mask) will decode the string."
4174 (setq mask
(abs mask
)) ; doesn't work if negative
4175 (let* ((string-vector (string-to-vector string
)) (i 0)
4176 (len (length string-vector
)) (curmask mask
) charmask
)
4179 (setq curmask mask
))
4180 (setq charmask
(% curmask
256))
4181 (setq curmask
(lsh curmask -
8))
4182 (aset string-vector i
(logxor charmask
(aref string-vector i
)))
4184 (concat string-vector
)))
4186 ;;;; Desktop support
4188 (defun rmail-restore-desktop-buffer (desktop-buffer-file-name
4190 desktop-buffer-misc
)
4191 "Restore an rmail buffer specified in a desktop file."
4192 (condition-case error
4194 (rmail-input desktop-buffer-file-name
)
4195 (if (eq major-mode
'rmail-mode
)
4199 (kill-buffer (current-buffer))
4202 (add-to-list 'desktop-buffer-mode-handlers
4203 '(rmail-mode . rmail-restore-desktop-buffer
))
4207 ;;; arch-tag: cff0a950-57fe-4f73-a86e-91ff75afd06c
4208 ;;; rmail.el ends here