1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
3 ;; Copyright (C) 1985,86,87,88,93,94,95,96,97,98,2000,01,2004,2005
4 ;; Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, 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
45 ; These variables now declared in paths.el.
46 ;(defvar rmail-spool-directory "/usr/spool/mail/"
47 ; "This is the name of the directory used by the system mailer for\n\
48 ;delivering new mail. Its name should end with a slash.")
49 ;(defvar rmail-file-name
50 ; (expand-file-name "~/RMAIL")
54 "Mail reader for Emacs."
57 (defgroup rmail-retrieve nil
58 "Rmail retrieval options."
62 (defgroup rmail-files nil
67 (defgroup rmail-headers nil
68 "Rmail header options."
72 (defgroup rmail-reply nil
73 "Rmail reply options."
77 (defgroup rmail-summary nil
78 "Rmail summary options."
80 :prefix
"rmail-summary-"
83 (defgroup rmail-output nil
84 "Output message to a file."
85 :prefix
"rmail-output-"
89 (defgroup rmail-edit nil
94 (defgroup rmail-obsolete nil
95 "Rmail obsolete customization variables."
98 (defcustom rmail-movemail-program nil
99 "If non-nil, the file name of the `movemail' program."
100 :group
'rmail-retrieve
101 :type
'(choice (const nil
) string
))
103 (defcustom rmail-pop-password nil
104 "*Password to use when reading mail from POP server.
105 Please use `rmail-remote-password' instead."
106 :type
'(choice (string :tag
"Password")
107 (const :tag
"Not Required" nil
))
108 :group
'rmail-obsolete
)
110 (defcustom rmail-pop-password-required nil
111 "*Non-nil if a password is required when reading mail from a POP server.
112 Please use rmail-remote-password-required instead."
114 :group
'rmail-obsolete
)
116 (defcustom rmail-remote-password nil
117 "*Password to use when reading mail from a remote server.
118 This setting is ignored for mailboxes whose URL already contains a password."
119 :type
'(choice (string :tag
"Password")
120 (const :tag
"Not Required" nil
))
121 :set-after
'(rmail-pop-password)
122 :set
#'(lambda (symbol value
)
125 (boundp 'rmail-pop-password
)
129 (setq rmail-pop-password nil
))
130 :group
'rmail-retrieve
133 (defcustom rmail-remote-password-required nil
134 "*Non-nil if a password is required when reading mail from a remote server."
136 :set-after
'(rmail-pop-password-required)
137 :set
#'(lambda (symbol value
)
140 (boundp 'rmail-pop-password-required
)
141 rmail-pop-password-required
)
142 rmail-pop-password-required
144 (setq rmail-pop-password-required nil
))
145 :group
'rmail-retrieve
148 (defcustom rmail-movemail-flags nil
149 "*List of flags to pass to movemail.
150 Most commonly used to specify `-g' to enable GSS-API authentication
151 or `-k' to enable Kerberos authentication."
152 :type
'(repeat string
)
153 :group
'rmail-retrieve
156 (defvar rmail-remote-password-error
"invalid usercode or password\\|
157 unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
158 "Regular expression matching incorrect-password POP or IMAP server error
160 If you get an incorrect-password error that this expression does not match,
161 please report it with \\[report-emacs-bug].")
163 (defvar rmail-encoded-remote-password nil
)
165 (defcustom rmail-preserve-inbox nil
166 "*Non-nil means leave incoming mail in the user's inbox--don't delete it."
168 :group
'rmail-retrieve
)
170 (defcustom rmail-movemail-search-path nil
171 "*List of directories to search for movemail (in addition to `exec-path')."
172 :group
'rmail-retrieve
173 :type
'(repeat (directory)))
175 (defun rmail-probe (prog)
176 "Determine what flavor of movemail PROG is.
177 We do this by executing it with `--version' and analyzing its output."
179 (let ((tbuf (current-buffer)))
180 (buffer-disable-undo tbuf
)
181 (call-process prog nil tbuf nil
"--version")
182 (if (not (buffer-modified-p tbuf
))
183 ;; Should not happen...
185 (goto-char (point-min))
187 ((looking-at ".*movemail: invalid option")
188 'emacs
) ;; Possibly...
189 ((looking-at "movemail (GNU Mailutils .*)")
195 (defun rmail-autodetect ()
196 "Determine and return the file name of the `movemail' program.
197 If `rmail-movemail-program' is non-nil, use it.
198 Otherwise, look for `movemail' in the directories in
199 `rmail-movemail-search-path', those in `exec-path', and `exec-directory'."
200 (if rmail-movemail-program
201 (rmail-probe rmail-movemail-program
)
203 (dolist (dir (append rmail-movemail-search-path exec-path
204 (list exec-directory
)))
205 (when (and dir
(file-accessible-directory-p dir
))
206 (let ((progname (expand-file-name "movemail" dir
)))
207 (when (and (not (file-directory-p progname
))
208 (file-executable-p progname
))
209 (let ((x (rmail-probe progname
)))
211 (setq rmail-movemail-program progname
)
212 (throw 'scan x
))))))))))
214 (defvar rmail-movemail-variant-in-use nil
215 "The movemail variant currently in use. Known variants are:
217 `emacs' Means any implementation, compatible with the native Emacs one.
219 `mailutils' Means GNU mailutils implementation, capable of handling full
220 mail URLs as the source mailbox;")
223 (defun rmail-movemail-variant-p (&rest variants
)
224 "Return t if the current movemail variant is any of VARIANTS.
225 Currently known variants are 'emacs and 'mailutils."
226 (when (not rmail-movemail-variant-in-use
)
228 (setq rmail-movemail-variant-in-use
(rmail-autodetect)))
229 (not (null (member rmail-movemail-variant-in-use variants
))))
232 (defcustom rmail-dont-reply-to-names nil
"\
233 *A regexp specifying addresses to prune from a reply message.
234 A value of nil means exclude your own email address as an address
235 plus whatever is specified by `rmail-default-dont-reply-to-names'."
236 :type
'(choice regexp
(const :tag
"Your Name" nil
))
240 (defvar rmail-default-dont-reply-to-names
"\\`info-" "\
241 A regular expression specifying part of the default value of the
242 variable `rmail-dont-reply-to-names', for when the user does not set
243 `rmail-dont-reply-to-names' explicitly. (The other part of the default
244 value is the user's email address and name.)
245 It is useful to set this variable in the site customization file.")
248 (defcustom rmail-ignored-headers
249 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
250 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
251 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
252 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
253 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
254 "\\|^x-mailer:\\|^delivered-to:\\|^lines:\\|^mime-version:"
255 "\\|^content-transfer-encoding:\\|^x-coding-system:"
256 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
257 "\\|^x-sign:\\|^x-beenthere:\\|^x-mailman-version:\\|^x-mailman-copy:"
258 "\\|^precedence:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
259 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
260 "\\|^content-type:\\|^content-length:"
261 "\\|^x-attribution:\\|^x-disclaimer:\\|^x-trace:"
262 "\\|^x-complaints-to:\\|^nntp-posting-date:\\|^user-agent"
263 "\\|^importance:\\|^envelope-to:\\|^delivery-date"
264 "\\|^x.*-priority:\\|^x-mimeole:\\|^x-archive:"
265 "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization\\|^resent-openpgp"
266 "\\|^openpgp:\\|^x-request-pgp:\\|^x-original.*:"
267 "\\|^x-virus-scanned:\\|^x-spam-[^s].*:")
268 "*Regexp to match header fields that Rmail should normally hide.
269 This variable is used for reformatting the message header,
270 which normally happens once for each message,
271 when you view the message for the first time in Rmail.
272 To make a change in this variable take effect
273 for a message that you have already viewed,
274 go to that message and type \\[rmail-toggle-header] twice."
276 :group
'rmail-headers
)
279 (defcustom rmail-displayed-headers nil
280 "*Regexp to match Header fields that Rmail should display.
281 If nil, display all header fields except those matched by
282 `rmail-ignored-headers'."
283 :type
'(choice regexp
(const :tag
"All"))
284 :group
'rmail-headers
)
287 (defcustom rmail-retry-ignored-headers
"^x-authentication-warning:" "\
288 *Headers that should be stripped when retrying a failed message."
289 :type
'(choice regexp
(const nil
:tag
"None"))
290 :group
'rmail-headers
)
293 (defcustom rmail-highlighted-headers
"^From:\\|^Subject:" "\
294 *Regexp to match Header fields that Rmail should normally highlight.
295 A value of nil means don't highlight.
296 See also `rmail-highlight-face'."
298 :group
'rmail-headers
)
301 (defcustom rmail-highlight-face nil
"\
302 *Face used by Rmail for highlighting headers."
303 :type
'(choice (const :tag
"Default" nil
)
305 :group
'rmail-headers
)
308 (defcustom rmail-delete-after-output nil
"\
309 *Non-nil means automatically delete a message that is copied to a file."
314 (defcustom rmail-primary-inbox-list nil
"\
315 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
316 nil means the default, which is (\"/usr/spool/mail/$USER\")
317 \(the name varies depending on the operating system,
318 and the value of the environment variable MAIL overrides it)."
319 ;; Don't use backquote here, because we don't want to need it
321 :type
(list 'choice
'(const :tag
"Default" nil
)
322 (list 'repeat
':value
(list (or (getenv "MAIL")
323 (concat "/var/spool/mail/"
326 :group
'rmail-retrieve
330 (defcustom rmail-mail-new-frame nil
331 "*Non-nil means Rmail makes a new frame for composing outgoing mail.
332 This is handy if you want to preserve the window configuration of
333 the frame where you have the RMAIL buffer displayed."
338 (defcustom rmail-secondary-file-directory
"~/"
339 "*Directory for additional secondary Rmail files."
343 (defcustom rmail-secondary-file-regexp
"\\.xmail$"
344 "*Regexp for which files are secondary Rmail files."
349 (defcustom rmail-confirm-expunge
'y-or-n-p
350 "*Whether and how to ask for confirmation before expunging deleted messages."
351 :type
'(choice (const :tag
"No confirmation" nil
)
352 (const :tag
"Confirm with y-or-n-p" y-or-n-p
)
353 (const :tag
"Confirm with yes-or-no-p" yes-or-no-p
))
358 (defvar rmail-mode-hook nil
359 "List of functions to call when Rmail is invoked.")
362 (defvar rmail-get-new-mail-hook nil
363 "List of functions to call when Rmail has retrieved new mail.")
366 (defcustom rmail-show-message-hook nil
367 "List of functions to call when Rmail displays a message."
369 :options
'(goto-address)
373 (defvar rmail-quit-hook nil
374 "List of functions to call when quitting out of Rmail.")
377 (defvar rmail-delete-message-hook nil
378 "List of functions to call when Rmail deletes a message.
379 When the hooks are called, the message has been marked deleted but is
380 still the current message in the Rmail buffer.")
382 ;; These may be altered by site-init.el to match the format of mmdf files
383 ;; delimiting used on a given host (delim1 and delim2 from the config
386 (defvar rmail-mmdf-delim1
"^\001\001\001\001\n"
387 "Regexp marking the start of an mmdf message.")
388 (defvar rmail-mmdf-delim2
"^\001\001\001\001\n"
389 "Regexp marking the end of an mmdf message.")
391 (defcustom rmail-message-filter nil
392 "If non-nil, a filter function for new messages in RMAIL.
393 Called with region narrowed to the message, including headers,
394 before obeying `rmail-ignored-headers'."
395 :group
'rmail-headers
398 (defcustom rmail-automatic-folder-directives nil
399 "List of directives specifying where to put a message.
400 Each element of the list is of the form:
402 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
404 Where FOLDERNAME is the name of a BABYL format folder to put the
405 message. If any of the field regexp's are nil, then it is ignored.
407 If FOLDERNAME is \"/dev/null\", it is deleted.
408 If FOLDERNAME is nil then it is deleted, and skipped.
410 FIELD is the plain text name of a field in the message, such as
411 \"subject\" or \"from\". A FIELD of \"to\" will automatically include
412 all text from the \"cc\" field as well.
414 REGEXP is an expression to match in the preceeding specified FIELD.
415 FIELD/REGEXP pairs continue in the list.
418 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
419 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
422 :type
'(repeat (sexp :tag
"Directive")))
424 (defvar rmail-reply-prefix
"Re: "
425 "String to prepend to Subject line when replying to a message.")
427 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
428 ;; This pattern should catch all the common variants.
429 (defvar rmail-reply-regexp
"\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
430 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
432 (defcustom rmail-display-summary nil
433 "*If non-nil, Rmail always displays the summary buffer."
434 :group
'rmail-summary
437 (defvar rmail-inbox-list nil
)
438 (put 'rmail-inbox-list
'permanent-local t
)
440 (defvar rmail-keywords nil
)
441 (put 'rmail-keywords
'permanent-local t
)
443 (defvar rmail-buffer nil
444 "The RMAIL buffer related to the current buffer.
445 In an RMAIL buffer, this holds the RMAIL buffer itself.
446 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
447 (put 'rmail-buffer
'permanent-local t
)
449 ;; Message counters and markers. Deleted flags.
451 (defvar rmail-current-message nil
)
452 (put 'rmail-current-message
'permanent-local t
)
454 (defvar rmail-total-messages nil
)
455 (put 'rmail-total-messages
'permanent-local t
)
457 (defvar rmail-message-vector nil
)
458 (put 'rmail-message-vector
'permanent-local t
)
460 (defvar rmail-deleted-vector nil
)
461 (put 'rmail-deleted-vector
'permanent-local t
)
463 (defvar rmail-msgref-vector nil
464 "In an Rmail buffer, a vector whose Nth element is a list (N).
465 When expunging renumbers messages, these lists are modified
466 by substituting the new message number into the existing list.")
467 (put 'rmail-msgref-vector
'permanent-local t
)
469 (defvar rmail-overlay-list nil
)
470 (put 'rmail-overlay-list
'permanent-local t
)
472 ;; These are used by autoloaded rmail-summary.
474 (defvar rmail-summary-buffer nil
)
475 (put 'rmail-summary-buffer
'permanent-local t
)
476 (defvar rmail-summary-vector nil
)
477 (put 'rmail-summary-vector
'permanent-local t
)
479 (defvar rmail-view-buffer nil
480 "Buffer which holds RMAIL message for MIME displaying.")
481 (put 'rmail-view-buffer
'permanent-local t
)
483 ;; `Sticky' default variables.
485 ;; Last individual label specified to a or k.
486 (defvar rmail-last-label nil
)
487 (put 'rmail-last-label
'permanent-local t
)
489 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
490 (defvar rmail-last-multi-labels nil
)
492 (defvar rmail-last-regexp nil
)
493 (put 'rmail-last-regexp
'permanent-local t
)
495 (defcustom rmail-default-file
"~/xmail"
496 "*Default file name for \\[rmail-output]."
499 (defcustom rmail-default-rmail-file
"~/XMAIL"
500 "*Default file name for \\[rmail-output-to-rmail-file]."
503 (defcustom rmail-default-body-file
"~/mailout"
504 "*Default file name for \\[rmail-output-body-to-file]."
509 ;; Mule and MIME related variables.
512 (defvar rmail-file-coding-system nil
513 "Coding system used in RMAIL file.
515 This is set to nil by default.")
518 (defcustom rmail-enable-mime nil
519 "*If non-nil, RMAIL uses MIME feature.
520 If the value is t, RMAIL automatically shows MIME decoded message.
521 If the value is neither t nor nil, RMAIL does not show MIME decoded message
522 until a user explicitly requires it."
523 :type
'(choice (const :tag
"on" t
)
524 (const :tag
"off" nil
)
525 (other :tag
"when asked" ask
))
528 (defvar rmail-enable-mime-composing nil
529 "*If non-nil, RMAIL uses `rmail-insert-mime-forwarded-message-function' to forward.")
532 (defvar rmail-show-mime-function nil
533 "Function to show MIME decoded message of RMAIL file.
534 This function is called when `rmail-enable-mime' is non-nil.
535 It is called with no argument.")
538 (defvar rmail-insert-mime-forwarded-message-function nil
539 "Function to insert a message in MIME format so it can be forwarded.
540 This function is called if `rmail-enable-mime' or
541 `rmail-enable-mime-composing' is non-nil.
542 It is called with one argument FORWARD-BUFFER, which is a
543 buffer containing the message to forward. The current buffer
544 is the outgoing mail buffer.")
547 (defvar rmail-insert-mime-resent-message-function nil
548 "Function to insert a message in MIME format so it can be resent.
549 This function is called if `rmail-enable-mime' is non-nil.
550 It is called with one argument FORWARD-BUFFER, which is a
551 buffer containing the message to forward. The current buffer
552 is the outgoing mail buffer.")
555 (defvar rmail-search-mime-message-function nil
556 "Function to check if a regexp matches a MIME message.
557 This function is called if `rmail-enable-mime' is non-nil.
558 It is called with two arguments MSG and REGEXP, where
559 MSG is the message number, REGEXP is the regular expression.")
562 (defvar rmail-search-mime-header-function nil
563 "Function to check if a regexp matches a header of MIME message.
564 This function is called if `rmail-enable-mime' is non-nil.
565 It is called with three arguments MSG, REGEXP, and LIMIT, where
566 MSG is the message number,
567 REGEXP is the regular expression,
568 LIMIT is the position specifying the end of header.")
571 (defvar rmail-mime-feature
'rmail-mime
572 "Feature to require to load MIME support in Rmail.
573 When starting Rmail, if `rmail-enable-mime' is non-nil,
574 this feature is required with `require'.")
577 (defvar rmail-decode-mime-charset t
578 "*Non-nil means a message is decoded by MIME's charset specification.
579 If this variable is nil, or the message has not MIME specification,
580 the message is decoded as normal way.
582 If the variable `rmail-enable-mime' is non-nil, this variables is
583 ignored, and all the decoding work is done by a feature specified by
584 the variable `rmail-mime-feature'.")
587 (defvar rmail-mime-charset-pattern
588 "^content-type:[ ]*text/plain;[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?"
589 "Regexp to match MIME-charset specification in a header of message.
590 The first parenthesized expression should match the MIME-charset name.")
593 ;;; Regexp matching the delimiter of messages in UNIX mail format
594 ;;; (UNIX From lines), minus the initial ^. Note that if you change
595 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
596 ;;; that knows the exact ordering of the \\( \\) subexpressions.
597 (defvar rmail-unix-mail-delimiter
598 (let ((time-zone-regexp
599 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
600 "\\|[-+]?[0-9][0-9][0-9][0-9]"
606 ;; Many things can happen to an RFC 822 mailbox before it is put into
607 ;; a `From' line. The leading phrase can be stripped, e.g.
608 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
609 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
610 ;; can be removed, e.g.
611 ;; From: joe@y.z (Joe K
613 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
616 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
617 ;; The mailbox can be removed or be replaced by white space, e.g.
618 ;; From: "Joe User"{space}{tab}
620 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
621 ;; where {space} and {tab} represent the Ascii space and tab characters.
622 ;; We want to match the results of any of these manglings.
623 ;; The following regexp rejects names whose first characters are
624 ;; obviously bogus, but after that anything goes.
625 "\\([^\0-\b\n-\r\^?].*\\)? "
627 ;; The time the message was sent.
628 "\\([^\0-\r \^?]+\\) +" ; day of the week
629 "\\([^\0-\r \^?]+\\) +" ; month
630 "\\([0-3]?[0-9]\\) +" ; day of month
631 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
633 ;; Perhaps a time zone, specified by an abbreviation, or by a
638 " \\([0-9][0-9]+\\) *"
640 ;; On some systems the time zone can appear after the year, too.
644 "\\(remote from .*\\)?"
649 (defvar rmail-font-lock-keywords
650 ;; These are all matched case-insensitively.
652 (let* ((cite-chars "[>|}]")
654 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
655 (list '("^\\(From\\|Sender\\|Resent-From\\):"
656 . font-lock-function-name-face
)
657 '("^Reply-To:.*$" . font-lock-function-name-face
)
658 '("^Subject:" . font-lock-comment-face
)
659 '("^X-Spam-Status:" . font-lock-keyword-face
)
660 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
661 . font-lock-keyword-face
)
662 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
664 (,(concat "\\=[ \t]*"
665 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
666 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
668 (beginning-of-line) (end-of-line)
669 (1 font-lock-comment-delimiter-face nil t
)
670 (5 font-lock-comment-face nil t
)))
671 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
672 . font-lock-string-face
))))
673 "Additional expressions to highlight in Rmail mode.")
675 ;; Perform BODY in the summary buffer
676 ;; in such a way that its cursor is properly updated in its own window.
677 (defmacro rmail-select-summary
(&rest body
)
678 `(let ((total rmail-total-messages
))
679 (if (rmail-summary-displayed)
680 (let ((window (selected-window)))
684 (pop-to-buffer rmail-summary-buffer
)
685 ;; rmail-total-messages is a buffer-local var
686 ;; in the rmail buffer.
687 ;; This way we make it available for the body
688 ;; even tho the rmail buffer is not current.
689 (let ((rmail-total-messages total
))
691 (select-window window
))))
693 (set-buffer rmail-summary-buffer
)
694 (let ((rmail-total-messages total
))
696 (rmail-maybe-display-summary)))
698 ;;;; *** Rmail Mode ***
700 ;; This variable is dynamically bound. The defvar is here to placate
701 ;; the byte compiler.
703 (defvar rmail-enable-multibyte nil
)
706 (defun rmail-require-mime-maybe ()
707 "Require `rmail-mime-feature' if that is non-nil.
708 Signal an error and set `rmail-mime-feature' to nil if the feature
710 (when rmail-enable-mime
712 (require rmail-mime-feature
)
714 (message "Feature `%s' not provided" rmail-mime-feature
)
716 (setq rmail-enable-mime nil
)))))
720 (defun rmail (&optional file-name-arg
)
721 "Read and edit incoming mail.
722 Moves messages into file named by `rmail-file-name' (a babyl format file)
723 and edits that file in RMAIL Mode.
724 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
726 May be called with file name as argument; then performs rmail editing on
727 that file, but does not copy any new mail into the file.
728 Interactively, if you supply a prefix argument, then you
729 have a chance to specify a file name with the minibuffer.
731 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
732 (interactive (if current-prefix-arg
733 (list (read-file-name "Run rmail on RMAIL file: "))))
734 (rmail-require-mime-maybe)
735 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
736 ;; Use find-buffer-visiting, not get-file-buffer, for those users
737 ;; who have find-file-visit-truename set to t.
738 (existed (find-buffer-visiting file-name
))
739 ;; This binding is necessary because we must decide if we
740 ;; need code conversion while the buffer is unibyte
741 ;; (i.e. enable-multibyte-characters is nil).
742 (rmail-enable-multibyte
744 (with-current-buffer existed enable-multibyte-characters
)
745 (default-value 'enable-multibyte-characters
)))
746 ;; Since the file may contain messages of different encodings
747 ;; at the tail (non-BYBYL part), we can't decode them at once
748 ;; on reading. So, at first, we read the file without text
749 ;; code conversion, then decode the messages one by one by
750 ;; rmail-decode-babyl-format or
751 ;; rmail-convert-to-babyl-format.
752 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
))
753 run-mail-hook msg-shown
)
754 ;; Like find-file, but in the case where a buffer existed
755 ;; and the file was reverted, recompute the message-data.
756 ;; We used to bind enable-local-variables to nil here,
757 ;; but that should not be needed now that rmail-mode
758 ;; sets it locally to nil.
759 ;; (Binding a variable locally with let is not safe if it has
760 ;; buffer-local bindings.)
761 (if (and existed
(not (verify-visited-file-modtime existed
)))
763 (find-file file-name
)
764 (if (and (verify-visited-file-modtime existed
)
765 (eq major-mode
'rmail-mode
))
766 (progn (rmail-forget-messages)
767 (rmail-set-message-counters))))
769 (let ((enable-local-variables nil
))
770 (find-file-noselect file-name
))))
771 (if (eq major-mode
'rmail-edit-mode
)
772 (error "Exit Rmail Edit mode before getting new mail"))
773 (if (and existed
(> (buffer-size) 0))
774 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
775 (or (eq major-mode
'rmail-mode
)
776 (progn (rmail-mode-2)
777 (setq run-mail-hook t
)))
778 (setq run-mail-hook t
)
780 ;; Convert all or part to Babyl file if possible.
782 (goto-char (point-max)))
783 ;; As we have read a file by raw-text, the buffer is set to
784 ;; unibyte. We must make it multibyte if necessary.
785 (if (and rmail-enable-multibyte
786 (not enable-multibyte-characters
))
787 (set-buffer-multibyte t
))
788 ;; If necessary, scan to find all the messages.
789 (rmail-maybe-set-message-counters)
791 (unless (and (not file-name-arg
)
792 (rmail-get-new-mail))
793 (rmail-show-message (rmail-first-unseen-message)))
795 (if rmail-display-summary
(rmail-summary))
796 (rmail-construct-io-menu)
798 (run-hooks 'rmail-mode-hook
))))))
800 ;; Given the value of MAILPATH, return a list of inbox file names.
801 ;; This is turned off because it is not clear that the user wants
802 ;; all these inboxes to feed into the primary rmail file.
803 ; (defun rmail-convert-mailpath (string)
805 ; (while (setq idx (string-match "[%:]" string))
806 ; (let ((this (substring string 0 idx)))
807 ; (setq string (substring string (1+ idx)))
808 ; (setq list (cons (if (string-match "%" this)
809 ; (substring this 0 (string-match "%" this))
814 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
815 ; will not cause emacs 18.55 problems.
817 ;; This calls rmail-decode-babyl-format if the file is already Babyl.
819 (defun rmail-convert-file ()
822 (goto-char (point-min))
823 ;; If file doesn't start like a Babyl file,
824 ;; convert it to one, by adding a header and converting each message.
825 (cond ((looking-at "BABYL OPTIONS:"))
826 ((looking-at "Version: 5\n")
827 ;; Losing babyl file made by old version of Rmail.
828 ;; Just fix the babyl file header; don't make a new one,
829 ;; so we don't lose the Labels: file attribute, etc.
830 (let ((buffer-read-only nil
))
831 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
832 ((equal (point-min) (point-max))
833 ;; Empty RMAIL file. Just insert the header.
834 (rmail-insert-rmail-file-header))
836 ;; Non-empty file in non-RMAIL format. Add header and convert.
838 (rmail-insert-rmail-file-header)))
839 ;; If file was not a Babyl file or if there are
840 ;; Unix format messages added at the end,
841 ;; convert file as necessary.
844 (goto-char (point-max))
845 (search-backward "\n\^_")
847 (looking-at "\n*From ")))
848 (let ((buffer-read-only nil
))
849 (message "Converting to Babyl format...")
850 ;; If file needs conversion, convert it all,
851 ;; except for the BABYL header.
852 ;; (rmail-convert-to-babyl-format would delete the header.)
853 (goto-char (point-min))
854 (search-forward "\n\^_" nil t
)
855 (narrow-to-region (point) (point-max))
856 (rmail-convert-to-babyl-format)
857 (message "Converting to Babyl format...done"))
858 (if (and (not rmail-enable-mime
)
859 rmail-enable-multibyte
)
860 ;; We still have to decode BABYL part.
861 (rmail-decode-babyl-format)))))
863 (defun rmail-insert-rmail-file-header ()
864 (let ((buffer-read-only nil
))
865 ;; -*-rmail-*- is here so that visiting the file normally
866 ;; recognizes it as an Rmail file.
867 (insert "BABYL OPTIONS: -*- rmail -*-
870 Note: This is the header of an rmail file.
871 Note: If you are seeing it in rmail,
872 Note: it means the file has no messages in it.\n\^_")))
874 ;; Decode Babyl formatted part at the head of current buffer by
875 ;; rmail-file-coding-system, or if it is nil, do auto conversion.
877 (defun rmail-decode-babyl-format ()
878 (let ((modifiedp (buffer-modified-p))
879 (buffer-read-only nil
)
880 (coding-system rmail-file-coding-system
)
882 (goto-char (point-min))
883 (search-forward "\n\^_" nil t
) ; Skip BABYL header.
885 (goto-char (point-max))
886 (search-backward "\n\^_" from
'mv
)
888 (unless (and coding-system
889 (coding-system-p coding-system
))
891 ;; If rmail-file-coding-system is nil, Emacs 21 writes
892 ;; RMAIL files in emacs-mule, Emacs 22 in utf-8, but
893 ;; earlier versions did that with the current buffer's
894 ;; encoding. So we want to favor detection of emacs-mule
895 ;; (whose normal priority is quite low) and utf-8, but
896 ;; still allow detection of other encodings if they won't
897 ;; fit. The call to with-coding-priority below achieves
899 (with-coding-priority '(emacs-mule utf-8
)
900 (detect-coding-region from to
'highest
))))
901 (unless (eq (coding-system-type coding-system
) 'undecided
)
902 (set-buffer-modified-p t
) ; avoid locking when decoding
903 (let ((buffer-undo-list t
))
904 (decode-coding-region from to coding-system
))
905 (setq coding-system last-coding-system-used
))
906 (set-buffer-modified-p modifiedp
)
907 (setq buffer-file-coding-system nil
)
908 (setq save-buffer-coding-system
909 (or coding-system
'undecided
))))
911 (defvar rmail-mode-map nil
)
914 (setq rmail-mode-map
(make-keymap))
915 (suppress-keymap rmail-mode-map
)
916 (define-key rmail-mode-map
"a" 'rmail-add-label
)
917 (define-key rmail-mode-map
"b" 'rmail-bury
)
918 (define-key rmail-mode-map
"c" 'rmail-continue
)
919 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
920 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
)
921 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
922 (define-key rmail-mode-map
"f" 'rmail-forward
)
923 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
924 (define-key rmail-mode-map
"h" 'rmail-summary
)
925 (define-key rmail-mode-map
"i" 'rmail-input
)
926 (define-key rmail-mode-map
"j" 'rmail-show-message
)
927 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
928 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
929 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
930 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
931 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
932 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
933 (define-key rmail-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
934 (define-key rmail-mode-map
"m" 'rmail-mail
)
935 (define-key rmail-mode-map
"\em" 'rmail-retry-failure
)
936 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
937 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
938 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
939 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
940 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
941 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
942 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
943 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
944 (define-key rmail-mode-map
"q" 'rmail-quit
)
945 (define-key rmail-mode-map
"r" 'rmail-reply
)
946 ;; I find I can't live without the default M-r command -- rms.
947 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
948 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
949 (define-key rmail-mode-map
"\es" 'rmail-search
)
950 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
951 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
952 (define-key rmail-mode-map
"w" 'rmail-output-body-to-file
)
953 (define-key rmail-mode-map
"x" 'rmail-expunge
)
954 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
955 (define-key rmail-mode-map
"<" 'rmail-first-message
)
956 (define-key rmail-mode-map
">" 'rmail-last-message
)
957 (define-key rmail-mode-map
" " 'scroll-up
)
958 (define-key rmail-mode-map
"\177" 'scroll-down
)
959 (define-key rmail-mode-map
"?" 'describe-mode
)
960 (define-key rmail-mode-map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
961 (define-key rmail-mode-map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
962 (define-key rmail-mode-map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
963 (define-key rmail-mode-map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
964 (define-key rmail-mode-map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
965 (define-key rmail-mode-map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
966 (define-key rmail-mode-map
"\C-c\C-s\C-k" 'rmail-sort-by-labels
)
967 (define-key rmail-mode-map
"\C-c\C-n" 'rmail-next-same-subject
)
968 (define-key rmail-mode-map
"\C-c\C-p" 'rmail-previous-same-subject
)
971 (define-key rmail-mode-map
[menu-bar
] (make-sparse-keymap))
973 (define-key rmail-mode-map
[menu-bar classify
]
974 (cons "Classify" (make-sparse-keymap "Classify")))
976 (define-key rmail-mode-map
[menu-bar classify input-menu
]
979 (define-key rmail-mode-map
[menu-bar classify output-menu
]
982 (define-key rmail-mode-map
[menu-bar classify output-body
]
983 '("Output body to file..." . rmail-output-body-to-file
))
985 (define-key rmail-mode-map
[menu-bar classify output-inbox
]
986 '("Output (inbox)..." . rmail-output
))
988 (define-key rmail-mode-map
[menu-bar classify output
]
989 '("Output (Rmail)..." . rmail-output-to-rmail-file
))
991 (define-key rmail-mode-map
[menu-bar classify kill-label
]
992 '("Kill Label..." . rmail-kill-label
))
994 (define-key rmail-mode-map
[menu-bar classify add-label
]
995 '("Add Label..." . rmail-add-label
))
997 (define-key rmail-mode-map
[menu-bar summary
]
998 (cons "Summary" (make-sparse-keymap "Summary")))
1000 (define-key rmail-mode-map
[menu-bar summary senders
]
1001 '("By Senders..." . rmail-summary-by-senders
))
1003 (define-key rmail-mode-map
[menu-bar summary labels
]
1004 '("By Labels..." . rmail-summary-by-labels
))
1006 (define-key rmail-mode-map
[menu-bar summary recipients
]
1007 '("By Recipients..." . rmail-summary-by-recipients
))
1009 (define-key rmail-mode-map
[menu-bar summary topic
]
1010 '("By Topic..." . rmail-summary-by-topic
))
1012 (define-key rmail-mode-map
[menu-bar summary regexp
]
1013 '("By Regexp..." . rmail-summary-by-regexp
))
1015 (define-key rmail-mode-map
[menu-bar summary all
]
1016 '("All" . rmail-summary
))
1018 (define-key rmail-mode-map
[menu-bar mail
]
1019 (cons "Mail" (make-sparse-keymap "Mail")))
1021 (define-key rmail-mode-map
[menu-bar mail rmail-get-new-mail
]
1022 '("Get New Mail" . rmail-get-new-mail
))
1024 (define-key rmail-mode-map
[menu-bar mail lambda
]
1027 (define-key rmail-mode-map
[menu-bar mail continue
]
1028 '("Continue" . rmail-continue
))
1030 (define-key rmail-mode-map
[menu-bar mail resend
]
1031 '("Re-send..." . rmail-resend
))
1033 (define-key rmail-mode-map
[menu-bar mail forward
]
1034 '("Forward" . rmail-forward
))
1036 (define-key rmail-mode-map
[menu-bar mail retry
]
1037 '("Retry" . rmail-retry-failure
))
1039 (define-key rmail-mode-map
[menu-bar mail reply
]
1040 '("Reply" . rmail-reply
))
1042 (define-key rmail-mode-map
[menu-bar mail mail
]
1043 '("Mail" . rmail-mail
))
1045 (define-key rmail-mode-map
[menu-bar delete
]
1046 (cons "Delete" (make-sparse-keymap "Delete")))
1048 (define-key rmail-mode-map
[menu-bar delete expunge
/save
]
1049 '("Expunge/Save" . rmail-expunge-and-save
))
1051 (define-key rmail-mode-map
[menu-bar delete expunge
]
1052 '("Expunge" . rmail-expunge
))
1054 (define-key rmail-mode-map
[menu-bar delete undelete
]
1055 '("Undelete" . rmail-undelete-previous-message
))
1057 (define-key rmail-mode-map
[menu-bar delete delete
]
1058 '("Delete" . rmail-delete-forward
))
1060 (define-key rmail-mode-map
[menu-bar move
]
1061 (cons "Move" (make-sparse-keymap "Move")))
1063 (define-key rmail-mode-map
[menu-bar move search-back
]
1064 '("Search Back..." . rmail-search-backwards
))
1066 (define-key rmail-mode-map
[menu-bar move search
]
1067 '("Search..." . rmail-search
))
1069 (define-key rmail-mode-map
[menu-bar move previous
]
1070 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
1072 (define-key rmail-mode-map
[menu-bar move next
]
1073 '("Next Nondeleted" . rmail-next-undeleted-message
))
1075 (define-key rmail-mode-map
[menu-bar move last
]
1076 '("Last" . rmail-last-message
))
1078 (define-key rmail-mode-map
[menu-bar move first
]
1079 '("First" . rmail-first-message
))
1081 (define-key rmail-mode-map
[menu-bar move previous
]
1082 '("Previous" . rmail-previous-message
))
1084 (define-key rmail-mode-map
[menu-bar move next
]
1085 '("Next" . rmail-next-message
))
1087 ;; Rmail mode is suitable only for specially formatted data.
1088 (put 'rmail-mode
'mode-class
'special
)
1090 (defun rmail-mode-kill-summary ()
1091 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
1094 (defun rmail-mode ()
1095 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
1096 All normal editing commands are turned off.
1097 Instead, these commands are available:
1099 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
1100 \\[scroll-up] Scroll to next screen of this message.
1101 \\[scroll-down] Scroll to previous screen of this message.
1102 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
1103 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
1104 \\[rmail-next-message] Move to Next message whether deleted or not.
1105 \\[rmail-previous-message] Move to Previous message whether deleted or not.
1106 \\[rmail-first-message] Move to the first message in Rmail file.
1107 \\[rmail-last-message] Move to the last message in Rmail file.
1108 \\[rmail-show-message] Jump to message specified by numeric position in file.
1109 \\[rmail-search] Search for string and show message it is found in.
1110 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
1111 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
1112 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1113 till a deleted message is found.
1114 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
1115 \\[rmail-expunge] Expunge deleted messages.
1116 \\[rmail-expunge-and-save] Expunge and save the file.
1117 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
1118 \\[save-buffer] Save without expunging.
1119 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
1120 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
1121 \\[rmail-continue] Continue composing outgoing message started before.
1122 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
1123 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
1124 \\[rmail-forward] Forward this message to another user.
1125 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
1126 \\[rmail-output] Output this message to a Unix-format mail file (append it).
1127 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1128 \\[rmail-input] Input Rmail file. Run Rmail on that file.
1129 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
1130 \\[rmail-kill-label] Kill label. Remove a label from current message.
1131 \\[rmail-next-labeled-message] Move to Next message with specified label
1132 (label defaults to last one specified).
1133 Standard labels: filed, unseen, answered, forwarded, deleted.
1134 Any other label is present only if you add it with \\[rmail-add-label].
1135 \\[rmail-previous-labeled-message] Move to Previous message with specified label
1136 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
1137 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
1138 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1139 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1140 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1141 \\[rmail-toggle-header] Toggle display of complete header."
1143 (let ((finding-rmail-file (not (eq major-mode
'rmail-mode
))))
1145 (when (and finding-rmail-file
1146 (null coding-system-for-read
)
1147 default-enable-multibyte-characters
)
1148 (let ((rmail-enable-multibyte t
))
1149 (rmail-require-mime-maybe)
1150 (rmail-convert-file)
1151 (goto-char (point-max))
1152 (set-buffer-multibyte t
)))
1153 (rmail-set-message-counters)
1154 (rmail-show-message rmail-total-messages
)
1155 (when finding-rmail-file
1156 (when rmail-display-summary
1158 (rmail-construct-io-menu))
1159 (run-mode-hooks 'rmail-mode-hook
)))
1161 (defun rmail-mode-2 ()
1162 (kill-all-local-variables)
1164 (rmail-perm-variables)
1167 (defun rmail-mode-1 ()
1168 (setq major-mode
'rmail-mode
)
1169 (setq mode-name
"RMAIL")
1170 (setq buffer-read-only t
)
1171 ;; No need to auto save RMAIL files in normal circumstances
1172 ;; because they contain no info except attribute changes
1173 ;; and deletion of messages.
1174 ;; The one exception is when messages are copied into an Rmail mode buffer.
1175 ;; rmail-output-to-rmail-file enables auto save when you do that.
1176 (setq buffer-auto-save-file-name nil
)
1177 (setq mode-line-modified
"--")
1178 (use-local-map rmail-mode-map
)
1179 (set-syntax-table text-mode-syntax-table
)
1180 (setq local-abbrev-table text-mode-abbrev-table
))
1182 ;; Set up the permanent locals associated with an Rmail file.
1183 (defun rmail-perm-variables ()
1184 (make-local-variable 'rmail-last-label
)
1185 (make-local-variable 'rmail-last-regexp
)
1186 (make-local-variable 'rmail-deleted-vector
)
1187 (make-local-variable 'rmail-buffer
)
1188 (setq rmail-buffer
(current-buffer))
1189 (make-local-variable 'rmail-view-buffer
)
1190 (setq rmail-view-buffer rmail-buffer
)
1191 (make-local-variable 'rmail-summary-buffer
)
1192 (make-local-variable 'rmail-summary-vector
)
1193 (make-local-variable 'rmail-current-message
)
1194 (make-local-variable 'rmail-total-messages
)
1195 (make-local-variable 'rmail-overlay-list
)
1196 (setq rmail-overlay-list nil
)
1197 (make-local-variable 'rmail-message-vector
)
1198 (make-local-variable 'rmail-msgref-vector
)
1199 (make-local-variable 'rmail-inbox-list
)
1200 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
1201 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1202 (and (null rmail-inbox-list
)
1203 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
1204 (equal buffer-file-truename
1205 (abbreviate-file-name (file-truename rmail-file-name
))))
1206 (setq rmail-inbox-list
1207 (or rmail-primary-inbox-list
1208 (list (or (getenv "MAIL")
1209 (concat rmail-spool-directory
1210 (user-login-name)))))))
1211 (make-local-variable 'rmail-keywords
)
1212 ;; this gets generated as needed
1213 (setq rmail-keywords nil
))
1215 ;; Set up the non-permanent locals associated with Rmail mode.
1216 (defun rmail-variables ()
1217 (make-local-variable 'save-buffer-coding-system
)
1218 ;; If we don't already have a value for save-buffer-coding-system,
1219 ;; get it from buffer-file-coding-system, and clear that
1220 ;; because it should be determined in rmail-show-message.
1221 (unless save-buffer-coding-system
1222 (setq save-buffer-coding-system
(or buffer-file-coding-system
'undecided
))
1223 (setq buffer-file-coding-system nil
))
1224 ;; Don't let a local variables list in a message cause confusion.
1225 (make-local-variable 'local-enable-local-variables
)
1226 (setq local-enable-local-variables nil
)
1227 (make-local-variable 'revert-buffer-function
)
1228 (setq revert-buffer-function
'rmail-revert
)
1229 (make-local-variable 'font-lock-defaults
)
1230 (setq font-lock-defaults
1231 '(rmail-font-lock-keywords
1233 (font-lock-maximum-size . nil
)
1234 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
1235 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
1236 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
1237 (make-local-variable 'require-final-newline
)
1238 (setq require-final-newline nil
)
1239 (make-local-variable 'version-control
)
1240 (setq version-control
'never
)
1241 (make-local-variable 'kill-buffer-hook
)
1242 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
1243 (make-local-variable 'file-precious-flag
)
1244 (setq file-precious-flag t
)
1245 (make-local-variable 'desktop-save-buffer
)
1246 (setq desktop-save-buffer t
))
1248 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1249 (defun rmail-revert (arg noconfirm
)
1250 (set-buffer rmail-buffer
)
1251 (let* ((revert-buffer-function (default-value 'revert-buffer-function
))
1252 (rmail-enable-multibyte enable-multibyte-characters
)
1253 ;; See similar code in `rmail'.
1254 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
)))
1255 ;; Call our caller again, but this time it does the default thing.
1256 (if (revert-buffer arg noconfirm
)
1257 ;; If the user said "yes", and we changed something,
1258 ;; reparse the messages.
1260 (set-buffer rmail-buffer
)
1262 ;; Convert all or part to Babyl file if possible.
1263 (rmail-convert-file)
1264 ;; We have read the file as raw-text, so the buffer is set to
1265 ;; unibyte. Make it multibyte if necessary.
1266 (if (and rmail-enable-multibyte
1267 (not enable-multibyte-characters
))
1268 (set-buffer-multibyte t
))
1269 (goto-char (point-max))
1270 (rmail-set-message-counters)
1271 (rmail-show-message rmail-total-messages
)
1272 (run-hooks 'rmail-mode-hook
)))))
1274 ;; Return a list of files from this buffer's Mail: option.
1275 ;; Does not assume that messages have been parsed.
1276 ;; Just returns nil if buffer does not look like Babyl format.
1277 (defun rmail-parse-file-inboxes ()
1282 (cond ((looking-at "BABYL OPTIONS:")
1283 (search-forward "\n\^_" nil
'move
)
1284 (narrow-to-region 1 (point))
1286 (if (search-forward "\nMail:" nil t
)
1288 (narrow-to-region (point) (progn (end-of-line) (point)))
1289 (goto-char (point-min))
1290 (mail-parse-comma-list))))))))
1292 (defun rmail-expunge-and-save ()
1293 "Expunge and save RMAIL file."
1296 (set-buffer rmail-buffer
)
1298 (if (rmail-summary-exists)
1299 (rmail-select-summary (set-buffer-modified-p nil
))))
1301 (defun rmail-quit ()
1303 Hook `rmail-quit-hook' is run after expunging."
1305 (rmail-expunge-and-save)
1306 (when (boundp 'rmail-quit-hook
)
1307 (run-hooks 'rmail-quit-hook
))
1308 ;; Don't switch to the summary buffer even if it was recently visible.
1309 (when rmail-summary-buffer
1310 (replace-buffer-in-windows rmail-summary-buffer
)
1311 (bury-buffer rmail-summary-buffer
))
1312 (if rmail-enable-mime
1313 (let ((obuf rmail-buffer
)
1314 (ovbuf rmail-view-buffer
))
1315 (set-buffer rmail-view-buffer
)
1317 (replace-buffer-in-windows ovbuf
)
1318 (replace-buffer-in-windows obuf
)
1320 (let ((obuf (current-buffer)))
1322 (replace-buffer-in-windows obuf
))))
1324 (defun rmail-bury ()
1325 "Bury current Rmail buffer and its summary buffer."
1327 ;; This let var was called rmail-buffer, but that interfered
1328 ;; with the buffer-local var used in summary buffers.
1329 (let ((buffer-to-bury (current-buffer)))
1330 (if (rmail-summary-exists)
1332 (while (setq window
(get-buffer-window rmail-summary-buffer
))
1333 (quit-window nil window
))
1334 (bury-buffer rmail-summary-buffer
)))
1337 (defun rmail-duplicate-message ()
1338 "Create a duplicated copy of the current message.
1339 The duplicate copy goes into the Rmail file just after the
1343 (let ((buffer-read-only nil
)
1344 (number rmail-current-message
)
1345 (string (buffer-substring (rmail-msgbeg rmail-current-message
)
1346 (rmail-msgend rmail-current-message
))))
1347 (goto-char (rmail-msgend rmail-current-message
))
1349 (rmail-forget-messages)
1350 (rmail-show-message number
)
1351 (message "Message duplicated")))
1354 (defun rmail-input (filename)
1355 "Run Rmail on file FILENAME."
1356 (interactive "FRun rmail on RMAIL file: ")
1360 ;; This used to scan subdirectories recursively, but someone pointed out
1361 ;; that if the user wants that, person can put all the files in one dir.
1362 ;; And the recursive scan was slow. So I took it out.
1364 (defun rmail-find-all-files (start)
1365 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1366 (if (file-accessible-directory-p start
)
1368 (let* ((case-fold-search t
)
1369 (files (directory-files start t rmail-secondary-file-regexp
)))
1370 ;; Sort here instead of in directory-files
1371 ;; because this list is usually much shorter.
1372 (sort files
'string
<))))
1374 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
1375 (let ((menu (make-sparse-keymap menu-name
)))
1377 (function (lambda (item)
1382 (rmail-list-to-menu (car item
) (cdr item
)
1385 (concat full-name
"/"
1388 (setq name
(car item
)))
1392 (list 'lambda
() '(interactive)
1396 (concat full-name
"/" item
)
1398 rmail-secondary-file-directory
))))))
1399 (define-key menu
(vector (intern name
))
1400 (cons name command
)))))
1404 ;; This command is always "disabled" when it appears in a menu.
1405 (put 'rmail-disable-menu
'menu-enable
''nil
)
1407 (defun rmail-construct-io-menu ()
1408 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1411 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1412 (cons "Input Rmail File"
1413 (rmail-list-to-menu "Input Rmail File"
1416 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1417 (cons "Output Rmail File"
1418 (rmail-list-to-menu "Output Rmail File"
1420 'rmail-output-to-rmail-file
))))
1422 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1423 '("Input Rmail File" . rmail-disable-menu
))
1424 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1425 '("Output Rmail File" . rmail-disable-menu
)))))
1428 ;;;; *** Rmail input ***
1430 ;; RLK feature not added in this version:
1431 ;; argument specifies inbox file or files in various ways.
1433 (defun rmail-get-new-mail (&optional file-name
)
1434 "Move any new mail from this RMAIL file's inbox files.
1435 The inbox files can be specified with the file's Mail: option. The
1436 variable `rmail-primary-inbox-list' specifies the inboxes for your
1437 primary RMAIL file if it has no Mail: option. By default, this is
1438 your /usr/spool/mail/$USER.
1440 You can also specify the file to get new mail from. In this case, the
1441 file of new mail is not changed or deleted. Noninteractively, you can
1442 pass the inbox file name as an argument. Interactively, a prefix
1443 argument causes us to read a file name and use that file as the inbox.
1445 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1446 always be left in inbox files rather than deleted.
1448 This function runs `rmail-get-new-mail-hook' before saving the updated file.
1449 It returns t if it got any new messages."
1451 (list (if current-prefix-arg
1452 (read-file-name "Get new mail from file: "))))
1453 (run-hooks 'rmail-before-get-new-mail-hook
)
1454 ;; If the disk file has been changed from under us,
1455 ;; revert to it before we get new mail.
1456 (or (verify-visited-file-modtime (current-buffer))
1457 (find-file (buffer-file-name)))
1458 (set-buffer rmail-buffer
)
1459 (rmail-maybe-set-message-counters)
1461 ;; Get rid of all undo records for this buffer.
1462 (or (eq buffer-undo-list t
)
1463 (setq buffer-undo-list nil
))
1464 (let ((all-files (if file-name
(list file-name
)
1466 (rmail-enable-multibyte (default-value 'enable-multibyte-characters
))
1471 (let ((opoint (point))
1473 (rsf-number-of-spam 0)
1475 ;; If buffer has not changed yet, and has not been saved yet,
1476 ;; don't replace the old backup file now.
1477 (make-backup-files (and make-backup-files
(buffer-modified-p)))
1478 (buffer-read-only nil
)
1479 ;; Don't make undo records for what we do in getting mail.
1480 (buffer-undo-list t
)
1482 ;; Files to insert this time around.
1484 ;; Last names of those files.
1486 ;; Pull files off all-files onto files
1487 ;; as long as there is no name conflict.
1488 ;; A conflict happens when two inbox file names
1489 ;; have the same last component.
1490 (while (and all-files
1491 (not (member (file-name-nondirectory (car all-files
))
1493 (setq files
(cons (car all-files
) files
)
1495 (cons (file-name-nondirectory (car all-files
)) files
))
1496 (setq all-files
(cdr all-files
)))
1497 ;; Put them back in their original order.
1498 (setq files
(nreverse files
))
1500 (goto-char (point-max))
1501 (skip-chars-backward " \t\n") ; just in case of brain damage
1502 (delete-region (point) (point-max)) ; caused by require-final-newline
1505 (narrow-to-region (point) (point))
1506 ;; Read in the contents of the inbox files,
1507 ;; renaming them as necessary,
1508 ;; and adding to the list of files to delete eventually.
1510 (rmail-insert-inbox-text files nil
)
1511 (setq delete-files
(rmail-insert-inbox-text files t
)))
1512 ;; Scan the new text and convert each message to babyl format.
1513 (goto-char (point-min))
1516 (setq new-messages
(rmail-convert-to-babyl-format)
1518 ;; Try to delete the garbage just inserted.
1519 (or success
(delete-region (point-min) (point-max)))
1520 ;; If we could not convert the file's inboxes,
1521 ;; rename the files we tried to read
1522 ;; so we won't over and over again.
1523 (if (and (not file-name
) (not success
))
1524 (let ((delfiles delete-files
)
1527 (while (file-exists-p (format "RMAILOSE.%d" count
))
1528 (setq count
(1+ count
)))
1529 (rename-file (car delfiles
)
1530 (format "RMAILOSE.%d" count
))
1531 (setq delfiles
(cdr delfiles
))))))
1532 (or (zerop new-messages
)
1535 (search-backward "\n\^_" nil t
)
1536 (narrow-to-region (point) (point-max))
1537 (goto-char (1+ (point-min)))
1538 (rmail-count-new-messages)
1539 (run-hooks 'rmail-get-new-mail-hook
)
1541 ;; Delete the old files, now that babyl file is saved.
1544 ;; First, try deleting.
1546 (delete-file (car delete-files
))
1548 ;; If we can't delete it, truncate it.
1549 (write-region (point) (point) (car delete-files
))))
1551 (setq delete-files
(cdr delete-files
)))))
1552 (if (= new-messages
0)
1553 (progn (goto-char opoint
)
1554 (if (or file-name rmail-inbox-list
)
1555 (message "(No new mail has arrived)")))
1556 ;; check new messages to see if any of them is spam:
1557 (if (and (featurep 'rmail-spam-filter
)
1558 rmail-use-spam-filter
)
1560 ((old-messages (- rmail-total-messages new-messages
))
1561 (rsf-scanned-message-number (1+ old-messages
))
1562 ;; save deletion flags of old messages: vector starts
1563 ;; at zero (is one longer that no of messages),
1564 ;; therefore take 1+ old-messages
1566 (substring rmail-deleted-vector
0 (1+
1568 ;; set all messages to undeleted
1569 (setq rmail-deleted-vector
1570 (make-string (1+ rmail-total-messages
) ?\
))
1571 (while (<= rsf-scanned-message-number
1572 rmail-total-messages
)
1574 (if (not (rmail-spam-filter rsf-scanned-message-number
))
1575 (progn (setq rsf-number-of-spam
(1+ rsf-number-of-spam
)))
1577 (setq rsf-scanned-message-number
(1+ rsf-scanned-message-number
))
1579 (if (> rsf-number-of-spam
0)
1581 (when (rmail-expunge-confirmed)
1582 (rmail-only-expunge t
))
1584 (setq rmail-deleted-vector
1587 (make-string (- rmail-total-messages old-messages
)
1590 (if (rmail-summary-exists)
1591 (rmail-select-summary
1592 (rmail-update-summary)))
1593 (message "%d new message%s read%s"
1594 new-messages
(if (= 1 new-messages
) "" "s")
1595 ;; print out a message on number of spam messages found:
1596 (if (and (featurep 'rmail-spam-filter
)
1597 rmail-use-spam-filter
1598 (> rsf-number-of-spam
0))
1599 (if (= 1 new-messages
)
1600 ", and found to be a spam message"
1601 (if (> rsf-number-of-spam
1)
1602 (format ", %d of which found to be spam messages"
1604 ", one of which found to be a spam message"))
1606 (if (and (featurep 'rmail-spam-filter
)
1607 rmail-use-spam-filter
1608 (> rsf-number-of-spam
0))
1609 (progn (if rsf-beep
(beep t
))
1610 (sleep-for rsf-sleep-after-message
)))
1612 ;; Move to the first new message
1613 ;; unless we have other unseen messages before it.
1614 (rmail-show-message (rmail-first-unseen-message))
1615 (run-hooks 'rmail-after-get-new-mail-hook
)
1618 ;; Don't leave the buffer screwed up if we get a disk-full error.
1619 (or found
(rmail-show-message)))))
1621 (defun rmail-parse-url (file)
1622 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1623 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1624 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1625 a remote mailbox, PASSWORD is the password if it should be
1626 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1627 is non-nil if the user has supplied the password interactively.
1630 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file
)
1631 (let (got-password supplied-password
1632 (proto (match-string 1 file
))
1633 (user (match-string 3 file
))
1634 (pass (match-string 5 file
))
1635 (host (substring file
(or (match-end 2)
1636 (+ 3 (match-end 1))))))
1639 (when rmail-remote-password-required
1640 (setq got-password
(not (rmail-have-password)))
1641 (setq supplied-password
(rmail-get-remote-password
1642 (string-equal proto
"imap")))))
1644 (if (rmail-movemail-variant-p 'emacs
)
1645 (if (string-equal proto
"pop")
1646 (list (concat "po:" user
":" host
)
1648 (or pass supplied-password
)
1650 (error "Emacs movemail does not support %s protocol" proto
))
1652 (or (string-equal proto
"pop") (string-equal proto
"imap"))
1656 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file
)
1657 (let (got-password supplied-password
1659 (user (match-string 1 file
))
1660 (host (match-string 3 file
)))
1662 (when rmail-remote-password-required
1663 (setq got-password
(not (rmail-have-password)))
1664 (setq supplied-password
(rmail-get-remote-password nil
)))
1666 (list file
"pop" supplied-password got-password
)))
1669 (list file nil nil nil
))))
1671 (defun rmail-insert-inbox-text (files renamep
)
1672 ;; Detect a locked file now, so that we avoid moving mail
1673 ;; out of the real inbox file. (That could scare people.)
1674 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1675 (error "RMAIL file %s is locked"
1676 (file-name-nondirectory buffer-file-name
)))
1677 (let (file tofile delete-files movemail popmail got-password password
)
1679 ;; Handle remote mailbox names specially; don't expand as filenames
1680 ;; in case the userid contains a directory separator.
1681 (setq file
(car files
))
1682 (let ((url-data (rmail-parse-url file
)))
1683 (setq file
(nth 0 url-data
))
1684 (setq popmail
(nth 1 url-data
))
1685 (setq password
(nth 2 url-data
))
1686 (setq got-password
(nth 3 url-data
)))
1690 (setq file
(file-truename
1691 (substitute-in-file-name (expand-file-name file
)))))
1692 (setq tofile
(expand-file-name
1693 ;; Generate name to move to from inbox name,
1694 ;; in case of multiple inboxes that need moving.
1696 (file-name-nondirectory
1697 (if (memq system-type
'(windows-nt cygwin
))
1698 ;; cannot have "po:" in file name
1701 ;; Use the directory of this rmail file
1702 ;; because it's a nuisance to use the homedir
1703 ;; if that is on a full disk and this rmail
1705 (file-name-directory
1706 (expand-file-name buffer-file-name
))))
1707 ;; Always use movemail to rename the file,
1708 ;; since there can be mailboxes in various directories.
1711 ;; On some systems, /usr/spool/mail/foo is a directory
1712 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1713 (if (file-directory-p file
)
1714 (setq file
(expand-file-name (user-login-name)
1717 (message "Getting mail from the remote server ..."))
1718 ((and (file-exists-p tofile
)
1719 (/= 0 (nth 7 (file-attributes tofile
))))
1720 (message "Getting mail from %s..." tofile
))
1721 ((and (file-exists-p file
)
1722 (/= 0 (nth 7 (file-attributes file
))))
1723 (message "Getting mail from %s..." file
)))
1724 ;; Set TOFILE if have not already done so, and
1725 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1726 (cond ((not renamep
)
1728 ((or (file-exists-p tofile
) (and (not popmail
)
1729 (not (file-exists-p file
))))
1733 (let ((errors (current-buffer)))
1734 (buffer-disable-undo errors
)
1737 (list (or rmail-movemail-program
1738 (expand-file-name "movemail"
1741 (if rmail-preserve-inbox
1744 (if (rmail-movemail-variant-p 'mailutils
)
1745 (append (list "--emacs") rmail-movemail-flags
)
1746 rmail-movemail-flags
)
1748 (if password
(list password
) nil
))))
1749 (apply 'call-process args
))
1750 (if (not (buffer-modified-p errors
))
1751 ;; No output => movemail won
1754 (subst-char-in-region (point-min) (point-max)
1756 (goto-char (point-max))
1757 (skip-chars-backward " \t")
1758 (delete-region (point) (point-max))
1759 (goto-char (point-min))
1760 (if (looking-at "movemail: ")
1761 (delete-region (point-min) (match-end 0)))
1763 ;; If we just read the password, most likely it is
1764 ;; wrong. Otherwise, see if there is a specific
1765 ;; reason to think that the problem is a wrong passwd.
1766 (if (or got-password
1767 (re-search-forward rmail-remote-password-error
1769 (rmail-set-remote-password nil
))
1771 ;; If using Mailutils, remove initial error code
1773 (when (rmail-movemail-variant-p 'mailutils
)
1774 (goto-char (point-min))
1775 (when (looking-at "[A-Z][A-Z0-9_]*:")
1776 (delete-region (point-min) (match-end 0))))
1778 (message "movemail: %s"
1779 (buffer-substring (point-min)
1785 ;; At this point, TOFILE contains the name to read:
1786 ;; Either the alternate name (if we renamed)
1787 ;; or the actual inbox (if not renaming).
1788 (if (file-exists-p tofile
)
1789 (let ((coding-system-for-read 'no-conversion
)
1791 (goto-char (point-max))
1792 (setq size
(nth 1 (insert-file-contents tofile
)))
1793 (goto-char (point-max))
1794 (or (= (preceding-char) ?
\n)
1797 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
1798 (setq delete-files
(cons tofile delete-files
)))))
1800 (setq files
(cdr files
)))
1803 ;; Decode the region specified by FROM and TO by CODING.
1804 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
1805 (defun rmail-decode-region (from to coding
)
1806 (if (or (not coding
) (not (coding-system-p coding
)))
1807 (setq coding
'undecided
))
1808 ;; Use -dos decoding, to remove ^M characters left from base64 or
1809 ;; rogue qp-encoded text.
1810 (decode-coding-region from to
1811 (coding-system-change-eol-conversion coding
1))
1812 ;; Don't reveal the fact we used -dos decoding, as users generally
1813 ;; will not expect the RMAIL buffer to use DOS EOL format.
1814 (setq buffer-file-coding-system
1815 (setq last-coding-system-used
1816 (coding-system-change-eol-conversion coding
0))))
1818 ;; the rmail-break-forwarded-messages feature is not implemented
1819 (defun rmail-convert-to-babyl-format ()
1820 (let ((count 0) start
1821 (case-fold-search nil
)
1822 (invalid-input-resync
1823 (function (lambda ()
1824 (message "Invalid Babyl format in inbox!")
1826 ;; Try to get back in sync with a real message.
1827 (if (re-search-forward
1828 (concat rmail-mmdf-delim1
"\\|^From") nil t
)
1830 (goto-char (point-max)))))))
1831 (goto-char (point-min))
1834 (setq start
(point))
1835 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1836 (if (search-forward "\n\^_" nil t
)
1837 ;; If we find the proper terminator, delete through there.
1838 (delete-region (point-min) (point))
1839 (funcall invalid-input-resync
)
1840 (delete-region (point-min) (point))))
1841 ;; Babyl format message
1843 (or (search-forward "\n\^_" nil t
)
1844 (funcall invalid-input-resync
))
1845 (setq count
(1+ count
))
1846 ;; Make sure there is no extra white space after the ^_
1847 ;; at the end of the message.
1848 ;; Narrowing will make sure that whatever follows the junk
1849 ;; will be treated properly.
1850 (delete-region (point)
1852 (skip-chars-forward " \t\n")
1860 (if (looking-at "0")
1864 (narrow-to-region (point) (point-max))
1867 (case-fold-search t
)
1868 (quoted-printable-header-field-end
1872 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
1874 (base64-header-field-end
1878 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
1880 (if quoted-printable-header-field-end
1883 (mail-unquote-printable-region header-end
(point) nil t t
)
1884 (message "Malformed MIME quoted-printable message"))
1885 ;; Change "quoted-printable" to "8bit",
1886 ;; to reflect the decoding we just did.
1887 (goto-char quoted-printable-header-field-end
)
1888 (delete-region (point) (search-backward ":"))
1890 (if base64-header-field-end
1895 (base64-decode-region (1+ header-end
)
1899 ;; Change "base64" to "8bit", to reflect the
1900 ;; decoding we just did.
1901 (goto-char base64-header-field-end
)
1902 (delete-region (point) (search-backward ":"))
1903 (insert ": 8bit"))))
1904 (setq last-coding-system-used nil
)
1905 (or rmail-enable-mime
1906 (not rmail-enable-multibyte
)
1908 (if (and rmail-decode-mime-charset
1911 (search-forward "\n\n" nil t
)
1912 (let ((case-fold-search t
))
1914 rmail-mime-charset-pattern
1916 (intern (downcase (match-string 1))))))
1917 (rmail-decode-region start
(point) mime-charset
)))))
1918 ;; Add an X-Coding-System: header if we don't have one.
1922 (if (looking-at "0")
1925 (or (save-restriction
1926 (narrow-to-region (point) (point-max))
1928 (goto-char (point-min))
1929 (re-search-forward "^X-Coding-System:" nil t
))
1930 (insert "X-Coding-System: "
1931 (symbol-name last-coding-system-used
)
1933 (narrow-to-region (point) (point-max))
1934 (and (= 0 (% count
10))
1935 (message "Converting to Babyl format...%d" count
)))
1937 ((let ((case-fold-search t
))
1938 (looking-at rmail-mmdf-delim1
))
1939 (let ((case-fold-search t
))
1940 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1941 (re-search-forward rmail-mmdf-delim2 nil t
)
1942 (replace-match "\^_"))
1945 (narrow-to-region start
(1- (point)))
1946 (goto-char (point-min))
1947 (while (search-forward "\n\^_" nil t
); single char "\^_"
1948 (replace-match "\n^_")))); 2 chars: "^" and "_"
1949 (setq last-coding-system-used nil
)
1950 (or rmail-enable-mime
1951 (not rmail-enable-multibyte
)
1952 (decode-coding-region start
(point) 'undecided
))
1956 (insert "X-Coding-System: "
1957 (symbol-name last-coding-system-used
)
1959 (narrow-to-region (point) (point-max))
1960 (setq count
(1+ count
))
1961 (and (= 0 (% count
10))
1962 (message "Converting to Babyl format...%d" count
)))
1964 ((looking-at "^From ")
1965 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1966 (rmail-nuke-pinhead-header)
1967 ;; If this message has a Content-Length field,
1968 ;; skip to the end of the contents.
1969 (let* ((header-end (save-excursion
1970 (and (re-search-forward "\n\n" nil t
)
1972 (case-fold-search t
)
1973 (quoted-printable-header-field-end
1976 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
1978 (base64-header-field-end
1981 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
1984 ;; Get the numeric value from the Content-Length field.
1986 ;; Back up to end of prev line,
1987 ;; in case the Content-Length field comes first.
1989 (and (search-forward "\ncontent-length: "
1992 (eol (progn (end-of-line) (point))))
1993 (string-to-number (buffer-substring beg eol
)))))))
1995 (if (and (natnump size
)
1996 (<= (+ header-end size
) (point-max))
1997 ;; Make sure this would put us at a position
1998 ;; that we could continue from.
2000 (goto-char (+ header-end size
))
2001 (skip-chars-forward "\n")
2003 (and (looking-at "BABYL OPTIONS:")
2004 (search-forward "\n\^_" nil t
))
2005 (and (looking-at "\^L")
2006 (search-forward "\n\^_" nil t
))
2007 (let ((case-fold-search t
))
2008 (looking-at rmail-mmdf-delim1
))
2009 (looking-at "From "))))
2010 (goto-char (+ header-end size
))
2011 (message "Ignoring invalid Content-Length field")
2013 (if (let ((case-fold-search nil
))
2015 (concat "^[\^_]?\\("
2016 rmail-unix-mail-delimiter
2018 rmail-mmdf-delim1
"\\|"
2019 "^BABYL OPTIONS:\\|"
2020 "\^L\n[01],\\)") nil t
))
2021 (goto-char (match-beginning 1))
2022 (goto-char (point-max)))
2023 (setq count
(1+ count
))
2024 (if quoted-printable-header-field-end
2027 (mail-unquote-printable-region header-end
(point) nil t t
)
2028 (message "Malformed MIME quoted-printable message"))
2029 ;; Change "quoted-printable" to "8bit",
2030 ;; to reflect the decoding we just did.
2031 (goto-char quoted-printable-header-field-end
)
2032 (delete-region (point) (search-backward ":"))
2034 (if base64-header-field-end
2039 (base64-decode-region
2042 ;; Prevent base64-decode-region
2043 ;; from removing newline characters.
2044 (skip-chars-backward "\n\t ")
2048 ;; Change "base64" to "8bit", to reflect the
2049 ;; decoding we just did.
2050 (goto-char base64-header-field-end
)
2051 (delete-region (point) (search-backward ":"))
2052 (insert ": 8bit")))))
2056 (narrow-to-region start
(point))
2057 (goto-char (point-min))
2058 (while (search-forward "\n\^_" nil t
); single char
2059 (replace-match "\n^_")))); 2 chars: "^" and "_"
2060 ;; This is for malformed messages that don't end in newline.
2061 ;; There shouldn't be any, but some users say occasionally
2063 (or (bolp) (newline))
2065 (setq last-coding-system-used nil
)
2066 (or rmail-enable-mime
2067 (not rmail-enable-multibyte
)
2069 (if (and rmail-decode-mime-charset
2072 (search-forward "\n\n" nil t
)
2073 (let ((case-fold-search t
))
2075 rmail-mime-charset-pattern
2077 (intern (downcase (match-string 1))))))
2078 (rmail-decode-region start
(point) mime-charset
)))
2082 (insert "X-Coding-System: "
2083 (symbol-name last-coding-system-used
)
2085 (narrow-to-region (point) (point-max))
2086 (and (= 0 (% count
10))
2087 (message "Converting to Babyl format...%d" count
)))
2089 ;; This kludge is because some versions of sendmail.el
2090 ;; insert an extra newline at the beginning that shouldn't
2091 ;; be there. sendmail.el has been fixed, but old versions
2092 ;; may still be in use. -- rms, 7 May 1993.
2093 ((eolp) (delete-char 1))
2094 (t (error "Cannot convert to babyl format")))))
2097 ;; Delete the "From ..." line, creating various other headers with
2098 ;; information from it if they don't already exist. Now puts the
2099 ;; original line into a mail-from: header line for debugging and for
2100 ;; use by the rmail-output function.
2101 (defun rmail-nuke-pinhead-header ()
2104 (let ((start (point))
2107 (search-forward "\n\n")
2109 (goto-char (point-max))
2113 (narrow-to-region start end
)
2114 (let ((case-fold-search t
))
2116 (setq has-from
(search-forward "\nFrom:" nil t
))
2118 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
2120 (let ((case-fold-search nil
))
2121 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
2125 ;; Keep and reformat the date if we don't
2126 ;; have a Date: field.
2130 "Date: \\2, \\4 \\3 \\9 \\5 "
2132 ;; The timezone could be matched by group 7 or group 10.
2133 ;; If neither of them matched, assume EST, since only
2134 ;; Easterners would be so sloppy.
2135 ;; It's a shame the substitution can't use "\\10".
2137 ((/= (match-beginning 7) (match-end 7)) "\\7")
2138 ((/= (match-beginning 10) (match-end 10))
2139 (buffer-substring (match-beginning 10)
2143 ;; Keep and reformat the sender if we don't
2144 ;; have a From: field.
2150 ;;;; *** Rmail Message Formatting and Header Manipulation ***
2152 (defun rmail-reformat-message (beg end
)
2155 (if (/= (following-char) ?
0)
2156 (error "Bad format in RMAIL file"))
2157 (let ((inhibit-read-only t
)
2158 (delta (- (buffer-size) end
)))
2162 (let ((case-fold-search t
))
2163 (while (looking-at "Summary-line:\\|Mail-From:")
2165 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
2166 (delete-region (point)
2167 (progn (forward-line 1) (point))))
2168 (let ((str (buffer-substring (point)
2169 (save-excursion (search-forward "\n\n" end
'move
)
2171 (insert str
"*** EOOH ***\n")
2172 (narrow-to-region (point) (- (buffer-size) delta
)))
2173 (goto-char (point-min))
2174 (if rmail-message-filter
(funcall rmail-message-filter
))
2175 (if (or rmail-displayed-headers rmail-ignored-headers
)
2176 (rmail-clear-headers))))
2178 (defun rmail-clear-headers (&optional ignored-headers
)
2179 "Delete all header fields that Rmail should not show.
2180 If the optional argument IGNORED-HEADERS is non-nil,
2181 delete all header fields whose names match that regexp.
2182 Otherwise, if `rmail-displayed-headers' is non-nil,
2183 delete all header fields *except* those whose names match that regexp.
2184 Otherwise, delete all header fields whose names match `rmail-ignored-headers'."
2185 (when (search-forward "\n\n" nil t
)
2187 (let ((case-fold-search t
)
2188 (buffer-read-only nil
))
2189 (if (and rmail-displayed-headers
(null ignored-headers
))
2191 (narrow-to-region (point-min) (point))
2193 (goto-char (point-min))
2194 (while (and (not (eobp))
2196 (if (re-search-forward "\n[^ \t]" nil t
)
2197 (setq lim
(match-beginning 0)
2199 (setq lim nil next
(point-max)))))
2201 (re-search-forward rmail-displayed-headers lim t
))
2203 (delete-region (point) next
))))
2204 (goto-char (point-min)))
2205 (or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
2207 (narrow-to-region (point-min) (point))
2208 (while (and ignored-headers
2210 (goto-char (point-min))
2211 (re-search-forward ignored-headers nil t
)))
2213 (delete-region (point)
2214 (if (re-search-forward "\n[^ \t]" nil t
)
2218 (defun rmail-msg-is-pruned ()
2219 (rmail-maybe-set-message-counters)
2221 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2223 (goto-char (point-min))
2225 (= (following-char) ?
1))))
2227 (defun rmail-msg-restore-non-pruned-header ()
2228 (let ((old-point (point))
2231 (inhibit-read-only t
))
2233 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2234 (goto-char (point-min))
2239 ;; Insert new EOOH line at the proper place.
2241 (let ((case-fold-search t
))
2242 (while (looking-at "Summary-Line:\\|Mail-From:")
2244 (insert "*** EOOH ***\n")
2245 (setq new-start
(point))
2246 ;; Delete the old reformatted header.
2248 (search-forward "\n*** EOOH ***\n")
2250 (let ((start (point)))
2251 (search-forward "\n\n")
2252 (if (and (<= start old-point
)
2253 (<= old-point
(point)))
2254 (setq new-point new-start
))
2255 (delete-region start
(point)))
2256 ;; Narrow to after the new EOOH line.
2257 (narrow-to-region new-start
(point-max)))
2259 (goto-char new-point
))))
2261 (defun rmail-msg-prune-header ()
2263 (= (point) (point-min))))
2265 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2266 (rmail-reformat-message (point-min) (point-max)))
2268 (goto-char (point-min)))))
2270 (defun rmail-toggle-header (&optional arg
)
2271 "Show original message header if pruned header currently shown, or vice versa.
2272 With argument ARG, show the message header pruned if ARG is greater than zero;
2273 otherwise, show it in full."
2275 (let* ((pruned (with-current-buffer rmail-buffer
2276 (rmail-msg-is-pruned)))
2278 (> (prefix-numeric-value arg
) 0)
2280 (if (eq pruned prune
)
2282 (set-buffer rmail-buffer
)
2283 (rmail-maybe-set-message-counters)
2284 (if rmail-enable-mime
2285 (let ((buffer-read-only nil
))
2287 (rmail-msg-restore-non-pruned-header)
2288 (rmail-msg-prune-header))
2289 (funcall rmail-show-mime-function
))
2290 (let* ((buffer-read-only nil
)
2291 (window (get-buffer-window (current-buffer)))
2292 (at-point-min (= (point) (point-min)))
2293 (all-headers-visible (= (window-start window
) (point-min)))
2296 (and (not (search-backward "\n\n" nil t
))
2299 (re-search-backward "^[-A-Za-z0-9]+:" nil t
))
2302 (rmail-count-screen-lines (window-start window
) (point))))
2304 (rmail-msg-restore-non-pruned-header)
2305 (rmail-msg-prune-header))
2307 (goto-char (point-min)))
2309 (goto-char (point-min))
2310 (search-forward "\n\n")
2311 (or (re-search-backward
2312 (concat "^" (regexp-quote on-header
)) nil t
)
2313 (goto-char (point-min))))
2315 (save-selected-window
2316 (select-window window
)
2317 (recenter old-screen-line
)
2318 (if (and all-headers-visible
2319 (not (= (window-start) (point-min))))
2320 (recenter (- (window-height) 2))))))))
2321 (rmail-highlight-headers))))
2323 (defun rmail-narrow-to-non-pruned-header ()
2324 "Narrow to the whole (original) header of the current message."
2326 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2327 (goto-char (point-min))
2329 (if (= (following-char) ?
1)
2332 (setq start
(point))
2333 (search-forward "*** EOOH ***\n")
2334 (setq end
(match-beginning 0)))
2336 (setq start
(point))
2337 (search-forward "\n\n")
2338 (setq end
(1- (point))))
2339 (narrow-to-region start end
)
2342 ;; Lifted from repos-count-screen-lines.
2343 ;; Return number of screen lines between START and END.
2344 (defun rmail-count-screen-lines (start end
)
2347 (narrow-to-region start end
)
2348 (goto-char (point-min))
2349 (vertical-motion (- (point-max) (point-min))))))
2351 ;;;; *** Rmail Attributes and Keywords ***
2353 ;; Make a string describing current message's attributes and keywords
2354 ;; and set it up as the name of a minor mode
2355 ;; so it will appear in the mode line.
2356 (defun rmail-display-labels ()
2357 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
2362 (goto-char (rmail-msgbeg rmail-current-message
))
2364 (if (looking-at "[01],")
2366 (narrow-to-region (point) (progn (end-of-line) (point)))
2367 ;; Truly valid BABYL format requires a space before each
2368 ;; attribute or keyword name. Put them in if missing.
2369 (let (buffer-read-only)
2370 (goto-char (point-min))
2371 (while (search-forward "," nil t
)
2372 (or (looking-at "[ ,]") (eobp)
2374 (goto-char (point-max))
2375 (if (search-backward ",," nil
'move
)
2377 (if (> (point) (1+ (point-min)))
2378 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
2379 (if (> (- (point-max) (point)) 2)
2383 (buffer-substring (+ (point) 3)
2384 (1- (point-max)))))))))))
2385 ;; Note: we don't use save-restriction because that does not work right
2386 ;; if changes are made outside the saved restriction
2387 ;; before that restriction is restored.
2388 (narrow-to-region beg end
)
2389 (set-marker beg nil
)
2390 (set-marker end nil
)))
2391 (while (string-match " +," blurb
)
2392 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2393 (substring blurb
(match-end 0)))))
2394 (while (string-match ", +" blurb
)
2395 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2396 (substring blurb
(match-end 0)))))
2397 (setq mode-line-process
2399 rmail-current-message rmail-total-messages blurb
))
2400 ;; If rmail-enable-mime is non-nil, we may have to update
2401 ;; `mode-line-process' of rmail-view-buffer too.
2402 (if (and rmail-enable-mime
2403 (not (eq (current-buffer) rmail-view-buffer
))
2404 (buffer-live-p rmail-view-buffer
))
2405 (let ((mlp mode-line-process
))
2406 (with-current-buffer rmail-view-buffer
2407 (setq mode-line-process mlp
))))))
2409 ;; Turn an attribute of a message on or off according to STATE.
2410 ;; ATTR is the name of the attribute, as a string.
2411 ;; MSGNUM is message number to change; nil means current message.
2412 (defun rmail-set-attribute (attr state
&optional msgnum
)
2413 (set-buffer rmail-buffer
)
2414 (let ((omax (point-max-marker))
2415 (omin (point-min-marker))
2416 (buffer-read-only nil
))
2417 (or msgnum
(setq msgnum rmail-current-message
))
2422 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
2425 (null (search-backward (concat ", " attr
",")
2426 (prog1 (point) (end-of-line)) t
)))))
2427 (or (eq curstate
(not (not state
)))
2429 (delete-region (point) (1- (match-end 0)))
2432 (insert " " attr
","))))
2433 (if (string= attr
"deleted")
2434 (rmail-set-message-deleted-p msgnum state
)))
2435 ;; Note: we don't use save-restriction because that does not work right
2436 ;; if changes are made outside the saved restriction
2437 ;; before that restriction is restored.
2438 (narrow-to-region omin omax
)
2439 (set-marker omin nil
)
2440 (set-marker omax nil
)
2441 (if (= msgnum rmail-current-message
)
2442 (rmail-display-labels))))))
2444 ;; Return t if the attributes/keywords line of msg number MSG
2445 ;; contains a match for the regexp LABELS.
2446 (defun rmail-message-labels-p (msg labels
)
2450 (goto-char (rmail-msgbeg msg
))
2452 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
2454 ;;;; *** Rmail Message Selection And Support ***
2456 (defun rmail-msgend (n)
2457 (marker-position (aref rmail-message-vector
(1+ n
))))
2459 (defun rmail-msgbeg (n)
2460 (marker-position (aref rmail-message-vector n
)))
2462 (defun rmail-widen-to-current-msgbeg (function)
2463 "Call FUNCTION with point at start of internal data of current message.
2464 Assumes that bounds were previously narrowed to display the message in Rmail.
2465 The bounds are widened enough to move point where desired, then narrowed
2468 FUNCTION may not change the visible text of the message, but it may
2469 change the invisible header text."
2473 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2475 (goto-char (point-min))
2477 ;; Note: we don't use save-restriction because that does not work right
2478 ;; if changes are made outside the saved restriction
2479 ;; before that restriction is restored.
2480 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2481 (rmail-msgend rmail-current-message
)))))
2483 (defun rmail-forget-messages ()
2485 (if (vectorp rmail-message-vector
)
2487 (v rmail-message-vector
)
2490 (move-marker (aref v i
) nil
)
2492 (setq rmail-message-vector nil
)
2493 (setq rmail-msgref-vector nil
)
2494 (setq rmail-deleted-vector nil
)))
2496 (defun rmail-maybe-set-message-counters ()
2497 (if (not (and rmail-deleted-vector
2498 rmail-message-vector
2499 rmail-current-message
2500 rmail-total-messages
))
2501 (rmail-set-message-counters)))
2503 (defun rmail-count-new-messages (&optional nomsg
)
2504 (let* ((case-fold-search nil
)
2508 (or nomsg
(message "Counting new messages..."))
2509 (goto-char (point-max))
2510 ;; Put at the end of messages-head
2511 ;; the entry for message N+1, which marks
2512 ;; the end of message N. (N = number of messages).
2513 (search-backward "\n\^_")
2515 (setq messages-head
(list (point-marker)))
2516 (rmail-set-message-counters-counter (point-min))
2517 (setq rmail-current-message
(1+ rmail-total-messages
))
2518 (setq rmail-total-messages
2519 (+ rmail-total-messages total-messages
))
2520 (setq rmail-message-vector
2521 (vconcat rmail-message-vector
(cdr messages-head
)))
2522 (aset rmail-message-vector
2523 rmail-current-message
(car messages-head
))
2524 (setq rmail-deleted-vector
2525 (concat rmail-deleted-vector deleted-head
))
2526 (setq rmail-summary-vector
2527 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
2528 (setq rmail-msgref-vector
2529 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
2530 ;; Fill in the new elements of rmail-msgref-vector.
2531 (let ((i (1+ (- rmail-total-messages total-messages
))))
2532 (while (<= i rmail-total-messages
)
2533 (aset rmail-msgref-vector i
(list i
))
2535 (goto-char (point-min))
2536 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
2538 (defun rmail-set-message-counters ()
2539 (rmail-forget-messages)
2543 (let* ((point-save (point))
2545 (messages-after-point)
2546 (case-fold-search nil
)
2549 (message "Counting messages...")
2550 (goto-char (point-max))
2551 ;; Put at the end of messages-head
2552 ;; the entry for message N+1, which marks
2553 ;; the end of message N. (N = number of messages).
2554 (search-backward "\n\^_" nil t
)
2555 (if (/= (point) (point-max)) (forward-char 1))
2556 (setq messages-head
(list (point-marker)))
2557 (rmail-set-message-counters-counter (min (point) point-save
))
2558 (setq messages-after-point total-messages
)
2559 (rmail-set-message-counters-counter)
2560 (setq rmail-total-messages total-messages
)
2561 (setq rmail-current-message
2563 (max 1 (- total-messages messages-after-point
))))
2564 (setq rmail-message-vector
2565 (apply 'vector
(cons (point-min-marker) messages-head
))
2566 rmail-deleted-vector
(concat "0" deleted-head
)
2567 rmail-summary-vector
(make-vector rmail-total-messages nil
)
2568 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
2570 (while (<= i rmail-total-messages
)
2571 (aset rmail-msgref-vector i
(list i
))
2573 (message "Counting messages...done")))))
2575 (defun rmail-set-message-counters-counter (&optional stop
)
2576 (let ((start (point))
2578 (while (search-backward "\n\^_\^L" stop t
)
2579 ;; Detect messages that have been added with DOS line endings and
2580 ;; convert the line endings for such messages.
2582 (if (looking-at "\n\^_\^L\r\n")
2583 (let ((buffer-read-only nil
)
2585 (message "Counting messages...(converting line endings)")
2588 (while (search-backward "\r\n" next t
)
2592 (setq messages-head
(cons (point-marker) messages-head
))
2595 (cons (if (search-backward ", deleted,"
2601 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
2602 (message "Counting messages...%d" total-messages
)))))
2604 (defun rmail-beginning-of-message ()
2605 "Show current message starting from the beginning."
2607 (rmail-show-message rmail-current-message
))
2609 (defun rmail-unknown-mail-followup-to ()
2610 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2611 Ask the user whether to add that list name to `mail-mailing-lists'."
2613 (rmail-narrow-to-non-pruned-header)
2614 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t
)))
2615 (when mail-followup-to
2618 (mail-strip-quoted-names mail-followup-to
)
2619 ",[[:space:]]+" t
)))
2620 (dolist (addr addresses
)
2621 (when (and (not (member addr mail-mailing-lists
))
2623 ;; taken from rmailsum.el
2625 (or rmail-user-mail-address-regexp
2627 (regexp-quote (user-login-name))
2630 (or user-mail-address
2631 (concat (user-login-name) "@"
2632 (or mail-host-address
2637 (format "Add `%s' to `mail-mailing-lists'? "
2639 (customize-save-variable 'mail-mailing-lists
2640 (cons addr mail-mailing-lists
)))))))))
2642 (defun rmail-show-message (&optional n no-summary
)
2643 "Show message number N (prefix argument), counting from start of file.
2644 If summary buffer is currently displayed, update current message there also."
2646 (or (eq major-mode
'rmail-mode
)
2647 (switch-to-buffer rmail-buffer
))
2648 (rmail-maybe-set-message-counters)
2650 (if (zerop rmail-total-messages
)
2651 (progn (narrow-to-region (point-min) (1- (point-max)))
2652 (goto-char (point-min))
2653 (setq mode-line-process nil
))
2654 (let (blurb coding-system
)
2656 (setq n rmail-current-message
)
2659 rmail-current-message
1
2660 blurb
"No previous message"))
2661 ((> n rmail-total-messages
)
2662 (setq n rmail-total-messages
2663 rmail-current-message rmail-total-messages
2664 blurb
"No following message"))
2666 (setq rmail-current-message n
))))
2667 (let ((beg (rmail-msgbeg n
)))
2671 (let ((end (rmail-msgend n
)))
2673 (if (prog1 (= (following-char) ?
0)
2675 ;; If there's a Summary-line in the (otherwise empty)
2676 ;; header, we didn't yet get past the EOOH line.
2677 (if (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
2679 (narrow-to-region (point) end
))
2681 (search-forward "\n*** EOOH ***\n" end t
))
2682 (narrow-to-region beg
(point))
2683 (goto-char (point-min))
2684 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2685 (let ((coding-system (intern (match-string 1))))
2688 (check-coding-system coding-system
)
2689 (setq buffer-file-coding-system coding-system
))
2691 (setq buffer-file-coding-system nil
))))
2692 (setq buffer-file-coding-system nil
)))))
2693 ;; Clear the "unseen" attribute when we show a message.
2694 (rmail-set-attribute "unseen" nil
)
2695 (let ((end (rmail-msgend n
)))
2696 ;; Reformat the header, or else find the reformatted header.
2697 (if (= (following-char) ?
0)
2698 (rmail-reformat-message beg end
)
2699 (search-forward "\n*** EOOH ***\n" end t
)
2700 (narrow-to-region (point) end
)))
2701 (goto-char (point-min))
2703 (function (lambda (window)
2704 (if (eq (window-buffer window
) (current-buffer))
2705 (set-window-point window
(point)))))
2707 (rmail-display-labels)
2708 (if (eq rmail-enable-mime t
)
2709 (funcall rmail-show-mime-function
)
2710 (setq rmail-view-buffer rmail-buffer
))
2711 (when mail-mailing-lists
2712 (rmail-unknown-mail-followup-to))
2713 (rmail-highlight-headers)
2714 (if transient-mark-mode
(deactivate-mark))
2715 (run-hooks 'rmail-show-message-hook
)
2716 ;; If there is a summary buffer, try to move to this message
2717 ;; in that buffer. But don't complain if this message
2718 ;; is not mentioned in the summary.
2719 ;; Don't do this at all if we were called on behalf
2720 ;; of cursor motion in the summary buffer.
2721 (and (rmail-summary-exists) (not no-summary
)
2722 (let ((curr-msg rmail-current-message
))
2723 (rmail-select-summary
2724 (rmail-summary-goto-msg curr-msg t t
))))
2725 (with-current-buffer rmail-buffer
2728 (message blurb
))))))
2730 (defun rmail-redecode-body (coding)
2731 "Decode the body of the current message using coding system CODING.
2732 This is useful with mail messages that have malformed or missing
2735 This function assumes that the current message is already decoded
2736 and displayed in the RMAIL buffer, but the coding system used to
2737 decode it was incorrect. It then encodes the message back to its
2738 original form, and decodes it again, using the coding system CODING.
2740 Note that if Emacs erroneously auto-detected one of the iso-2022
2741 encodings in the message, this function might fail because the escape
2742 sequences that switch between character sets and also single-shift and
2743 locking-shift codes are impossible to recover. This function is meant
2744 to be used to fix messages encoded with 8-bit encodings, such as
2745 iso-8859, koi8-r, etc."
2746 (interactive "zCoding system for re-decoding this message: ")
2747 (when (not rmail-enable-mime
)
2748 (or (eq major-mode
'rmail-mode
)
2749 (switch-to-buffer rmail-buffer
))
2751 (let ((pruned (rmail-msg-is-pruned)))
2753 (let ((msgbeg (rmail-msgbeg rmail-current-message
))
2754 (msgend (rmail-msgend rmail-current-message
))
2756 ;; We need the message headers pruned (we later restore
2757 ;; the pruned stat to what it was, see the end of
2758 ;; unwind-protect form).
2760 (rmail-toggle-header 1))
2761 (narrow-to-region msgbeg msgend
)
2762 (goto-char (point-min))
2763 (when (search-forward "\n*** EOOH ***\n" (point-max) t
)
2764 (narrow-to-region msgbeg
(point)))
2765 (goto-char (point-min))
2766 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2767 (let ((old-coding (intern (match-string 1)))
2768 (buffer-read-only nil
))
2769 (check-coding-system old-coding
)
2770 ;; Make sure the new coding system uses the same EOL
2771 ;; conversion, to prevent ^M characters from popping
2772 ;; up all over the place.
2774 (coding-system-change-eol-conversion
2776 (coding-system-eol-type old-coding
)))
2777 (setq x-coding-header
(point-marker))
2778 (narrow-to-region msgbeg msgend
)
2779 (encode-coding-region (point) msgend old-coding
)
2780 (decode-coding-region (point) msgend coding
)
2781 (setq last-coding-system-used coding
)
2782 ;; Rewrite the coding-system header according
2784 (goto-char x-coding-header
)
2785 (delete-region (point)
2789 (insert "X-Coding-System: "
2790 (symbol-name last-coding-system-used
))
2791 (set-marker x-coding-header nil
)
2792 (rmail-show-message))
2793 (error "No X-Coding-System header found")))
2795 (rmail-toggle-header 0)))))))
2797 ;; Find all occurrences of certain fields, and highlight them.
2798 (defun rmail-highlight-headers ()
2799 ;; Do this only if the system supports faces.
2800 (if (and (fboundp 'internal-find-face
)
2801 rmail-highlighted-headers
)
2803 (search-forward "\n\n" nil
'move
)
2805 (narrow-to-region (point-min) (point))
2806 (let ((case-fold-search t
)
2807 (inhibit-read-only t
)
2808 ;; Highlight with boldface if that is available.
2809 ;; Otherwise use the `highlight' face.
2810 (face (or rmail-highlight-face
2811 (if (face-differs-from-default-p 'bold
)
2813 ;; List of overlays to reuse.
2814 (overlays rmail-overlay-list
))
2815 (goto-char (point-min))
2816 (while (re-search-forward rmail-highlighted-headers nil t
)
2817 (skip-chars-forward " \t")
2820 (while (progn (forward-line 1)
2821 (looking-at "[ \t]")))
2822 ;; Back up over newline, then trailing spaces or tabs
2824 (while (member (preceding-char) '(? ?
\t))
2827 ;; Reuse an overlay we already have.
2829 (setq overlay
(car overlays
)
2830 overlays
(cdr overlays
))
2831 (overlay-put overlay
'face face
)
2832 (move-overlay overlay beg
(point)))
2833 ;; Make a new overlay and add it to
2834 ;; rmail-overlay-list.
2835 (setq overlay
(make-overlay beg
(point)))
2836 (overlay-put overlay
'face face
)
2837 (setq rmail-overlay-list
2838 (cons overlay rmail-overlay-list
))))))))))
2840 (defun rmail-auto-file ()
2841 "Automatically move a message into a sub-folder based on criteria.
2842 Called when a new message is displayed."
2843 (if (or (rmail-message-labels-p rmail-current-message
"filed")
2844 (not (string= (buffer-file-name)
2845 (expand-file-name rmail-file-name
))))
2846 ;; Do nothing if it's already been filed.
2848 ;; Find out some basics (common fields)
2849 (let ((from (mail-fetch-field "from"))
2850 (subj (mail-fetch-field "subject"))
2851 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
2852 (d rmail-automatic-folder-directives
)
2853 (directive-loop nil
)
2856 (setq folder
(car (car d
))
2857 directive-loop
(cdr (car d
)))
2858 (while (and (car directive-loop
)
2860 ((string= (car directive-loop
) "from") from
)
2861 ((string= (car directive-loop
) "to") to
)
2862 ((string= (car directive-loop
) "subject") subj
)
2863 (t (mail-fetch-field (car directive-loop
))))))
2864 (and f
(string-match (car (cdr directive-loop
)) f
))))
2865 (setq directive-loop
(cdr (cdr directive-loop
))))
2866 ;; If there are no directives left, then it was a complete match.
2867 (if (null directive-loop
)
2869 (rmail-delete-forward)
2870 (if (string= "/dev/null" folder
)
2871 (rmail-delete-message)
2872 (rmail-output-to-rmail-file folder
1 t
)
2874 (setq d
(cdr d
))))))
2876 (defun rmail-next-message (n)
2877 "Show following message whether deleted or not.
2878 With prefix arg N, moves forward N messages, or backward if N is negative."
2880 (set-buffer rmail-buffer
)
2881 (rmail-maybe-set-message-counters)
2882 (rmail-show-message (+ rmail-current-message n
)))
2884 (defun rmail-previous-message (n)
2885 "Show previous message whether deleted or not.
2886 With prefix arg N, moves backward N messages, or forward if N is negative."
2888 (rmail-next-message (- n
)))
2890 (defun rmail-next-undeleted-message (n)
2891 "Show following non-deleted message.
2892 With prefix arg N, moves forward N non-deleted messages,
2893 or backward if N is negative.
2895 Returns t if a new message is being shown, nil otherwise."
2897 (set-buffer rmail-buffer
)
2898 (rmail-maybe-set-message-counters)
2899 (let ((lastwin rmail-current-message
)
2900 (current rmail-current-message
))
2901 (while (and (> n
0) (< current rmail-total-messages
))
2902 (setq current
(1+ current
))
2903 (if (not (rmail-message-deleted-p current
))
2904 (setq lastwin current n
(1- n
))))
2905 (while (and (< n
0) (> current
1))
2906 (setq current
(1- current
))
2907 (if (not (rmail-message-deleted-p current
))
2908 (setq lastwin current n
(1+ n
))))
2909 (if (/= lastwin rmail-current-message
)
2910 (progn (rmail-show-message lastwin
)
2913 (message "No previous nondeleted message"))
2915 (message "No following nondeleted message"))
2918 (defun rmail-previous-undeleted-message (n)
2919 "Show previous non-deleted message.
2920 With prefix argument N, moves backward N non-deleted messages,
2921 or forward if N is negative."
2923 (rmail-next-undeleted-message (- n
)))
2925 (defun rmail-first-message ()
2926 "Show first message in file."
2928 (rmail-maybe-set-message-counters)
2929 (rmail-show-message 1))
2931 (defun rmail-last-message ()
2932 "Show last message in file."
2934 (rmail-maybe-set-message-counters)
2935 (rmail-show-message rmail-total-messages
))
2937 (defun rmail-what-message ()
2938 (let ((where (point))
2940 (high rmail-total-messages
)
2941 (mid (/ rmail-total-messages
2)))
2942 (while (> (- high low
) 1)
2943 (if (>= where
(rmail-msgbeg mid
))
2946 (setq mid
(+ low
(/ (- high low
) 2))))
2947 (if (>= where
(rmail-msgbeg high
)) high low
)))
2949 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
2951 (goto-char (rmail-msgbeg msg
))
2952 (search-forward "\n*** EOOH ***\n")
2953 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
2954 (or (string-match recipients
(or (mail-fetch-field "To") ""))
2955 (string-match recipients
(or (mail-fetch-field "From") ""))
2956 (if (not primary-only
)
2957 (string-match recipients
(or (mail-fetch-field "Cc") ""))))))
2959 (defun rmail-message-regexp-p (n regexp
)
2960 "Return t, if for message number N, regexp REGEXP matches in the header."
2961 (let ((beg (rmail-msgbeg n
))
2962 (end (rmail-msgend n
)))
2967 (if (prog1 (= (following-char) ?
0)
2969 ;; If there's a Summary-line in the (otherwise empty)
2970 ;; header, we didn't yet get past the EOOH line.
2971 (when (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
2974 (narrow-to-region (point) end
))
2979 (search-forward "\n*** EOOH ***\n" end t
)
2980 (setq end
(1+ (match-beginning 0)))))
2982 (if rmail-enable-mime
2983 (funcall rmail-search-mime-header-function n regexp end
)
2984 (re-search-forward regexp end t
)))))
2986 (defun rmail-search-message (msg regexp
)
2987 "Return non-nil, if for message number MSG, regexp REGEXP matches."
2988 (goto-char (rmail-msgbeg msg
))
2989 (if rmail-enable-mime
2990 (funcall rmail-search-mime-message-function msg regexp
)
2991 (re-search-forward regexp
(rmail-msgend msg
) t
)))
2993 (defvar rmail-search-last-regexp nil
)
2994 (defun rmail-search (regexp &optional n
)
2995 "Show message containing next match for REGEXP (but not the current msg).
2996 Prefix argument gives repeat count; negative argument means search
2997 backwards (through earlier messages).
2998 Interactively, empty argument means use same regexp used last time."
3000 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
3002 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
3004 (if rmail-search-last-regexp
3005 (setq prompt
(concat prompt
3007 rmail-search-last-regexp
3009 (setq regexp
(read-string prompt
))
3010 (cond ((not (equal regexp
""))
3011 (setq rmail-search-last-regexp regexp
))
3012 ((not rmail-search-last-regexp
)
3013 (error "No previous Rmail search string")))
3014 (list rmail-search-last-regexp
3015 (prefix-numeric-value current-prefix-arg
))))
3017 (message "%sRmail search for %s..."
3018 (if (< n
0) "Reverse " "")
3020 (set-buffer rmail-buffer
)
3021 (rmail-maybe-set-message-counters)
3022 (let ((omin (point-min))
3027 (msg rmail-current-message
))
3032 ;; Check messages one by one, advancing message number up or down
3033 ;; but searching forward through each message.
3035 (while (and (null win
) (> msg
1))
3037 win
(rmail-search-message msg regexp
)))
3038 (while (and (null win
) (< msg rmail-total-messages
))
3040 win
(rmail-search-message msg regexp
))))
3041 (setq n
(+ n
(if reversep
1 -
1)))))
3044 (rmail-show-message msg
)
3045 ;; Search forward (if this is a normal search) or backward
3046 ;; (if this is a reverse search) through this message to
3047 ;; position point. This search may fail because REGEXP
3048 ;; was found in the hidden portion of this message. In
3049 ;; that case, move point to the beginning of visible
3053 (goto-char (point-max))
3054 (re-search-backward regexp nil
'move
))
3055 (goto-char (point-min))
3056 (re-search-forward regexp nil t
))
3057 (message "%sRmail search for %s...done"
3058 (if reversep
"Reverse " "")
3061 (narrow-to-region omin omax
)
3063 (message "Search failed: %s" regexp
)))))
3065 (defun rmail-search-backwards (regexp &optional n
)
3066 "Show message containing previous match for REGEXP.
3067 Prefix argument gives repeat count; negative argument means search
3068 forward (through later messages).
3069 Interactively, empty argument means use same regexp used last time."
3071 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
3073 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
3075 (if rmail-search-last-regexp
3076 (setq prompt
(concat prompt
3078 rmail-search-last-regexp
3080 (setq regexp
(read-string prompt
))
3081 (cond ((not (equal regexp
""))
3082 (setq rmail-search-last-regexp regexp
))
3083 ((not rmail-search-last-regexp
)
3084 (error "No previous Rmail search string")))
3085 (list rmail-search-last-regexp
3086 (prefix-numeric-value current-prefix-arg
))))
3087 (rmail-search regexp
(- (or n
1))))
3089 ;; Show the first message which has the `unseen' attribute.
3090 (defun rmail-first-unseen-message ()
3091 (rmail-maybe-set-message-counters)
3096 (while (and (not found
) (<= current rmail-total-messages
))
3097 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
3098 (setq found current
))
3099 (setq current
(1+ current
))))
3100 ;; Let the caller show the message.
3102 ;; (rmail-show-message found))
3105 (defun rmail-next-same-subject (n)
3106 "Go to the next mail message having the same subject header.
3107 With prefix argument N, do this N times.
3108 If N is negative, go backwards instead."
3110 (let ((subject (mail-fetch-field "Subject"))
3112 (i rmail-current-message
)
3113 (case-fold-search t
)
3114 search-regexp found
)
3115 (if (string-match "\\`[ \t]+" subject
)
3116 (setq subject
(substring subject
(match-end 0))))
3117 (if (string-match "Re:[ \t]*" subject
)
3118 (setq subject
(substring subject
(match-end 0))))
3119 (if (string-match "[ \t]+\\'" subject
)
3120 (setq subject
(substring subject
0 (match-beginning 0))))
3121 (setq search-regexp
(concat "^Subject: *\\(Re:[ \t]*\\)?"
3122 (regexp-quote subject
)
3127 (while (and (/= n
0)
3129 (< i rmail-total-messages
)
3132 (while (and (not done
)
3134 (< i rmail-total-messages
)
3136 (setq i
(if forward
(1+ i
) (1- i
)))
3137 (goto-char (rmail-msgbeg i
))
3138 (search-forward "\n*** EOOH ***\n")
3139 (let ((beg (point)) end
)
3140 (search-forward "\n\n")
3143 (setq done
(re-search-forward search-regexp end t
))))
3144 (if done
(setq found i
)))
3145 (setq n
(if forward
(1- n
) (1+ n
))))))
3147 (rmail-show-message found
)
3148 (error "No %s message with same subject"
3149 (if forward
"following" "previous")))))
3151 (defun rmail-previous-same-subject (n)
3152 "Go to the previous mail message having the same subject header.
3153 With prefix argument N, do this N times.
3154 If N is negative, go forwards instead."
3156 (rmail-next-same-subject (- n
)))
3158 ;;;; *** Rmail Message Deletion Commands ***
3160 (defun rmail-message-deleted-p (n)
3161 (= (aref rmail-deleted-vector n
) ?D
))
3163 (defun rmail-set-message-deleted-p (n state
)
3164 (aset rmail-deleted-vector n
(if state ?D ?\
)))
3166 (defun rmail-delete-message ()
3167 "Delete this message and stay on it."
3169 (rmail-set-attribute "deleted" t
)
3170 (run-hooks 'rmail-delete-message-hook
))
3172 (defun rmail-undelete-previous-message ()
3173 "Back up to deleted message, select it, and undelete it."
3175 (set-buffer rmail-buffer
)
3176 (let ((msg rmail-current-message
))
3177 (while (and (> msg
0)
3178 (not (rmail-message-deleted-p msg
)))
3179 (setq msg
(1- msg
)))
3181 (error "No previous deleted message")
3182 (if (/= msg rmail-current-message
)
3183 (rmail-show-message msg
))
3184 (rmail-set-attribute "deleted" nil
)
3185 (if (rmail-summary-exists)
3187 (set-buffer rmail-summary-buffer
)
3188 (rmail-summary-mark-undeleted msg
)))
3189 (rmail-maybe-display-summary))))
3191 (defun rmail-delete-forward (&optional backward
)
3192 "Delete this message and move to next nondeleted one.
3193 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
3194 With prefix argument, delete and move backward.
3196 Returns t if a new message is displayed after the delete, or nil otherwise."
3198 (rmail-set-attribute "deleted" t
)
3199 (run-hooks 'rmail-delete-message-hook
)
3200 (let ((del-msg rmail-current-message
))
3201 (if (rmail-summary-exists)
3202 (rmail-select-summary
3203 (rmail-summary-mark-deleted del-msg
)))
3204 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
3205 (rmail-maybe-display-summary))))
3207 (defun rmail-delete-backward ()
3208 "Delete this message and move to previous nondeleted one.
3209 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
3211 (rmail-delete-forward t
))
3213 ;; Compute the message number a given message would have after expunging.
3214 ;; The present number of the message is OLDNUM.
3215 ;; DELETEDVEC should be rmail-deleted-vector.
3216 ;; The value is nil for a message that would be deleted.
3217 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
3218 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
3223 (if (/= (aref deletedvec i
) ?D
)
3224 (setq newnum
(1+ newnum
)))
3228 (defun rmail-expunge-confirmed ()
3229 "Return t if deleted message should be expunged. If necessary, ask the user.
3230 See also user-option `rmail-confirm-expunge'."
3231 (set-buffer rmail-buffer
)
3232 (or (not (stringp rmail-deleted-vector
))
3233 (not (string-match "D" rmail-deleted-vector
))
3234 (null rmail-confirm-expunge
)
3235 (funcall rmail-confirm-expunge
3236 "Erase deleted messages from Rmail file? ")))
3238 (defun rmail-only-expunge (&optional dont-show
)
3239 "Actually erase all deleted messages in the file."
3241 (set-buffer rmail-buffer
)
3242 (message "Expunging deleted messages...")
3243 ;; Discard all undo records for this buffer.
3244 (or (eq buffer-undo-list t
)
3245 (setq buffer-undo-list nil
))
3246 (rmail-maybe-set-message-counters)
3247 (let* ((omax (- (buffer-size) (point-max)))
3248 (omin (- (buffer-size) (point-min)))
3249 (opoint (if (and (> rmail-current-message
0)
3250 (rmail-message-deleted-p rmail-current-message
))
3252 (if rmail-enable-mime
3253 (with-current-buffer rmail-view-buffer
3254 (- (point)(point-min)))
3255 (- (point) (point-min)))))
3256 (messages-head (cons (aref rmail-message-vector
0) nil
))
3257 (messages-tail messages-head
)
3258 ;; Don't make any undo records for the expunging.
3259 (buffer-undo-list t
)
3264 (goto-char (point-min))
3267 (total rmail-total-messages
)
3268 (new-message-number rmail-current-message
)
3270 (new-msgref (list (list 0)))
3271 (rmailbuf (current-buffer))
3272 (buffer-read-only nil
)
3273 (messages rmail-message-vector
)
3274 (deleted rmail-deleted-vector
)
3275 (summary rmail-summary-vector
))
3276 (setq rmail-total-messages nil
3277 rmail-current-message nil
3278 rmail-message-vector nil
3279 rmail-deleted-vector nil
3280 rmail-summary-vector nil
)
3282 (while (<= number total
)
3283 (if (= (aref deleted number
) ?D
)
3286 (marker-position (aref messages number
))
3287 (marker-position (aref messages
(1+ number
))))
3288 (move-marker (aref messages number
) nil
)
3289 (if (> new-message-number counter
)
3290 (setq new-message-number
(1- new-message-number
))))
3291 (setq counter
(1+ counter
))
3293 (setcdr messages-tail
3294 (cons (aref messages number
) nil
)))
3296 (cons (if (= counter number
) (aref summary
(1- number
)))
3299 (cons (aref rmail-msgref-vector number
)
3301 (setcar (car new-msgref
) counter
))
3302 (if (zerop (%
(setq number
(1+ number
)) 20))
3303 (message "Expunging deleted messages...%d" number
)))
3305 (setcdr messages-tail
3306 (cons (aref messages number
) nil
)))
3307 (setq rmail-current-message new-message-number
3308 rmail-total-messages counter
3309 rmail-message-vector
(apply 'vector messages-head
)
3310 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
3311 rmail-summary-vector
(vconcat (nreverse new-summary
))
3312 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
3314 (message "Expunging deleted messages...done")
3316 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
3319 (if (zerop rmail-current-message
) 1 nil
)
3320 (if rmail-enable-mime
3321 (goto-char (+ (point-min) opoint
))
3322 (goto-char (+ (point) opoint
))))))))
3324 (defun rmail-expunge ()
3325 "Erase deleted messages from Rmail file and summary buffer."
3327 (when (rmail-expunge-confirmed)
3328 (rmail-only-expunge)
3329 (if (rmail-summary-exists)
3330 (rmail-select-summary (rmail-update-summary)))))
3332 ;;;; *** Rmail Mailing Commands ***
3334 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
3335 replybuffer sendactions same-window others
)
3338 (setq yank-action
(list 'insert-buffer replybuffer
)))
3339 (setq others
(cons (cons "cc" cc
) others
))
3340 (setq others
(cons (cons "in-reply-to" in-reply-to
) others
))
3342 (compose-mail to subject others
3344 yank-action sendactions
)
3345 (if rmail-mail-new-frame
3347 (compose-mail to subject others
3348 noerase
'switch-to-buffer-other-frame
3349 yank-action sendactions
)
3350 ;; This is not a standard frame parameter;
3351 ;; nothing except sendmail.el looks at it.
3352 (modify-frame-parameters (selected-frame)
3353 '((mail-dedicated-frame . t
))))
3354 (compose-mail to subject others
3355 noerase
'switch-to-buffer-other-window
3356 yank-action sendactions
)))))
3358 (defun rmail-mail ()
3359 "Send mail in another window.
3360 While composing the message, use \\[mail-yank-original] to yank the
3361 original message into it."
3363 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
3365 (defun rmail-continue ()
3366 "Continue composing outgoing message previously being composed."
3368 (rmail-start-mail t
))
3370 (defun rmail-reply (just-sender)
3371 "Reply to the current message.
3372 Normally include CC: to all other recipients of original message;
3373 prefix argument means ignore them. While composing the reply,
3374 use \\[mail-yank-original] to yank the original message into it."
3376 (let (from reply-to cc subject date to message-id references
3377 resent-to resent-cc resent-reply-to
3378 (msgnum rmail-current-message
))
3381 (if rmail-enable-mime
3383 (goto-char (point-min))
3384 (if (search-forward "\n\n" nil
'move
)
3385 (1+ (match-beginning 0))
3388 (goto-char (rmail-msgbeg rmail-current-message
))
3390 (if (= (following-char) ?
0)
3392 (progn (forward-line 2)
3394 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
3397 (narrow-to-region (point)
3398 (progn (search-forward "\n*** EOOH ***\n")
3399 (beginning-of-line) (point)))))
3400 (setq from
(mail-fetch-field "from")
3401 reply-to
(or (if just-sender
3402 (mail-fetch-field "mail-reply-to" nil t
)
3403 (mail-fetch-field "mail-followup-to" nil t
))
3404 (mail-fetch-field "reply-to" nil t
)
3406 cc
(and (not just-sender
)
3407 ;; mail-followup-to, if given, overrides cc.
3408 (not (mail-fetch-field "mail-followup-to" nil t
))
3409 (mail-fetch-field "cc" nil t
))
3410 subject
(mail-fetch-field "subject")
3411 date
(mail-fetch-field "date")
3412 to
(or (mail-fetch-field "to" nil t
) "")
3413 message-id
(mail-fetch-field "message-id")
3414 references
(mail-fetch-field "references" nil nil t
)
3415 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
3416 resent-cc
(and (not just-sender
)
3417 (mail-fetch-field "resent-cc" nil t
))
3418 resent-to
(or (mail-fetch-field "resent-to" nil t
) "")
3419 ;;; resent-subject (mail-fetch-field "resent-subject")
3420 ;;; resent-date (mail-fetch-field "resent-date")
3421 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3423 ;; Merge the resent-to and resent-cc into the to and cc.
3424 (if (and resent-to
(not (equal resent-to
"")))
3425 (if (not (equal to
""))
3426 (setq to
(concat to
", " resent-to
))
3427 (setq to resent-to
)))
3428 (if (and resent-cc
(not (equal resent-cc
"")))
3429 (if (not (equal cc
""))
3430 (setq cc
(concat cc
", " resent-cc
))
3431 (setq cc resent-cc
)))
3432 ;; Add `Re: ' to subject if not there already.
3433 (and (stringp subject
)
3435 (concat rmail-reply-prefix
3436 (if (let ((case-fold-search t
))
3437 (string-match rmail-reply-regexp subject
))
3438 (substring subject
(match-end 0))
3442 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3443 ;; since they can handle the names unstripped.
3444 ;; I don't know whether there are other mailers that still
3445 ;; need the names to be stripped.
3446 ;;; (mail-strip-quoted-names reply-to)
3447 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3448 ;; header causes all the names in it to wind up in reply-to, not
3449 ;; in cc. But if what's left is an empty list, use the original.
3450 (let* ((reply-to-list (rmail-dont-reply-to reply-to
)))
3451 (if (string= reply-to-list
"") reply-to reply-to-list
))
3453 (rmail-make-in-reply-to-field from date message-id
)
3456 ;; mail-strip-quoted-names is NOT necessary for rmail-dont-reply-to
3458 (let* ((cc-list (rmail-dont-reply-to
3459 (mail-strip-quoted-names
3460 (if (null cc
) to
(concat to
", " cc
))))))
3461 (if (string= cc-list
"") nil cc-list
)))
3463 (list (list 'rmail-mark-message
3465 (with-current-buffer rmail-buffer
3466 (aref rmail-msgref-vector msgnum
))
3469 (list (cons "References" (concat (mapconcat 'identity references
" ")
3470 " " message-id
))))))
3472 (defun rmail-mark-message (buffer msgnum-list attribute
)
3473 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3474 This is use in the send-actions for message buffers.
3475 MSGNUM-LIST is a list of the form (MSGNUM)
3476 which is an element of rmail-msgref-vector."
3479 (if (car msgnum-list
)
3480 (rmail-set-attribute attribute t
(car msgnum-list
)))))
3482 (defun rmail-make-in-reply-to-field (from date message-id
)
3489 (let ((tem (car (rfc822-addresses from
))))
3493 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
3495 (match-beginning 0))
3498 ;; missing From, or Message-ID is sufficiently informative
3500 (concat message-id
" (" tem
")"))
3501 ;; Copy TEM, discarding text properties.
3502 (setq tem
(copy-sequence tem
))
3503 (set-text-properties 0 (length tem
) nil tem
)
3504 (setq tem
(copy-sequence tem
))
3505 ;; Use prin1 to fake RFC822 quoting
3506 (let ((field (prin1-to-string tem
)))
3508 (concat field
"'s message of " date
)
3510 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3511 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3512 ;; These strings both match all non-ASCII characters.
3513 (or (string-match (concat "\\`[ \t]*\\(" bar
3514 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
3515 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3517 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
3518 bar
"\\))[ \t]*\\'")
3519 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3521 (let ((start (match-beginning 1))
3522 (end (match-end 1)))
3523 ;; Trim whitespace which above regexp match allows
3524 (while (and (< start end
)
3525 (memq (aref from start
) '(?
\t ?\
)))
3526 (setq start
(1+ start
)))
3527 (while (and (< start end
)
3528 (memq (aref from
(1- end
)) '(?
\t ?\
)))
3529 (setq end
(1- end
)))
3530 (let ((field (substring from start end
)))
3531 (if date
(setq field
(concat "message from " field
" on " date
)))
3533 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3534 (concat message-id
" (" field
")")
3537 ;; If we can't kludge it simply, do it correctly
3538 (let ((mail-use-rfc822 t
))
3539 (rmail-make-in-reply-to-field from date message-id
)))))
3541 (defun rmail-forward (resend)
3542 "Forward the current message to another user.
3543 With prefix argument, \"resend\" the message instead of forwarding it;
3544 see the documentation of `rmail-resend'."
3547 (call-interactively 'rmail-resend
)
3548 (let ((forward-buffer rmail-buffer
)
3549 (msgnum rmail-current-message
)
3550 (subject (concat "["
3551 (let ((from (or (mail-fetch-field "From")
3552 (mail-fetch-field ">From"))))
3554 (concat (mail-strip-quoted-names from
) ": ")
3556 (or (mail-fetch-field "Subject") "")
3558 (if (rmail-start-mail
3559 nil nil subject nil nil nil
3560 (list (list 'rmail-mark-message
3562 (with-current-buffer rmail-buffer
3563 (aref rmail-msgref-vector msgnum
))
3565 ;; If only one window, use it for the mail buffer.
3566 ;; Otherwise, use another window for the mail buffer
3567 ;; so that the Rmail buffer remains visible
3568 ;; and sending the mail will get back to it.
3569 (and (not rmail-mail-new-frame
) (one-window-p t
)))
3570 ;; The mail buffer is now current.
3572 ;; Insert after header separator--before signature if any.
3573 (goto-char (mail-text-start))
3574 (if (or rmail-enable-mime rmail-enable-mime-composing
)
3575 (funcall rmail-insert-mime-forwarded-message-function
3577 (insert "------- Start of forwarded message -------\n")
3578 ;; Quote lines with `- ' if they start with `-'.
3579 (let ((beg (point)) end
)
3580 (setq end
(point-marker))
3581 (set-marker-insertion-type end t
)
3582 (insert-buffer-substring forward-buffer
)
3584 (while (re-search-forward "^-" end t
)
3589 (skip-chars-backward "\n")
3592 (delete-region (point) end
)
3593 (set-marker end nil
))
3594 (insert "------- End of forwarded message -------\n"))
3597 (defun rmail-resend (address &optional from comment mail-alias-file
)
3598 "Resend current message to ADDRESSES.
3599 ADDRESSES should be a single address, a string consisting of several
3600 addresses separated by commas, or a list of addresses.
3602 Optional FROM is the address to resend the message from, and
3603 defaults from the value of `user-mail-address'.
3604 Optional COMMENT is a string to insert as a comment in the resent message.
3605 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3606 typically for purposes of moderating a list."
3607 (interactive "sResend to: ")
3609 (require 'mailalias
)
3610 (unless (or (eq rmail-view-buffer
(current-buffer))
3611 (eq rmail-buffer
(current-buffer)))
3612 (error "Not an Rmail buffer"))
3613 (if (not from
) (setq from user-mail-address
))
3614 (let ((tembuf (generate-new-buffer " sendmail temp"))
3615 (case-fold-search nil
)
3616 (mail-personal-alias-file
3617 (or mail-alias-file mail-personal-alias-file
))
3618 (mailbuf rmail-buffer
))
3620 (with-current-buffer tembuf
3621 ;;>> Copy message into temp buffer
3622 (if rmail-enable-mime
3623 (funcall rmail-insert-mime-resent-message-function mailbuf
)
3624 (insert-buffer-substring mailbuf
))
3625 (goto-char (point-min))
3626 ;; Delete any Sender field, since that's not specifiable.
3627 ; Only delete Sender fields in the actual header.
3628 (re-search-forward "^$" nil
'move
)
3629 ; Using "while" here rather than "if" because some buggy mail
3630 ; software may have inserted multiple Sender fields.
3631 (while (re-search-backward "^Sender:" nil t
)
3635 (while (looking-at "[ \t]")
3637 (delete-region beg
(point))))
3638 ; Go back to the beginning of the buffer so the Resent- fields
3639 ; are inserted there.
3640 (goto-char (point-min))
3641 ;;>> Insert resent-from:
3642 (insert "Resent-From: " from
"\n")
3643 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3644 ;;>> Insert resent-to: and bcc if need be.
3645 (let ((before (point)))
3647 (insert "Resent-Bcc: " (user-login-name) "\n"))
3648 (insert "Resent-To: " (if (stringp address
)
3650 (mapconcat 'identity address
",\n\t"))
3652 ;; Expand abbrevs in the recipients.
3654 (if (featurep 'mailabbrev
)
3655 (let ((end (point-marker))
3656 (local-abbrev-table mail-abbrevs
)
3657 (old-syntax-table (syntax-table)))
3658 (if (and (not (vectorp mail-abbrevs
))
3659 (file-exists-p mail-personal-alias-file
))
3660 (build-mail-abbrevs))
3661 (unless mail-abbrev-syntax-table
3662 (mail-abbrev-make-syntax-table))
3663 (set-syntax-table mail-abbrev-syntax-table
)
3665 (while (and (< (point) end
)
3666 (progn (forward-word 1)
3669 (set-syntax-table old-syntax-table
))
3670 (expand-mail-aliases before
(point)))))
3671 ;;>> Set up comment, if any.
3672 (if (and (sequencep comment
) (not (zerop (length comment
))))
3673 (let ((before (point))
3676 (or (eolp) (insert "\n"))
3677 (setq after
(point))
3679 (while (< (point) after
)
3680 (insert "Resent-Comment: ")
3682 ;; Don't expand aliases in the destination fields
3683 ;; of the original message.
3685 (funcall send-mail-function
)))
3686 (kill-buffer tembuf
))
3687 (with-current-buffer rmail-buffer
3688 (rmail-set-attribute "resent" t rmail-current-message
))))
3690 (defvar mail-unsent-separator
3691 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3692 "^ *---+ +Returned message +---+ *$\\|"
3693 "^ *---+ *Returned mail follows *---+ *$\\|"
3694 "^Start of returned message$\\|"
3695 "^---+ Below this line is a copy of the message.$\\|"
3696 "^ *---+ +Original message +---+ *$\\|"
3697 "^ *--+ +begin message +--+ *$\\|"
3698 "^ *---+ +Original message follows +---+ *$\\|"
3699 "^ *---+ +Your message follows +---+ *$\\|"
3700 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3701 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
3702 "A regexp that matches the separator before the text of a failed message.")
3704 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
3705 "A regexp that matches the header of a MIME body part with a failed message.")
3707 (defun rmail-retry-failure ()
3708 "Edit a mail message which is based on the contents of the current message.
3709 For a message rejected by the mail system, extract the interesting headers and
3710 the body of the original message.
3711 If the failed message is a MIME multipart message, it is searched for a
3712 body part with a header which matches the variable `mail-mime-unsent-header'.
3713 Otherwise, the variable `mail-unsent-separator' should match the string that
3714 delimits the returned original message.
3715 The variable `rmail-retry-ignored-headers' is a regular expression
3716 specifying headers which should not be copied into the new message."
3718 (require 'mail-utils
)
3719 (let ((rmail-this-buffer (current-buffer))
3720 (msgnum rmail-current-message
)
3721 bounce-start bounce-end bounce-indent resending
3722 ;; Fetch any content-type header in current message
3723 ;; Must search thru the whole unpruned header.
3727 (rmail-narrow-to-non-pruned-header)
3728 (mail-fetch-field "Content-Type") ))))
3730 (goto-char (point-min))
3731 (let ((case-fold-search t
))
3732 (if (and content-type
3734 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3736 ;; Handle a MIME multipart bounce message.
3739 (substring content-type
(match-beginning 1)
3741 (unless (re-search-forward mail-mime-unsent-header nil t
)
3742 (error "Cannot find beginning of header in failed message"))
3743 (unless (search-forward "\n\n" nil t
)
3744 (error "Cannot find start of Mime data in failed message"))
3745 (setq bounce-start
(point))
3746 (if (search-forward codestring nil t
)
3747 (setq bounce-end
(match-beginning 0))
3748 (setq bounce-end
(point-max))))
3750 (or (re-search-forward mail-unsent-separator nil t
)
3751 (error "Cannot parse this as a failure message"))
3752 (skip-chars-forward "\n")
3753 ;; Support a style of failure message in which the original
3754 ;; message is indented, and included within lines saying
3755 ;; `Start of returned message' and `End of returned message'.
3756 (if (looking-at " +Received:")
3758 (setq bounce-start
(point))
3759 (skip-chars-forward " ")
3760 (setq bounce-indent
(- (current-column)))
3761 (goto-char (point-max))
3762 (re-search-backward "^End of returned message$" nil t
)
3763 (setq bounce-end
(point)))
3764 ;; One message contained a few random lines before
3765 ;; the old message header. The first line of the
3766 ;; message started with two hyphens. A blank line
3767 ;; followed these random lines. The same line
3768 ;; beginning with two hyphens was possibly marking
3769 ;; the end of the message.
3770 (if (looking-at "^--")
3771 (let ((boundary (buffer-substring-no-properties
3773 (progn (end-of-line) (point)))))
3774 (search-forward "\n\n")
3775 (skip-chars-forward "\n")
3776 (setq bounce-start
(point))
3777 (goto-char (point-max))
3778 (search-backward (concat "\n\n" boundary
) bounce-start t
)
3779 (setq bounce-end
(point)))
3780 (setq bounce-start
(point)
3781 bounce-end
(point-max)))
3782 (unless (search-forward "\n\n" nil t
)
3783 (error "Cannot find end of header in failed message"))))))
3784 ;; We have found the message that bounced, within the current message.
3785 ;; Now start sending new message; default header fields from original.
3786 ;; Turn off the usual actions for initializing the message body
3787 ;; because we want to get only the text from the failure message.
3788 (let (mail-signature mail-setup-hook
)
3789 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
3790 (list (list 'rmail-mark-message
3792 (aref rmail-msgref-vector msgnum
)
3794 ;; Insert original text as initial text of new draft message.
3795 ;; Bind inhibit-read-only since the header delimiter
3796 ;; of the previous message was probably read-only.
3797 (let ((inhibit-read-only t
)
3798 rmail-displayed-headers
3799 rmail-ignored-headers
)
3801 (insert-buffer-substring rmail-this-buffer
3802 bounce-start bounce-end
)
3803 (goto-char (point-min))
3805 (indent-rigidly (point-min) (point-max) bounce-indent
))
3806 (rmail-clear-headers rmail-retry-ignored-headers
)
3807 (rmail-clear-headers "^sender:\\|^return-path:\\|^received:")
3808 (mail-sendmail-delimit-header)
3810 (narrow-to-region (point-min) (mail-header-end))
3811 (setq resending
(mail-fetch-field "resent-to"))
3814 (insert "Resent-Bcc: " (user-login-name) "\n")
3815 (insert "BCC: " (user-login-name) "\n"))))
3816 (goto-char (point-min))
3817 (mail-position-on-field (if resending
"Resent-To" "To") t
))))))
3819 (defun rmail-summary-exists ()
3820 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
3821 In fact, the non-nil value returned is the summary buffer itself."
3822 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3823 rmail-summary-buffer
))
3825 (defun rmail-summary-displayed ()
3826 "t iff in RMAIL buffer and an associated summary buffer is displayed."
3827 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
3829 (defcustom rmail-redisplay-summary nil
3830 "*Non-nil means Rmail should show the summary when it changes.
3831 This has an effect only if a summary buffer exists."
3833 :group
'rmail-summary
)
3835 (defcustom rmail-summary-window-size nil
3836 "*Non-nil means specify the height for an Rmail summary window."
3837 :type
'(choice (const :tag
"Disabled" nil
) integer
)
3838 :group
'rmail-summary
)
3840 ;; Put the summary buffer back on the screen, if user wants that.
3841 (defun rmail-maybe-display-summary ()
3842 (let ((selected (selected-window))
3844 ;; If requested, make sure the summary is displayed.
3845 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3846 rmail-redisplay-summary
3847 (if (get-buffer-window rmail-summary-buffer
0)
3848 ;; It's already in some frame; show that one.
3849 (let ((frame (window-frame
3850 (get-buffer-window rmail-summary-buffer
0))))
3851 (make-frame-visible frame
)
3852 (raise-frame frame
))
3853 (display-buffer rmail-summary-buffer
)))
3854 ;; If requested, set the height of the summary window.
3855 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3856 rmail-summary-window-size
3857 (setq window
(get-buffer-window rmail-summary-buffer
))
3858 ;; Don't try to change the size if just one window in frame.
3859 (not (eq window
(frame-root-window (window-frame window
))))
3862 (select-window window
)
3863 (enlarge-window (- rmail-summary-window-size
(window-height))))
3864 (select-window selected
)))))
3866 ;;;; *** Rmail Local Fontification ***
3868 (defun rmail-fontify-buffer-function ()
3869 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
3870 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
3871 ;; If we're already showing a message, fontify it now.
3872 (if rmail-current-message
(rmail-fontify-message))
3873 ;; Prevent Font Lock mode from kicking in.
3874 (setq font-lock-fontified t
))
3876 (defun rmail-unfontify-buffer-function ()
3877 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
3878 (let ((modified (buffer-modified-p))
3879 (buffer-undo-list t
) (inhibit-read-only t
)
3880 before-change-functions after-change-functions
3881 buffer-file-name buffer-file-truename
)
3884 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
3885 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
3886 (font-lock-default-unfontify-buffer)
3887 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))
3889 (defun rmail-fontify-message ()
3890 ;; Fontify the current message if it is not already fontified.
3891 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
3892 (let ((modified (buffer-modified-p))
3893 (buffer-undo-list t
) (inhibit-read-only t
)
3894 before-change-functions after-change-functions
3895 buffer-file-name buffer-file-truename
)
3898 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
3899 (font-lock-fontify-region (point-min) (point-max))
3900 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))))
3902 ;;; Speedbar support for RMAIL files.
3903 (eval-when-compile (require 'speedbar
))
3905 (defvar rmail-speedbar-match-folder-regexp
"^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
3906 "*This regex is used to match folder names to be displayed in speedbar.
3907 Enabling this will permit speedbar to display your folders for easy
3908 browsing, and moving of messages.")
3910 (defvar rmail-speedbar-last-user nil
3911 "The last user to be displayed in the speedbar.")
3913 (defvar rmail-speedbar-key-map nil
3914 "Keymap used when in rmail display mode.")
3916 (defun rmail-install-speedbar-variables ()
3917 "Install those variables used by speedbar to enhance rmail."
3918 (if rmail-speedbar-key-map
3920 (setq rmail-speedbar-key-map
(speedbar-make-specialized-keymap))
3922 (define-key rmail-speedbar-key-map
"e" 'speedbar-edit-line
)
3923 (define-key rmail-speedbar-key-map
"r" 'speedbar-edit-line
)
3924 (define-key rmail-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
3925 (define-key rmail-speedbar-key-map
"M"
3926 'rmail-speedbar-move-message-to-folder-on-line
)))
3928 (defvar rmail-speedbar-menu-items
3929 '(["Read Folder" speedbar-edit-line t
]
3930 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
3931 (save-excursion (beginning-of-line)
3932 (looking-at "<M> "))])
3933 "Additional menu-items to add to speedbar frame.")
3935 ;; Make sure our special speedbar major mode is loaded
3936 (if (featurep 'speedbar
)
3937 (rmail-install-speedbar-variables)
3938 (add-hook 'speedbar-load-hook
'rmail-install-speedbar-variables
))
3940 (defun rmail-speedbar-buttons (buffer)
3941 "Create buttons for BUFFER containing rmail messages.
3942 Click on the address under Reply to: to reply to this person.
3943 Under Folders: Click a name to read it, or on the <M> to move the
3944 current message into that RMAIL folder."
3948 (goto-char (point-min))
3949 (if (not (re-search-forward "^Reply-To: " nil t
))
3950 (if (not (re-search-forward "^From:? " nil t
))
3954 (setq from
(buffer-substring (point) (save-excursion
3957 (goto-char (point-min))
3958 (if (and (looking-at "Reply to:")
3959 (equal from rmail-speedbar-last-user
))
3961 (setq rmail-speedbar-last-user from
)
3963 (insert "Reply To:\n")
3965 (speedbar-insert-button from
'speedbar-directory-face
'highlight
3966 'rmail-speedbar-button
'rmail-reply
))
3967 (insert "Folders:\n")
3968 (let* ((case-fold-search nil
)
3969 (df (directory-files (save-excursion (set-buffer buffer
)
3971 nil rmail-speedbar-match-folder-regexp
)))
3973 (speedbar-insert-button "<M>" 'speedbar-button-face
'highlight
3974 'rmail-speedbar-move-message
(car df
))
3975 (speedbar-insert-button (car df
) 'speedbar-file-face
'highlight
3976 'rmail-speedbar-find-file nil t
)
3977 (setq df
(cdr df
)))))))
3979 (defun rmail-speedbar-button (text token indent
)
3980 "Execute an rmail command specified by TEXT.
3981 The command used is TOKEN. INDENT is not used."
3982 (speedbar-with-attached-buffer
3985 (defun rmail-speedbar-find-file (text token indent
)
3986 "Load in the rmail file TEXT.
3987 TOKEN and INDENT are not used."
3988 (speedbar-with-attached-buffer
3989 (message "Loading in RMAIL file %s..." text
)
3992 (defun rmail-speedbar-move-message-to-folder-on-line ()
3993 "If the current line is a folder, move current message to it."
3997 (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t
)
4000 (speedbar-do-function-pointer)))))
4002 (defun rmail-speedbar-move-message (text token indent
)
4003 "From button TEXT, copy current message to the rmail file specified by TOKEN.
4004 TEXT and INDENT are not used."
4005 (speedbar-with-attached-buffer
4006 (message "Moving message to %s" token
)
4007 (rmail-output-to-rmail-file token
)))
4009 ; Functions for setting, getting and encoding the POP password.
4010 ; The password is encoded to prevent it from being easily accessible
4011 ; to "prying eyes." Obviously, this encoding isn't "real security,"
4012 ; nor is it meant to be.
4015 (defun rmail-set-remote-password (password)
4016 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
4017 (interactive "sPassword: ")
4019 (setq rmail-encoded-remote-password
4020 (rmail-encode-string password
(emacs-pid)))
4021 (setq rmail-remote-password nil
)
4022 (setq rmail-encoded-remote-password nil
)))
4024 (defun rmail-get-remote-password (imap)
4025 "Get the password for retrieving mail from a POP or IMAP server. If none
4026 has been set, then prompt the user for one."
4027 (when (not rmail-encoded-remote-password
)
4028 (if (not rmail-remote-password
)
4029 (setq rmail-remote-password
4030 (read-passwd (if imap
4032 "POP password: "))))
4033 (rmail-set-remote-password rmail-remote-password
)
4034 (setq rmail-remote-password nil
))
4035 (rmail-encode-string rmail-encoded-remote-password
(emacs-pid)))
4037 (defun rmail-have-password ()
4038 (or rmail-remote-password rmail-encoded-remote-password
))
4040 (defun rmail-encode-string (string mask
)
4041 "Encode STRING with integer MASK, by taking the exclusive OR of the
4042 lowest byte in the mask with the first character of string, the
4043 second-lowest-byte with the second character of the string, etc.,
4044 restarting at the lowest byte of the mask whenever it runs out.
4045 Returns the encoded string. Calling the function again with an
4046 encoded string (and the same mask) will decode the string."
4047 (setq mask
(abs mask
)) ; doesn't work if negative
4048 (let* ((string-vector (string-to-vector string
)) (i 0)
4049 (len (length string-vector
)) (curmask mask
) charmask
)
4052 (setq curmask mask
))
4053 (setq charmask
(% curmask
256))
4054 (setq curmask
(lsh curmask -
8))
4055 (aset string-vector i
(logxor charmask
(aref string-vector i
)))
4057 (concat string-vector
)))
4059 ;;;; Desktop support
4062 (defun rmail-restore-desktop-buffer (desktop-buffer-file-name
4064 desktop-buffer-misc
)
4065 "Restore an rmail buffer specified in a desktop file."
4066 (condition-case error
4068 (rmail-input desktop-buffer-file-name
)
4069 (if (eq major-mode
'rmail-mode
)
4073 (kill-buffer (current-buffer))
4078 ;;; arch-tag: cff0a950-57fe-4f73-a86e-91ff75afd06c
4079 ;;; rmail.el ends here