(rmail-ignored-headers): Add X-Sign, X-BeenThere,
[emacs.git] / lisp / mail / rmail.el
blobafbea71a9b350a775b67d261fe720948d7708011
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, 2001
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: mail
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)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; 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.
26 ;;; Code:
28 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
29 ;; New features include attribute and keyword support, message
30 ;; selection by dispatch table, summary by attributes and keywords,
31 ;; expunging by dispatch table, sticky options for file commands.
33 ;; Extended by Bob Weiner of Motorola
34 ;; New features include: rmail and rmail-summary buffers remain
35 ;; synchronized and key bindings basically operate the same way in both
36 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
37 ;; variable, and a bury rmail buffer (wipe) command.
40 (require 'mail-utils)
42 ; These variables now declared in paths.el.
43 ;(defvar rmail-spool-directory "/usr/spool/mail/"
44 ; "This is the name of the directory used by the system mailer for\n\
45 ;delivering new mail. Its name should end with a slash.")
46 ;(defvar rmail-file-name
47 ; (expand-file-name "~/RMAIL")
48 ; "")
50 (defgroup rmail nil
51 "Mail reader for Emacs."
52 :group 'mail)
54 (defgroup rmail-retrieve nil
55 "Rmail retrieval options."
56 :prefix "rmail-"
57 :group 'rmail)
59 (defgroup rmail-files nil
60 "Rmail files."
61 :prefix "rmail-"
62 :group 'rmail)
64 (defgroup rmail-headers nil
65 "Rmail header options."
66 :prefix "rmail-"
67 :group 'rmail)
69 (defgroup rmail-reply nil
70 "Rmail reply options."
71 :prefix "rmail-"
72 :group 'rmail)
74 (defgroup rmail-summary nil
75 "Rmail summary options."
76 :prefix "rmail-"
77 :prefix "rmail-summary-"
78 :group 'rmail)
80 (defgroup rmail-output nil
81 "Output message to a file."
82 :prefix "rmail-output-"
83 :prefix "rmail-"
84 :group 'rmail)
87 (defcustom rmail-movemail-program nil
88 "If non-nil, name of program for fetching new mail."
89 :group 'rmail-retrieve
90 :type '(choice (const nil) string))
92 (defcustom rmail-pop-password nil
93 "*Password to use when reading mail from a POP server, if required."
94 :type '(choice (string :tag "Password")
95 (const :tag "Not Required" nil))
96 :group 'rmail-retrieve)
98 (defcustom rmail-pop-password-required nil
99 "*Non-nil if a password is required when reading mail using POP."
100 :type 'boolean
101 :group 'rmail-retrieve)
103 (defcustom rmail-movemail-flags nil
104 "*List of flags to pass to movemail.
105 Most commonly used to specify `-g' to enable GSS-API authentication
106 or `-k' to enable Kerberos authentication."
107 :type '(repeat string)
108 :group 'rmail-retrieve
109 :version "20.3")
111 (defvar rmail-pop-password-error "invalid usercode or password\\|
112 unknown user name or bad password"
113 "Regular expression matching incorrect-password POP server error messages.
114 If you get an incorrect-password error that this expression does not match,
115 please report it with \\[report-emacs-bug].")
117 (defvar rmail-encoded-pop-password nil)
119 (defcustom rmail-preserve-inbox nil
120 "*Non-nil if incoming mail should be left in the user's inbox,
121 rather than deleted, after it is retrieved."
122 :type 'boolean
123 :group 'rmail-retrieve)
125 ;;;###autoload
126 (defcustom rmail-dont-reply-to-names nil "\
127 *A regexp specifying names to prune of reply to messages.
128 A value of nil means exclude your own login name as an address
129 plus whatever is specified by `rmail-default-dont-reply-to-names'."
130 :type '(choice regexp (const :tag "Your Name" nil))
131 :group 'rmail-reply)
133 ;;;###autoload
134 (defvar rmail-default-dont-reply-to-names "info-" "\
135 A regular expression specifying part of the value of the default value of
136 the variable `rmail-dont-reply-to-names', for when the user does not set
137 `rmail-dont-reply-to-names' explicitly. (The other part of the default
138 value is the user's name.)
139 It is useful to set this variable in the site customization file.")
141 ;;;###autoload
142 (defcustom rmail-ignored-headers
143 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:"
144 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
145 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
146 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
147 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:"
148 "\\|^x-mailer:\\|^delivered-to:\\|^lines:\\|^mime-version:"
149 "\\|^content-transfer-encoding:\\|^x-coding-system:"
150 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
151 "\\|^x-sign:\\|^x-beenthere:\\|^x-mailman-version:"
152 "\\|^precedence:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
153 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
154 "\\|^content-type:\\|^content-length:"
155 "\\|^x-attribution:\\|^x-disclaimer:")
156 "*Regexp to match header fields that Rmail should normally hide.
157 This variable is used for reformatting the message header,
158 which normally happens once for each message,
159 when you view the message for the first time in Rmail.
160 To make a change in this variable take effect
161 for a message that you have already viewed,
162 go to that message and type \\[rmail-toggle-header] twice."
163 :type 'regexp
164 :group 'rmail-headers)
166 ;;;###autoload
167 (defcustom rmail-displayed-headers nil
168 "*Regexp to match Header fields that Rmail should display.
169 If nil, display all header fields except those matched by
170 `rmail-ignored-headers'."
171 :type '(choice regexp (const :tag "All"))
172 :group 'rmail-headers)
174 ;;;###autoload
175 (defcustom rmail-retry-ignored-headers nil "\
176 *Headers that should be stripped when retrying a failed message."
177 :type '(choice regexp (const nil :tag "None"))
178 :group 'rmail-headers)
180 ;;;###autoload
181 (defcustom rmail-highlighted-headers "^From:\\|^Subject:" "\
182 *Regexp to match Header fields that Rmail should normally highlight.
183 A value of nil means don't highlight.
184 See also `rmail-highlight-face'."
185 :type 'regexp
186 :group 'rmail-headers)
188 ;;;###autoload
189 (defcustom rmail-highlight-face nil "\
190 *Face used by Rmail for highlighting headers."
191 :type '(choice (const :tag "Default" nil)
192 face)
193 :group 'rmail-headers)
195 ;;;###autoload
196 (defcustom rmail-delete-after-output nil "\
197 *Non-nil means automatically delete a message that is copied to a file."
198 :type 'boolean
199 :group 'rmail-files)
201 ;;;###autoload
202 (defcustom rmail-primary-inbox-list nil "\
203 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
204 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
205 \(the name varies depending on the operating system,
206 and the value of the environment variable MAIL overrides it)."
207 ;; Don't use backquote here, because we don't want to need it
208 ;; at load time.
209 :type (list 'choice '(const :tag "Default" nil)
210 (list 'repeat ':value (list (or (getenv "MAIL")
211 (concat "/var/spool/mail/"
212 (getenv "USER"))))
213 'file))
214 :group 'rmail-retrieve
215 :group 'rmail-files)
217 ;;;###autoload
218 (defcustom rmail-mail-new-frame nil
219 "*Non-nil means Rmail makes a new frame for composing outgoing mail."
220 :type 'boolean
221 :group 'rmail-reply)
223 ;;;###autoload
224 (defcustom rmail-secondary-file-directory "~/"
225 "*Directory for additional secondary Rmail files."
226 :type 'directory
227 :group 'rmail-files)
228 ;;;###autoload
229 (defcustom rmail-secondary-file-regexp "\\.xmail$"
230 "*Regexp for which files are secondary Rmail files."
231 :type 'regexp
232 :group 'rmail-files)
234 ;;;###autoload
235 (defcustom rmail-confirm-expunge 'y-or-n-p
236 "*Whether and how to ask for confirmation before expunging deleted messages."
237 :type '(choice (const :tag "No confirmation" nil)
238 (const :tag "Confirm with y-or-n-p" y-or-n-p)
239 (const :tag "Confirm with yes-or-no-p" yes-or-no-p))
240 :version "21.1"
241 :group 'rmail-files)
243 ;;;###autoload
244 (defvar rmail-mode-hook nil
245 "List of functions to call when Rmail is invoked.")
247 ;;;###autoload
248 (defvar rmail-get-new-mail-hook nil
249 "List of functions to call when Rmail has retrieved new mail.")
251 ;;;###autoload
252 (defcustom rmail-show-message-hook nil
253 "List of functions to call when Rmail displays a message."
254 :type 'hook
255 :options '(goto-addr)
256 :group 'rmail)
258 ;;;###autoload
259 (defvar rmail-quit-hook nil
260 "List of functions to call when quitting out of Rmail.")
262 ;;;###autoload
263 (defvar rmail-delete-message-hook nil
264 "List of functions to call when Rmail deletes a message.
265 When the hooks are called, the message has been marked deleted but is
266 still the current message in the Rmail buffer.")
268 ;; These may be altered by site-init.el to match the format of mmdf files
269 ;; delimiting used on a given host (delim1 and delim2 from the config
270 ;; files).
272 (defvar rmail-mmdf-delim1 "^\001\001\001\001\n"
273 "Regexp marking the start of an mmdf message")
274 (defvar rmail-mmdf-delim2 "^\001\001\001\001\n"
275 "Regexp marking the end of an mmdf message")
277 (defcustom rmail-message-filter nil
278 "If non-nil, a filter function for new messages in RMAIL.
279 Called with region narrowed to the message, including headers,
280 before obeying `rmail-ignored-headers'."
281 :group 'rmail-headers
282 :type 'function)
284 (defcustom rmail-automatic-folder-directives nil
285 "List of directives specifying where to put a message.
286 Each element of the list is of the form:
288 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
290 Where FOLDERNAME is the name of a BABYL format folder to put the
291 message. If any of the field regexp's are nil, then it is ignored.
293 If FOLDERNAME is \"/dev/null\", it is deleted.
294 If FOLDERNAME is nil then it is deleted, and skipped.
296 FIELD is the plain text name of a field in the message, such as
297 \"subject\" or \"from\". A FIELD of \"to\" will automatically include
298 all text from the \"cc\" field as well.
300 REGEXP is an expression to match in the preceeding specified FIELD.
301 FIELD/REGEXP pairs continue in the list.
303 examples:
304 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
305 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
306 :group 'rmail
307 :version "21.1"
308 :type '(repeat (sexp :tag "Directive")))
310 (defvar rmail-reply-prefix "Re: "
311 "String to prepend to Subject line when replying to a message.")
313 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
314 ;; This pattern should catch all the common variants.
315 (defvar rmail-reply-regexp "\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
316 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
318 (defcustom rmail-display-summary nil
319 "*If non-nil, Rmail always displays the summary buffer."
320 :group 'rmail-summary
321 :type 'boolean)
323 (defvar rmail-inbox-list nil)
324 (put 'rmail-inbox-list 'permanent-local t)
326 (defvar rmail-keywords nil)
327 (put 'rmail-keywords 'permanent-local t)
329 (defvar rmail-buffer nil
330 "The RMAIL buffer related to the current buffer.
331 In an RMAIL buffer, this holds the RMAIL buffer itself.
332 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
333 (put 'rmail-buffer 'permanent-local t)
335 ;; Message counters and markers. Deleted flags.
337 (defvar rmail-current-message nil)
338 (put 'rmail-current-message 'permanent-local t)
340 (defvar rmail-total-messages nil)
341 (put 'rmail-total-messages 'permanent-local t)
343 (defvar rmail-message-vector nil)
344 (put 'rmail-message-vector 'permanent-local t)
346 (defvar rmail-deleted-vector nil)
347 (put 'rmail-deleted-vector 'permanent-local t)
349 (defvar rmail-msgref-vector nil
350 "In an Rmail buffer, a vector whose Nth element is a list (N).
351 When expunging renumbers messages, these lists are modified
352 by substituting the new message number into the existing list.")
353 (put 'rmail-msgref-vector 'permanent-local t)
355 (defvar rmail-overlay-list nil)
356 (put 'rmail-overlay-list 'permanent-local t)
358 ;; These are used by autoloaded rmail-summary.
360 (defvar rmail-summary-buffer nil)
361 (put 'rmail-summary-buffer 'permanent-local t)
362 (defvar rmail-summary-vector nil)
363 (put 'rmail-summary-vector 'permanent-local t)
365 (defvar rmail-view-buffer nil
366 "Buffer which holds RMAIL message for MIME displaying.")
367 (put 'rmail-view-buffer 'permanent-local t)
369 ;; `Sticky' default variables.
371 ;; Last individual label specified to a or k.
372 (defvar rmail-last-label nil)
373 (put 'rmail-last-label 'permanent-local t)
375 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
376 (defvar rmail-last-multi-labels nil)
378 (defvar rmail-last-regexp nil)
379 (put 'rmail-last-regexp 'permanent-local t)
381 (defcustom rmail-default-file "~/xmail"
382 "*Default file name for \\[rmail-output]."
383 :type 'file
384 :group 'rmail-files)
385 (defcustom rmail-default-rmail-file "~/XMAIL"
386 "*Default file name for \\[rmail-output-to-rmail-file]."
387 :type 'file
388 :group 'rmail-files)
389 (defcustom rmail-default-body-file "~/mailout"
390 "*Default file name for \\[rmail-output-body-to-file]."
391 :type 'file
392 :group 'rmail-files
393 :version "20.3")
395 ;; Mule and MIME related variables.
397 ;;;###autoload
398 (defvar rmail-file-coding-system nil
399 "Coding system used in RMAIL file.
401 This is set to nil by default.")
403 ;;;###autoload
404 (defcustom rmail-enable-mime nil
405 "*If non-nil, RMAIL uses MIME feature.
406 If the value is t, RMAIL automatically shows MIME decoded message.
407 If the value is neither t nor nil, RMAIL does not show MIME decoded message
408 until a user explicitly requires it."
409 :type '(choice (const :tag "on" t)
410 (const :tag "off" nil)
411 (other :tag "when asked" ask))
412 :group 'rmail)
414 ;;;###autoload
415 (defvar rmail-show-mime-function nil
416 "Function to show MIME decoded message of RMAIL file.")
418 ;;;###autoload
419 (defvar rmail-mime-feature 'rmail-mime
420 "Feature to require to load MIME support in Rmail.
421 When starting Rmail, if `rmail-enable-mime' is non-nil,
422 this feature is required with `require'.")
424 ;;;###autoload
425 (defvar rmail-decode-mime-charset t
426 "*Non-nil means a message is decoded by MIME's charset specification.
427 If this variable is nil, or the message has not MIME specification,
428 the message is decoded as normal way.
430 If the variable `rmail-enable-mime' is non-nil, this variables is
431 ignored, and all the decoding work is done by a feature specified by
432 the variable `rmail-mime-feature'.")
434 ;;;###autoload
435 (defvar rmail-mime-charset-pattern
436 "^content-type:[ ]*text/plain;[ \t\n]*charset=\"?\\([^ \t\n\"]+\\)\"?"
437 "Regexp to match MIME-charset specification in a header of message.
438 The first parenthesized expression should match the MIME-charset name.")
441 ;;; Regexp matching the delimiter of messages in UNIX mail format
442 ;;; (UNIX From lines), minus the initial ^. Note that if you change
443 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
444 ;;; that knows the exact ordering of the \\( \\) subexpressions.
445 (defvar rmail-unix-mail-delimiter
446 (let ((time-zone-regexp
447 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
448 "\\|[-+]?[0-9][0-9][0-9][0-9]"
449 "\\|"
450 "\\) *")))
451 (concat
452 "From "
454 ;; Many things can happen to an RFC 822 mailbox before it is put into
455 ;; a `From' line. The leading phrase can be stripped, e.g.
456 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
457 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
458 ;; can be removed, e.g.
459 ;; From: joe@y.z (Joe K
460 ;; User)
461 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
462 ;; From: Joe User
463 ;; <joe@y.z>
464 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
465 ;; The mailbox can be removed or be replaced by white space, e.g.
466 ;; From: "Joe User"{space}{tab}
467 ;; <joe@y.z>
468 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
469 ;; where {space} and {tab} represent the Ascii space and tab characters.
470 ;; We want to match the results of any of these manglings.
471 ;; The following regexp rejects names whose first characters are
472 ;; obviously bogus, but after that anything goes.
473 "\\([^\0-\b\n-\r\^?].*\\)? "
475 ;; The time the message was sent.
476 "\\([^\0-\r \^?]+\\) +" ; day of the week
477 "\\([^\0-\r \^?]+\\) +" ; month
478 "\\([0-3]?[0-9]\\) +" ; day of month
479 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
481 ;; Perhaps a time zone, specified by an abbreviation, or by a
482 ;; numeric offset.
483 time-zone-regexp
485 ;; The year.
486 " \\([0-9][0-9]+\\) *"
488 ;; On some systems the time zone can appear after the year, too.
489 time-zone-regexp
491 ;; Old uucp cruft.
492 "\\(remote from .*\\)?"
494 "\n"))
495 nil)
497 (defvar rmail-font-lock-keywords
498 (eval-when-compile
499 (let* ((cite-chars "[>|}]")
500 (cite-prefix "A-Za-z")
501 (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
502 (list '("^\\(From\\|Sender\\):" . font-lock-function-name-face)
503 '("^Reply-To:.*$" . font-lock-function-name-face)
504 '("^Subject:" . font-lock-comment-face)
505 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
506 . font-lock-keyword-face)
507 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
508 `(,cite-chars
509 (,(concat "\\=[ \t]*"
510 "\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
511 "\\(" cite-chars "[ \t]*\\)\\)+"
512 "\\(.*\\)")
513 (beginning-of-line) (end-of-line)
514 (2 font-lock-constant-face nil t)
515 (4 font-lock-comment-face nil t)))
516 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\|Date\\):.*$"
517 . font-lock-string-face))))
518 "Additional expressions to highlight in Rmail mode.")
520 ;; Perform BODY in the summary buffer
521 ;; in such a way that its cursor is properly updated in its own window.
522 (defmacro rmail-select-summary (&rest body)
523 `(let ((total rmail-total-messages))
524 (if (rmail-summary-displayed)
525 (let ((window (selected-window)))
526 (save-excursion
527 (unwind-protect
528 (progn
529 (pop-to-buffer rmail-summary-buffer)
530 ;; rmail-total-messages is a buffer-local var
531 ;; in the rmail buffer.
532 ;; This way we make it available for the body
533 ;; even tho the rmail buffer is not current.
534 (let ((rmail-total-messages total))
535 ,@body))
536 (select-window window))))
537 (save-excursion
538 (set-buffer rmail-summary-buffer)
539 (let ((rmail-total-messages total))
540 ,@body)))
541 (rmail-maybe-display-summary)))
543 ;;;; *** Rmail Mode ***
545 (defvar rmail-enable-multibyte nil)
547 ;;;###autoload
548 (defun rmail (&optional file-name-arg)
549 "Read and edit incoming mail.
550 Moves messages into file named by `rmail-file-name' (a babyl format file)
551 and edits that file in RMAIL Mode.
552 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
554 May be called with file name as argument; then performs rmail editing on
555 that file, but does not copy any new mail into the file.
556 Interactively, if you supply a prefix argument, then you
557 have a chance to specify a file name with the minibuffer.
559 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
560 (interactive (if current-prefix-arg
561 (list (read-file-name "Run rmail on RMAIL file: "))))
562 (if rmail-enable-mime
563 (condition-case err
564 (require rmail-mime-feature)
565 (error (message "Feature `%s' not provided" rmail-mime-feature)
566 (sit-for 1)
567 (setq rmail-enable-mime nil))))
568 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
569 (existed (get-file-buffer file-name))
570 ;; This binding is necessary because we much decide if we
571 ;; need code conversion while the buffer is unibyte
572 ;; (i.e. enable-multibyte-characters is nil).
573 (rmail-enable-multibyte
574 (if existed
575 (with-current-buffer existed enable-multibyte-characters)
576 (default-value 'enable-multibyte-characters)))
577 ;; Since the file may contain messages of different encodings
578 ;; at the tail (non-BYBYL part), we can't decode them at once
579 ;; on reading. So, at first, we read the file without text
580 ;; code conversion, then decode the messages one by one by
581 ;; rmail-decode-babyl-format or
582 ;; rmail-convert-to-babyl-format.
583 (coding-system-for-read (and rmail-enable-multibyte 'raw-text))
584 run-mail-hook msg-shown)
585 ;; Like find-file, but in the case where a buffer existed
586 ;; and the file was reverted, recompute the message-data.
587 ;; We used to bind enable-local-variables to nil here,
588 ;; but that should not be needed now that rmail-mode
589 ;; sets it locally to nil.
590 ;; (Binding a variable locally with let is not safe if it has
591 ;; buffer-local bindings.)
592 (if (and existed (not (verify-visited-file-modtime existed)))
593 (progn
594 (find-file file-name)
595 (if (and (verify-visited-file-modtime existed)
596 (eq major-mode 'rmail-mode))
597 (progn (rmail-forget-messages)
598 (rmail-set-message-counters))))
599 (switch-to-buffer
600 (let ((enable-local-variables nil))
601 (find-file-noselect file-name))))
602 (if (eq major-mode 'rmail-edit-mode)
603 (error "Exit Rmail Edit mode before getting new mail"))
604 (if (and existed (> (buffer-size) 0))
605 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
606 (or (eq major-mode 'rmail-mode)
607 (progn (rmail-mode-2)
608 (setq run-mail-hook t)))
609 (setq run-mail-hook t)
610 (rmail-mode-2)
611 ;; Convert all or part to Babyl file if possible.
612 (rmail-convert-file)
613 (goto-char (point-max)))
614 ;; As we have read a file by raw-text, the buffer is set to
615 ;; unibyte. We must make it multibyte if necessary.
616 (if (and rmail-enable-multibyte
617 (not enable-multibyte-characters))
618 (set-buffer-multibyte t))
619 ;; If necessary, scan to find all the messages.
620 (rmail-maybe-set-message-counters)
621 (unwind-protect
622 (unless (and (not file-name-arg)
623 (rmail-get-new-mail))
624 (rmail-show-message (rmail-first-unseen-message)))
625 (progn
626 (if rmail-display-summary (rmail-summary))
627 (rmail-construct-io-menu)
628 (if run-mail-hook
629 (run-hooks 'rmail-mode-hook))))))
631 ;; Given the value of MAILPATH, return a list of inbox file names.
632 ;; This is turned off because it is not clear that the user wants
633 ;; all these inboxes to feed into the primary rmail file.
634 ; (defun rmail-convert-mailpath (string)
635 ; (let (idx list)
636 ; (while (setq idx (string-match "[%:]" string))
637 ; (let ((this (substring string 0 idx)))
638 ; (setq string (substring string (1+ idx)))
639 ; (setq list (cons (if (string-match "%" this)
640 ; (substring this 0 (string-match "%" this))
641 ; this)
642 ; list))))
643 ; list))
645 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
646 ; will not cause emacs 18.55 problems.
648 ;; This calls rmail-decode-babyl-format if the file is already Babyl.
650 (defun rmail-convert-file ()
651 (let (convert)
652 (widen)
653 (goto-char (point-min))
654 ;; If file doesn't start like a Babyl file,
655 ;; convert it to one, by adding a header and converting each message.
656 (cond ((looking-at "BABYL OPTIONS:"))
657 ((looking-at "Version: 5\n")
658 ;; Losing babyl file made by old version of Rmail.
659 ;; Just fix the babyl file header; don't make a new one,
660 ;; so we don't lose the Labels: file attribute, etc.
661 (let ((buffer-read-only nil))
662 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
663 ((equal (point-min) (point-max))
664 ;; Empty RMAIL file. Just insert the header.
665 (rmail-insert-rmail-file-header))
667 ;; Non-empty file in non-RMAIL format. Add header and convert.
668 (setq convert t)
669 (rmail-insert-rmail-file-header)))
670 ;; If file was not a Babyl file or if there are
671 ;; Unix format messages added at the end,
672 ;; convert file as necessary.
673 (if (or convert
674 (save-excursion
675 (goto-char (point-max))
676 (search-backward "\n\^_")
677 (forward-char 2)
678 (looking-at "\n*From ")))
679 (let ((buffer-read-only nil))
680 (message "Converting to Babyl format...")
681 ;; If file needs conversion, convert it all,
682 ;; except for the BABYL header.
683 ;; (rmail-convert-to-babyl-format would delete the header.)
684 (goto-char (point-min))
685 (search-forward "\n\^_" nil t)
686 (narrow-to-region (point) (point-max))
687 (rmail-convert-to-babyl-format)
688 (message "Converting to Babyl format...done"))
689 (if (and (not rmail-enable-mime)
690 rmail-enable-multibyte)
691 ;; We still have to decode BABYL part.
692 (rmail-decode-babyl-format)))))
694 (defun rmail-insert-rmail-file-header ()
695 (let ((buffer-read-only nil))
696 ;; -*-rmail-*- is here so that visiting the file normally
697 ;; recognizes it as an Rmail file.
698 (insert "BABYL OPTIONS: -*- rmail -*-
699 Version: 5
700 Labels:
701 Note: This is the header of an rmail file.
702 Note: If you are seeing it in rmail,
703 Note: it means the file has no messages in it.\n\^_")))
705 ;; Decode Babyl formated part at the head of current buffer by
706 ;; rmail-file-coding-system, or if it is nil, do auto conversion.
708 (defun rmail-decode-babyl-format ()
709 (let ((modifiedp (buffer-modified-p))
710 (buffer-read-only nil)
711 (coding-system rmail-file-coding-system)
712 from to)
713 (goto-char (point-min))
714 (search-forward "\n\^_" nil t) ; Skip BABYL header.
715 (setq from (point))
716 (goto-char (point-max))
717 (search-backward "\n\^_" from 'mv)
718 (setq to (point))
719 (unless (and coding-system
720 (coding-system-p coding-system))
721 (setq coding-system (detect-coding-region from to t)))
722 (unless (memq coding-system
723 '(undecided undecided-unix))
724 (set-buffer-modified-p t) ; avoid locking when decoding
725 (decode-coding-region from to coding-system)
726 (setq coding-system last-coding-system-used))
727 (set-buffer-modified-p modifiedp)
728 (setq buffer-file-coding-system nil)
729 (setq save-buffer-coding-system
730 (or coding-system 'undecided))))
732 (defvar rmail-mode-map nil)
733 (if rmail-mode-map
735 (setq rmail-mode-map (make-keymap))
736 (suppress-keymap rmail-mode-map)
737 (define-key rmail-mode-map "a" 'rmail-add-label)
738 (define-key rmail-mode-map "b" 'rmail-bury)
739 (define-key rmail-mode-map "c" 'rmail-continue)
740 (define-key rmail-mode-map "d" 'rmail-delete-forward)
741 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)
742 (define-key rmail-mode-map "e" 'rmail-edit-current-message)
743 (define-key rmail-mode-map "f" 'rmail-forward)
744 (define-key rmail-mode-map "g" 'rmail-get-new-mail)
745 (define-key rmail-mode-map "h" 'rmail-summary)
746 (define-key rmail-mode-map "i" 'rmail-input)
747 (define-key rmail-mode-map "j" 'rmail-show-message)
748 (define-key rmail-mode-map "k" 'rmail-kill-label)
749 (define-key rmail-mode-map "l" 'rmail-summary-by-labels)
750 (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
751 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
752 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
753 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
754 (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
755 (define-key rmail-mode-map "m" 'rmail-mail)
756 (define-key rmail-mode-map "\em" 'rmail-retry-failure)
757 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message)
758 (define-key rmail-mode-map "\en" 'rmail-next-message)
759 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
760 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file)
761 (define-key rmail-mode-map "\C-o" 'rmail-output)
762 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message)
763 (define-key rmail-mode-map "\ep" 'rmail-previous-message)
764 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
765 (define-key rmail-mode-map "q" 'rmail-quit)
766 (define-key rmail-mode-map "r" 'rmail-reply)
767 ;; I find I can't live without the default M-r command -- rms.
768 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
769 (define-key rmail-mode-map "s" 'rmail-expunge-and-save)
770 (define-key rmail-mode-map "\es" 'rmail-search)
771 (define-key rmail-mode-map "t" 'rmail-toggle-header)
772 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message)
773 (define-key rmail-mode-map "w" 'rmail-output-body-to-file)
774 (define-key rmail-mode-map "x" 'rmail-expunge)
775 (define-key rmail-mode-map "." 'rmail-beginning-of-message)
776 (define-key rmail-mode-map "<" 'rmail-first-message)
777 (define-key rmail-mode-map ">" 'rmail-last-message)
778 (define-key rmail-mode-map " " 'scroll-up)
779 (define-key rmail-mode-map "\177" 'scroll-down)
780 (define-key rmail-mode-map "?" 'describe-mode)
781 (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
782 (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
783 (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
784 (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
785 (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
786 (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
787 (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-keywords)
788 (define-key rmail-mode-map "\C-c\C-n" 'rmail-next-same-subject)
789 (define-key rmail-mode-map "\C-c\C-p" 'rmail-previous-same-subject)
792 (define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
794 (define-key rmail-mode-map [menu-bar classify]
795 (cons "Classify" (make-sparse-keymap "Classify")))
797 (define-key rmail-mode-map [menu-bar classify input-menu]
798 nil)
800 (define-key rmail-mode-map [menu-bar classify output-menu]
801 nil)
803 (define-key rmail-mode-map [menu-bar classify output-body]
804 '("Output body to file..." . rmail-output-body-to-file))
806 (define-key rmail-mode-map [menu-bar classify output-inbox]
807 '("Output (inbox)..." . rmail-output))
809 (define-key rmail-mode-map [menu-bar classify output]
810 '("Output (Rmail)..." . rmail-output-to-rmail-file))
812 (define-key rmail-mode-map [menu-bar classify kill-label]
813 '("Kill Label..." . rmail-kill-label))
815 (define-key rmail-mode-map [menu-bar classify add-label]
816 '("Add Label..." . rmail-add-label))
818 (define-key rmail-mode-map [menu-bar summary]
819 (cons "Summary" (make-sparse-keymap "Summary")))
821 (define-key rmail-mode-map [menu-bar summary senders]
822 '("By Senders..." . rmail-summary-by-senders))
824 (define-key rmail-mode-map [menu-bar summary labels]
825 '("By Labels..." . rmail-summary-by-labels))
827 (define-key rmail-mode-map [menu-bar summary recipients]
828 '("By Recipients..." . rmail-summary-by-recipients))
830 (define-key rmail-mode-map [menu-bar summary topic]
831 '("By Topic..." . rmail-summary-by-topic))
833 (define-key rmail-mode-map [menu-bar summary regexp]
834 '("By Regexp..." . rmail-summary-by-regexp))
836 (define-key rmail-mode-map [menu-bar summary all]
837 '("All" . rmail-summary))
839 (define-key rmail-mode-map [menu-bar mail]
840 (cons "Mail" (make-sparse-keymap "Mail")))
842 (define-key rmail-mode-map [menu-bar mail rmail-get-new-mail]
843 '("Get New Mail" . rmail-get-new-mail))
845 (define-key rmail-mode-map [menu-bar mail lambda]
846 '("----"))
848 (define-key rmail-mode-map [menu-bar mail continue]
849 '("Continue" . rmail-continue))
851 (define-key rmail-mode-map [menu-bar mail resend]
852 '("Re-send..." . rmail-resend))
854 (define-key rmail-mode-map [menu-bar mail forward]
855 '("Forward" . rmail-forward))
857 (define-key rmail-mode-map [menu-bar mail retry]
858 '("Retry" . rmail-retry-failure))
860 (define-key rmail-mode-map [menu-bar mail reply]
861 '("Reply" . rmail-reply))
863 (define-key rmail-mode-map [menu-bar mail mail]
864 '("Mail" . rmail-mail))
866 (define-key rmail-mode-map [menu-bar delete]
867 (cons "Delete" (make-sparse-keymap "Delete")))
869 (define-key rmail-mode-map [menu-bar delete expunge/save]
870 '("Expunge/Save" . rmail-expunge-and-save))
872 (define-key rmail-mode-map [menu-bar delete expunge]
873 '("Expunge" . rmail-expunge))
875 (define-key rmail-mode-map [menu-bar delete undelete]
876 '("Undelete" . rmail-undelete-previous-message))
878 (define-key rmail-mode-map [menu-bar delete delete]
879 '("Delete" . rmail-delete-forward))
881 (define-key rmail-mode-map [menu-bar move]
882 (cons "Move" (make-sparse-keymap "Move")))
884 (define-key rmail-mode-map [menu-bar move search-back]
885 '("Search Back..." . rmail-search-backwards))
887 (define-key rmail-mode-map [menu-bar move search]
888 '("Search..." . rmail-search))
890 (define-key rmail-mode-map [menu-bar move previous]
891 '("Previous Nondeleted" . rmail-previous-undeleted-message))
893 (define-key rmail-mode-map [menu-bar move next]
894 '("Next Nondeleted" . rmail-next-undeleted-message))
896 (define-key rmail-mode-map [menu-bar move last]
897 '("Last" . rmail-last-message))
899 (define-key rmail-mode-map [menu-bar move first]
900 '("First" . rmail-first-message))
902 (define-key rmail-mode-map [menu-bar move previous]
903 '("Previous" . rmail-previous-message))
905 (define-key rmail-mode-map [menu-bar move next]
906 '("Next" . rmail-next-message))
908 ;; Rmail mode is suitable only for specially formatted data.
909 (put 'rmail-mode 'mode-class 'special)
911 (defun rmail-mode-kill-summary ()
912 (if rmail-summary-buffer (kill-buffer rmail-summary-buffer)))
914 ;;;###autoload
915 (defun rmail-mode ()
916 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
917 All normal editing commands are turned off.
918 Instead, these commands are available:
920 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
921 \\[scroll-up] Scroll to next screen of this message.
922 \\[scroll-down] Scroll to previous screen of this message.
923 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
924 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
925 \\[rmail-next-message] Move to Next message whether deleted or not.
926 \\[rmail-previous-message] Move to Previous message whether deleted or not.
927 \\[rmail-first-message] Move to the first message in Rmail file.
928 \\[rmail-last-message] Move to the last message in Rmail file.
929 \\[rmail-show-message] Jump to message specified by numeric position in file.
930 \\[rmail-search] Search for string and show message it is found in.
931 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
932 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
933 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
934 till a deleted message is found.
935 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
936 \\[rmail-expunge] Expunge deleted messages.
937 \\[rmail-expunge-and-save] Expunge and save the file.
938 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
939 \\[save-buffer] Save without expunging.
940 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
941 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
942 \\[rmail-continue] Continue composing outgoing message started before.
943 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
944 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
945 \\[rmail-forward] Forward this message to another user.
946 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
947 \\[rmail-output] Output this message to a Unix-format mail file (append it).
948 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
949 \\[rmail-input] Input Rmail file. Run Rmail on that file.
950 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
951 \\[rmail-kill-label] Kill label. Remove a label from current message.
952 \\[rmail-next-labeled-message] Move to Next message with specified label
953 (label defaults to last one specified).
954 Standard labels: filed, unseen, answered, forwarded, deleted.
955 Any other label is present only if you add it with \\[rmail-add-label].
956 \\[rmail-previous-labeled-message] Move to Previous message with specified label
957 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
958 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
959 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
960 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
961 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
962 \\[rmail-toggle-header] Toggle display of complete header."
963 (interactive)
964 (rmail-mode-2)
965 (rmail-set-message-counters)
966 (rmail-show-message rmail-total-messages)
967 (run-hooks 'rmail-mode-hook))
969 (defun rmail-mode-2 ()
970 (kill-all-local-variables)
971 (rmail-mode-1)
972 (rmail-perm-variables)
973 (rmail-variables))
975 (defun rmail-mode-1 ()
976 (setq major-mode 'rmail-mode)
977 (setq mode-name "RMAIL")
978 (setq buffer-read-only t)
979 ;; No need to auto save RMAIL files in normal circumstances
980 ;; because they contain no info except attribute changes
981 ;; and deletion of messages.
982 ;; The one exception is when messages are copied into an Rmail mode buffer.
983 ;; rmail-output-to-rmail-file enables auto save when you do that.
984 (setq buffer-auto-save-file-name nil)
985 (setq mode-line-modified "--")
986 (use-local-map rmail-mode-map)
987 (set-syntax-table text-mode-syntax-table)
988 (setq local-abbrev-table text-mode-abbrev-table))
990 ;; Set up the permanent locals associated with an Rmail file.
991 (defun rmail-perm-variables ()
992 (make-local-variable 'rmail-last-label)
993 (make-local-variable 'rmail-last-regexp)
994 (make-local-variable 'rmail-deleted-vector)
995 (make-local-variable 'rmail-buffer)
996 (setq rmail-buffer (current-buffer))
997 (make-local-variable 'rmail-view-buffer)
998 (setq rmail-view-buffer rmail-buffer)
999 (make-local-variable 'rmail-summary-buffer)
1000 (make-local-variable 'rmail-summary-vector)
1001 (make-local-variable 'rmail-current-message)
1002 (make-local-variable 'rmail-total-messages)
1003 (make-local-variable 'rmail-overlay-list)
1004 (setq rmail-overlay-list nil)
1005 (make-local-variable 'rmail-message-vector)
1006 (make-local-variable 'rmail-msgref-vector)
1007 (make-local-variable 'rmail-inbox-list)
1008 (setq rmail-inbox-list (rmail-parse-file-inboxes))
1009 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1010 (and (null rmail-inbox-list)
1011 (or (equal buffer-file-name (expand-file-name rmail-file-name))
1012 (equal buffer-file-truename
1013 (abbreviate-file-name (file-truename rmail-file-name))))
1014 (setq rmail-inbox-list
1015 (or rmail-primary-inbox-list
1016 (list (or (getenv "MAIL")
1017 (concat rmail-spool-directory
1018 (user-login-name)))))))
1019 (make-local-variable 'rmail-keywords)
1020 ;; this gets generated as needed
1021 (setq rmail-keywords nil))
1023 ;; Set up the non-permanent locals associated with Rmail mode.
1024 (defun rmail-variables ()
1025 (make-local-variable 'save-buffer-coding-system)
1026 ;; If we don't already have a value for save-buffer-coding-system,
1027 ;; get it from buffer-file-coding-system, and clear that
1028 ;; because it should be determined in rmail-show-message.
1029 (unless save-buffer-coding-system
1030 (setq save-buffer-coding-system (or buffer-file-coding-system 'undecided))
1031 (setq buffer-file-coding-system nil))
1032 ;; Don't let a local variables list in a message cause confusion.
1033 (make-local-variable 'local-enable-local-variables)
1034 (setq local-enable-local-variables nil)
1035 (make-local-variable 'revert-buffer-function)
1036 (setq revert-buffer-function 'rmail-revert)
1037 (make-local-variable 'font-lock-defaults)
1038 (setq font-lock-defaults
1039 '(rmail-font-lock-keywords
1040 t nil nil nil
1041 (font-lock-maximum-size . nil)
1042 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function)
1043 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function)
1044 (font-lock-inhibit-thing-lock . (lazy-lock-mode fast-lock-mode))))
1045 (make-local-variable 'require-final-newline)
1046 (setq require-final-newline nil)
1047 (make-local-variable 'version-control)
1048 (setq version-control 'never)
1049 (make-local-variable 'kill-buffer-hook)
1050 (add-hook 'kill-buffer-hook 'rmail-mode-kill-summary)
1051 (make-local-variable 'file-precious-flag)
1052 (setq file-precious-flag t))
1054 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1055 (defun rmail-revert (arg noconfirm)
1056 (let* ((revert-buffer-function (default-value 'revert-buffer-function))
1057 (rmail-enable-multibyte enable-multibyte-characters)
1058 ;; See similar code in `rmail'.
1059 (coding-system-for-read (and rmail-enable-multibyte 'raw-text)))
1060 ;; Call our caller again, but this time it does the default thing.
1061 (if (revert-buffer arg noconfirm)
1062 ;; If the user said "yes", and we changed something,
1063 ;; reparse the messages.
1064 (progn
1065 (rmail-mode-2)
1066 ;; Convert all or part to Babyl file if possible.
1067 (rmail-convert-file)
1068 ;; We have read the file as raw-text, so the buffer is set to
1069 ;; unibyte. Make it multibyte if necessary.
1070 (if (and rmail-enable-multibyte
1071 (not enable-multibyte-characters))
1072 (set-buffer-multibyte t))
1073 (goto-char (point-max))
1074 (rmail-set-message-counters)
1075 (rmail-show-message rmail-total-messages)
1076 (run-hooks 'rmail-mode-hook)))))
1078 ;; Return a list of files from this buffer's Mail: option.
1079 ;; Does not assume that messages have been parsed.
1080 ;; Just returns nil if buffer does not look like Babyl format.
1081 (defun rmail-parse-file-inboxes ()
1082 (save-excursion
1083 (save-restriction
1084 (widen)
1085 (goto-char 1)
1086 (cond ((looking-at "BABYL OPTIONS:")
1087 (search-forward "\n\^_" nil 'move)
1088 (narrow-to-region 1 (point))
1089 (goto-char 1)
1090 (if (search-forward "\nMail:" nil t)
1091 (progn
1092 (narrow-to-region (point) (progn (end-of-line) (point)))
1093 (goto-char (point-min))
1094 (mail-parse-comma-list))))))))
1096 (defun rmail-expunge-and-save ()
1097 "Expunge and save RMAIL file."
1098 (interactive)
1099 (rmail-expunge)
1100 (save-buffer)
1101 (if (rmail-summary-exists)
1102 (rmail-select-summary (set-buffer-modified-p nil))))
1104 (defun rmail-quit ()
1105 "Quit out of RMAIL.
1106 Hook `rmail-quit-hook' is run after expunging."
1107 (interactive)
1108 (rmail-expunge-and-save)
1109 (when (boundp 'rmail-quit-hook)
1110 (run-hooks 'rmail-quit-hook))
1111 ;; Don't switch to the summary buffer even if it was recently visible.
1112 (when rmail-summary-buffer
1113 (replace-buffer-in-windows rmail-summary-buffer)
1114 (bury-buffer rmail-summary-buffer))
1115 (let ((obuf (current-buffer)))
1116 (quit-window)
1117 (replace-buffer-in-windows obuf)))
1119 (defun rmail-bury ()
1120 "Bury current Rmail buffer and its summary buffer."
1121 (interactive)
1122 ;; This let var was called rmail-buffer, but that interfered
1123 ;; with the buffer-local var used in summary buffers.
1124 (let ((buffer-to-bury (current-buffer)))
1125 (if (rmail-summary-exists)
1126 (let (window)
1127 (while (setq window (get-buffer-window rmail-summary-buffer))
1128 (quit-window nil window))
1129 (bury-buffer rmail-summary-buffer)))
1130 (quit-window)))
1132 (defun rmail-duplicate-message ()
1133 "Create a duplicated copy of the current message.
1134 The duplicate copy goes into the Rmail file just after the
1135 original copy."
1136 (interactive)
1137 (widen)
1138 (let ((buffer-read-only nil)
1139 (number rmail-current-message)
1140 (string (buffer-substring (rmail-msgbeg rmail-current-message)
1141 (rmail-msgend rmail-current-message))))
1142 (goto-char (rmail-msgend rmail-current-message))
1143 (insert string)
1144 (rmail-forget-messages)
1145 (rmail-show-message number)
1146 (message "Message duplicated")))
1148 ;;;###autoload
1149 (defun rmail-input (filename)
1150 "Run Rmail on file FILENAME."
1151 (interactive "FRun rmail on RMAIL file: ")
1152 (rmail filename))
1155 ;; This used to scan subdirectories recursively, but someone pointed out
1156 ;; that if the user wants that, person can put all the files in one dir.
1157 ;; And the recursive scan was slow. So I took it out.
1158 ;; rms, Sep 1996.
1159 (defun rmail-find-all-files (start)
1160 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1161 (if (file-accessible-directory-p start)
1162 ;; Don't sort here.
1163 (let* ((case-fold-search t)
1164 (files (directory-files start t rmail-secondary-file-regexp)))
1165 ;; Sort here instead of in directory-files
1166 ;; because this list is usually much shorter.
1167 (sort files 'string<))))
1169 (defun rmail-list-to-menu (menu-name l action &optional full-name)
1170 (let ((menu (make-sparse-keymap menu-name)))
1171 (mapcar
1172 (function (lambda (item)
1173 (let (command)
1174 (if (consp item)
1175 (progn
1176 (setq command
1177 (rmail-list-to-menu (car item) (cdr item)
1178 action
1179 (if full-name
1180 (concat full-name "/"
1181 (car item))
1182 (car item))))
1183 (setq name (car item)))
1184 (progn
1185 (setq name item)
1186 (setq command
1187 (list 'lambda () '(interactive)
1188 (list action
1189 (expand-file-name
1190 (if full-name
1191 (concat full-name "/" item)
1192 item)
1193 rmail-secondary-file-directory))))))
1194 (define-key menu (vector (intern name))
1195 (cons name command)))))
1196 (reverse l))
1197 menu))
1199 ;; This command is always "disabled" when it appears in a menu.
1200 (put 'rmail-disable-menu 'menu-enable ''nil)
1202 (defun rmail-construct-io-menu ()
1203 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
1204 (if files
1205 (progn
1206 (define-key rmail-mode-map [menu-bar classify input-menu]
1207 (cons "Input Rmail File"
1208 (rmail-list-to-menu "Input Rmail File"
1209 files
1210 'rmail-input)))
1211 (define-key rmail-mode-map [menu-bar classify output-menu]
1212 (cons "Output Rmail File"
1213 (rmail-list-to-menu "Output Rmail File"
1214 files
1215 'rmail-output-to-rmail-file))))
1217 (define-key rmail-mode-map [menu-bar classify input-menu]
1218 '("Input Rmail File" . rmail-disable-menu))
1219 (define-key rmail-mode-map [menu-bar classify output-menu]
1220 '("Output Rmail File" . rmail-disable-menu)))))
1223 ;;;; *** Rmail input ***
1225 ;; RLK feature not added in this version:
1226 ;; argument specifies inbox file or files in various ways.
1228 (defun rmail-get-new-mail (&optional file-name)
1229 "Move any new mail from this RMAIL file's inbox files.
1230 The inbox files can be specified with the file's Mail: option. The
1231 variable `rmail-primary-inbox-list' specifies the inboxes for your
1232 primary RMAIL file if it has no Mail: option. By default, this is
1233 your /usr/spool/mail/$USER.
1235 You can also specify the file to get new mail from. In this case, the
1236 file of new mail is not changed or deleted. Noninteractively, you can
1237 pass the inbox file name as an argument. Interactively, a prefix
1238 argument causes us to read a file name and use that file as the inbox.
1240 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1241 always be left in inbox files rather than deleted.
1243 This function runs `rmail-get-new-mail-hook' before saving the updated file.
1244 It returns t if it got any new messages."
1245 (interactive
1246 (list (if current-prefix-arg
1247 (read-file-name "Get new mail from file: "))))
1248 (run-hooks 'rmail-before-get-new-mail-hook)
1249 ;; If the disk file has been changed from under us,
1250 ;; revert to it before we get new mail.
1251 (or (verify-visited-file-modtime (current-buffer))
1252 (find-file (buffer-file-name)))
1253 (rmail-maybe-set-message-counters)
1254 (widen)
1255 ;; Get rid of all undo records for this buffer.
1256 (or (eq buffer-undo-list t)
1257 (setq buffer-undo-list nil))
1258 (let ((all-files (if file-name (list file-name)
1259 rmail-inbox-list))
1260 (rmail-enable-multibyte (default-value 'enable-multibyte-characters))
1261 found)
1262 (unwind-protect
1263 (progn
1264 (while all-files
1265 (let ((opoint (point))
1266 (new-messages 0)
1267 (delete-files ())
1268 ;; If buffer has not changed yet, and has not been saved yet,
1269 ;; don't replace the old backup file now.
1270 (make-backup-files (and make-backup-files (buffer-modified-p)))
1271 (buffer-read-only nil)
1272 ;; Don't make undo records for what we do in getting mail.
1273 (buffer-undo-list t)
1274 success
1275 ;; Files to insert this time around.
1276 files
1277 ;; Last names of those files.
1278 file-last-names)
1279 ;; Pull files off all-files onto files
1280 ;; as long as there is no name conflict.
1281 ;; A conflict happens when two inbox file names
1282 ;; have the same last component.
1283 (while (and all-files
1284 (not (member (file-name-nondirectory (car all-files))
1285 file-last-names)))
1286 (setq files (cons (car all-files) files)
1287 file-last-names
1288 (cons (file-name-nondirectory (car all-files)) files))
1289 (setq all-files (cdr all-files)))
1290 ;; Put them back in their original order.
1291 (setq files (nreverse files))
1293 (goto-char (point-max))
1294 (skip-chars-backward " \t\n") ; just in case of brain damage
1295 (delete-region (point) (point-max)) ; caused by require-final-newline
1296 (save-excursion
1297 (save-restriction
1298 (narrow-to-region (point) (point))
1299 ;; Read in the contents of the inbox files,
1300 ;; renaming them as necessary,
1301 ;; and adding to the list of files to delete eventually.
1302 (if file-name
1303 (rmail-insert-inbox-text files nil)
1304 (setq delete-files (rmail-insert-inbox-text files t)))
1305 ;; Scan the new text and convert each message to babyl format.
1306 (goto-char (point-min))
1307 (unwind-protect
1308 (save-excursion
1309 (setq new-messages (rmail-convert-to-babyl-format)
1310 success t))
1311 ;; Try to delete the garbage just inserted.
1312 (or success (delete-region (point-min) (point-max)))
1313 ;; If we could not convert the file's inboxes,
1314 ;; rename the files we tried to read
1315 ;; so we won't over and over again.
1316 (if (and (not file-name) (not success))
1317 (let ((delfiles delete-files)
1318 (count 0))
1319 (while delfiles
1320 (while (file-exists-p (format "RMAILOSE.%d" count))
1321 (setq count (1+ count)))
1322 (rename-file (car delfiles)
1323 (format "RMAILOSE.%d" count))
1324 (setq delfiles (cdr delfiles))))))
1325 (or (zerop new-messages)
1326 (let (success)
1327 (widen)
1328 (search-backward "\n\^_" nil t)
1329 (narrow-to-region (point) (point-max))
1330 (goto-char (1+ (point-min)))
1331 (rmail-count-new-messages)
1332 (run-hooks 'rmail-get-new-mail-hook)
1333 (save-buffer)))
1334 ;; Delete the old files, now that babyl file is saved.
1335 (while delete-files
1336 (condition-case ()
1337 ;; First, try deleting.
1338 (condition-case ()
1339 (delete-file (car delete-files))
1340 (file-error
1341 ;; If we can't delete it, truncate it.
1342 (write-region (point) (point) (car delete-files))))
1343 (file-error nil))
1344 (setq delete-files (cdr delete-files)))))
1345 (if (= new-messages 0)
1346 (progn (goto-char opoint)
1347 (if (or file-name rmail-inbox-list)
1348 (message "(No new mail has arrived)")))
1349 (if (rmail-summary-exists)
1350 (rmail-select-summary
1351 (rmail-update-summary)))
1352 (message "%d new message%s read"
1353 new-messages (if (= 1 new-messages) "" "s"))
1354 ;; Move to the first new message
1355 ;; unless we have other unseen messages before it.
1356 (rmail-show-message (rmail-first-unseen-message))
1357 (run-hooks 'rmail-after-get-new-mail-hook)
1358 (setq found t))))
1359 found)
1360 ;; Don't leave the buffer screwed up if we get a disk-full error.
1361 (or found (rmail-show-message)))))
1363 (defun rmail-insert-inbox-text (files renamep)
1364 ;; Detect a locked file now, so that we avoid moving mail
1365 ;; out of the real inbox file. (That could scare people.)
1366 (or (memq (file-locked-p buffer-file-name) '(nil t))
1367 (error "RMAIL file %s is locked"
1368 (file-name-nondirectory buffer-file-name)))
1369 (let (file tofile delete-files movemail popmail got-password password)
1370 (while files
1371 ;; Handle POP mailbox names specially; don't expand as filenames
1372 ;; in case the userid contains a directory separator.
1373 (setq file (car files))
1374 (setq popmail (string-match "^po:" file))
1375 (if popmail
1376 (setq renamep t)
1377 (setq file (file-truename
1378 (expand-file-name (substitute-in-file-name file)))))
1379 (setq tofile (expand-file-name
1380 ;; Generate name to move to from inbox name,
1381 ;; in case of multiple inboxes that need moving.
1382 (concat ".newmail-" (file-name-nondirectory file))
1383 ;; Use the directory of this rmail file
1384 ;; because it's a nuisance to use the homedir
1385 ;; if that is on a full disk and this rmail
1386 ;; file isn't.
1387 (file-name-directory
1388 (expand-file-name buffer-file-name))))
1389 ;; Always use movemail to rename the file,
1390 ;; since there can be mailboxes in various directories.
1391 (setq movemail t)
1392 ;;; ;; If getting from mail spool directory,
1393 ;;; ;; use movemail to move rather than just renaming,
1394 ;;; ;; so as to interlock with the mailer.
1395 ;;; (setq movemail (string= file
1396 ;;; (file-truename
1397 ;;; (concat rmail-spool-directory
1398 ;;; (file-name-nondirectory file)))))
1399 (if (and movemail (not popmail))
1400 (progn
1401 ;; On some systems, /usr/spool/mail/foo is a directory
1402 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1403 (if (file-directory-p file)
1404 (setq file (expand-file-name (user-login-name)
1405 file)))))
1406 (cond (popmail
1407 (if rmail-pop-password-required
1408 (progn (setq got-password (not (rmail-have-password)))
1409 (setq password (rmail-get-pop-password))))
1410 (if (eq system-type 'windows-nt)
1411 ;; cannot have "po:" in file name
1412 (setq tofile
1413 (expand-file-name
1414 (concat ".newmail-pop-"
1415 (file-name-nondirectory (substring file 3)))
1416 (file-name-directory
1417 (expand-file-name buffer-file-name)))))
1418 (message "Getting mail from post office ..."))
1419 ((and (file-exists-p tofile)
1420 (/= 0 (nth 7 (file-attributes tofile))))
1421 (message "Getting mail from %s..." tofile))
1422 ((and (file-exists-p file)
1423 (/= 0 (nth 7 (file-attributes file))))
1424 (message "Getting mail from %s..." file)))
1425 ;; Set TOFILE if have not already done so, and
1426 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1427 (cond ((not renamep)
1428 (setq tofile file))
1429 ((or (file-exists-p tofile) (and (not popmail)
1430 (not (file-exists-p file))))
1431 nil)
1432 ((and (not movemail) (not popmail))
1433 ;; Try copying. If that fails (perhaps no space) and
1434 ;; we're allowed to blow away the inbox, rename instead.
1435 (if rmail-preserve-inbox
1436 (copy-file file tofile nil)
1437 (condition-case nil
1438 (copy-file file tofile nil)
1439 (error
1440 ;; Third arg is t so we can replace existing file TOFILE.
1441 (rename-file file tofile t))))
1442 ;; Make the real inbox file empty.
1443 ;; Leaving it deleted could cause lossage
1444 ;; because mailers often won't create the file.
1445 (if (not rmail-preserve-inbox)
1446 (condition-case ()
1447 (write-region (point) (point) file)
1448 (file-error nil))))
1450 (let ((errors nil))
1451 (unwind-protect
1452 (save-excursion
1453 (setq errors (generate-new-buffer " *rmail loss*"))
1454 (buffer-disable-undo errors)
1455 (let ((args
1456 (append
1457 (list (or rmail-movemail-program
1458 (expand-file-name "movemail"
1459 exec-directory))
1460 nil errors nil)
1461 (if rmail-preserve-inbox
1462 (list "-p")
1463 nil)
1464 rmail-movemail-flags
1465 (list file tofile)
1466 (if password (list password) nil))))
1467 (apply 'call-process args))
1468 (if (not (buffer-modified-p errors))
1469 ;; No output => movemail won
1471 (set-buffer errors)
1472 (subst-char-in-region (point-min) (point-max)
1473 ?\n ?\ )
1474 (goto-char (point-max))
1475 (skip-chars-backward " \t")
1476 (delete-region (point) (point-max))
1477 (goto-char (point-min))
1478 (if (looking-at "movemail: ")
1479 (delete-region (point-min) (match-end 0)))
1480 (beep t)
1481 (message "movemail: %s"
1482 (buffer-substring (point-min)
1483 (point-max)))
1484 ;; If we just read the password, most likely it is
1485 ;; wrong. Otherwise, see if there is a specific
1486 ;; reason to think that the problem is a wrong passwd.
1487 (if (or got-password
1488 (re-search-forward rmail-pop-password-error
1489 nil t))
1490 (rmail-set-pop-password nil))
1491 (sit-for 3)
1492 nil))
1493 (if errors (kill-buffer errors))))))
1494 ;; At this point, TOFILE contains the name to read:
1495 ;; Either the alternate name (if we renamed)
1496 ;; or the actual inbox (if not renaming).
1497 (if (file-exists-p tofile)
1498 (let ((coding-system-for-read 'no-conversion)
1499 size)
1500 (goto-char (point-max))
1501 (setq size (nth 1 (insert-file-contents tofile)))
1502 (goto-char (point-max))
1503 (or (= (preceding-char) ?\n)
1504 (zerop size)
1505 (insert ?\n))
1506 (if (not (and rmail-preserve-inbox (string= file tofile)))
1507 (setq delete-files (cons tofile delete-files)))))
1508 (message "")
1509 (setq files (cdr files)))
1510 delete-files))
1512 ;; Decode the region specified by FROM and TO by CODING.
1513 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
1514 (defun rmail-decode-region (from to coding)
1515 (if (or (not coding) (not (coding-system-p coding)))
1516 (setq coding 'undecided))
1517 (decode-coding-region from to coding))
1519 ;; the rmail-break-forwarded-messages feature is not implemented
1520 (defun rmail-convert-to-babyl-format ()
1521 (let ((count 0) start
1522 (case-fold-search nil)
1523 (invalid-input-resync
1524 (function (lambda ()
1525 (message "Invalid Babyl format in inbox!")
1526 (sit-for 3)
1527 ;; Try to get back in sync with a real message.
1528 (if (re-search-forward
1529 (concat rmail-mmdf-delim1 "\\|^From") nil t)
1530 (beginning-of-line)
1531 (goto-char (point-max)))))))
1532 (goto-char (point-min))
1533 (save-restriction
1534 (while (not (eobp))
1535 (setq start (point))
1536 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1537 (if (search-forward "\n\^_" nil t)
1538 ;; If we find the proper terminator, delete through there.
1539 (delete-region (point-min) (point))
1540 (funcall invalid-input-resync)
1541 (delete-region (point-min) (point))))
1542 ;; Babyl format message
1543 ((looking-at "\^L")
1544 (or (search-forward "\n\^_" nil t)
1545 (funcall invalid-input-resync))
1546 (setq count (1+ count))
1547 ;; Make sure there is no extra white space after the ^_
1548 ;; at the end of the message.
1549 ;; Narrowing will make sure that whatever follows the junk
1550 ;; will be treated properly.
1551 (delete-region (point)
1552 (save-excursion
1553 (skip-chars-forward " \t\n")
1554 (point)))
1555 (setq last-coding-system-used nil)
1556 (or rmail-enable-mime
1557 (not rmail-enable-multibyte)
1558 (decode-coding-region start (point)
1559 (or rmail-file-coding-system
1560 'undecided)))
1561 ;; Add an X-Coding-System: header if we don't have one.
1562 (save-excursion
1563 (goto-char start)
1564 (forward-line 1)
1565 (if (looking-at "0")
1566 (forward-line 1)
1567 (forward-line 2))
1568 (or (save-restriction
1569 (narrow-to-region (point) (point-max))
1570 (rfc822-goto-eoh)
1571 (goto-char (point-min))
1572 (re-search-forward "^X-Coding-System:" nil t))
1573 (insert "X-Coding-System: "
1574 (symbol-name last-coding-system-used)
1575 "\n")))
1576 (narrow-to-region (point) (point-max)))
1577 ;;*** MMDF format
1578 ((let ((case-fold-search t))
1579 (looking-at rmail-mmdf-delim1))
1580 (let ((case-fold-search t))
1581 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1582 (re-search-forward rmail-mmdf-delim2 nil t)
1583 (replace-match "\^_"))
1584 (save-excursion
1585 (save-restriction
1586 (narrow-to-region start (1- (point)))
1587 (goto-char (point-min))
1588 (while (search-forward "\n\^_" nil t); single char "\^_"
1589 (replace-match "\n^_")))); 2 chars: "^" and "_"
1590 (setq last-coding-system-used nil)
1591 (or rmail-enable-mime
1592 (not rmail-enable-multibyte)
1593 (decode-coding-region start (point) 'undecided))
1594 (save-excursion
1595 (goto-char start)
1596 (forward-line 3)
1597 (insert "X-Coding-System: "
1598 (symbol-name last-coding-system-used)
1599 "\n"))
1600 (narrow-to-region (point) (point-max))
1601 (setq count (1+ count)))
1602 ;;*** Mail format
1603 ((looking-at "^From ")
1604 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1605 (rmail-nuke-pinhead-header)
1606 ;; If this message has a Content-Length field,
1607 ;; skip to the end of the contents.
1608 (let* ((header-end (save-excursion
1609 (and (re-search-forward "\n\n" nil t)
1610 (1- (point)))))
1611 (case-fold-search t)
1612 (quoted-printable-header-field-end
1613 (save-excursion
1614 (re-search-forward
1615 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
1616 header-end t)))
1617 (size
1618 ;; Get the numeric value from the Content-Length field.
1619 (save-excursion
1620 ;; Back up to end of prev line,
1621 ;; in case the Content-Length field comes first.
1622 (forward-char -1)
1623 (and (search-forward "\ncontent-length: "
1624 header-end t)
1625 (let ((beg (point))
1626 (eol (progn (end-of-line) (point))))
1627 (string-to-int (buffer-substring beg eol)))))))
1628 (and size
1629 (if (and (natnump size)
1630 (<= (+ header-end size) (point-max))
1631 ;; Make sure this would put us at a position
1632 ;; that we could continue from.
1633 (save-excursion
1634 (goto-char (+ header-end size))
1635 (skip-chars-forward "\n")
1636 (or (eobp)
1637 (and (looking-at "BABYL OPTIONS:")
1638 (search-forward "\n\^_" nil t))
1639 (and (looking-at "\^L")
1640 (search-forward "\n\^_" nil t))
1641 (let ((case-fold-search t))
1642 (looking-at rmail-mmdf-delim1))
1643 (looking-at "From "))))
1644 (goto-char (+ header-end size))
1645 (message "Ignoring invalid Content-Length field")
1646 (sit-for 1 0 t)))
1647 (if (re-search-forward
1648 (concat "^[\^_]?\\("
1649 rmail-unix-mail-delimiter
1650 "\\|"
1651 rmail-mmdf-delim1 "\\|"
1652 "^BABYL OPTIONS:\\|"
1653 "\^L\n[01],\\)") nil t)
1654 (goto-char (match-beginning 1))
1655 (goto-char (point-max)))
1656 (setq count (1+ count))
1657 (if quoted-printable-header-field-end
1658 (save-excursion
1659 (rmail-decode-quoted-printable header-end (point))
1660 ;; Change "quoted-printable" to "8bit",
1661 ;; to reflect the decoding we just did.
1662 (goto-char quoted-printable-header-field-end)
1663 (delete-region (point) (search-backward ":"))
1664 (insert ": 8bit"))))
1666 (save-excursion
1667 (save-restriction
1668 (narrow-to-region start (point))
1669 (goto-char (point-min))
1670 (while (search-forward "\n\^_" nil t); single char
1671 (replace-match "\n^_")))); 2 chars: "^" and "_"
1672 (insert ?\^_)
1673 (setq last-coding-system-used nil)
1674 (or rmail-enable-mime
1675 (not rmail-enable-multibyte)
1676 (let ((mime-charset
1677 (if (and rmail-decode-mime-charset
1678 (save-excursion
1679 (goto-char start)
1680 (search-forward "\n\n" nil t)
1681 (let ((case-fold-search t))
1682 (re-search-backward
1683 rmail-mime-charset-pattern
1684 start t))))
1685 (intern (downcase (match-string 1))))))
1686 (rmail-decode-region start (point) mime-charset)))
1687 (save-excursion
1688 (goto-char start)
1689 (forward-line 3)
1690 (insert "X-Coding-System: "
1691 (symbol-name last-coding-system-used)
1692 "\n"))
1693 (narrow-to-region (point) (point-max)))
1695 ;; This kludge is because some versions of sendmail.el
1696 ;; insert an extra newline at the beginning that shouldn't
1697 ;; be there. sendmail.el has been fixed, but old versions
1698 ;; may still be in use. -- rms, 7 May 1993.
1699 ((eolp) (delete-char 1))
1700 (t (error "Cannot convert to babyl format")))))
1701 count))
1703 (defun rmail-hex-char-to-integer (character)
1704 "Return CHARACTER's value interpreted as a hex digit."
1705 (if (and (>= character ?0) (<= character ?9))
1706 (- character ?0)
1707 (let ((ch (logior character 32)))
1708 (if (and (>= ch ?a) (<= ch ?f))
1709 (- ch (- ?a 10))
1710 (error "Invalid hex digit `%c'" ch)))))
1712 (defun rmail-hex-string-to-integer (hex-string)
1713 "Return decimal integer for HEX-STRING."
1714 (let ((hex-num 0)
1715 (index 0))
1716 (while (< index (length hex-string))
1717 (setq hex-num (+ (* hex-num 16)
1718 (rmail-hex-char-to-integer (aref hex-string index))))
1719 (setq index (1+ index)))
1720 hex-num))
1722 (defun rmail-decode-quoted-printable (from to)
1723 "Decode Quoted-Printable in the region between FROM and TO."
1724 (interactive "r")
1725 (goto-char from)
1726 (or (markerp to)
1727 (setq to (copy-marker to)))
1728 (while (search-forward "=" to t)
1729 (cond ((eq (following-char) ?\n)
1730 (delete-char -1)
1731 (delete-char 1))
1732 ((looking-at "[0-9A-F][0-9A-F]")
1733 (let ((byte (rmail-hex-string-to-integer
1734 (buffer-substring (point) (+ 2 (point))))))
1735 (delete-region (1- (point)) (+ 2 (point)))
1736 (insert byte)))
1737 ((looking-at "=")
1738 (delete-char 1))
1740 (message "Malformed MIME quoted-printable message")))))
1742 ;; Delete the "From ..." line, creating various other headers with
1743 ;; information from it if they don't already exist. Now puts the
1744 ;; original line into a mail-from: header line for debugging and for
1745 ;; use by the rmail-output function.
1746 (defun rmail-nuke-pinhead-header ()
1747 (save-excursion
1748 (save-restriction
1749 (let ((start (point))
1750 (end (progn
1751 (condition-case ()
1752 (search-forward "\n\n")
1753 (error
1754 (goto-char (point-max))
1755 (insert "\n\n")))
1756 (point)))
1757 has-from has-date)
1758 (narrow-to-region start end)
1759 (let ((case-fold-search t))
1760 (goto-char start)
1761 (setq has-from (search-forward "\nFrom:" nil t))
1762 (goto-char start)
1763 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
1764 (goto-char start))
1765 (let ((case-fold-search nil))
1766 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
1767 (replace-match
1768 (concat
1769 "Mail-from: \\&"
1770 ;; Keep and reformat the date if we don't
1771 ;; have a Date: field.
1772 (if has-date
1774 (concat
1775 "Date: \\2, \\4 \\3 \\9 \\5 "
1777 ;; The timezone could be matched by group 7 or group 10.
1778 ;; If neither of them matched, assume EST, since only
1779 ;; Easterners would be so sloppy.
1780 ;; It's a shame the substitution can't use "\\10".
1781 (cond
1782 ((/= (match-beginning 7) (match-end 7)) "\\7")
1783 ((/= (match-beginning 10) (match-end 10))
1784 (buffer-substring (match-beginning 10)
1785 (match-end 10)))
1786 (t "EST"))
1787 "\n"))
1788 ;; Keep and reformat the sender if we don't
1789 ;; have a From: field.
1790 (if has-from
1792 "From: \\1\n"))
1793 t)))))))
1795 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1797 (defun rmail-reformat-message (beg end)
1798 (goto-char beg)
1799 (forward-line 1)
1800 (if (/= (following-char) ?0)
1801 (error "Bad format in RMAIL file."))
1802 (let ((buffer-read-only nil)
1803 (delta (- (buffer-size) end)))
1804 (delete-char 1)
1805 (insert ?1)
1806 (forward-line 1)
1807 (let ((case-fold-search t))
1808 (while (looking-at "Summary-line:\\|Mail-From:")
1809 (forward-line 1)))
1810 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1811 (delete-region (point)
1812 (progn (forward-line 1) (point))))
1813 (let ((str (buffer-substring (point)
1814 (save-excursion (search-forward "\n\n" end 'move)
1815 (point)))))
1816 (insert str "*** EOOH ***\n")
1817 (narrow-to-region (point) (- (buffer-size) delta)))
1818 (goto-char (point-min))
1819 (if rmail-message-filter (funcall rmail-message-filter))
1820 (if (or rmail-displayed-headers rmail-ignored-headers)
1821 (rmail-clear-headers))))
1823 (defun rmail-clear-headers (&optional ignored-headers)
1824 "Delete all header fields that Rmail should not show.
1825 If the optional argument IGNORED-HEADERS is non-nil,
1826 delete all header fields whose names match that regexp.
1827 Otherwise, if `rmail-displayed-headers' is non-nil,
1828 delete all header fields *except* those whose names match that regexp.
1829 Otherwise, delete all header fields whose names match `rmail-ignored-headers'."
1830 (when (search-forward "\n\n" nil t)
1831 (forward-char -1)
1832 (let ((case-fold-search t)
1833 (buffer-read-only nil))
1834 (if (and rmail-displayed-headers (null ignored-headers))
1835 (save-restriction
1836 (narrow-to-region (point-min) (point))
1837 (let (lim next)
1838 (goto-char (point-min))
1839 (while (and (not (eobp))
1840 (save-excursion
1841 (if (re-search-forward "\n[^ \t]" nil t)
1842 (setq lim (match-beginning 0)
1843 next (1+ lim))
1844 (setq lim nil next (point-max)))))
1845 (if (save-excursion
1846 (re-search-forward rmail-displayed-headers lim t))
1847 (goto-char next)
1848 (delete-region (point) next))))
1849 (goto-char (point-min)))
1850 (or ignored-headers (setq ignored-headers rmail-ignored-headers))
1851 (save-restriction
1852 (narrow-to-region (point-min) (point))
1853 (while (and ignored-headers
1854 (progn
1855 (goto-char (point-min))
1856 (re-search-forward ignored-headers nil t)))
1857 (beginning-of-line)
1858 (delete-region (point)
1859 (if (re-search-forward "\n[^ \t]" nil t)
1860 (1- (point))
1861 (point-max)))))))))
1863 (defun rmail-msg-is-pruned ()
1864 (rmail-maybe-set-message-counters)
1865 (save-restriction
1866 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1867 (save-excursion
1868 (goto-char (point-min))
1869 (forward-line 1)
1870 (= (following-char) ?1))))
1872 (defun rmail-toggle-header (&optional arg)
1873 "Show original message header if pruned header currently shown, or vice versa.
1874 With argument ARG, show the message header pruned if ARG is greater than zero;
1875 otherwise, show it in full."
1876 (interactive "P")
1877 (let* ((buffer-read-only nil)
1878 (pruned (rmail-msg-is-pruned))
1879 (prune (if arg
1880 (> (prefix-numeric-value arg) 0)
1881 (not pruned))))
1882 (if (eq pruned prune)
1884 (rmail-maybe-set-message-counters)
1885 (let ((at-point-min (= (point) (point-min)))
1886 (all-headers-visible (= (window-start) (point-min)))
1887 (on-header (save-excursion
1888 (and (not (search-backward "\n\n" nil t))
1889 (progn
1890 (end-of-line)
1891 (re-search-backward "^[-A-Za-z0-9]+:" nil t))
1892 (match-string 0))))
1893 (old-screen-line (rmail-count-screen-lines (window-start) (point))))
1894 (save-excursion
1895 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1896 (if pruned
1897 (let (new-start)
1898 (goto-char (point-min))
1899 (forward-line 1)
1900 ;; Change 1 to 0.
1901 (delete-char 1)
1902 (insert ?0)
1903 ;; Insert new EOOH line at the proper place.
1904 (forward-line 1)
1905 (let ((case-fold-search t))
1906 (while (looking-at "Summary-Line:\\|Mail-From:")
1907 (forward-line 1)))
1908 (insert "*** EOOH ***\n")
1909 (setq new-start (point))
1910 ;; Delete the old reformatted header.
1911 (forward-char -1)
1912 (search-forward "\n*** EOOH ***\n")
1913 (forward-line -1)
1914 (let ((start (point)))
1915 (search-forward "\n\n")
1916 (delete-region start (point)))
1917 ;; Narrow to after the new EOOH line.
1918 (narrow-to-region new-start (point-max)))
1919 (rmail-reformat-message (point-min) (point-max))))
1920 (cond (at-point-min
1921 (goto-char (point-min)))
1922 (on-header
1923 (goto-char (point-min))
1924 (search-forward "\n\n")
1925 (or (re-search-backward (concat "^" (regexp-quote on-header)) nil t)
1926 (goto-char (point-min))))
1928 (recenter old-screen-line)
1929 (if (and all-headers-visible
1930 (not (= (window-start) (point-min))))
1931 (let ((lines-offscreen (rmail-count-screen-lines
1932 (point-min) (window-start))))
1933 (recenter (min (+ old-screen-line lines-offscreen)
1934 ;; last line of window
1935 (- (window-height) 2))))))))
1936 (rmail-highlight-headers))))
1938 ;; Lifted from repos-count-screen-lines.
1939 ;; Return number of screen lines between START and END.
1940 (defun rmail-count-screen-lines (start end)
1941 (save-excursion
1942 (save-restriction
1943 (narrow-to-region start end)
1944 (goto-char (point-min))
1945 (vertical-motion (- (point-max) (point-min))))))
1947 ;;;; *** Rmail Attributes and Keywords ***
1949 ;; Make a string describing current message's attributes and keywords
1950 ;; and set it up as the name of a minor mode
1951 ;; so it will appear in the mode line.
1952 (defun rmail-display-labels ()
1953 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1954 (save-excursion
1955 (unwind-protect
1956 (progn
1957 (widen)
1958 (goto-char (rmail-msgbeg rmail-current-message))
1959 (forward-line 1)
1960 (if (looking-at "[01],")
1961 (progn
1962 (narrow-to-region (point) (progn (end-of-line) (point)))
1963 ;; Truly valid BABYL format requires a space before each
1964 ;; attribute or keyword name. Put them in if missing.
1965 (let (buffer-read-only)
1966 (goto-char (point-min))
1967 (while (search-forward "," nil t)
1968 (or (looking-at "[ ,]") (eobp)
1969 (insert " "))))
1970 (goto-char (point-max))
1971 (if (search-backward ",," nil 'move)
1972 (progn
1973 (if (> (point) (1+ (point-min)))
1974 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
1975 (if (> (- (point-max) (point)) 2)
1976 (setq blurb
1977 (concat blurb
1979 (buffer-substring (+ (point) 3)
1980 (1- (point-max)))))))))))
1981 ;; Note: we don't use save-restriction because that does not work right
1982 ;; if changes are made outside the saved restriction
1983 ;; before that restriction is restored.
1984 (narrow-to-region beg end)
1985 (set-marker beg nil)
1986 (set-marker end nil)))
1987 (while (string-match " +," blurb)
1988 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1989 (substring blurb (match-end 0)))))
1990 (while (string-match ", +" blurb)
1991 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1992 (substring blurb (match-end 0)))))
1993 (setq mode-line-process
1994 (format " %d/%d%s"
1995 rmail-current-message rmail-total-messages blurb))))
1997 ;; Turn an attribute of a message on or off according to STATE.
1998 ;; ATTR is the name of the attribute, as a string.
1999 ;; MSGNUM is message number to change; nil means current message.
2000 (defun rmail-set-attribute (attr state &optional msgnum)
2001 (let ((omax (point-max-marker))
2002 (omin (point-min-marker))
2003 (buffer-read-only nil))
2004 (or msgnum (setq msgnum rmail-current-message))
2005 (if (> msgnum 0)
2006 (unwind-protect
2007 (save-excursion
2008 (widen)
2009 (goto-char (+ 3 (rmail-msgbeg msgnum)))
2010 (let ((curstate
2011 (not
2012 (null (search-backward (concat ", " attr ",")
2013 (prog1 (point) (end-of-line)) t)))))
2014 (or (eq curstate (not (not state)))
2015 (if curstate
2016 (delete-region (point) (1- (match-end 0)))
2017 (beginning-of-line)
2018 (forward-char 2)
2019 (insert " " attr ","))))
2020 (if (string= attr "deleted")
2021 (rmail-set-message-deleted-p msgnum state)))
2022 ;; Note: we don't use save-restriction because that does not work right
2023 ;; if changes are made outside the saved restriction
2024 ;; before that restriction is restored.
2025 (narrow-to-region omin omax)
2026 (set-marker omin nil)
2027 (set-marker omax nil)
2028 (if (= msgnum rmail-current-message)
2029 (rmail-display-labels))))))
2031 ;; Return t if the attributes/keywords line of msg number MSG
2032 ;; contains a match for the regexp LABELS.
2033 (defun rmail-message-labels-p (msg labels)
2034 (save-excursion
2035 (save-restriction
2036 (widen)
2037 (goto-char (rmail-msgbeg msg))
2038 (forward-char 3)
2039 (re-search-backward labels (prog1 (point) (end-of-line)) t))))
2041 ;;;; *** Rmail Message Selection And Support ***
2043 (defun rmail-msgend (n)
2044 (marker-position (aref rmail-message-vector (1+ n))))
2046 (defun rmail-msgbeg (n)
2047 (marker-position (aref rmail-message-vector n)))
2049 (defun rmail-widen-to-current-msgbeg (function)
2050 "Call FUNCTION with point at start of internal data of current message.
2051 Assumes that bounds were previously narrowed to display the message in Rmail.
2052 The bounds are widened enough to move point where desired, then narrowed
2053 again afterward.
2055 FUNCTION may not change the visible text of the message, but it may
2056 change the invisible header text."
2057 (save-excursion
2058 (unwind-protect
2059 (progn
2060 (narrow-to-region (rmail-msgbeg rmail-current-message)
2061 (point-max))
2062 (goto-char (point-min))
2063 (funcall function))
2064 ;; Note: we don't use save-restriction because that does not work right
2065 ;; if changes are made outside the saved restriction
2066 ;; before that restriction is restored.
2067 (narrow-to-region (rmail-msgbeg rmail-current-message)
2068 (rmail-msgend rmail-current-message)))))
2070 (defun rmail-forget-messages ()
2071 (unwind-protect
2072 (if (vectorp rmail-message-vector)
2073 (let* ((i 0)
2074 (v rmail-message-vector)
2075 (n (length v)))
2076 (while (< i n)
2077 (move-marker (aref v i) nil)
2078 (setq i (1+ i)))))
2079 (setq rmail-message-vector nil)
2080 (setq rmail-msgref-vector nil)
2081 (setq rmail-deleted-vector nil)))
2083 (defun rmail-maybe-set-message-counters ()
2084 (if (not (and rmail-deleted-vector
2085 rmail-message-vector
2086 rmail-current-message
2087 rmail-total-messages))
2088 (rmail-set-message-counters)))
2090 (defun rmail-count-new-messages (&optional nomsg)
2091 (let* ((case-fold-search nil)
2092 (total-messages 0)
2093 (messages-head nil)
2094 (deleted-head nil))
2095 (or nomsg (message "Counting new messages..."))
2096 (goto-char (point-max))
2097 ;; Put at the end of messages-head
2098 ;; the entry for message N+1, which marks
2099 ;; the end of message N. (N = number of messages).
2100 (search-backward "\n\^_")
2101 (forward-char 1)
2102 (setq messages-head (list (point-marker)))
2103 (rmail-set-message-counters-counter (point-min))
2104 (setq rmail-current-message (1+ rmail-total-messages))
2105 (setq rmail-total-messages
2106 (+ rmail-total-messages total-messages))
2107 (setq rmail-message-vector
2108 (vconcat rmail-message-vector (cdr messages-head)))
2109 (aset rmail-message-vector
2110 rmail-current-message (car messages-head))
2111 (setq rmail-deleted-vector
2112 (concat rmail-deleted-vector deleted-head))
2113 (setq rmail-summary-vector
2114 (vconcat rmail-summary-vector (make-vector total-messages nil)))
2115 (setq rmail-msgref-vector
2116 (vconcat rmail-msgref-vector (make-vector total-messages nil)))
2117 ;; Fill in the new elements of rmail-msgref-vector.
2118 (let ((i (1+ (- rmail-total-messages total-messages))))
2119 (while (<= i rmail-total-messages)
2120 (aset rmail-msgref-vector i (list i))
2121 (setq i (1+ i))))
2122 (goto-char (point-min))
2123 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
2125 (defun rmail-set-message-counters ()
2126 (rmail-forget-messages)
2127 (save-excursion
2128 (save-restriction
2129 (widen)
2130 (let* ((point-save (point))
2131 (total-messages 0)
2132 (messages-after-point)
2133 (case-fold-search nil)
2134 (messages-head nil)
2135 (deleted-head nil))
2136 (message "Counting messages...")
2137 (goto-char (point-max))
2138 ;; Put at the end of messages-head
2139 ;; the entry for message N+1, which marks
2140 ;; the end of message N. (N = number of messages).
2141 (search-backward "\n\^_" nil t)
2142 (if (/= (point) (point-max)) (forward-char 1))
2143 (setq messages-head (list (point-marker)))
2144 (rmail-set-message-counters-counter (min (point) point-save))
2145 (setq messages-after-point total-messages)
2146 (rmail-set-message-counters-counter)
2147 (setq rmail-total-messages total-messages)
2148 (setq rmail-current-message
2149 (min total-messages
2150 (max 1 (- total-messages messages-after-point))))
2151 (setq rmail-message-vector
2152 (apply 'vector (cons (point-min-marker) messages-head))
2153 rmail-deleted-vector (concat "0" deleted-head)
2154 rmail-summary-vector (make-vector rmail-total-messages nil)
2155 rmail-msgref-vector (make-vector (1+ rmail-total-messages) nil))
2156 (let ((i 0))
2157 (while (<= i rmail-total-messages)
2158 (aset rmail-msgref-vector i (list i))
2159 (setq i (1+ i))))
2160 (message "Counting messages...done")))))
2162 (defun rmail-set-message-counters-counter (&optional stop)
2163 (let ((start (point))
2164 next)
2165 (while (search-backward "\n\^_\^L" stop t)
2166 ;; Detect messages that have been added with DOS line endings and
2167 ;; convert the line endings for such messages.
2168 (setq next (point))
2169 (if (looking-at "\n\^_\^L\r\n")
2170 (let ((buffer-read-only nil)
2171 (buffer-undo t))
2172 (message "Counting messages...(converting line endings)")
2173 (save-excursion
2174 (goto-char start)
2175 (while (search-backward "\r\n" next t)
2176 (delete-char 1)))))
2177 (setq start next)
2178 (forward-char 1)
2179 (setq messages-head (cons (point-marker) messages-head))
2180 (save-excursion
2181 (setq deleted-head
2182 (cons (if (search-backward ", deleted,"
2183 (prog1 (point)
2184 (forward-line 2))
2186 ?D ?\ )
2187 deleted-head)))
2188 (if (zerop (% (setq total-messages (1+ total-messages)) 20))
2189 (message "Counting messages...%d" total-messages)))))
2191 (defun rmail-beginning-of-message ()
2192 "Show current message starting from the beginning."
2193 (interactive)
2194 (rmail-show-message rmail-current-message))
2196 (defun rmail-show-message (&optional n no-summary)
2197 "Show message number N (prefix argument), counting from start of file.
2198 If summary buffer is currently displayed, update current message there also."
2199 (interactive "p")
2200 (or (eq major-mode 'rmail-mode)
2201 (switch-to-buffer rmail-buffer))
2202 (rmail-maybe-set-message-counters)
2203 (widen)
2204 (if (zerop rmail-total-messages)
2205 (progn (narrow-to-region (point-min) (1- (point-max)))
2206 (goto-char (point-min))
2207 (setq mode-line-process nil))
2208 (let (blurb coding-system)
2209 (if (not n)
2210 (setq n rmail-current-message)
2211 (cond ((<= n 0)
2212 (setq n 1
2213 rmail-current-message 1
2214 blurb "No previous message"))
2215 ((> n rmail-total-messages)
2216 (setq n rmail-total-messages
2217 rmail-current-message rmail-total-messages
2218 blurb "No following message"))
2220 (setq rmail-current-message n))))
2221 (let ((beg (rmail-msgbeg n)))
2222 (goto-char beg)
2223 (forward-line 1)
2224 (save-excursion
2225 (let ((end (rmail-msgend n)))
2226 (save-restriction
2227 (if (prog1 (= (following-char) ?0)
2228 (forward-line 2)
2229 ;; If there's a Summary-line in the (otherwise empty)
2230 ;; header, we didn't yet get past the EOOH line.
2231 (if (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
2232 (forward-line 1))
2233 (narrow-to-region (point) end))
2234 (rfc822-goto-eoh)
2235 (search-forward "\n*** EOOH ***\n" end t))
2236 (narrow-to-region beg (point))
2237 (goto-char (point-min))
2238 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t)
2239 (let ((coding-system (intern (match-string 1))))
2240 (check-coding-system coding-system)
2241 (setq buffer-file-coding-system coding-system))
2242 (setq buffer-file-coding-system nil)))))
2243 ;; Clear the "unseen" attribute when we show a message.
2244 (rmail-set-attribute "unseen" nil)
2245 (let ((end (rmail-msgend n)))
2246 ;; Reformat the header, or else find the reformatted header.
2247 (if (= (following-char) ?0)
2248 (rmail-reformat-message beg end)
2249 (search-forward "\n*** EOOH ***\n" end t)
2250 (narrow-to-region (point) end)))
2251 (goto-char (point-min))
2252 (rmail-display-labels)
2253 (if (eq rmail-enable-mime t)
2254 (funcall rmail-show-mime-function)
2255 (setq rmail-view-buffer rmail-buffer)
2257 (rmail-highlight-headers)
2258 (if transient-mark-mode (deactivate-mark))
2259 (run-hooks 'rmail-show-message-hook)
2260 ;; If there is a summary buffer, try to move to this message
2261 ;; in that buffer. But don't complain if this message
2262 ;; is not mentioned in the summary.
2263 ;; Don't do this at all if we were called on behalf
2264 ;; of cursor motion in the summary buffer.
2265 (and (rmail-summary-exists) (not no-summary)
2266 (let ((curr-msg rmail-current-message))
2267 (rmail-select-summary
2268 (rmail-summary-goto-msg curr-msg t t))))
2269 (rmail-auto-file)
2270 (if blurb
2271 (message blurb))))))
2273 (defun rmail-redecode-body (coding)
2274 "Decode the body of the current message using coding system CODING.
2275 This is useful with mail messages that have malformed or missing
2276 charset= headers.
2278 This function assumes that the current message is already decoded
2279 and displayed in the RMAIL buffer, but the coding system used to
2280 decode it was incorrect. It then encodes the message back to its
2281 original form, and decodes it again, using the coding system CODING.
2283 Note that if Emacs erroneously auto-detected one of the iso-2022
2284 encodings in the message, this function might fail because the escape
2285 sequences that switch between character sets and also single-shift and
2286 locking-shift codes are impossible to recover. This function is meant
2287 to be used to fix messages encoded with 8-bit encodings, such as
2288 iso-8859, koi8-r, etc."
2289 (interactive "zCoding system for re-decoding this message: ")
2290 (when (not rmail-enable-mime)
2291 (or (eq major-mode 'rmail-mode)
2292 (switch-to-buffer rmail-buffer))
2293 (save-excursion
2294 (unwind-protect
2295 (let ((msgbeg (rmail-msgbeg rmail-current-message))
2296 (msgend (rmail-msgend rmail-current-message))
2297 x-coding-header)
2298 (narrow-to-region msgbeg msgend)
2299 (goto-char (point-min))
2300 (when (search-forward "\n*** EOOH ***\n" (point-max) t)
2301 (narrow-to-region msgbeg (point)))
2302 (goto-char (point-min))
2303 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t)
2304 (let ((old-coding (intern (match-string 1)))
2305 (buffer-read-only nil))
2306 (check-coding-system old-coding)
2307 ;; Make sure the new coding system uses the same EOL
2308 ;; conversion, to prevent ^M characters from popping
2309 ;; up all over the place.
2310 (setq coding
2311 (coding-system-change-eol-conversion
2312 coding
2313 (coding-system-eol-type old-coding)))
2314 (setq x-coding-header (point-marker))
2315 (narrow-to-region msgbeg msgend)
2316 (encode-coding-region (point) msgend old-coding)
2317 (decode-coding-region (point) msgend coding)
2318 (setq last-coding-system-used coding)
2319 ;; Rewrite the coding-system header according
2320 ;; to what we did.
2321 (goto-char x-coding-header)
2322 (delete-region (point)
2323 (save-excursion
2324 (beginning-of-line)
2325 (point)))
2326 (insert "X-Coding-System: "
2327 (symbol-name last-coding-system-used))
2328 (set-marker x-coding-header nil)
2329 (rmail-show-message))
2330 (error "No X-Coding-System header found")))))))
2332 ;; Find all occurrences of certain fields, and highlight them.
2333 (defun rmail-highlight-headers ()
2334 ;; Do this only if the system supports faces.
2335 (if (and (fboundp 'internal-find-face)
2336 rmail-highlighted-headers)
2337 (save-excursion
2338 (search-forward "\n\n" nil 'move)
2339 (save-restriction
2340 (narrow-to-region (point-min) (point))
2341 (let ((case-fold-search t)
2342 (inhibit-read-only t)
2343 ;; Highlight with boldface if that is available.
2344 ;; Otherwise use the `highlight' face.
2345 (face (or rmail-highlight-face
2346 (if (face-differs-from-default-p 'bold)
2347 'bold 'highlight)))
2348 ;; List of overlays to reuse.
2349 (overlays rmail-overlay-list))
2350 (goto-char (point-min))
2351 (while (re-search-forward rmail-highlighted-headers nil t)
2352 (skip-chars-forward " \t")
2353 (let ((beg (point))
2354 overlay)
2355 (while (progn (forward-line 1)
2356 (looking-at "[ \t]")))
2357 ;; Back up over newline, then trailing spaces or tabs
2358 (forward-char -1)
2359 (while (member (preceding-char) '(? ?\t))
2360 (forward-char -1))
2361 (if overlays
2362 ;; Reuse an overlay we already have.
2363 (progn
2364 (setq overlay (car overlays)
2365 overlays (cdr overlays))
2366 (overlay-put overlay 'face face)
2367 (move-overlay overlay beg (point)))
2368 ;; Make a new overlay and add it to
2369 ;; rmail-overlay-list.
2370 (setq overlay (make-overlay beg (point)))
2371 (overlay-put overlay 'face face)
2372 (setq rmail-overlay-list
2373 (cons overlay rmail-overlay-list))))))))))
2375 (defun rmail-auto-file ()
2376 "Automatically move a message into a sub-folder based on criteria.
2377 Called when a new message is displayed."
2378 (if (or (rmail-message-labels-p rmail-current-message "filed")
2379 (not (string= (buffer-file-name)
2380 (expand-file-name rmail-file-name))))
2381 ;; Do nothing if it's already been filed.
2383 ;; Find out some basics (common fields)
2384 (let ((from (mail-fetch-field "from"))
2385 (subj (mail-fetch-field "subject"))
2386 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
2387 (d rmail-automatic-folder-directives)
2388 (directive-loop nil)
2389 (folder nil))
2390 (while d
2391 (setq folder (car (car d))
2392 directive-loop (cdr (car d)))
2393 (while (and (car directive-loop)
2394 (let ((f (cond
2395 ((string= (car directive-loop) "from") from)
2396 ((string= (car directive-loop) "to") to)
2397 ((string= (car directive-loop) "subject") subj)
2398 (t (mail-fetch-field (car directive-loop))))))
2399 (and f (string-match (car (cdr directive-loop)) f))))
2400 (setq directive-loop (cdr (cdr directive-loop))))
2401 ;; If there are no directives left, then it was a complete match.
2402 (if (null directive-loop)
2403 (if (null folder)
2404 (rmail-delete-forward)
2405 (if (string= "/dev/null" folder)
2406 (rmail-delete-message)
2407 (rmail-output-to-rmail-file folder 1 t)
2408 (setq d nil))))
2409 (setq d (cdr d))))))
2411 (defun rmail-next-message (n)
2412 "Show following message whether deleted or not.
2413 With prefix arg N, moves forward N messages, or backward if N is negative."
2414 (interactive "p")
2415 (rmail-maybe-set-message-counters)
2416 (rmail-show-message (+ rmail-current-message n)))
2418 (defun rmail-previous-message (n)
2419 "Show previous message whether deleted or not.
2420 With prefix arg N, moves backward N messages, or forward if N is negative."
2421 (interactive "p")
2422 (rmail-next-message (- n)))
2424 (defun rmail-next-undeleted-message (n)
2425 "Show following non-deleted message.
2426 With prefix arg N, moves forward N non-deleted messages,
2427 or backward if N is negative.
2429 Returns t if a new message is being shown, nil otherwise."
2430 (interactive "p")
2431 (rmail-maybe-set-message-counters)
2432 (let ((lastwin rmail-current-message)
2433 (current rmail-current-message))
2434 (while (and (> n 0) (< current rmail-total-messages))
2435 (setq current (1+ current))
2436 (if (not (rmail-message-deleted-p current))
2437 (setq lastwin current n (1- n))))
2438 (while (and (< n 0) (> current 1))
2439 (setq current (1- current))
2440 (if (not (rmail-message-deleted-p current))
2441 (setq lastwin current n (1+ n))))
2442 (if (/= lastwin rmail-current-message)
2443 (progn (rmail-show-message lastwin)
2445 (if (< n 0)
2446 (message "No previous nondeleted message"))
2447 (if (> n 0)
2448 (message "No following nondeleted message"))
2449 nil)))
2451 (defun rmail-previous-undeleted-message (n)
2452 "Show previous non-deleted message.
2453 With prefix argument N, moves backward N non-deleted messages,
2454 or forward if N is negative."
2455 (interactive "p")
2456 (rmail-next-undeleted-message (- n)))
2458 (defun rmail-first-message ()
2459 "Show first message in file."
2460 (interactive)
2461 (rmail-maybe-set-message-counters)
2462 (rmail-show-message 1))
2464 (defun rmail-last-message ()
2465 "Show last message in file."
2466 (interactive)
2467 (rmail-maybe-set-message-counters)
2468 (rmail-show-message rmail-total-messages))
2470 (defun rmail-what-message ()
2471 (let ((where (point))
2472 (low 1)
2473 (high rmail-total-messages)
2474 (mid (/ rmail-total-messages 2)))
2475 (while (> (- high low) 1)
2476 (if (>= where (rmail-msgbeg mid))
2477 (setq low mid)
2478 (setq high mid))
2479 (setq mid (+ low (/ (- high low) 2))))
2480 (if (>= where (rmail-msgbeg high)) high low)))
2482 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
2483 (save-restriction
2484 (goto-char (rmail-msgbeg msg))
2485 (search-forward "\n*** EOOH ***\n")
2486 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
2487 (or (string-match recipients (or (mail-fetch-field "To") ""))
2488 (string-match recipients (or (mail-fetch-field "From") ""))
2489 (if (not primary-only)
2490 (string-match recipients (or (mail-fetch-field "Cc") ""))))))
2492 (defun rmail-message-regexp-p (msg regexp)
2493 "Return t, if for message number MSG, regexp REGEXP matches in the header."
2494 (save-excursion
2495 (goto-char (rmail-msgbeg msg))
2496 (let (beg end)
2497 (save-excursion
2498 (forward-line 2)
2499 (setq beg (point)))
2500 (save-excursion
2501 (search-forward "\n*** EOOH ***\n" (point-max))
2502 (when (= beg (match-beginning 0))
2503 (setq beg (point))
2504 (search-forward "\n\n" (point-max)))
2505 (setq end (point)))
2506 (goto-char beg)
2507 (re-search-forward regexp end t))))
2509 (defvar rmail-search-last-regexp nil)
2510 (defun rmail-search (regexp &optional n)
2511 "Show message containing next match for REGEXP (but not the current msg).
2512 Prefix argument gives repeat count; negative argument means search
2513 backwards (through earlier messages).
2514 Interactively, empty argument means use same regexp used last time."
2515 (interactive
2516 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
2517 (prompt
2518 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
2519 regexp)
2520 (if rmail-search-last-regexp
2521 (setq prompt (concat prompt
2522 "(default "
2523 rmail-search-last-regexp
2524 ") ")))
2525 (setq regexp (read-string prompt))
2526 (cond ((not (equal regexp ""))
2527 (setq rmail-search-last-regexp regexp))
2528 ((not rmail-search-last-regexp)
2529 (error "No previous Rmail search string")))
2530 (list rmail-search-last-regexp
2531 (prefix-numeric-value current-prefix-arg))))
2532 (or n (setq n 1))
2533 (message "%sRmail search for %s..."
2534 (if (< n 0) "Reverse " "")
2535 regexp)
2536 (rmail-maybe-set-message-counters)
2537 (let ((omin (point-min))
2538 (omax (point-max))
2539 (opoint (point))
2541 (reversep (< n 0))
2542 (msg rmail-current-message))
2543 (unwind-protect
2544 (progn
2545 (widen)
2546 (while (/= n 0)
2547 ;; Check messages one by one, advancing message number up or down
2548 ;; but searching forward through each message.
2549 (if reversep
2550 (while (and (null win) (> msg 1))
2551 (goto-char (rmail-msgbeg (setq msg (1- msg))))
2552 (setq win (re-search-forward
2553 regexp (rmail-msgend msg) t)))
2554 (while (and (null win) (< msg rmail-total-messages))
2555 (goto-char (rmail-msgbeg (setq msg (1+ msg))))
2556 (setq win (re-search-forward regexp (rmail-msgend msg) t))))
2557 (setq n (+ n (if reversep 1 -1)))))
2558 (if win
2559 (progn
2560 ;; If this is a reverse search and we found a message,
2561 ;; search backward thru this message to position point.
2562 (if reversep
2563 (progn
2564 (goto-char (rmail-msgend msg))
2565 (re-search-backward
2566 regexp (rmail-msgbeg msg) t)))
2567 (setq win (point-marker))
2568 (rmail-show-message msg)
2569 (message "%sRmail search for %s...done"
2570 (if reversep "Reverse " "")
2571 regexp)
2572 (goto-char win))
2573 (goto-char opoint)
2574 (narrow-to-region omin omax)
2575 (ding)
2576 (message "Search failed: %s" regexp)))))
2578 (defun rmail-search-backwards (regexp &optional n)
2579 "Show message containing previous match for REGEXP.
2580 Prefix argument gives repeat count; negative argument means search
2581 forward (through later messages).
2582 Interactively, empty argument means use same regexp used last time."
2583 (interactive
2584 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
2585 (prompt
2586 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
2587 regexp)
2588 (if rmail-search-last-regexp
2589 (setq prompt (concat prompt
2590 "(default "
2591 rmail-search-last-regexp
2592 ") ")))
2593 (setq regexp (read-string prompt))
2594 (cond ((not (equal regexp ""))
2595 (setq rmail-search-last-regexp regexp))
2596 ((not rmail-search-last-regexp)
2597 (error "No previous Rmail search string")))
2598 (list rmail-search-last-regexp
2599 (prefix-numeric-value current-prefix-arg))))
2600 (rmail-search regexp (- (or n 1))))
2602 ;; Show the first message which has the `unseen' attribute.
2603 (defun rmail-first-unseen-message ()
2604 (rmail-maybe-set-message-counters)
2605 (let ((current 1)
2606 found)
2607 (save-restriction
2608 (widen)
2609 (while (and (not found) (<= current rmail-total-messages))
2610 (if (rmail-message-labels-p current ", ?\\(unseen\\),")
2611 (setq found current))
2612 (setq current (1+ current))))
2613 ;; Let the caller show the message.
2614 ;; (if found
2615 ;; (rmail-show-message found))
2616 found))
2618 (defun rmail-next-same-subject (n)
2619 "Go to the next mail message having the same subject header.
2620 With prefix argument N, do this N times.
2621 If N is negative, go backwards instead."
2622 (interactive "p")
2623 (let ((subject (mail-fetch-field "Subject"))
2624 (forward (> n 0))
2625 (i rmail-current-message)
2626 (case-fold-search t)
2627 search-regexp found)
2628 (if (string-match "\\`[ \t]+" subject)
2629 (setq subject (substring subject (match-end 0))))
2630 (if (string-match "Re:[ \t]*" subject)
2631 (setq subject (substring subject (match-end 0))))
2632 (if (string-match "[ \t]+\\'" subject)
2633 (setq subject (substring subject 0 (match-beginning 0))))
2634 (setq search-regexp (concat "^Subject: *\\(Re:[ \t]*\\)?"
2635 (regexp-quote subject)
2636 "[ \t]*\n"))
2637 (save-excursion
2638 (save-restriction
2639 (widen)
2640 (while (and (/= n 0)
2641 (if forward
2642 (< i rmail-total-messages)
2643 (> i 1)))
2644 (let (done)
2645 (while (and (not done)
2646 (if forward
2647 (< i rmail-total-messages)
2648 (> i 1)))
2649 (setq i (if forward (1+ i) (1- i)))
2650 (goto-char (rmail-msgbeg i))
2651 (search-forward "\n*** EOOH ***\n")
2652 (let ((beg (point)) end)
2653 (search-forward "\n\n")
2654 (setq end (point))
2655 (goto-char beg)
2656 (setq done (re-search-forward search-regexp end t))))
2657 (if done (setq found i)))
2658 (setq n (if forward (1- n) (1+ n))))))
2659 (if found
2660 (rmail-show-message found)
2661 (error "No %s message with same subject"
2662 (if forward "following" "previous")))))
2664 (defun rmail-previous-same-subject (n)
2665 "Go to the previous mail message having the same subject header.
2666 With prefix argument N, do this N times.
2667 If N is negative, go forwards instead."
2668 (interactive "p")
2669 (rmail-next-same-subject (- n)))
2671 ;;;; *** Rmail Message Deletion Commands ***
2673 (defun rmail-message-deleted-p (n)
2674 (= (aref rmail-deleted-vector n) ?D))
2676 (defun rmail-set-message-deleted-p (n state)
2677 (aset rmail-deleted-vector n (if state ?D ?\ )))
2679 (defun rmail-delete-message ()
2680 "Delete this message and stay on it."
2681 (interactive)
2682 (rmail-set-attribute "deleted" t)
2683 (run-hooks 'rmail-delete-message-hook))
2685 (defun rmail-undelete-previous-message ()
2686 "Back up to deleted message, select it, and undelete it."
2687 (interactive)
2688 (let ((msg rmail-current-message))
2689 (while (and (> msg 0)
2690 (not (rmail-message-deleted-p msg)))
2691 (setq msg (1- msg)))
2692 (if (= msg 0)
2693 (error "No previous deleted message")
2694 (if (/= msg rmail-current-message)
2695 (rmail-show-message msg))
2696 (rmail-set-attribute "deleted" nil)
2697 (if (rmail-summary-exists)
2698 (save-excursion
2699 (set-buffer rmail-summary-buffer)
2700 (rmail-summary-mark-undeleted msg)))
2701 (rmail-maybe-display-summary))))
2703 (defun rmail-delete-forward (&optional backward)
2704 "Delete this message and move to next nondeleted one.
2705 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
2706 With prefix argument, delete and move backward.
2708 Returns t if a new message is displayed after the delete, or nil otherwise."
2709 (interactive "P")
2710 (rmail-set-attribute "deleted" t)
2711 (run-hooks 'rmail-delete-message-hook)
2712 (let ((del-msg rmail-current-message))
2713 (if (rmail-summary-exists)
2714 (rmail-select-summary
2715 (rmail-summary-mark-deleted del-msg)))
2716 (prog1 (rmail-next-undeleted-message (if backward -1 1))
2717 (rmail-maybe-display-summary))))
2719 (defun rmail-delete-backward ()
2720 "Delete this message and move to previous nondeleted one.
2721 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
2722 (interactive)
2723 (rmail-delete-forward t))
2725 ;; Compute the message number a given message would have after expunging.
2726 ;; The present number of the message is OLDNUM.
2727 ;; DELETEDVEC should be rmail-deleted-vector.
2728 ;; The value is nil for a message that would be deleted.
2729 (defun rmail-msg-number-after-expunge (deletedvec oldnum)
2730 (if (or (null oldnum) (= (aref deletedvec oldnum) ?D))
2732 (let ((i 0)
2733 (newnum 0))
2734 (while (< i oldnum)
2735 (if (/= (aref deletedvec i) ?D)
2736 (setq newnum (1+ newnum)))
2737 (setq i (1+ i)))
2738 newnum)))
2740 (defun rmail-expunge-confirmed ()
2741 "Return t if deleted message should be expunged. If necessary, ask the user.
2742 See also user-option `rmail-confirm-expunge'."
2743 (or (not (stringp rmail-deleted-vector))
2744 (not (string-match "D" rmail-deleted-vector))
2745 (null rmail-confirm-expunge)
2746 (funcall rmail-confirm-expunge
2747 "Erase deleted messages from Rmail file? ")))
2749 (defun rmail-only-expunge ()
2750 "Actually erase all deleted messages in the file."
2751 (interactive)
2752 (message "Expunging deleted messages...")
2753 ;; Discard all undo records for this buffer.
2754 (or (eq buffer-undo-list t)
2755 (setq buffer-undo-list nil))
2756 (rmail-maybe-set-message-counters)
2757 (let* ((omax (- (buffer-size) (point-max)))
2758 (omin (- (buffer-size) (point-min)))
2759 (opoint (if (and (> rmail-current-message 0)
2760 (rmail-message-deleted-p rmail-current-message))
2762 (- (point) (point-min))))
2763 (messages-head (cons (aref rmail-message-vector 0) nil))
2764 (messages-tail messages-head)
2765 ;; Don't make any undo records for the expunging.
2766 (buffer-undo-list t)
2767 (win))
2768 (unwind-protect
2769 (save-excursion
2770 (widen)
2771 (goto-char (point-min))
2772 (let ((counter 0)
2773 (number 1)
2774 (total rmail-total-messages)
2775 (new-message-number rmail-current-message)
2776 (new-summary nil)
2777 (new-msgref (list (list 0)))
2778 (rmailbuf (current-buffer))
2779 (buffer-read-only nil)
2780 (messages rmail-message-vector)
2781 (deleted rmail-deleted-vector)
2782 (summary rmail-summary-vector))
2783 (setq rmail-total-messages nil
2784 rmail-current-message nil
2785 rmail-message-vector nil
2786 rmail-deleted-vector nil
2787 rmail-summary-vector nil)
2789 (while (<= number total)
2790 (if (= (aref deleted number) ?D)
2791 (progn
2792 (delete-region
2793 (marker-position (aref messages number))
2794 (marker-position (aref messages (1+ number))))
2795 (move-marker (aref messages number) nil)
2796 (if (> new-message-number counter)
2797 (setq new-message-number (1- new-message-number))))
2798 (setq counter (1+ counter))
2799 (setq messages-tail
2800 (setcdr messages-tail
2801 (cons (aref messages number) nil)))
2802 (setq new-summary
2803 (cons (if (= counter number) (aref summary (1- number)))
2804 new-summary))
2805 (setq new-msgref
2806 (cons (aref rmail-msgref-vector number)
2807 new-msgref))
2808 (setcar (car new-msgref) counter))
2809 (if (zerop (% (setq number (1+ number)) 20))
2810 (message "Expunging deleted messages...%d" number)))
2811 (setq messages-tail
2812 (setcdr messages-tail
2813 (cons (aref messages number) nil)))
2814 (setq rmail-current-message new-message-number
2815 rmail-total-messages counter
2816 rmail-message-vector (apply 'vector messages-head)
2817 rmail-deleted-vector (make-string (1+ counter) ?\ )
2818 rmail-summary-vector (vconcat (nreverse new-summary))
2819 rmail-msgref-vector (apply 'vector (nreverse new-msgref))
2820 win t)))
2821 (message "Expunging deleted messages...done")
2822 (if (not win)
2823 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
2824 (rmail-show-message
2825 (if (zerop rmail-current-message) 1 nil))
2826 (goto-char (+ (point) opoint)))))
2828 (defun rmail-expunge ()
2829 "Erase deleted messages from Rmail file and summary buffer."
2830 (interactive)
2831 (when (rmail-expunge-confirmed)
2832 (rmail-only-expunge)
2833 (if (rmail-summary-exists)
2834 (rmail-select-summary (rmail-update-summary)))))
2836 ;;;; *** Rmail Mailing Commands ***
2838 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
2839 replybuffer sendactions same-window others)
2840 (let (yank-action)
2841 (if replybuffer
2842 (setq yank-action (list 'insert-buffer replybuffer)))
2843 (setq others (cons (cons "cc" cc) others))
2844 (setq others (cons (cons "in-reply-to" in-reply-to) others))
2845 (if same-window
2846 (compose-mail to subject others
2847 noerase nil
2848 yank-action sendactions)
2849 (if (and (display-multi-frame-p) rmail-mail-new-frame)
2850 (prog1
2851 (compose-mail to subject others
2852 noerase 'switch-to-buffer-other-frame
2853 yank-action sendactions)
2854 ;; This is not a standard frame parameter;
2855 ;; nothing except sendmail.el looks at it.
2856 (modify-frame-parameters (selected-frame)
2857 '((mail-dedicated-frame . t))))
2858 (compose-mail to subject others
2859 noerase 'switch-to-buffer-other-window
2860 yank-action sendactions)))))
2862 (defun rmail-mail ()
2863 "Send mail in another window.
2864 While composing the message, use \\[mail-yank-original] to yank the
2865 original message into it."
2866 (interactive)
2867 (rmail-start-mail nil nil nil nil nil rmail-view-buffer))
2869 (defun rmail-continue ()
2870 "Continue composing outgoing message previously being composed."
2871 (interactive)
2872 (rmail-start-mail t))
2874 (defun rmail-reply (just-sender)
2875 "Reply to the current message.
2876 Normally include CC: to all other recipients of original message;
2877 prefix argument means ignore them. While composing the reply,
2878 use \\[mail-yank-original] to yank the original message into it."
2879 (interactive "P")
2880 (let (from reply-to cc subject date to message-id references
2881 resent-to resent-cc resent-reply-to
2882 (msgnum rmail-current-message))
2883 (save-excursion
2884 (save-restriction
2885 (widen)
2886 (goto-char (rmail-msgbeg rmail-current-message))
2887 (forward-line 1)
2888 (if (= (following-char) ?0)
2889 (narrow-to-region
2890 (progn (forward-line 2)
2891 (point))
2892 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
2893 'move)
2894 (point)))
2895 (narrow-to-region (point)
2896 (progn (search-forward "\n*** EOOH ***\n")
2897 (beginning-of-line) (point))))
2898 (setq from (mail-fetch-field "from")
2899 reply-to (or (mail-fetch-field "reply-to" nil t)
2900 from)
2901 cc (and (not just-sender)
2902 (mail-fetch-field "cc" nil t))
2903 subject (mail-fetch-field "subject")
2904 date (mail-fetch-field "date")
2905 to (or (mail-fetch-field "to" nil t) "")
2906 message-id (mail-fetch-field "message-id")
2907 references (mail-fetch-field "references" nil nil t)
2908 resent-reply-to (mail-fetch-field "resent-reply-to" nil t)
2909 resent-cc (and (not just-sender)
2910 (mail-fetch-field "resent-cc" nil t))
2911 resent-to (or (mail-fetch-field "resent-to" nil t) "")
2912 ;;; resent-subject (mail-fetch-field "resent-subject")
2913 ;;; resent-date (mail-fetch-field "resent-date")
2914 ;;; resent-message-id (mail-fetch-field "resent-message-id")
2916 ;; Merge the resent-to and resent-cc into the to and cc.
2917 (if (and resent-to (not (equal resent-to "")))
2918 (if (not (equal to ""))
2919 (setq to (concat to ", " resent-to))
2920 (setq to resent-to)))
2921 (if (and resent-cc (not (equal resent-cc "")))
2922 (if (not (equal cc ""))
2923 (setq cc (concat cc ", " resent-cc))
2924 (setq cc resent-cc)))
2925 ;; Add `Re: ' to subject if not there already.
2926 (and (stringp subject)
2927 (setq subject
2928 (concat rmail-reply-prefix
2929 (if (let ((case-fold-search t))
2930 (string-match rmail-reply-regexp subject))
2931 (substring subject (match-end 0))
2932 subject))))
2933 (rmail-start-mail
2935 ;; Using mail-strip-quoted-names is undesirable with newer mailers
2936 ;; since they can handle the names unstripped.
2937 ;; I don't know whether there are other mailers that still
2938 ;; need the names to be stripped.
2939 (mail-strip-quoted-names reply-to)
2940 subject
2941 (rmail-make-in-reply-to-field from date message-id)
2942 (if just-sender
2944 ;; mail-strip-quoted-names is NOT necessary for rmail-dont-reply-to
2945 ;; to do its job.
2946 (let* ((cc-list (rmail-dont-reply-to
2947 (mail-strip-quoted-names
2948 (if (null cc) to (concat to ", " cc))))))
2949 (if (string= cc-list "") nil cc-list)))
2950 rmail-view-buffer
2951 (list (list 'rmail-mark-message
2952 rmail-view-buffer
2953 (aref rmail-msgref-vector msgnum)
2954 "answered"))
2956 (list (cons "References" (concat (mapconcat 'identity references " ")
2957 " " message-id))))))
2959 (defun rmail-mark-message (buffer msgnum-list attribute)
2960 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
2961 This is use in the send-actions for message buffers.
2962 MSGNUM-LIST is a list of the form (MSGNUM)
2963 which is an element of rmail-msgref-vector."
2964 (save-excursion
2965 (set-buffer buffer)
2966 (if (car msgnum-list)
2967 (rmail-set-attribute attribute t (car msgnum-list)))))
2969 (defun rmail-make-in-reply-to-field (from date message-id)
2970 (cond ((not from)
2971 (if message-id
2972 message-id
2973 nil))
2974 (mail-use-rfc822
2975 (require 'rfc822)
2976 (let ((tem (car (rfc822-addresses from))))
2977 (if message-id
2978 (if (or (not tem)
2979 (string-match
2980 (regexp-quote (if (string-match "@[^@]*\\'" tem)
2981 (substring tem 0
2982 (match-beginning 0))
2983 tem))
2984 message-id))
2985 ;; missing From, or Message-ID is sufficiently informative
2986 message-id
2987 (concat message-id " (" tem ")"))
2988 ;; Copy TEM, discarding text properties.
2989 (setq tem (copy-sequence tem))
2990 (set-text-properties 0 (length tem) nil tem)
2991 (setq tem (copy-sequence tem))
2992 ;; Use prin1 to fake RFC822 quoting
2993 (let ((field (prin1-to-string tem)))
2994 (if date
2995 (concat field "'s message of " date)
2996 field)))))
2997 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
2998 (bar "[^][\000-\037()<>@,;:\\\"]+"))
2999 ;; These strings both match all non-ASCII characters.
3000 (or (string-match (concat "\\`[ \t]*\\(" bar
3001 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
3002 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3003 from)
3004 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
3005 bar "\\))[ \t]*\\'")
3006 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3007 from)))
3008 (let ((start (match-beginning 1))
3009 (end (match-end 1)))
3010 ;; Trim whitespace which above regexp match allows
3011 (while (and (< start end)
3012 (memq (aref from start) '(?\t ?\ )))
3013 (setq start (1+ start)))
3014 (while (and (< start end)
3015 (memq (aref from (1- end)) '(?\t ?\ )))
3016 (setq end (1- end)))
3017 (let ((field (substring from start end)))
3018 (if date (setq field (concat "message from " field " on " date)))
3019 (if message-id
3020 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3021 (concat message-id " (" field ")")
3022 field))))
3024 ;; If we can't kludge it simply, do it correctly
3025 (let ((mail-use-rfc822 t))
3026 (rmail-make-in-reply-to-field from date message-id)))))
3028 (defun rmail-forward (resend)
3029 "Forward the current message to another user.
3030 With prefix argument, \"resend\" the message instead of forwarding it;
3031 see the documentation of `rmail-resend'."
3032 (interactive "P")
3033 (if resend
3034 (call-interactively 'rmail-resend)
3035 (let ((forward-buffer (current-buffer))
3036 (msgnum rmail-current-message)
3037 (subject (concat "["
3038 (let ((from (or (mail-fetch-field "From")
3039 (mail-fetch-field ">From"))))
3040 (if from
3041 (concat (mail-strip-quoted-names from) ": ")
3042 ""))
3043 (or (mail-fetch-field "Subject") "")
3044 "]")))
3045 (if (rmail-start-mail
3046 nil nil subject nil nil nil
3047 (list (list 'rmail-mark-message
3048 forward-buffer
3049 (aref rmail-msgref-vector msgnum)
3050 "forwarded"))
3051 ;; If only one window, use it for the mail buffer.
3052 ;; Otherwise, use another window for the mail buffer
3053 ;; so that the Rmail buffer remains visible
3054 ;; and sending the mail will get back to it.
3055 (and (not rmail-mail-new-frame) (one-window-p t)))
3056 ;; The mail buffer is now current.
3057 (save-excursion
3058 ;; Insert after header separator--before signature if any.
3059 (goto-char (mail-text-start))
3060 (insert "------- Start of forwarded message -------\n")
3061 ;; Quote lines with `- ' if they start with `-'.
3062 (let ((beg (point)) end)
3063 (setq end (point-marker))
3064 (set-marker-insertion-type end t)
3065 (insert-buffer-substring forward-buffer)
3066 (goto-char beg)
3067 (while (re-search-forward "^-" end t)
3068 (beginning-of-line)
3069 (insert "- ")
3070 (forward-line 1))
3071 (goto-char end)
3072 (skip-chars-backward "\n")
3073 (if (< (point) end)
3074 (forward-char 1))
3075 (delete-region (point) end)
3076 (set-marker end nil))
3077 (insert "------- End of forwarded message -------\n")
3078 (push-mark))))))
3080 (defun rmail-resend (address &optional from comment mail-alias-file)
3081 "Resend current message to ADDRESSES.
3082 ADDRESSES should be a single address, a string consisting of several
3083 addresses separated by commas, or a list of addresses.
3085 Optional FROM is the address to resend the message from, and
3086 defaults from the value of `user-mail-address'.
3087 Optional COMMENT is a string to insert as a comment in the resent message.
3088 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3089 typically for purposes of moderating a list."
3090 (interactive "sResend to: ")
3091 (require 'sendmail)
3092 (require 'mailalias)
3093 (unless (eq rmail-buffer (current-buffer))
3094 (error "Not an Rmail buffer"))
3095 (if (not from) (setq from user-mail-address))
3096 (let ((tembuf (generate-new-buffer " sendmail temp"))
3097 (case-fold-search nil)
3098 (mailbuf rmail-buffer))
3099 (unwind-protect
3100 (with-current-buffer tembuf
3101 ;;>> Copy message into temp buffer
3102 (insert-buffer-substring mailbuf)
3103 (goto-char (point-min))
3104 ;; Delete any Sender field, since that's not specifiable.
3105 ; Only delete Sender fields in the actual header.
3106 (re-search-forward "^$" nil 'move)
3107 ; Using "while" here rather than "if" because some buggy mail
3108 ; software may have inserted multiple Sender fields.
3109 (while (re-search-backward "^Sender:" nil t)
3110 (let (beg)
3111 (setq beg (point))
3112 (forward-line 1)
3113 (while (looking-at "[ \t]")
3114 (forward-line 1))
3115 (delete-region beg (point))))
3116 ; Go back to the beginning of the buffer so the Resent- fields
3117 ; are inserted there.
3118 (goto-char (point-min))
3119 ;;>> Insert resent-from:
3120 (insert "Resent-From: " from "\n")
3121 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3122 ;;>> Insert resent-to: and bcc if need be.
3123 (let ((before (point)))
3124 (if mail-self-blind
3125 (insert "Resent-Bcc: " (user-login-name) "\n"))
3126 (insert "Resent-To: " (if (stringp address)
3127 address
3128 (mapconcat 'identity address ",\n\t"))
3129 "\n")
3130 ;; Expand abbrevs in the recipients.
3131 (save-excursion
3132 (if (featurep 'mailabbrev)
3133 (let ((end (point-marker))
3134 (local-abbrev-table mail-abbrevs)
3135 (old-syntax-table (syntax-table)))
3136 (if (and (not (vectorp mail-abbrevs))
3137 (file-exists-p mail-personal-alias-file))
3138 (build-mail-abbrevs))
3139 (set-syntax-table mail-abbrev-syntax-table)
3140 (goto-char before)
3141 (while (and (< (point) end)
3142 (progn (forward-word 1)
3143 (<= (point) end)))
3144 (expand-abbrev))
3145 (set-syntax-table old-syntax-table))
3146 (expand-mail-aliases before (point)))))
3147 ;;>> Set up comment, if any.
3148 (if (and (sequencep comment) (not (zerop (length comment))))
3149 (let ((before (point))
3150 after)
3151 (insert comment)
3152 (or (eolp) (insert "\n"))
3153 (setq after (point))
3154 (goto-char before)
3155 (while (< (point) after)
3156 (insert "Resent-Comment: ")
3157 (forward-line 1))))
3158 ;; Don't expand aliases in the destination fields
3159 ;; of the original message.
3160 (let (mail-aliases)
3161 (funcall send-mail-function)))
3162 (kill-buffer tembuf))
3163 (with-current-buffer rmail-buffer
3164 (rmail-set-attribute "resent" t rmail-current-message))))
3166 (defvar mail-unsent-separator
3167 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3168 "^ *---+ +Returned message +---+ *$\\|"
3169 "^ *---+ *Returned mail follows *---+ *$\\|"
3170 "^Start of returned message$\\|"
3171 "^---+ Below this line is a copy of the message.$\\|"
3172 "^ *---+ +Original message +---+ *$\\|"
3173 "^ *--+ +begin message +--+ *$\\|"
3174 "^ *---+ +Original message follows +---+ *$\\|"
3175 "^ *---+ +Your message follows +---+ *$\\|"
3176 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3177 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
3178 "A regexp that matches the separator before the text of a failed message.")
3180 (defvar mail-mime-unsent-header "^Content-Type: message/rfc822 *$"
3181 "A regexp that matches the header of a MIME body part with a failed message.")
3183 (defun rmail-retry-failure ()
3184 "Edit a mail message which is based on the contents of the current message.
3185 For a message rejected by the mail system, extract the interesting headers and
3186 the body of the original message.
3187 If the failed message is a MIME multipart message, it is searched for a
3188 body part with a header which matches the variable `mail-mime-unsent-header'.
3189 Otherwise, the variable `mail-unsent-separator' should match the string that
3190 delimits the returned original message.
3191 The variable `rmail-retry-ignored-headers' is a regular expression
3192 specifying headers which should not be copied into the new message."
3193 (interactive)
3194 (require 'mail-utils)
3195 (let ((rmail-this-buffer (current-buffer))
3196 (msgnum rmail-current-message)
3197 (pruned (rmail-msg-is-pruned))
3198 bounce-start bounce-end bounce-indent resending)
3199 (save-excursion
3200 ;; Narrow down to just the quoted original message
3201 (rmail-beginning-of-message)
3202 (if pruned
3203 (rmail-toggle-header 0))
3204 (let* ((case-fold-search t)
3205 (top (point))
3206 (content-type
3207 (save-restriction
3208 ;; Fetch any content-type header in current message
3209 (search-forward "\n\n") (narrow-to-region top (point))
3210 (mail-fetch-field "Content-Type") )) )
3211 ;; Handle MIME multipart bounce messages
3212 (if (and content-type
3213 (string-match
3214 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3215 content-type))
3216 (let ((codestring
3217 (concat "\n--"
3218 (substring content-type (match-beginning 1)
3219 (match-end 1)))))
3220 (or (re-search-forward mail-mime-unsent-header nil t)
3221 (error "Cannot find beginning of header in failed message"))
3222 (or (search-forward "\n\n" nil t)
3223 (error "Cannot find start of Mime data in failed message"))
3224 (setq bounce-start (point))
3225 (if (search-forward codestring nil t)
3226 (setq bounce-end (match-beginning 0))
3227 (setq bounce-end (point-max)))
3229 ;; non-MIME bounce
3230 (or (re-search-forward mail-unsent-separator nil t)
3231 (error "Cannot parse this as a failure message"))
3232 (skip-chars-forward "\n")
3233 ;; Support a style of failure message in which the original
3234 ;; message is indented, and included within lines saying
3235 ;; `Start of returned message' and `End of returned message'.
3236 (if (looking-at " +Received:")
3237 (progn
3238 (setq bounce-start (point))
3239 (skip-chars-forward " ")
3240 (setq bounce-indent (- (current-column)))
3241 (goto-char (point-max))
3242 (re-search-backward "^End of returned message$" nil t)
3243 (setq bounce-end (point)))
3244 ;; One message contained a few random lines before the old
3245 ;; message header. The first line of the message started with
3246 ;; two hyphens. A blank line followed these random lines.
3247 ;; The same line beginning with two hyphens was possibly
3248 ;; marking the end of the message.
3249 (if (looking-at "^--")
3250 (let ((boundary (buffer-substring-no-properties
3251 (point)
3252 (progn (end-of-line) (point)))))
3253 (search-forward "\n\n")
3254 (skip-chars-forward "\n")
3255 (setq bounce-start (point))
3256 (goto-char (point-max))
3257 (search-backward (concat "\n\n" boundary) bounce-start t)
3258 (setq bounce-end (point)))
3259 (setq bounce-start (point)
3260 bounce-end (point-max)))
3261 (or (search-forward "\n\n" nil t)
3262 (error "Cannot find end of header in failed message"))
3263 ))))
3264 ;; Start sending a new message; default header fields from the original.
3265 ;; Turn off the usual actions for initializing the message body
3266 ;; because we want to get only the text from the failure message.
3267 (let (mail-signature mail-setup-hook)
3268 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
3269 (list (list 'rmail-mark-message
3270 rmail-this-buffer
3271 (aref rmail-msgref-vector msgnum)
3272 "retried")))
3273 ;; Insert original text as initial text of new draft message.
3274 ;; Bind inhibit-read-only since the header delimiter
3275 ;; of the previous message was probably read-only.
3276 (let ((inhibit-read-only t)
3277 rmail-displayed-headers
3278 rmail-ignored-headers)
3279 (erase-buffer)
3280 (insert-buffer-substring rmail-this-buffer bounce-start bounce-end)
3281 (goto-char (point-min))
3282 (if bounce-indent
3283 (indent-rigidly (point-min) (point-max) bounce-indent))
3284 (rmail-clear-headers rmail-retry-ignored-headers)
3285 (rmail-clear-headers "^sender:\\|^from:\\|^return-path:")
3286 (mail-sendmail-delimit-header)
3287 (save-restriction
3288 (narrow-to-region (point-min) (mail-header-end))
3289 (setq resending (mail-fetch-field "resent-to"))
3290 (if mail-self-blind
3291 (if resending
3292 (insert "Resent-Bcc: " (user-login-name) "\n")
3293 (insert "BCC: " (user-login-name) "\n"))))
3294 (goto-char (point-min))
3295 (mail-position-on-field (if resending "Resent-To" "To") t)
3296 (set-buffer rmail-this-buffer)
3297 (rmail-beginning-of-message))))
3298 (if pruned
3299 (rmail-toggle-header))))
3301 (defun rmail-summary-exists ()
3302 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
3303 In fact, the non-nil value returned is the summary buffer itself."
3304 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
3305 rmail-summary-buffer))
3307 (defun rmail-summary-displayed ()
3308 "t iff in RMAIL buffer and an associated summary buffer is displayed."
3309 (and rmail-summary-buffer (get-buffer-window rmail-summary-buffer)))
3311 (defcustom rmail-redisplay-summary nil
3312 "*Non-nil means Rmail should show the summary when it changes.
3313 This has an effect only if a summary buffer exists."
3314 :type 'boolean
3315 :group 'rmail-summary)
3317 (defcustom rmail-summary-window-size nil
3318 "*Non-nil means specify the height for an Rmail summary window."
3319 :type '(choice (const :tag "Disabled" nil) integer)
3320 :group 'rmail-summary)
3322 ;; Put the summary buffer back on the screen, if user wants that.
3323 (defun rmail-maybe-display-summary ()
3324 (let ((selected (selected-window))
3325 window)
3326 ;; If requested, make sure the summary is displayed.
3327 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
3328 rmail-redisplay-summary
3329 (if (get-buffer-window rmail-summary-buffer 0)
3330 ;; It's already in some frame; show that one.
3331 (let ((frame (window-frame
3332 (get-buffer-window rmail-summary-buffer 0))))
3333 (make-frame-visible frame)
3334 (raise-frame frame))
3335 (display-buffer rmail-summary-buffer)))
3336 ;; If requested, set the height of the summary window.
3337 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
3338 rmail-summary-window-size
3339 (setq window (get-buffer-window rmail-summary-buffer))
3340 ;; Don't try to change the size if just one window in frame.
3341 (not (eq window (frame-root-window (window-frame window))))
3342 (unwind-protect
3343 (progn
3344 (select-window window)
3345 (enlarge-window (- rmail-summary-window-size (window-height))))
3346 (select-window selected)))))
3348 ;;;; *** Rmail Local Fontification ***
3350 (defun rmail-fontify-buffer-function ()
3351 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
3352 (make-local-hook 'rmail-show-message-hook)
3353 (add-hook 'rmail-show-message-hook 'rmail-fontify-message nil t)
3354 ;; If we're already showing a message, fontify it now.
3355 (if rmail-current-message (rmail-fontify-message))
3356 ;; Prevent Font Lock mode from kicking in.
3357 (setq font-lock-fontified t))
3359 (defun rmail-unfontify-buffer-function ()
3360 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
3361 (let ((modified (buffer-modified-p))
3362 (buffer-undo-list t) (inhibit-read-only t)
3363 before-change-functions after-change-functions
3364 buffer-file-name buffer-file-truename)
3365 (save-restriction
3366 (widen)
3367 (remove-hook 'rmail-show-message-hook 'rmail-fontify-message t)
3368 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil))
3369 (font-lock-default-unfontify-buffer)
3370 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))
3372 (defun rmail-fontify-message ()
3373 ;; Fontify the current message if it is not already fontified.
3374 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil)
3375 (let ((modified (buffer-modified-p))
3376 (buffer-undo-list t) (inhibit-read-only t)
3377 before-change-functions after-change-functions
3378 buffer-file-name buffer-file-truename)
3379 (save-excursion
3380 (save-match-data
3381 (add-text-properties (point-min) (point-max) '(rmail-fontified t))
3382 (font-lock-fontify-region (point-min) (point-max))
3383 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))))
3385 ;;; Speedbar support for RMAIL files.
3386 (eval-when-compile (require 'speedbar))
3388 (defvar rmail-speedbar-match-folder-regexp "^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
3389 "*This regex us used to match folder names to be displayed in speedbar.
3390 Enabling this will permit speedbar to display your folders for easy
3391 browsing, and moving of messages.")
3393 (defvar rmail-speedbar-last-user nil
3394 "The last user to be displayed in the speedbar.")
3396 (defvar rmail-speedbar-key-map nil
3397 "Keymap used when in rmail display mode.")
3399 (defun rmail-install-speedbar-variables ()
3400 "Install those variables used by speedbar to enhance rmail."
3401 (if rmail-speedbar-key-map
3403 (setq rmail-speedbar-key-map (speedbar-make-specialized-keymap))
3405 (define-key rmail-speedbar-key-map "e" 'speedbar-edit-line)
3406 (define-key rmail-speedbar-key-map "r" 'speedbar-edit-line)
3407 (define-key rmail-speedbar-key-map "\C-m" 'speedbar-edit-line)
3408 (define-key rmail-speedbar-key-map "M"
3409 'rmail-speedbar-move-message-to-folder-on-line)))
3411 (defvar rmail-speedbar-menu-items
3412 '(["Read Folder" speedbar-edit-line t]
3413 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
3414 (save-excursion (beginning-of-line)
3415 (looking-at "<M> "))])
3416 "Additional menu-items to add to speedbar frame.")
3418 ;; Make sure our special speedbar major mode is loaded
3419 (if (featurep 'speedbar)
3420 (rmail-install-speedbar-variables)
3421 (add-hook 'speedbar-load-hook 'rmail-install-speedbar-variables))
3423 (defun rmail-speedbar-buttons (buffer)
3424 "Create buttons for BUFFER containing rmail messages.
3425 Click on the address under Reply to: to reply to this person.
3426 Under Folders: Click a name to read it, or on the <M> to move the
3427 current message into that RMAIL folder."
3428 (let ((from nil))
3429 (save-excursion
3430 (set-buffer buffer)
3431 (goto-char (point-min))
3432 (if (not (re-search-forward "^Reply-To: " nil t))
3433 (if (not (re-search-forward "^From:? " nil t))
3434 (setq from t)))
3435 (if from
3437 (setq from (buffer-substring (point) (save-excursion
3438 (end-of-line)
3439 (point))))))
3440 (goto-char (point-min))
3441 (if (and (looking-at "Reply to:")
3442 (equal from rmail-speedbar-last-user))
3444 (setq rmail-speedbar-last-user from)
3445 (erase-buffer)
3446 (insert "Reply To:\n")
3447 (if (stringp from)
3448 (speedbar-insert-button from 'speedbar-directory-face 'highlight
3449 'rmail-speedbar-button 'rmail-reply))
3450 (insert "Folders:\n")
3451 (let* ((case-fold-search nil)
3452 (df (directory-files (save-excursion (set-buffer buffer)
3453 default-directory)
3454 nil rmail-speedbar-match-folder-regexp)))
3455 (while df
3456 (speedbar-insert-button "<M>" 'speedbar-button-face 'highlight
3457 'rmail-speedbar-move-message (car df))
3458 (speedbar-insert-button (car df) 'speedbar-file-face 'highlight
3459 'rmail-speedbar-find-file nil t)
3460 (setq df (cdr df)))))))
3462 (defun rmail-speedbar-button (text token indent)
3463 "Execute an rmail command specified by TEXT.
3464 The command used is TOKEN. INDENT is not used."
3465 (speedbar-with-attached-buffer
3466 (funcall token t)))
3468 (defun rmail-speedbar-find-file (text token indent)
3469 "Load in the rmail file TEXT.
3470 TOKEN and INDENT are not used."
3471 (speedbar-with-attached-buffer
3472 (message "Loading in RMAIL file %s..." text)
3473 (find-file text)))
3475 (defun rmail-speedbar-move-message-to-folder-on-line ()
3476 "If the current line is a folder, move current message to it."
3477 (interactive)
3478 (save-excursion
3479 (beginning-of-line)
3480 (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t)
3481 (progn
3482 (forward-char -2)
3483 (speedbar-do-function-pointer)))))
3485 (defun rmail-speedbar-move-message (text token indent)
3486 "From button TEXT, copy current message to the rmail file specified by TOKEN.
3487 TEXT and INDENT are not used."
3488 (speedbar-with-attached-buffer
3489 (message "Moving message to %s" token)
3490 (rmail-output-to-rmail-file token)))
3492 ; Functions for setting, getting and encoding the POP password.
3493 ; The password is encoded to prevent it from being easily accessible
3494 ; to "prying eyes." Obviously, this encoding isn't "real security,"
3495 ; nor is it meant to be.
3497 ;;;###autoload
3498 (defun rmail-set-pop-password (password)
3499 "Set PASSWORD to be used for retrieving mail from a POP server."
3500 (interactive "sPassword: ")
3501 (if password
3502 (setq rmail-encoded-pop-password
3503 (rmail-encode-string password (emacs-pid)))
3504 (setq rmail-pop-password nil)
3505 (setq rmail-encoded-pop-password nil)))
3507 (defun rmail-get-pop-password ()
3508 "Get the password for retrieving mail from a POP server. If none
3509 has been set, then prompt the user for one."
3510 (if (not rmail-encoded-pop-password)
3511 (progn (if (not rmail-pop-password)
3512 (setq rmail-pop-password (read-passwd "POP password: ")))
3513 (rmail-set-pop-password rmail-pop-password)
3514 (setq rmail-pop-password nil)))
3515 (rmail-encode-string rmail-encoded-pop-password (emacs-pid)))
3517 (defun rmail-have-password ()
3518 (or rmail-pop-password rmail-encoded-pop-password))
3520 (defun rmail-encode-string (string mask)
3521 "Encode STRING with integer MASK, by taking the exclusive OR of the
3522 lowest byte in the mask with the first character of string, the
3523 second-lowest-byte with the second character of the string, etc.,
3524 restarting at the lowest byte of the mask whenever it runs out.
3525 Returns the encoded string. Calling the function again with an
3526 encoded string (and the same mask) will decode the string."
3527 (setq mask (abs mask)) ; doesn't work if negative
3528 (let* ((string-vector (string-to-vector string)) (i 0)
3529 (len (length string-vector)) (curmask mask) charmask)
3530 (while (< i len)
3531 (if (= curmask 0)
3532 (setq curmask mask))
3533 (setq charmask (% curmask 256))
3534 (setq curmask (lsh curmask -8))
3535 (aset string-vector i (logxor charmask (aref string-vector i)))
3536 (setq i (1+ i)))
3537 (concat string-vector)))
3539 (provide 'rmail)
3541 ;;; rmail.el ends here