1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
3 ;; Copyright (C) 1985,86,87,88,93,94,95,96,97 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
28 ;; New features include attribute and keyword support, message
29 ;; selection by dispatch table, summary by attributes and keywords,
30 ;; expunging by dispatch table, sticky options for file commands.
32 ;; Extended by Bob Weiner of Motorola
33 ;; New features include: rmail and rmail-summary buffers remain
34 ;; synchronized and key bindings basically operate the same way in both
35 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
36 ;; variable, and a bury rmail buffer (wipe) command.
41 ;; For Emacs V18 compatibility
42 (and (not (fboundp 'buffer-disable-undo
))
43 (fboundp 'buffer-flush-undo
)
44 (defalias 'buffer-disable-undo
'buffer-flush-undo
))
46 ; These variables now declared in paths.el.
47 ;(defvar rmail-spool-directory "/usr/spool/mail/"
48 ; "This is the name of the directory used by the system mailer for\n\
49 ;delivering new mail. Its name should end with a slash.")
50 ;(defvar rmail-file-name
51 ; (expand-file-name "~/RMAIL")
55 "Mail reader for Emacs."
58 (defgroup rmail-retrieve nil
59 "Rmail retrieval options."
63 (defgroup rmail-files nil
68 (defgroup rmail-headers nil
69 "Rmail header options."
73 (defgroup rmail-reply nil
74 "Rmail reply options."
78 (defgroup rmail-summary nil
79 "Rmail summary options."
81 :prefix
"rmail-summary-"
84 (defgroup rmail-output nil
85 "Output message to a file."
86 :prefix
"rmail-output-"
91 (defvar rmail-movemail-program nil
92 "If non-nil, name of program for fetching new mail.")
94 (defcustom rmail-pop-password nil
95 "*Password to use when reading mail from a POP server, if required."
96 :type
'(choice (string :tag
"Password")
97 (const :tag
"Not Required" nil
))
98 :group
'rmail-retrieve
)
100 (defcustom rmail-pop-password-required nil
101 "*Non-nil if a password is required when reading mail using POP."
103 :group
'rmail-retrieve
)
105 (defcustom rmail-preserve-inbox nil
106 "*Non-nil if incoming mail should be left in the user's inbox,
107 rather than deleted, after it is retrieved."
109 :group
'rmail-retrieve
)
112 (defcustom rmail-dont-reply-to-names nil
"\
113 *A regexp specifying names to prune of reply to messages.
114 A value of nil means exclude your own name only."
115 :type
'(choice regexp
(const :tag
"Your Name" nil
))
119 (defvar rmail-default-dont-reply-to-names
"info-" "\
120 A regular expression specifying part of the value of the default value of
121 the variable `rmail-dont-reply-to-names', for when the user does not set
122 `rmail-dont-reply-to-names' explicitly. (The other part of the default
123 value is the user's name.)
124 It is useful to set this variable in the site customization file.")
127 (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:"
128 "*Regexp to match header fields that Rmail should normally hide."
130 :group
'rmail-headers
)
133 (defcustom rmail-displayed-headers nil
134 "*Regexp to match Header fields that Rmail should display.
135 If nil, display all header fields except those matched by
136 `rmail-ignored-headers'."
137 :type
'(choice regexp
(const :tag
"All"))
138 :group
'rmail-headers
)
141 (defcustom rmail-retry-ignored-headers nil
"\
142 *Headers that should be stripped when retrying a failed message."
143 :type
'(choice regexp
(const nil
:tag
"None"))
144 :group
'rmail-headers
)
147 (defcustom rmail-highlighted-headers
"^From:\\|^Subject:" "\
148 *Regexp to match Header fields that Rmail should normally highlight.
149 A value of nil means don't highlight.
150 See also `rmail-highlight-face'."
152 :group
'rmail-headers
)
155 (defcustom rmail-highlight-face nil
"\
156 *Face used by Rmail for highlighting headers."
157 :type
'(choice (const :tag
"Default" nil
)
159 :group
'rmail-headers
)
162 (defcustom rmail-delete-after-output nil
"\
163 *Non-nil means automatically delete a message that is copied to a file."
168 (defcustom rmail-primary-inbox-list nil
"\
169 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
170 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
171 \(the name varies depending on the operating system,
172 and the value of the environment variable MAIL overrides it)."
173 ;; Don't use backquote here, because we don't want to need it
175 :type
(list 'choice
'(const :tag
"Default" nil
)
176 (list 'repeat
':value
(or (getenv "MAIL")
177 (concat "/var/spool/mail/"
180 :group
'rmail-retrieve
184 (defcustom rmail-mail-new-frame nil
185 "*Non-nil means Rmail makes a new frame for composing outgoing mail."
190 (defcustom rmail-secondary-file-directory
"~/"
191 "*Directory for additional secondary Rmail files."
195 (defcustom rmail-secondary-file-regexp
"\\.xmail$"
196 "*Regexp for which files are secondary Rmail files."
201 (defvar rmail-mode-hook nil
202 "List of functions to call when Rmail is invoked.")
205 (defvar rmail-get-new-mail-hook nil
206 "List of functions to call when Rmail has retrieved new mail.")
209 (defvar rmail-show-message-hook nil
210 "List of functions to call when Rmail displays a message.")
213 (defvar rmail-delete-message-hook nil
214 "List of functions to call when Rmail deletes a message.
215 When the hooks are called, the message has been marked deleted but is
216 still the current message in the Rmail buffer.")
218 ;; These may be altered by site-init.el to match the format of mmdf files
219 ;; delimiting used on a given host (delim1 and delim2 from the config
222 (defvar rmail-mmdf-delim1
"^\001\001\001\001\n"
223 "Regexp marking the start of an mmdf message")
224 (defvar rmail-mmdf-delim2
"^\001\001\001\001\n"
225 "Regexp marking the end of an mmdf message")
227 (defvar rmail-message-filter nil
228 "If non-nil, a filter function for new messages in RMAIL.
229 Called with region narrowed to the message, including headers,
230 before obeying `rmail-ignored-headers'.")
232 (defvar rmail-reply-prefix
"Re: "
233 "String to prepend to Subject line when replying to a message.")
235 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
236 ;; This pattern should catch all the common variants.
237 (defvar rmail-reply-regexp
"\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
238 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
240 (defvar rmail-display-summary nil
241 "If non-nil, Rmail always displays the summary buffer.")
243 (defvar rmail-mode-map nil
)
245 (defvar rmail-inbox-list nil
)
246 (defvar rmail-keywords nil
)
248 ;; Message counters and markers. Deleted flags.
250 (defvar rmail-current-message nil
)
251 (defvar rmail-total-messages nil
)
252 (defvar rmail-message-vector nil
)
253 (defvar rmail-deleted-vector nil
)
254 (defvar rmail-msgref-vector nil
255 "In an Rmail buffer, a vector whose Nth element is a list (N).
256 When expunging renumbers messages, these lists are modified
257 by substituting the new message number into the existing list.")
259 (defvar rmail-overlay-list nil
)
261 (defvar rmail-font-lock-keywords
263 (let* ((cite-chars "[>|}]")
264 (cite-prefix "A-Za-z")
265 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
266 (list '("^\\(From\\|Sender\\):" . font-lock-function-name-face
)
267 '("^Reply-To:.*$" . font-lock-function-name-face
)
268 '("^Subject:" . font-lock-comment-face
)
269 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
270 . font-lock-keyword-face
)
271 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
273 (,(concat "\\=[ \t]*"
274 "\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
275 "\\(" cite-chars
"[ \t]*\\)\\)+"
277 (beginning-of-line) (end-of-line)
278 (2 font-lock-reference-face nil t
)
279 (4 font-lock-comment-face nil t
)))
280 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\|Date\\):.*$"
281 . font-lock-string-face
))))
282 "Additional expressions to highlight in Rmail mode.")
284 ;; These are used by autoloaded rmail-summary.
286 (defvar rmail-summary-buffer nil
)
287 (defvar rmail-summary-vector nil
)
289 ;; `Sticky' default variables.
291 ;; Last individual label specified to a or k.
292 (defvar rmail-last-label nil
)
293 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
294 (defvar rmail-last-multi-labels nil
)
295 (defvar rmail-last-regexp nil
)
296 (defcustom rmail-default-file
"~/xmail"
297 "*Default file name for \\[rmail-output]."
300 (defcustom rmail-default-rmail-file
"~/XMAIL"
301 "*Default file name for \\[rmail-output-to-rmail-file]."
305 ;;; Regexp matching the delimiter of messages in UNIX mail format
306 ;;; (UNIX From lines), minus the initial ^. Note that if you change
307 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
308 ;;; that knows the exact ordering of the \\( \\) subexpressions.
309 (defvar rmail-unix-mail-delimiter
310 (let ((time-zone-regexp
311 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
312 "\\|[-+]?[0-9][0-9][0-9][0-9]"
318 ;; Many things can happen to an RFC 822 mailbox before it is put into
319 ;; a `From' line. The leading phrase can be stripped, e.g.
320 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
321 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
322 ;; can be removed, e.g.
323 ;; From: joe@y.z (Joe K
325 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
328 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
329 ;; The mailbox can be removed or be replaced by white space, e.g.
330 ;; From: "Joe User"{space}{tab}
332 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
333 ;; where {space} and {tab} represent the Ascii space and tab characters.
334 ;; We want to match the results of any of these manglings.
335 ;; The following regexp rejects names whose first characters are
336 ;; obviously bogus, but after that anything goes.
337 "\\([^\0-\b\n-\r\^?].*\\)? "
339 ;; The time the message was sent.
340 "\\([^\0-\r \^?]+\\) +" ; day of the week
341 "\\([^\0-\r \^?]+\\) +" ; month
342 "\\([0-3]?[0-9]\\) +" ; day of month
343 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
345 ;; Perhaps a time zone, specified by an abbreviation, or by a
350 " \\([0-9][0-9]+\\) *"
352 ;; On some systems the time zone can appear after the year, too.
356 "\\(remote from .*\\)?"
361 ;; Perform BODY in the summary buffer
362 ;; in such a way that its cursor is properly updated in its own window.
363 (defmacro rmail-select-summary
(&rest body
)
364 (` (let ((total rmail-total-messages
))
365 (if (rmail-summary-displayed)
366 (let ((window (selected-window)))
370 (pop-to-buffer rmail-summary-buffer
)
371 ;; rmail-total-messages is a buffer-local var
372 ;; in the rmail buffer.
373 ;; This way we make it available for the body
374 ;; even tho the rmail buffer is not current.
375 (let ((rmail-total-messages total
))
377 (select-window window
))))
379 (set-buffer rmail-summary-buffer
)
380 (let ((rmail-total-messages total
))
382 (rmail-maybe-display-summary))))
384 (defvar rmail-view-buffer nil
385 "Buffer which holds RMAIL message for displaying.")
387 ;; Mule and MIME related variables.
390 (defvar rmail-file-coding-system nil
391 "Coding system used in RMAIL file.
393 This is set to nil by default.")
396 (defcustom rmail-enable-mime nil
397 "*If non-nil, RMAIL uses MIME feature.
398 If the value is t, RMAIL automatically shows MIME decoded message.
399 If the value is neither t nor nil, RMAIL does not show MIME decoded message
400 until a user explicitly require it."
401 :type
'(choice (const :tag
"on" t
)
402 (const :tag
"off" nil
)
403 (sexp :tag
"When Asked" :format
"%t\n" ask
))
407 (defvar rmail-show-mime-function nil
408 "Function to show MIME decoded message of RMAIL file.")
411 (defvar rmail-mime-feature
'rmail-mime
412 "Feature to provide for using MIME feature in RMAIL.
413 When starting rmail, this feature is requrired if rmail-enable-mime
417 ;;;; *** Rmail Mode ***
420 (defun rmail (&optional file-name-arg
)
421 "Read and edit incoming mail.
422 Moves messages into file named by `rmail-file-name' (a babyl format file)
423 and edits that file in RMAIL Mode.
424 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
426 May be called with file name as argument; then performs rmail editing on
427 that file, but does not copy any new mail into the file.
428 Interactively, if you supply a prefix argument, then you
429 have a chance to specify a file name with the minibuffer.
431 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
432 (interactive (if current-prefix-arg
433 (list (read-file-name "Run rmail on RMAIL file: "))))
434 (if rmail-enable-mime
436 (require rmail-mime-feature
)
437 (error (message "Feature `%s' not provided" rmail-mime-feature
)
439 (setq rmail-enable-mime nil
))))
440 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
441 (existed (get-file-buffer file-name
))
442 (coding-system-for-read 'no-conversion
)
444 ;; Like find-file, but in the case where a buffer existed
445 ;; and the file was reverted, recompute the message-data.
446 (if (and existed
(not (verify-visited-file-modtime existed
)))
448 ;; Don't be confused by apparent local-variables spec
449 ;; in the last message in the RMAIL file.
450 (let ((enable-local-variables nil
))
451 (find-file file-name
))
452 (if (and (verify-visited-file-modtime existed
)
453 (eq major-mode
'rmail-mode
))
454 (progn (rmail-forget-messages)
455 (rmail-set-message-counters))))
456 (let ((enable-local-variables nil
))
457 (find-file file-name
)))
458 (if (eq major-mode
'rmail-edit-mode
)
459 (error "Exit Rmail Edit mode before getting new mail."))
460 (if (and existed
(> (buffer-size) 0))
461 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
462 (or (eq major-mode
'rmail-mode
)
463 (progn (rmail-mode-2)
464 (setq run-mail-hook t
)))
465 (setq run-mail-hook t
)
467 ;; Convert all or part to Babyl file if possible.
469 (goto-char (point-max))
470 (if (null rmail-inbox-list
)
472 (rmail-set-message-counters)
473 (rmail-show-message))))
474 (or (and (null file-name-arg
)
475 (rmail-get-new-mail))
476 (rmail-show-message (rmail-first-unseen-message)))
477 (if rmail-display-summary
(rmail-summary))
478 (rmail-construct-io-menu)
480 (run-hooks 'rmail-mode-hook
))))
482 ;; Given the value of MAILPATH, return a list of inbox file names.
483 ;; This is turned off because it is not clear that the user wants
484 ;; all these inboxes to feed into the primary rmail file.
485 ; (defun rmail-convert-mailpath (string)
487 ; (while (setq idx (string-match "[%:]" string))
488 ; (let ((this (substring string 0 idx)))
489 ; (setq string (substring string (1+ idx)))
490 ; (setq list (cons (if (string-match "%" this)
491 ; (substring this 0 (string-match "%" this))
496 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
497 ; will not cause emacs 18.55 problems.
499 (defun rmail-convert-file ()
502 (goto-char (point-min))
503 ;; If file doesn't start like a Babyl file,
504 ;; convert it to one, by adding a header and converting each message.
505 (cond ((looking-at "BABYL OPTIONS:"))
506 ((looking-at "Version: 5\n")
507 ;; Losing babyl file made by old version of Rmail.
508 ;; Just fix the babyl file header; don't make a new one,
509 ;; so we don't lose the Labels: file attribute, etc.
510 (let ((buffer-read-only nil
))
511 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
512 ((equal (point-min) (point-max))
513 ;; Empty RMAIL file. Just insert the header.
514 (rmail-insert-rmail-file-header))
516 ;; Non-empty file in non-RMAIL format. Add header and convert.
518 (rmail-insert-rmail-file-header)))
519 (if (and (not convert
)
520 (not rmail-enable-mime
)
521 rmail-file-coding-system
)
522 ;; Decode coding system of BABYL part at the head only. The
523 ;; remaining non BABYL parts are decoded in
524 ;; rmail-convert-to-babyl-format if necessary.
525 (rmail-decode-babyl-format))
526 ;; If file was not a Babyl file or if there are
527 ;; Unix format messages added at the end,
528 ;; convert file as necessary.
531 (goto-char (point-max))
532 (search-backward "\n\^_")
534 (looking-at "\n*From ")))
535 (let ((buffer-read-only nil
))
536 (message "Converting to Babyl format...")
537 ;; If file needs conversion, convert it all,
538 ;; except for the BABYL header.
539 ;; (rmail-convert-to-babyl-format would delete the header.)
540 (goto-char (point-min))
541 (search-forward "\n\^_" nil t
)
542 (narrow-to-region (point) (point-max))
543 (rmail-convert-to-babyl-format)
544 (message "Converting to Babyl format...done")))))
546 ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
547 ;;; will not cause emacs 18.55 problems.
549 (defun rmail-insert-rmail-file-header ()
550 (let ((buffer-read-only nil
))
551 (insert "BABYL OPTIONS: -*- rmail -*-
554 Note: This is the header of an rmail file.
555 Note: If you are seeing it in rmail,
556 Note: it means the file has no messages in it.\n\^_")))
558 ;; Decode Babyl formated part at the head of current buffer by
559 ;; rmail-file-coding-system.
561 (defun rmail-decode-babyl-format ()
562 (let ((modifiedp (buffer-modified-p))
563 (buffer-read-only nil
)
565 (goto-char (point-min))
566 (search-forward "\n\^_" nil t
) ; Skip BYBYL header.
568 (message "Decoding messages...")
569 (while (search-forward "\n\^_" nil t
)
570 (decode-coding-region pos
(point) rmail-file-coding-system
)
572 (message "Decoding messages...done")
573 (set-buffer-file-coding-system rmail-file-coding-system
)
574 (set-buffer-modified-p modifiedp
)))
578 (setq rmail-mode-map
(make-keymap))
579 (suppress-keymap rmail-mode-map
)
580 (define-key rmail-mode-map
"a" 'rmail-add-label
)
581 (define-key rmail-mode-map
"b" 'rmail-bury
)
582 (define-key rmail-mode-map
"c" 'rmail-continue
)
583 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
584 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
)
585 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
586 (define-key rmail-mode-map
"f" 'rmail-forward
)
587 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
588 (define-key rmail-mode-map
"h" 'rmail-summary
)
589 (define-key rmail-mode-map
"i" 'rmail-input
)
590 (define-key rmail-mode-map
"j" 'rmail-show-message
)
591 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
592 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
593 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
594 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
595 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
596 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
597 (define-key rmail-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
598 (define-key rmail-mode-map
"m" 'rmail-mail
)
599 (define-key rmail-mode-map
"\em" 'rmail-retry-failure
)
600 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
601 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
602 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
603 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
604 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
605 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
606 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
607 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
608 (define-key rmail-mode-map
"q" 'rmail-quit
)
609 (define-key rmail-mode-map
"r" 'rmail-reply
)
610 ;; I find I can't live without the default M-r command -- rms.
611 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
612 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
613 (define-key rmail-mode-map
"\es" 'rmail-search
)
614 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
615 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
616 (define-key rmail-mode-map
"w" 'rmail-output-body-to-file
)
617 (define-key rmail-mode-map
"x" 'rmail-expunge
)
618 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
619 (define-key rmail-mode-map
"<" 'rmail-first-message
)
620 (define-key rmail-mode-map
">" 'rmail-last-message
)
621 (define-key rmail-mode-map
" " 'scroll-up
)
622 (define-key rmail-mode-map
"\177" 'scroll-down
)
623 (define-key rmail-mode-map
"?" 'describe-mode
)
624 (define-key rmail-mode-map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
625 (define-key rmail-mode-map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
626 (define-key rmail-mode-map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
627 (define-key rmail-mode-map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
628 (define-key rmail-mode-map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
629 (define-key rmail-mode-map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
630 (define-key rmail-mode-map
"\C-c\C-s\C-k" 'rmail-sort-by-keywords
)
631 (define-key rmail-mode-map
"\C-c\C-n" 'rmail-next-same-subject
)
632 (define-key rmail-mode-map
"\C-c\C-p" 'rmail-previous-same-subject
)
635 (define-key rmail-mode-map
[menu-bar
] (make-sparse-keymap))
637 (define-key rmail-mode-map
[menu-bar classify
]
638 (cons "Classify" (make-sparse-keymap "Classify")))
640 (define-key rmail-mode-map
[menu-bar classify input-menu
]
643 (define-key rmail-mode-map
[menu-bar classify output-menu
]
646 (define-key rmail-mode-map
[menu-bar classify output-body
]
647 '("Output body to file..." . rmail-output-body-to-file
))
649 (define-key rmail-mode-map
[menu-bar classify output-inbox
]
650 '("Output (inbox)..." . rmail-output
))
652 (define-key rmail-mode-map
[menu-bar classify output
]
653 '("Output (Rmail)..." . rmail-output-to-rmail-file
))
655 (define-key rmail-mode-map
[menu-bar classify kill-label
]
656 '("Kill Label..." . rmail-kill-label
))
658 (define-key rmail-mode-map
[menu-bar classify add-label
]
659 '("Add Label..." . rmail-add-label
))
661 (define-key rmail-mode-map
[menu-bar summary
]
662 (cons "Summary" (make-sparse-keymap "Summary")))
664 (define-key rmail-mode-map
[menu-bar summary senders
]
665 '("By Senders..." . rmail-summary-by-senders
))
667 (define-key rmail-mode-map
[menu-bar summary labels
]
668 '("By Labels..." . rmail-summary-by-labels
))
670 (define-key rmail-mode-map
[menu-bar summary recipients
]
671 '("By Recipients..." . rmail-summary-by-recipients
))
673 (define-key rmail-mode-map
[menu-bar summary topic
]
674 '("By Topic..." . rmail-summary-by-topic
))
676 (define-key rmail-mode-map
[menu-bar summary regexp
]
677 '("By Regexp..." . rmail-summary-by-regexp
))
679 (define-key rmail-mode-map
[menu-bar summary all
]
680 '("All" . rmail-summary
))
682 (define-key rmail-mode-map
[menu-bar mail
]
683 (cons "Mail" (make-sparse-keymap "Mail")))
685 (define-key rmail-mode-map
[menu-bar mail rmail-get-new-mail
]
686 '("Get New Mail" . rmail-get-new-mail
))
688 (define-key rmail-mode-map
[menu-bar mail lambda
]
691 (define-key rmail-mode-map
[menu-bar mail continue
]
692 '("Continue" . rmail-continue
))
694 (define-key rmail-mode-map
[menu-bar mail resend
]
695 '("Re-send..." . rmail-resend
))
697 (define-key rmail-mode-map
[menu-bar mail forward
]
698 '("Forward" . rmail-forward
))
700 (define-key rmail-mode-map
[menu-bar mail retry
]
701 '("Retry" . rmail-retry-failure
))
703 (define-key rmail-mode-map
[menu-bar mail reply
]
704 '("Reply" . rmail-reply
))
706 (define-key rmail-mode-map
[menu-bar mail mail
]
707 '("Mail" . rmail-mail
))
709 (define-key rmail-mode-map
[menu-bar delete
]
710 (cons "Delete" (make-sparse-keymap "Delete")))
712 (define-key rmail-mode-map
[menu-bar delete expunge
/save
]
713 '("Expunge/Save" . rmail-expunge-and-save
))
715 (define-key rmail-mode-map
[menu-bar delete expunge
]
716 '("Expunge" . rmail-expunge
))
718 (define-key rmail-mode-map
[menu-bar delete undelete
]
719 '("Undelete" . rmail-undelete-previous-message
))
721 (define-key rmail-mode-map
[menu-bar delete delete
]
722 '("Delete" . rmail-delete-forward
))
724 (define-key rmail-mode-map
[menu-bar move
]
725 (cons "Move" (make-sparse-keymap "Move")))
727 (define-key rmail-mode-map
[menu-bar move search-back
]
728 '("Search Back..." . rmail-search-backwards
))
730 (define-key rmail-mode-map
[menu-bar move search
]
731 '("Search..." . rmail-search
))
733 (define-key rmail-mode-map
[menu-bar move previous
]
734 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
736 (define-key rmail-mode-map
[menu-bar move next
]
737 '("Next Nondeleted" . rmail-next-undeleted-message
))
739 (define-key rmail-mode-map
[menu-bar move last
]
740 '("Last" . rmail-last-message
))
742 (define-key rmail-mode-map
[menu-bar move first
]
743 '("First" . rmail-first-message
))
745 (define-key rmail-mode-map
[menu-bar move previous
]
746 '("Previous" . rmail-previous-message
))
748 (define-key rmail-mode-map
[menu-bar move next
]
749 '("Next" . rmail-next-message
))
751 ;; Rmail mode is suitable only for specially formatted data.
752 (put 'rmail-mode
'mode-class
'special
)
754 (defun rmail-mode-kill-summary ()
755 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
759 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
760 All normal editing commands are turned off.
761 Instead, these commands are available:
763 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
764 \\[scroll-up] Scroll to next screen of this message.
765 \\[scroll-down] Scroll to previous screen of this message.
766 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
767 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
768 \\[rmail-next-message] Move to Next message whether deleted or not.
769 \\[rmail-previous-message] Move to Previous message whether deleted or not.
770 \\[rmail-first-message] Move to the first message in Rmail file.
771 \\[rmail-last-message] Move to the last message in Rmail file.
772 \\[rmail-show-message] Jump to message specified by numeric position in file.
773 \\[rmail-search] Search for string and show message it is found in.
774 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
775 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
776 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
777 till a deleted message is found.
778 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
779 \\[rmail-expunge] Expunge deleted messages.
780 \\[rmail-expunge-and-save] Expunge and save the file.
781 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
782 \\[save-buffer] Save without expunging.
783 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
784 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
785 \\[rmail-continue] Continue composing outgoing message started before.
786 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
787 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
788 \\[rmail-forward] Forward this message to another user.
789 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
790 \\[rmail-output] Output this message to a Unix-format mail file (append it).
791 \\[rmail-input] Input Rmail file. Run Rmail on that file.
792 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
793 \\[rmail-kill-label] Kill label. Remove a label from current message.
794 \\[rmail-next-labeled-message] Move to Next message with specified label
795 (label defaults to last one specified).
796 Standard labels: filed, unseen, answered, forwarded, deleted.
797 Any other label is present only if you add it with \\[rmail-add-label].
798 \\[rmail-previous-labeled-message] Move to Previous message with specified label
799 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
800 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
801 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
802 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
803 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
804 \\[rmail-toggle-header] Toggle display of complete header."
807 (rmail-set-message-counters)
808 (rmail-show-message rmail-total-messages
)
809 (run-hooks 'rmail-mode-hook
))
811 (defun rmail-mode-2 ()
812 (kill-all-local-variables)
816 (defun rmail-mode-1 ()
817 (setq major-mode
'rmail-mode
)
818 (setq mode-name
"RMAIL")
819 (setq buffer-read-only t
)
820 ;; No need to auto save RMAIL files in normal circumstances
821 ;; because they contain no info except attribute changes
822 ;; and deletion of messages.
823 ;; The one exception is when messages are copied into an Rmail mode buffer.
824 ;; rmail-output-to-rmail-file enables auto save when you do that.
825 (setq buffer-auto-save-file-name nil
)
826 (if (boundp 'mode-line-modified
)
827 (setq mode-line-modified
"--- ")
828 (setq mode-line-format
829 (cons "--- " (cdr (default-value 'mode-line-format
)))))
830 (use-local-map rmail-mode-map
)
831 (set-syntax-table text-mode-syntax-table
)
832 (setq local-abbrev-table text-mode-abbrev-table
))
834 (defun rmail-variables ()
835 (make-local-variable 'revert-buffer-function
)
836 (setq revert-buffer-function
'rmail-revert
)
837 (make-local-variable 'font-lock-defaults
)
838 (setq font-lock-defaults
839 '(rmail-font-lock-keywords t nil nil nil
840 (font-lock-maximum-size . nil
)
841 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
842 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
843 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
844 (make-local-variable 'rmail-last-label
)
845 (make-local-variable 'rmail-last-regexp
)
846 (make-local-variable 'rmail-deleted-vector
)
847 (make-local-variable 'rmail-buffer
)
848 (setq rmail-buffer
(current-buffer))
849 (make-local-variable 'rmail-view-buffer
)
850 (setq rmail-view-buffer rmail-buffer
)
851 (make-local-variable 'rmail-summary-buffer
)
852 (make-local-variable 'rmail-summary-vector
)
853 (make-local-variable 'rmail-current-message
)
854 (make-local-variable 'rmail-total-messages
)
855 (make-local-variable 'require-final-newline
)
856 (setq require-final-newline nil
)
857 (make-local-variable 'rmail-overlay-list
)
858 (setq rmail-overlay-list nil
)
859 (make-local-variable 'version-control
)
860 (setq version-control
'never
)
861 (make-local-variable 'kill-buffer-hook
)
862 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
863 (make-local-variable 'file-precious-flag
)
864 (setq file-precious-flag t
)
865 (make-local-variable 'rmail-message-vector
)
866 (make-local-variable 'rmail-msgref-vector
)
867 (make-local-variable 'rmail-inbox-list
)
868 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
869 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
870 (and (null rmail-inbox-list
)
871 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
872 (equal buffer-file-truename
873 (abbreviate-file-name (file-truename rmail-file-name
))))
874 (setq rmail-inbox-list
875 (or rmail-primary-inbox-list
876 (list (or (getenv "MAIL")
877 (concat rmail-spool-directory
878 (user-login-name)))))))
879 (make-local-variable 'rmail-keywords
)
880 ;; this gets generated as needed
881 (setq rmail-keywords nil
))
883 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
884 (defun rmail-revert (arg noconfirm
)
885 (let ((revert-buffer-function (default-value 'revert-buffer-function
)))
886 ;; Call our caller again, but this time it does the default thing.
887 (if (revert-buffer arg noconfirm
)
888 ;; If the user said "yes", and we changed something,
889 ;; reparse the messages.
890 ;; But, we don't have to convert coding system because backup
891 ;; files should have been saved by Emacs' internal format.
892 (let ((rmail-file-coding-system nil
)
893 (enable-multibyte-characters nil
))
895 (goto-char (point-max))
898 ;; Return a list of files from this buffer's Mail: option.
899 ;; Does not assume that messages have been parsed.
900 ;; Just returns nil if buffer does not look like Babyl format.
901 (defun rmail-parse-file-inboxes ()
906 (cond ((looking-at "BABYL OPTIONS:")
907 (search-forward "\n\^_" nil
'move
)
908 (narrow-to-region 1 (point))
910 (if (search-forward "\nMail:" nil t
)
912 (narrow-to-region (point) (progn (end-of-line) (point)))
913 (goto-char (point-min))
914 (mail-parse-comma-list))))))))
916 (defun rmail-expunge-and-save ()
917 "Expunge and save RMAIL file."
921 (if (rmail-summary-exists)
922 (rmail-select-summary (set-buffer-modified-p nil
))))
927 (rmail-expunge-and-save)
928 ;; Don't switch to the summary buffer even if it was recently visible.
929 (if rmail-summary-buffer
931 (replace-buffer-in-windows rmail-summary-buffer
)
932 (bury-buffer rmail-summary-buffer
)))
933 (let ((obuf (current-buffer)))
934 (replace-buffer-in-windows obuf
)
938 "Bury current Rmail buffer and its summary buffer."
940 ;; This let var was called rmail-buffer, but that interfered
941 ;; with the buffer-local var used in summary buffers.
942 (let ((buffer-to-bury (current-buffer)))
943 (if (rmail-summary-exists)
945 (while (setq window
(get-buffer-window rmail-summary-buffer
))
946 (set-window-buffer window
(other-buffer rmail-summary-buffer
)))
947 (bury-buffer rmail-summary-buffer
)))
948 (switch-to-buffer (other-buffer (current-buffer)))
949 (bury-buffer buffer-to-bury
)))
951 (defun rmail-duplicate-message ()
952 "Create a duplicated copy of the current message.
953 The duplicate copy goes into the Rmail file just after the
957 (let ((buffer-read-only nil
)
958 (number rmail-current-message
)
959 (string (buffer-substring (rmail-msgbeg rmail-current-message
)
960 (rmail-msgend rmail-current-message
))))
961 (goto-char (rmail-msgend rmail-current-message
))
963 (rmail-forget-messages)
964 (rmail-show-message number
)
965 (message "Message duplicated")))
968 (defun rmail-input (filename)
969 "Run Rmail on file FILENAME."
970 (interactive "FRun rmail on RMAIL file: ")
974 ;; This used to scan subdirectories recursively, but someone pointed out
975 ;; that if the user wants that, person can put all the files in one dir.
976 ;; And the recursive scan was slow. So I took it out.
978 (defun rmail-find-all-files (start)
979 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
980 (if (file-accessible-directory-p start
)
982 (let* ((case-fold-search t
)
983 (files (directory-files start t rmail-secondary-file-regexp
)))
984 ;; Sort here instead of in directory-files
985 ;; because this list is usually much shorter.
986 (sort files
'string
<))))
988 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
989 (let ((menu (make-sparse-keymap menu-name
)))
991 (function (lambda (item)
996 (rmail-list-to-menu (car item
) (cdr item
)
999 (concat full-name
"/"
1002 (setq name
(car item
)))
1006 (list 'lambda
() '(interactive)
1010 (concat full-name
"/" item
)
1012 rmail-secondary-file-directory
))))))
1013 (define-key menu
(vector (intern name
))
1014 (cons name command
)))))
1018 ;; This command is always "disabled" when it appears in a menu.
1019 (put 'rmail-disable-menu
'menu-enable
''nil
)
1021 (defun rmail-construct-io-menu ()
1022 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1025 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1026 (cons "Input Rmail File"
1027 (rmail-list-to-menu "Input Rmail File"
1030 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1031 (cons "Output Rmail File"
1032 (rmail-list-to-menu "Output Rmail File"
1034 'rmail-output-to-rmail-file
))))
1036 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1037 '("Input Rmail File" . rmail-disable-menu
))
1038 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1039 '("Output Rmail File" . rmail-disable-menu
)))))
1042 ;;;; *** Rmail input ***
1044 ;; RLK feature not added in this version:
1045 ;; argument specifies inbox file or files in various ways.
1047 (defun rmail-get-new-mail (&optional file-name
)
1048 "Move any new mail from this RMAIL file's inbox files.
1049 The inbox files can be specified with the file's Mail: option. The
1050 variable `rmail-primary-inbox-list' specifies the inboxes for your
1051 primary RMAIL file if it has no Mail: option. By default, this is
1052 your /usr/spool/mail/$USER.
1054 You can also specify the file to get new mail from. In this case, the
1055 file of new mail is not changed or deleted. Noninteractively, you can
1056 pass the inbox file name as an argument. Interactively, a prefix
1057 argument causes us to read a file name and use that file as the inbox.
1059 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1060 always be left in inbox files rather than deleted.
1062 This function runs `rmail-get-new-mail-hook' before saving the updated file.
1063 It returns t if it got any new messages."
1065 (list (if current-prefix-arg
1066 (read-file-name "Get new mail from file: "))))
1067 (run-hooks 'rmail-before-get-new-mail-hook
)
1068 ;; If the disk file has been changed from under us,
1069 ;; revert to it before we get new mail.
1070 (or (verify-visited-file-modtime (current-buffer))
1071 (find-file (buffer-file-name)))
1072 (rmail-maybe-set-message-counters)
1074 ;; Get rid of all undo records for this buffer.
1075 (or (eq buffer-undo-list t
)
1076 (setq buffer-undo-list nil
))
1077 (let ((all-files (if file-name
(list file-name
)
1082 (let ((opoint (point))
1085 ;; If buffer has not changed yet, and has not been saved yet,
1086 ;; don't replace the old backup file now.
1087 (make-backup-files (and make-backup-files
(buffer-modified-p)))
1088 (buffer-read-only nil
)
1089 ;; Don't make undo records for what we do in getting mail.
1090 (buffer-undo-list t
)
1092 ;; Files to insert this time around.
1094 ;; Last names of those files.
1096 ;; Pull files off all-files onto files
1097 ;; as long as there is no name conflict.
1098 ;; A conflict happens when two inbox file names
1099 ;; have the same last component.
1100 (while (and all-files
1101 (not (member (file-name-nondirectory (car all-files
))
1103 (setq files
(cons (car all-files
) files
)
1105 (cons (file-name-nondirectory (car all-files
)) files
))
1106 (setq all-files
(cdr all-files
)))
1107 ;; Put them back in their original order.
1108 (setq files
(nreverse files
))
1110 (goto-char (point-max))
1111 (skip-chars-backward " \t\n") ; just in case of brain damage
1112 (delete-region (point) (point-max)) ; caused by require-final-newline
1115 (narrow-to-region (point) (point))
1116 ;; Read in the contents of the inbox files,
1117 ;; renaming them as necessary,
1118 ;; and adding to the list of files to delete eventually.
1120 (rmail-insert-inbox-text files nil
)
1121 (setq delete-files
(rmail-insert-inbox-text files t
)))
1122 ;; Scan the new text and convert each message to babyl format.
1123 (goto-char (point-min))
1126 (setq new-messages
(rmail-convert-to-babyl-format)
1128 ;; If we could not convert the file's inboxes,
1129 ;; rename the files we tried to read
1130 ;; so we won't over and over again.
1131 (if (and (not file-name
) (not success
))
1132 (let ((delfiles delete-files
)
1134 ;; Try to delete the garbage just inserted.
1135 (delete-region (point-min) (point-max))
1137 (while (file-exists-p (format "RMAILOSE.%d" count
))
1138 (setq count
(1+ count
)))
1139 (rename-file (car delfiles
)
1140 (format "RMAILOSE.%d" count
))
1141 (setq delfiles
(cdr delfiles
))))))
1142 (or (zerop new-messages
)
1145 (search-backward "\n\^_" nil t
)
1146 (narrow-to-region (point) (point-max))
1147 (goto-char (1+ (point-min)))
1148 (rmail-count-new-messages)
1149 (run-hooks 'rmail-get-new-mail-hook
)
1151 ;; Delete the old files, now that babyl file is saved.
1154 ;; First, try deleting.
1156 (delete-file (car delete-files
))
1158 ;; If we can't delete it, truncate it.
1159 (write-region (point) (point) (car delete-files
))))
1161 (setq delete-files
(cdr delete-files
)))))
1162 (if (= new-messages
0)
1163 (progn (goto-char opoint
)
1164 (if (or file-name rmail-inbox-list
)
1165 (message "(No new mail has arrived)")))
1166 (if (rmail-summary-exists)
1167 (rmail-select-summary
1168 (rmail-update-summary)))
1169 (message "%d new message%s read"
1170 new-messages
(if (= 1 new-messages
) "" "s"))
1171 ;; Move to the first new message
1172 ;; unless we have other unseen messages before it.
1173 (rmail-show-message (rmail-first-unseen-message))
1174 (run-hooks 'rmail-after-get-new-mail-hook
)
1177 ;; Don't leave the buffer screwed up if we get a disk-full error.
1178 (rmail-show-message))))
1180 (defun rmail-insert-inbox-text (files renamep
)
1181 ;; Detect a locked file now, so that we avoid moving mail
1182 ;; out of the real inbox file. (That could scare people.)
1183 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1184 (error "RMAIL file %s is locked"
1185 (file-name-nondirectory buffer-file-name
)))
1186 (let (file tofile delete-files movemail popmail
)
1188 (setq file
(file-truename
1189 (expand-file-name (substitute-in-file-name (car files
))))
1190 tofile
(expand-file-name
1191 ;; Generate name to move to from inbox name,
1192 ;; in case of multiple inboxes that need moving.
1193 (concat ".newmail-" (file-name-nondirectory file
))
1194 ;; Use the directory of this rmail file
1195 ;; because it's a nuisance to use the homedir
1196 ;; if that is on a full disk and this rmail
1198 (file-name-directory
1199 (expand-file-name buffer-file-name
))))
1200 ;; Always use movemail to rename the file,
1201 ;; since there can be mailboxes in various directories.
1203 ;;; ;; If getting from mail spool directory,
1204 ;;; ;; use movemail to move rather than just renaming,
1205 ;;; ;; so as to interlock with the mailer.
1206 ;;; (setq movemail (string= file
1208 ;;; (concat rmail-spool-directory
1209 ;;; (file-name-nondirectory file)))))
1210 (setq popmail
(string-match "^po:" (file-name-nondirectory file
)))
1211 (if popmail
(setq file
(file-name-nondirectory file
)
1215 ;; On some systems, /usr/spool/mail/foo is a directory
1216 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1217 (if (file-directory-p file
)
1218 (setq file
(expand-file-name (user-login-name)
1221 (if (and rmail-pop-password-required
(not rmail-pop-password
))
1222 (setq rmail-pop-password
1224 (format "Password for %s: "
1225 (substring file
(+ popmail
3))))))
1226 (if (eq system-type
'windows-nt
)
1227 ;; cannot have "po:" in file name
1230 (concat ".newmail-pop-" (substring file
(+ popmail
3)))
1231 (file-name-directory
1232 (expand-file-name buffer-file-name
)))))
1233 (message "Getting mail from post office ..."))
1234 ((and (file-exists-p tofile
)
1235 (/= 0 (nth 7 (file-attributes tofile
))))
1236 (message "Getting mail from %s..." tofile
))
1237 ((and (file-exists-p file
)
1238 (/= 0 (nth 7 (file-attributes file
))))
1239 (message "Getting mail from %s..." file
)))
1240 ;; Set TOFILE if have not already done so, and
1241 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1242 (cond ((not renamep
)
1244 ((or (file-exists-p tofile
) (and (not popmail
)
1245 (not (file-exists-p file
))))
1247 ((and (not movemail
) (not popmail
))
1248 ;; Try copying. If that fails (perhaps no space) and
1249 ;; we're allowed to blow away the inbox, rename instead.
1250 (if rmail-preserve-inbox
1251 (copy-file file tofile nil
)
1253 (copy-file file tofile nil
)
1255 ;; Third arg is t so we can replace existing file TOFILE.
1256 (rename-file file tofile t
))))
1257 ;; Make the real inbox file empty.
1258 ;; Leaving it deleted could cause lossage
1259 ;; because mailers often won't create the file.
1260 (if (not rmail-preserve-inbox
)
1262 (write-region (point) (point) file
)
1268 (setq errors
(generate-new-buffer " *rmail loss*"))
1269 (buffer-disable-undo errors
)
1272 (list (or rmail-movemail-program
1273 (expand-file-name "movemail"
1276 (if rmail-preserve-inbox
1280 (if rmail-pop-password
1281 (list rmail-pop-password
)
1283 (apply 'call-process args
))
1284 (if (not (buffer-modified-p errors
))
1285 ;; No output => movemail won
1288 (subst-char-in-region (point-min) (point-max)
1290 (goto-char (point-max))
1291 (skip-chars-backward " \t")
1292 (delete-region (point) (point-max))
1293 (goto-char (point-min))
1294 (if (looking-at "movemail: ")
1295 (delete-region (point-min) (match-end 0)))
1297 (message "movemail: %s"
1298 (buffer-substring (point-min)
1302 (if errors
(kill-buffer errors
))))))
1303 ;; At this point, TOFILE contains the name to read:
1304 ;; Either the alternate name (if we renamed)
1305 ;; or the actual inbox (if not renaming).
1306 (if (file-exists-p tofile
)
1307 (let ((coding-system-for-read 'no-conversion
)
1309 (goto-char (point-max))
1310 (setq size
(nth 1 (insert-file-contents tofile
)))
1311 (goto-char (point-max))
1312 (or (= (preceding-char) ?
\n)
1315 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
1316 (setq delete-files
(cons tofile delete-files
)))))
1318 (setq files
(cdr files
)))
1321 (defun rmail-read-passwd (prompt &optional default
)
1322 "Read a password, echoing `.' for each character typed.
1323 End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line.
1324 Optional DEFAULT is password to start with."
1325 (let ((pass (if default default
""))
1328 (cursor-in-echo-area t
))
1329 (while (progn (message "%s%s"
1331 (make-string (length pass
) ?.
))
1332 (setq c
(read-char))
1333 (and (/= c ?
\r) (/= c ?
\n) (/= c ?\e
)))
1336 (if (and (/= c ?
\b) (/= c ?
\177))
1337 (setq pass
(concat pass
(char-to-string c
)))
1338 (if (> (length pass
) 0)
1339 (setq pass
(substring pass
0 -
1))))))
1344 ;; the rmail-break-forwarded-messages feature is not implemented
1345 (defun rmail-convert-to-babyl-format ()
1346 (let ((count 0) start
1347 (case-fold-search nil
)
1348 (invalid-input-resync
1349 (function (lambda ()
1350 (message "Invalid Babyl format in inbox!")
1352 ;; Try to get back in sync with a real message.
1353 (if (re-search-forward
1354 (concat rmail-mmdf-delim1
"\\|^From") nil t
)
1356 (goto-char (point-max)))))))
1357 (goto-char (point-min))
1360 (setq start
(point))
1361 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1362 (if (search-forward "\n\^_" nil t
)
1363 ;; If we find the proper terminator, delete through there.
1364 (delete-region (point-min) (point))
1365 (funcall invalid-input-resync
)
1366 (delete-region (point-min) (point))))
1367 ;; Babyl format message
1369 (or (search-forward "\n\^_" nil t
)
1370 (funcall invalid-input-resync
))
1371 (setq count
(1+ count
))
1372 ;; Make sure there is no extra white space after the ^_
1373 ;; at the end of the message.
1374 ;; Narrowing will make sure that whatever follows the junk
1375 ;; will be treated properly.
1376 (delete-region (point)
1378 (skip-chars-forward " \t\n")
1380 (or rmail-enable-mime
1381 (not rmail-file-coding-system
)
1382 (decode-coding-region start
(point)
1383 rmail-file-coding-system
))
1384 (narrow-to-region (point) (point-max)))
1386 ((let ((case-fold-search t
))
1387 (looking-at rmail-mmdf-delim1
))
1388 (let ((case-fold-search t
))
1389 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1390 (re-search-forward rmail-mmdf-delim2 nil t
)
1391 (replace-match "\^_"))
1394 (narrow-to-region start
(1- (point)))
1395 (goto-char (point-min))
1396 (while (search-forward "\n\^_" nil t
); single char "\^_"
1397 (replace-match "\n^_")))); 2 chars: "^" and "_"
1398 (or rmail-enable-mime
1399 (not enable-multibyte-characters
)
1400 (decode-coding-region start
(point) 'undecided
))
1401 (narrow-to-region (point) (point-max))
1402 (setq count
(1+ count
)))
1404 ((looking-at "^From ")
1405 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1406 (rmail-nuke-pinhead-header)
1407 ;; If this message has a Content-Length field,
1408 ;; skip to the end of the contents.
1409 (let* ((header-end (save-excursion
1410 (and (re-search-forward "\n\n" nil t
)
1412 (case-fold-search t
)
1414 ;; Get the numeric value from the Content-Length field.
1416 ;; Back up to end of prev line,
1417 ;; in case the Content-Length field comes first.
1419 (and (search-forward "\ncontent-length: "
1422 (eol (progn (end-of-line) (point))))
1423 (string-to-int (buffer-substring beg eol
)))))))
1425 (if (and (natnump size
)
1426 (<= (+ header-end size
) (point-max))
1427 ;; Make sure this would put us at a position
1428 ;; that we could continue from.
1430 (goto-char (+ header-end size
))
1431 (skip-chars-forward "\n")
1433 (and (looking-at "BABYL OPTIONS:")
1434 (search-forward "\n\^_" nil t
))
1435 (and (looking-at "\^L")
1436 (search-forward "\n\^_" nil t
))
1437 (let ((case-fold-search t
))
1438 (looking-at rmail-mmdf-delim1
))
1439 (looking-at "From "))))
1440 (goto-char (+ header-end size
))
1441 (message "Ignoring invalid Content-Length field")
1444 (if (re-search-forward
1445 (concat "^[\^_]?\\("
1446 rmail-unix-mail-delimiter
1448 rmail-mmdf-delim1
"\\|"
1449 "^BABYL OPTIONS:\\|"
1450 "\^L\n[01],\\)") nil t
)
1451 (goto-char (match-beginning 1))
1452 (goto-char (point-max)))
1453 (setq count
(1+ count
))
1456 (narrow-to-region start
(point))
1457 (goto-char (point-min))
1458 (while (search-forward "\n\^_" nil t
); single char
1459 (replace-match "\n^_")))); 2 chars: "^" and "_"
1461 (or rmail-enable-mime
1462 (not enable-multibyte-characters
)
1463 (decode-coding-region start
(point) 'undecided
))
1464 (narrow-to-region (point) (point-max)))
1466 ;; This kludge is because some versions of sendmail.el
1467 ;; insert an extra newline at the beginning that shouldn't
1468 ;; be there. sendmail.el has been fixed, but old versions
1469 ;; may still be in use. -- rms, 7 May 1993.
1470 ((eolp) (delete-char 1))
1471 (t (error "Cannot convert to babyl format")))))
1474 ;; Delete the "From ..." line, creating various other headers with
1475 ;; information from it if they don't already exist. Now puts the
1476 ;; original line into a mail-from: header line for debugging and for
1477 ;; use by the rmail-output function.
1478 (defun rmail-nuke-pinhead-header ()
1481 (let ((start (point))
1484 (search-forward "\n\n")
1486 (goto-char (point-max))
1490 (narrow-to-region start end
)
1491 (let ((case-fold-search t
))
1493 (setq has-from
(search-forward "\nFrom:" nil t
))
1495 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
1497 (let ((case-fold-search nil
))
1498 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
1502 ;; Keep and reformat the date if we don't
1503 ;; have a Date: field.
1507 "Date: \\2, \\4 \\3 \\9 \\5 "
1509 ;; The timezone could be matched by group 7 or group 10.
1510 ;; If neither of them matched, assume EST, since only
1511 ;; Easterners would be so sloppy.
1512 ;; It's a shame the substitution can't use "\\10".
1514 ((/= (match-beginning 7) (match-end 7)) "\\7")
1515 ((/= (match-beginning 10) (match-end 10))
1516 (buffer-substring (match-beginning 10)
1520 ;; Keep and reformat the sender if we don't
1521 ;; have a From: field.
1527 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1529 (defun rmail-reformat-message (beg end
)
1532 (if (/= (following-char) ?
0)
1533 (error "Bad format in RMAIL file."))
1534 (let ((buffer-read-only nil
)
1535 (delta (- (buffer-size) end
)))
1539 (let ((case-fold-search t
))
1540 (while (looking-at "Summary-line:\\|Mail-From:")
1542 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1543 (delete-region (point)
1544 (progn (forward-line 1) (point))))
1545 (let ((str (buffer-substring (point)
1546 (save-excursion (search-forward "\n\n" end
'move
)
1548 (insert str
"*** EOOH ***\n")
1549 (narrow-to-region (point) (- (buffer-size) delta
)))
1550 (goto-char (point-min))
1551 (if rmail-message-filter
(funcall rmail-message-filter
))
1552 (if (or rmail-displayed-headers rmail-ignored-headers
)
1553 (rmail-clear-headers))))
1555 (defun rmail-clear-headers (&optional ignored-headers
)
1556 "Delete all header fields that Rmail should not show.
1557 If the optional argument IGNORED-HEADERS is non-nil,
1558 delete all header fields whose names match that regexp.
1559 Otherwise, if `rmail-displayed-headers' is non-nil,
1560 delete all header fields *except* those whose names match that regexp.
1561 Otherwise, delete all header fields whose names match `rmail-ignored-headers'."
1562 (if (search-forward "\n\n" nil t
)
1563 (let ((case-fold-search t
)
1564 (buffer-read-only nil
))
1565 (if (and rmail-displayed-headers
(null ignored-headers
))
1567 (narrow-to-region (point-min) (point))
1569 (goto-char (point-min))
1570 (while (save-excursion
1571 (re-search-forward "\n[^ \t]")
1573 (setq lim
(1- (point)))))
1575 (re-search-forward rmail-displayed-headers lim t
))
1577 (delete-region (point) lim
))))
1578 (goto-char (point-min)))
1579 (or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
1581 (narrow-to-region (point-min) (point))
1583 (goto-char (point-min))
1584 (re-search-forward ignored-headers nil t
))
1586 (delete-region (point)
1587 (progn (re-search-forward "\n[^ \t]")
1588 (1- (point))))))))))
1590 (defun rmail-msg-is-pruned ()
1591 (rmail-maybe-set-message-counters)
1594 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
1595 (goto-char (point-min))
1597 (= (following-char) ?
1))))
1599 (defun rmail-toggle-header (&optional arg
)
1600 "Show original message header if pruned header currently shown, or vice versa.
1601 With argument ARG, show the message header pruned if ARG is greater than zero;
1602 otherwise, show it in full."
1604 (let* ((buffer-read-only nil
)
1605 (pruned (rmail-msg-is-pruned))
1607 (> (prefix-numeric-value arg
) 0)
1609 (if (eq pruned prune
)
1611 (rmail-maybe-set-message-counters)
1612 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
1614 (progn (goto-char (point-min))
1619 (let ((case-fold-search t
))
1620 (while (looking-at "Summary-Line:\\|Mail-From:")
1622 (insert "*** EOOH ***\n")
1624 (search-forward "\n*** EOOH ***\n")
1626 (let ((temp (point)))
1627 (and (search-forward "\n\n" nil t
)
1628 (delete-region temp
(point))))
1629 (goto-char (point-min))
1630 (search-forward "\n*** EOOH ***\n")
1631 (narrow-to-region (point) (point-max)))
1632 (rmail-reformat-message (point-min) (point-max)))
1633 (rmail-highlight-headers))))
1635 ;;;; *** Rmail Attributes and Keywords ***
1637 ;; Make a string describing current message's attributes and keywords
1638 ;; and set it up as the name of a minor mode
1639 ;; so it will appear in the mode line.
1640 (defun rmail-display-labels ()
1641 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1646 (goto-char (rmail-msgbeg rmail-current-message
))
1648 (if (looking-at "[01],")
1650 (narrow-to-region (point) (progn (end-of-line) (point)))
1651 ;; Truly valid BABYL format requires a space before each
1652 ;; attribute or keyword name. Put them in if missing.
1653 (let (buffer-read-only)
1654 (goto-char (point-min))
1655 (while (search-forward "," nil t
)
1656 (or (looking-at "[ ,]") (eobp)
1658 (goto-char (point-max))
1659 (if (search-backward ",," nil
'move
)
1661 (if (> (point) (1+ (point-min)))
1662 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
1663 (if (> (- (point-max) (point)) 2)
1667 (buffer-substring (+ (point) 3)
1668 (1- (point-max)))))))))))
1669 ;; Note: we don't use save-restriction because that does not work right
1670 ;; if changes are made outside the saved restriction
1671 ;; before that restriction is restored.
1672 (narrow-to-region beg end
)
1673 (set-marker beg nil
)
1674 (set-marker end nil
)))
1675 (while (string-match " +," blurb
)
1676 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
1677 (substring blurb
(match-end 0)))))
1678 (while (string-match ", +" blurb
)
1679 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
1680 (substring blurb
(match-end 0)))))
1681 (setq mode-line-process
1683 rmail-current-message rmail-total-messages blurb
))))
1685 ;; Turn an attribute of a message on or off according to STATE.
1686 ;; ATTR is the name of the attribute, as a string.
1687 ;; MSGNUM is message number to change; nil means current message.
1688 (defun rmail-set-attribute (attr state
&optional msgnum
)
1689 (let ((omax (point-max-marker))
1690 (omin (point-min-marker))
1691 (buffer-read-only nil
))
1692 (or msgnum
(setq msgnum rmail-current-message
))
1697 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
1700 (null (search-backward (concat ", " attr
",")
1701 (prog1 (point) (end-of-line)) t
)))))
1702 (or (eq curstate
(not (not state
)))
1704 (delete-region (point) (1- (match-end 0)))
1707 (insert " " attr
","))))
1708 (if (string= attr
"deleted")
1709 (rmail-set-message-deleted-p msgnum state
)))
1710 ;; Note: we don't use save-restriction because that does not work right
1711 ;; if changes are made outside the saved restriction
1712 ;; before that restriction is restored.
1713 (narrow-to-region omin omax
)
1714 (set-marker omin nil
)
1715 (set-marker omax nil
)
1716 (if (= msgnum rmail-current-message
)
1717 (rmail-display-labels))))))
1719 ;; Return t if the attributes/keywords line of msg number MSG
1720 ;; contains a match for the regexp LABELS.
1721 (defun rmail-message-labels-p (msg labels
)
1725 (goto-char (rmail-msgbeg msg
))
1727 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
1729 ;;;; *** Rmail Message Selection And Support ***
1731 (defun rmail-msgend (n)
1732 (marker-position (aref rmail-message-vector
(1+ n
))))
1734 (defun rmail-msgbeg (n)
1735 (marker-position (aref rmail-message-vector n
)))
1737 (defun rmail-widen-to-current-msgbeg (function)
1738 "Call FUNCTION with point at start of internal data of current message.
1739 Assumes that bounds were previously narrowed to display the message in Rmail.
1740 The bounds are widened enough to move point where desired, then narrowed
1743 FUNCTION may not change the visible text of the message, but it may
1744 change the invisible header text."
1746 (let ((obeg (- (point-max) (point-min))))
1749 (narrow-to-region (rmail-msgbeg rmail-current-message
)
1751 (goto-char (point-min))
1753 ;; Note: we don't use save-restriction because that does not work right
1754 ;; if changes are made outside the saved restriction
1755 ;; before that restriction is restored.
1756 ;; Here we assume that changes made by FUNCTION
1757 ;; occur before the visible region of the message.
1758 (narrow-to-region (- (point-max) obeg
) (point-max))))))
1760 (defun rmail-forget-messages ()
1762 (if (vectorp rmail-message-vector
)
1764 (v rmail-message-vector
)
1767 (move-marker (aref v i
) nil
)
1769 (setq rmail-message-vector nil
)
1770 (setq rmail-msgref-vector nil
)
1771 (setq rmail-deleted-vector nil
)))
1773 (defun rmail-maybe-set-message-counters ()
1774 (if (not (and rmail-deleted-vector
1775 rmail-message-vector
1776 rmail-current-message
1777 rmail-total-messages
))
1778 (rmail-set-message-counters)))
1780 (defun rmail-count-new-messages (&optional nomsg
)
1781 (let* ((case-fold-search nil
)
1785 (or nomsg
(message "Counting new messages..."))
1786 (goto-char (point-max))
1787 ;; Put at the end of messages-head
1788 ;; the entry for message N+1, which marks
1789 ;; the end of message N. (N = number of messages).
1790 (search-backward "\n\^_")
1792 (setq messages-head
(list (point-marker)))
1793 (rmail-set-message-counters-counter (point-min))
1794 (setq rmail-current-message
(1+ rmail-total-messages
))
1795 (setq rmail-total-messages
1796 (+ rmail-total-messages total-messages
))
1797 (setq rmail-message-vector
1798 (vconcat rmail-message-vector
(cdr messages-head
)))
1799 (aset rmail-message-vector
1800 rmail-current-message
(car messages-head
))
1801 (setq rmail-deleted-vector
1802 (concat rmail-deleted-vector deleted-head
))
1803 (setq rmail-summary-vector
1804 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
1805 (setq rmail-msgref-vector
1806 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
1807 ;; Fill in the new elements of rmail-msgref-vector.
1808 (let ((i (1+ (- rmail-total-messages total-messages
))))
1809 (while (<= i rmail-total-messages
)
1810 (aset rmail-msgref-vector i
(list i
))
1812 (goto-char (point-min))
1813 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
1815 (defun rmail-set-message-counters ()
1816 (rmail-forget-messages)
1820 (let* ((point-save (point))
1822 (messages-after-point)
1823 (case-fold-search nil
)
1826 (message "Counting messages...")
1827 (goto-char (point-max))
1828 ;; Put at the end of messages-head
1829 ;; the entry for message N+1, which marks
1830 ;; the end of message N. (N = number of messages).
1831 (search-backward "\n\^_" nil t
)
1832 (if (/= (point) (point-max)) (forward-char 1))
1833 (setq messages-head
(list (point-marker)))
1834 (rmail-set-message-counters-counter (min (point) point-save
))
1835 (setq messages-after-point total-messages
)
1836 (rmail-set-message-counters-counter)
1837 (setq rmail-total-messages total-messages
)
1838 (setq rmail-current-message
1840 (max 1 (- total-messages messages-after-point
))))
1841 (setq rmail-message-vector
1842 (apply 'vector
(cons (point-min-marker) messages-head
))
1843 rmail-deleted-vector
(concat "D" deleted-head
)
1844 rmail-summary-vector
(make-vector rmail-total-messages nil
)
1845 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
1847 (while (<= i rmail-total-messages
)
1848 (aset rmail-msgref-vector i
(list i
))
1850 (message "Counting messages...done")))))
1852 (defun rmail-set-message-counters-counter (&optional stop
)
1853 (while (search-backward "\n\^_\^L\n" stop t
)
1855 (setq messages-head
(cons (point-marker) messages-head
))
1858 (cons (if (search-backward ", deleted,"
1864 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
1865 (message "Counting messages...%d" total-messages
))))
1867 (defun rmail-beginning-of-message ()
1868 "Show current message starting from the beginning."
1870 (rmail-show-message rmail-current-message
))
1872 (defun rmail-show-message (&optional n no-summary
)
1873 "Show message number N (prefix argument), counting from start of file.
1874 If summary buffer is currently displayed, update current message there also."
1876 (or (eq major-mode
'rmail-mode
)
1877 (switch-to-buffer rmail-buffer
))
1878 (rmail-maybe-set-message-counters)
1880 (if (zerop rmail-total-messages
)
1881 (progn (narrow-to-region (point-min) (1- (point-max)))
1882 (goto-char (point-min))
1883 (setq mode-line-process nil
))
1886 (setq n rmail-current-message
)
1889 rmail-current-message
1
1890 blurb
"No previous message"))
1891 ((> n rmail-total-messages
)
1892 (setq n rmail-total-messages
1893 rmail-current-message rmail-total-messages
1894 blurb
"No following message"))
1896 (setq rmail-current-message n
))))
1897 (let ((beg (rmail-msgbeg n
)))
1900 ;; Clear the "unseen" attribute when we show a message.
1901 (rmail-set-attribute "unseen" nil
)
1902 ;; Reformat the header, or else find the reformatted header.
1903 (let ((end (rmail-msgend n
)))
1904 (if (= (following-char) ?
0)
1905 (rmail-reformat-message beg end
)
1906 (search-forward "\n*** EOOH ***\n" end t
)
1907 (narrow-to-region (point) end
)))
1908 (goto-char (point-min))
1909 (rmail-display-labels)
1910 (if (eq rmail-enable-mime t
)
1911 (funcall rmail-show-mime-function
)
1912 (setq rmail-view-buffer rmail-buffer
)
1914 (rmail-highlight-headers)
1915 (if transient-mark-mode
(deactivate-mark))
1916 (run-hooks 'rmail-show-message-hook
)
1917 ;; If there is a summary buffer, try to move to this message
1918 ;; in that buffer. But don't complain if this message
1919 ;; is not mentioned in the summary.
1920 ;; Don't do this at all if we were called on behalf
1921 ;; of cursor motion in the summary buffer.
1922 (and (rmail-summary-exists) (not no-summary
)
1923 (let ((curr-msg rmail-current-message
))
1924 (rmail-select-summary
1925 (rmail-summary-goto-msg curr-msg t t
))))
1927 (message blurb
))))))
1929 ;; Find all occurrences of certain fields, and highlight them.
1930 (defun rmail-highlight-headers ()
1931 ;; Do this only if the system supports faces.
1932 (if (and (fboundp 'internal-find-face
)
1933 rmail-highlighted-headers
)
1935 (search-forward "\n\n" nil
'move
)
1937 (narrow-to-region (point-min) (point))
1938 (let ((case-fold-search t
)
1939 (inhibit-read-only t
)
1940 ;; Highlight with boldface if that is available.
1941 ;; Otherwise use the `highlight' face.
1942 (face (or rmail-highlight-face
1943 (if (face-differs-from-default-p 'bold
)
1945 ;; List of overlays to reuse.
1946 (overlays rmail-overlay-list
))
1947 (goto-char (point-min))
1948 (while (re-search-forward rmail-highlighted-headers nil t
)
1949 (skip-chars-forward " \t")
1952 (while (progn (forward-line 1)
1953 (looking-at "[ \t]")))
1954 ;; Back up over newline, then trailing spaces or tabs
1956 (while (member (preceding-char) '(? ?
\t))
1959 ;; Reuse an overlay we already have.
1961 (setq overlay
(car overlays
)
1962 overlays
(cdr overlays
))
1963 (overlay-put overlay
'face face
)
1964 (move-overlay overlay beg
(point)))
1965 ;; Make a new overlay and add it to
1966 ;; rmail-overlay-list.
1967 (setq overlay
(make-overlay beg
(point)))
1968 (overlay-put overlay
'face face
)
1969 (setq rmail-overlay-list
1970 (cons overlay rmail-overlay-list
))))))))))
1972 (defun rmail-next-message (n)
1973 "Show following message whether deleted or not.
1974 With prefix arg N, moves forward N messages, or backward if N is negative."
1976 (rmail-maybe-set-message-counters)
1977 (rmail-show-message (+ rmail-current-message n
)))
1979 (defun rmail-previous-message (n)
1980 "Show previous message whether deleted or not.
1981 With prefix arg N, moves backward N messages, or forward if N is negative."
1983 (rmail-next-message (- n
)))
1985 (defun rmail-next-undeleted-message (n)
1986 "Show following non-deleted message.
1987 With prefix arg N, moves forward N non-deleted messages,
1988 or backward if N is negative.
1990 Returns t if a new message is being shown, nil otherwise."
1992 (rmail-maybe-set-message-counters)
1993 (let ((lastwin rmail-current-message
)
1994 (current rmail-current-message
))
1995 (while (and (> n
0) (< current rmail-total-messages
))
1996 (setq current
(1+ current
))
1997 (if (not (rmail-message-deleted-p current
))
1998 (setq lastwin current n
(1- n
))))
1999 (while (and (< n
0) (> current
1))
2000 (setq current
(1- current
))
2001 (if (not (rmail-message-deleted-p current
))
2002 (setq lastwin current n
(1+ n
))))
2003 (if (/= lastwin rmail-current-message
)
2004 (progn (rmail-show-message lastwin
)
2007 (message "No previous nondeleted message"))
2009 (message "No following nondeleted message"))
2012 (defun rmail-previous-undeleted-message (n)
2013 "Show previous non-deleted message.
2014 With prefix argument N, moves backward N non-deleted messages,
2015 or forward if N is negative."
2017 (rmail-next-undeleted-message (- n
)))
2019 (defun rmail-first-message ()
2020 "Show first message in file."
2022 (rmail-maybe-set-message-counters)
2023 (rmail-show-message 1))
2025 (defun rmail-last-message ()
2026 "Show last message in file."
2028 (rmail-maybe-set-message-counters)
2029 (rmail-show-message rmail-total-messages
))
2031 (defun rmail-what-message ()
2032 (let ((where (point))
2034 (high rmail-total-messages
)
2035 (mid (/ rmail-total-messages
2)))
2036 (while (> (- high low
) 1)
2037 (if (>= where
(rmail-msgbeg mid
))
2040 (setq mid
(+ low
(/ (- high low
) 2))))
2041 (if (>= where
(rmail-msgbeg high
)) high low
)))
2043 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
2045 (goto-char (rmail-msgbeg msg
))
2046 (search-forward "\n*** EOOH ***\n")
2047 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
2048 (or (string-match recipients
(or (mail-fetch-field "To") ""))
2049 (string-match recipients
(or (mail-fetch-field "From") ""))
2050 (if (not primary-only
)
2051 (string-match recipients
(or (mail-fetch-field "Cc") ""))))))
2053 (defun rmail-message-regexp-p (msg regexp
)
2054 "Return t, if for message number MSG, regexp REGEXP matches in the header."
2055 (goto-char (rmail-msgbeg msg
))
2058 (search-forward "*** EOOH ***" (point-max)) (point))))
2059 (re-search-forward regexp end t
)))
2061 (defvar rmail-search-last-regexp nil
)
2062 (defun rmail-search (regexp &optional n
)
2063 "Show message containing next match for REGEXP (but not the current msg).
2064 Prefix argument gives repeat count; negative argument means search
2065 backwards (through earlier messages).
2066 Interactively, empty argument means use same regexp used last time."
2068 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
2070 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
2072 (if rmail-search-last-regexp
2073 (setq prompt
(concat prompt
2075 rmail-search-last-regexp
2077 (setq regexp
(read-string prompt
))
2078 (cond ((not (equal regexp
""))
2079 (setq rmail-search-last-regexp regexp
))
2080 ((not rmail-search-last-regexp
)
2081 (error "No previous Rmail search string")))
2082 (list rmail-search-last-regexp
2083 (prefix-numeric-value current-prefix-arg
))))
2085 (message "%sRmail search for %s..."
2086 (if (< n
0) "Reverse " "")
2088 (rmail-maybe-set-message-counters)
2089 (let ((omin (point-min))
2094 (msg rmail-current-message
))
2099 ;; Check messages one by one, advancing message number up or down
2100 ;; but searching forward through each message.
2102 (while (and (null win
) (> msg
1))
2103 (goto-char (rmail-msgbeg (setq msg
(1- msg
))))
2104 (setq win
(re-search-forward
2105 regexp
(rmail-msgend msg
) t
)))
2106 (while (and (null win
) (< msg rmail-total-messages
))
2107 (goto-char (rmail-msgbeg (setq msg
(1+ msg
))))
2108 (setq win
(re-search-forward regexp
(rmail-msgend msg
) t
))))
2109 (setq n
(+ n
(if reversep
1 -
1)))))
2112 ;; If this is a reverse search and we found a message,
2113 ;; search backward thru this message to position point.
2116 (goto-char (rmail-msgend msg
))
2118 regexp
(rmail-msgbeg msg
) t
)))
2120 (rmail-show-message msg
)
2121 (message "%sRmail search for %s...done"
2122 (if reversep
"Reverse " "")
2126 (narrow-to-region omin omax
)
2128 (message "Search failed: %s" regexp
)))))
2130 (defun rmail-search-backwards (regexp &optional n
)
2131 "Show message containing previous match for REGEXP.
2132 Prefix argument gives repeat count; negative argument means search
2133 forward (through later messages).
2134 Interactively, empty argument means use same regexp used last time."
2136 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
2138 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
2140 (if rmail-search-last-regexp
2141 (setq prompt
(concat prompt
2143 rmail-search-last-regexp
2145 (setq regexp
(read-string prompt
))
2146 (cond ((not (equal regexp
""))
2147 (setq rmail-search-last-regexp regexp
))
2148 ((not rmail-search-last-regexp
)
2149 (error "No previous Rmail search string")))
2150 (list rmail-search-last-regexp
2151 (prefix-numeric-value current-prefix-arg
))))
2152 (rmail-search regexp
(- (or n
1))))
2154 ;; Show the first message which has the `unseen' attribute.
2155 (defun rmail-first-unseen-message ()
2156 (rmail-maybe-set-message-counters)
2161 (while (and (not found
) (<= current rmail-total-messages
))
2162 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
2163 (setq found current
))
2164 (setq current
(1+ current
))))
2165 ;; Let the caller show the message.
2167 ;; (rmail-show-message found))
2170 (defun rmail-next-same-subject (n)
2171 "Go to the next mail message having the same subject header.
2172 With prefix argument N, do this N times.
2173 If N is negative, go backwards instead."
2175 (let ((subject (mail-fetch-field "Subject"))
2177 (i rmail-current-message
)
2178 (case-fold-search t
)
2179 search-regexp found
)
2180 (if (string-match "Re:[ \t]*" subject
)
2181 (setq subject
(substring subject
(match-end 0))))
2182 (setq search-regexp
(concat "^Subject: *\\(Re: *\\)?"
2183 (regexp-quote subject
)
2188 (while (and (/= n
0)
2190 (< i rmail-total-messages
)
2193 (while (and (not done
)
2195 (< i rmail-total-messages
)
2197 (setq i
(if forward
(1+ i
) (1- i
)))
2198 (goto-char (rmail-msgbeg i
))
2199 (search-forward "\n*** EOOH ***\n")
2200 (let ((beg (point)) end
)
2201 (search-forward "\n\n")
2204 (setq done
(re-search-forward search-regexp end t
))))
2205 (if done
(setq found i
)))
2206 (setq n
(if forward
(1- n
) (1+ n
))))))
2208 (rmail-show-message found
)
2209 (error "No %s message with same subject"
2210 (if forward
"following" "previous")))))
2212 (defun rmail-previous-same-subject (n)
2213 "Go to the previous mail message having the same subject header.
2214 With prefix argument N, do this N times.
2215 If N is negative, go forwards instead."
2217 (rmail-next-same-subject (- n
)))
2219 ;;;; *** Rmail Message Deletion Commands ***
2221 (defun rmail-message-deleted-p (n)
2222 (= (aref rmail-deleted-vector n
) ?D
))
2224 (defun rmail-set-message-deleted-p (n state
)
2225 (aset rmail-deleted-vector n
(if state ?D ?\
)))
2227 (defun rmail-delete-message ()
2228 "Delete this message and stay on it."
2230 (rmail-set-attribute "deleted" t
)
2231 (run-hooks 'rmail-delete-message-hook
))
2233 (defun rmail-undelete-previous-message ()
2234 "Back up to deleted message, select it, and undelete it."
2236 (let ((msg rmail-current-message
))
2237 (while (and (> msg
0)
2238 (not (rmail-message-deleted-p msg
)))
2239 (setq msg
(1- msg
)))
2241 (error "No previous deleted message")
2242 (if (/= msg rmail-current-message
)
2243 (rmail-show-message msg
))
2244 (rmail-set-attribute "deleted" nil
)
2245 (if (rmail-summary-exists)
2247 (set-buffer rmail-summary-buffer
)
2248 (rmail-summary-mark-undeleted msg
)))
2249 (rmail-maybe-display-summary))))
2251 (defun rmail-delete-forward (&optional backward
)
2252 "Delete this message and move to next nondeleted one.
2253 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
2254 With prefix argument, delete and move backward.
2256 Returns t if a new message is displayed after the delete, or nil otherwise."
2258 (rmail-set-attribute "deleted" t
)
2259 (run-hooks 'rmail-delete-message-hook
)
2260 (let ((del-msg rmail-current-message
))
2261 (if (rmail-summary-exists)
2262 (rmail-select-summary
2263 (rmail-summary-mark-deleted del-msg
)))
2264 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
2265 (rmail-maybe-display-summary))))
2267 (defun rmail-delete-backward ()
2268 "Delete this message and move to previous nondeleted one.
2269 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
2271 (rmail-delete-forward t
))
2273 ;; Compute the message number a given message would have after expunging.
2274 ;; The present number of the message is OLDNUM.
2275 ;; DELETEDVEC should be rmail-deleted-vector.
2276 ;; The value is nil for a message that would be deleted.
2277 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
2278 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
2283 (if (/= (aref deletedvec i
) ?D
)
2284 (setq newnum
(1+ newnum
)))
2288 (defun rmail-only-expunge ()
2289 "Actually erase all deleted messages in the file."
2291 (message "Expunging deleted messages...")
2292 ;; Discard all undo records for this buffer.
2293 (or (eq buffer-undo-list t
)
2294 (setq buffer-undo-list nil
))
2295 (rmail-maybe-set-message-counters)
2296 (let* ((omax (- (buffer-size) (point-max)))
2297 (omin (- (buffer-size) (point-min)))
2298 (opoint (if (and (> rmail-current-message
0)
2299 (rmail-message-deleted-p rmail-current-message
))
2301 (- (point) (point-min))))
2302 (messages-head (cons (aref rmail-message-vector
0) nil
))
2303 (messages-tail messages-head
)
2304 ;; Don't make any undo records for the expunging.
2305 (buffer-undo-list t
)
2310 (goto-char (point-min))
2313 (total rmail-total-messages
)
2314 (new-message-number rmail-current-message
)
2316 (new-msgref (list (list 0)))
2317 (rmailbuf (current-buffer))
2318 (buffer-read-only nil
)
2319 (messages rmail-message-vector
)
2320 (deleted rmail-deleted-vector
)
2321 (summary rmail-summary-vector
))
2322 (setq rmail-total-messages nil
2323 rmail-current-message nil
2324 rmail-message-vector nil
2325 rmail-deleted-vector nil
2326 rmail-summary-vector nil
)
2328 (while (<= number total
)
2329 (if (= (aref deleted number
) ?D
)
2332 (marker-position (aref messages number
))
2333 (marker-position (aref messages
(1+ number
))))
2334 (move-marker (aref messages number
) nil
)
2335 (if (> new-message-number counter
)
2336 (setq new-message-number
(1- new-message-number
))))
2337 (setq counter
(1+ counter
))
2339 (setcdr messages-tail
2340 (cons (aref messages number
) nil
)))
2342 (cons (if (= counter number
) (aref summary
(1- number
)))
2345 (cons (aref rmail-msgref-vector number
)
2347 (setcar (car new-msgref
) counter
))
2348 (if (zerop (%
(setq number
(1+ number
)) 20))
2349 (message "Expunging deleted messages...%d" number
)))
2351 (setcdr messages-tail
2352 (cons (aref messages number
) nil
)))
2353 (setq rmail-current-message new-message-number
2354 rmail-total-messages counter
2355 rmail-message-vector
(apply 'vector messages-head
)
2356 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
2357 rmail-summary-vector
(vconcat (nreverse new-summary
))
2358 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
2360 (message "Expunging deleted messages...done")
2362 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
2364 (if (zerop rmail-current-message
) 1 nil
))
2365 (goto-char (+ (point) opoint
)))))
2367 (defun rmail-expunge ()
2368 "Erase deleted messages from Rmail file and summary buffer."
2370 (rmail-only-expunge)
2371 (if (rmail-summary-exists)
2372 (rmail-select-summary
2373 (rmail-update-summary))))
2375 ;;;; *** Rmail Mailing Commands ***
2377 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
2378 replybuffer sendactions same-window others
)
2381 (setq yank-action
(list 'insert-buffer replybuffer
)))
2382 (setq others
(cons (cons "cc" cc
) others
))
2383 (setq others
(cons (cons "in-reply-to" in-reply-to
) others
))
2385 (compose-mail to subject others
2387 yank-action sendactions
)
2388 (if (and window-system rmail-mail-new-frame
)
2390 (compose-mail to subject others
2391 noerase
'switch-to-buffer-other-frame
2392 yank-action sendactions
)
2393 ;; This is not a standard frame parameter;
2394 ;; nothing except sendmail.el looks at it.
2395 (modify-frame-parameters (selected-frame)
2396 '((mail-dedicated-frame . t
))))
2397 (compose-mail to subject others
2398 noerase
'switch-to-buffer-other-window
2399 yank-action sendactions
)))))
2401 (defun rmail-mail ()
2402 "Send mail in another window.
2403 While composing the message, use \\[mail-yank-original] to yank the
2404 original message into it."
2406 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
2408 (defun rmail-continue ()
2409 "Continue composing outgoing message previously being composed."
2411 (rmail-start-mail t
))
2413 (defun rmail-reply (just-sender)
2414 "Reply to the current message.
2415 Normally include CC: to all other recipients of original message;
2416 prefix argument means ignore them. While composing the reply,
2417 use \\[mail-yank-original] to yank the original message into it."
2419 (let (from reply-to cc subject date to message-id references
2420 resent-to resent-cc resent-reply-to
2421 (msgnum rmail-current-message
))
2425 (goto-char (rmail-msgbeg rmail-current-message
))
2427 (if (= (following-char) ?
0)
2429 (progn (forward-line 2)
2431 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
2434 (narrow-to-region (point)
2435 (progn (search-forward "\n*** EOOH ***\n")
2436 (beginning-of-line) (point))))
2437 (setq from
(mail-fetch-field "from")
2438 reply-to
(or (mail-fetch-field "reply-to" nil t
)
2440 cc
(and (not just-sender
)
2441 (mail-fetch-field "cc" nil t
))
2442 subject
(mail-fetch-field "subject")
2443 date
(mail-fetch-field "date")
2444 to
(or (mail-fetch-field "to" nil t
) "")
2445 message-id
(mail-fetch-field "message-id")
2446 references
(mail-fetch-field "references" nil nil t
)
2447 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
2448 resent-cc
(and (not just-sender
)
2449 (mail-fetch-field "resent-cc" nil t
))
2450 resent-to
(or (mail-fetch-field "resent-to" nil t
) "")
2451 ;;; resent-subject (mail-fetch-field "resent-subject")
2452 ;;; resent-date (mail-fetch-field "resent-date")
2453 ;;; resent-message-id (mail-fetch-field "resent-message-id")
2455 ;; Merge the resent-to and resent-cc into the to and cc.
2456 (if (and resent-to
(not (equal resent-to
"")))
2457 (if (not (equal to
""))
2458 (setq to
(concat to
", " resent-to
))
2459 (setq to resent-to
)))
2460 (if (and resent-cc
(not (equal resent-cc
"")))
2461 (if (not (equal cc
""))
2462 (setq cc
(concat cc
", " resent-cc
))
2463 (setq cc resent-cc
)))
2464 ;; Add `Re: ' to subject if not there already.
2465 (and (stringp subject
)
2467 (concat rmail-reply-prefix
2468 (if (let ((case-fold-search t
))
2469 (string-match rmail-reply-regexp subject
))
2470 (substring subject
(match-end 0))
2474 ;; Using mail-strip-quoted-names is undesirable with newer mailers
2475 ;; since they can handle the names unstripped.
2476 ;; I don't know whether there are other mailers that still
2477 ;; need the names to be stripped.
2478 (mail-strip-quoted-names reply-to
)
2480 (rmail-make-in-reply-to-field from date message-id
)
2483 ;; mail-strip-quoted-names is NOT necessary for rmail-dont-reply-to
2485 (let* ((cc-list (rmail-dont-reply-to
2486 (mail-strip-quoted-names
2487 (if (null cc
) to
(concat to
", " cc
))))))
2488 (if (string= cc-list
"") nil cc-list
)))
2490 (list (list 'rmail-mark-message
2492 (aref rmail-msgref-vector msgnum
)
2495 (list (cons "References" (concat (mapconcat 'identity references
" ")
2496 " " message-id
))))))
2498 (defun rmail-mark-message (buffer msgnum-list attribute
)
2499 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
2500 This is use in the send-actions for message buffers.
2501 MSGNUM-LIST is a list of the form (MSGNUM)
2502 which is an element of rmail-msgref-vector."
2505 (if (car msgnum-list
)
2506 (rmail-set-attribute attribute t
(car msgnum-list
)))))
2508 (defun rmail-make-in-reply-to-field (from date message-id
)
2515 (let ((tem (car (rfc822-addresses from
))))
2518 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
2519 (substring tem
0 (match-beginning 0))
2522 ;; Message-ID is sufficiently informative
2524 (concat message-id
" (" tem
")"))
2525 ;; Copy TEM, discarding text properties.
2526 (setq tem
(copy-sequence tem
))
2527 (set-text-properties 0 (length tem
) nil tem
)
2528 (setq tem
(copy-sequence tem
))
2529 ;; Use prin1 to fake RFC822 quoting
2530 (let ((field (prin1-to-string tem
)))
2532 (concat field
"'s message of " date
)
2534 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
2535 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
2536 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
2537 (or (string-match (concat "\\`[ \t]*\\(" bar
2538 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
2539 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
2541 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
2542 bar
"\\))[ \t]*\\'")
2543 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
2545 (let ((start (match-beginning 1))
2546 (end (match-end 1)))
2547 ;; Trim whitespace which above regexp match allows
2548 (while (and (< start end
)
2549 (memq (aref from start
) '(?
\t ?\
)))
2550 (setq start
(1+ start
)))
2551 (while (and (< start end
)
2552 (memq (aref from
(1- end
)) '(?
\t ?\
)))
2553 (setq end
(1- end
)))
2554 (let ((field (substring from start end
)))
2555 (if date
(setq field
(concat "message from " field
" on " date
)))
2557 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
2558 (concat message-id
" (" field
")")
2561 ;; If we can't kludge it simply, do it correctly
2562 (let ((mail-use-rfc822 t
))
2563 (rmail-make-in-reply-to-field from date message-id
)))))
2565 (defun rmail-forward (resend)
2566 "Forward the current message to another user.
2567 With prefix argument, \"resend\" the message instead of forwarding it;
2568 see the documentation of `rmail-resend'."
2571 (call-interactively 'rmail-resend
)
2572 (let ((forward-buffer (current-buffer))
2573 (msgnum rmail-current-message
)
2574 (subject (concat "["
2575 (let ((from (or (mail-fetch-field "From")
2576 (mail-fetch-field ">From"))))
2578 (concat (mail-strip-quoted-names from
) ": ")
2580 (or (mail-fetch-field "Subject") "")
2582 (if (rmail-start-mail
2583 nil nil subject nil nil nil
2584 (list (list 'rmail-mark-message
2586 (aref rmail-msgref-vector msgnum
)
2588 ;; If only one window, use it for the mail buffer.
2589 ;; Otherwise, use another window for the mail buffer
2590 ;; so that the Rmail buffer remains visible
2591 ;; and sending the mail will get back to it.
2592 (and (not rmail-mail-new-frame
) (one-window-p t
)))
2593 ;; The mail buffer is now current.
2595 ;; Insert after header separator--before signature if any.
2596 (goto-char (point-min))
2597 (search-forward-regexp
2598 (concat "^" (regexp-quote mail-header-separator
) "$"))
2600 (insert "------- Start of forwarded message -------\n")
2601 ;; Quote lines with `- ' if they start with `-'.
2602 (let ((beg (point)) end
)
2603 (setq end
(point-marker))
2604 (set-marker-insertion-type end t
)
2605 (insert-buffer-substring forward-buffer
)
2607 (while (re-search-forward "^-" end t
)
2612 (skip-chars-backward "\n")
2615 (delete-region (point) end
)
2616 (set-marker end nil
))
2617 (insert "------- End of forwarded message -------\n")
2620 (defun rmail-resend (address &optional from comment mail-alias-file
)
2621 "Resend current message to ADDRESSES.
2622 ADDRESSES should be a single address, a string consisting of several
2623 addresses separated by commas, or a list of addresses.
2625 Optional FROM is the address to resend the message from, and
2626 defaults to the username of the person redistributing the message.
2627 Optional COMMENT is a string that will be inserted as a comment in the
2629 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
2630 typically for purposes of moderating a list."
2631 (interactive "sResend to: ")
2633 (require 'mailalias
)
2634 (if (not from
) (setq from
(user-login-name)))
2635 (let ((tembuf (generate-new-buffer " sendmail temp"))
2636 (mail-header-separator "")
2637 (case-fold-search nil
)
2638 (mailbuf (current-buffer)))
2641 ;;>> Copy message into temp buffer
2643 (insert-buffer-substring mailbuf
)
2644 (goto-char (point-min))
2645 ;; Delete any Sender field, since that's not specifiable.
2646 ; Only delete Sender fields in the actual header.
2647 (re-search-forward "^$" nil
'move
)
2648 ; Using "while" here rather than "if" because some buggy mail
2649 ; software may have inserted multiple Sender fields.
2650 (while (re-search-backward "^Sender:" nil t
)
2654 (while (looking-at "[ \t]")
2656 (delete-region beg
(point))))
2657 ; Go back to the beginning of the buffer so the Resent- fields
2658 ; are inserted there.
2659 (goto-char (point-min))
2660 ;;>> Insert resent-from:
2661 (insert "Resent-From: " from
"\n")
2662 (insert "Resent-Date: " (mail-rfc822-date) "\n")
2663 ;;>> Insert resent-to: and bcc if need be.
2664 (let ((before (point)))
2666 (insert "Resent-Bcc: " (user-login-name) "\n"))
2667 (insert "Resent-To: " (if (stringp address
)
2669 (mapconcat 'identity address
",\n\t"))
2671 ;; Expand abbrevs in the recipients.
2673 (if (featurep 'mailabbrev
)
2674 (let ((end (point-marker))
2675 (local-abbrev-table mail-abbrevs
)
2676 (old-syntax-table (syntax-table)))
2677 (if (and (not (vectorp mail-abbrevs
))
2678 (file-exists-p mail-personal-alias-file
))
2679 (build-mail-abbrevs))
2680 (set-syntax-table mail-abbrev-syntax-table
)
2682 (while (and (< (point) end
)
2683 (progn (forward-word 1)
2686 (set-syntax-table old-syntax-table
))
2687 (expand-mail-aliases before
(point)))))
2688 ;;>> Set up comment, if any.
2689 (if (and (sequencep comment
) (not (zerop (length comment
))))
2690 (let ((before (point))
2693 (or (eolp) (insert "\n"))
2694 (setq after
(point))
2696 (while (< (point) after
)
2697 (insert "Resent-Comment: ")
2699 ;; Don't expand aliases in the destination fields
2700 ;; of the original message.
2702 (funcall send-mail-function
)))
2703 (kill-buffer tembuf
))
2704 (rmail-set-attribute "resent" t rmail-current-message
)))
2706 (defvar mail-unsent-separator
2707 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
2708 "^ *---+ +Returned message +---+ *$\\|"
2709 "^Start of returned message$\\|"
2710 "^ *---+ +Original message +---+ *$\\|"
2711 "^ *--+ +begin message +--+ *$\\|"
2712 "^ *---+ +Original message follows +---+ *$\\|"
2713 "^|? *---+ +Message text follows: +---+ *|?$")
2714 "A regexp that matches the separator before the text of a failed message.")
2716 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
2717 "A regexp that matches the header of a MIME body part with a failed message.")
2719 (defun rmail-retry-failure ()
2720 "Edit a mail message which is based on the contents of the current message.
2721 For a message rejected by the mail system, extract the interesting headers and
2722 the body of the original message.
2723 If the failed message is a MIME multipart message, it is searched for a
2724 body part with a header which matches the variable `mail-mime-unsent-header'.
2725 Otherwise, the variable `mail-unsent-separator' should match the string that
2726 delimits the returned original message.
2727 The variable `rmail-retry-ignored-headers' is a regular expression
2728 specifying headers which should not be copied into the new message."
2730 (require 'mail-utils
)
2731 (let ((rmail-this-buffer (current-buffer))
2732 (msgnum rmail-current-message
)
2733 bounce-start bounce-end bounce-indent resending
)
2735 ;; Narrow down to just the quoted original message
2736 (rmail-beginning-of-message)
2737 (let* ((case-fold-search t
)
2741 ;; Fetch any content-type header in current message
2742 (search-forward "\n\n") (narrow-to-region top
(point))
2743 (mail-fetch-field "Content-Type") )) )
2744 ;; Handle MIME multipart bounce messages
2745 (if (and content-type
2747 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=?]+\\)\"?"
2751 (substring content-type
(match-beginning 1)
2753 (or (re-search-forward mail-mime-unsent-header nil t
)
2754 (error "Cannot find beginning of header in failed message"))
2755 (or (search-forward "\n\n" nil t
)
2756 (error "Cannot find end of Mime data in failed message"))
2757 (setq bounce-start
(point))
2758 (or (search-forward codestring nil t
)
2759 (error "Cannot find end of Mime data in failed message"))
2760 (setq bounce-end
(match-beginning 0))
2761 ; (or (search-forward "\n\n" nil t)
2762 ; (error "Cannot find end of header in failed message"))
2765 (or (re-search-forward mail-unsent-separator nil t
)
2766 (error "Cannot parse this as a failure message"))
2767 (skip-chars-forward "\n")
2768 ;; Support a style of failure message in which the original
2769 ;; message is indented, and included within lines saying
2770 ;; `Start of returned message' and `End of returned message'.
2771 (if (looking-at " +Received:")
2773 (setq bounce-start
(point))
2774 (skip-chars-forward " ")
2775 (setq bounce-indent
(- (current-column)))
2776 (goto-char (point-max))
2777 (re-search-backward "^End of returned message$" nil t
)
2778 (setq bounce-end
(point)))
2779 ;; One message contained a few random lines before the old
2780 ;; message header. The first line of the message started with
2781 ;; two hyphens. A blank line followed these random lines.
2782 ;; The same line beginning with two hyphens was possibly
2783 ;; marking the end of the message.
2784 (if (looking-at "^--")
2785 (let ((boundary (buffer-substring-no-properties
2787 (progn (end-of-line) (point)))))
2788 (search-forward "\n\n")
2789 (skip-chars-forward "\n")
2790 (setq bounce-start
(point))
2791 (goto-char (point-max))
2792 (search-backward (concat "\n\n" boundary
) bounce-start t
)
2793 (setq bounce-end
(point)))
2794 (setq bounce-start
(point)
2795 bounce-end
(point-max)))
2796 (or (search-forward "\n\n" nil t
)
2797 (error "Cannot find end of header in failed message"))
2799 ;; Start sending a new message; default header fields from the original.
2800 ;; Turn off the usual actions for initializing the message body
2801 ;; because we want to get only the text from the failure message.
2802 (let (mail-signature mail-setup-hook
)
2803 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
2804 (list (list 'rmail-mark-message
2806 (aref rmail-msgref-vector msgnum
)
2808 ;; Insert original text as initial text of new draft message.
2809 ;; Bind inhibit-read-only since the header delimiter
2810 ;; of the previous message was probably read-only.
2811 (let ((inhibit-read-only t
))
2813 (insert-buffer-substring rmail-this-buffer bounce-start bounce-end
)
2814 (goto-char (point-min))
2816 (indent-rigidly (point-min) (point-max) bounce-indent
))
2817 (rmail-clear-headers rmail-retry-ignored-headers
)
2818 (rmail-clear-headers "^sender:\\|^from:\\|^return-path:")
2819 (goto-char (point-min))
2821 (search-forward "\n\n")
2823 (narrow-to-region (point-min) (point))
2824 (setq resending
(mail-fetch-field "resent-to"))
2827 (insert "Resent-Bcc: " (user-login-name) "\n")
2828 (insert "BCC: " (user-login-name) "\n"))))
2829 (insert mail-header-separator
)
2830 (mail-position-on-field (if resending
"Resent-To" "To") t
)
2831 (set-buffer rmail-this-buffer
)
2832 (rmail-beginning-of-message))))))
2834 (defun rmail-summary-exists ()
2835 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
2836 In fact, the non-nil value returned is the summary buffer itself."
2837 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
2838 rmail-summary-buffer
))
2840 (defun rmail-summary-displayed ()
2841 "t iff in RMAIL buffer and an associated summary buffer is displayed."
2842 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
2844 (defcustom rmail-redisplay-summary nil
2845 "*Non-nil means Rmail should show the summary when it changes.
2846 This has an effect only if a summary buffer exists."
2848 :group
'rmail-summary
)
2850 (defcustom rmail-summary-window-size nil
2851 "*Non-nil means specify the height for an Rmail summary window."
2853 :group
'rmail-summary
)
2855 ;; Put the summary buffer back on the screen, if user wants that.
2856 (defun rmail-maybe-display-summary ()
2857 (let ((selected (selected-window))
2859 ;; If requested, make sure the summary is displayed.
2860 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
2861 rmail-redisplay-summary
2862 (if (get-buffer-window rmail-summary-buffer
0)
2863 ;; It's already in some frame; show that one.
2864 (let ((frame (window-frame
2865 (get-buffer-window rmail-summary-buffer
0))))
2866 (make-frame-visible frame
)
2867 (raise-frame frame
))
2868 (display-buffer rmail-summary-buffer
)))
2869 ;; If requested, set the height of the summary window.
2870 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
2871 rmail-summary-window-size
2872 (setq window
(get-buffer-window rmail-summary-buffer
))
2873 ;; Don't try to change the size if just one window in frame.
2874 (not (eq window
(frame-root-window (window-frame window
))))
2877 (select-window window
)
2878 (enlarge-window (- rmail-summary-window-size
(window-height))))
2879 (select-window selected
)))))
2881 ;;;; *** Rmail Local Fontification ***
2883 (defun rmail-fontify-buffer-function ()
2884 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
2885 (make-local-hook 'rmail-show-message-hook
)
2886 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
2887 ;; If we're already showing a message, fontify it now.
2888 (if rmail-current-message
(rmail-fontify-message))
2889 ;; Prevent Font Lock mode from kicking in.
2890 (setq font-lock-fontified t
))
2892 (defun rmail-unfontify-buffer-function ()
2893 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
2894 (let ((modified (buffer-modified-p))
2895 (buffer-undo-list t
) (inhibit-read-only t
)
2896 before-change-functions after-change-functions
2897 buffer-file-name buffer-file-truename
)
2900 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
2901 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
2902 (font-lock-default-unfontify-buffer)
2903 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))
2905 (defun rmail-fontify-message ()
2906 ;; Fontify the current message if it is not already fontified.
2907 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
2908 (let ((modified (buffer-modified-p))
2909 (buffer-undo-list t
) (inhibit-read-only t
)
2910 before-change-functions after-change-functions
2911 buffer-file-name buffer-file-truename
)
2914 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
2915 (font-lock-fontify-region (point-min) (point-max))
2916 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))))
2920 ;;; rmail.el ends here