1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
3 ;; Copyright (C) 1985,86,87,88,93,94 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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
27 ;; New features include attribute and keyword support, message
28 ;; selection by dispatch table, summary by attributes and keywords,
29 ;; expunging by dispatch table, sticky options for file commands.
31 ;; Extended by Bob Weiner of Motorola
32 ;; New features include: rmail and rmail-summary buffers remain
33 ;; synchronized and key bindings basically operate the same way in both
34 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
35 ;; variable, and a bury rmail buffer (wipe) command.
40 ;; For Emacs V18 compatibility
41 (and (not (fboundp 'buffer-disable-undo))
42 (fboundp 'buffer-flush-undo)
43 (defalias 'buffer-disable-undo 'buffer-flush-undo))
45 ; These variables now declared in paths.el.
46 ;(defvar rmail-spool-directory "/usr/spool/mail/"
47 ; "This is the name of the directory used by the system mailer for\n\
48 ;delivering new mail. It's name should end with a slash.")
49 ;(defvar rmail-file-name
50 ; (expand-file-name "~/RMAIL")
53 (defvar rmail-movemail-program nil
54 "If non-nil, name of program for fetching new mail.")
57 (defvar rmail-dont-reply-to-names nil "\
58 *A regexp specifying names to prune of reply to messages.
59 A value of nil means exclude your own name only.")
62 (defvar rmail-default-dont-reply-to-names "info-" "\
63 A regular expression specifying part of the value of the default value of
64 the variable `rmail-dont-reply-to-names', for when the user does not set
65 `rmail-dont-reply-to-names' explicitly. (The other part of the default
66 value is the user's name.)
67 It is useful to set this variable in the site customization file.")
70 (defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|\
71 ^received:\\|^x400-originator:\\|^x400-recipients:\\|^x400-received:\\|\
72 ^x400-mts-identifier:\\|^x400-content-type:\\|^message-id:\\|^summary-line:"
73 "*Regexp to match Header fields that Rmail should normally hide.")
76 (defvar rmail-highlighted-headers "^From:\\|^Subject:" "\
77 *Regexp to match Header fields that Rmail should normally highlight.
78 A value of nil means don't highlight.
79 See also `rmail-highlight-face'.")
82 (defvar rmail-highlight-face nil "\
83 *Face used by Rmail for highlighting headers.")
86 (defvar rmail-delete-after-output nil "\
87 *Non-nil means automatically delete a message that is copied to a file.")
90 (defvar rmail-primary-inbox-list nil "\
91 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
92 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
93 \(the name varies depending on the operating system,
94 and the value of the environment variable MAIL overrides it).")
97 (defvar rmail-mail-new-frame nil
98 "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
101 (defvar rmail-retry-setup-hook nil
102 "Hook that `rmail-retry-failure' uses in place of `mail-setup-hook'.")
105 (defvar rmail-secondary-file-directory "~/"
106 "*Directory for additional secondary Rmail files.")
108 (defvar rmail-secondary-file-regexp "\\.xmail$"
109 "*Regexp for which files are secondary Rmail files.")
111 ;; These may be altered by site-init.el to match the format of mmdf files
112 ;; delimiting used on a given host (delim1 and delim2 from the config
115 (defvar mmdf-delim1 "^\001\001\001\001\n"
116 "Regexp marking the start of an mmdf message")
117 (defvar mmdf-delim2 "^\001\001\001\001\n"
118 "Regexp marking the end of an mmdf message")
120 (defvar rmail-message-filter nil
121 "If non nil, a filter function for new messages in RMAIL.
122 Called with region narrowed to the message, including headers.")
124 (defvar rmail-reply-prefix "Re: "
125 "String to prepend to Subject line when replying to a message.")
127 (defvar rmail-display-summary nil
128 "If non nil, the summary buffer is always displayed.")
130 (defvar rmail-mode-map nil)
132 (defvar rmail-inbox-list nil)
133 (defvar rmail-keywords nil)
135 ;; Message counters and markers. Deleted flags.
137 (defvar rmail-current-message nil)
138 (defvar rmail-total-messages nil)
139 (defvar rmail-message-vector nil)
140 (defvar rmail-deleted-vector nil)
142 (defvar rmail-overlay-list nil)
144 ;; These are used by autoloaded rmail-summary.
146 (defvar rmail-summary-buffer nil)
147 (defvar rmail-summary-vector nil)
149 ;; `Sticky' default variables.
151 ;; Last individual label specified to a or k.
152 (defvar rmail-last-label nil)
153 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
154 (defvar rmail-last-multi-labels nil)
155 (defvar rmail-last-regexp nil)
156 (defvar rmail-default-file nil
157 "*Default file name for \\[rmail-output].")
158 (defvar rmail-default-rmail-file (expand-file-name "~/XMAIL")
159 "*Default file name for \\[rmail-output-to-rmail-file].")
161 ;;; Regexp matching the delimiter of messages in UNIX mail format
162 ;;; (UNIX From lines), minus the initial ^. Note that if you change
163 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
164 ;;; that knows the exact ordering of the \\( \\) subexpressions.
165 (defvar rmail-unix-mail-delimiter
166 (let ((time-zone-regexp
167 (concat "\\([A-Z]?[A-Z][A-Z][A-Z]\\( DST\\)?"
168 "\\|[-+]?[0-9][0-9][0-9][0-9]"
174 ;; Username, perhaps with a quoted section that can contain spaces.
177 "\\(\\|\".*\"[^ \n]*\\)"
180 ;; The time the message was sent.
181 "\\([^ \n]*\\) *" ; day of the week
182 "\\([^ ]*\\) *" ; month
183 "\\([0-9]*\\) *" ; day of month
184 "\\([0-9:]*\\) *" ; time of day
186 ;; Perhaps a time zone, specified by an abbreviation, or by a
191 " [0-9][0-9]\\([0-9]*\\) *"
193 ;; On some systems the time zone can appear after the year, too.
197 "\\(remote from .*\\)?"
202 ;; Perform BODY in the summary buffer
203 ;; in such a way that its cursor is properly updated in its own window.
204 (defmacro rmail-select-summary (&rest body)
205 (` (let ((total rmail-total-messages))
206 (if (rmail-summary-displayed)
207 (let ((window (selected-window)))
211 (pop-to-buffer rmail-summary-buffer)
212 ;; rmail-total-messages is a buffer-local var
213 ;; in the rmail buffer.
214 ;; This way we make it available for the body
215 ;; even tho the rmail buffer is not current.
216 (let ((rmail-total-messages total))
218 (select-window window))))
220 (set-buffer rmail-summary-buffer)
221 (let ((rmail-total-messages total))
223 (rmail-maybe-display-summary))))
225 ;;;; *** Rmail Mode ***
228 (defun rmail (&optional file-name-arg)
229 "Read and edit incoming mail.
230 Moves messages into file named by `rmail-file-name' (a babyl format file)
231 and edits that file in RMAIL Mode.
232 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
234 May be called with file name as argument; then performs rmail editing on
235 that file, but does not copy any new mail into the file.
236 Interactively, if you supply a prefix argument, then you
237 have a chance to specify a file name with the minibuffer.
239 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
240 (interactive (if current-prefix-arg
241 (list (read-file-name "Run rmail on RMAIL file: "
243 (or rmail-default-file
244 (setq rmail-default-file (expand-file-name "~/xmail")))
245 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
246 (existed (get-file-buffer file-name)))
247 ;; Like find-file, but in the case where a buffer existed
248 ;; and the file was reverted, recompute the message-data.
249 (if (and existed (not (verify-visited-file-modtime existed)))
251 ;; Don't be confused by apparent local-variables spec
252 ;; in the last message in the RMAIL file.
253 (let ((enable-local-variables nil))
254 (find-file file-name))
255 (if (and (verify-visited-file-modtime existed)
256 (eq major-mode 'rmail-mode))
257 (progn (rmail-forget-messages)
258 (rmail-set-message-counters))))
259 (let ((enable-local-variables nil))
260 (find-file file-name)))
261 (if (eq major-mode 'rmail-edit-mode)
262 (error "Exit Rmail Edit mode before getting new mail."))
263 (if (and existed (> (buffer-size) 0))
264 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
265 (or (eq major-mode 'rmail-mode)
268 ;; Convert all or part to Babyl file if possible.
270 (goto-char (point-max))
271 (if (null rmail-inbox-list)
273 (rmail-set-message-counters)
274 (rmail-show-message))))
275 (let ((existing-unseen (rmail-first-unseen-message)))
277 (rmail-get-new-mail))
278 ;; Show the first unseen message, which might be from a previous session
279 ;; or might have been just read in by rmail-get-new-mail. Must
280 ;; determine already unseen messages first, as rmail-get-new-mail
281 ;; positions on the first new message, thus marking it as seen.
282 (rmail-show-message existing-unseen))
283 (if rmail-display-summary (rmail-summary))
284 (rmail-construct-io-menu)))
286 ;; Given the value of MAILPATH, return a list of inbox file names.
287 ;; This is turned off because it is not clear that the user wants
288 ;; all these inboxes to feed into the primary rmail file.
289 ; (defun rmail-convert-mailpath (string)
291 ; (while (setq idx (string-match "[%:]" string))
292 ; (let ((this (substring string 0 idx)))
293 ; (setq string (substring string (1+ idx)))
294 ; (setq list (cons (if (string-match "%" this)
295 ; (substring this 0 (string-match "%" this))
300 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
301 ; will not cause emacs 18.55 problems.
303 (defun rmail-convert-file ()
306 (goto-char (point-min))
307 ;; If file doesn't start like a Babyl file,
308 ;; convert it to one, by adding a header and converting each message.
309 (cond ((looking-at "BABYL OPTIONS:"))
310 ((looking-at "Version: 5\n")
311 ;; Losing babyl file made by old version of Rmail.
312 ;; Just fix the babyl file header; don't make a new one,
313 ;; so we don't lose the Labels: file attribute, etc.
314 (let ((buffer-read-only nil))
315 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
316 ((equal (point-min) (point-max))
317 ;; Empty RMAIL file. Just insert the header.
318 (rmail-insert-rmail-file-header))
320 ;; Non-empty file in non-RMAIL format. Add header and convert.
322 (rmail-insert-rmail-file-header)))
323 ;; If file was not a Babyl file or if there are
324 ;; Unix format messages added at the end,
325 ;; convert file as necessary.
328 (goto-char (point-max))
329 (search-backward "\^_")
331 (looking-at "\n*From ")))
332 (let ((buffer-read-only nil))
333 (message "Converting to Babyl format...")
334 ;; If file needs conversion, convert it all,
335 ;; except for the BABYL header.
336 ;; (rmail-convert-to-babyl-format would delete the header.)
337 (goto-char (point-min))
338 (search-forward "\n\^_" nil t)
339 (narrow-to-region (point) (point-max))
340 (rmail-convert-to-babyl-format)
341 (message "Converting to Babyl format...done")))))
343 ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
344 ;;; will not cause emacs 18.55 problems.
346 (defun rmail-insert-rmail-file-header ()
347 (let ((buffer-read-only nil))
348 (insert "BABYL OPTIONS: -*- rmail -*-
351 Note: This is the header of an rmail file.
352 Note: If you are seeing it in rmail,
353 Note: it means the file has no messages in it.\n\^_")))
357 (setq rmail-mode-map (make-keymap))
358 (suppress-keymap rmail-mode-map)
359 (define-key rmail-mode-map "a" 'rmail-add-label)
360 (define-key rmail-mode-map "b" 'rmail-bury)
361 (define-key rmail-mode-map "c" 'rmail-continue)
362 (define-key rmail-mode-map "d" 'rmail-delete-forward)
363 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)
364 (define-key rmail-mode-map "e" 'rmail-edit-current-message)
365 (define-key rmail-mode-map "f" 'rmail-forward)
366 (define-key rmail-mode-map "g" 'rmail-get-new-mail)
367 (define-key rmail-mode-map "h" 'rmail-summary)
368 (define-key rmail-mode-map "i" 'rmail-input)
369 (define-key rmail-mode-map "j" 'rmail-show-message)
370 (define-key rmail-mode-map "k" 'rmail-kill-label)
371 (define-key rmail-mode-map "l" 'rmail-summary-by-labels)
372 (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
373 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
374 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
375 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
376 (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
377 (define-key rmail-mode-map "m" 'rmail-mail)
378 (define-key rmail-mode-map "\em" 'rmail-retry-failure)
379 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message)
380 (define-key rmail-mode-map "\en" 'rmail-next-message)
381 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
382 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file)
383 (define-key rmail-mode-map "\C-o" 'rmail-output)
384 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message)
385 (define-key rmail-mode-map "\ep" 'rmail-previous-message)
386 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
387 (define-key rmail-mode-map "q" 'rmail-quit)
388 (define-key rmail-mode-map "r" 'rmail-reply)
389 ;; I find I can't live without the default M-r command -- rms.
390 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
391 (define-key rmail-mode-map "s" 'rmail-expunge-and-save)
392 (define-key rmail-mode-map "\es" 'rmail-search)
393 (define-key rmail-mode-map "t" 'rmail-toggle-header)
394 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message)
395 (define-key rmail-mode-map "w" 'rmail-edit-current-message)
396 (define-key rmail-mode-map "x" 'rmail-expunge)
397 (define-key rmail-mode-map "." 'rmail-beginning-of-message)
398 (define-key rmail-mode-map "<" 'rmail-first-message)
399 (define-key rmail-mode-map ">" 'rmail-last-message)
400 (define-key rmail-mode-map " " 'scroll-up)
401 (define-key rmail-mode-map "\177" 'scroll-down)
402 (define-key rmail-mode-map "?" 'describe-mode)
403 (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
404 (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
405 (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
406 (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
407 (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
408 (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
409 (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-keywords)
412 (define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
414 (define-key rmail-mode-map [menu-bar classify]
415 (cons "Classify" (make-sparse-keymap "Classify")))
417 (define-key rmail-mode-map [menu-bar classify input-menu]
420 (define-key rmail-mode-map [menu-bar classify output-menu]
423 (define-key rmail-mode-map [menu-bar classify output-inbox]
424 '("Output (inbox)..." . rmail-output))
426 (define-key rmail-mode-map [menu-bar classify output]
427 '("Output (Rmail)..." . rmail-output-to-rmail-file))
429 (define-key rmail-mode-map [menu-bar classify kill-label]
430 '("Kill Label..." . rmail-kill-label))
432 (define-key rmail-mode-map [menu-bar classify add-label]
433 '("Add Label..." . rmail-add-label))
435 (define-key rmail-mode-map [menu-bar summary]
436 (cons "Summary" (make-sparse-keymap "Summary")))
438 (define-key rmail-mode-map [menu-bar summary labels]
439 '("By Labels..." . rmail-summary-by-labels))
441 (define-key rmail-mode-map [menu-bar summary recipients]
442 '("By Recipients..." . rmail-summary-by-recipients))
444 (define-key rmail-mode-map [menu-bar summary topic]
445 '("By Topic..." . rmail-summary-by-topic))
447 (define-key rmail-mode-map [menu-bar summary regexp]
448 '("By Regexp..." . rmail-summary-by-regexp))
450 (define-key rmail-mode-map [menu-bar summary all]
451 '("All" . rmail-summary))
453 (define-key rmail-mode-map [menu-bar mail]
454 (cons "Mail" (make-sparse-keymap "Mail")))
456 (define-key rmail-mode-map [menu-bar mail rmail-get-new-mail]
457 '("Get New Mail" . rmail-get-new-mail))
459 (define-key rmail-mode-map [menu-bar mail lambda]
462 (define-key rmail-mode-map [menu-bar mail continue]
463 '("Continue" . rmail-continue))
465 (define-key rmail-mode-map [menu-bar mail resend]
466 '("Re-send..." . rmail-resend))
468 (define-key rmail-mode-map [menu-bar mail forward]
469 '("Forward" . rmail-forward))
471 (define-key rmail-mode-map [menu-bar mail retry]
472 '("Retry" . rmail-retry-failure))
474 (define-key rmail-mode-map [menu-bar mail reply]
475 '("Reply" . rmail-reply))
477 (define-key rmail-mode-map [menu-bar mail mail]
478 '("Mail" . rmail-mail))
480 (define-key rmail-mode-map [menu-bar delete]
481 (cons "Delete" (make-sparse-keymap "Delete")))
483 (define-key rmail-mode-map [menu-bar delete expunge/save]
484 '("Expunge/Save" . rmail-expunge-and-save))
486 (define-key rmail-mode-map [menu-bar delete expunge]
487 '("Expunge" . rmail-expunge))
489 (define-key rmail-mode-map [menu-bar delete undelete]
490 '("Undelete" . rmail-undelete-previous-message))
492 (define-key rmail-mode-map [menu-bar delete delete]
493 '("Delete" . rmail-delete-forward))
495 (define-key rmail-mode-map [menu-bar move]
496 (cons "Move" (make-sparse-keymap "Move")))
498 (define-key rmail-mode-map [menu-bar move search-back]
499 '("Search Back..." . rmail-search-backward))
501 (define-key rmail-mode-map [menu-bar move search]
502 '("Search..." . rmail-search))
504 (define-key rmail-mode-map [menu-bar move previous]
505 '("Previous Nondeleted" . rmail-previous-undeleted-message))
507 (define-key rmail-mode-map [menu-bar move next]
508 '("Next Nondeleted" . rmail-next-undeleted-message))
510 (define-key rmail-mode-map [menu-bar move last]
511 '("Last" . rmail-last-message))
513 (define-key rmail-mode-map [menu-bar move first]
514 '("First" . rmail-first-message))
516 (define-key rmail-mode-map [menu-bar move previous]
517 '("Previous" . rmail-previous-message))
519 (define-key rmail-mode-map [menu-bar move next]
520 '("Next" . rmail-next-message))
522 ;; Rmail mode is suitable only for specially formatted data.
523 (put 'rmail-mode 'mode-class 'special)
527 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
528 All normal editing commands are turned off.
529 Instead, these commands are available:
531 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
532 \\[scroll-up] Scroll to next screen of this message.
533 \\[scroll-down] Scroll to previous screen of this message.
534 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
535 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
536 \\[rmail-next-message] Move to Next message whether deleted or not.
537 \\[rmail-previous-message] Move to Previous message whether deleted or not.
538 \\[rmail-first-message] Move to the first message in Rmail file.
539 \\[rmail-last-message] Move to the last message in Rmail file.
540 \\[rmail-show-message] Jump to message specified by numeric position in file.
541 \\[rmail-search] Search for string and show message it is found in.
542 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
543 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
544 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
545 till a deleted message is found.
546 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
547 \\[rmail-expunge] Expunge deleted messages.
548 \\[rmail-expunge-and-save] Expunge and save the file.
549 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
550 \\[save-buffer] Save without expunging.
551 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
552 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
553 \\[rmail-continue] Continue composing outgoing message started before.
554 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
555 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
556 \\[rmail-forward] Forward this message to another user.
557 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
558 \\[rmail-output] Output this message to a Unix-format mail file (append it).
559 \\[rmail-input] Input Rmail file. Run Rmail on that file.
560 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
561 \\[rmail-kill-label] Kill label. Remove a label from current message.
562 \\[rmail-next-labeled-message] Move to Next message with specified label
563 (label defaults to last one specified).
564 Standard labels: filed, unseen, answered, forwarded, deleted.
565 Any other label is present only if you add it with \\[rmail-add-label].
566 \\[rmail-previous-labeled-message] Move to Previous message with specified label
567 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
568 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
569 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
570 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
571 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
572 \\[rmail-toggle-header] Toggle display of complete header."
575 (rmail-set-message-counters)
576 (rmail-show-message rmail-total-messages))
578 (defun rmail-mode-2 ()
579 (kill-all-local-variables)
582 (run-hooks 'rmail-mode-hook))
584 (defun rmail-mode-1 ()
585 (setq major-mode 'rmail-mode)
586 (setq mode-name "RMAIL")
587 (setq buffer-read-only t)
588 ;; No need to auto save RMAIL files in normal circumstances
589 ;; because they contain no info except attribute changes
590 ;; and deletion of messages.
591 ;; The one exception is when messages are copied into an Rmail mode buffer.
592 ;; rmail-output-to-rmail-file enables auto save when you do that.
593 (setq buffer-auto-save-file-name nil)
594 (if (boundp 'mode-line-modified)
595 (setq mode-line-modified "--- ")
596 (setq mode-line-format
597 (cons "--- " (cdr (default-value 'mode-line-format)))))
598 (use-local-map rmail-mode-map)
599 (set-syntax-table text-mode-syntax-table)
600 (setq local-abbrev-table text-mode-abbrev-table))
602 (defun rmail-variables ()
603 (make-local-variable 'revert-buffer-function)
604 (setq revert-buffer-function 'rmail-revert)
605 (make-local-variable 'rmail-last-label)
606 (make-local-variable 'rmail-last-regexp)
607 (make-local-variable 'rmail-deleted-vector)
608 (make-local-variable 'rmail-summary-buffer)
609 (make-local-variable 'rmail-summary-vector)
610 (make-local-variable 'rmail-current-message)
611 (make-local-variable 'rmail-total-messages)
612 (make-local-variable 'require-final-newline)
613 (setq require-final-newline nil)
614 (make-local-variable 'rmail-overlay-list)
615 (setq rmail-overlay-list nil)
616 (make-local-variable 'version-control)
617 (setq version-control 'never)
618 (make-local-variable 'file-precious-flag)
619 (setq file-precious-flag t)
620 (make-local-variable 'rmail-message-vector)
621 (make-local-variable 'rmail-inbox-list)
622 (setq rmail-inbox-list (rmail-parse-file-inboxes))
623 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
624 (and (null rmail-inbox-list)
625 (or (equal buffer-file-name (expand-file-name rmail-file-name))
626 (equal buffer-file-truename
627 (abbreviate-file-name (file-truename rmail-file-name))))
628 (setq rmail-inbox-list
629 (or rmail-primary-inbox-list
630 (list (or (getenv "MAIL")
631 (concat rmail-spool-directory
632 (user-login-name)))))))
633 (make-local-variable 'rmail-keywords)
634 ;; this gets generated as needed
635 (setq rmail-keywords nil))
637 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
638 (defun rmail-revert (arg noconfirm)
639 (let (revert-buffer-function)
640 ;; Call our caller again, but this time it does the default thing.
641 (if (revert-buffer arg noconfirm)
642 ;; If the user said "yes", and we changed something,
643 ;; reparse the messages.
646 (goto-char (point-max))
647 (rmail-set-message-counters)
648 (rmail-show-message)))))
650 ;; Return a list of files from this buffer's Mail: option.
651 ;; Does not assume that messages have been parsed.
652 ;; Just returns nil if buffer does not look like Babyl format.
653 (defun rmail-parse-file-inboxes ()
658 (cond ((looking-at "BABYL OPTIONS:")
659 (search-forward "\n\^_" nil 'move)
660 (narrow-to-region 1 (point))
662 (if (search-forward "\nMail:" nil t)
664 (narrow-to-region (point) (progn (end-of-line) (point)))
665 (goto-char (point-min))
666 (mail-parse-comma-list))))))))
668 (defun rmail-expunge-and-save ()
669 "Expunge and save RMAIL file."
673 (if (rmail-summary-exists)
674 (rmail-select-summary (set-buffer-modified-p nil))))
679 (rmail-expunge-and-save)
680 ;; Don't switch to the summary buffer even if it was recently visible.
681 (if rmail-summary-buffer
683 (replace-buffer-in-windows rmail-summary-buffer)
684 (bury-buffer rmail-summary-buffer)))
685 (let ((obuf (current-buffer)))
686 (replace-buffer-in-windows obuf)
690 (defun rmail-input (filename)
691 "Run Rmail on file FILENAME."
692 (interactive "FRun rmail on RMAIL file: ")
695 (defun rmail-find-all-files (start)
696 (if (file-accessible-directory-p start)
697 (let ((files (directory-files start nil
698 rmail-secondary-file-regexp))
701 (setq file (car files))
702 (setq files (cdr files))
704 (rmail-find-all-files (concat start "/" file))
706 (cons (file-name-nondirectory start) ret))
707 (file-name-nondirectory start)))
709 (defun rmail-list-to-menu (menu-name l action &optional full-name)
710 (let ((menu (make-sparse-keymap menu-name)))
712 (function (lambda (item)
716 (rmail-list-to-menu (car item) (cdr item)
719 (concat full-name "/"
722 (setq name (car item)))
726 (list 'lambda () '(interactive)
730 (concat full-name "/" item)
732 rmail-secondary-file-directory))))))
733 (define-key menu (vector (intern name))
734 (cons name command))))
738 (defun rmail-construct-io-menu ()
739 (let ((files (rmail-find-all-files rmail-secondary-file-directory)))
742 (define-key rmail-mode-map [menu-bar classify input-menu]
743 (cons "Input Rmail File"
744 (rmail-list-to-menu "Input Rmail File"
747 (define-key rmail-mode-map [menu-bar classify output-menu]
748 (cons "Output Rmail File"
749 (rmail-list-to-menu "Output Rmail File"
751 'rmail-output-to-rmail-file)))))
752 (message "No files matching %s/%s found"
753 rmail-secondary-file-directory rmail-secondary-file-regexp)))
756 ;;;; *** Rmail input ***
758 ;; RLK feature not added in this version:
759 ;; argument specifies inbox file or files in various ways.
761 (defun rmail-get-new-mail (&optional file-name)
762 "Move any new mail from this RMAIL file's inbox files.
763 The inbox files can be specified with the file's Mail: option. The
764 variable `rmail-primary-inbox-list' specifies the inboxes for your
765 primary RMAIL file if it has no Mail: option. By default, this is
766 your /usr/spool/mail/$USER.
768 You can also specify the file to get new mail from. In this case, the
769 file of new mail is not changed or deleted. Noninteractively, you can
770 pass the inbox file name as an argument. Interactively, a prefix
771 argument causes us to read a file name and use that file as the inbox.
773 This function runs `rmail-get-new-mail-hook' before saving the updated file."
775 (list (if current-prefix-arg
776 (read-file-name "Get new mail from file: "))))
777 (or (verify-visited-file-modtime (current-buffer))
779 (find-file (buffer-file-name))
780 (setq buffer-read-only t)
781 (if (verify-visited-file-modtime (current-buffer))
782 (rmail-forget-messages))))
783 (rmail-maybe-set-message-counters)
785 ;; Get rid of all undo records for this buffer.
786 (or (eq buffer-undo-list t)
787 (setq buffer-undo-list nil))
789 (let ((opoint (point))
792 ;; If buffer has not changed yet, and has not been saved yet,
793 ;; don't replace the old backup file now.
794 (make-backup-files (and make-backup-files (buffer-modified-p)))
795 (buffer-read-only nil)
796 ;; Don't make undo records for what we do in getting mail.
797 (buffer-undo-list t))
798 (goto-char (point-max))
799 (skip-chars-backward " \t\n") ; just in case of brain damage
800 (delete-region (point) (point-max)) ; caused by require-final-newline
803 (narrow-to-region (point) (point))
804 ;; Read in the contents of the inbox files,
805 ;; renaming them as necessary,
806 ;; and adding to the list of files to delete eventually.
808 (rmail-insert-inbox-text (list file-name) nil)
809 (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
810 ;; Scan the new text and convert each message to babyl format.
811 (goto-char (point-min))
813 (setq new-messages (rmail-convert-to-babyl-format)))
814 (or (zerop new-messages)
817 (search-backward "\n\^_" nil t)
818 (narrow-to-region (point) (point-max))
819 (goto-char (1+ (point-min)))
820 (rmail-count-new-messages)
821 (run-hooks 'rmail-get-new-mail-hook)
823 ;; Delete the old files, now that babyl file is saved.
826 ;; First, try deleting.
828 (delete-file (car delete-files))
830 ;; If we can't delete it, truncate it.
831 (write-region (point) (point) (car delete-files))))
833 (setq delete-files (cdr delete-files)))))
834 (if (= new-messages 0)
835 (progn (goto-char opoint)
836 (if (or file-name rmail-inbox-list)
837 (message "(No new mail has arrived)")))
838 (if (rmail-summary-exists)
839 (rmail-select-summary
840 (rmail-update-summary)))
841 (message "%d new message%s read"
842 new-messages (if (= 1 new-messages) "" "s"))
843 (and (boundp 'display-time-string)
844 (stringp display-time-string)
845 (string-match " Mail" display-time-string)
846 (setq display-time-string
848 (substring display-time-string 0 (match-beginning 0))
849 (substring display-time-string (match-end 0))))
850 (force-mode-line-update 'all))))
851 ;; Don't leave the buffer screwed up if we get a disk-full error.
852 (rmail-show-message)))
854 (defun rmail-insert-inbox-text (files renamep)
855 (let (file tofile delete-files movemail popmail)
857 (setq file (file-truename
858 (expand-file-name (substitute-in-file-name (car files))))
859 ;;>> un*x specific <<
860 ;; The "+" used to be "~", which is an extremely poor choice;
861 ;; it might accidentally be deleted when space is low
862 ;; (as happened to me!).
863 tofile (concat file "+"))
864 ;; If getting from mail spool directory,
865 ;; use movemail to move rather than just renaming,
866 ;; so as to interlock with the mailer.
867 (setq movemail (string= (file-name-directory file)
868 (file-truename rmail-spool-directory))
869 popmail (string-match "^po:" (file-name-nondirectory file)))
870 (if popmail (setq file (file-name-nondirectory file)
874 (setq tofile (expand-file-name
875 ;; Generate name to move to from inbox name,
876 ;; in case of multiple inboxes that need moving.
877 (concat ".newmail-" (file-name-nondirectory file))
878 ;; Use the directory of this rmail file
879 ;; because it's a nuisance to use the homedir
880 ;; if that is on a full disk and this rmail
883 (expand-file-name buffer-file-name))))
884 ;; On some systems, /usr/spool/mail/foo is a directory
885 ;; and the actual inbox is /usr/spool/mail/foo/foo.
886 (if (file-directory-p file)
887 (setq file (expand-file-name (user-login-name)
890 (message "Getting mail from post office ...")
891 (if (or (and (file-exists-p tofile)
892 (/= 0 (nth 7 (file-attributes tofile))))
893 (and (file-exists-p file)
894 (/= 0 (nth 7 (file-attributes file)))))
895 (message "Getting mail from %s..." file)))
896 ;; Set TOFILE if have not already done so, and
897 ;; rename or copy the file FILE to TOFILE if and as appropriate.
900 ((or (file-exists-p tofile) (and (not popmail)
901 (not (file-exists-p file))))
903 ((and (not movemail) (not popmail))
904 ;; Try copying. If that fails (perhaps no space),
907 (copy-file file tofile nil)
909 ;; Third arg is t so we can replace existing file TOFILE.
910 (rename-file file tofile t)))
911 ;; Make the real inbox file empty.
912 ;; Leaving it deleted could cause lossage
913 ;; because mailers often won't create the file.
915 (write-region (point) (point) file)
921 (setq errors (generate-new-buffer " *rmail loss*"))
922 (buffer-disable-undo errors)
924 (or rmail-movemail-program
925 (expand-file-name "movemail" exec-directory))
926 nil errors nil file tofile)
927 (if (not (buffer-modified-p errors))
928 ;; No output => movemail won
931 (subst-char-in-region (point-min) (point-max)
933 (goto-char (point-max))
934 (skip-chars-backward " \t")
935 (delete-region (point) (point-max))
936 (goto-char (point-min))
937 (if (looking-at "movemail: ")
938 (delete-region (point-min) (match-end 0)))
940 (message (concat "movemail: "
941 (buffer-substring (point-min)
945 (if errors (kill-buffer errors))))))
946 ;; At this point, TOFILE contains the name to read:
947 ;; Either the alternate name (if we renamed)
948 ;; or the actual inbox (if not renaming).
949 (if (file-exists-p tofile)
951 (goto-char (point-max))
952 (setq size (nth 1 (insert-file-contents tofile)))
953 (goto-char (point-max))
954 (or (= (preceding-char) ?\n)
957 (setq delete-files (cons tofile delete-files))))
959 (setq files (cdr files)))
962 ;; the rmail-break-forwarded-messages feature is not implemented
963 (defun rmail-convert-to-babyl-format ()
964 (let ((count 0) start
965 (case-fold-search nil)
966 (invalid-input-resync
968 (message "Invalid Babyl format in inbox!")
970 ;; Try to get back in sync with a real message.
971 (if (re-search-forward
972 (concat mmdf-delim1 "\\|^From") nil t)
974 (goto-char (point-max)))))))
975 (goto-char (point-min))
978 (cond ((looking-at "BABYL OPTIONS:");Babyl header
979 (if (search-forward "\n\^_" nil t)
980 ;; If we find the proper terminator, delete through there.
981 (delete-region (point-min) (point))
982 (funcall invalid-input-resync)
983 (delete-region (point-min) (point))))
984 ;; Babyl format message
986 (or (search-forward "\n\^_" nil t)
987 (funcall invalid-input-resync))
988 (setq count (1+ count))
989 ;; Make sure there is no extra white space after the ^_
990 ;; at the end of the message.
991 ;; Narrowing will make sure that whatever follows the junk
992 ;; will be treated properly.
993 (delete-region (point)
995 (skip-chars-forward " \t\n")
997 (narrow-to-region (point) (point-max)))
999 ((let ((case-fold-search t))
1000 (looking-at mmdf-delim1))
1001 (let ((case-fold-search t))
1002 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1003 (setq start (point))
1004 (re-search-forward mmdf-delim2 nil t)
1005 (replace-match "\^_"))
1008 (narrow-to-region start (1- (point)))
1009 (goto-char (point-min))
1010 (while (search-forward "\n\^_" nil t); single char "\^_"
1011 (replace-match "\n^_")))); 2 chars: "^" and "_"
1012 (narrow-to-region (point) (point-max))
1013 (setq count (1+ count)))
1015 ((looking-at "^From ")
1016 (setq start (point))
1017 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1018 (rmail-nuke-pinhead-header)
1019 ;; If this message has a Content-Length field,
1020 ;; skip to the end of the contents.
1021 (let* ((header-end (save-excursion
1022 (and (re-search-forward "\n\n" nil t)
1024 (case-fold-search t)
1026 ;; Get the numeric value from the Content-Length field.
1028 ;; Back up to end of prev line,
1029 ;; in case the Content-Length field comes first.
1031 (and (search-forward "\ncontent-length: "
1034 (eol (progn (end-of-line) (point))))
1035 (string-to-int (buffer-substring beg eol)))))))
1037 (if (and (natnump size)
1038 (<= (+ header-end size) (point-max))
1039 ;; Make sure this would put us at a position
1040 ;; that we could continue from.
1042 (goto-char (+ header-end size))
1043 (skip-chars-forward "\n")
1045 (and (looking-at "BABYL OPTIONS:")
1046 (search-forward "\n\^_" nil t))
1047 (and (looking-at "\^L")
1048 (search-forward "\n\^_" nil t))
1049 (let ((case-fold-search t))
1050 (looking-at mmdf-delim1))
1051 (looking-at "From "))))
1052 (goto-char (+ header-end size))
1053 (message "Ignoring invalid Content-Length field")
1056 (if (re-search-forward
1057 (concat "^[\^_]?\\("
1058 rmail-unix-mail-delimiter
1061 "^BABYL OPTIONS:\\|"
1062 "\^L\n[01],\\)") nil t)
1063 (goto-char (match-beginning 1))
1064 (goto-char (point-max)))
1065 (setq count (1+ count))
1068 (narrow-to-region start (point))
1069 (goto-char (point-min))
1070 (while (search-forward "\n\^_" nil t); single char
1071 (replace-match "\n^_")))); 2 chars: "^" and "_"
1073 (narrow-to-region (point) (point-max)))
1075 ;; This kludge is because some versions of sendmail.el
1076 ;; insert an extra newline at the beginning that shouldn't
1077 ;; be there. sendmail.el has been fixed, but old versions
1078 ;; may still be in use. -- rms, 7 May 1993.
1079 ((eolp) (delete-char 1))
1080 (t (error "Cannot convert to babyl format")))))
1083 ;; Delete the "From ..." line, creating various other headers with
1084 ;; information from it if they don't already exist. Now puts the
1085 ;; original line into a mail-from: header line for debugging and for
1086 ;; use by the rmail-output function.
1087 (defun rmail-nuke-pinhead-header ()
1090 (let ((start (point))
1093 (search-forward "\n\n")
1095 (goto-char (point-max))
1099 (narrow-to-region start end)
1100 (let ((case-fold-search t))
1102 (setq has-from (search-forward "\nFrom:" nil t))
1104 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
1106 (let ((case-fold-search nil))
1107 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
1111 ;; Keep and reformat the date if we don't
1112 ;; have a Date: field.
1116 "Date: \\3, \\5 \\4 \\9 \\6 "
1118 ;; The timezone could be matched by group 7 or group 10.
1119 ;; If neither of them matched, assume EST, since only
1120 ;; Easterners would be so sloppy.
1121 ;; It's a shame the substitution can't use "\\10".
1123 ((/= (match-beginning 7) (match-end 7)) "\\7")
1124 ((/= (match-beginning 10) (match-end 10))
1125 (buffer-substring (match-beginning 10)
1129 ;; Keep and reformat the sender if we don't
1130 ;; have a From: field.
1136 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1138 (defun rmail-reformat-message (beg end)
1141 (if (/= (following-char) ?0)
1142 (error "Bad format in RMAIL file."))
1143 (let ((buffer-read-only nil)
1144 (delta (- (buffer-size) end)))
1148 (let ((case-fold-search t))
1149 (while (looking-at "Summary-line:\\|Mail-From:")
1151 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1152 (delete-region (point)
1153 (progn (forward-line 1) (point))))
1154 (let ((str (buffer-substring (point)
1155 (save-excursion (search-forward "\n\n" end 'move)
1157 (insert str "*** EOOH ***\n")
1158 (narrow-to-region (point) (- (buffer-size) delta)))
1159 (goto-char (point-min))
1160 (if rmail-ignored-headers (rmail-clear-headers))
1161 (if rmail-message-filter (funcall rmail-message-filter))))
1163 (defun rmail-clear-headers ()
1164 (if (search-forward "\n\n" nil t)
1166 (narrow-to-region (point-min) (point))
1167 (let ((buffer-read-only nil))
1168 (while (let ((case-fold-search t))
1169 (goto-char (point-min))
1170 (re-search-forward rmail-ignored-headers nil t))
1172 (delete-region (point)
1173 (progn (re-search-forward "\n[^ \t]")
1177 (defun rmail-toggle-header ()
1178 "Show original message header if pruned header currently shown, or vice versa."
1180 (rmail-maybe-set-message-counters)
1181 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1182 (let ((buffer-read-only nil))
1183 (goto-char (point-min))
1185 (if (= (following-char) ?1)
1186 (progn (delete-char 1)
1189 (let ((case-fold-search t))
1190 (while (looking-at "Summary-Line:\\|Mail-From:")
1192 (insert "*** EOOH ***\n")
1194 (search-forward "\n*** EOOH ***\n")
1196 (let ((temp (point)))
1197 (and (search-forward "\n\n" nil t)
1198 (delete-region temp (point))))
1199 (goto-char (point-min))
1200 (search-forward "\n*** EOOH ***\n")
1201 (narrow-to-region (point) (point-max)))
1202 (rmail-reformat-message (point-min) (point-max))))
1203 (rmail-highlight-headers))
1205 ;;;; *** Rmail Attributes and Keywords ***
1207 ;; Make a string describing current message's attributes and keywords
1208 ;; and set it up as the name of a minor mode
1209 ;; so it will appear in the mode line.
1210 (defun rmail-display-labels ()
1211 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1216 (goto-char (rmail-msgbeg rmail-current-message))
1218 (if (looking-at "[01],")
1220 (narrow-to-region (point) (progn (end-of-line) (point)))
1221 ;; Truly valid BABYL format requires a space before each
1222 ;; attribute or keyword name. Put them in if missing.
1223 (let (buffer-read-only)
1224 (goto-char (point-min))
1225 (while (search-forward "," nil t)
1226 (or (looking-at "[ ,]") (eobp)
1228 (goto-char (point-max))
1229 (if (search-backward ",," nil 'move)
1231 (if (> (point) (1+ (point-min)))
1232 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
1233 (if (> (- (point-max) (point)) 2)
1237 (buffer-substring (+ (point) 3)
1238 (1- (point-max)))))))))))
1239 ;; Note: we don't use save-restriction because that does not work right
1240 ;; if changes are made outside the saved restriction
1241 ;; before that restriction is restored.
1242 (narrow-to-region beg end)
1243 (set-marker beg nil)
1244 (set-marker end nil)))
1245 (while (string-match " +," blurb)
1246 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1247 (substring blurb (match-end 0)))))
1248 (while (string-match ", +" blurb)
1249 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1250 (substring blurb (match-end 0)))))
1251 (setq mode-line-process
1252 (concat " " rmail-current-message "/" rmail-total-messages
1255 ;; Turn an attribute of a message on or off according to STATE.
1256 ;; ATTR is the name of the attribute, as a string.
1257 ;; MSGNUM is message number to change; nil means current message.
1258 (defun rmail-set-attribute (attr state &optional msgnum)
1259 (let ((omax (point-max-marker))
1260 (omin (point-min-marker))
1261 (buffer-read-only nil))
1262 (or msgnum (setq msgnum rmail-current-message))
1267 (goto-char (+ 3 (rmail-msgbeg msgnum)))
1270 (null (search-backward (concat ", " attr ",")
1271 (prog1 (point) (end-of-line)) t)))))
1272 (or (eq curstate (not (not state)))
1274 (delete-region (point) (1- (match-end 0)))
1277 (insert " " attr ","))))
1278 (if (string= attr "deleted")
1279 (rmail-set-message-deleted-p msgnum state)))
1280 ;; Note: we don't use save-restriction because that does not work right
1281 ;; if changes are made outside the saved restriction
1282 ;; before that restriction is restored.
1283 (narrow-to-region omin omax)
1284 (set-marker omin nil)
1285 (set-marker omax nil)
1286 (if (= msgnum rmail-current-message)
1287 (rmail-display-labels))))))
1289 ;; Return t if the attributes/keywords line of msg number MSG
1290 ;; contains a match for the regexp LABELS.
1291 (defun rmail-message-labels-p (msg labels)
1295 (goto-char (rmail-msgbeg msg))
1297 (re-search-backward labels (prog1 (point) (end-of-line)) t))))
1299 ;;;; *** Rmail Message Selection And Support ***
1301 (defun rmail-msgend (n)
1302 (marker-position (aref rmail-message-vector (1+ n))))
1304 (defun rmail-msgbeg (n)
1305 (marker-position (aref rmail-message-vector n)))
1307 (defun rmail-widen-to-current-msgbeg (function)
1308 "Call FUNCTION with point at start of internal data of current message.
1309 Assumes that bounds were previously narrowed to display the message in Rmail.
1310 The bounds are widened enough to move point where desired, then narrowed
1313 FUNCTION may not change the visible text of the message, but it may
1314 change the invisible header text."
1316 (let ((obeg (- (point-max) (point-min))))
1319 (narrow-to-region (rmail-msgbeg rmail-current-message)
1321 (goto-char (point-min))
1323 ;; Note: we don't use save-restriction because that does not work right
1324 ;; if changes are made outside the saved restriction
1325 ;; before that restriction is restored.
1326 ;; Here we assume that changes made by FUNCTION
1327 ;; occur before the visible region of the message.
1328 (narrow-to-region (- (point-max) obeg) (point-max))))))
1330 (defun rmail-forget-messages ()
1332 (if (vectorp rmail-message-vector)
1334 (v rmail-message-vector)
1337 (move-marker (aref v i) nil)
1339 (setq rmail-message-vector nil)
1340 (setq rmail-deleted-vector nil)))
1342 (defun rmail-maybe-set-message-counters ()
1343 (if (not (and rmail-deleted-vector
1344 rmail-message-vector
1345 rmail-current-message
1346 rmail-total-messages))
1347 (rmail-set-message-counters)))
1349 (defun rmail-count-new-messages (&optional nomsg)
1350 (let* ((case-fold-search nil)
1354 (or nomsg (message "Counting new messages..."))
1355 (goto-char (point-max))
1356 ;; Put at the end of messages-head
1357 ;; the entry for message N+1, which marks
1358 ;; the end of message N. (N = number of messages).
1359 (search-backward "\n\^_")
1361 (setq messages-head (list (point-marker)))
1362 (rmail-set-message-counters-counter (point-min))
1363 (setq rmail-current-message (1+ rmail-total-messages))
1364 (setq rmail-total-messages
1365 (+ rmail-total-messages total-messages))
1366 (setq rmail-message-vector
1367 (vconcat rmail-message-vector (cdr messages-head)))
1368 (aset rmail-message-vector
1369 rmail-current-message (car messages-head))
1370 (setq rmail-deleted-vector
1371 (concat rmail-deleted-vector deleted-head))
1372 (setq rmail-summary-vector
1373 (vconcat rmail-summary-vector (make-vector total-messages nil)))
1374 (goto-char (point-min))
1375 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
1377 (defun rmail-set-message-counters ()
1378 (rmail-forget-messages)
1382 (let* ((point-save (point))
1384 (messages-after-point)
1385 (case-fold-search nil)
1388 (message "Counting messages...")
1389 (goto-char (point-max))
1390 ;; Put at the end of messages-head
1391 ;; the entry for message N+1, which marks
1392 ;; the end of message N. (N = number of messages).
1393 (search-backward "\n\^_" nil t)
1394 (if (/= (point) (point-max)) (forward-char 1))
1395 (setq messages-head (list (point-marker)))
1396 (rmail-set-message-counters-counter (min (point) point-save))
1397 (setq messages-after-point total-messages)
1398 (rmail-set-message-counters-counter)
1399 (setq rmail-total-messages total-messages)
1400 (setq rmail-current-message
1402 (max 1 (- total-messages messages-after-point))))
1403 (setq rmail-message-vector
1404 (apply 'vector (cons (point-min-marker) messages-head))
1405 rmail-deleted-vector (concat "D" deleted-head)
1406 rmail-summary-vector (make-vector rmail-total-messages nil))
1407 (message "Counting messages...done")))))
1409 (defun rmail-set-message-counters-counter (&optional stop)
1410 (while (search-backward "\n\^_\^L\n" stop t)
1412 (setq messages-head (cons (point-marker) messages-head))
1415 (cons (if (search-backward ", deleted,"
1421 (if (zerop (% (setq total-messages (1+ total-messages)) 20))
1422 (message "Counting messages...%d" total-messages))))
1424 (defun rmail-beginning-of-message ()
1425 "Show current message starting from the beginning."
1427 (rmail-show-message rmail-current-message))
1429 (defun rmail-show-message (&optional n)
1430 "Show message number N (prefix argument), counting from start of file.
1431 If summary buffer is currently displayed, update current message there also."
1433 (rmail-maybe-set-message-counters)
1435 (if (zerop rmail-total-messages)
1436 (progn (narrow-to-region (point-min) (1- (point-max)))
1437 (goto-char (point-min))
1438 (setq mode-line-process nil))
1441 (setq n rmail-current-message)
1444 rmail-current-message 1
1445 blurb "No previous message"))
1446 ((> n rmail-total-messages)
1447 (setq n rmail-total-messages
1448 rmail-current-message rmail-total-messages
1449 blurb "No following message"))
1451 (setq rmail-current-message n))))
1452 (let ((beg (rmail-msgbeg n))
1453 (end (rmail-msgend n)))
1456 (if (= (following-char) ?0)
1458 (rmail-reformat-message beg end)
1459 (rmail-set-attribute "unseen" nil))
1460 (search-forward "\n*** EOOH ***\n" end t)
1461 (narrow-to-region (point) end))
1462 (goto-char (point-min))
1463 (rmail-display-labels)
1464 (rmail-highlight-headers)
1465 (if transient-mark-mode (deactivate-mark))
1466 (run-hooks 'rmail-show-message-hook)
1467 ;; If there is a summary buffer, try to move to this message
1468 ;; in that buffer. But don't complain if this message
1469 ;; is not mentioned in the summary.
1470 (if (rmail-summary-exists)
1471 (let ((curr-msg rmail-current-message))
1472 (rmail-select-summary
1473 (rmail-summary-goto-msg curr-msg t t))))
1475 (message blurb))))))
1477 ;; Find all occurrences of certain fields, and highlight them.
1478 (defun rmail-highlight-headers ()
1479 ;; Do this only if the system supports faces.
1480 (if (and (fboundp 'internal-find-face)
1481 rmail-highlighted-headers)
1483 (search-forward "\n\n" nil 'move)
1485 (narrow-to-region (point-min) (point))
1486 (let ((case-fold-search t)
1487 (inhibit-read-only t)
1488 ;; Highlight with boldface if that is available.
1489 ;; Otherwise use the `highlight' face.
1490 (face (or rmail-highlight-face
1491 (if (face-differs-from-default-p 'bold)
1493 ;; List of overlays to reuse.
1494 (overlays rmail-overlay-list))
1495 (goto-char (point-min))
1496 (while (re-search-forward rmail-highlighted-headers nil t)
1497 (skip-chars-forward " \t")
1500 (while (progn (forward-line 1)
1501 (looking-at "[ \t]")))
1502 ;; Back up over newline, then trailing spaces or tabs
1504 (while (member (preceding-char) '(? ?\t))
1507 ;; Reuse an overlay we already have.
1509 (setq overlay (car overlays)
1510 overlays (cdr overlays))
1511 (overlay-put overlay 'face face)
1512 (move-overlay overlay beg (point)))
1513 ;; Make a new overlay and add it to
1514 ;; rmail-overlay-list.
1515 (setq overlay (make-overlay beg (point)))
1516 (overlay-put overlay 'face face)
1517 (setq rmail-overlay-list
1518 (cons overlay rmail-overlay-list))))))))))
1520 (defun rmail-next-message (n)
1521 "Show following message whether deleted or not.
1522 With prefix arg N, moves forward N messages, or backward if N is negative."
1524 (rmail-maybe-set-message-counters)
1525 (rmail-show-message (+ rmail-current-message n)))
1527 (defun rmail-previous-message (n)
1528 "Show previous message whether deleted or not.
1529 With prefix arg N, moves backward N messages, or forward if N is negative."
1531 (rmail-next-message (- n)))
1533 (defun rmail-next-undeleted-message (n)
1534 "Show following non-deleted message.
1535 With prefix arg N, moves forward N non-deleted messages,
1536 or backward if N is negative.
1538 Returns t if a new message is being shown, nil otherwise."
1540 (rmail-maybe-set-message-counters)
1541 (let ((lastwin rmail-current-message)
1542 (current rmail-current-message))
1543 (while (and (> n 0) (< current rmail-total-messages))
1544 (setq current (1+ current))
1545 (if (not (rmail-message-deleted-p current))
1546 (setq lastwin current n (1- n))))
1547 (while (and (< n 0) (> current 1))
1548 (setq current (1- current))
1549 (if (not (rmail-message-deleted-p current))
1550 (setq lastwin current n (1+ n))))
1551 (if (/= lastwin rmail-current-message)
1552 (progn (rmail-show-message lastwin)
1555 (message "No previous nondeleted message"))
1557 (message "No following nondeleted message"))
1560 (defun rmail-previous-undeleted-message (n)
1561 "Show previous non-deleted message.
1562 With prefix argument N, moves backward N non-deleted messages,
1563 or forward if N is negative."
1565 (rmail-next-undeleted-message (- n)))
1567 (defun rmail-first-message ()
1568 "Show first message in file."
1570 (rmail-maybe-set-message-counters)
1571 (rmail-show-message 1))
1573 (defun rmail-last-message ()
1574 "Show last message in file."
1576 (rmail-maybe-set-message-counters)
1577 (rmail-show-message rmail-total-messages))
1579 (defun rmail-what-message ()
1580 (let ((where (point))
1582 (high rmail-total-messages)
1583 (mid (/ rmail-total-messages 2)))
1584 (while (> (- high low) 1)
1585 (if (>= where (rmail-msgbeg mid))
1588 (setq mid (+ low (/ (- high low) 2))))
1589 (if (>= where (rmail-msgbeg high)) high low)))
1591 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
1593 (goto-char (rmail-msgbeg msg))
1594 (search-forward "\n*** EOOH ***\n")
1595 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
1596 (or (string-match recipients (or (mail-fetch-field "To") ""))
1597 (string-match recipients (or (mail-fetch-field "From") ""))
1598 (if (not primary-only)
1599 (string-match recipients (or (mail-fetch-field "Cc") ""))))))
1601 (defun rmail-message-regexp-p (msg regexp)
1602 "Return t, if for message number MSG, regexp REGEXP matches in the header."
1603 (goto-char (rmail-msgbeg msg))
1606 (search-forward "*** EOOH ***" (point-max)) (point))))
1607 (re-search-forward regexp end t)))
1609 (defun rmail-search-backward (regexp &optional n)
1610 "Show message containing next match for REGEXP.
1611 Prefix argument gives repeat count; negative argument means search
1612 backwards (through earlier messages).
1613 Interactively, empty argument means use same regexp used last time."
1615 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1617 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1619 (if rmail-search-last-regexp
1620 (setq prompt (concat prompt
1622 rmail-search-last-regexp
1624 (setq regexp (read-string prompt))
1625 (cond ((not (equal regexp ""))
1626 (setq rmail-search-last-regexp regexp))
1627 ((not rmail-search-last-regexp)
1628 (error "No previous Rmail search string")))
1629 (list rmail-search-last-regexp
1630 (prefix-numeric-value current-prefix-arg))))
1631 (rmail-search regexp (- n)))
1633 (defvar rmail-search-last-regexp nil)
1634 (defun rmail-search (regexp &optional n)
1635 "Show message containing next match for REGEXP.
1636 Prefix argument gives repeat count; negative argument means search
1637 backwards (through earlier messages).
1638 Interactively, empty argument means use same regexp used last time."
1640 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1642 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1644 (if rmail-search-last-regexp
1645 (setq prompt (concat prompt
1647 rmail-search-last-regexp
1649 (setq regexp (read-string prompt))
1650 (cond ((not (equal regexp ""))
1651 (setq rmail-search-last-regexp regexp))
1652 ((not rmail-search-last-regexp)
1653 (error "No previous Rmail search string")))
1654 (list rmail-search-last-regexp
1655 (prefix-numeric-value current-prefix-arg))))
1657 (message "%sRmail search for %s..."
1658 (if (< n 0) "Reverse " "")
1660 (rmail-maybe-set-message-counters)
1661 (let ((omin (point-min))
1666 (msg rmail-current-message))
1671 ;; Check messages one by one, advancing message number up or down
1672 ;; but searching forward through each message.
1674 (while (and (null win) (> msg 1))
1675 (goto-char (rmail-msgbeg (setq msg (1- msg))))
1676 (setq win (re-search-forward
1677 regexp (rmail-msgend msg) t)))
1678 (while (and (null win) (< msg rmail-total-messages))
1679 (goto-char (rmail-msgbeg (setq msg (1+ msg))))
1680 (setq win (re-search-forward regexp (rmail-msgend msg) t))))
1681 (setq n (+ n (if reversep 1 -1)))))
1684 ;; If this is a reverse search and we found a message,
1685 ;; search backward thru this message to position point.
1688 (goto-char (rmail-msgend msg))
1690 regexp (rmail-msgbeg msg) t)))
1692 (rmail-show-message msg)
1693 (message "%sRmail search for %s...done"
1694 (if reversep "Reverse " "")
1698 (narrow-to-region omin omax)
1700 (message "Search failed: %s" regexp)))))
1702 (defun rmail-search-backwards (regexp &optional n)
1703 "Show message containing previous match for REGEXP.
1704 Prefix argument gives repeat count; negative argument means search
1705 forward (through later messages).
1706 Interactively, empty argument means use same regexp used last time."
1708 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1710 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1712 (if rmail-search-last-regexp
1713 (setq prompt (concat prompt
1715 rmail-search-last-regexp
1717 (setq regexp (read-string prompt))
1718 (cond ((not (equal regexp ""))
1719 (setq rmail-search-last-regexp regexp))
1720 ((not rmail-search-last-regexp)
1721 (error "No previous Rmail search string")))
1722 (list rmail-search-last-regexp
1723 (prefix-numeric-value current-prefix-arg))))
1724 (rmail-search regexp (- (or n -1))))
1726 ;; Show the first message which has the `unseen' attribute.
1727 (defun rmail-first-unseen-message ()
1728 (rmail-maybe-set-message-counters)
1733 (while (and (not found) (< current rmail-total-messages))
1734 (if (rmail-message-labels-p current ", ?\\(unseen\\),")
1735 (setq found current))
1736 (setq current (1+ current))))
1737 ;; Let the caller show the message.
1739 ;; (rmail-show-message found))
1742 ;;;; *** Rmail Message Deletion Commands ***
1744 (defun rmail-message-deleted-p (n)
1745 (= (aref rmail-deleted-vector n) ?D))
1747 (defun rmail-set-message-deleted-p (n state)
1748 (aset rmail-deleted-vector n (if state ?D ?\ )))
1750 (defun rmail-delete-message ()
1751 "Delete this message and stay on it."
1753 (rmail-set-attribute "deleted" t))
1755 (defun rmail-undelete-previous-message ()
1756 "Back up to deleted message, select it, and undelete it."
1758 (let ((msg rmail-current-message))
1759 (while (and (> msg 0)
1760 (not (rmail-message-deleted-p msg)))
1761 (setq msg (1- msg)))
1763 (error "No previous deleted message")
1764 (if (/= msg rmail-current-message)
1765 (rmail-show-message msg))
1766 (rmail-set-attribute "deleted" nil)
1767 (if (rmail-summary-exists)
1769 (set-buffer rmail-summary-buffer)
1770 (rmail-summary-mark-undeleted msg)))
1771 (rmail-maybe-display-summary))))
1773 (defun rmail-delete-forward (&optional backward)
1774 "Delete this message and move to next nondeleted one.
1775 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
1776 With prefix argument, delete and move backward.
1778 Returns t if a new message is displayed after the delete, or nil otherwise."
1780 (rmail-set-attribute "deleted" t)
1781 (let ((del-msg rmail-current-message))
1782 (if (rmail-summary-exists)
1784 (set-buffer rmail-summary-buffer)
1785 (rmail-summary-mark-deleted del-msg)))
1786 (prog1 (rmail-next-undeleted-message (if backward -1 1))
1787 (rmail-maybe-display-summary))))
1789 (defun rmail-delete-backward ()
1790 "Delete this message and move to previous nondeleted one.
1791 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
1793 (rmail-delete-forward t))
1795 (defun rmail-only-expunge ()
1796 "Actually erase all deleted messages in the file."
1798 (message "Expunging deleted messages...")
1799 ;; Discard all undo records for this buffer.
1800 (or (eq buffer-undo-list t)
1801 (setq buffer-undo-list nil))
1802 (rmail-maybe-set-message-counters)
1803 (let* ((omax (- (buffer-size) (point-max)))
1804 (omin (- (buffer-size) (point-min)))
1805 (opoint (if (and (> rmail-current-message 0)
1806 (rmail-message-deleted-p rmail-current-message))
1808 (- (point) (point-min))))
1809 (messages-head (cons (aref rmail-message-vector 0) nil))
1810 (messages-tail messages-head)
1811 ;; Don't make any undo records for the expunging.
1812 (buffer-undo-list t)
1817 (goto-char (point-min))
1820 (total rmail-total-messages)
1821 (new-message-number rmail-current-message)
1823 (buffer-read-only nil)
1824 (messages rmail-message-vector)
1825 (deleted rmail-deleted-vector)
1826 (summary rmail-summary-vector))
1827 (setq rmail-total-messages nil
1828 rmail-current-message nil
1829 rmail-message-vector nil
1830 rmail-deleted-vector nil
1831 rmail-summary-vector nil)
1832 (while (<= number total)
1833 (if (= (aref deleted number) ?D)
1836 (marker-position (aref messages number))
1837 (marker-position (aref messages (1+ number))))
1838 (move-marker (aref messages number) nil)
1839 (if (> new-message-number counter)
1840 (setq new-message-number (1- new-message-number))))
1841 (setq counter (1+ counter))
1843 (setcdr messages-tail
1844 (cons (aref messages number) nil)))
1846 (cons (if (= counter number) (aref summary (1- number)))
1848 (if (zerop (% (setq number (1+ number)) 20))
1849 (message "Expunging deleted messages...%d" number)))
1851 (setcdr messages-tail
1852 (cons (aref messages number) nil)))
1853 (setq rmail-current-message new-message-number
1854 rmail-total-messages counter
1855 rmail-message-vector (apply 'vector messages-head)
1856 rmail-deleted-vector (make-string (1+ counter) ?\ )
1857 rmail-summary-vector (vconcat (nreverse new-summary))
1859 (message "Expunging deleted messages...done")
1861 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
1863 (if (zerop rmail-current-message) 1 nil))
1864 (forward-char opoint))))
1866 (defun rmail-expunge ()
1867 "Erase deleted messages from Rmail file and summary buffer."
1869 (rmail-only-expunge)
1870 (if (rmail-summary-exists)
1871 (rmail-select-summary
1872 (rmail-update-summary))))
1874 ;;;; *** Rmail Mailing Commands ***
1876 (defun rmail-start-mail (&rest args)
1877 (if (and window-system rmail-mail-new-frame)
1879 (apply 'mail-other-frame args)
1880 (modify-frame-parameters (selected-frame)
1881 '((dedicated . t))))
1882 (apply 'mail-other-window args)))
1884 (defun rmail-mail ()
1885 "Send mail in another window.
1886 While composing the message, use \\[mail-yank-original] to yank the
1887 original message into it."
1889 (rmail-start-mail nil nil nil nil nil (current-buffer)))
1891 (defun rmail-continue ()
1892 "Continue composing outgoing message previously being composed."
1894 (rmail-start-mail t))
1896 (defun rmail-reply (just-sender)
1897 "Reply to the current message.
1898 Normally include CC: to all other recipients of original message;
1899 prefix argument means ignore them. While composing the reply,
1900 use \\[mail-yank-original] to yank the original message into it."
1902 (let (from reply-to cc subject date to message-id resent-reply-to)
1906 (goto-char (rmail-msgbeg rmail-current-message))
1908 (if (= (following-char) ?0)
1910 (progn (forward-line 2)
1912 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
1915 (narrow-to-region (point)
1916 (progn (search-forward "\n*** EOOH ***\n")
1917 (beginning-of-line) (point))))
1918 (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
1919 from (mail-fetch-field "from")
1920 reply-to (or resent-reply-to
1921 (mail-fetch-field "reply-to" nil t)
1923 cc (cond (just-sender nil)
1924 (resent-reply-to (mail-fetch-field "resent-cc" t))
1925 (t (mail-fetch-field "cc" nil t)))
1926 subject (or (and resent-reply-to
1927 (mail-fetch-field "resent-subject" t))
1928 (mail-fetch-field "subject"))
1929 date (or (and resent-reply-to
1930 (mail-fetch-field "resent-date" t))
1931 (mail-fetch-field "date"))
1932 to (cond (resent-reply-to
1933 (or (mail-fetch-field "resent-to" t)) "")
1934 ((mail-fetch-field "to" nil t))
1935 ;((mail-fetch-field "apparently-to")) ack gag barf
1937 message-id (cond (resent-reply-to
1938 (mail-fetch-field "resent-message-id" t))
1939 ((mail-fetch-field "message-id"))))))
1940 (and (stringp subject)
1941 (or (string-match (concat "\\`" (regexp-quote rmail-reply-prefix))
1943 (setq subject (concat rmail-reply-prefix subject))))
1944 (rmail-start-mail nil
1945 (mail-strip-quoted-names reply-to)
1947 (rmail-make-in-reply-to-field from date message-id)
1950 (let* ((cc-list (rmail-dont-reply-to
1951 (mail-strip-quoted-names
1952 (if (null cc) to (concat to ", " cc))))))
1953 (if (string= cc-list "") nil cc-list)))
1955 (list (list '(lambda (buf msgnum)
1958 (rmail-set-attribute "answered" t msgnum)))
1959 (current-buffer) rmail-current-message)))))
1961 (defun rmail-make-in-reply-to-field (from date message-id)
1968 (let ((tem (car (rfc822-addresses from))))
1971 (regexp-quote (if (string-match "@[^@]*\\'" tem)
1972 (substring tem 0 (match-beginning 0))
1975 ;; Message-ID is sufficiently informative
1977 (concat message-id " (" tem ")"))
1978 ;; Copy TEM, discarding text properties.
1979 (setq tem (copy-sequence tem))
1980 (set-text-properties 0 (length tem) nil tem)
1981 (setq tem (copy-sequence tem))
1982 ;; Use prin1 to fake RFC822 quoting
1983 (let ((field (prin1-to-string tem)))
1985 (concat field "'s message of " date)
1987 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
1988 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
1989 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
1990 (or (string-match (concat "\\`[ \t]*\\(" bar
1991 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
1992 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
1994 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
1995 bar "\\))[ \t]*\\'")
1996 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
1998 (let ((start (match-beginning 1))
1999 (end (match-end 1)))
2000 ;; Trim whitespace which above regexp match allows
2001 (while (and (< start end)
2002 (memq (aref from start) '(?\t ?\ )))
2003 (setq start (1+ start)))
2004 (while (and (< start end)
2005 (memq (aref from (1- end)) '(?\t ?\ )))
2006 (setq end (1- end)))
2007 (let ((field (substring from start end)))
2008 (if date (setq field (concat "message from " field " on " date)))
2010 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
2011 (concat message-id " (" field ")")
2014 ;; If we can't kludge it simply, do it correctly
2015 (let ((mail-use-rfc822 t))
2016 (rmail-make-in-reply-to-field from date message-id)))))
2018 (defun rmail-forward (resend)
2019 "Forward the current message to another user.
2020 With prefix argument, \"resend\" the message instead of forwarding it;
2021 see the documentation of `rmail-resend'."
2024 (call-interactively 'rmail-resend)
2025 (let ((forward-buffer (current-buffer))
2026 (subject (concat "["
2027 (let ((from (or (mail-fetch-field "From")
2028 (mail-fetch-field ">From"))))
2030 (concat (mail-strip-quoted-names from) ": ")
2032 (or (mail-fetch-field "Subject") "")
2034 ;; If only one window, use it for the mail buffer.
2035 ;; Otherwise, use another window for the mail buffer
2036 ;; so that the Rmail buffer remains visible
2037 ;; and sending the mail will get back to it.
2038 (if (funcall (if (and (not rmail-mail-new-frame) (one-window-p t))
2040 (function rmail-start-mail))
2041 nil nil subject nil nil nil
2042 (list (list (function (lambda (buf msgnum)
2045 (rmail-set-attribute
2046 "forwarded" t msgnum))))
2048 rmail-current-message)))
2050 ;; Insert after header separator--before signature if any.
2051 (goto-char (point-min))
2052 (search-forward-regexp
2053 (concat "^" (regexp-quote mail-header-separator) "$"))
2055 (insert "------- Start of forwarded message -------\n")
2056 (insert-buffer forward-buffer)
2058 (exchange-point-and-mark)
2059 (insert "------- End of forwarded message -------\n")
2061 (exchange-point-and-mark))))))
2063 (defun rmail-resend (address &optional from comment mail-alias-file)
2064 "Resend current message to ADDRESSES.
2065 ADDRESSES should be a single address, a string consisting of several
2066 addresses separated by commas, or a list of addresses.
2068 Optional FROM is the address to resend the message from, and
2069 defaults to the username of the person redistributing the message.
2070 Optional COMMENT is a string that will be inserted as a comment in the
2072 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
2073 typically for purposes of moderating a list."
2074 (interactive "sResend to: ")
2076 (require 'mailalias)
2077 (if (not from) (setq from (user-login-name)))
2078 (let ((tembuf (generate-new-buffer " sendmail temp"))
2079 (mail-header-separator "")
2080 (case-fold-search nil)
2081 (mailbuf (current-buffer)))
2084 ;;>> Copy message into temp buffer
2086 (insert-buffer-substring mailbuf)
2087 (goto-char (point-min))
2088 ;; Delete any Sender field, since that's not specifyable.
2089 ; Only delete Sender fields in the actual header.
2090 (re-search-forward "^$" nil 'move)
2091 ; Using "while" here rather than "if" because some buggy mail
2092 ; software may have inserted multiple Sender fields.
2093 (while (re-search-backward "^Sender:" nil t)
2097 (while (looking-at "[ \t]")
2099 (delete-region beg (point))))
2100 ; Go back to the beginning of the buffer so the Resent- fields
2101 ; are inserted there.
2102 (goto-char (point-min))
2103 ;;>> Insert resent-from:
2104 (insert "Resent-From: " from "\n")
2105 (insert "Resent-Date: " (mail-rfc822-date) "\n")
2106 ;;>> Insert resent-to: and bcc if need be.
2107 (let ((before (point)))
2109 (insert "Resent-Bcc: " (user-login-name) "\n"))
2110 (insert "Resent-To: " (if (stringp address)
2112 (mapconcat 'identity address ",\n\t"))
2115 (expand-mail-aliases before (point))))
2116 ;;>> Set up comment, if any.
2117 (if (and (sequencep comment) (not (zerop (length comment))))
2118 (let ((before (point))
2121 (or (eolp) (insert "\n"))
2122 (setq after (point))
2124 (while (< (point) after)
2125 (insert "Resent-Comment: ")
2127 ;; Don't expand aliases in the destination fields
2128 ;; of the original message.
2130 (funcall send-mail-function)))
2131 (kill-buffer tembuf))
2132 (rmail-set-attribute "resent" t rmail-current-message)))
2134 (defvar mail-unsent-separator
2135 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
2136 "^ *---+ +Returned message +---+ *$\\|"
2137 "^ *---+ +Original message +---+ *$\\|"
2138 "^ *--+ +begin message +--+ *$\\|"
2139 "^ *---+ +Original message follows +---+ *$\\|"
2140 "^|? *---+ +Message text follows: +---+ *|?$")
2141 "A regexp that matches the separator before the text of a failed message.")
2143 (defun rmail-retry-failure ()
2144 "Edit a mail message which is based on the contents of the current message.
2145 For a message rejected by the mail system, extract the interesting headers and
2146 the body of the original message.
2147 The variable `mail-unsent-separator' should match the string that
2148 delimits the returned original message."
2150 (require 'mail-utils)
2151 (let (to subj irp2 cc orig-message)
2153 ;; Narrow down to just the quoted original message
2154 (rmail-beginning-of-message)
2155 (let ((case-fold-search t))
2156 (or (re-search-forward mail-unsent-separator nil t)
2157 (error "Cannot parse this as a failure message")))
2159 (let ((old-end (point-max)))
2160 ;; One message contained a few random lines before the old
2161 ;; message header. The first line of the message started with
2162 ;; two hyphens. A blank line follows these random lines.
2163 (skip-chars-forward "\n")
2164 (if (looking-at "^--")
2166 (search-forward "\n\n")
2167 (skip-chars-forward "\n")))
2168 (narrow-to-region (point) (point-max))
2169 (goto-char (point-min))
2170 (search-forward "\n\n")
2171 (narrow-to-region (point-min) (point))
2172 ;; Now mail-fetch-field will get from headers of the original message,
2173 ;; not from the headers of the rejection.
2174 (setq to (mail-fetch-field "To")
2175 subj (mail-fetch-field "Subject")
2176 irp2 (mail-fetch-field "In-reply-to")
2177 cc (mail-fetch-field "Cc"))
2178 ;; Get the entire text (not headers) of the original message.
2179 (goto-char (point-max))
2182 (buffer-substring (point) old-end)))))
2183 ;; Start sending a new message; default header fields from the original.
2184 ;; Turn off the usual actions for initializing the message body
2185 ;; because we want to get only the text from the failure message.
2186 (let (mail-signature
2187 (mail-setup-hook rmail-retry-setup-hook))
2188 (if (rmail-start-mail nil to subj irp2 cc (current-buffer))
2189 ;; Insert original text as initial text of new draft message.
2191 (goto-char (point-max))
2192 (insert orig-message)
2193 (goto-char (point-min))
2196 (defun rmail-bury ()
2197 "Bury current Rmail buffer and its summary buffer."
2199 ;; This let var was called rmail-buffer, but that interfered
2200 ;; with the buffer-local var used in summary buffers.
2201 (let ((buffer-to-bury (current-buffer)))
2202 (if (rmail-summary-exists)
2204 (while (setq window (get-buffer-window rmail-summary-buffer))
2205 (set-window-buffer window (other-buffer rmail-summary-buffer)))
2206 (bury-buffer rmail-summary-buffer)))
2207 (switch-to-buffer (other-buffer (current-buffer)))
2208 (bury-buffer buffer-to-bury)))
2210 (defun rmail-summary-exists ()
2211 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
2212 In fact, the non-nil value returned is the summary buffer itself."
2213 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2214 rmail-summary-buffer))
2216 (defun rmail-summary-displayed ()
2217 "t iff in RMAIL buffer and an associated summary buffer is displayed."
2218 (and rmail-summary-buffer (get-buffer-window rmail-summary-buffer)))
2220 (defvar rmail-redisplay-summary nil
2221 "*Non-nil means Rmail should show the summary when it changes.
2222 This has an effect only if a summary buffer exists.")
2224 (defvar rmail-summary-window-size nil
2225 "*Non-nil means specify the height for an Rmail summary window.")
2227 ;; Put the summary buffer back on the screen, if user wants that.
2228 (defun rmail-maybe-display-summary ()
2229 (let ((selected (selected-window))
2231 ;; If requested, make sure the summary is displayed.
2232 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2233 rmail-redisplay-summary
2234 (if (get-buffer-window rmail-summary-buffer 0)
2235 ;; It's already in some frame; show that one.
2236 (let ((frame (window-frame
2237 (get-buffer-window rmail-summary-buffer 0))))
2238 (make-frame-visible frame)
2239 (raise-frame frame))
2240 (display-buffer rmail-summary-buffer)))
2241 ;; If requested, set the height of the summary window.
2242 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2243 rmail-summary-window-size
2244 (setq window (get-buffer-window rmail-summary-buffer))
2245 ;; Don't try to change the size if just one window in frame.
2246 (not (eq window (frame-root-window (window-frame window))))
2249 (select-window window)
2250 (enlarge-window (- rmail-summary-window-size
2252 (select-window selected)))))
2254 ;;;; *** Rmail Specify Inbox Files ***
2256 (autoload 'set-rmail-inbox-list "rmailmsc"
2257 "Set the inbox list of the current RMAIL file to FILE-NAME.
2258 This may be a list of file names separated by commas.
2259 If FILE-NAME is empty, remove any inbox list."
2262 ;;;; *** Rmail Commands for Labels ***
2264 (autoload 'rmail-add-label "rmailkwd"
2265 "Add LABEL to labels associated with current RMAIL message.
2266 Completion is performed over known labels when reading."
2269 (autoload 'rmail-kill-label "rmailkwd"
2270 "Remove LABEL from labels associated with current RMAIL message.
2271 Completion is performed over known labels when reading."
2274 (autoload 'rmail-next-labeled-message "rmailkwd"
2275 "Show next message with LABEL. Defaults to last label used.
2276 With prefix argument N moves forward N messages with this label."
2279 (autoload 'rmail-previous-labeled-message "rmailkwd"
2280 "Show previous message with LABEL. Defaults to last label used.
2281 With prefix argument N moves backward N messages with this label."
2284 (autoload 'rmail-read-label "rmailkwd"
2285 "PROMPT and read with completion an Rmail message label."
2288 ;;;; *** Rmail Edit Mode ***
2290 (autoload 'rmail-edit-current-message "rmailedit"
2291 "Edit the contents of the current message"
2294 ;;;; *** Rmail Sorting ***
2296 (autoload 'rmail-sort-by-date "rmailsort"
2297 "Sort messages of current Rmail file by date.
2298 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2300 (autoload 'rmail-sort-by-subject "rmailsort"
2301 "Sort messages of current Rmail file by subject.
2302 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2304 (autoload 'rmail-sort-by-author "rmailsort"
2305 "Sort messages of current Rmail file by author.
2306 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2308 (autoload 'rmail-sort-by-recipient "rmailsort"
2309 "Sort messages of current Rmail file by recipient.
2310 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2312 (autoload 'rmail-sort-by-correspondent "rmailsort"
2313 "Sort messages of current Rmail file by other correspondent.
2314 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2316 (autoload 'rmail-sort-by-lines "rmailsort"
2317 "Sort messages of current Rmail file by number of lines.
2318 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2320 (autoload 'rmail-sort-by-keywords "rmailsort"
2321 "Sort messages of current Rmail file by labels.
2322 If prefix argument REVERSE is non-nil, sort them in reverse order.
2323 KEYWORDS is a comma-separated list of labels." t)
2325 ;;;; *** Rmail Summary Mode ***
2327 (autoload 'rmail-summary "rmailsum"
2328 "Display a summary of all messages, one line per message."
2331 (autoload 'rmail-summary-by-labels "rmailsum"
2332 "Display a summary of all messages with one or more LABELS.
2333 LABELS should be a string containing the desired labels, separated by commas."
2336 (autoload 'rmail-summary-by-recipients "rmailsum"
2337 "Display a summary of all messages with the given RECIPIENTS.
2338 Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
2339 is non-nil (prefix arg given), only look in the To and From fields.
2340 RECIPIENTS is a string of regexps separated by commas."
2343 (autoload 'rmail-summary-by-regexp "rmailsum"
2344 "Display a summary of all messages according to regexp REGEXP.
2345 If the regular expression is found in the header of the message
2346 \(including in the date and other lines, as well as the subject line),
2347 Emacs will list the header line in the RMAIL-summary."
2350 (autoload 'rmail-summary-by-topic "rmailsum"
2351 "Display a summary of all messages with the given SUBJECT.
2352 Normally checks the Subject field of headers;
2353 but if WHOLE-MESSAGE is non-nil (prefix arg given),
2354 look in the whole message.
2355 SUBJECT is a string of regexps separated by commas."
2358 ;;;; *** Rmail output messages to files ***
2360 (autoload 'rmail-output-to-rmail-file "rmailout"
2361 "Append the current message to an Rmail file named FILE-NAME.
2362 If the file does not exist, ask if it should be created.
2363 If file is being visited, the message is appended to the Emacs
2364 buffer visiting that file."
2367 (autoload 'rmail-output "rmailout"
2368 "Append this message to Unix mail file named FILE-NAME."
2371 ;;;; *** Rmail undigestification ***
2373 (autoload 'undigestify-rmail-message "undigest"
2374 "Break up a digest message into its constituent messages.
2375 Leaves original message, deleted, before the undigestified messages."
2380 ;;; rmail.el ends here