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
4 ;; Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
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.
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")
51 "Mail reader for Emacs."
54 (defgroup rmail-retrieve nil
55 "Rmail retrieval options."
59 (defgroup rmail-files nil
64 (defgroup rmail-headers nil
65 "Rmail header options."
69 (defgroup rmail-reply nil
70 "Rmail reply options."
74 (defgroup rmail-summary nil
75 "Rmail summary options."
77 :prefix
"rmail-summary-"
80 (defgroup rmail-output nil
81 "Output message to a file."
82 :prefix
"rmail-output-"
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."
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
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."
123 :group
'rmail-retrieve
)
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
))
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.")
142 (defcustom rmail-ignored-headers
"^via:\\|^mail-from:\\|^origin:\\|^references:\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^x-mailer:\\|^delivered-to:\\|^lines:\\|^mime-version:\\|^content-transfer-encoding:\\|^x-coding-system:\\|^return-path:\\|^errors-to:\\|^return-receipt-to:\\|^x-attribution:\\|^x-disclaimer:"
143 "*Regexp to match header fields that Rmail should normally hide.
144 This variable is used for reformatting the message header,
145 which normally happens once for each message,
146 when you view the message for the first time in Rmail.
147 To make a change in this variable take effect
148 for a message that you have already viewed,
149 go to that message and type \\[rmail-toggle-header] twice."
151 :group
'rmail-headers
)
154 (defcustom rmail-displayed-headers nil
155 "*Regexp to match Header fields that Rmail should display.
156 If nil, display all header fields except those matched by
157 `rmail-ignored-headers'."
158 :type
'(choice regexp
(const :tag
"All"))
159 :group
'rmail-headers
)
162 (defcustom rmail-retry-ignored-headers nil
"\
163 *Headers that should be stripped when retrying a failed message."
164 :type
'(choice regexp
(const nil
:tag
"None"))
165 :group
'rmail-headers
)
168 (defcustom rmail-highlighted-headers
"^From:\\|^Subject:" "\
169 *Regexp to match Header fields that Rmail should normally highlight.
170 A value of nil means don't highlight.
171 See also `rmail-highlight-face'."
173 :group
'rmail-headers
)
176 (defcustom rmail-highlight-face nil
"\
177 *Face used by Rmail for highlighting headers."
178 :type
'(choice (const :tag
"Default" nil
)
180 :group
'rmail-headers
)
183 (defcustom rmail-delete-after-output nil
"\
184 *Non-nil means automatically delete a message that is copied to a file."
189 (defcustom rmail-primary-inbox-list nil
"\
190 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
191 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
192 \(the name varies depending on the operating system,
193 and the value of the environment variable MAIL overrides it)."
194 ;; Don't use backquote here, because we don't want to need it
196 :type
(list 'choice
'(const :tag
"Default" nil
)
197 (list 'repeat
':value
(list (or (getenv "MAIL")
198 (concat "/var/spool/mail/"
201 :group
'rmail-retrieve
205 (defcustom rmail-mail-new-frame nil
206 "*Non-nil means Rmail makes a new frame for composing outgoing mail."
211 (defcustom rmail-secondary-file-directory
"~/"
212 "*Directory for additional secondary Rmail files."
216 (defcustom rmail-secondary-file-regexp
"\\.xmail$"
217 "*Regexp for which files are secondary Rmail files."
222 (defvar rmail-mode-hook nil
223 "List of functions to call when Rmail is invoked.")
226 (defvar rmail-get-new-mail-hook nil
227 "List of functions to call when Rmail has retrieved new mail.")
230 (defvar rmail-show-message-hook nil
231 "List of functions to call when Rmail displays a message.")
234 (defvar rmail-quit-hook nil
235 "List of functions to call when quitting out of Rmail.")
238 (defvar rmail-delete-message-hook nil
239 "List of functions to call when Rmail deletes a message.
240 When the hooks are called, the message has been marked deleted but is
241 still the current message in the Rmail buffer.")
243 ;; These may be altered by site-init.el to match the format of mmdf files
244 ;; delimiting used on a given host (delim1 and delim2 from the config
247 (defvar rmail-mmdf-delim1
"^\001\001\001\001\n"
248 "Regexp marking the start of an mmdf message")
249 (defvar rmail-mmdf-delim2
"^\001\001\001\001\n"
250 "Regexp marking the end of an mmdf message")
252 (defcustom rmail-message-filter nil
253 "If non-nil, a filter function for new messages in RMAIL.
254 Called with region narrowed to the message, including headers,
255 before obeying `rmail-ignored-headers'."
256 :group
'rmail-headers
259 (defvar rmail-reply-prefix
"Re: "
260 "String to prepend to Subject line when replying to a message.")
262 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
263 ;; This pattern should catch all the common variants.
264 (defvar rmail-reply-regexp
"\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
265 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
267 (defcustom rmail-display-summary nil
268 "*If non-nil, Rmail always displays the summary buffer."
269 :group
'rmail-summary
272 (defvar rmail-inbox-list nil
)
273 (put 'rmail-inbox-list
'permanent-local t
)
275 (defvar rmail-keywords nil
)
276 (put 'rmail-keywords
'permanent-local t
)
278 (defvar rmail-buffer nil
279 "The RMAIL buffer related to the current buffer.
280 In an RMAIL buffer, this holds the RMAIL buffer itself.
281 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
282 (put 'rmail-buffer
'permanent-local t
)
284 ;; Message counters and markers. Deleted flags.
286 (defvar rmail-current-message nil
)
287 (put 'rmail-current-message
'permanent-local t
)
289 (defvar rmail-total-messages nil
)
290 (put 'rmail-total-messages
'permanent-local t
)
292 (defvar rmail-message-vector nil
)
293 (put 'rmail-message-vector
'permanent-local t
)
295 (defvar rmail-deleted-vector nil
)
296 (put 'rmail-deleted-vector
'permanent-local t
)
298 (defvar rmail-msgref-vector nil
299 "In an Rmail buffer, a vector whose Nth element is a list (N).
300 When expunging renumbers messages, these lists are modified
301 by substituting the new message number into the existing list.")
302 (put 'rmail-msgref-vector
'permanent-local t
)
304 (defvar rmail-overlay-list nil
)
305 (put 'rmail-overlay-list
'permanent-local t
)
307 ;; These are used by autoloaded rmail-summary.
309 (defvar rmail-summary-buffer nil
)
310 (put 'rmail-summary-buffer
'permanent-local t
)
311 (defvar rmail-summary-vector nil
)
312 (put 'rmail-summary-vector
'permanent-local t
)
314 (defvar rmail-view-buffer nil
315 "Buffer which holds RMAIL message for MIME displaying.")
316 (put 'rmail-view-buffer
'permanent-local t
)
318 ;; `Sticky' default variables.
320 ;; Last individual label specified to a or k.
321 (defvar rmail-last-label nil
)
322 (put 'rmail-last-label
'permanent-local t
)
324 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
325 (defvar rmail-last-multi-labels nil
)
327 (defvar rmail-last-regexp nil
)
328 (put 'rmail-last-regexp
'permanent-local t
)
330 (defcustom rmail-default-file
"~/xmail"
331 "*Default file name for \\[rmail-output]."
334 (defcustom rmail-default-rmail-file
"~/XMAIL"
335 "*Default file name for \\[rmail-output-to-rmail-file]."
338 (defcustom rmail-default-body-file
"~/mailout"
339 "*Default file name for \\[rmail-output-body-to-file]."
344 ;; Mule and MIME related variables.
347 (defvar rmail-file-coding-system nil
348 "Coding system used in RMAIL file.
350 This is set to nil by default.")
353 (defcustom rmail-enable-mime nil
354 "*If non-nil, RMAIL uses MIME feature.
355 If the value is t, RMAIL automatically shows MIME decoded message.
356 If the value is neither t nor nil, RMAIL does not show MIME decoded message
357 until a user explicitly requires it."
358 :type
'(choice (const :tag
"on" t
)
359 (const :tag
"off" nil
)
360 (other :tag
"when asked" ask
))
364 (defvar rmail-show-mime-function nil
365 "Function to show MIME decoded message of RMAIL file.")
368 (defvar rmail-mime-feature
'rmail-mime
369 "Feature to require to load MIME support in Rmail.
370 When starting Rmail, if `rmail-enable-mime' is non-nil,
371 this feature is required with `require'.")
374 (defvar rmail-decode-mime-charset t
375 "*Non-nil means a message is decoded by MIME's charset specification.
376 If this variable is nil, or the message has not MIME specification,
377 the message is decoded as normal way.
379 If the variable `rmail-enable-mime' is non-nil, this variables is
380 ignored, and all the decoding work is done by a feature specified by
381 the variable `rmail-mime-feature'.")
384 (defvar rmail-mime-charset-pattern
385 "^content-type:[ ]*text/plain;[ \t\n]*charset=\"?\\([^ \t\n\"]+\\)\"?"
386 "Regexp to match MIME-charset specification in a header of message.
387 The first parenthesized expression should match the MIME-charset name.")
390 ;;; Regexp matching the delimiter of messages in UNIX mail format
391 ;;; (UNIX From lines), minus the initial ^. Note that if you change
392 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
393 ;;; that knows the exact ordering of the \\( \\) subexpressions.
394 (defvar rmail-unix-mail-delimiter
395 (let ((time-zone-regexp
396 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
397 "\\|[-+]?[0-9][0-9][0-9][0-9]"
403 ;; Many things can happen to an RFC 822 mailbox before it is put into
404 ;; a `From' line. The leading phrase can be stripped, e.g.
405 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
406 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
407 ;; can be removed, e.g.
408 ;; From: joe@y.z (Joe K
410 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
413 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
414 ;; The mailbox can be removed or be replaced by white space, e.g.
415 ;; From: "Joe User"{space}{tab}
417 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
418 ;; where {space} and {tab} represent the Ascii space and tab characters.
419 ;; We want to match the results of any of these manglings.
420 ;; The following regexp rejects names whose first characters are
421 ;; obviously bogus, but after that anything goes.
422 "\\([^\0-\b\n-\r\^?].*\\)? "
424 ;; The time the message was sent.
425 "\\([^\0-\r \^?]+\\) +" ; day of the week
426 "\\([^\0-\r \^?]+\\) +" ; month
427 "\\([0-3]?[0-9]\\) +" ; day of month
428 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
430 ;; Perhaps a time zone, specified by an abbreviation, or by a
435 " \\([0-9][0-9]+\\) *"
437 ;; On some systems the time zone can appear after the year, too.
441 "\\(remote from .*\\)?"
446 (defvar rmail-font-lock-keywords
448 (let* ((cite-chars "[>|}]")
449 (cite-prefix "A-Za-z")
450 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
451 (list '("^\\(From\\|Sender\\):" . font-lock-function-name-face
)
452 '("^Reply-To:.*$" . font-lock-function-name-face
)
453 '("^Subject:" . font-lock-comment-face
)
454 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
455 . font-lock-keyword-face
)
456 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
458 (,(concat "\\=[ \t]*"
459 "\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
460 "\\(" cite-chars
"[ \t]*\\)\\)+"
462 (beginning-of-line) (end-of-line)
463 (2 font-lock-constant-face nil t
)
464 (4 font-lock-comment-face nil t
)))
465 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\|Date\\):.*$"
466 . font-lock-string-face
))))
467 "Additional expressions to highlight in Rmail mode.")
469 ;; Perform BODY in the summary buffer
470 ;; in such a way that its cursor is properly updated in its own window.
471 (defmacro rmail-select-summary
(&rest body
)
472 `(let ((total rmail-total-messages
))
473 (if (rmail-summary-displayed)
474 (let ((window (selected-window)))
478 (pop-to-buffer rmail-summary-buffer
)
479 ;; rmail-total-messages is a buffer-local var
480 ;; in the rmail buffer.
481 ;; This way we make it available for the body
482 ;; even tho the rmail buffer is not current.
483 (let ((rmail-total-messages total
))
485 (select-window window
))))
487 (set-buffer rmail-summary-buffer
)
488 (let ((rmail-total-messages total
))
490 (rmail-maybe-display-summary)))
492 ;;;; *** Rmail Mode ***
494 (defvar rmail-enable-multibyte nil
)
497 (defun rmail (&optional file-name-arg
)
498 "Read and edit incoming mail.
499 Moves messages into file named by `rmail-file-name' (a babyl format file)
500 and edits that file in RMAIL Mode.
501 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
503 May be called with file name as argument; then performs rmail editing on
504 that file, but does not copy any new mail into the file.
505 Interactively, if you supply a prefix argument, then you
506 have a chance to specify a file name with the minibuffer.
508 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
509 (interactive (if current-prefix-arg
510 (list (read-file-name "Run rmail on RMAIL file: "))))
511 (if rmail-enable-mime
513 (require rmail-mime-feature
)
514 (error (message "Feature `%s' not provided" rmail-mime-feature
)
516 (setq rmail-enable-mime nil
))))
517 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
518 (existed (get-file-buffer file-name
))
519 ;; This binding is necessary because we much decide if we
520 ;; need code conversion while the buffer is unibyte
521 ;; (i.e. enable-multibyte-characters is nil).
522 (rmail-enable-multibyte
524 (with-current-buffer existed enable-multibyte-characters
)
525 (default-value 'enable-multibyte-characters
)))
526 ;; Since the file may contain messages of different encodings
527 ;; at the tail (non-BYBYL part), we can't decode them at once
528 ;; on reading. So, at first, we read the file without text
529 ;; code conversion, then decode the messages one by one by
530 ;; rmail-decode-babyl-format or
531 ;; rmail-convert-to-babyl-format.
532 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
))
533 run-mail-hook msg-shown
)
534 ;; Like find-file, but in the case where a buffer existed
535 ;; and the file was reverted, recompute the message-data.
536 ;; We used to bind enable-local-variables to nil here,
537 ;; but that should not be needed now that rmail-mode
538 ;; sets it locally to nil.
539 ;; (Binding a variable locally with let is not safe if it has
540 ;; buffer-local bindings.)
541 (if (and existed
(not (verify-visited-file-modtime existed
)))
543 (find-file file-name
)
544 (if (and (verify-visited-file-modtime existed
)
545 (eq major-mode
'rmail-mode
))
546 (progn (rmail-forget-messages)
547 (rmail-set-message-counters))))
549 (let ((enable-local-variables nil
))
550 (find-file-noselect file-name
))))
551 (if (eq major-mode
'rmail-edit-mode
)
552 (error "Exit Rmail Edit mode before getting new mail"))
553 (if (and existed
(> (buffer-size) 0))
554 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
555 (or (eq major-mode
'rmail-mode
)
556 (progn (rmail-mode-2)
557 (setq run-mail-hook t
)))
558 (setq run-mail-hook t
)
560 ;; Convert all or part to Babyl file if possible.
562 (goto-char (point-max)))
563 ;; As we have read a file by raw-text, the buffer is set to
564 ;; unibyte. We must make it multibyte if necessary.
565 (if (and rmail-enable-multibyte
566 (not enable-multibyte-characters
))
567 (set-buffer-multibyte t
))
568 ;; If necessary, scan to find all the messages.
569 (rmail-maybe-set-message-counters)
571 (unless (and (not file-name-arg
)
572 (rmail-get-new-mail))
573 (rmail-show-message (rmail-first-unseen-message)))
575 (if rmail-display-summary
(rmail-summary))
576 (rmail-construct-io-menu)
578 (run-hooks 'rmail-mode-hook
))))))
580 ;; Given the value of MAILPATH, return a list of inbox file names.
581 ;; This is turned off because it is not clear that the user wants
582 ;; all these inboxes to feed into the primary rmail file.
583 ; (defun rmail-convert-mailpath (string)
585 ; (while (setq idx (string-match "[%:]" string))
586 ; (let ((this (substring string 0 idx)))
587 ; (setq string (substring string (1+ idx)))
588 ; (setq list (cons (if (string-match "%" this)
589 ; (substring this 0 (string-match "%" this))
594 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
595 ; will not cause emacs 18.55 problems.
597 ;; This calls rmail-decode-babyl-format if the file is already Babyl.
599 (defun rmail-convert-file ()
602 (goto-char (point-min))
603 ;; If file doesn't start like a Babyl file,
604 ;; convert it to one, by adding a header and converting each message.
605 (cond ((looking-at "BABYL OPTIONS:"))
606 ((looking-at "Version: 5\n")
607 ;; Losing babyl file made by old version of Rmail.
608 ;; Just fix the babyl file header; don't make a new one,
609 ;; so we don't lose the Labels: file attribute, etc.
610 (let ((buffer-read-only nil
))
611 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
612 ((equal (point-min) (point-max))
613 ;; Empty RMAIL file. Just insert the header.
614 (rmail-insert-rmail-file-header))
616 ;; Non-empty file in non-RMAIL format. Add header and convert.
618 (rmail-insert-rmail-file-header)))
619 ;; If file was not a Babyl file or if there are
620 ;; Unix format messages added at the end,
621 ;; convert file as necessary.
624 (goto-char (point-max))
625 (search-backward "\n\^_")
627 (looking-at "\n*From ")))
628 (let ((buffer-read-only nil
))
629 (message "Converting to Babyl format...")
630 ;; If file needs conversion, convert it all,
631 ;; except for the BABYL header.
632 ;; (rmail-convert-to-babyl-format would delete the header.)
633 (goto-char (point-min))
634 (search-forward "\n\^_" nil t
)
635 (narrow-to-region (point) (point-max))
636 (rmail-convert-to-babyl-format)
637 (message "Converting to Babyl format...done"))
638 (if (and (not rmail-enable-mime
)
639 rmail-enable-multibyte
)
640 ;; We still have to decode BABYL part.
641 (rmail-decode-babyl-format)))))
643 (defun rmail-insert-rmail-file-header ()
644 (let ((buffer-read-only nil
))
645 ;; -*-rmail-*- is here so that visiting the file normally
646 ;; recognizes it as an Rmail file.
647 (insert "BABYL OPTIONS: -*- rmail -*-
650 Note: This is the header of an rmail file.
651 Note: If you are seeing it in rmail,
652 Note: it means the file has no messages in it.\n\^_")))
654 ;; Decode Babyl formated part at the head of current buffer by
655 ;; rmail-file-coding-system, or if it is nil, do auto conversion.
657 (defun rmail-decode-babyl-format ()
658 (let ((modifiedp (buffer-modified-p))
659 (buffer-read-only nil
)
660 (coding-system rmail-file-coding-system
)
662 (goto-char (point-min))
663 (search-forward "\n\^_" nil t
) ; Skip BABYL header.
665 (goto-char (point-max))
666 (search-backward "\n\^_" from
'mv
)
668 (unless (and coding-system
669 (coding-system-p coding-system
))
670 (setq coding-system
(detect-coding-region from to t
)))
671 (unless (memq coding-system
672 '(undecided undecided-unix
))
673 (set-buffer-modified-p t
) ; avoid locking when decoding
674 (decode-coding-region from to coding-system
)
675 (setq coding-system last-coding-system-used
))
676 (set-buffer-modified-p modifiedp
)
677 (setq buffer-file-coding-system nil
)
678 (setq save-buffer-coding-system
679 (or coding-system
'undecided
))))
681 (defvar rmail-mode-map nil
)
684 (setq rmail-mode-map
(make-keymap))
685 (suppress-keymap rmail-mode-map
)
686 (define-key rmail-mode-map
"a" 'rmail-add-label
)
687 (define-key rmail-mode-map
"b" 'rmail-bury
)
688 (define-key rmail-mode-map
"c" 'rmail-continue
)
689 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
690 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
)
691 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
692 (define-key rmail-mode-map
"f" 'rmail-forward
)
693 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
694 (define-key rmail-mode-map
"h" 'rmail-summary
)
695 (define-key rmail-mode-map
"i" 'rmail-input
)
696 (define-key rmail-mode-map
"j" 'rmail-show-message
)
697 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
698 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
699 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
700 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
701 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
702 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
703 (define-key rmail-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
704 (define-key rmail-mode-map
"m" 'rmail-mail
)
705 (define-key rmail-mode-map
"\em" 'rmail-retry-failure
)
706 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
707 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
708 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
709 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
710 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
711 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
712 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
713 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
714 (define-key rmail-mode-map
"q" 'rmail-quit
)
715 (define-key rmail-mode-map
"r" 'rmail-reply
)
716 ;; I find I can't live without the default M-r command -- rms.
717 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
718 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
719 (define-key rmail-mode-map
"\es" 'rmail-search
)
720 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
721 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
722 (define-key rmail-mode-map
"w" 'rmail-output-body-to-file
)
723 (define-key rmail-mode-map
"x" 'rmail-expunge
)
724 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
725 (define-key rmail-mode-map
"<" 'rmail-first-message
)
726 (define-key rmail-mode-map
">" 'rmail-last-message
)
727 (define-key rmail-mode-map
" " 'scroll-up
)
728 (define-key rmail-mode-map
"\177" 'scroll-down
)
729 (define-key rmail-mode-map
"?" 'describe-mode
)
730 (define-key rmail-mode-map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
731 (define-key rmail-mode-map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
732 (define-key rmail-mode-map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
733 (define-key rmail-mode-map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
734 (define-key rmail-mode-map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
735 (define-key rmail-mode-map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
736 (define-key rmail-mode-map
"\C-c\C-s\C-k" 'rmail-sort-by-keywords
)
737 (define-key rmail-mode-map
"\C-c\C-n" 'rmail-next-same-subject
)
738 (define-key rmail-mode-map
"\C-c\C-p" 'rmail-previous-same-subject
)
741 (define-key rmail-mode-map
[menu-bar
] (make-sparse-keymap))
743 (define-key rmail-mode-map
[menu-bar classify
]
744 (cons "Classify" (make-sparse-keymap "Classify")))
746 (define-key rmail-mode-map
[menu-bar classify input-menu
]
749 (define-key rmail-mode-map
[menu-bar classify output-menu
]
752 (define-key rmail-mode-map
[menu-bar classify output-body
]
753 '("Output body to file..." . rmail-output-body-to-file
))
755 (define-key rmail-mode-map
[menu-bar classify output-inbox
]
756 '("Output (inbox)..." . rmail-output
))
758 (define-key rmail-mode-map
[menu-bar classify output
]
759 '("Output (Rmail)..." . rmail-output-to-rmail-file
))
761 (define-key rmail-mode-map
[menu-bar classify kill-label
]
762 '("Kill Label..." . rmail-kill-label
))
764 (define-key rmail-mode-map
[menu-bar classify add-label
]
765 '("Add Label..." . rmail-add-label
))
767 (define-key rmail-mode-map
[menu-bar summary
]
768 (cons "Summary" (make-sparse-keymap "Summary")))
770 (define-key rmail-mode-map
[menu-bar summary senders
]
771 '("By Senders..." . rmail-summary-by-senders
))
773 (define-key rmail-mode-map
[menu-bar summary labels
]
774 '("By Labels..." . rmail-summary-by-labels
))
776 (define-key rmail-mode-map
[menu-bar summary recipients
]
777 '("By Recipients..." . rmail-summary-by-recipients
))
779 (define-key rmail-mode-map
[menu-bar summary topic
]
780 '("By Topic..." . rmail-summary-by-topic
))
782 (define-key rmail-mode-map
[menu-bar summary regexp
]
783 '("By Regexp..." . rmail-summary-by-regexp
))
785 (define-key rmail-mode-map
[menu-bar summary all
]
786 '("All" . rmail-summary
))
788 (define-key rmail-mode-map
[menu-bar mail
]
789 (cons "Mail" (make-sparse-keymap "Mail")))
791 (define-key rmail-mode-map
[menu-bar mail rmail-get-new-mail
]
792 '("Get New Mail" . rmail-get-new-mail
))
794 (define-key rmail-mode-map
[menu-bar mail lambda
]
797 (define-key rmail-mode-map
[menu-bar mail continue
]
798 '("Continue" . rmail-continue
))
800 (define-key rmail-mode-map
[menu-bar mail resend
]
801 '("Re-send..." . rmail-resend
))
803 (define-key rmail-mode-map
[menu-bar mail forward
]
804 '("Forward" . rmail-forward
))
806 (define-key rmail-mode-map
[menu-bar mail retry
]
807 '("Retry" . rmail-retry-failure
))
809 (define-key rmail-mode-map
[menu-bar mail reply
]
810 '("Reply" . rmail-reply
))
812 (define-key rmail-mode-map
[menu-bar mail mail
]
813 '("Mail" . rmail-mail
))
815 (define-key rmail-mode-map
[menu-bar delete
]
816 (cons "Delete" (make-sparse-keymap "Delete")))
818 (define-key rmail-mode-map
[menu-bar delete expunge
/save
]
819 '("Expunge/Save" . rmail-expunge-and-save
))
821 (define-key rmail-mode-map
[menu-bar delete expunge
]
822 '("Expunge" . rmail-expunge
))
824 (define-key rmail-mode-map
[menu-bar delete undelete
]
825 '("Undelete" . rmail-undelete-previous-message
))
827 (define-key rmail-mode-map
[menu-bar delete delete
]
828 '("Delete" . rmail-delete-forward
))
830 (define-key rmail-mode-map
[menu-bar move
]
831 (cons "Move" (make-sparse-keymap "Move")))
833 (define-key rmail-mode-map
[menu-bar move search-back
]
834 '("Search Back..." . rmail-search-backwards
))
836 (define-key rmail-mode-map
[menu-bar move search
]
837 '("Search..." . rmail-search
))
839 (define-key rmail-mode-map
[menu-bar move previous
]
840 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
842 (define-key rmail-mode-map
[menu-bar move next
]
843 '("Next Nondeleted" . rmail-next-undeleted-message
))
845 (define-key rmail-mode-map
[menu-bar move last
]
846 '("Last" . rmail-last-message
))
848 (define-key rmail-mode-map
[menu-bar move first
]
849 '("First" . rmail-first-message
))
851 (define-key rmail-mode-map
[menu-bar move previous
]
852 '("Previous" . rmail-previous-message
))
854 (define-key rmail-mode-map
[menu-bar move next
]
855 '("Next" . rmail-next-message
))
857 ;; Rmail mode is suitable only for specially formatted data.
858 (put 'rmail-mode
'mode-class
'special
)
860 (defun rmail-mode-kill-summary ()
861 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
865 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
866 All normal editing commands are turned off.
867 Instead, these commands are available:
869 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
870 \\[scroll-up] Scroll to next screen of this message.
871 \\[scroll-down] Scroll to previous screen of this message.
872 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
873 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
874 \\[rmail-next-message] Move to Next message whether deleted or not.
875 \\[rmail-previous-message] Move to Previous message whether deleted or not.
876 \\[rmail-first-message] Move to the first message in Rmail file.
877 \\[rmail-last-message] Move to the last message in Rmail file.
878 \\[rmail-show-message] Jump to message specified by numeric position in file.
879 \\[rmail-search] Search for string and show message it is found in.
880 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
881 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
882 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
883 till a deleted message is found.
884 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
885 \\[rmail-expunge] Expunge deleted messages.
886 \\[rmail-expunge-and-save] Expunge and save the file.
887 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
888 \\[save-buffer] Save without expunging.
889 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
890 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
891 \\[rmail-continue] Continue composing outgoing message started before.
892 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
893 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
894 \\[rmail-forward] Forward this message to another user.
895 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
896 \\[rmail-output] Output this message to a Unix-format mail file (append it).
897 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
898 \\[rmail-input] Input Rmail file. Run Rmail on that file.
899 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
900 \\[rmail-kill-label] Kill label. Remove a label from current message.
901 \\[rmail-next-labeled-message] Move to Next message with specified label
902 (label defaults to last one specified).
903 Standard labels: filed, unseen, answered, forwarded, deleted.
904 Any other label is present only if you add it with \\[rmail-add-label].
905 \\[rmail-previous-labeled-message] Move to Previous message with specified label
906 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
907 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
908 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
909 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
910 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
911 \\[rmail-toggle-header] Toggle display of complete header."
914 (rmail-set-message-counters)
915 (rmail-show-message rmail-total-messages
)
916 (run-hooks 'rmail-mode-hook
))
918 (defun rmail-mode-2 ()
919 (kill-all-local-variables)
921 (rmail-perm-variables)
924 (defun rmail-mode-1 ()
925 (setq major-mode
'rmail-mode
)
926 (setq mode-name
"RMAIL")
927 (setq buffer-read-only t
)
928 ;; No need to auto save RMAIL files in normal circumstances
929 ;; because they contain no info except attribute changes
930 ;; and deletion of messages.
931 ;; The one exception is when messages are copied into an Rmail mode buffer.
932 ;; rmail-output-to-rmail-file enables auto save when you do that.
933 (setq buffer-auto-save-file-name nil
)
934 (setq mode-line-modified
"--")
935 (use-local-map rmail-mode-map
)
936 (set-syntax-table text-mode-syntax-table
)
937 (setq local-abbrev-table text-mode-abbrev-table
))
939 ;; Set up the permanent locals associated with an Rmail file.
940 (defun rmail-perm-variables ()
941 (make-local-variable 'rmail-last-label
)
942 (make-local-variable 'rmail-last-regexp
)
943 (make-local-variable 'rmail-deleted-vector
)
944 (make-local-variable 'rmail-buffer
)
945 (setq rmail-buffer
(current-buffer))
946 (make-local-variable 'rmail-view-buffer
)
947 (setq rmail-view-buffer rmail-buffer
)
948 (make-local-variable 'rmail-summary-buffer
)
949 (make-local-variable 'rmail-summary-vector
)
950 (make-local-variable 'rmail-current-message
)
951 (make-local-variable 'rmail-total-messages
)
952 (make-local-variable 'rmail-overlay-list
)
953 (setq rmail-overlay-list nil
)
954 (make-local-variable 'rmail-message-vector
)
955 (make-local-variable 'rmail-msgref-vector
)
956 (make-local-variable 'rmail-inbox-list
)
957 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
958 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
959 (and (null rmail-inbox-list
)
960 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
961 (equal buffer-file-truename
962 (abbreviate-file-name (file-truename rmail-file-name
))))
963 (setq rmail-inbox-list
964 (or rmail-primary-inbox-list
965 (list (or (getenv "MAIL")
966 (concat rmail-spool-directory
967 (user-login-name)))))))
968 (make-local-variable 'rmail-keywords
)
969 ;; this gets generated as needed
970 (setq rmail-keywords nil
))
972 ;; Set up the non-permanent locals associated with Rmail mode.
973 (defun rmail-variables ()
974 (make-local-variable 'save-buffer-coding-system
)
975 ;; If we don't already have a value for save-buffer-coding-system,
976 ;; get it from buffer-file-coding-system, and clear that
977 ;; because it should be determined in rmail-show-message.
978 (unless save-buffer-coding-system
979 (setq save-buffer-coding-system
(or buffer-file-coding-system
'undecided
))
980 (setq buffer-file-coding-system nil
))
981 ;; Don't let a local variables list in a message cause confusion.
982 (make-local-variable 'local-enable-local-variables
)
983 (setq local-enable-local-variables nil
)
984 (make-local-variable 'revert-buffer-function
)
985 (setq revert-buffer-function
'rmail-revert
)
986 (make-local-variable 'font-lock-defaults
)
987 (setq font-lock-defaults
988 '(rmail-font-lock-keywords
990 (font-lock-maximum-size . nil
)
991 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
992 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
993 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
994 (make-local-variable 'require-final-newline
)
995 (setq require-final-newline nil
)
996 (make-local-variable 'version-control
)
997 (setq version-control
'never
)
998 (make-local-variable 'kill-buffer-hook
)
999 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
1000 (make-local-variable 'file-precious-flag
)
1001 (setq file-precious-flag t
))
1003 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1004 (defun rmail-revert (arg noconfirm
)
1005 (let* ((revert-buffer-function (default-value 'revert-buffer-function
))
1006 (rmail-enable-multibyte enable-multibyte-characters
)
1007 ;; See similar code in `rmail'.
1008 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
)))
1009 ;; Call our caller again, but this time it does the default thing.
1010 (if (revert-buffer arg noconfirm
)
1011 ;; If the user said "yes", and we changed something,
1012 ;; reparse the messages.
1015 ;; Convert all or part to Babyl file if possible.
1016 (rmail-convert-file)
1017 ;; We have read the file as raw-text, so the buffer is set to
1018 ;; unibyte. Make it multibyte if necessary.
1019 (if (and rmail-enable-multibyte
1020 (not enable-multibyte-characters
))
1021 (set-buffer-multibyte t
))
1022 (goto-char (point-max))
1023 (rmail-set-message-counters)
1024 (rmail-show-message rmail-total-messages
)
1025 (run-hooks 'rmail-mode-hook
)))))
1027 ;; Return a list of files from this buffer's Mail: option.
1028 ;; Does not assume that messages have been parsed.
1029 ;; Just returns nil if buffer does not look like Babyl format.
1030 (defun rmail-parse-file-inboxes ()
1035 (cond ((looking-at "BABYL OPTIONS:")
1036 (search-forward "\n\^_" nil
'move
)
1037 (narrow-to-region 1 (point))
1039 (if (search-forward "\nMail:" nil t
)
1041 (narrow-to-region (point) (progn (end-of-line) (point)))
1042 (goto-char (point-min))
1043 (mail-parse-comma-list))))))))
1045 (defun rmail-expunge-and-save ()
1046 "Expunge and save RMAIL file."
1050 (if (rmail-summary-exists)
1051 (rmail-select-summary (set-buffer-modified-p nil
))))
1053 (defun rmail-quit ()
1055 Hook `rmail-quit-hook' is run after expunging."
1057 (rmail-expunge-and-save)
1058 (when (boundp 'rmail-quit-hook
)
1059 (run-hooks 'rmail-quit-hook
))
1060 ;; Don't switch to the summary buffer even if it was recently visible.
1061 (when rmail-summary-buffer
1062 (replace-buffer-in-windows rmail-summary-buffer
)
1063 (bury-buffer rmail-summary-buffer
))
1064 (let ((obuf (current-buffer)))
1066 (replace-buffer-in-windows obuf
)))
1068 (defun rmail-bury ()
1069 "Bury current Rmail buffer and its summary buffer."
1071 ;; This let var was called rmail-buffer, but that interfered
1072 ;; with the buffer-local var used in summary buffers.
1073 (let ((buffer-to-bury (current-buffer)))
1074 (if (rmail-summary-exists)
1076 (while (setq window
(get-buffer-window rmail-summary-buffer
))
1077 (quit-window nil window
))
1078 (bury-buffer rmail-summary-buffer
)))
1081 (defun rmail-duplicate-message ()
1082 "Create a duplicated copy of the current message.
1083 The duplicate copy goes into the Rmail file just after the
1087 (let ((buffer-read-only nil
)
1088 (number rmail-current-message
)
1089 (string (buffer-substring (rmail-msgbeg rmail-current-message
)
1090 (rmail-msgend rmail-current-message
))))
1091 (goto-char (rmail-msgend rmail-current-message
))
1093 (rmail-forget-messages)
1094 (rmail-show-message number
)
1095 (message "Message duplicated")))
1098 (defun rmail-input (filename)
1099 "Run Rmail on file FILENAME."
1100 (interactive "FRun rmail on RMAIL file: ")
1104 ;; This used to scan subdirectories recursively, but someone pointed out
1105 ;; that if the user wants that, person can put all the files in one dir.
1106 ;; And the recursive scan was slow. So I took it out.
1108 (defun rmail-find-all-files (start)
1109 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1110 (if (file-accessible-directory-p start
)
1112 (let* ((case-fold-search t
)
1113 (files (directory-files start t rmail-secondary-file-regexp
)))
1114 ;; Sort here instead of in directory-files
1115 ;; because this list is usually much shorter.
1116 (sort files
'string
<))))
1118 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
1119 (let ((menu (make-sparse-keymap menu-name
)))
1121 (function (lambda (item)
1126 (rmail-list-to-menu (car item
) (cdr item
)
1129 (concat full-name
"/"
1132 (setq name
(car item
)))
1136 (list 'lambda
() '(interactive)
1140 (concat full-name
"/" item
)
1142 rmail-secondary-file-directory
))))))
1143 (define-key menu
(vector (intern name
))
1144 (cons name command
)))))
1148 ;; This command is always "disabled" when it appears in a menu.
1149 (put 'rmail-disable-menu
'menu-enable
''nil
)
1151 (defun rmail-construct-io-menu ()
1152 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1155 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1156 (cons "Input Rmail File"
1157 (rmail-list-to-menu "Input Rmail File"
1160 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1161 (cons "Output Rmail File"
1162 (rmail-list-to-menu "Output Rmail File"
1164 'rmail-output-to-rmail-file
))))
1166 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1167 '("Input Rmail File" . rmail-disable-menu
))
1168 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1169 '("Output Rmail File" . rmail-disable-menu
)))))
1172 ;;;; *** Rmail input ***
1174 ;; RLK feature not added in this version:
1175 ;; argument specifies inbox file or files in various ways.
1177 (defun rmail-get-new-mail (&optional file-name
)
1178 "Move any new mail from this RMAIL file's inbox files.
1179 The inbox files can be specified with the file's Mail: option. The
1180 variable `rmail-primary-inbox-list' specifies the inboxes for your
1181 primary RMAIL file if it has no Mail: option. By default, this is
1182 your /usr/spool/mail/$USER.
1184 You can also specify the file to get new mail from. In this case, the
1185 file of new mail is not changed or deleted. Noninteractively, you can
1186 pass the inbox file name as an argument. Interactively, a prefix
1187 argument causes us to read a file name and use that file as the inbox.
1189 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1190 always be left in inbox files rather than deleted.
1192 This function runs `rmail-get-new-mail-hook' before saving the updated file.
1193 It returns t if it got any new messages."
1195 (list (if current-prefix-arg
1196 (read-file-name "Get new mail from file: "))))
1197 (run-hooks 'rmail-before-get-new-mail-hook
)
1198 ;; If the disk file has been changed from under us,
1199 ;; revert to it before we get new mail.
1200 (or (verify-visited-file-modtime (current-buffer))
1201 (find-file (buffer-file-name)))
1202 (rmail-maybe-set-message-counters)
1204 ;; Get rid of all undo records for this buffer.
1205 (or (eq buffer-undo-list t
)
1206 (setq buffer-undo-list nil
))
1207 (let ((all-files (if file-name
(list file-name
)
1209 (rmail-enable-multibyte (default-value 'enable-multibyte-characters
))
1214 (let ((opoint (point))
1217 ;; If buffer has not changed yet, and has not been saved yet,
1218 ;; don't replace the old backup file now.
1219 (make-backup-files (and make-backup-files
(buffer-modified-p)))
1220 (buffer-read-only nil
)
1221 ;; Don't make undo records for what we do in getting mail.
1222 (buffer-undo-list t
)
1224 ;; Files to insert this time around.
1226 ;; Last names of those files.
1228 ;; Pull files off all-files onto files
1229 ;; as long as there is no name conflict.
1230 ;; A conflict happens when two inbox file names
1231 ;; have the same last component.
1232 (while (and all-files
1233 (not (member (file-name-nondirectory (car all-files
))
1235 (setq files
(cons (car all-files
) files
)
1237 (cons (file-name-nondirectory (car all-files
)) files
))
1238 (setq all-files
(cdr all-files
)))
1239 ;; Put them back in their original order.
1240 (setq files
(nreverse files
))
1242 (goto-char (point-max))
1243 (skip-chars-backward " \t\n") ; just in case of brain damage
1244 (delete-region (point) (point-max)) ; caused by require-final-newline
1247 (narrow-to-region (point) (point))
1248 ;; Read in the contents of the inbox files,
1249 ;; renaming them as necessary,
1250 ;; and adding to the list of files to delete eventually.
1252 (rmail-insert-inbox-text files nil
)
1253 (setq delete-files
(rmail-insert-inbox-text files t
)))
1254 ;; Scan the new text and convert each message to babyl format.
1255 (goto-char (point-min))
1258 (setq new-messages
(rmail-convert-to-babyl-format)
1260 ;; Try to delete the garbage just inserted.
1261 (or success
(delete-region (point-min) (point-max)))
1262 ;; If we could not convert the file's inboxes,
1263 ;; rename the files we tried to read
1264 ;; so we won't over and over again.
1265 (if (and (not file-name
) (not success
))
1266 (let ((delfiles delete-files
)
1269 (while (file-exists-p (format "RMAILOSE.%d" count
))
1270 (setq count
(1+ count
)))
1271 (rename-file (car delfiles
)
1272 (format "RMAILOSE.%d" count
))
1273 (setq delfiles
(cdr delfiles
))))))
1274 (or (zerop new-messages
)
1277 (search-backward "\n\^_" nil t
)
1278 (narrow-to-region (point) (point-max))
1279 (goto-char (1+ (point-min)))
1280 (rmail-count-new-messages)
1281 (run-hooks 'rmail-get-new-mail-hook
)
1283 ;; Delete the old files, now that babyl file is saved.
1286 ;; First, try deleting.
1288 (delete-file (car delete-files
))
1290 ;; If we can't delete it, truncate it.
1291 (write-region (point) (point) (car delete-files
))))
1293 (setq delete-files
(cdr delete-files
)))))
1294 (if (= new-messages
0)
1295 (progn (goto-char opoint
)
1296 (if (or file-name rmail-inbox-list
)
1297 (message "(No new mail has arrived)")))
1298 (if (rmail-summary-exists)
1299 (rmail-select-summary
1300 (rmail-update-summary)))
1301 (message "%d new message%s read"
1302 new-messages
(if (= 1 new-messages
) "" "s"))
1303 ;; Move to the first new message
1304 ;; unless we have other unseen messages before it.
1305 (rmail-show-message (rmail-first-unseen-message))
1306 (run-hooks 'rmail-after-get-new-mail-hook
)
1309 ;; Don't leave the buffer screwed up if we get a disk-full error.
1310 (or found
(rmail-show-message)))))
1312 (defun rmail-insert-inbox-text (files renamep
)
1313 ;; Detect a locked file now, so that we avoid moving mail
1314 ;; out of the real inbox file. (That could scare people.)
1315 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1316 (error "RMAIL file %s is locked"
1317 (file-name-nondirectory buffer-file-name
)))
1318 (let (file tofile delete-files movemail popmail got-password password
)
1320 ;; Handle POP mailbox names specially; don't expand as filenames
1321 ;; in case the userid contains a directory separator.
1322 (setq file
(car files
))
1323 (setq popmail
(string-match "^po:" file
))
1326 (setq file
(file-truename
1327 (expand-file-name (substitute-in-file-name file
)))))
1328 (setq tofile
(expand-file-name
1329 ;; Generate name to move to from inbox name,
1330 ;; in case of multiple inboxes that need moving.
1331 (concat ".newmail-" (file-name-nondirectory file
))
1332 ;; Use the directory of this rmail file
1333 ;; because it's a nuisance to use the homedir
1334 ;; if that is on a full disk and this rmail
1336 (file-name-directory
1337 (expand-file-name buffer-file-name
))))
1338 ;; Always use movemail to rename the file,
1339 ;; since there can be mailboxes in various directories.
1341 ;;; ;; If getting from mail spool directory,
1342 ;;; ;; use movemail to move rather than just renaming,
1343 ;;; ;; so as to interlock with the mailer.
1344 ;;; (setq movemail (string= file
1346 ;;; (concat rmail-spool-directory
1347 ;;; (file-name-nondirectory file)))))
1348 (if (and movemail
(not popmail
))
1350 ;; On some systems, /usr/spool/mail/foo is a directory
1351 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1352 (if (file-directory-p file
)
1353 (setq file
(expand-file-name (user-login-name)
1356 (if rmail-pop-password-required
1357 (progn (setq got-password
(not (rmail-have-password)))
1358 (setq password
(rmail-get-pop-password))))
1359 (if (eq system-type
'windows-nt
)
1360 ;; cannot have "po:" in file name
1363 (concat ".newmail-pop-"
1364 (file-name-nondirectory (substring file
3)))
1365 (file-name-directory
1366 (expand-file-name buffer-file-name
)))))
1367 (message "Getting mail from post office ..."))
1368 ((and (file-exists-p tofile
)
1369 (/= 0 (nth 7 (file-attributes tofile
))))
1370 (message "Getting mail from %s..." tofile
))
1371 ((and (file-exists-p file
)
1372 (/= 0 (nth 7 (file-attributes file
))))
1373 (message "Getting mail from %s..." file
)))
1374 ;; Set TOFILE if have not already done so, and
1375 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1376 (cond ((not renamep
)
1378 ((or (file-exists-p tofile
) (and (not popmail
)
1379 (not (file-exists-p file
))))
1381 ((and (not movemail
) (not popmail
))
1382 ;; Try copying. If that fails (perhaps no space) and
1383 ;; we're allowed to blow away the inbox, rename instead.
1384 (if rmail-preserve-inbox
1385 (copy-file file tofile nil
)
1387 (copy-file file tofile nil
)
1389 ;; Third arg is t so we can replace existing file TOFILE.
1390 (rename-file file tofile t
))))
1391 ;; Make the real inbox file empty.
1392 ;; Leaving it deleted could cause lossage
1393 ;; because mailers often won't create the file.
1394 (if (not rmail-preserve-inbox
)
1396 (write-region (point) (point) file
)
1402 (setq errors
(generate-new-buffer " *rmail loss*"))
1403 (buffer-disable-undo errors
)
1406 (list (or rmail-movemail-program
1407 (expand-file-name "movemail"
1410 (if rmail-preserve-inbox
1413 rmail-movemail-flags
1415 (if password
(list password
) nil
))))
1416 (apply 'call-process args
))
1417 (if (not (buffer-modified-p errors
))
1418 ;; No output => movemail won
1421 (subst-char-in-region (point-min) (point-max)
1423 (goto-char (point-max))
1424 (skip-chars-backward " \t")
1425 (delete-region (point) (point-max))
1426 (goto-char (point-min))
1427 (if (looking-at "movemail: ")
1428 (delete-region (point-min) (match-end 0)))
1430 (message "movemail: %s"
1431 (buffer-substring (point-min)
1433 ;; If we just read the password, most likely it is
1434 ;; wrong. Otherwise, see if there is a specific
1435 ;; reason to think that the problem is a wrong passwd.
1436 (if (or got-password
1437 (re-search-forward rmail-pop-password-error
1439 (rmail-set-pop-password nil
))
1442 (if errors
(kill-buffer errors
))))))
1443 ;; At this point, TOFILE contains the name to read:
1444 ;; Either the alternate name (if we renamed)
1445 ;; or the actual inbox (if not renaming).
1446 (if (file-exists-p tofile
)
1447 (let ((coding-system-for-read 'no-conversion
)
1449 (goto-char (point-max))
1450 (setq size
(nth 1 (insert-file-contents tofile
)))
1451 (goto-char (point-max))
1452 (or (= (preceding-char) ?
\n)
1455 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
1456 (setq delete-files
(cons tofile delete-files
)))))
1458 (setq files
(cdr files
)))
1461 ;; Decode the region specified by FROM and TO by CODING.
1462 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
1463 (defun rmail-decode-region (from to coding
)
1464 (if (or (not coding
) (not (coding-system-p coding
)))
1465 (setq coding
'undecided
))
1466 (decode-coding-region from to coding
))
1468 ;; the rmail-break-forwarded-messages feature is not implemented
1469 (defun rmail-convert-to-babyl-format ()
1470 (let ((count 0) start
1471 (case-fold-search nil
)
1472 (invalid-input-resync
1473 (function (lambda ()
1474 (message "Invalid Babyl format in inbox!")
1476 ;; Try to get back in sync with a real message.
1477 (if (re-search-forward
1478 (concat rmail-mmdf-delim1
"\\|^From") nil t
)
1480 (goto-char (point-max)))))))
1481 (goto-char (point-min))
1484 (setq start
(point))
1485 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1486 (if (search-forward "\n\^_" nil t
)
1487 ;; If we find the proper terminator, delete through there.
1488 (delete-region (point-min) (point))
1489 (funcall invalid-input-resync
)
1490 (delete-region (point-min) (point))))
1491 ;; Babyl format message
1493 (or (search-forward "\n\^_" nil t
)
1494 (funcall invalid-input-resync
))
1495 (setq count
(1+ count
))
1496 ;; Make sure there is no extra white space after the ^_
1497 ;; at the end of the message.
1498 ;; Narrowing will make sure that whatever follows the junk
1499 ;; will be treated properly.
1500 (delete-region (point)
1502 (skip-chars-forward " \t\n")
1504 (setq last-coding-system-used nil
)
1505 (or rmail-enable-mime
1506 (not rmail-enable-multibyte
)
1507 (decode-coding-region start
(point)
1508 (or rmail-file-coding-system
1510 ;; Add an X-Coding-System: header if we don't have one.
1514 (if (looking-at "0")
1517 (or (save-restriction
1518 (narrow-to-region (point) (point-max))
1520 (goto-char (point-min))
1521 (re-search-forward "^X-Coding-System:" nil t
))
1522 (insert "X-Coding-System: "
1523 (symbol-name last-coding-system-used
)
1525 (narrow-to-region (point) (point-max)))
1527 ((let ((case-fold-search t
))
1528 (looking-at rmail-mmdf-delim1
))
1529 (let ((case-fold-search t
))
1530 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1531 (re-search-forward rmail-mmdf-delim2 nil t
)
1532 (replace-match "\^_"))
1535 (narrow-to-region start
(1- (point)))
1536 (goto-char (point-min))
1537 (while (search-forward "\n\^_" nil t
); single char "\^_"
1538 (replace-match "\n^_")))); 2 chars: "^" and "_"
1539 (setq last-coding-system-used nil
)
1540 (or rmail-enable-mime
1541 (not rmail-enable-multibyte
)
1542 (decode-coding-region start
(point) 'undecided
))
1546 (insert "X-Coding-System: "
1547 (symbol-name last-coding-system-used
)
1549 (narrow-to-region (point) (point-max))
1550 (setq count
(1+ count
)))
1552 ((looking-at "^From ")
1553 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1554 (rmail-nuke-pinhead-header)
1555 ;; If this message has a Content-Length field,
1556 ;; skip to the end of the contents.
1557 (let* ((header-end (save-excursion
1558 (and (re-search-forward "\n\n" nil t
)
1560 (case-fold-search t
)
1561 (quoted-printable-header-field-end
1564 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
1567 ;; Get the numeric value from the Content-Length field.
1569 ;; Back up to end of prev line,
1570 ;; in case the Content-Length field comes first.
1572 (and (search-forward "\ncontent-length: "
1575 (eol (progn (end-of-line) (point))))
1576 (string-to-int (buffer-substring beg eol
)))))))
1578 (if (and (natnump size
)
1579 (<= (+ header-end size
) (point-max))
1580 ;; Make sure this would put us at a position
1581 ;; that we could continue from.
1583 (goto-char (+ header-end size
))
1584 (skip-chars-forward "\n")
1586 (and (looking-at "BABYL OPTIONS:")
1587 (search-forward "\n\^_" nil t
))
1588 (and (looking-at "\^L")
1589 (search-forward "\n\^_" nil t
))
1590 (let ((case-fold-search t
))
1591 (looking-at rmail-mmdf-delim1
))
1592 (looking-at "From "))))
1593 (goto-char (+ header-end size
))
1594 (message "Ignoring invalid Content-Length field")
1596 (if (re-search-forward
1597 (concat "^[\^_]?\\("
1598 rmail-unix-mail-delimiter
1600 rmail-mmdf-delim1
"\\|"
1601 "^BABYL OPTIONS:\\|"
1602 "\^L\n[01],\\)") nil t
)
1603 (goto-char (match-beginning 1))
1604 (goto-char (point-max)))
1605 (setq count
(1+ count
))
1606 (if quoted-printable-header-field-end
1608 (rmail-decode-quoted-printable header-end
(point))
1609 ;; Change "quoted-printable" to "8bit",
1610 ;; to reflect the decoding we just did.
1611 (goto-char quoted-printable-header-field-end
)
1612 (delete-region (point) (search-backward ":"))
1613 (insert ": 8bit"))))
1617 (narrow-to-region start
(point))
1618 (goto-char (point-min))
1619 (while (search-forward "\n\^_" nil t
); single char
1620 (replace-match "\n^_")))); 2 chars: "^" and "_"
1622 (setq last-coding-system-used nil
)
1623 (or rmail-enable-mime
1624 (not rmail-enable-multibyte
)
1626 (if (and rmail-decode-mime-charset
1629 (search-forward "\n\n" nil t
)
1630 (let ((case-fold-search t
))
1632 rmail-mime-charset-pattern
1634 (intern (downcase (match-string 1))))))
1635 (rmail-decode-region start
(point) mime-charset
)))
1639 (insert "X-Coding-System: "
1640 (symbol-name last-coding-system-used
)
1642 (narrow-to-region (point) (point-max)))
1644 ;; This kludge is because some versions of sendmail.el
1645 ;; insert an extra newline at the beginning that shouldn't
1646 ;; be there. sendmail.el has been fixed, but old versions
1647 ;; may still be in use. -- rms, 7 May 1993.
1648 ((eolp) (delete-char 1))
1649 (t (error "Cannot convert to babyl format")))))
1652 (defun rmail-hex-char-to-integer (character)
1653 "Return CHARACTER's value interpreted as a hex digit."
1654 (if (and (>= character ?
0) (<= character ?
9))
1656 (let ((ch (logior character
32)))
1657 (if (and (>= ch ?a
) (<= ch ?f
))
1659 (error "Invalid hex digit `%c'" ch
)))))
1661 (defun rmail-hex-string-to-integer (hex-string)
1662 "Return decimal integer for HEX-STRING."
1665 (while (< index
(length hex-string
))
1666 (setq hex-num
(+ (* hex-num
16)
1667 (rmail-hex-char-to-integer (aref hex-string index
))))
1668 (setq index
(1+ index
)))
1671 (defun rmail-decode-quoted-printable (from to
)
1672 "Decode Quoted-Printable in the region between FROM and TO."
1676 (setq to
(copy-marker to
)))
1677 (while (search-forward "=" to t
)
1678 (cond ((eq (following-char) ?
\n)
1681 ((looking-at "[0-9A-F][0-9A-F]")
1682 (subst-char-in-region
1683 (1- (point)) (point) ?
=
1684 (rmail-hex-string-to-integer
1685 (buffer-substring (point) (+ 2 (point)))))
1690 (message "Malformed MIME quoted-printable message")))))
1692 ;; Delete the "From ..." line, creating various other headers with
1693 ;; information from it if they don't already exist. Now puts the
1694 ;; original line into a mail-from: header line for debugging and for
1695 ;; use by the rmail-output function.
1696 (defun rmail-nuke-pinhead-header ()
1699 (let ((start (point))
1702 (search-forward "\n\n")
1704 (goto-char (point-max))
1708 (narrow-to-region start end
)
1709 (let ((case-fold-search t
))
1711 (setq has-from
(search-forward "\nFrom:" nil t
))
1713 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
1715 (let ((case-fold-search nil
))
1716 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
1720 ;; Keep and reformat the date if we don't
1721 ;; have a Date: field.
1725 "Date: \\2, \\4 \\3 \\9 \\5 "
1727 ;; The timezone could be matched by group 7 or group 10.
1728 ;; If neither of them matched, assume EST, since only
1729 ;; Easterners would be so sloppy.
1730 ;; It's a shame the substitution can't use "\\10".
1732 ((/= (match-beginning 7) (match-end 7)) "\\7")
1733 ((/= (match-beginning 10) (match-end 10))
1734 (buffer-substring (match-beginning 10)
1738 ;; Keep and reformat the sender if we don't
1739 ;; have a From: field.
1745 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1747 (defun rmail-reformat-message (beg end
)
1750 (if (/= (following-char) ?
0)
1751 (error "Bad format in RMAIL file."))
1752 (let ((buffer-read-only nil
)
1753 (delta (- (buffer-size) end
)))
1757 (let ((case-fold-search t
))
1758 (while (looking-at "Summary-line:\\|Mail-From:")
1760 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1761 (delete-region (point)
1762 (progn (forward-line 1) (point))))
1763 (let ((str (buffer-substring (point)
1764 (save-excursion (search-forward "\n\n" end
'move
)
1766 (insert str
"*** EOOH ***\n")
1767 (narrow-to-region (point) (- (buffer-size) delta
)))
1768 (goto-char (point-min))
1769 (if rmail-message-filter
(funcall rmail-message-filter
))
1770 (if (or rmail-displayed-headers rmail-ignored-headers
)
1771 (rmail-clear-headers))))
1773 (defun rmail-clear-headers (&optional ignored-headers
)
1774 "Delete all header fields that Rmail should not show.
1775 If the optional argument IGNORED-HEADERS is non-nil,
1776 delete all header fields whose names match that regexp.
1777 Otherwise, if `rmail-displayed-headers' is non-nil,
1778 delete all header fields *except* those whose names match that regexp.
1779 Otherwise, delete all header fields whose names match `rmail-ignored-headers'."
1780 (when (search-forward "\n\n" nil t
)
1782 (let ((case-fold-search t
)
1783 (buffer-read-only nil
))
1784 (if (and rmail-displayed-headers
(null ignored-headers
))
1786 (narrow-to-region (point-min) (point))
1788 (goto-char (point-min))
1789 (while (and (not (eobp))
1791 (if (re-search-forward "\n[^ \t]" nil t
)
1792 (setq lim
(match-beginning 0)
1794 (setq lim nil next
(point-max)))))
1796 (re-search-forward rmail-displayed-headers lim t
))
1798 (delete-region (point) next
))))
1799 (goto-char (point-min)))
1800 (or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
1802 (narrow-to-region (point-min) (point))
1804 (goto-char (point-min))
1805 (re-search-forward ignored-headers nil t
))
1807 (delete-region (point)
1808 (if (re-search-forward "\n[^ \t]" nil t
)
1812 (defun rmail-msg-is-pruned ()
1813 (rmail-maybe-set-message-counters)
1815 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
1817 (goto-char (point-min))
1819 (= (following-char) ?
1))))
1821 (defun rmail-toggle-header (&optional arg
)
1822 "Show original message header if pruned header currently shown, or vice versa.
1823 With argument ARG, show the message header pruned if ARG is greater than zero;
1824 otherwise, show it in full."
1826 (let* ((buffer-read-only nil
)
1827 (pruned (rmail-msg-is-pruned))
1829 (> (prefix-numeric-value arg
) 0)
1831 (if (eq pruned prune
)
1833 (rmail-maybe-set-message-counters)
1834 (let ((at-point-min (= (point) (point-min)))
1835 (all-headers-visible (= (window-start) (point-min)))
1836 (on-header (save-excursion
1837 (and (not (search-backward "\n\n" nil t
))
1840 (re-search-backward "^[-A-Za-z0-9]+:" nil t
))
1842 (old-screen-line (rmail-count-screen-lines (window-start) (point))))
1844 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
1847 (goto-char (point-min))
1852 ;; Insert new EOOH line at the proper place.
1854 (let ((case-fold-search t
))
1855 (while (looking-at "Summary-Line:\\|Mail-From:")
1857 (insert "*** EOOH ***\n")
1858 (setq new-start
(point))
1859 ;; Delete the old reformatted header.
1861 (search-forward "\n*** EOOH ***\n")
1863 (let ((start (point)))
1864 (search-forward "\n\n")
1865 (delete-region start
(point)))
1866 ;; Narrow to after the new EOOH line.
1867 (narrow-to-region new-start
(point-max)))
1868 (rmail-reformat-message (point-min) (point-max))))
1870 (goto-char (point-min)))
1872 (goto-char (point-min))
1873 (search-forward "\n\n")
1874 (or (re-search-backward (concat "^" (regexp-quote on-header
)) nil t
)
1875 (goto-char (point-min))))
1877 (recenter old-screen-line
)
1878 (if (and all-headers-visible
1879 (not (= (window-start) (point-min))))
1880 (let ((lines-offscreen (rmail-count-screen-lines
1881 (point-min) (window-start))))
1882 (recenter (min (+ old-screen-line lines-offscreen
)
1883 ;; last line of window
1884 (- (window-height) 2))))))))
1885 (rmail-highlight-headers))))
1887 ;; Lifted from repos-count-screen-lines.
1888 ;; Return number of screen lines between START and END.
1889 (defun rmail-count-screen-lines (start end
)
1892 (narrow-to-region start end
)
1893 (goto-char (point-min))
1894 (vertical-motion (- (point-max) (point-min))))))
1896 ;;;; *** Rmail Attributes and Keywords ***
1898 ;; Make a string describing current message's attributes and keywords
1899 ;; and set it up as the name of a minor mode
1900 ;; so it will appear in the mode line.
1901 (defun rmail-display-labels ()
1902 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1907 (goto-char (rmail-msgbeg rmail-current-message
))
1909 (if (looking-at "[01],")
1911 (narrow-to-region (point) (progn (end-of-line) (point)))
1912 ;; Truly valid BABYL format requires a space before each
1913 ;; attribute or keyword name. Put them in if missing.
1914 (let (buffer-read-only)
1915 (goto-char (point-min))
1916 (while (search-forward "," nil t
)
1917 (or (looking-at "[ ,]") (eobp)
1919 (goto-char (point-max))
1920 (if (search-backward ",," nil
'move
)
1922 (if (> (point) (1+ (point-min)))
1923 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
1924 (if (> (- (point-max) (point)) 2)
1928 (buffer-substring (+ (point) 3)
1929 (1- (point-max)))))))))))
1930 ;; Note: we don't use save-restriction because that does not work right
1931 ;; if changes are made outside the saved restriction
1932 ;; before that restriction is restored.
1933 (narrow-to-region beg end
)
1934 (set-marker beg nil
)
1935 (set-marker end nil
)))
1936 (while (string-match " +," blurb
)
1937 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
1938 (substring blurb
(match-end 0)))))
1939 (while (string-match ", +" blurb
)
1940 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
1941 (substring blurb
(match-end 0)))))
1942 (setq mode-line-process
1944 rmail-current-message rmail-total-messages blurb
))))
1946 ;; Turn an attribute of a message on or off according to STATE.
1947 ;; ATTR is the name of the attribute, as a string.
1948 ;; MSGNUM is message number to change; nil means current message.
1949 (defun rmail-set-attribute (attr state
&optional msgnum
)
1950 (let ((omax (point-max-marker))
1951 (omin (point-min-marker))
1952 (buffer-read-only nil
))
1953 (or msgnum
(setq msgnum rmail-current-message
))
1958 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
1961 (null (search-backward (concat ", " attr
",")
1962 (prog1 (point) (end-of-line)) t
)))))
1963 (or (eq curstate
(not (not state
)))
1965 (delete-region (point) (1- (match-end 0)))
1968 (insert " " attr
","))))
1969 (if (string= attr
"deleted")
1970 (rmail-set-message-deleted-p msgnum state
)))
1971 ;; Note: we don't use save-restriction because that does not work right
1972 ;; if changes are made outside the saved restriction
1973 ;; before that restriction is restored.
1974 (narrow-to-region omin omax
)
1975 (set-marker omin nil
)
1976 (set-marker omax nil
)
1977 (if (= msgnum rmail-current-message
)
1978 (rmail-display-labels))))))
1980 ;; Return t if the attributes/keywords line of msg number MSG
1981 ;; contains a match for the regexp LABELS.
1982 (defun rmail-message-labels-p (msg labels
)
1986 (goto-char (rmail-msgbeg msg
))
1988 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
1990 ;;;; *** Rmail Message Selection And Support ***
1992 (defun rmail-msgend (n)
1993 (marker-position (aref rmail-message-vector
(1+ n
))))
1995 (defun rmail-msgbeg (n)
1996 (marker-position (aref rmail-message-vector n
)))
1998 (defun rmail-widen-to-current-msgbeg (function)
1999 "Call FUNCTION with point at start of internal data of current message.
2000 Assumes that bounds were previously narrowed to display the message in Rmail.
2001 The bounds are widened enough to move point where desired, then narrowed
2004 FUNCTION may not change the visible text of the message, but it may
2005 change the invisible header text."
2007 (let ((obeg (- (point-max) (point-min))))
2010 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2012 (goto-char (point-min))
2014 ;; Note: we don't use save-restriction because that does not work right
2015 ;; if changes are made outside the saved restriction
2016 ;; before that restriction is restored.
2017 ;; Here we assume that changes made by FUNCTION
2018 ;; occur before the visible region of the message.
2019 (narrow-to-region (- (point-max) obeg
) (point-max))))))
2021 (defun rmail-forget-messages ()
2023 (if (vectorp rmail-message-vector
)
2025 (v rmail-message-vector
)
2028 (move-marker (aref v i
) nil
)
2030 (setq rmail-message-vector nil
)
2031 (setq rmail-msgref-vector nil
)
2032 (setq rmail-deleted-vector nil
)))
2034 (defun rmail-maybe-set-message-counters ()
2035 (if (not (and rmail-deleted-vector
2036 rmail-message-vector
2037 rmail-current-message
2038 rmail-total-messages
))
2039 (rmail-set-message-counters)))
2041 (defun rmail-count-new-messages (&optional nomsg
)
2042 (let* ((case-fold-search nil
)
2046 (or nomsg
(message "Counting new messages..."))
2047 (goto-char (point-max))
2048 ;; Put at the end of messages-head
2049 ;; the entry for message N+1, which marks
2050 ;; the end of message N. (N = number of messages).
2051 (search-backward "\n\^_")
2053 (setq messages-head
(list (point-marker)))
2054 (rmail-set-message-counters-counter (point-min))
2055 (setq rmail-current-message
(1+ rmail-total-messages
))
2056 (setq rmail-total-messages
2057 (+ rmail-total-messages total-messages
))
2058 (setq rmail-message-vector
2059 (vconcat rmail-message-vector
(cdr messages-head
)))
2060 (aset rmail-message-vector
2061 rmail-current-message
(car messages-head
))
2062 (setq rmail-deleted-vector
2063 (concat rmail-deleted-vector deleted-head
))
2064 (setq rmail-summary-vector
2065 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
2066 (setq rmail-msgref-vector
2067 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
2068 ;; Fill in the new elements of rmail-msgref-vector.
2069 (let ((i (1+ (- rmail-total-messages total-messages
))))
2070 (while (<= i rmail-total-messages
)
2071 (aset rmail-msgref-vector i
(list i
))
2073 (goto-char (point-min))
2074 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
2076 (defun rmail-set-message-counters ()
2077 (rmail-forget-messages)
2081 (let* ((point-save (point))
2083 (messages-after-point)
2084 (case-fold-search nil
)
2087 (message "Counting messages...")
2088 (goto-char (point-max))
2089 ;; Put at the end of messages-head
2090 ;; the entry for message N+1, which marks
2091 ;; the end of message N. (N = number of messages).
2092 (search-backward "\n\^_" nil t
)
2093 (if (/= (point) (point-max)) (forward-char 1))
2094 (setq messages-head
(list (point-marker)))
2095 (rmail-set-message-counters-counter (min (point) point-save
))
2096 (setq messages-after-point total-messages
)
2097 (rmail-set-message-counters-counter)
2098 (setq rmail-total-messages total-messages
)
2099 (setq rmail-current-message
2101 (max 1 (- total-messages messages-after-point
))))
2102 (setq rmail-message-vector
2103 (apply 'vector
(cons (point-min-marker) messages-head
))
2104 rmail-deleted-vector
(concat "D" deleted-head
)
2105 rmail-summary-vector
(make-vector rmail-total-messages nil
)
2106 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
2108 (while (<= i rmail-total-messages
)
2109 (aset rmail-msgref-vector i
(list i
))
2111 (message "Counting messages...done")))))
2113 (defun rmail-set-message-counters-counter (&optional stop
)
2114 (let ((start (point))
2116 (while (search-backward "\n\^_\^L" stop t
)
2117 ;; Detect messages that have been added with DOS line endings and
2118 ;; convert the line endings for such messages.
2120 (if (looking-at "\n\^_\^L\r\n")
2121 (let ((buffer-read-only nil
)
2123 (message "Counting messages...(converting line endings)")
2126 (while (search-backward "\r\n" next t
)
2130 (setq messages-head
(cons (point-marker) messages-head
))
2133 (cons (if (search-backward ", deleted,"
2139 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
2140 (message "Counting messages...%d" total-messages
)))))
2142 (defun rmail-beginning-of-message ()
2143 "Show current message starting from the beginning."
2145 (rmail-show-message rmail-current-message
))
2147 (defun rmail-show-message (&optional n no-summary
)
2148 "Show message number N (prefix argument), counting from start of file.
2149 If summary buffer is currently displayed, update current message there also."
2151 (or (eq major-mode
'rmail-mode
)
2152 (switch-to-buffer rmail-buffer
))
2153 (rmail-maybe-set-message-counters)
2155 (if (zerop rmail-total-messages
)
2156 (progn (narrow-to-region (point-min) (1- (point-max)))
2157 (goto-char (point-min))
2158 (setq mode-line-process nil
))
2159 (let (blurb coding-system
)
2161 (setq n rmail-current-message
)
2164 rmail-current-message
1
2165 blurb
"No previous message"))
2166 ((> n rmail-total-messages
)
2167 (setq n rmail-total-messages
2168 rmail-current-message rmail-total-messages
2169 blurb
"No following message"))
2171 (setq rmail-current-message n
))))
2172 (let ((beg (rmail-msgbeg n
)))
2176 (let ((end (rmail-msgend n
)))
2178 (if (prog1 (= (following-char) ?
0)
2180 ;; If there's a Summary-line in the (otherwise empty)
2181 ;; header, we didn't yet get past the EOOH line.
2182 (if (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
2184 (narrow-to-region (point) end
))
2186 (search-forward "\n*** EOOH ***\n" end t
))
2187 (narrow-to-region beg
(point))
2188 (goto-char (point-min))
2189 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2190 (let ((coding-system (intern (match-string 1))))
2191 (check-coding-system coding-system
)
2192 (setq buffer-file-coding-system coding-system
))
2193 (setq buffer-file-coding-system nil
)))))
2194 ;; Clear the "unseen" attribute when we show a message.
2195 (rmail-set-attribute "unseen" nil
)
2196 (let ((end (rmail-msgend n
)))
2197 ;; Reformat the header, or else find the reformatted header.
2198 (if (= (following-char) ?
0)
2199 (rmail-reformat-message beg end
)
2200 (search-forward "\n*** EOOH ***\n" end t
)
2201 (narrow-to-region (point) end
)))
2202 (goto-char (point-min))
2203 (rmail-display-labels)
2204 (if (eq rmail-enable-mime t
)
2205 (funcall rmail-show-mime-function
)
2206 (setq rmail-view-buffer rmail-buffer
)
2208 (rmail-highlight-headers)
2209 (if transient-mark-mode
(deactivate-mark))
2210 (run-hooks 'rmail-show-message-hook
)
2211 ;; If there is a summary buffer, try to move to this message
2212 ;; in that buffer. But don't complain if this message
2213 ;; is not mentioned in the summary.
2214 ;; Don't do this at all if we were called on behalf
2215 ;; of cursor motion in the summary buffer.
2216 (and (rmail-summary-exists) (not no-summary
)
2217 (let ((curr-msg rmail-current-message
))
2218 (rmail-select-summary
2219 (rmail-summary-goto-msg curr-msg t t
))))
2221 (message blurb
))))))
2223 ;; Find all occurrences of certain fields, and highlight them.
2224 (defun rmail-highlight-headers ()
2225 ;; Do this only if the system supports faces.
2226 (if (and (fboundp 'internal-find-face
)
2227 rmail-highlighted-headers
)
2229 (search-forward "\n\n" nil
'move
)
2231 (narrow-to-region (point-min) (point))
2232 (let ((case-fold-search t
)
2233 (inhibit-read-only t
)
2234 ;; Highlight with boldface if that is available.
2235 ;; Otherwise use the `highlight' face.
2236 (face (or rmail-highlight-face
2237 (if (face-differs-from-default-p 'bold
)
2239 ;; List of overlays to reuse.
2240 (overlays rmail-overlay-list
))
2241 (goto-char (point-min))
2242 (while (re-search-forward rmail-highlighted-headers nil t
)
2243 (skip-chars-forward " \t")
2246 (while (progn (forward-line 1)
2247 (looking-at "[ \t]")))
2248 ;; Back up over newline, then trailing spaces or tabs
2250 (while (member (preceding-char) '(? ?
\t))
2253 ;; Reuse an overlay we already have.
2255 (setq overlay
(car overlays
)
2256 overlays
(cdr overlays
))
2257 (overlay-put overlay
'face face
)
2258 (move-overlay overlay beg
(point)))
2259 ;; Make a new overlay and add it to
2260 ;; rmail-overlay-list.
2261 (setq overlay
(make-overlay beg
(point)))
2262 (overlay-put overlay
'face face
)
2263 (setq rmail-overlay-list
2264 (cons overlay rmail-overlay-list
))))))))))
2266 (defun rmail-next-message (n)
2267 "Show following message whether deleted or not.
2268 With prefix arg N, moves forward N messages, or backward if N is negative."
2270 (rmail-maybe-set-message-counters)
2271 (rmail-show-message (+ rmail-current-message n
)))
2273 (defun rmail-previous-message (n)
2274 "Show previous message whether deleted or not.
2275 With prefix arg N, moves backward N messages, or forward if N is negative."
2277 (rmail-next-message (- n
)))
2279 (defun rmail-next-undeleted-message (n)
2280 "Show following non-deleted message.
2281 With prefix arg N, moves forward N non-deleted messages,
2282 or backward if N is negative.
2284 Returns t if a new message is being shown, nil otherwise."
2286 (rmail-maybe-set-message-counters)
2287 (let ((lastwin rmail-current-message
)
2288 (current rmail-current-message
))
2289 (while (and (> n
0) (< current rmail-total-messages
))
2290 (setq current
(1+ current
))
2291 (if (not (rmail-message-deleted-p current
))
2292 (setq lastwin current n
(1- n
))))
2293 (while (and (< n
0) (> current
1))
2294 (setq current
(1- current
))
2295 (if (not (rmail-message-deleted-p current
))
2296 (setq lastwin current n
(1+ n
))))
2297 (if (/= lastwin rmail-current-message
)
2298 (progn (rmail-show-message lastwin
)
2301 (message "No previous nondeleted message"))
2303 (message "No following nondeleted message"))
2306 (defun rmail-previous-undeleted-message (n)
2307 "Show previous non-deleted message.
2308 With prefix argument N, moves backward N non-deleted messages,
2309 or forward if N is negative."
2311 (rmail-next-undeleted-message (- n
)))
2313 (defun rmail-first-message ()
2314 "Show first message in file."
2316 (rmail-maybe-set-message-counters)
2317 (rmail-show-message 1))
2319 (defun rmail-last-message ()
2320 "Show last message in file."
2322 (rmail-maybe-set-message-counters)
2323 (rmail-show-message rmail-total-messages
))
2325 (defun rmail-what-message ()
2326 (let ((where (point))
2328 (high rmail-total-messages
)
2329 (mid (/ rmail-total-messages
2)))
2330 (while (> (- high low
) 1)
2331 (if (>= where
(rmail-msgbeg mid
))
2334 (setq mid
(+ low
(/ (- high low
) 2))))
2335 (if (>= where
(rmail-msgbeg high
)) high low
)))
2337 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
2339 (goto-char (rmail-msgbeg msg
))
2340 (search-forward "\n*** EOOH ***\n")
2341 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
2342 (or (string-match recipients
(or (mail-fetch-field "To") ""))
2343 (string-match recipients
(or (mail-fetch-field "From") ""))
2344 (if (not primary-only
)
2345 (string-match recipients
(or (mail-fetch-field "Cc") ""))))))
2347 (defun rmail-message-regexp-p (msg regexp
)
2348 "Return t, if for message number MSG, regexp REGEXP matches in the header."
2350 (goto-char (rmail-msgbeg msg
))
2356 (search-forward "\n*** EOOH ***\n" (point-max))
2357 (when (= beg
(match-beginning 0))
2359 (search-forward "\n\n" (point-max)))
2362 (re-search-forward regexp end t
))))
2364 (defvar rmail-search-last-regexp nil
)
2365 (defun rmail-search (regexp &optional n
)
2366 "Show message containing next match for REGEXP (but not the current msg).
2367 Prefix argument gives repeat count; negative argument means search
2368 backwards (through earlier messages).
2369 Interactively, empty argument means use same regexp used last time."
2371 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
2373 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
2375 (if rmail-search-last-regexp
2376 (setq prompt
(concat prompt
2378 rmail-search-last-regexp
2380 (setq regexp
(read-string prompt
))
2381 (cond ((not (equal regexp
""))
2382 (setq rmail-search-last-regexp regexp
))
2383 ((not rmail-search-last-regexp
)
2384 (error "No previous Rmail search string")))
2385 (list rmail-search-last-regexp
2386 (prefix-numeric-value current-prefix-arg
))))
2388 (message "%sRmail search for %s..."
2389 (if (< n
0) "Reverse " "")
2391 (rmail-maybe-set-message-counters)
2392 (let ((omin (point-min))
2397 (msg rmail-current-message
))
2402 ;; Check messages one by one, advancing message number up or down
2403 ;; but searching forward through each message.
2405 (while (and (null win
) (> msg
1))
2406 (goto-char (rmail-msgbeg (setq msg
(1- msg
))))
2407 (setq win
(re-search-forward
2408 regexp
(rmail-msgend msg
) t
)))
2409 (while (and (null win
) (< msg rmail-total-messages
))
2410 (goto-char (rmail-msgbeg (setq msg
(1+ msg
))))
2411 (setq win
(re-search-forward regexp
(rmail-msgend msg
) t
))))
2412 (setq n
(+ n
(if reversep
1 -
1)))))
2415 ;; If this is a reverse search and we found a message,
2416 ;; search backward thru this message to position point.
2419 (goto-char (rmail-msgend msg
))
2421 regexp
(rmail-msgbeg msg
) t
)))
2422 (setq win
(point-marker))
2423 (rmail-show-message msg
)
2424 (message "%sRmail search for %s...done"
2425 (if reversep
"Reverse " "")
2429 (narrow-to-region omin omax
)
2431 (message "Search failed: %s" regexp
)))))
2433 (defun rmail-search-backwards (regexp &optional n
)
2434 "Show message containing previous match for REGEXP.
2435 Prefix argument gives repeat count; negative argument means search
2436 forward (through later messages).
2437 Interactively, empty argument means use same regexp used last time."
2439 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
2441 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
2443 (if rmail-search-last-regexp
2444 (setq prompt
(concat prompt
2446 rmail-search-last-regexp
2448 (setq regexp
(read-string prompt
))
2449 (cond ((not (equal regexp
""))
2450 (setq rmail-search-last-regexp regexp
))
2451 ((not rmail-search-last-regexp
)
2452 (error "No previous Rmail search string")))
2453 (list rmail-search-last-regexp
2454 (prefix-numeric-value current-prefix-arg
))))
2455 (rmail-search regexp
(- (or n
1))))
2457 ;; Show the first message which has the `unseen' attribute.
2458 (defun rmail-first-unseen-message ()
2459 (rmail-maybe-set-message-counters)
2464 (while (and (not found
) (<= current rmail-total-messages
))
2465 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
2466 (setq found current
))
2467 (setq current
(1+ current
))))
2468 ;; Let the caller show the message.
2470 ;; (rmail-show-message found))
2473 (defun rmail-next-same-subject (n)
2474 "Go to the next mail message having the same subject header.
2475 With prefix argument N, do this N times.
2476 If N is negative, go backwards instead."
2478 (let ((subject (mail-fetch-field "Subject"))
2480 (i rmail-current-message
)
2481 (case-fold-search t
)
2482 search-regexp found
)
2483 (if (string-match "\\`[ \t]+" subject
)
2484 (setq subject
(substring subject
(match-end 0))))
2485 (if (string-match "Re:[ \t]*" subject
)
2486 (setq subject
(substring subject
(match-end 0))))
2487 (if (string-match "[ \t]+\\'" subject
)
2488 (setq subject
(substring subject
0 (match-beginning 0))))
2489 (setq search-regexp
(concat "^Subject: *\\(Re:[ \t]*\\)?"
2490 (regexp-quote subject
)
2495 (while (and (/= n
0)
2497 (< i rmail-total-messages
)
2500 (while (and (not done
)
2502 (< i rmail-total-messages
)
2504 (setq i
(if forward
(1+ i
) (1- i
)))
2505 (goto-char (rmail-msgbeg i
))
2506 (search-forward "\n*** EOOH ***\n")
2507 (let ((beg (point)) end
)
2508 (search-forward "\n\n")
2511 (setq done
(re-search-forward search-regexp end t
))))
2512 (if done
(setq found i
)))
2513 (setq n
(if forward
(1- n
) (1+ n
))))))
2515 (rmail-show-message found
)
2516 (error "No %s message with same subject"
2517 (if forward
"following" "previous")))))
2519 (defun rmail-previous-same-subject (n)
2520 "Go to the previous mail message having the same subject header.
2521 With prefix argument N, do this N times.
2522 If N is negative, go forwards instead."
2524 (rmail-next-same-subject (- n
)))
2526 ;;;; *** Rmail Message Deletion Commands ***
2528 (defun rmail-message-deleted-p (n)
2529 (= (aref rmail-deleted-vector n
) ?D
))
2531 (defun rmail-set-message-deleted-p (n state
)
2532 (aset rmail-deleted-vector n
(if state ?D ?\
)))
2534 (defun rmail-delete-message ()
2535 "Delete this message and stay on it."
2537 (rmail-set-attribute "deleted" t
)
2538 (run-hooks 'rmail-delete-message-hook
))
2540 (defun rmail-undelete-previous-message ()
2541 "Back up to deleted message, select it, and undelete it."
2543 (let ((msg rmail-current-message
))
2544 (while (and (> msg
0)
2545 (not (rmail-message-deleted-p msg
)))
2546 (setq msg
(1- msg
)))
2548 (error "No previous deleted message")
2549 (if (/= msg rmail-current-message
)
2550 (rmail-show-message msg
))
2551 (rmail-set-attribute "deleted" nil
)
2552 (if (rmail-summary-exists)
2554 (set-buffer rmail-summary-buffer
)
2555 (rmail-summary-mark-undeleted msg
)))
2556 (rmail-maybe-display-summary))))
2558 (defun rmail-delete-forward (&optional backward
)
2559 "Delete this message and move to next nondeleted one.
2560 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
2561 With prefix argument, delete and move backward.
2563 Returns t if a new message is displayed after the delete, or nil otherwise."
2565 (rmail-set-attribute "deleted" t
)
2566 (run-hooks 'rmail-delete-message-hook
)
2567 (let ((del-msg rmail-current-message
))
2568 (if (rmail-summary-exists)
2569 (rmail-select-summary
2570 (rmail-summary-mark-deleted del-msg
)))
2571 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
2572 (rmail-maybe-display-summary))))
2574 (defun rmail-delete-backward ()
2575 "Delete this message and move to previous nondeleted one.
2576 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
2578 (rmail-delete-forward t
))
2580 ;; Compute the message number a given message would have after expunging.
2581 ;; The present number of the message is OLDNUM.
2582 ;; DELETEDVEC should be rmail-deleted-vector.
2583 ;; The value is nil for a message that would be deleted.
2584 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
2585 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
2590 (if (/= (aref deletedvec i
) ?D
)
2591 (setq newnum
(1+ newnum
)))
2595 (defun rmail-only-expunge ()
2596 "Actually erase all deleted messages in the file."
2598 (message "Expunging deleted messages...")
2599 ;; Discard all undo records for this buffer.
2600 (or (eq buffer-undo-list t
)
2601 (setq buffer-undo-list nil
))
2602 (rmail-maybe-set-message-counters)
2603 (let* ((omax (- (buffer-size) (point-max)))
2604 (omin (- (buffer-size) (point-min)))
2605 (opoint (if (and (> rmail-current-message
0)
2606 (rmail-message-deleted-p rmail-current-message
))
2608 (- (point) (point-min))))
2609 (messages-head (cons (aref rmail-message-vector
0) nil
))
2610 (messages-tail messages-head
)
2611 ;; Don't make any undo records for the expunging.
2612 (buffer-undo-list t
)
2617 (goto-char (point-min))
2620 (total rmail-total-messages
)
2621 (new-message-number rmail-current-message
)
2623 (new-msgref (list (list 0)))
2624 (rmailbuf (current-buffer))
2625 (buffer-read-only nil
)
2626 (messages rmail-message-vector
)
2627 (deleted rmail-deleted-vector
)
2628 (summary rmail-summary-vector
))
2629 (setq rmail-total-messages nil
2630 rmail-current-message nil
2631 rmail-message-vector nil
2632 rmail-deleted-vector nil
2633 rmail-summary-vector nil
)
2635 (while (<= number total
)
2636 (if (= (aref deleted number
) ?D
)
2639 (marker-position (aref messages number
))
2640 (marker-position (aref messages
(1+ number
))))
2641 (move-marker (aref messages number
) nil
)
2642 (if (> new-message-number counter
)
2643 (setq new-message-number
(1- new-message-number
))))
2644 (setq counter
(1+ counter
))
2646 (setcdr messages-tail
2647 (cons (aref messages number
) nil
)))
2649 (cons (if (= counter number
) (aref summary
(1- number
)))
2652 (cons (aref rmail-msgref-vector number
)
2654 (setcar (car new-msgref
) counter
))
2655 (if (zerop (%
(setq number
(1+ number
)) 20))
2656 (message "Expunging deleted messages...%d" number
)))
2658 (setcdr messages-tail
2659 (cons (aref messages number
) nil
)))
2660 (setq rmail-current-message new-message-number
2661 rmail-total-messages counter
2662 rmail-message-vector
(apply 'vector messages-head
)
2663 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
2664 rmail-summary-vector
(vconcat (nreverse new-summary
))
2665 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
2667 (message "Expunging deleted messages...done")
2669 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
2671 (if (zerop rmail-current-message
) 1 nil
))
2672 (goto-char (+ (point) opoint
)))))
2674 (defun rmail-expunge ()
2675 "Erase deleted messages from Rmail file and summary buffer."
2677 (rmail-only-expunge)
2678 (if (rmail-summary-exists)
2679 (rmail-select-summary
2680 (rmail-update-summary))))
2682 ;;;; *** Rmail Mailing Commands ***
2684 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
2685 replybuffer sendactions same-window others
)
2688 (setq yank-action
(list 'insert-buffer replybuffer
)))
2689 (setq others
(cons (cons "cc" cc
) others
))
2690 (setq others
(cons (cons "in-reply-to" in-reply-to
) others
))
2692 (compose-mail to subject others
2694 yank-action sendactions
)
2695 (if (and window-system rmail-mail-new-frame
)
2697 (compose-mail to subject others
2698 noerase
'switch-to-buffer-other-frame
2699 yank-action sendactions
)
2700 ;; This is not a standard frame parameter;
2701 ;; nothing except sendmail.el looks at it.
2702 (modify-frame-parameters (selected-frame)
2703 '((mail-dedicated-frame . t
))))
2704 (compose-mail to subject others
2705 noerase
'switch-to-buffer-other-window
2706 yank-action sendactions
)))))
2708 (defun rmail-mail ()
2709 "Send mail in another window.
2710 While composing the message, use \\[mail-yank-original] to yank the
2711 original message into it."
2713 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
2715 (defun rmail-continue ()
2716 "Continue composing outgoing message previously being composed."
2718 (rmail-start-mail t
))
2720 (defun rmail-reply (just-sender)
2721 "Reply to the current message.
2722 Normally include CC: to all other recipients of original message;
2723 prefix argument means ignore them. While composing the reply,
2724 use \\[mail-yank-original] to yank the original message into it."
2726 (let (from reply-to cc subject date to message-id references
2727 resent-to resent-cc resent-reply-to
2728 (msgnum rmail-current-message
))
2732 (goto-char (rmail-msgbeg rmail-current-message
))
2734 (if (= (following-char) ?
0)
2736 (progn (forward-line 2)
2738 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
2741 (narrow-to-region (point)
2742 (progn (search-forward "\n*** EOOH ***\n")
2743 (beginning-of-line) (point))))
2744 (setq from
(mail-fetch-field "from")
2745 reply-to
(or (mail-fetch-field "reply-to" nil t
)
2747 cc
(and (not just-sender
)
2748 (mail-fetch-field "cc" nil t
))
2749 subject
(mail-fetch-field "subject")
2750 date
(mail-fetch-field "date")
2751 to
(or (mail-fetch-field "to" nil t
) "")
2752 message-id
(mail-fetch-field "message-id")
2753 references
(mail-fetch-field "references" nil nil t
)
2754 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
2755 resent-cc
(and (not just-sender
)
2756 (mail-fetch-field "resent-cc" nil t
))
2757 resent-to
(or (mail-fetch-field "resent-to" nil t
) "")
2758 ;;; resent-subject (mail-fetch-field "resent-subject")
2759 ;;; resent-date (mail-fetch-field "resent-date")
2760 ;;; resent-message-id (mail-fetch-field "resent-message-id")
2762 ;; Merge the resent-to and resent-cc into the to and cc.
2763 (if (and resent-to
(not (equal resent-to
"")))
2764 (if (not (equal to
""))
2765 (setq to
(concat to
", " resent-to
))
2766 (setq to resent-to
)))
2767 (if (and resent-cc
(not (equal resent-cc
"")))
2768 (if (not (equal cc
""))
2769 (setq cc
(concat cc
", " resent-cc
))
2770 (setq cc resent-cc
)))
2771 ;; Add `Re: ' to subject if not there already.
2772 (and (stringp subject
)
2774 (concat rmail-reply-prefix
2775 (if (let ((case-fold-search t
))
2776 (string-match rmail-reply-regexp subject
))
2777 (substring subject
(match-end 0))
2781 ;; Using mail-strip-quoted-names is undesirable with newer mailers
2782 ;; since they can handle the names unstripped.
2783 ;; I don't know whether there are other mailers that still
2784 ;; need the names to be stripped.
2785 (mail-strip-quoted-names reply-to
)
2787 (rmail-make-in-reply-to-field from date message-id
)
2790 ;; mail-strip-quoted-names is NOT necessary for rmail-dont-reply-to
2792 (let* ((cc-list (rmail-dont-reply-to
2793 (mail-strip-quoted-names
2794 (if (null cc
) to
(concat to
", " cc
))))))
2795 (if (string= cc-list
"") nil cc-list
)))
2797 (list (list 'rmail-mark-message
2799 (aref rmail-msgref-vector msgnum
)
2802 (list (cons "References" (concat (mapconcat 'identity references
" ")
2803 " " message-id
))))))
2805 (defun rmail-mark-message (buffer msgnum-list attribute
)
2806 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
2807 This is use in the send-actions for message buffers.
2808 MSGNUM-LIST is a list of the form (MSGNUM)
2809 which is an element of rmail-msgref-vector."
2812 (if (car msgnum-list
)
2813 (rmail-set-attribute attribute t
(car msgnum-list
)))))
2815 (defun rmail-make-in-reply-to-field (from date message-id
)
2822 (let ((tem (car (rfc822-addresses from
))))
2826 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
2828 (match-beginning 0))
2831 ;; missing From, or Message-ID is sufficiently informative
2833 (concat message-id
" (" tem
")"))
2834 ;; Copy TEM, discarding text properties.
2835 (setq tem
(copy-sequence tem
))
2836 (set-text-properties 0 (length tem
) nil tem
)
2837 (setq tem
(copy-sequence tem
))
2838 ;; Use prin1 to fake RFC822 quoting
2839 (let ((field (prin1-to-string tem
)))
2841 (concat field
"'s message of " date
)
2843 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
2844 (bar "[^][\000-\037()<>@,;:\\\"]+"))
2845 ;; These strings both match all non-ASCII characters.
2846 (or (string-match (concat "\\`[ \t]*\\(" bar
2847 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
2848 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
2850 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
2851 bar
"\\))[ \t]*\\'")
2852 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
2854 (let ((start (match-beginning 1))
2855 (end (match-end 1)))
2856 ;; Trim whitespace which above regexp match allows
2857 (while (and (< start end
)
2858 (memq (aref from start
) '(?
\t ?\
)))
2859 (setq start
(1+ start
)))
2860 (while (and (< start end
)
2861 (memq (aref from
(1- end
)) '(?
\t ?\
)))
2862 (setq end
(1- end
)))
2863 (let ((field (substring from start end
)))
2864 (if date
(setq field
(concat "message from " field
" on " date
)))
2866 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
2867 (concat message-id
" (" field
")")
2870 ;; If we can't kludge it simply, do it correctly
2871 (let ((mail-use-rfc822 t
))
2872 (rmail-make-in-reply-to-field from date message-id
)))))
2874 (defun rmail-forward (resend)
2875 "Forward the current message to another user.
2876 With prefix argument, \"resend\" the message instead of forwarding it;
2877 see the documentation of `rmail-resend'."
2880 (call-interactively 'rmail-resend
)
2881 (let ((forward-buffer (current-buffer))
2882 (msgnum rmail-current-message
)
2883 (subject (concat "["
2884 (let ((from (or (mail-fetch-field "From")
2885 (mail-fetch-field ">From"))))
2887 (concat (mail-strip-quoted-names from
) ": ")
2889 (or (mail-fetch-field "Subject") "")
2891 (if (rmail-start-mail
2892 nil nil subject nil nil nil
2893 (list (list 'rmail-mark-message
2895 (aref rmail-msgref-vector msgnum
)
2897 ;; If only one window, use it for the mail buffer.
2898 ;; Otherwise, use another window for the mail buffer
2899 ;; so that the Rmail buffer remains visible
2900 ;; and sending the mail will get back to it.
2901 (and (not rmail-mail-new-frame
) (one-window-p t
)))
2902 ;; The mail buffer is now current.
2904 ;; Insert after header separator--before signature if any.
2905 (goto-char (mail-text-start))
2906 (insert "------- Start of forwarded message -------\n")
2907 ;; Quote lines with `- ' if they start with `-'.
2908 (let ((beg (point)) end
)
2909 (setq end
(point-marker))
2910 (set-marker-insertion-type end t
)
2911 (insert-buffer-substring forward-buffer
)
2913 (while (re-search-forward "^-" end t
)
2918 (skip-chars-backward "\n")
2921 (delete-region (point) end
)
2922 (set-marker end nil
))
2923 (insert "------- End of forwarded message -------\n")
2926 (defun rmail-resend (address &optional from comment mail-alias-file
)
2927 "Resend current message to ADDRESSES.
2928 ADDRESSES should be a single address, a string consisting of several
2929 addresses separated by commas, or a list of addresses.
2931 Optional FROM is the address to resend the message from, and
2932 defaults from the value of `user-mail-address'.
2933 Optional COMMENT is a string to insert as a comment in the resent message.
2934 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
2935 typically for purposes of moderating a list."
2936 (interactive "sResend to: ")
2938 (require 'mailalias
)
2939 (unless (eq rmail-buffer
(current-buffer))
2940 (error "Not an Rmail buffer"))
2941 (if (not from
) (setq from user-mail-address
))
2942 (let ((tembuf (generate-new-buffer " sendmail temp"))
2943 (case-fold-search nil
)
2944 (mailbuf rmail-buffer
))
2946 (with-current-buffer tembuf
2947 ;;>> Copy message into temp buffer
2948 (insert-buffer-substring mailbuf
)
2949 (goto-char (point-min))
2950 ;; Delete any Sender field, since that's not specifiable.
2951 ; Only delete Sender fields in the actual header.
2952 (re-search-forward "^$" nil
'move
)
2953 ; Using "while" here rather than "if" because some buggy mail
2954 ; software may have inserted multiple Sender fields.
2955 (while (re-search-backward "^Sender:" nil t
)
2959 (while (looking-at "[ \t]")
2961 (delete-region beg
(point))))
2962 ; Go back to the beginning of the buffer so the Resent- fields
2963 ; are inserted there.
2964 (goto-char (point-min))
2965 ;;>> Insert resent-from:
2966 (insert "Resent-From: " from
"\n")
2967 (insert "Resent-Date: " (mail-rfc822-date) "\n")
2968 ;;>> Insert resent-to: and bcc if need be.
2969 (let ((before (point)))
2971 (insert "Resent-Bcc: " (user-login-name) "\n"))
2972 (insert "Resent-To: " (if (stringp address
)
2974 (mapconcat 'identity address
",\n\t"))
2976 ;; Expand abbrevs in the recipients.
2978 (if (featurep 'mailabbrev
)
2979 (let ((end (point-marker))
2980 (local-abbrev-table mail-abbrevs
)
2981 (old-syntax-table (syntax-table)))
2982 (if (and (not (vectorp mail-abbrevs
))
2983 (file-exists-p mail-personal-alias-file
))
2984 (build-mail-abbrevs))
2985 (set-syntax-table mail-abbrev-syntax-table
)
2987 (while (and (< (point) end
)
2988 (progn (forward-word 1)
2991 (set-syntax-table old-syntax-table
))
2992 (expand-mail-aliases before
(point)))))
2993 ;;>> Set up comment, if any.
2994 (if (and (sequencep comment
) (not (zerop (length comment
))))
2995 (let ((before (point))
2998 (or (eolp) (insert "\n"))
2999 (setq after
(point))
3001 (while (< (point) after
)
3002 (insert "Resent-Comment: ")
3004 ;; Don't expand aliases in the destination fields
3005 ;; of the original message.
3007 (funcall send-mail-function
)))
3008 (kill-buffer tembuf
))
3009 (with-current-buffer rmail-buffer
3010 (rmail-set-attribute "resent" t rmail-current-message
))))
3012 (defvar mail-unsent-separator
3013 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3014 "^ *---+ +Returned message +---+ *$\\|"
3015 "^ *---+ *Returned mail follows *---+ *$\\|"
3016 "^Start of returned message$\\|"
3017 "^---+ Below this line is a copy of the message.$\\|"
3018 "^ *---+ +Original message +---+ *$\\|"
3019 "^ *--+ +begin message +--+ *$\\|"
3020 "^ *---+ +Original message follows +---+ *$\\|"
3021 "^ *---+ +Your message follows +---+ *$\\|"
3022 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3023 "^ *---+ +This is a copy of the message, including all the headers.*---+ *$")
3024 "A regexp that matches the separator before the text of a failed message.")
3026 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
3027 "A regexp that matches the header of a MIME body part with a failed message.")
3029 (defun rmail-retry-failure ()
3030 "Edit a mail message which is based on the contents of the current message.
3031 For a message rejected by the mail system, extract the interesting headers and
3032 the body of the original message.
3033 If the failed message is a MIME multipart message, it is searched for a
3034 body part with a header which matches the variable `mail-mime-unsent-header'.
3035 Otherwise, the variable `mail-unsent-separator' should match the string that
3036 delimits the returned original message.
3037 The variable `rmail-retry-ignored-headers' is a regular expression
3038 specifying headers which should not be copied into the new message."
3040 (require 'mail-utils
)
3041 (let ((rmail-this-buffer (current-buffer))
3042 (msgnum rmail-current-message
)
3043 (pruned (rmail-msg-is-pruned))
3044 bounce-start bounce-end bounce-indent resending
)
3046 ;; Narrow down to just the quoted original message
3047 (rmail-beginning-of-message)
3049 (rmail-toggle-header 0))
3050 (let* ((case-fold-search t
)
3054 ;; Fetch any content-type header in current message
3055 (search-forward "\n\n") (narrow-to-region top
(point))
3056 (mail-fetch-field "Content-Type") )) )
3057 ;; Handle MIME multipart bounce messages
3058 (if (and content-type
3060 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3064 (substring content-type
(match-beginning 1)
3066 (or (re-search-forward mail-mime-unsent-header nil t
)
3067 (error "Cannot find beginning of header in failed message"))
3068 (or (search-forward "\n\n" nil t
)
3069 (error "Cannot find start of Mime data in failed message"))
3070 (setq bounce-start
(point))
3071 (if (search-forward codestring nil t
)
3072 (setq bounce-end
(match-beginning 0))
3073 (setq bounce-end
(point-max)))
3076 (or (re-search-forward mail-unsent-separator nil t
)
3077 (error "Cannot parse this as a failure message"))
3078 (skip-chars-forward "\n")
3079 ;; Support a style of failure message in which the original
3080 ;; message is indented, and included within lines saying
3081 ;; `Start of returned message' and `End of returned message'.
3082 (if (looking-at " +Received:")
3084 (setq bounce-start
(point))
3085 (skip-chars-forward " ")
3086 (setq bounce-indent
(- (current-column)))
3087 (goto-char (point-max))
3088 (re-search-backward "^End of returned message$" nil t
)
3089 (setq bounce-end
(point)))
3090 ;; One message contained a few random lines before the old
3091 ;; message header. The first line of the message started with
3092 ;; two hyphens. A blank line followed these random lines.
3093 ;; The same line beginning with two hyphens was possibly
3094 ;; marking the end of the message.
3095 (if (looking-at "^--")
3096 (let ((boundary (buffer-substring-no-properties
3098 (progn (end-of-line) (point)))))
3099 (search-forward "\n\n")
3100 (skip-chars-forward "\n")
3101 (setq bounce-start
(point))
3102 (goto-char (point-max))
3103 (search-backward (concat "\n\n" boundary
) bounce-start t
)
3104 (setq bounce-end
(point)))
3105 (setq bounce-start
(point)
3106 bounce-end
(point-max)))
3107 (or (search-forward "\n\n" nil t
)
3108 (error "Cannot find end of header in failed message"))
3110 ;; Start sending a new message; default header fields from the original.
3111 ;; Turn off the usual actions for initializing the message body
3112 ;; because we want to get only the text from the failure message.
3113 (let (mail-signature mail-setup-hook
)
3114 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
3115 (list (list 'rmail-mark-message
3117 (aref rmail-msgref-vector msgnum
)
3119 ;; Insert original text as initial text of new draft message.
3120 ;; Bind inhibit-read-only since the header delimiter
3121 ;; of the previous message was probably read-only.
3122 (let ((inhibit-read-only t
))
3124 (insert-buffer-substring rmail-this-buffer bounce-start bounce-end
)
3125 (goto-char (point-min))
3127 (indent-rigidly (point-min) (point-max) bounce-indent
))
3128 (rmail-clear-headers rmail-retry-ignored-headers
)
3129 (rmail-clear-headers "^sender:\\|^from:\\|^return-path:")
3130 (mail-sendmail-delimit-header)
3132 (narrow-to-region (point-min) (mail-header-end))
3133 (setq resending
(mail-fetch-field "resent-to"))
3136 (insert "Resent-Bcc: " (user-login-name) "\n")
3137 (insert "BCC: " (user-login-name) "\n"))))
3138 (goto-char (point-min))
3139 (mail-position-on-field (if resending
"Resent-To" "To") t
)
3140 (set-buffer rmail-this-buffer
)
3141 (rmail-beginning-of-message))))
3143 (rmail-toggle-header))))
3145 (defun rmail-summary-exists ()
3146 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
3147 In fact, the non-nil value returned is the summary buffer itself."
3148 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3149 rmail-summary-buffer
))
3151 (defun rmail-summary-displayed ()
3152 "t iff in RMAIL buffer and an associated summary buffer is displayed."
3153 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
3155 (defcustom rmail-redisplay-summary nil
3156 "*Non-nil means Rmail should show the summary when it changes.
3157 This has an effect only if a summary buffer exists."
3159 :group
'rmail-summary
)
3161 (defcustom rmail-summary-window-size nil
3162 "*Non-nil means specify the height for an Rmail summary window."
3163 :type
'(choice (const :tag
"Disabled" nil
) integer
)
3164 :group
'rmail-summary
)
3166 ;; Put the summary buffer back on the screen, if user wants that.
3167 (defun rmail-maybe-display-summary ()
3168 (let ((selected (selected-window))
3170 ;; If requested, make sure the summary is displayed.
3171 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3172 rmail-redisplay-summary
3173 (if (get-buffer-window rmail-summary-buffer
0)
3174 ;; It's already in some frame; show that one.
3175 (let ((frame (window-frame
3176 (get-buffer-window rmail-summary-buffer
0))))
3177 (make-frame-visible frame
)
3178 (raise-frame frame
))
3179 (display-buffer rmail-summary-buffer
)))
3180 ;; If requested, set the height of the summary window.
3181 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3182 rmail-summary-window-size
3183 (setq window
(get-buffer-window rmail-summary-buffer
))
3184 ;; Don't try to change the size if just one window in frame.
3185 (not (eq window
(frame-root-window (window-frame window
))))
3188 (select-window window
)
3189 (enlarge-window (- rmail-summary-window-size
(window-height))))
3190 (select-window selected
)))))
3192 ;;;; *** Rmail Local Fontification ***
3194 (defun rmail-fontify-buffer-function ()
3195 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
3196 (make-local-hook 'rmail-show-message-hook
)
3197 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
3198 ;; If we're already showing a message, fontify it now.
3199 (if rmail-current-message
(rmail-fontify-message))
3200 ;; Prevent Font Lock mode from kicking in.
3201 (setq font-lock-fontified t
))
3203 (defun rmail-unfontify-buffer-function ()
3204 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
3205 (let ((modified (buffer-modified-p))
3206 (buffer-undo-list t
) (inhibit-read-only t
)
3207 before-change-functions after-change-functions
3208 buffer-file-name buffer-file-truename
)
3211 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
3212 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
3213 (font-lock-default-unfontify-buffer)
3214 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))
3216 (defun rmail-fontify-message ()
3217 ;; Fontify the current message if it is not already fontified.
3218 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
3219 (let ((modified (buffer-modified-p))
3220 (buffer-undo-list t
) (inhibit-read-only t
)
3221 before-change-functions after-change-functions
3222 buffer-file-name buffer-file-truename
)
3225 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
3226 (font-lock-fontify-region (point-min) (point-max))
3227 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))))
3229 ;;; Speedbar support for RMAIL files.
3230 (eval-when-compile (require 'speedbar
))
3232 (defvar rmail-speedbar-match-folder-regexp
"^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
3233 "*This regex us used to match folder names to be displayed in speedbar.
3234 Enabling this will permit speedbar to display your folders for easy
3235 browsing, and moving of messages.")
3237 (defvar rmail-speedbar-last-user nil
3238 "The last user to be displayed in the speedbar.")
3240 (defvar rmail-speedbar-key-map nil
3241 "Keymap used when in rmail display mode.")
3243 (defun rmail-install-speedbar-variables ()
3244 "Install those variables used by speedbar to enhance rmail."
3245 (if rmail-speedbar-key-map
3247 (setq rmail-speedbar-key-map
(speedbar-make-specialized-keymap))
3249 (define-key rmail-speedbar-key-map
"e" 'speedbar-edit-line
)
3250 (define-key rmail-speedbar-key-map
"r" 'speedbar-edit-line
)
3251 (define-key rmail-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
3252 (define-key rmail-speedbar-key-map
"M"
3253 'rmail-speedbar-move-message-to-folder-on-line
)))
3255 (defvar rmail-speedbar-menu-items
3256 '(["Read Folder" speedbar-edit-line t
]
3257 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
3258 (save-excursion (beginning-of-line)
3259 (looking-at "<M> "))])
3260 "Additional menu-items to add to speedbar frame.")
3262 ;; Make sure our special speedbar major mode is loaded
3263 (if (featurep 'speedbar
)
3264 (rmail-install-speedbar-variables)
3265 (add-hook 'speedbar-load-hook
'rmail-install-speedbar-variables
))
3267 (defun rmail-speedbar-buttons (buffer)
3268 "Create buttons for BUFFER containing rmail messages.
3269 Click on the address under Reply to: to reply to this person.
3270 Under Folders: Click a name to read it, or on the <M> to move the
3271 current message into that RMAIL folder."
3275 (goto-char (point-min))
3276 (if (not (re-search-forward "^Reply-To: " nil t
))
3277 (if (not (re-search-forward "^From:? " nil t
))
3281 (setq from
(buffer-substring (point) (save-excursion
3284 (goto-char (point-min))
3285 (if (and (looking-at "Reply to:")
3286 (equal from rmail-speedbar-last-user
))
3288 (setq rmail-speedbar-last-user from
)
3290 (insert "Reply To:\n")
3292 (speedbar-insert-button from
'speedbar-directory-face
'highlight
3293 'rmail-speedbar-button
'rmail-reply
))
3294 (insert "Folders:\n")
3295 (let* ((case-fold-search nil
)
3296 (df (directory-files (save-excursion (set-buffer buffer
)
3298 nil rmail-speedbar-match-folder-regexp
)))
3300 (speedbar-insert-button "<M>" 'speedbar-button-face
'highlight
3301 'rmail-speedbar-move-message
(car df
))
3302 (speedbar-insert-button (car df
) 'speedbar-file-face
'highlight
3303 'rmail-speedbar-find-file nil t
)
3304 (setq df
(cdr df
)))))))
3306 (defun rmail-speedbar-button (text token indent
)
3307 "Execute an rmail command specified by TEXT.
3308 The command used is TOKEN. INDENT is not used."
3309 (speedbar-with-attached-buffer
3312 (defun rmail-speedbar-find-file (text token indent
)
3313 "Load in the rmail file TEXT.
3314 TOKEN and INDENT are not used."
3315 (speedbar-with-attached-buffer
3316 (message "Loading in RMAIL file %s..." text
)
3319 (defun rmail-speedbar-move-message-to-folder-on-line ()
3320 "If the current line is a folder, move current message to it."
3324 (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t
)
3327 (speedbar-do-function-pointer)))))
3329 (defun rmail-speedbar-move-message (text token indent
)
3330 "From button TEXT, copy current message to the rmail file specified by TOKEN.
3331 TEXT and INDENT are not used."
3332 (speedbar-with-attached-buffer
3333 (message "Moving message to %s" token
)
3334 (rmail-output-to-rmail-file token
)))
3336 ; Functions for setting, getting and encoding the POP password.
3337 ; The password is encoded to prevent it from being easily accessible
3338 ; to "prying eyes." Obviously, this encoding isn't "real security,"
3339 ; nor is it meant to be.
3342 (defun rmail-set-pop-password (password)
3343 "Set PASSWORD to be used for retrieving mail from a POP server."
3344 (interactive "sPassword: ")
3346 (setq rmail-encoded-pop-password
3347 (rmail-encode-string password
(emacs-pid)))
3348 (setq rmail-pop-password nil
)
3349 (setq rmail-encoded-pop-password nil
)))
3351 (defun rmail-get-pop-password ()
3352 "Get the password for retrieving mail from a POP server. If none
3353 has been set, then prompt the user for one."
3354 (if (not rmail-encoded-pop-password
)
3355 (progn (if (not rmail-pop-password
)
3356 (setq rmail-pop-password
(read-passwd "POP password: ")))
3357 (rmail-set-pop-password rmail-pop-password
)
3358 (setq rmail-pop-password nil
)))
3359 (rmail-encode-string rmail-encoded-pop-password
(emacs-pid)))
3361 (defun rmail-have-password ()
3362 (or rmail-pop-password rmail-encoded-pop-password
))
3364 (defun rmail-encode-string (string mask
)
3365 "Encode STRING with integer MASK, by taking the exclusive OR of the
3366 lowest byte in the mask with the first character of string, the
3367 second-lowest-byte with the second character of the string, etc.,
3368 restarting at the lowest byte of the mask whenever it runs out.
3369 Returns the encoded string. Calling the function again with an
3370 encoded string (and the same mask) will decode the string."
3371 (setq mask
(abs mask
)) ; doesn't work if negative
3372 (let* ((string-vector (string-to-vector string
)) (i 0)
3373 (len (length string-vector
)) (curmask mask
) charmask
)
3376 (setq curmask mask
))
3377 (setq charmask
(% curmask
256))
3378 (setq curmask
(lsh curmask -
8))
3379 (aset string-vector i
(logxor charmask
(aref string-vector i
)))
3381 (concat string-vector
)))
3385 ;;; rmail.el ends here