1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
3 ;; Copyright (C) 1985,86,87,88,93,94,95,96 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")
54 (defvar rmail-movemail-program nil
55 "If non-nil, name of program for fetching new mail.")
57 (defvar rmail-pop-password nil
58 "*Password to use when reading mail from a POP server, if required.")
60 (defvar rmail-pop-password-required nil
61 "*Non-nil if a password is required when reading mail using POP.")
63 (defvar rmail-preserve-inbox nil
64 "*Non-nil if incoming mail should be left in the user's inbox,
65 rather than deleted, after it is retrieved.")
68 (defvar rmail-dont-reply-to-names nil
"\
69 *A regexp specifying names to prune of reply to messages.
70 A value of nil means exclude your own name only.")
73 (defvar rmail-default-dont-reply-to-names
"info-" "\
74 A regular expression specifying part of the value of the default value of
75 the variable `rmail-dont-reply-to-names', for when the user does not set
76 `rmail-dont-reply-to-names' explicitly. (The other part of the default
77 value is the user's name.)
78 It is useful to set this variable in the site customization file.")
81 (defvar rmail-ignored-headers
"^via:\\|^mail-from:\\|^origin:\\|^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:"
82 "*Regexp to match header fields that Rmail should normally hide.")
85 (defvar rmail-displayed-headers nil
86 "*Regexp to match Header fields that Rmail should display.
87 If nil, display all header fields except those matched by
88 `rmail-ignored-headers'.")
91 (defvar rmail-retry-ignored-headers nil
"\
92 *Headers that should be stripped when retrying a failed message.")
95 (defvar rmail-highlighted-headers
"^From:\\|^Subject:" "\
96 *Regexp to match Header fields that Rmail should normally highlight.
97 A value of nil means don't highlight.
98 See also `rmail-highlight-face'.")
101 (defvar rmail-highlight-face nil
"\
102 *Face used by Rmail for highlighting headers.")
105 (defvar rmail-delete-after-output nil
"\
106 *Non-nil means automatically delete a message that is copied to a file.")
109 (defvar rmail-primary-inbox-list nil
"\
110 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
111 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
112 \(the name varies depending on the operating system,
113 and the value of the environment variable MAIL overrides it).")
116 (defvar rmail-mail-new-frame nil
117 "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
120 (defvar rmail-secondary-file-directory
"~/"
121 "*Directory for additional secondary Rmail files.")
123 (defvar rmail-secondary-file-regexp
"\\.xmail$"
124 "*Regexp for which files are secondary Rmail files.")
127 (defvar rmail-mode-hook nil
128 "List of functions to call when Rmail is invoked.")
131 (defvar rmail-get-new-mail-hook nil
132 "List of functions to call when Rmail has retrieved new mail.")
135 (defvar rmail-show-message-hook nil
136 "List of functions to call when Rmail displays a message.")
139 (defvar rmail-delete-message-hook nil
140 "List of functions to call when Rmail deletes a message.
141 When the hooks are called, the message has been marked deleted but is
142 still the current message in the Rmail buffer.")
144 ;; These may be altered by site-init.el to match the format of mmdf files
145 ;; delimiting used on a given host (delim1 and delim2 from the config
148 (defvar mmdf-delim1
"^\001\001\001\001\n"
149 "Regexp marking the start of an mmdf message")
150 (defvar mmdf-delim2
"^\001\001\001\001\n"
151 "Regexp marking the end of an mmdf message")
153 (defvar rmail-message-filter nil
154 "If non-nil, a filter function for new messages in RMAIL.
155 Called with region narrowed to the message, including headers,
156 before obeying `rmail-ignored-headers'.")
158 (defvar rmail-reply-prefix
"Re: "
159 "String to prepend to Subject line when replying to a message.")
161 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
162 ;; This pattern should catch all the common variants.
163 (defvar rmail-reply-regexp
"\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
164 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
166 (defvar rmail-display-summary nil
167 "If non-nil, Rmail always displays the summary buffer.")
169 (defvar rmail-mode-map nil
)
171 (defvar rmail-inbox-list nil
)
172 (defvar rmail-keywords nil
)
174 ;; Message counters and markers. Deleted flags.
176 (defvar rmail-current-message nil
)
177 (defvar rmail-total-messages nil
)
178 (defvar rmail-message-vector nil
)
179 (defvar rmail-deleted-vector nil
)
181 (defvar rmail-overlay-list nil
)
183 (defvar rmail-font-lock-keywords
185 (let* ((cite-chars "[>|}]")
186 (cite-prefix "A-Za-z")
187 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
188 (list '("^\\(From\\|Sender\\):" . font-lock-function-name-face
)
189 '("^Reply-To:.*$" . font-lock-function-name-face
)
190 '("^Subject:" . font-lock-comment-face
)
191 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
192 . font-lock-keyword-face
)
193 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
195 (,(concat "\\=[ \t]*"
196 "\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
197 "\\(" cite-chars
"[ \t]*\\)\\)+"
199 (beginning-of-line) (end-of-line)
200 (2 font-lock-reference-face nil t
)
201 (4 font-lock-comment-face nil t
)))
202 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\|Date\\):.*$"
203 . font-lock-string-face
))))
204 "Additional expressions to highlight in Rmail mode.")
206 ;; These are used by autoloaded rmail-summary.
208 (defvar rmail-summary-buffer nil
)
209 (defvar rmail-summary-vector nil
)
211 ;; `Sticky' default variables.
213 ;; Last individual label specified to a or k.
214 (defvar rmail-last-label nil
)
215 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
216 (defvar rmail-last-multi-labels nil
)
217 (defvar rmail-last-regexp nil
)
218 (defvar rmail-default-file
"~/xmail"
219 "*Default file name for \\[rmail-output].")
220 (defvar rmail-default-rmail-file
"~/XMAIL"
221 "*Default file name for \\[rmail-output-to-rmail-file].")
223 ;;; Regexp matching the delimiter of messages in UNIX mail format
224 ;;; (UNIX From lines), minus the initial ^. Note that if you change
225 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
226 ;;; that knows the exact ordering of the \\( \\) subexpressions.
227 (defvar rmail-unix-mail-delimiter
228 (let ((time-zone-regexp
229 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
230 "\\|[-+]?[0-9][0-9][0-9][0-9]"
236 ;; Many things can happen to an RFC 822 mailbox before it is put into
237 ;; a `From' line. The leading phrase can be stripped, e.g.
238 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
239 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
240 ;; can be removed, e.g.
241 ;; From: joe@y.z (Joe K
243 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
246 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
247 ;; The mailbox can be removed or be replaced by white space, e.g.
248 ;; From: "Joe User"{space}{tab}
250 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
251 ;; where {space} and {tab} represent the Ascii space and tab characters.
252 ;; We want to match the results of any of these manglings.
253 ;; The following regexp rejects names whose first characters are
254 ;; obviously bogus, but after that anything goes.
255 "\\([^\0-\b\n-\r\^?].*\\)? "
257 ;; The time the message was sent.
258 "\\([^\0-\r \^?]+\\) +" ; day of the week
259 "\\([^\0-\r \^?]+\\) +" ; month
260 "\\([0-3]?[0-9]\\) +" ; day of month
261 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
263 ;; Perhaps a time zone, specified by an abbreviation, or by a
268 " \\([0-9][0-9]+\\) *"
270 ;; On some systems the time zone can appear after the year, too.
274 "\\(remote from .*\\)?"
279 ;; Perform BODY in the summary buffer
280 ;; in such a way that its cursor is properly updated in its own window.
281 (defmacro rmail-select-summary
(&rest body
)
282 (` (let ((total rmail-total-messages
))
283 (if (rmail-summary-displayed)
284 (let ((window (selected-window)))
288 (pop-to-buffer rmail-summary-buffer
)
289 ;; rmail-total-messages is a buffer-local var
290 ;; in the rmail buffer.
291 ;; This way we make it available for the body
292 ;; even tho the rmail buffer is not current.
293 (let ((rmail-total-messages total
))
295 (select-window window
))))
297 (set-buffer rmail-summary-buffer
)
298 (let ((rmail-total-messages total
))
300 (rmail-maybe-display-summary))))
302 (defvar rmail-view-buffer nil
303 "Buffer which holds RMAIL message for displaying.")
305 ;; Mule and MIME related variables.
308 (defvar rmail-file-coding-system nil
309 "Coding system used in RMAIL file.
311 This is set to nil by default.")
314 (defvar rmail-enable-mime nil
315 "*If non-nil, RMAIL uses MIME feature.
316 If the value is t, RMAIL automatically shows MIME decoded message.
317 If the value is neither t nor nil, RMAIL does not show MIME decoded message
318 until a user explicitly require it.")
321 (defvar rmail-show-mime-function nil
322 "Function to show MIME decoded message of RMAIL file.")
325 (defvar rmail-mime-feature
'rmail-mime
326 "Feature to provide for using MIME feature in RMAIL.
327 When starting rmail, this feature is requrired if rmail-enable-mime
331 ;;;; *** Rmail Mode ***
334 (defun rmail (&optional file-name-arg
)
335 "Read and edit incoming mail.
336 Moves messages into file named by `rmail-file-name' (a babyl format file)
337 and edits that file in RMAIL Mode.
338 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
340 May be called with file name as argument; then performs rmail editing on
341 that file, but does not copy any new mail into the file.
342 Interactively, if you supply a prefix argument, then you
343 have a chance to specify a file name with the minibuffer.
345 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
346 (interactive (if current-prefix-arg
347 (list (read-file-name "Run rmail on RMAIL file: "))))
348 (if rmail-enable-mime
350 (require rmail-mime-feature
)
351 (error (message "Feature `%s' not provided" rmail-mime-feature
)
353 (setq rmail-enable-mime nil
))))
354 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
355 (existed (get-file-buffer file-name
))
356 (coding-system-for-read 'no-conversion
)
358 ;; Like find-file, but in the case where a buffer existed
359 ;; and the file was reverted, recompute the message-data.
360 (if (and existed
(not (verify-visited-file-modtime existed
)))
362 ;; Don't be confused by apparent local-variables spec
363 ;; in the last message in the RMAIL file.
364 (let ((enable-local-variables nil
))
365 (find-file file-name
))
366 (if (and (verify-visited-file-modtime existed
)
367 (eq major-mode
'rmail-mode
))
368 (progn (rmail-forget-messages)
369 (rmail-set-message-counters))))
370 (let ((enable-local-variables nil
))
371 (find-file file-name
)))
372 (if (eq major-mode
'rmail-edit-mode
)
373 (error "Exit Rmail Edit mode before getting new mail."))
374 (if (and existed
(> (buffer-size) 0))
375 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
376 (or (eq major-mode
'rmail-mode
)
377 (progn (rmail-mode-2)
378 (setq run-mail-hook t
)))
379 (setq run-mail-hook t
)
381 ;; Convert all or part to Babyl file if possible.
383 (goto-char (point-max))
384 (if (null rmail-inbox-list
)
386 (rmail-set-message-counters)
387 (rmail-show-message))))
388 (or (and (null file-name-arg
)
389 (rmail-get-new-mail))
390 (rmail-show-message (rmail-first-unseen-message)))
391 (if rmail-display-summary
(rmail-summary))
392 (rmail-construct-io-menu)
394 (run-hooks 'rmail-mode-hook
))))
396 ;; Given the value of MAILPATH, return a list of inbox file names.
397 ;; This is turned off because it is not clear that the user wants
398 ;; all these inboxes to feed into the primary rmail file.
399 ; (defun rmail-convert-mailpath (string)
401 ; (while (setq idx (string-match "[%:]" string))
402 ; (let ((this (substring string 0 idx)))
403 ; (setq string (substring string (1+ idx)))
404 ; (setq list (cons (if (string-match "%" this)
405 ; (substring this 0 (string-match "%" this))
410 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
411 ; will not cause emacs 18.55 problems.
413 (defun rmail-convert-file ()
416 (goto-char (point-min))
417 ;; If file doesn't start like a Babyl file,
418 ;; convert it to one, by adding a header and converting each message.
419 (cond ((looking-at "BABYL OPTIONS:"))
420 ((looking-at "Version: 5\n")
421 ;; Losing babyl file made by old version of Rmail.
422 ;; Just fix the babyl file header; don't make a new one,
423 ;; so we don't lose the Labels: file attribute, etc.
424 (let ((buffer-read-only nil
))
425 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
426 ((equal (point-min) (point-max))
427 ;; Empty RMAIL file. Just insert the header.
428 (rmail-insert-rmail-file-header))
430 ;; Non-empty file in non-RMAIL format. Add header and convert.
432 (rmail-insert-rmail-file-header)))
433 (if (and (not convert
)
434 (not rmail-enable-mime
)
435 rmail-file-coding-system
)
436 ;; Decode BABYL part at the headq only. The remaining non
437 ;; BABYL parts are decode in rmail-convert-to-babyl-format if
439 (rmail-decode-babyl-format))
440 ;; If file was not a Babyl file or if there are
441 ;; Unix format messages added at the end,
442 ;; convert file as necessary.
445 (goto-char (point-max))
446 (search-backward "\n\^_")
448 (looking-at "\n*From ")))
449 (let ((buffer-read-only nil
))
450 (message "Converting to Babyl format...")
451 ;; If file needs conversion, convert it all,
452 ;; except for the BABYL header.
453 ;; (rmail-convert-to-babyl-format would delete the header.)
454 (goto-char (point-min))
455 (search-forward "\n\^_" nil t
)
456 (narrow-to-region (point) (point-max))
457 (rmail-convert-to-babyl-format)
458 (message "Converting to Babyl format...done")))))
460 ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
461 ;;; will not cause emacs 18.55 problems.
463 (defun rmail-insert-rmail-file-header ()
464 (let ((buffer-read-only nil
))
465 (insert "BABYL OPTIONS: -*- rmail -*-
468 Note: This is the header of an rmail file.
469 Note: If you are seeing it in rmail,
470 Note: it means the file has no messages in it.\n\^_")))
472 ;; Decode Babyl formated part at the head of current buffer by
473 ;; rmail-file-coding-system.
475 (defun rmail-decode-babyl-format ()
476 (let ((modifiedp (buffer-modified-p))
477 (buffer-read-only nil
)
479 (goto-char (point-min))
480 (search-forward "\n\^_" nil t
) ; Skip BYBYL header.
482 (message "Decoding messages...")
483 (while (search-forward "\n\^_" nil t
)
484 (decode-coding-region pos
(point) rmail-file-coding-system
)
486 (message "Decoding messages...done")
487 (set-buffer-file-coding-system rmail-file-coding-system
)
488 (set-buffer-modified-p modifiedp
)))
492 (setq rmail-mode-map
(make-keymap))
493 (suppress-keymap rmail-mode-map
)
494 (define-key rmail-mode-map
"a" 'rmail-add-label
)
495 (define-key rmail-mode-map
"b" 'rmail-bury
)
496 (define-key rmail-mode-map
"c" 'rmail-continue
)
497 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
498 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
)
499 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
500 (define-key rmail-mode-map
"f" 'rmail-forward
)
501 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
502 (define-key rmail-mode-map
"h" 'rmail-summary
)
503 (define-key rmail-mode-map
"i" 'rmail-input
)
504 (define-key rmail-mode-map
"j" 'rmail-show-message
)
505 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
506 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
507 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
508 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
509 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
510 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
511 (define-key rmail-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
512 (define-key rmail-mode-map
"m" 'rmail-mail
)
513 (define-key rmail-mode-map
"\em" 'rmail-retry-failure
)
514 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
515 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
516 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
517 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
518 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
519 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
520 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
521 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
522 (define-key rmail-mode-map
"q" 'rmail-quit
)
523 (define-key rmail-mode-map
"r" 'rmail-reply
)
524 ;; I find I can't live without the default M-r command -- rms.
525 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
526 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
527 (define-key rmail-mode-map
"\es" 'rmail-search
)
528 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
529 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
530 (define-key rmail-mode-map
"w" 'rmail-edit-current-message
)
531 (define-key rmail-mode-map
"x" 'rmail-expunge
)
532 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
533 (define-key rmail-mode-map
"<" 'rmail-first-message
)
534 (define-key rmail-mode-map
">" 'rmail-last-message
)
535 (define-key rmail-mode-map
" " 'scroll-up
)
536 (define-key rmail-mode-map
"\177" 'scroll-down
)
537 (define-key rmail-mode-map
"?" 'describe-mode
)
538 (define-key rmail-mode-map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
539 (define-key rmail-mode-map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
540 (define-key rmail-mode-map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
541 (define-key rmail-mode-map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
542 (define-key rmail-mode-map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
543 (define-key rmail-mode-map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
544 (define-key rmail-mode-map
"\C-c\C-s\C-k" 'rmail-sort-by-keywords
)
545 (define-key rmail-mode-map
"\C-c\C-n" 'rmail-next-same-subject
)
546 (define-key rmail-mode-map
"\C-c\C-p" 'rmail-previous-same-subject
)
549 (define-key rmail-mode-map
[menu-bar
] (make-sparse-keymap))
551 (define-key rmail-mode-map
[menu-bar classify
]
552 (cons "Classify" (make-sparse-keymap "Classify")))
554 (define-key rmail-mode-map
[menu-bar classify input-menu
]
557 (define-key rmail-mode-map
[menu-bar classify output-menu
]
560 (define-key rmail-mode-map
[menu-bar classify output-inbox
]
561 '("Output (inbox)..." . rmail-output
))
563 (define-key rmail-mode-map
[menu-bar classify output
]
564 '("Output (Rmail)..." . rmail-output-to-rmail-file
))
566 (define-key rmail-mode-map
[menu-bar classify kill-label
]
567 '("Kill Label..." . rmail-kill-label
))
569 (define-key rmail-mode-map
[menu-bar classify add-label
]
570 '("Add Label..." . rmail-add-label
))
572 (define-key rmail-mode-map
[menu-bar summary
]
573 (cons "Summary" (make-sparse-keymap "Summary")))
575 (define-key rmail-mode-map
[menu-bar summary senders
]
576 '("By Senders..." . rmail-summary-by-senders
))
578 (define-key rmail-mode-map
[menu-bar summary labels
]
579 '("By Labels..." . rmail-summary-by-labels
))
581 (define-key rmail-mode-map
[menu-bar summary recipients
]
582 '("By Recipients..." . rmail-summary-by-recipients
))
584 (define-key rmail-mode-map
[menu-bar summary topic
]
585 '("By Topic..." . rmail-summary-by-topic
))
587 (define-key rmail-mode-map
[menu-bar summary regexp
]
588 '("By Regexp..." . rmail-summary-by-regexp
))
590 (define-key rmail-mode-map
[menu-bar summary all
]
591 '("All" . rmail-summary
))
593 (define-key rmail-mode-map
[menu-bar mail
]
594 (cons "Mail" (make-sparse-keymap "Mail")))
596 (define-key rmail-mode-map
[menu-bar mail rmail-get-new-mail
]
597 '("Get New Mail" . rmail-get-new-mail
))
599 (define-key rmail-mode-map
[menu-bar mail lambda
]
602 (define-key rmail-mode-map
[menu-bar mail continue
]
603 '("Continue" . rmail-continue
))
605 (define-key rmail-mode-map
[menu-bar mail resend
]
606 '("Re-send..." . rmail-resend
))
608 (define-key rmail-mode-map
[menu-bar mail forward
]
609 '("Forward" . rmail-forward
))
611 (define-key rmail-mode-map
[menu-bar mail retry
]
612 '("Retry" . rmail-retry-failure
))
614 (define-key rmail-mode-map
[menu-bar mail reply
]
615 '("Reply" . rmail-reply
))
617 (define-key rmail-mode-map
[menu-bar mail mail
]
618 '("Mail" . rmail-mail
))
620 (define-key rmail-mode-map
[menu-bar delete
]
621 (cons "Delete" (make-sparse-keymap "Delete")))
623 (define-key rmail-mode-map
[menu-bar delete expunge
/save
]
624 '("Expunge/Save" . rmail-expunge-and-save
))
626 (define-key rmail-mode-map
[menu-bar delete expunge
]
627 '("Expunge" . rmail-expunge
))
629 (define-key rmail-mode-map
[menu-bar delete undelete
]
630 '("Undelete" . rmail-undelete-previous-message
))
632 (define-key rmail-mode-map
[menu-bar delete delete
]
633 '("Delete" . rmail-delete-forward
))
635 (define-key rmail-mode-map
[menu-bar move
]
636 (cons "Move" (make-sparse-keymap "Move")))
638 (define-key rmail-mode-map
[menu-bar move search-back
]
639 '("Search Back..." . rmail-search-backwards
))
641 (define-key rmail-mode-map
[menu-bar move search
]
642 '("Search..." . rmail-search
))
644 (define-key rmail-mode-map
[menu-bar move previous
]
645 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
647 (define-key rmail-mode-map
[menu-bar move next
]
648 '("Next Nondeleted" . rmail-next-undeleted-message
))
650 (define-key rmail-mode-map
[menu-bar move last
]
651 '("Last" . rmail-last-message
))
653 (define-key rmail-mode-map
[menu-bar move first
]
654 '("First" . rmail-first-message
))
656 (define-key rmail-mode-map
[menu-bar move previous
]
657 '("Previous" . rmail-previous-message
))
659 (define-key rmail-mode-map
[menu-bar move next
]
660 '("Next" . rmail-next-message
))
662 ;; Rmail mode is suitable only for specially formatted data.
663 (put 'rmail-mode
'mode-class
'special
)
665 (defun rmail-mode-kill-summary ()
666 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
670 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
671 All normal editing commands are turned off.
672 Instead, these commands are available:
674 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
675 \\[scroll-up] Scroll to next screen of this message.
676 \\[scroll-down] Scroll to previous screen of this message.
677 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
678 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
679 \\[rmail-next-message] Move to Next message whether deleted or not.
680 \\[rmail-previous-message] Move to Previous message whether deleted or not.
681 \\[rmail-first-message] Move to the first message in Rmail file.
682 \\[rmail-last-message] Move to the last message in Rmail file.
683 \\[rmail-show-message] Jump to message specified by numeric position in file.
684 \\[rmail-search] Search for string and show message it is found in.
685 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
686 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
687 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
688 till a deleted message is found.
689 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
690 \\[rmail-expunge] Expunge deleted messages.
691 \\[rmail-expunge-and-save] Expunge and save the file.
692 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
693 \\[save-buffer] Save without expunging.
694 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
695 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
696 \\[rmail-continue] Continue composing outgoing message started before.
697 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
698 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
699 \\[rmail-forward] Forward this message to another user.
700 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
701 \\[rmail-output] Output this message to a Unix-format mail file (append it).
702 \\[rmail-input] Input Rmail file. Run Rmail on that file.
703 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
704 \\[rmail-kill-label] Kill label. Remove a label from current message.
705 \\[rmail-next-labeled-message] Move to Next message with specified label
706 (label defaults to last one specified).
707 Standard labels: filed, unseen, answered, forwarded, deleted.
708 Any other label is present only if you add it with \\[rmail-add-label].
709 \\[rmail-previous-labeled-message] Move to Previous message with specified label
710 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
711 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
712 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
713 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
714 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
715 \\[rmail-toggle-header] Toggle display of complete header."
718 (rmail-set-message-counters)
719 (rmail-show-message rmail-total-messages
)
720 (run-hooks 'rmail-mode-hook
))
722 (defun rmail-mode-2 ()
723 (kill-all-local-variables)
727 (defun rmail-mode-1 ()
728 (setq major-mode
'rmail-mode
)
729 (setq mode-name
"RMAIL")
730 (setq buffer-read-only t
)
731 ;; No need to auto save RMAIL files in normal circumstances
732 ;; because they contain no info except attribute changes
733 ;; and deletion of messages.
734 ;; The one exception is when messages are copied into an Rmail mode buffer.
735 ;; rmail-output-to-rmail-file enables auto save when you do that.
736 (setq buffer-auto-save-file-name nil
)
737 (if (boundp 'mode-line-modified
)
738 (setq mode-line-modified
"--- ")
739 (setq mode-line-format
740 (cons "--- " (cdr (default-value 'mode-line-format
)))))
741 (use-local-map rmail-mode-map
)
742 (set-syntax-table text-mode-syntax-table
)
743 (setq local-abbrev-table text-mode-abbrev-table
))
745 (defun rmail-variables ()
746 (make-local-variable 'revert-buffer-function
)
747 (setq revert-buffer-function
'rmail-revert
)
748 (make-local-variable 'font-lock-defaults
)
749 (setq font-lock-defaults
750 '(rmail-font-lock-keywords t nil nil nil
751 (font-lock-maximum-size . nil
)
752 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
753 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
754 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
755 (make-local-variable 'rmail-last-label
)
756 (make-local-variable 'rmail-last-regexp
)
757 (make-local-variable 'rmail-deleted-vector
)
758 (make-local-variable 'rmail-buffer
)
759 (setq rmail-buffer
(current-buffer))
760 (make-local-variable 'rmail-view-buffer
)
761 (setq rmail-view-buffer rmail-buffer
)
762 (make-local-variable 'rmail-summary-buffer
)
763 (make-local-variable 'rmail-summary-vector
)
764 (make-local-variable 'rmail-current-message
)
765 (make-local-variable 'rmail-total-messages
)
766 (make-local-variable 'require-final-newline
)
767 (setq require-final-newline nil
)
768 (make-local-variable 'rmail-overlay-list
)
769 (setq rmail-overlay-list nil
)
770 (make-local-variable 'version-control
)
771 (setq version-control
'never
)
772 (make-local-variable 'kill-buffer-hook
)
773 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
774 (make-local-variable 'file-precious-flag
)
775 (setq file-precious-flag t
)
776 (make-local-variable 'rmail-message-vector
)
777 (make-local-variable 'rmail-inbox-list
)
778 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
779 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
780 (and (null rmail-inbox-list
)
781 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
782 (equal buffer-file-truename
783 (abbreviate-file-name (file-truename rmail-file-name
))))
784 (setq rmail-inbox-list
785 (or rmail-primary-inbox-list
786 (list (or (getenv "MAIL")
787 (concat rmail-spool-directory
788 (user-login-name)))))))
789 (make-local-variable 'rmail-keywords
)
790 ;; this gets generated as needed
791 (setq rmail-keywords nil
))
793 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
794 (defun rmail-revert (arg noconfirm
)
795 (let ((revert-buffer-function (default-value 'revert-buffer-function
)))
796 ;; Call our caller again, but this time it does the default thing.
797 (if (revert-buffer arg noconfirm
)
798 ;; If the user said "yes", and we changed something,
799 ;; reparse the messages.
802 (goto-char (point-max))
805 ;; Return a list of files from this buffer's Mail: option.
806 ;; Does not assume that messages have been parsed.
807 ;; Just returns nil if buffer does not look like Babyl format.
808 (defun rmail-parse-file-inboxes ()
813 (cond ((looking-at "BABYL OPTIONS:")
814 (search-forward "\n\^_" nil
'move
)
815 (narrow-to-region 1 (point))
817 (if (search-forward "\nMail:" nil t
)
819 (narrow-to-region (point) (progn (end-of-line) (point)))
820 (goto-char (point-min))
821 (mail-parse-comma-list))))))))
823 (defun rmail-expunge-and-save ()
824 "Expunge and save RMAIL file."
828 (if (rmail-summary-exists)
829 (rmail-select-summary (set-buffer-modified-p nil
))))
834 (rmail-expunge-and-save)
835 ;; Don't switch to the summary buffer even if it was recently visible.
836 (if rmail-summary-buffer
838 (replace-buffer-in-windows rmail-summary-buffer
)
839 (bury-buffer rmail-summary-buffer
)))
840 (let ((obuf (current-buffer)))
841 (replace-buffer-in-windows obuf
)
845 "Bury current Rmail buffer and its summary buffer."
847 ;; This let var was called rmail-buffer, but that interfered
848 ;; with the buffer-local var used in summary buffers.
849 (let ((buffer-to-bury (current-buffer)))
850 (if (rmail-summary-exists)
852 (while (setq window
(get-buffer-window rmail-summary-buffer
))
853 (set-window-buffer window
(other-buffer rmail-summary-buffer
)))
854 (bury-buffer rmail-summary-buffer
)))
855 (switch-to-buffer (other-buffer (current-buffer)))
856 (bury-buffer buffer-to-bury
)))
858 (defun rmail-duplicate-message ()
859 "Create a duplicated copy of the current message.
860 The duplicate copy goes into the Rmail file just after the
864 (let ((buffer-read-only nil
)
865 (number rmail-current-message
)
866 (string (buffer-substring (rmail-msgbeg rmail-current-message
)
867 (rmail-msgend rmail-current-message
))))
868 (goto-char (rmail-msgend rmail-current-message
))
870 (rmail-forget-messages)
871 (rmail-show-message number
)
872 (message "Message duplicated")))
875 (defun rmail-input (filename)
876 "Run Rmail on file FILENAME."
877 (interactive "FRun rmail on RMAIL file: ")
881 ;; This used to scan subdirectories recursively, but someone pointed out
882 ;; that if the user wants that, person can put all the files in one dir.
883 ;; And the recursive scan was slow. So I took it out.
885 (defun rmail-find-all-files (start)
886 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
887 (if (file-accessible-directory-p start
)
889 (let* ((case-fold-search t
)
890 (files (directory-files start t rmail-secondary-file-regexp
)))
891 ;; Sort here instead of in directory-files
892 ;; because this list is usually much shorter.
893 (sort files
'string
<))))
895 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
896 (let ((menu (make-sparse-keymap menu-name
)))
898 (function (lambda (item)
903 (rmail-list-to-menu (car item
) (cdr item
)
906 (concat full-name
"/"
909 (setq name
(car item
)))
913 (list 'lambda
() '(interactive)
917 (concat full-name
"/" item
)
919 rmail-secondary-file-directory
))))))
920 (define-key menu
(vector (intern name
))
921 (cons name command
)))))
925 ;; This command is always "disabled" when it appears in a menu.
926 (put 'rmail-disable-menu
'menu-enable
''nil
)
928 (defun rmail-construct-io-menu ()
929 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
932 (define-key rmail-mode-map
[menu-bar classify input-menu
]
933 (cons "Input Rmail File"
934 (rmail-list-to-menu "Input Rmail File"
937 (define-key rmail-mode-map
[menu-bar classify output-menu
]
938 (cons "Output Rmail File"
939 (rmail-list-to-menu "Output Rmail File"
941 'rmail-output-to-rmail-file
))))
943 (define-key rmail-mode-map
[menu-bar classify input-menu
]
944 '("Input Rmail File" . rmail-disable-menu
))
945 (define-key rmail-mode-map
[menu-bar classify output-menu
]
946 '("Output Rmail File" . rmail-disable-menu
)))))
949 ;;;; *** Rmail input ***
951 ;; RLK feature not added in this version:
952 ;; argument specifies inbox file or files in various ways.
954 (defun rmail-get-new-mail (&optional file-name
)
955 "Move any new mail from this RMAIL file's inbox files.
956 The inbox files can be specified with the file's Mail: option. The
957 variable `rmail-primary-inbox-list' specifies the inboxes for your
958 primary RMAIL file if it has no Mail: option. By default, this is
959 your /usr/spool/mail/$USER.
961 You can also specify the file to get new mail from. In this case, the
962 file of new mail is not changed or deleted. Noninteractively, you can
963 pass the inbox file name as an argument. Interactively, a prefix
964 argument causes us to read a file name and use that file as the inbox.
966 If the variable `rmail-preserve-inbox' is non-nil, new mail will
967 always be left in inbox files rather than deleted.
969 This function runs `rmail-get-new-mail-hook' before saving the updated file.
970 It returns t if it got any new messages."
972 (list (if current-prefix-arg
973 (read-file-name "Get new mail from file: "))))
974 (run-hooks 'rmail-before-get-new-mail-hook
)
975 ;; If the disk file has been changed from under us,
976 ;; revert to it before we get new mail.
977 (or (verify-visited-file-modtime (current-buffer))
978 (find-file (buffer-file-name)))
979 (rmail-maybe-set-message-counters)
981 ;; Get rid of all undo records for this buffer.
982 (or (eq buffer-undo-list t
)
983 (setq buffer-undo-list nil
))
984 (let ((all-files (if file-name
(list file-name
)
989 (let ((opoint (point))
992 ;; If buffer has not changed yet, and has not been saved yet,
993 ;; don't replace the old backup file now.
994 (make-backup-files (and make-backup-files
(buffer-modified-p)))
995 (buffer-read-only nil
)
996 ;; Don't make undo records for what we do in getting mail.
999 ;; Files to insert this time around.
1001 ;; Last names of those files.
1003 ;; Pull files off all-files onto files
1004 ;; as long as there is no name conflict.
1005 ;; A conflict happens when two inbox file names
1006 ;; have the same last component.
1007 (while (and all-files
1008 (not (member (file-name-nondirectory (car all-files
))
1010 (setq files
(cons (car all-files
) files
)
1012 (cons (file-name-nondirectory (car all-files
)) files
))
1013 (setq all-files
(cdr all-files
)))
1014 ;; Put them back in their original order.
1015 (setq files
(nreverse files
))
1017 (goto-char (point-max))
1018 (skip-chars-backward " \t\n") ; just in case of brain damage
1019 (delete-region (point) (point-max)) ; caused by require-final-newline
1022 (narrow-to-region (point) (point))
1023 ;; Read in the contents of the inbox files,
1024 ;; renaming them as necessary,
1025 ;; and adding to the list of files to delete eventually.
1027 (rmail-insert-inbox-text files nil
)
1028 (setq delete-files
(rmail-insert-inbox-text files t
)))
1029 ;; Scan the new text and convert each message to babyl format.
1030 (goto-char (point-min))
1033 (setq new-messages
(rmail-convert-to-babyl-format)
1035 ;; If we could not convert the file's inboxes,
1036 ;; rename the files we tried to read
1037 ;; so we won't over and over again.
1038 (if (and (not file-name
) (not success
))
1039 (let ((delfiles delete-files
)
1042 (while (file-exists-p (format "RMAILOSE.%d" count
))
1043 (setq count
(1+ count
)))
1044 (rename-file (car delfiles
)
1045 (format "RMAILOSE.%d" count
))
1046 (setq delfiles
(cdr delfiles
))))))
1047 (or (zerop new-messages
)
1050 (search-backward "\n\^_" nil t
)
1051 (narrow-to-region (point) (point-max))
1052 (goto-char (1+ (point-min)))
1053 (rmail-count-new-messages)
1054 (run-hooks 'rmail-get-new-mail-hook
)
1056 ;; Delete the old files, now that babyl file is saved.
1059 ;; First, try deleting.
1061 (delete-file (car delete-files
))
1063 ;; If we can't delete it, truncate it.
1064 (write-region (point) (point) (car delete-files
))))
1066 (setq delete-files
(cdr delete-files
)))))
1067 (if (= new-messages
0)
1068 (progn (goto-char opoint
)
1069 (if (or file-name rmail-inbox-list
)
1070 (message "(No new mail has arrived)")))
1071 (if (rmail-summary-exists)
1072 (rmail-select-summary
1073 (rmail-update-summary)))
1074 (message "%d new message%s read"
1075 new-messages
(if (= 1 new-messages
) "" "s"))
1076 ;; Move to the first new message
1077 ;; unless we have other unseen messages before it.
1078 (rmail-show-message (rmail-first-unseen-message))
1079 (run-hooks 'rmail-after-get-new-mail-hook
)
1082 ;; Don't leave the buffer screwed up if we get a disk-full error.
1083 (rmail-show-message))))
1085 (defun rmail-insert-inbox-text (files renamep
)
1086 ;; Detect a locked file now, so that we avoid moving mail
1087 ;; out of the real inbox file. (That could scare people.)
1088 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1089 (error "RMAIL file %s is locked"
1090 (file-name-nondirectory buffer-file-name
)))
1091 (let (file tofile delete-files movemail popmail
)
1093 (setq file
(file-truename
1094 (expand-file-name (substitute-in-file-name (car files
))))
1095 tofile
(expand-file-name
1096 ;; Generate name to move to from inbox name,
1097 ;; in case of multiple inboxes that need moving.
1098 (concat ".newmail-" (file-name-nondirectory file
))
1099 ;; Use the directory of this rmail file
1100 ;; because it's a nuisance to use the homedir
1101 ;; if that is on a full disk and this rmail
1103 (file-name-directory
1104 (expand-file-name buffer-file-name
))))
1105 ;; Always use movemail to rename the file,
1106 ;; since there can be mailboxes in various directories.
1108 ;;; ;; If getting from mail spool directory,
1109 ;;; ;; use movemail to move rather than just renaming,
1110 ;;; ;; so as to interlock with the mailer.
1111 ;;; (setq movemail (string= file
1113 ;;; (concat rmail-spool-directory
1114 ;;; (file-name-nondirectory file)))))
1115 (setq popmail
(string-match "^po:" (file-name-nondirectory file
)))
1116 (if popmail
(setq file
(file-name-nondirectory file
)
1120 ;; On some systems, /usr/spool/mail/foo is a directory
1121 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1122 (if (file-directory-p file
)
1123 (setq file
(expand-file-name (user-login-name)
1126 (if (and rmail-pop-password-required
(not rmail-pop-password
))
1127 (setq rmail-pop-password
1129 (format "Password for %s: "
1130 (substring file
(+ popmail
3))))))
1131 (if (eq system-type
'windows-nt
)
1132 ;; cannot have "po:" in file name
1135 (concat ".newmail-pop-" (substring file
(+ popmail
3)))
1136 (file-name-directory
1137 (expand-file-name buffer-file-name
)))))
1138 (message "Getting mail from post office ..."))
1139 ((and (file-exists-p tofile
)
1140 (/= 0 (nth 7 (file-attributes tofile
))))
1141 (message "Getting mail from %s..." tofile
))
1142 ((and (file-exists-p file
)
1143 (/= 0 (nth 7 (file-attributes file
))))
1144 (message "Getting mail from %s..." file
)))
1145 ;; Set TOFILE if have not already done so, and
1146 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1147 (cond ((not renamep
)
1149 ((or (file-exists-p tofile
) (and (not popmail
)
1150 (not (file-exists-p file
))))
1152 ((and (not movemail
) (not popmail
))
1153 ;; Try copying. If that fails (perhaps no space) and
1154 ;; we're allowed to blow away the inbox, rename instead.
1155 (if rmail-preserve-inbox
1156 (copy-file file tofile nil
)
1158 (copy-file file tofile nil
)
1160 ;; Third arg is t so we can replace existing file TOFILE.
1161 (rename-file file tofile t
))))
1162 ;; Make the real inbox file empty.
1163 ;; Leaving it deleted could cause lossage
1164 ;; because mailers often won't create the file.
1165 (if (not rmail-preserve-inbox
)
1167 (write-region (point) (point) file
)
1173 (setq errors
(generate-new-buffer " *rmail loss*"))
1174 (buffer-disable-undo errors
)
1177 (list (or rmail-movemail-program
1178 (expand-file-name "movemail"
1181 (if rmail-preserve-inbox
1185 (if rmail-pop-password
1186 (list rmail-pop-password
)
1188 (apply 'call-process args
))
1189 (if (not (buffer-modified-p errors
))
1190 ;; No output => movemail won
1193 (subst-char-in-region (point-min) (point-max)
1195 (goto-char (point-max))
1196 (skip-chars-backward " \t")
1197 (delete-region (point) (point-max))
1198 (goto-char (point-min))
1199 (if (looking-at "movemail: ")
1200 (delete-region (point-min) (match-end 0)))
1202 (message "movemail: %s"
1203 (buffer-substring (point-min)
1207 (if errors
(kill-buffer errors
))))))
1208 ;; At this point, TOFILE contains the name to read:
1209 ;; Either the alternate name (if we renamed)
1210 ;; or the actual inbox (if not renaming).
1211 (if (file-exists-p tofile
)
1212 (let ((coding-system-for-read 'no-conversion
)
1214 (goto-char (point-max))
1215 (setq size
(nth 1 (insert-file-contents tofile
)))
1216 (goto-char (point-max))
1217 (or (= (preceding-char) ?
\n)
1220 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
1221 (setq delete-files
(cons tofile delete-files
)))))
1223 (setq files
(cdr files
)))
1226 (defun rmail-read-passwd (prompt &optional default
)
1227 "Read a password, echoing `.' for each character typed.
1228 End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line.
1229 Optional DEFAULT is password to start with."
1230 (let ((pass (if default default
""))
1233 (cursor-in-echo-area t
))
1234 (while (progn (message "%s%s"
1236 (make-string (length pass
) ?.
))
1237 (setq c
(read-char))
1238 (and (/= c ?
\r) (/= c ?
\n) (/= c ?\e
)))
1241 (if (and (/= c ?
\b) (/= c ?
\177))
1242 (setq pass
(concat pass
(char-to-string c
)))
1243 (if (> (length pass
) 0)
1244 (setq pass
(substring pass
0 -
1))))))
1249 ;; the rmail-break-forwarded-messages feature is not implemented
1250 (defun rmail-convert-to-babyl-format ()
1251 (let ((count 0) start
1252 (case-fold-search nil
)
1253 (invalid-input-resync
1254 (function (lambda ()
1255 (message "Invalid Babyl format in inbox!")
1257 ;; Try to get back in sync with a real message.
1258 (if (re-search-forward
1259 (concat mmdf-delim1
"\\|^From") nil t
)
1261 (goto-char (point-max)))))))
1262 (goto-char (point-min))
1265 (setq start
(point))
1266 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1267 (if (search-forward "\n\^_" nil t
)
1268 ;; If we find the proper terminator, delete through there.
1269 (delete-region (point-min) (point))
1270 (funcall invalid-input-resync
)
1271 (delete-region (point-min) (point))))
1272 ;; Babyl format message
1274 (or (search-forward "\n\^_" nil t
)
1275 (funcall invalid-input-resync
))
1276 (setq count
(1+ count
))
1277 ;; Make sure there is no extra white space after the ^_
1278 ;; at the end of the message.
1279 ;; Narrowing will make sure that whatever follows the junk
1280 ;; will be treated properly.
1281 (delete-region (point)
1283 (skip-chars-forward " \t\n")
1285 (or rmail-enable-mime
1286 (not rmail-file-coding-system
)
1287 (decode-coding-region start
(point)
1288 rmail-file-coding-system
))
1289 (narrow-to-region (point) (point-max)))
1291 ((let ((case-fold-search t
))
1292 (looking-at mmdf-delim1
))
1293 (let ((case-fold-search t
))
1294 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1295 (re-search-forward mmdf-delim2 nil t
)
1296 (replace-match "\^_"))
1299 (narrow-to-region start
(1- (point)))
1300 (goto-char (point-min))
1301 (while (search-forward "\n\^_" nil t
); single char "\^_"
1302 (replace-match "\n^_")))); 2 chars: "^" and "_"
1303 (or rmail-enable-mime
1304 (not rmail-file-coding-system
)
1305 (decode-coding-region start
(point) 'automatic-conversion
))
1306 (narrow-to-region (point) (point-max))
1307 (setq count
(1+ count
)))
1309 ((looking-at "^From ")
1310 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1311 (rmail-nuke-pinhead-header)
1312 ;; If this message has a Content-Length field,
1313 ;; skip to the end of the contents.
1314 (let* ((header-end (save-excursion
1315 (and (re-search-forward "\n\n" nil t
)
1317 (case-fold-search t
)
1319 ;; Get the numeric value from the Content-Length field.
1321 ;; Back up to end of prev line,
1322 ;; in case the Content-Length field comes first.
1324 (and (search-forward "\ncontent-length: "
1327 (eol (progn (end-of-line) (point))))
1328 (string-to-int (buffer-substring beg eol
)))))))
1330 (if (and (natnump size
)
1331 (<= (+ header-end size
) (point-max))
1332 ;; Make sure this would put us at a position
1333 ;; that we could continue from.
1335 (goto-char (+ header-end size
))
1336 (skip-chars-forward "\n")
1338 (and (looking-at "BABYL OPTIONS:")
1339 (search-forward "\n\^_" nil t
))
1340 (and (looking-at "\^L")
1341 (search-forward "\n\^_" nil t
))
1342 (let ((case-fold-search t
))
1343 (looking-at mmdf-delim1
))
1344 (looking-at "From "))))
1345 (goto-char (+ header-end size
))
1346 (message "Ignoring invalid Content-Length field")
1349 (if (re-search-forward
1350 (concat "^[\^_]?\\("
1351 rmail-unix-mail-delimiter
1354 "^BABYL OPTIONS:\\|"
1355 "\^L\n[01],\\)") nil t
)
1356 (goto-char (match-beginning 1))
1357 (goto-char (point-max)))
1358 (setq count
(1+ count
))
1361 (narrow-to-region start
(point))
1362 (goto-char (point-min))
1363 (while (search-forward "\n\^_" nil t
); single char
1364 (replace-match "\n^_")))); 2 chars: "^" and "_"
1366 (or rmail-enable-mime
1367 (not rmail-file-coding-system
)
1368 (decode-coding-region start
(point) 'automatic-conversion
))
1369 (narrow-to-region (point) (point-max)))
1371 ;; This kludge is because some versions of sendmail.el
1372 ;; insert an extra newline at the beginning that shouldn't
1373 ;; be there. sendmail.el has been fixed, but old versions
1374 ;; may still be in use. -- rms, 7 May 1993.
1375 ((eolp) (delete-char 1))
1376 (t (error "Cannot convert to babyl format")))))
1379 ;; Delete the "From ..." line, creating various other headers with
1380 ;; information from it if they don't already exist. Now puts the
1381 ;; original line into a mail-from: header line for debugging and for
1382 ;; use by the rmail-output function.
1383 (defun rmail-nuke-pinhead-header ()
1386 (let ((start (point))
1389 (search-forward "\n\n")
1391 (goto-char (point-max))
1395 (narrow-to-region start end
)
1396 (let ((case-fold-search t
))
1398 (setq has-from
(search-forward "\nFrom:" nil t
))
1400 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
1402 (let ((case-fold-search nil
))
1403 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
1407 ;; Keep and reformat the date if we don't
1408 ;; have a Date: field.
1412 "Date: \\2, \\4 \\3 \\9 \\5 "
1414 ;; The timezone could be matched by group 7 or group 10.
1415 ;; If neither of them matched, assume EST, since only
1416 ;; Easterners would be so sloppy.
1417 ;; It's a shame the substitution can't use "\\10".
1419 ((/= (match-beginning 7) (match-end 7)) "\\7")
1420 ((/= (match-beginning 10) (match-end 10))
1421 (buffer-substring (match-beginning 10)
1425 ;; Keep and reformat the sender if we don't
1426 ;; have a From: field.
1432 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1434 (defun rmail-reformat-message (beg end
)
1437 (if (/= (following-char) ?
0)
1438 (error "Bad format in RMAIL file."))
1439 (let ((buffer-read-only nil
)
1440 (delta (- (buffer-size) end
)))
1444 (let ((case-fold-search t
))
1445 (while (looking-at "Summary-line:\\|Mail-From:")
1447 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1448 (delete-region (point)
1449 (progn (forward-line 1) (point))))
1450 (let ((str (buffer-substring (point)
1451 (save-excursion (search-forward "\n\n" end
'move
)
1453 (insert str
"*** EOOH ***\n")
1454 (narrow-to-region (point) (- (buffer-size) delta
)))
1455 (goto-char (point-min))
1456 (if rmail-message-filter
(funcall rmail-message-filter
))
1457 (if (or rmail-displayed-headers rmail-ignored-headers
)
1458 (rmail-clear-headers))))
1460 (defun rmail-clear-headers (&optional ignored-headers
)
1461 "Delete all header fields that Rmail should not show.
1462 If the optional argument IGNORED-HEADERS is non-nil,
1463 delete all header fields whose names match that regexp.
1464 Otherwise, if `rmail-displayed-headers' is non-nil,
1465 delete all header fields *except* those whose names match that regexp.
1466 Otherwise, delete all header fields whose names match `rmail-ignored-headers'."
1467 (if (search-forward "\n\n" nil t
)
1468 (let ((case-fold-search t
)
1469 (buffer-read-only nil
))
1470 (if (and rmail-displayed-headers
(null ignored-headers
))
1472 (narrow-to-region (point-min) (point))
1474 (goto-char (point-min))
1475 (while (save-excursion
1476 (re-search-forward "\n[^ \t]")
1478 (setq lim
(1- (point)))))
1480 (re-search-forward rmail-displayed-headers lim t
))
1482 (delete-region (point) lim
))))
1483 (goto-char (point-min)))
1484 (or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
1486 (narrow-to-region (point-min) (point))
1488 (goto-char (point-min))
1489 (re-search-forward ignored-headers nil t
))
1491 (delete-region (point)
1492 (progn (re-search-forward "\n[^ \t]")
1493 (1- (point))))))))))
1495 (defun rmail-msg-is-pruned ()
1496 (rmail-maybe-set-message-counters)
1499 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
1500 (goto-char (point-min))
1502 (= (following-char) ?
1))))
1504 (defun rmail-toggle-header (&optional arg
)
1505 "Show original message header if pruned header currently shown, or vice versa.
1506 With argument ARG, show the message header pruned if ARG is greater than zero;
1507 otherwise, show it in full."
1509 (let* ((buffer-read-only nil
)
1510 (pruned (rmail-msg-is-pruned))
1512 (> (prefix-numeric-value arg
) 0)
1514 (if (eq pruned prune
)
1516 (rmail-maybe-set-message-counters)
1517 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
1519 (progn (goto-char (point-min))
1524 (let ((case-fold-search t
))
1525 (while (looking-at "Summary-Line:\\|Mail-From:")
1527 (insert "*** EOOH ***\n")
1529 (search-forward "\n*** EOOH ***\n")
1531 (let ((temp (point)))
1532 (and (search-forward "\n\n" nil t
)
1533 (delete-region temp
(point))))
1534 (goto-char (point-min))
1535 (search-forward "\n*** EOOH ***\n")
1536 (narrow-to-region (point) (point-max)))
1537 (rmail-reformat-message (point-min) (point-max)))
1538 (rmail-highlight-headers))))
1540 ;;;; *** Rmail Attributes and Keywords ***
1542 ;; Make a string describing current message's attributes and keywords
1543 ;; and set it up as the name of a minor mode
1544 ;; so it will appear in the mode line.
1545 (defun rmail-display-labels ()
1546 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1551 (goto-char (rmail-msgbeg rmail-current-message
))
1553 (if (looking-at "[01],")
1555 (narrow-to-region (point) (progn (end-of-line) (point)))
1556 ;; Truly valid BABYL format requires a space before each
1557 ;; attribute or keyword name. Put them in if missing.
1558 (let (buffer-read-only)
1559 (goto-char (point-min))
1560 (while (search-forward "," nil t
)
1561 (or (looking-at "[ ,]") (eobp)
1563 (goto-char (point-max))
1564 (if (search-backward ",," nil
'move
)
1566 (if (> (point) (1+ (point-min)))
1567 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
1568 (if (> (- (point-max) (point)) 2)
1572 (buffer-substring (+ (point) 3)
1573 (1- (point-max)))))))))))
1574 ;; Note: we don't use save-restriction because that does not work right
1575 ;; if changes are made outside the saved restriction
1576 ;; before that restriction is restored.
1577 (narrow-to-region beg end
)
1578 (set-marker beg nil
)
1579 (set-marker end nil
)))
1580 (while (string-match " +," blurb
)
1581 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
1582 (substring blurb
(match-end 0)))))
1583 (while (string-match ", +" blurb
)
1584 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
1585 (substring blurb
(match-end 0)))))
1586 (setq mode-line-process
1588 rmail-current-message rmail-total-messages blurb
))))
1590 ;; Turn an attribute of a message on or off according to STATE.
1591 ;; ATTR is the name of the attribute, as a string.
1592 ;; MSGNUM is message number to change; nil means current message.
1593 (defun rmail-set-attribute (attr state
&optional msgnum
)
1594 (let ((omax (point-max-marker))
1595 (omin (point-min-marker))
1596 (buffer-read-only nil
))
1597 (or msgnum
(setq msgnum rmail-current-message
))
1602 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
1605 (null (search-backward (concat ", " attr
",")
1606 (prog1 (point) (end-of-line)) t
)))))
1607 (or (eq curstate
(not (not state
)))
1609 (delete-region (point) (1- (match-end 0)))
1612 (insert " " attr
","))))
1613 (if (string= attr
"deleted")
1614 (rmail-set-message-deleted-p msgnum state
)))
1615 ;; Note: we don't use save-restriction because that does not work right
1616 ;; if changes are made outside the saved restriction
1617 ;; before that restriction is restored.
1618 (narrow-to-region omin omax
)
1619 (set-marker omin nil
)
1620 (set-marker omax nil
)
1621 (if (= msgnum rmail-current-message
)
1622 (rmail-display-labels))))))
1624 ;; Return t if the attributes/keywords line of msg number MSG
1625 ;; contains a match for the regexp LABELS.
1626 (defun rmail-message-labels-p (msg labels
)
1630 (goto-char (rmail-msgbeg msg
))
1632 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
1634 ;;;; *** Rmail Message Selection And Support ***
1636 (defun rmail-msgend (n)
1637 (marker-position (aref rmail-message-vector
(1+ n
))))
1639 (defun rmail-msgbeg (n)
1640 (marker-position (aref rmail-message-vector n
)))
1642 (defun rmail-widen-to-current-msgbeg (function)
1643 "Call FUNCTION with point at start of internal data of current message.
1644 Assumes that bounds were previously narrowed to display the message in Rmail.
1645 The bounds are widened enough to move point where desired, then narrowed
1648 FUNCTION may not change the visible text of the message, but it may
1649 change the invisible header text."
1651 (let ((obeg (- (point-max) (point-min))))
1654 (narrow-to-region (rmail-msgbeg rmail-current-message
)
1656 (goto-char (point-min))
1658 ;; Note: we don't use save-restriction because that does not work right
1659 ;; if changes are made outside the saved restriction
1660 ;; before that restriction is restored.
1661 ;; Here we assume that changes made by FUNCTION
1662 ;; occur before the visible region of the message.
1663 (narrow-to-region (- (point-max) obeg
) (point-max))))))
1665 (defun rmail-forget-messages ()
1667 (if (vectorp rmail-message-vector
)
1669 (v rmail-message-vector
)
1672 (move-marker (aref v i
) nil
)
1674 (setq rmail-message-vector nil
)
1675 (setq rmail-deleted-vector nil
)))
1677 (defun rmail-maybe-set-message-counters ()
1678 (if (not (and rmail-deleted-vector
1679 rmail-message-vector
1680 rmail-current-message
1681 rmail-total-messages
))
1682 (rmail-set-message-counters)))
1684 (defun rmail-count-new-messages (&optional nomsg
)
1685 (let* ((case-fold-search nil
)
1689 (or nomsg
(message "Counting new messages..."))
1690 (goto-char (point-max))
1691 ;; Put at the end of messages-head
1692 ;; the entry for message N+1, which marks
1693 ;; the end of message N. (N = number of messages).
1694 (search-backward "\n\^_")
1696 (setq messages-head
(list (point-marker)))
1697 (rmail-set-message-counters-counter (point-min))
1698 (setq rmail-current-message
(1+ rmail-total-messages
))
1699 (setq rmail-total-messages
1700 (+ rmail-total-messages total-messages
))
1701 (setq rmail-message-vector
1702 (vconcat rmail-message-vector
(cdr messages-head
)))
1703 (aset rmail-message-vector
1704 rmail-current-message
(car messages-head
))
1705 (setq rmail-deleted-vector
1706 (concat rmail-deleted-vector deleted-head
))
1707 (setq rmail-summary-vector
1708 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
1709 (goto-char (point-min))
1710 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
1712 (defun rmail-set-message-counters ()
1713 (rmail-forget-messages)
1717 (let* ((point-save (point))
1719 (messages-after-point)
1720 (case-fold-search nil
)
1723 (message "Counting messages...")
1724 (goto-char (point-max))
1725 ;; Put at the end of messages-head
1726 ;; the entry for message N+1, which marks
1727 ;; the end of message N. (N = number of messages).
1728 (search-backward "\n\^_" nil t
)
1729 (if (/= (point) (point-max)) (forward-char 1))
1730 (setq messages-head
(list (point-marker)))
1731 (rmail-set-message-counters-counter (min (point) point-save
))
1732 (setq messages-after-point total-messages
)
1733 (rmail-set-message-counters-counter)
1734 (setq rmail-total-messages total-messages
)
1735 (setq rmail-current-message
1737 (max 1 (- total-messages messages-after-point
))))
1738 (setq rmail-message-vector
1739 (apply 'vector
(cons (point-min-marker) messages-head
))
1740 rmail-deleted-vector
(concat "D" deleted-head
)
1741 rmail-summary-vector
(make-vector rmail-total-messages nil
))
1742 (message "Counting messages...done")))))
1744 (defun rmail-set-message-counters-counter (&optional stop
)
1745 (while (search-backward "\n\^_\^L\n" stop t
)
1747 (setq messages-head
(cons (point-marker) messages-head
))
1750 (cons (if (search-backward ", deleted,"
1756 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
1757 (message "Counting messages...%d" total-messages
))))
1759 (defun rmail-beginning-of-message ()
1760 "Show current message starting from the beginning."
1762 (rmail-show-message rmail-current-message
))
1764 (defun rmail-show-message (&optional n no-summary
)
1765 "Show message number N (prefix argument), counting from start of file.
1766 If summary buffer is currently displayed, update current message there also."
1768 (or (eq major-mode
'rmail-mode
)
1769 (switch-to-buffer rmail-buffer
))
1770 (rmail-maybe-set-message-counters)
1772 (if (zerop rmail-total-messages
)
1773 (progn (narrow-to-region (point-min) (1- (point-max)))
1774 (goto-char (point-min))
1775 (setq mode-line-process nil
))
1778 (setq n rmail-current-message
)
1781 rmail-current-message
1
1782 blurb
"No previous message"))
1783 ((> n rmail-total-messages
)
1784 (setq n rmail-total-messages
1785 rmail-current-message rmail-total-messages
1786 blurb
"No following message"))
1788 (setq rmail-current-message n
))))
1789 (let ((beg (rmail-msgbeg n
)))
1792 ;; Clear the "unseen" attribute when we show a message.
1793 (rmail-set-attribute "unseen" nil
)
1794 ;; Reformat the header, or else find the reformatted header.
1795 (let ((end (rmail-msgend n
)))
1796 (if (= (following-char) ?
0)
1797 (rmail-reformat-message beg end
)
1798 (search-forward "\n*** EOOH ***\n" end t
)
1799 (narrow-to-region (point) end
)))
1800 (goto-char (point-min))
1801 (rmail-display-labels)
1802 (if (eq rmail-enable-mime t
)
1803 (funcall rmail-show-mime-function
)
1804 (setq rmail-view-buffer rmail-buffer
)
1806 (rmail-highlight-headers)
1807 (if transient-mark-mode
(deactivate-mark))
1808 (run-hooks 'rmail-show-message-hook
)
1809 ;; If there is a summary buffer, try to move to this message
1810 ;; in that buffer. But don't complain if this message
1811 ;; is not mentioned in the summary.
1812 ;; Don't do this at all if we were called on behalf
1813 ;; of cursor motion in the summary buffer.
1814 (and (rmail-summary-exists) (not no-summary
)
1815 (let ((curr-msg rmail-current-message
))
1816 (rmail-select-summary
1817 (rmail-summary-goto-msg curr-msg t t
))))
1819 (message blurb
))))))
1821 ;; Find all occurrences of certain fields, and highlight them.
1822 (defun rmail-highlight-headers ()
1823 ;; Do this only if the system supports faces.
1824 (if (and (fboundp 'internal-find-face
)
1825 rmail-highlighted-headers
)
1827 (search-forward "\n\n" nil
'move
)
1829 (narrow-to-region (point-min) (point))
1830 (let ((case-fold-search t
)
1831 (inhibit-read-only t
)
1832 ;; Highlight with boldface if that is available.
1833 ;; Otherwise use the `highlight' face.
1834 (face (or rmail-highlight-face
1835 (if (face-differs-from-default-p 'bold
)
1837 ;; List of overlays to reuse.
1838 (overlays rmail-overlay-list
))
1839 (goto-char (point-min))
1840 (while (re-search-forward rmail-highlighted-headers nil t
)
1841 (skip-chars-forward " \t")
1844 (while (progn (forward-line 1)
1845 (looking-at "[ \t]")))
1846 ;; Back up over newline, then trailing spaces or tabs
1848 (while (member (preceding-char) '(? ?
\t))
1851 ;; Reuse an overlay we already have.
1853 (setq overlay
(car overlays
)
1854 overlays
(cdr overlays
))
1855 (overlay-put overlay
'face face
)
1856 (move-overlay overlay beg
(point)))
1857 ;; Make a new overlay and add it to
1858 ;; rmail-overlay-list.
1859 (setq overlay
(make-overlay beg
(point)))
1860 (overlay-put overlay
'face face
)
1861 (setq rmail-overlay-list
1862 (cons overlay rmail-overlay-list
))))))))))
1864 (defun rmail-next-message (n)
1865 "Show following message whether deleted or not.
1866 With prefix arg N, moves forward N messages, or backward if N is negative."
1868 (rmail-maybe-set-message-counters)
1869 (rmail-show-message (+ rmail-current-message n
)))
1871 (defun rmail-previous-message (n)
1872 "Show previous message whether deleted or not.
1873 With prefix arg N, moves backward N messages, or forward if N is negative."
1875 (rmail-next-message (- n
)))
1877 (defun rmail-next-undeleted-message (n)
1878 "Show following non-deleted message.
1879 With prefix arg N, moves forward N non-deleted messages,
1880 or backward if N is negative.
1882 Returns t if a new message is being shown, nil otherwise."
1884 (rmail-maybe-set-message-counters)
1885 (let ((lastwin rmail-current-message
)
1886 (current rmail-current-message
))
1887 (while (and (> n
0) (< current rmail-total-messages
))
1888 (setq current
(1+ current
))
1889 (if (not (rmail-message-deleted-p current
))
1890 (setq lastwin current n
(1- n
))))
1891 (while (and (< n
0) (> current
1))
1892 (setq current
(1- current
))
1893 (if (not (rmail-message-deleted-p current
))
1894 (setq lastwin current n
(1+ n
))))
1895 (if (/= lastwin rmail-current-message
)
1896 (progn (rmail-show-message lastwin
)
1899 (message "No previous nondeleted message"))
1901 (message "No following nondeleted message"))
1904 (defun rmail-previous-undeleted-message (n)
1905 "Show previous non-deleted message.
1906 With prefix argument N, moves backward N non-deleted messages,
1907 or forward if N is negative."
1909 (rmail-next-undeleted-message (- n
)))
1911 (defun rmail-first-message ()
1912 "Show first message in file."
1914 (rmail-maybe-set-message-counters)
1915 (rmail-show-message 1))
1917 (defun rmail-last-message ()
1918 "Show last message in file."
1920 (rmail-maybe-set-message-counters)
1921 (rmail-show-message rmail-total-messages
))
1923 (defun rmail-what-message ()
1924 (let ((where (point))
1926 (high rmail-total-messages
)
1927 (mid (/ rmail-total-messages
2)))
1928 (while (> (- high low
) 1)
1929 (if (>= where
(rmail-msgbeg mid
))
1932 (setq mid
(+ low
(/ (- high low
) 2))))
1933 (if (>= where
(rmail-msgbeg high
)) high low
)))
1935 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
1937 (goto-char (rmail-msgbeg msg
))
1938 (search-forward "\n*** EOOH ***\n")
1939 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
1940 (or (string-match recipients
(or (mail-fetch-field "To") ""))
1941 (string-match recipients
(or (mail-fetch-field "From") ""))
1942 (if (not primary-only
)
1943 (string-match recipients
(or (mail-fetch-field "Cc") ""))))))
1945 (defun rmail-message-regexp-p (msg regexp
)
1946 "Return t, if for message number MSG, regexp REGEXP matches in the header."
1947 (goto-char (rmail-msgbeg msg
))
1950 (search-forward "*** EOOH ***" (point-max)) (point))))
1951 (re-search-forward regexp end t
)))
1953 (defvar rmail-search-last-regexp nil
)
1954 (defun rmail-search (regexp &optional n
)
1955 "Show message containing next match for REGEXP (but not the current msg).
1956 Prefix argument gives repeat count; negative argument means search
1957 backwards (through earlier messages).
1958 Interactively, empty argument means use same regexp used last time."
1960 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1962 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
1964 (if rmail-search-last-regexp
1965 (setq prompt
(concat prompt
1967 rmail-search-last-regexp
1969 (setq regexp
(read-string prompt
))
1970 (cond ((not (equal regexp
""))
1971 (setq rmail-search-last-regexp regexp
))
1972 ((not rmail-search-last-regexp
)
1973 (error "No previous Rmail search string")))
1974 (list rmail-search-last-regexp
1975 (prefix-numeric-value current-prefix-arg
))))
1977 (message "%sRmail search for %s..."
1978 (if (< n
0) "Reverse " "")
1980 (rmail-maybe-set-message-counters)
1981 (let ((omin (point-min))
1986 (msg rmail-current-message
))
1991 ;; Check messages one by one, advancing message number up or down
1992 ;; but searching forward through each message.
1994 (while (and (null win
) (> msg
1))
1995 (goto-char (rmail-msgbeg (setq msg
(1- msg
))))
1996 (setq win
(re-search-forward
1997 regexp
(rmail-msgend msg
) t
)))
1998 (while (and (null win
) (< msg rmail-total-messages
))
1999 (goto-char (rmail-msgbeg (setq msg
(1+ msg
))))
2000 (setq win
(re-search-forward regexp
(rmail-msgend msg
) t
))))
2001 (setq n
(+ n
(if reversep
1 -
1)))))
2004 ;; If this is a reverse search and we found a message,
2005 ;; search backward thru this message to position point.
2008 (goto-char (rmail-msgend msg
))
2010 regexp
(rmail-msgbeg msg
) t
)))
2012 (rmail-show-message msg
)
2013 (message "%sRmail search for %s...done"
2014 (if reversep
"Reverse " "")
2018 (narrow-to-region omin omax
)
2020 (message "Search failed: %s" regexp
)))))
2022 (defun rmail-search-backwards (regexp &optional n
)
2023 "Show message containing previous match for REGEXP.
2024 Prefix argument gives repeat count; negative argument means search
2025 forward (through later messages).
2026 Interactively, empty argument means use same regexp used last time."
2028 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
2030 (concat (if reversep
"Reverse " "") "Rmail search (regexp): "))
2032 (if rmail-search-last-regexp
2033 (setq prompt
(concat prompt
2035 rmail-search-last-regexp
2037 (setq regexp
(read-string prompt
))
2038 (cond ((not (equal regexp
""))
2039 (setq rmail-search-last-regexp regexp
))
2040 ((not rmail-search-last-regexp
)
2041 (error "No previous Rmail search string")))
2042 (list rmail-search-last-regexp
2043 (prefix-numeric-value current-prefix-arg
))))
2044 (rmail-search regexp
(- (or n
1))))
2046 ;; Show the first message which has the `unseen' attribute.
2047 (defun rmail-first-unseen-message ()
2048 (rmail-maybe-set-message-counters)
2053 (while (and (not found
) (<= current rmail-total-messages
))
2054 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
2055 (setq found current
))
2056 (setq current
(1+ current
))))
2057 ;; Let the caller show the message.
2059 ;; (rmail-show-message found))
2062 (defun rmail-next-same-subject (n)
2063 "Go to the next mail message having the same subject header.
2064 With prefix argument N, do this N times.
2065 If N is negative, go backwards instead."
2067 (let ((subject (mail-fetch-field "Subject"))
2069 (i rmail-current-message
)
2070 (case-fold-search t
)
2071 search-regexp found
)
2072 (if (string-match "Re:[ \t]*" subject
)
2073 (setq subject
(substring subject
(match-end 0))))
2074 (setq search-regexp
(concat "^Subject: *\\(Re: *\\)?"
2075 (regexp-quote subject
)
2080 (while (and (/= n
0)
2082 (< i rmail-total-messages
)
2085 (while (and (not done
)
2087 (< i rmail-total-messages
)
2089 (setq i
(if forward
(1+ i
) (1- i
)))
2090 (goto-char (rmail-msgbeg i
))
2091 (search-forward "\n*** EOOH ***\n")
2092 (let ((beg (point)) end
)
2093 (search-forward "\n\n")
2096 (setq done
(re-search-forward search-regexp end t
))))
2097 (if done
(setq found i
)))
2098 (setq n
(if forward
(1- n
) (1+ n
))))))
2100 (rmail-show-message found
)
2101 (error "No %s message with same subject"
2102 (if forward
"following" "previous")))))
2104 (defun rmail-previous-same-subject (n)
2105 "Go to the previous mail message having the same subject header.
2106 With prefix argument N, do this N times.
2107 If N is negative, go forwards instead."
2109 (rmail-next-same-subject (- n
)))
2111 ;;;; *** Rmail Message Deletion Commands ***
2113 (defun rmail-message-deleted-p (n)
2114 (= (aref rmail-deleted-vector n
) ?D
))
2116 (defun rmail-set-message-deleted-p (n state
)
2117 (aset rmail-deleted-vector n
(if state ?D ?\
)))
2119 (defun rmail-delete-message ()
2120 "Delete this message and stay on it."
2122 (rmail-set-attribute "deleted" t
)
2123 (run-hooks 'rmail-delete-message-hook
))
2125 (defun rmail-undelete-previous-message ()
2126 "Back up to deleted message, select it, and undelete it."
2128 (let ((msg rmail-current-message
))
2129 (while (and (> msg
0)
2130 (not (rmail-message-deleted-p msg
)))
2131 (setq msg
(1- msg
)))
2133 (error "No previous deleted message")
2134 (if (/= msg rmail-current-message
)
2135 (rmail-show-message msg
))
2136 (rmail-set-attribute "deleted" nil
)
2137 (if (rmail-summary-exists)
2139 (set-buffer rmail-summary-buffer
)
2140 (rmail-summary-mark-undeleted msg
)))
2141 (rmail-maybe-display-summary))))
2143 (defun rmail-delete-forward (&optional backward
)
2144 "Delete this message and move to next nondeleted one.
2145 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
2146 With prefix argument, delete and move backward.
2148 Returns t if a new message is displayed after the delete, or nil otherwise."
2150 (rmail-set-attribute "deleted" t
)
2151 (run-hooks 'rmail-delete-message-hook
)
2152 (let ((del-msg rmail-current-message
))
2153 (if (rmail-summary-exists)
2154 (rmail-select-summary
2155 (rmail-summary-mark-deleted del-msg
)))
2156 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
2157 (rmail-maybe-display-summary))))
2159 (defun rmail-delete-backward ()
2160 "Delete this message and move to previous nondeleted one.
2161 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
2163 (rmail-delete-forward t
))
2165 ;; Compute the message number a given message would have after expunging.
2166 ;; The present number of the message is OLDNUM.
2167 ;; DELETEDVEC should be rmail-deleted-vector.
2168 ;; The value is nil for a message that would be deleted.
2169 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
2170 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
2175 (if (/= (aref deletedvec i
) ?D
)
2176 (setq newnum
(1+ newnum
)))
2180 (defun rmail-only-expunge ()
2181 "Actually erase all deleted messages in the file."
2183 (message "Expunging deleted messages...")
2184 ;; Discard all undo records for this buffer.
2185 (or (eq buffer-undo-list t
)
2186 (setq buffer-undo-list nil
))
2187 (rmail-maybe-set-message-counters)
2188 (let* ((omax (- (buffer-size) (point-max)))
2189 (omin (- (buffer-size) (point-min)))
2190 (opoint (if (and (> rmail-current-message
0)
2191 (rmail-message-deleted-p rmail-current-message
))
2193 (- (point) (point-min))))
2194 (messages-head (cons (aref rmail-message-vector
0) nil
))
2195 (messages-tail messages-head
)
2196 ;; Don't make any undo records for the expunging.
2197 (buffer-undo-list t
)
2202 (goto-char (point-min))
2205 (total rmail-total-messages
)
2206 (new-message-number rmail-current-message
)
2208 (rmailbuf (current-buffer))
2209 (buffer-read-only nil
)
2210 (messages rmail-message-vector
)
2211 (deleted rmail-deleted-vector
)
2212 (summary rmail-summary-vector
))
2213 (setq rmail-total-messages nil
2214 rmail-current-message nil
2215 rmail-message-vector nil
2216 rmail-deleted-vector nil
2217 rmail-summary-vector nil
)
2219 ;; Find each sendmail buffer that is set to reply
2220 ;; to a message in this buffer, and update its
2222 (let ((bufs (buffer-list)))
2225 (set-buffer (car bufs
))
2226 (and (boundp 'rmail-send-actions-rmail-buffer
)
2227 (eq rmail-send-actions-rmail-buffer rmailbuf
)
2228 (setq rmail-send-actions-rmail-msg-number
2229 (rmail-msg-number-after-expunge
2231 rmail-send-actions-rmail-msg-number
))))
2232 (setq bufs
(cdr bufs
))))
2234 (while (<= number total
)
2235 (if (= (aref deleted number
) ?D
)
2238 (marker-position (aref messages number
))
2239 (marker-position (aref messages
(1+ number
))))
2240 (move-marker (aref messages number
) nil
)
2241 (if (> new-message-number counter
)
2242 (setq new-message-number
(1- new-message-number
))))
2243 (setq counter
(1+ counter
))
2245 (setcdr messages-tail
2246 (cons (aref messages number
) nil
)))
2248 (cons (if (= counter number
) (aref summary
(1- number
)))
2250 (if (zerop (%
(setq number
(1+ number
)) 20))
2251 (message "Expunging deleted messages...%d" number
)))
2253 (setcdr messages-tail
2254 (cons (aref messages number
) nil
)))
2255 (setq rmail-current-message new-message-number
2256 rmail-total-messages counter
2257 rmail-message-vector
(apply 'vector messages-head
)
2258 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
2259 rmail-summary-vector
(vconcat (nreverse new-summary
))
2261 (message "Expunging deleted messages...done")
2263 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
2265 (if (zerop rmail-current-message
) 1 nil
))
2266 (goto-char (+ (point) opoint
)))))
2268 (defun rmail-expunge ()
2269 "Erase deleted messages from Rmail file and summary buffer."
2271 (rmail-only-expunge)
2272 (if (rmail-summary-exists)
2273 (rmail-select-summary
2274 (rmail-update-summary))))
2276 ;;;; *** Rmail Mailing Commands ***
2278 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
2279 replybuffer sendactions same-window others
)
2282 (setq yank-action
(list 'insert-buffer replybuffer
)))
2283 (setq others
(cons (cons "cc" cc
) others
))
2284 (setq others
(cons (cons "in-reply-to" in-reply-to
) others
))
2286 (compose-mail to subject others
2288 yank-action sendactions
)
2289 (if (and window-system rmail-mail-new-frame
)
2291 (compose-mail to subject others
2292 noerase
'switch-to-buffer-other-frame
2293 yank-action sendactions
)
2294 ;; This is not a standard frame parameter;
2295 ;; nothing except sendmail.el looks at it.
2296 (modify-frame-parameters (selected-frame)
2297 '((mail-dedicated-frame . t
))))
2298 (compose-mail to subject others
2299 noerase
'switch-to-buffer-other-window
2300 yank-action sendactions
)))))
2302 (defun rmail-mail ()
2303 "Send mail in another window.
2304 While composing the message, use \\[mail-yank-original] to yank the
2305 original message into it."
2307 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
2309 (defun rmail-continue ()
2310 "Continue composing outgoing message previously being composed."
2312 (rmail-start-mail t
))
2314 (put 'rmail-send-actions-rmail-buffer
'permanent-local t
)
2315 (put 'rmail-send-actions-rmail-msg-number
'permanent-local t
)
2317 (defun rmail-reply (just-sender)
2318 "Reply to the current message.
2319 Normally include CC: to all other recipients of original message;
2320 prefix argument means ignore them. While composing the reply,
2321 use \\[mail-yank-original] to yank the original message into it."
2323 (let (from reply-to cc subject date to message-id references
2324 resent-to resent-cc resent-reply-to
2325 (msgnum rmail-current-message
))
2329 (goto-char (rmail-msgbeg rmail-current-message
))
2331 (if (= (following-char) ?
0)
2333 (progn (forward-line 2)
2335 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
2338 (narrow-to-region (point)
2339 (progn (search-forward "\n*** EOOH ***\n")
2340 (beginning-of-line) (point))))
2341 (setq from
(mail-fetch-field "from")
2342 reply-to
(or (mail-fetch-field "reply-to" nil t
)
2344 cc
(and (not just-sender
)
2345 (mail-fetch-field "cc" nil t
))
2346 subject
(mail-fetch-field "subject")
2347 date
(mail-fetch-field "date")
2348 to
(or (mail-fetch-field "to" nil t
) "")
2349 message-id
(mail-fetch-field "message-id")
2350 references
(mail-fetch-field "references" nil nil t
)
2351 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
2352 resent-cc
(and (not just-sender
)
2353 (mail-fetch-field "resent-cc" nil t
))
2354 resent-to
(or (mail-fetch-field "resent-to" nil t
) "")
2355 ;;; resent-subject (mail-fetch-field "resent-subject")
2356 ;;; resent-date (mail-fetch-field "resent-date")
2357 ;;; resent-message-id (mail-fetch-field "resent-message-id")
2359 ;; Merge the resent-to and resent-cc into the to and cc.
2360 (if (and resent-to
(not (equal resent-to
"")))
2361 (if (not (equal to
""))
2362 (setq to
(concat to
", " resent-to
))
2363 (setq to resent-to
)))
2364 (if (and resent-cc
(not (equal resent-cc
"")))
2365 (if (not (equal cc
""))
2366 (setq cc
(concat cc
", " resent-cc
))
2367 (setq cc resent-cc
)))
2368 ;; Add `Re: ' to subject if not there already.
2369 (and (stringp subject
)
2371 (concat rmail-reply-prefix
2372 (if (let ((case-fold-search t
))
2373 (string-match rmail-reply-regexp subject
))
2374 (substring subject
(match-end 0))
2376 (rmail-start-mail nil
2377 (mail-strip-quoted-names reply-to
)
2379 (rmail-make-in-reply-to-field from date message-id
)
2382 (let* ((cc-list (rmail-dont-reply-to
2383 (mail-strip-quoted-names
2384 (if (null cc
) to
(concat to
", " cc
))))))
2385 (if (string= cc-list
"") nil cc-list
)))
2387 (list (list '(lambda ()
2388 (let ((msgnum rmail-send-actions-rmail-msg-number
))
2390 (set-buffer rmail-send-actions-rmail-buffer
)
2392 (rmail-set-attribute "answered" t msgnum
)))))))
2394 (list (cons "References" (concat (mapconcat 'identity references
" ")
2396 ;; We keep the rmail buffer and message number in these
2397 ;; buffer-local vars in the sendmail buffer,
2398 ;; so that rmail-only-expunge can relocate the message number.
2399 (make-local-variable 'rmail-send-actions-rmail-buffer
)
2400 (make-local-variable 'rmail-send-actions-rmail-msg-number
)
2401 (setq rmail-send-actions-rmail-buffer rmail-view-buffer
)
2402 (setq rmail-send-actions-rmail-msg-number msgnum
)))
2404 (defun rmail-make-in-reply-to-field (from date message-id
)
2411 (let ((tem (car (rfc822-addresses from
))))
2414 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
2415 (substring tem
0 (match-beginning 0))
2418 ;; Message-ID is sufficiently informative
2420 (concat message-id
" (" tem
")"))
2421 ;; Copy TEM, discarding text properties.
2422 (setq tem
(copy-sequence tem
))
2423 (set-text-properties 0 (length tem
) nil tem
)
2424 (setq tem
(copy-sequence tem
))
2425 ;; Use prin1 to fake RFC822 quoting
2426 (let ((field (prin1-to-string tem
)))
2428 (concat field
"'s message of " date
)
2430 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
2431 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
2432 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
2433 (or (string-match (concat "\\`[ \t]*\\(" bar
2434 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
2435 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
2437 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
2438 bar
"\\))[ \t]*\\'")
2439 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
2441 (let ((start (match-beginning 1))
2442 (end (match-end 1)))
2443 ;; Trim whitespace which above regexp match allows
2444 (while (and (< start end
)
2445 (memq (aref from start
) '(?
\t ?\
)))
2446 (setq start
(1+ start
)))
2447 (while (and (< start end
)
2448 (memq (aref from
(1- end
)) '(?
\t ?\
)))
2449 (setq end
(1- end
)))
2450 (let ((field (substring from start end
)))
2451 (if date
(setq field
(concat "message from " field
" on " date
)))
2453 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
2454 (concat message-id
" (" field
")")
2457 ;; If we can't kludge it simply, do it correctly
2458 (let ((mail-use-rfc822 t
))
2459 (rmail-make-in-reply-to-field from date message-id
)))))
2461 (defun rmail-forward (resend)
2462 "Forward the current message to another user.
2463 With prefix argument, \"resend\" the message instead of forwarding it;
2464 see the documentation of `rmail-resend'."
2467 (call-interactively 'rmail-resend
)
2468 (let ((forward-buffer (current-buffer))
2469 (msgnum rmail-current-message
)
2470 (subject (concat "["
2471 (let ((from (or (mail-fetch-field "From")
2472 (mail-fetch-field ">From"))))
2474 (concat (mail-strip-quoted-names from
) ": ")
2476 (or (mail-fetch-field "Subject") "")
2478 (if (rmail-start-mail
2479 nil nil subject nil nil nil
2480 (list (list (function
2483 rmail-send-actions-rmail-msg-number
))
2485 (set-buffer rmail-send-actions-rmail-buffer
)
2487 (rmail-set-attribute
2488 "forwarded" t msgnum
))))))))
2489 ;; If only one window, use it for the mail buffer.
2490 ;; Otherwise, use another window for the mail buffer
2491 ;; so that the Rmail buffer remains visible
2492 ;; and sending the mail will get back to it.
2493 (and (not rmail-mail-new-frame
) (one-window-p t
)))
2494 ;; The mail buffer is now current.
2496 ;; We keep the rmail buffer and message number in these
2497 ;; buffer-local vars in the sendmail buffer,
2498 ;; so that rmail-only-expunge can relocate the message number.
2499 (make-local-variable 'rmail-send-actions-rmail-buffer
)
2500 (make-local-variable 'rmail-send-actions-rmail-msg-number
)
2501 (setq rmail-send-actions-rmail-buffer forward-buffer
)
2502 (setq rmail-send-actions-rmail-msg-number msgnum
)
2503 ;; Insert after header separator--before signature if any.
2504 (goto-char (point-min))
2505 (search-forward-regexp
2506 (concat "^" (regexp-quote mail-header-separator
) "$"))
2508 (insert "------- Start of forwarded message -------\n")
2509 ;; Quote lines with `- ' if they start with `-'.
2510 (let ((beg (point)) end
)
2511 (setq end
(point-marker))
2512 (set-marker-insertion-type end t
)
2513 (insert-buffer-substring forward-buffer
)
2515 (while (re-search-forward "^-" nil t
)
2520 (skip-chars-backward "\n")
2523 (delete-region (point) end
)
2524 (set-marker end nil
))
2525 (insert "------- End of forwarded message -------\n")
2528 (defun rmail-resend (address &optional from comment mail-alias-file
)
2529 "Resend current message to ADDRESSES.
2530 ADDRESSES should be a single address, a string consisting of several
2531 addresses separated by commas, or a list of addresses.
2533 Optional FROM is the address to resend the message from, and
2534 defaults to the username of the person redistributing the message.
2535 Optional COMMENT is a string that will be inserted as a comment in the
2537 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
2538 typically for purposes of moderating a list."
2539 (interactive "sResend to: ")
2541 (require 'mailalias
)
2542 (if (not from
) (setq from
(user-login-name)))
2543 (let ((tembuf (generate-new-buffer " sendmail temp"))
2544 (mail-header-separator "")
2545 (case-fold-search nil
)
2546 (mailbuf (current-buffer)))
2549 ;;>> Copy message into temp buffer
2551 (insert-buffer-substring mailbuf
)
2552 (goto-char (point-min))
2553 ;; Delete any Sender field, since that's not specifiable.
2554 ; Only delete Sender fields in the actual header.
2555 (re-search-forward "^$" nil
'move
)
2556 ; Using "while" here rather than "if" because some buggy mail
2557 ; software may have inserted multiple Sender fields.
2558 (while (re-search-backward "^Sender:" nil t
)
2562 (while (looking-at "[ \t]")
2564 (delete-region beg
(point))))
2565 ; Go back to the beginning of the buffer so the Resent- fields
2566 ; are inserted there.
2567 (goto-char (point-min))
2568 ;;>> Insert resent-from:
2569 (insert "Resent-From: " from
"\n")
2570 (insert "Resent-Date: " (mail-rfc822-date) "\n")
2571 ;;>> Insert resent-to: and bcc if need be.
2572 (let ((before (point)))
2574 (insert "Resent-Bcc: " (user-login-name) "\n"))
2575 (insert "Resent-To: " (if (stringp address
)
2577 (mapconcat 'identity address
",\n\t"))
2579 ;; Expand abbrevs in the recipients.
2581 (if (featurep 'mailabbrev
)
2582 (let ((end (point-marker))
2583 (local-abbrev-table mail-abbrevs
)
2584 (old-syntax-table (syntax-table)))
2585 (if (and (not (vectorp mail-abbrevs
))
2586 (file-exists-p mail-personal-alias-file
))
2587 (build-mail-abbrevs))
2588 (set-syntax-table mail-abbrev-syntax-table
)
2590 (while (and (< (point) end
)
2591 (progn (forward-word 1)
2594 (set-syntax-table old-syntax-table
))
2595 (expand-mail-aliases before
(point)))))
2596 ;;>> Set up comment, if any.
2597 (if (and (sequencep comment
) (not (zerop (length comment
))))
2598 (let ((before (point))
2601 (or (eolp) (insert "\n"))
2602 (setq after
(point))
2604 (while (< (point) after
)
2605 (insert "Resent-Comment: ")
2607 ;; Don't expand aliases in the destination fields
2608 ;; of the original message.
2610 (funcall send-mail-function
)))
2611 (kill-buffer tembuf
))
2612 (rmail-set-attribute "resent" t rmail-current-message
)))
2614 (defvar mail-unsent-separator
2615 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
2616 "^ *---+ +Returned message +---+ *$\\|"
2617 "^Start of returned message$\\|"
2618 "^ *---+ +Original message +---+ *$\\|"
2619 "^ *--+ +begin message +--+ *$\\|"
2620 "^ *---+ +Original message follows +---+ *$\\|"
2621 "^|? *---+ +Message text follows: +---+ *|?$")
2622 "A regexp that matches the separator before the text of a failed message.")
2624 (defun rmail-retry-failure ()
2625 "Edit a mail message which is based on the contents of the current message.
2626 For a message rejected by the mail system, extract the interesting headers and
2627 the body of the original message.
2628 The variable `mail-unsent-separator' should match the string that
2629 delimits the returned original message.
2630 The variable `rmail-retry-ignored-headers' is a regular expression
2631 specifying headers which should not be copied into the new message."
2633 (require 'mail-utils
)
2634 (let ((rmail-buffer (current-buffer))
2635 (msgnum rmail-current-message
)
2636 bounce-start bounce-end bounce-indent resending
)
2638 ;; Narrow down to just the quoted original message
2639 (rmail-beginning-of-message)
2640 (let ((case-fold-search t
))
2641 (if (search-forward "This is a MIME-encapsulated message\n\n--" nil t
)
2643 (buffer-substring (progn (beginning-of-line) (point))
2644 (progn (end-of-line) (point)))))
2645 (or (re-search-forward mail-unsent-separator nil t
)
2646 (error "Cannot find beginning of header in failed message"))
2647 (or (and (search-forward codestring nil t
)
2648 (search-forward "\n\n" nil t
))
2649 (error "Cannot find end of Mime data in failed message"))
2650 (setq bounce-start
(point))
2652 (goto-char (point-max))
2653 (search-backward codestring
)
2654 (setq bounce-end
(point)))
2655 (or (search-forward "\n\n" nil t
)
2656 (error "Cannot find end of header in failed message")))
2657 (or (re-search-forward mail-unsent-separator nil t
)
2658 (error "Cannot parse this as a failure message"))
2659 (skip-chars-forward "\n")
2660 ;; Support a style of failure message in which the original
2661 ;; message is indented, and included within lines saying
2662 ;; `Start of returned message' and `End of returned message'.
2663 (if (looking-at " +Received:")
2665 (setq bounce-start
(point))
2666 (skip-chars-forward " ")
2667 (setq bounce-indent
(- (current-column)))
2668 (goto-char (point-max))
2669 (re-search-backward "^End of returned message$" nil t
)
2670 (setq bounce-end
(point)))
2671 ;; One message contained a few random lines before the old
2672 ;; message header. The first line of the message started with
2673 ;; two hyphens. A blank line followed these random lines.
2674 ;; The same line beginning with two hyphens was possibly
2675 ;; marking the end of the message.
2676 (if (looking-at "^--")
2677 (let ((boundary (buffer-substring-no-properties
2679 (progn (end-of-line) (point)))))
2680 (search-forward "\n\n")
2681 (skip-chars-forward "\n")
2682 (setq bounce-start
(point))
2683 (goto-char (point-max))
2684 (search-backward (concat "\n\n" boundary
) bounce-start t
)
2685 (setq bounce-end
(point)))
2686 (setq bounce-start
(point)
2687 bounce-end
(point-max)))
2688 (or (search-forward "\n\n" nil t
)
2689 (error "Cannot find end of header in failed message"))
2691 ;; Start sending a new message; default header fields from the original.
2692 ;; Turn off the usual actions for initializing the message body
2693 ;; because we want to get only the text from the failure message.
2695 ;; This function will be called when the user sends the retry.
2696 ;; It will mark the bounce message as "retried".
2697 (function (lambda ()
2698 (let ((msgnum rmail-send-actions-rmail-msg-number
))
2700 (set-buffer rmail-send-actions-rmail-buffer
)
2702 (rmail-set-attribute "retried" t msgnum
)))))))
2703 mail-signature mail-setup-hook
)
2704 (if (rmail-start-mail nil nil nil nil nil rmail-buffer
2705 (list (list action
)))
2706 ;; Insert original text as initial text of new draft message.
2707 ;; Bind inhibit-read-only since the header delimiter
2708 ;; of the previous message was probably read-only.
2709 (let ((inhibit-read-only t
))
2710 ;; We keep the rmail buffer and message number in these
2711 ;; buffer-local vars in the sendmail buffer,
2712 ;; so that the rmail-only-expunge can relocate the message number.
2713 (make-local-variable 'rmail-send-actions-rmail-buffer
)
2714 (make-local-variable 'rmail-send-actions-rmail-msg-number
)
2715 (setq rmail-send-actions-rmail-buffer rmail-buffer
)
2716 (setq rmail-send-actions-rmail-msg-number msgnum
)
2718 (insert-buffer-substring rmail-buffer bounce-start bounce-end
)
2719 (goto-char (point-min))
2721 (indent-rigidly (point-min) (point-max) bounce-indent
))
2722 (rmail-clear-headers rmail-retry-ignored-headers
)
2723 (rmail-clear-headers "^sender:\\|^from:\\|^return-path:")
2724 (goto-char (point-min))
2726 (search-forward "\n\n")
2728 (narrow-to-region (point-min) (point))
2729 (setq resending
(mail-fetch-field "resent-to"))
2732 (insert "Resent-Bcc: " (user-login-name) "\n")
2733 (insert "BCC: " (user-login-name) "\n"))))
2734 (insert mail-header-separator
)
2735 (mail-position-on-field (if resending
"Resent-To" "To") t
)
2736 (set-buffer rmail-buffer
)
2737 (rmail-beginning-of-message))))))
2739 (defun rmail-summary-exists ()
2740 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
2741 In fact, the non-nil value returned is the summary buffer itself."
2742 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
2743 rmail-summary-buffer
))
2745 (defun rmail-summary-displayed ()
2746 "t iff in RMAIL buffer and an associated summary buffer is displayed."
2747 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
2749 (defvar rmail-redisplay-summary nil
2750 "*Non-nil means Rmail should show the summary when it changes.
2751 This has an effect only if a summary buffer exists.")
2753 (defvar rmail-summary-window-size nil
2754 "*Non-nil means specify the height for an Rmail summary window.")
2756 ;; Put the summary buffer back on the screen, if user wants that.
2757 (defun rmail-maybe-display-summary ()
2758 (let ((selected (selected-window))
2760 ;; If requested, make sure the summary is displayed.
2761 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
2762 rmail-redisplay-summary
2763 (if (get-buffer-window rmail-summary-buffer
0)
2764 ;; It's already in some frame; show that one.
2765 (let ((frame (window-frame
2766 (get-buffer-window rmail-summary-buffer
0))))
2767 (make-frame-visible frame
)
2768 (raise-frame frame
))
2769 (display-buffer rmail-summary-buffer
)))
2770 ;; If requested, set the height of the summary window.
2771 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
2772 rmail-summary-window-size
2773 (setq window
(get-buffer-window rmail-summary-buffer
))
2774 ;; Don't try to change the size if just one window in frame.
2775 (not (eq window
(frame-root-window (window-frame window
))))
2778 (select-window window
)
2779 (enlarge-window (- rmail-summary-window-size
(window-height))))
2780 (select-window selected
)))))
2782 ;;;; *** Rmail Local Fontification ***
2784 (defun rmail-fontify-buffer-function ()
2785 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
2786 (make-local-hook 'rmail-show-message-hook
)
2787 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
2788 ;; If we're already showing a message, fontify it now.
2789 (if rmail-current-message
(rmail-fontify-message))
2790 ;; Prevent Font Lock mode from kicking in.
2791 (setq font-lock-fontified t
))
2793 (defun rmail-unfontify-buffer-function ()
2794 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
2795 (let ((modified (buffer-modified-p))
2796 (buffer-undo-list t
) (inhibit-read-only t
)
2797 before-change-functions after-change-functions
2798 buffer-file-name buffer-file-truename
)
2801 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
2802 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
2803 (font-lock-default-unfontify-buffer)
2804 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))
2806 (defun rmail-fontify-message ()
2807 ;; Fontify the current message if it is not already fontified.
2808 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
2809 (let ((modified (buffer-modified-p))
2810 (buffer-undo-list t
) (inhibit-read-only t
)
2811 before-change-functions after-change-functions
2812 buffer-file-name buffer-file-truename
)
2815 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
2816 (font-lock-fontify-region (point-min) (point-max))
2817 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))))
2821 ;;; rmail.el ends here