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))))
285 ;; Given the value of MAILPATH, return a list of inbox file names.
286 ;; This is turned off because it is not clear that the user wants
287 ;; all these inboxes to feed into the primary rmail file.
288 ; (defun rmail-convert-mailpath (string)
290 ; (while (setq idx (string-match "[%:]" string))
291 ; (let ((this (substring string 0 idx)))
292 ; (setq string (substring string (1+ idx)))
293 ; (setq list (cons (if (string-match "%" this)
294 ; (substring this 0 (string-match "%" this))
299 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
300 ; will not cause emacs 18.55 problems.
302 (defun rmail-convert-file ()
305 (goto-char (point-min))
306 ;; If file doesn't start like a Babyl file,
307 ;; convert it to one, by adding a header and converting each message.
308 (cond ((looking-at "BABYL OPTIONS:"))
309 ((looking-at "Version: 5\n")
310 ;; Losing babyl file made by old version of Rmail.
311 ;; Just fix the babyl file header; don't make a new one,
312 ;; so we don't lose the Labels: file attribute, etc.
313 (let ((buffer-read-only nil))
314 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
315 ((equal (point-min) (point-max))
316 ;; Empty RMAIL file. Just insert the header.
317 (rmail-insert-rmail-file-header))
319 ;; Non-empty file in non-RMAIL format. Add header and convert.
321 (rmail-insert-rmail-file-header)))
322 ;; If file was not a Babyl file or if there are
323 ;; Unix format messages added at the end,
324 ;; convert file as necessary.
327 (goto-char (point-max))
328 (search-backward "\^_")
330 (looking-at "\n*From ")))
331 (let ((buffer-read-only nil))
332 (message "Converting to Babyl format...")
333 ;; If file needs conversion, convert it all,
334 ;; except for the BABYL header.
335 ;; (rmail-convert-to-babyl-format would delete the header.)
336 (goto-char (point-min))
337 (search-forward "\n\^_" nil t)
338 (narrow-to-region (point) (point-max))
339 (rmail-convert-to-babyl-format)
340 (message "Converting to Babyl format...done")))))
342 ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
343 ;;; will not cause emacs 18.55 problems.
345 (defun rmail-insert-rmail-file-header ()
346 (let ((buffer-read-only nil))
347 (insert "BABYL OPTIONS: -*- rmail -*-
350 Note: This is the header of an rmail file.
351 Note: If you are seeing it in rmail,
352 Note: it means the file has no messages in it.\n\^_")))
356 (setq rmail-mode-map (make-keymap))
357 (suppress-keymap rmail-mode-map)
358 (define-key rmail-mode-map "a" 'rmail-add-label)
359 (define-key rmail-mode-map "b" 'rmail-bury)
360 (define-key rmail-mode-map "c" 'rmail-continue)
361 (define-key rmail-mode-map "d" 'rmail-delete-forward)
362 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)
363 (define-key rmail-mode-map "e" 'rmail-edit-current-message)
364 (define-key rmail-mode-map "f" 'rmail-forward)
365 (define-key rmail-mode-map "g" 'rmail-get-new-mail)
366 (define-key rmail-mode-map "h" 'rmail-summary)
367 (define-key rmail-mode-map "i" 'rmail-input)
368 (define-key rmail-mode-map "j" 'rmail-show-message)
369 (define-key rmail-mode-map "k" 'rmail-kill-label)
370 (define-key rmail-mode-map "l" 'rmail-summary-by-labels)
371 (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
372 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
373 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
374 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
375 (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
376 (define-key rmail-mode-map "m" 'rmail-mail)
377 (define-key rmail-mode-map "\em" 'rmail-retry-failure)
378 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message)
379 (define-key rmail-mode-map "\en" 'rmail-next-message)
380 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
381 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file)
382 (define-key rmail-mode-map "\C-o" 'rmail-output)
383 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message)
384 (define-key rmail-mode-map "\ep" 'rmail-previous-message)
385 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
386 (define-key rmail-mode-map "q" 'rmail-quit)
387 (define-key rmail-mode-map "r" 'rmail-reply)
388 ;; I find I can't live without the default M-r command -- rms.
389 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
390 (define-key rmail-mode-map "s" 'rmail-expunge-and-save)
391 (define-key rmail-mode-map "\es" 'rmail-search)
392 (define-key rmail-mode-map "t" 'rmail-toggle-header)
393 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message)
394 (define-key rmail-mode-map "w" 'rmail-edit-current-message)
395 (define-key rmail-mode-map "x" 'rmail-expunge)
396 (define-key rmail-mode-map "." 'rmail-beginning-of-message)
397 (define-key rmail-mode-map "<" 'rmail-first-message)
398 (define-key rmail-mode-map ">" 'rmail-last-message)
399 (define-key rmail-mode-map " " 'scroll-up)
400 (define-key rmail-mode-map "\177" 'scroll-down)
401 (define-key rmail-mode-map "?" 'describe-mode)
402 (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
403 (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
404 (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
405 (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
406 (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
407 (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
408 (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-keywords)
411 (define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
413 (define-key rmail-mode-map [menu-bar classify]
414 (cons "Classify" (make-sparse-keymap "Classify")))
416 (define-key rmail-mode-map [menu-bar classify input-menu]
417 '("Input Rmail file (menu)..." . rmail-input-menu))
419 (define-key rmail-mode-map [menu-bar classify output-menu]
420 '("Output (Rmail menu)..." . rmail-output-menu))
422 (define-key rmail-mode-map [menu-bar classify output-inbox]
423 '("Output (inbox)..." . rmail-output))
425 (define-key rmail-mode-map [menu-bar classify output]
426 '("Output (Rmail)..." . rmail-output-to-rmail-file))
428 (define-key rmail-mode-map [menu-bar classify kill-label]
429 '("Kill Label..." . rmail-kill-label))
431 (define-key rmail-mode-map [menu-bar classify add-label]
432 '("Add Label..." . rmail-add-label))
434 (define-key rmail-mode-map [menu-bar summary]
435 (cons "Summary" (make-sparse-keymap "Summary")))
437 (define-key rmail-mode-map [menu-bar summary labels]
438 '("By Labels..." . rmail-summary-by-labels))
440 (define-key rmail-mode-map [menu-bar summary recipients]
441 '("By Recipients..." . rmail-summary-by-recipients))
443 (define-key rmail-mode-map [menu-bar summary topic]
444 '("By Topic..." . rmail-summary-by-topic))
446 (define-key rmail-mode-map [menu-bar summary regexp]
447 '("By Regexp..." . rmail-summary-by-regexp))
449 (define-key rmail-mode-map [menu-bar summary all]
450 '("All" . rmail-summary))
452 (define-key rmail-mode-map [menu-bar mail]
453 (cons "Mail" (make-sparse-keymap "Mail")))
455 (define-key rmail-mode-map [menu-bar mail rmail-get-new-mail]
456 '("Get New Mail" . rmail-get-new-mail))
458 (define-key rmail-mode-map [menu-bar mail lambda]
461 (define-key rmail-mode-map [menu-bar mail continue]
462 '("Continue" . rmail-continue))
464 (define-key rmail-mode-map [menu-bar mail resend]
465 '("Re-send..." . rmail-resend))
467 (define-key rmail-mode-map [menu-bar mail forward]
468 '("Forward" . rmail-forward))
470 (define-key rmail-mode-map [menu-bar mail retry]
471 '("Retry" . rmail-retry-failure))
473 (define-key rmail-mode-map [menu-bar mail reply]
474 '("Reply" . rmail-reply))
476 (define-key rmail-mode-map [menu-bar mail mail]
477 '("Mail" . rmail-mail))
479 (define-key rmail-mode-map [menu-bar delete]
480 (cons "Delete" (make-sparse-keymap "Delete")))
482 (define-key rmail-mode-map [menu-bar delete expunge/save]
483 '("Expunge/Save" . rmail-expunge-and-save))
485 (define-key rmail-mode-map [menu-bar delete expunge]
486 '("Expunge" . rmail-expunge))
488 (define-key rmail-mode-map [menu-bar delete undelete]
489 '("Undelete" . rmail-undelete-previous-message))
491 (define-key rmail-mode-map [menu-bar delete delete]
492 '("Delete" . rmail-delete-forward))
494 (define-key rmail-mode-map [menu-bar move]
495 (cons "Move" (make-sparse-keymap "Move")))
497 (define-key rmail-mode-map [menu-bar move search-back]
498 '("Search Back..." . rmail-search-backward))
500 (define-key rmail-mode-map [menu-bar move search]
501 '("Search..." . rmail-search))
503 (define-key rmail-mode-map [menu-bar move previous]
504 '("Previous Nondeleted" . rmail-previous-undeleted-message))
506 (define-key rmail-mode-map [menu-bar move next]
507 '("Next Nondeleted" . rmail-next-undeleted-message))
509 (define-key rmail-mode-map [menu-bar move last]
510 '("Last" . rmail-last-message))
512 (define-key rmail-mode-map [menu-bar move first]
513 '("First" . rmail-first-message))
515 (define-key rmail-mode-map [menu-bar move previous]
516 '("Previous" . rmail-previous-message))
518 (define-key rmail-mode-map [menu-bar move next]
519 '("Next" . rmail-next-message))
521 ;; Rmail mode is suitable only for specially formatted data.
522 (put 'rmail-mode 'mode-class 'special)
526 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
527 All normal editing commands are turned off.
528 Instead, these commands are available:
530 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
531 \\[scroll-up] Scroll to next screen of this message.
532 \\[scroll-down] Scroll to previous screen of this message.
533 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
534 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
535 \\[rmail-next-message] Move to Next message whether deleted or not.
536 \\[rmail-previous-message] Move to Previous message whether deleted or not.
537 \\[rmail-first-message] Move to the first message in Rmail file.
538 \\[rmail-last-message] Move to the last message in Rmail file.
539 \\[rmail-show-message] Jump to message specified by numeric position in file.
540 \\[rmail-search] Search for string and show message it is found in.
541 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
542 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
543 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
544 till a deleted message is found.
545 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
546 \\[rmail-expunge] Expunge deleted messages.
547 \\[rmail-expunge-and-save] Expunge and save the file.
548 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
549 \\[save-buffer] Save without expunging.
550 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
551 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
552 \\[rmail-continue] Continue composing outgoing message started before.
553 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
554 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
555 \\[rmail-forward] Forward this message to another user.
556 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
557 \\[rmail-output] Output this message to a Unix-format mail file (append it).
558 \\[rmail-input] Input Rmail file. Run Rmail on that file.
559 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
560 \\[rmail-kill-label] Kill label. Remove a label from current message.
561 \\[rmail-next-labeled-message] Move to Next message with specified label
562 (label defaults to last one specified).
563 Standard labels: filed, unseen, answered, forwarded, deleted.
564 Any other label is present only if you add it with \\[rmail-add-label].
565 \\[rmail-previous-labeled-message] Move to Previous message with specified label
566 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
567 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
568 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
569 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
570 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
571 \\[rmail-toggle-header] Toggle display of complete header."
574 (rmail-set-message-counters)
575 (rmail-show-message rmail-total-messages))
577 (defun rmail-mode-2 ()
578 (kill-all-local-variables)
581 (run-hooks 'rmail-mode-hook))
583 (defun rmail-mode-1 ()
584 (setq major-mode 'rmail-mode)
585 (setq mode-name "RMAIL")
586 (setq buffer-read-only t)
587 ;; No need to auto save RMAIL files in normal circumstances
588 ;; because they contain no info except attribute changes
589 ;; and deletion of messages.
590 ;; The one exception is when messages are copied into an Rmail mode buffer.
591 ;; rmail-output-to-rmail-file enables auto save when you do that.
592 (setq buffer-auto-save-file-name nil)
593 (if (boundp 'mode-line-modified)
594 (setq mode-line-modified "--- ")
595 (setq mode-line-format
596 (cons "--- " (cdr (default-value 'mode-line-format)))))
597 (use-local-map rmail-mode-map)
598 (set-syntax-table text-mode-syntax-table)
599 (setq local-abbrev-table text-mode-abbrev-table))
601 (defun rmail-variables ()
602 (make-local-variable 'revert-buffer-function)
603 (setq revert-buffer-function 'rmail-revert)
604 (make-local-variable 'rmail-last-label)
605 (make-local-variable 'rmail-last-regexp)
606 (make-local-variable 'rmail-deleted-vector)
607 (make-local-variable 'rmail-summary-buffer)
608 (make-local-variable 'rmail-summary-vector)
609 (make-local-variable 'rmail-current-message)
610 (make-local-variable 'rmail-total-messages)
611 (make-local-variable 'require-final-newline)
612 (setq require-final-newline nil)
613 (make-local-variable 'rmail-overlay-list)
614 (setq rmail-overlay-list nil)
615 (make-local-variable 'version-control)
616 (setq version-control 'never)
617 (make-local-variable 'file-precious-flag)
618 (setq file-precious-flag t)
619 (make-local-variable 'rmail-message-vector)
620 (make-local-variable 'rmail-inbox-list)
621 (setq rmail-inbox-list (rmail-parse-file-inboxes))
622 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
623 (and (null rmail-inbox-list)
624 (or (equal buffer-file-name (expand-file-name rmail-file-name))
625 (equal buffer-file-truename
626 (abbreviate-file-name (file-truename rmail-file-name))))
627 (setq rmail-inbox-list
628 (or rmail-primary-inbox-list
629 (list (or (getenv "MAIL")
630 (concat rmail-spool-directory
631 (user-login-name)))))))
632 (make-local-variable 'rmail-keywords)
633 ;; this gets generated as needed
634 (setq rmail-keywords nil))
636 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
637 (defun rmail-revert (arg noconfirm)
638 (let (revert-buffer-function)
639 ;; Call our caller again, but this time it does the default thing.
640 (if (revert-buffer arg noconfirm)
641 ;; If the user said "yes", and we changed something,
642 ;; reparse the messages.
645 (goto-char (point-max))
646 (rmail-set-message-counters)
647 (rmail-show-message)))))
649 ;; Return a list of files from this buffer's Mail: option.
650 ;; Does not assume that messages have been parsed.
651 ;; Just returns nil if buffer does not look like Babyl format.
652 (defun rmail-parse-file-inboxes ()
657 (cond ((looking-at "BABYL OPTIONS:")
658 (search-forward "\n\^_" nil 'move)
659 (narrow-to-region 1 (point))
661 (if (search-forward "\nMail:" nil t)
663 (narrow-to-region (point) (progn (end-of-line) (point)))
664 (goto-char (point-min))
665 (mail-parse-comma-list))))))))
667 (defun rmail-expunge-and-save ()
668 "Expunge and save RMAIL file."
672 (if (rmail-summary-exists)
673 (rmail-select-summary (set-buffer-modified-p nil))))
678 (rmail-expunge-and-save)
679 ;; Don't switch to the summary buffer even if it was recently visible.
680 (if rmail-summary-buffer
682 (replace-buffer-in-windows rmail-summary-buffer)
683 (bury-buffer rmail-summary-buffer)))
684 (let ((obuf (current-buffer)))
685 (replace-buffer-in-windows obuf)
689 (defun rmail-input (filename)
690 "Run Rmail on file FILENAME."
691 (interactive "FRun rmail on RMAIL file: ")
694 ;; Choose a .xmail file in dir rmail-secondary-file-directory.
695 (defun rmail-secondary-file-menu (event)
696 (let ((files (directory-files rmail-secondary-file-directory nil
697 rmail-secondary-file-regexp)))
699 (let* ((menu (list "Rmail Files"
701 (mapcar (function (lambda (f) (cons f f)))
703 (chosen (x-popup-menu event menu)))
705 (expand-file-name chosen rmail-secondary-file-directory)))
706 (message "No files matching %s%s found"
707 rmail-secondary-file-directory rmail-secondary-file-regexp)
711 (defun rmail-input-menu (event)
712 "Choose a new Rmail file to edit, with a menu.
713 The variables `rmail-secondary-file-directory' and
714 `rmail-secondary-file-regexp' control which files are offered in the menu."
716 (let ((file-name (rmail-secondary-file-menu event)))
718 (rmail-input file-name))))
720 ;;;; *** Rmail input ***
722 ;; RLK feature not added in this version:
723 ;; argument specifies inbox file or files in various ways.
725 (defun rmail-get-new-mail (&optional file-name)
726 "Move any new mail from this RMAIL file's inbox files.
727 The inbox files can be specified with the file's Mail: option. The
728 variable `rmail-primary-inbox-list' specifies the inboxes for your
729 primary RMAIL file if it has no Mail: option. By default, this is
730 your /usr/spool/mail/$USER.
732 You can also specify the file to get new mail from. In this case, the
733 file of new mail is not changed or deleted. Noninteractively, you can
734 pass the inbox file name as an argument. Interactively, a prefix
735 argument causes us to read a file name and use that file as the inbox.
737 This function runs `rmail-get-new-mail-hook' before saving the updated file."
739 (list (if current-prefix-arg
740 (read-file-name "Get new mail from file: "))))
741 (or (verify-visited-file-modtime (current-buffer))
743 (find-file (buffer-file-name))
744 (setq buffer-read-only t)
745 (if (verify-visited-file-modtime (current-buffer))
746 (rmail-forget-messages))))
747 (rmail-maybe-set-message-counters)
749 ;; Get rid of all undo records for this buffer.
750 (or (eq buffer-undo-list t)
751 (setq buffer-undo-list nil))
753 (let ((opoint (point))
756 ;; If buffer has not changed yet, and has not been saved yet,
757 ;; don't replace the old backup file now.
758 (make-backup-files (and make-backup-files (buffer-modified-p)))
759 (buffer-read-only nil)
760 ;; Don't make undo records for what we do in getting mail.
761 (buffer-undo-list t))
762 (goto-char (point-max))
763 (skip-chars-backward " \t\n") ; just in case of brain damage
764 (delete-region (point) (point-max)) ; caused by require-final-newline
767 (narrow-to-region (point) (point))
768 ;; Read in the contents of the inbox files,
769 ;; renaming them as necessary,
770 ;; and adding to the list of files to delete eventually.
772 (rmail-insert-inbox-text (list file-name) nil)
773 (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
774 ;; Scan the new text and convert each message to babyl format.
775 (goto-char (point-min))
777 (setq new-messages (rmail-convert-to-babyl-format)))
778 (or (zerop new-messages)
781 (search-backward "\n\^_" nil t)
782 (narrow-to-region (point) (point-max))
783 (goto-char (1+ (point-min)))
784 (rmail-count-new-messages)
785 (run-hooks 'rmail-get-new-mail-hook)
787 ;; Delete the old files, now that babyl file is saved.
790 ;; First, try deleting.
792 (delete-file (car delete-files))
794 ;; If we can't delete it, truncate it.
795 (write-region (point) (point) (car delete-files))))
797 (setq delete-files (cdr delete-files)))))
798 (if (= new-messages 0)
799 (progn (goto-char opoint)
800 (if (or file-name rmail-inbox-list)
801 (message "(No new mail has arrived)")))
802 (if (rmail-summary-exists)
803 (rmail-select-summary
804 (rmail-update-summary)))
805 (message "%d new message%s read"
806 new-messages (if (= 1 new-messages) "" "s"))
807 (and (boundp 'display-time-string)
808 (stringp display-time-string)
809 (string-match " Mail" display-time-string)
810 (setq display-time-string
812 (substring display-time-string 0 (match-beginning 0))
813 (substring display-time-string (match-end 0))))
814 (force-mode-line-update 'all))))
815 ;; Don't leave the buffer screwed up if we get a disk-full error.
816 (rmail-show-message)))
818 (defun rmail-insert-inbox-text (files renamep)
819 (let (file tofile delete-files movemail popmail)
821 (setq file (file-truename
822 (expand-file-name (substitute-in-file-name (car files))))
823 ;;>> un*x specific <<
824 ;; The "+" used to be "~", which is an extremely poor choice;
825 ;; it might accidentally be deleted when space is low
826 ;; (as happened to me!).
827 tofile (concat file "+"))
828 ;; If getting from mail spool directory,
829 ;; use movemail to move rather than just renaming,
830 ;; so as to interlock with the mailer.
831 (setq movemail (string= (file-name-directory file)
832 (file-truename rmail-spool-directory))
833 popmail (string-match "^po:" (file-name-nondirectory file)))
834 (if popmail (setq file (file-name-nondirectory file)
838 (setq tofile (expand-file-name
839 ;; Generate name to move to from inbox name,
840 ;; in case of multiple inboxes that need moving.
841 (concat ".newmail-" (file-name-nondirectory file))
842 ;; Use the directory of this rmail file
843 ;; because it's a nuisance to use the homedir
844 ;; if that is on a full disk and this rmail
847 (expand-file-name buffer-file-name))))
848 ;; On some systems, /usr/spool/mail/foo is a directory
849 ;; and the actual inbox is /usr/spool/mail/foo/foo.
850 (if (file-directory-p file)
851 (setq file (expand-file-name (user-login-name)
854 (message "Getting mail from post office ...")
855 (if (or (and (file-exists-p tofile)
856 (/= 0 (nth 7 (file-attributes tofile))))
857 (and (file-exists-p file)
858 (/= 0 (nth 7 (file-attributes file)))))
859 (message "Getting mail from %s..." file)))
860 ;; Set TOFILE if have not already done so, and
861 ;; rename or copy the file FILE to TOFILE if and as appropriate.
864 ((or (file-exists-p tofile) (and (not popmail)
865 (not (file-exists-p file))))
867 ((and (not movemail) (not popmail))
868 ;; Try copying. If that fails (perhaps no space),
871 (copy-file file tofile nil)
873 ;; Third arg is t so we can replace existing file TOFILE.
874 (rename-file file tofile t)))
875 ;; Make the real inbox file empty.
876 ;; Leaving it deleted could cause lossage
877 ;; because mailers often won't create the file.
879 (write-region (point) (point) file)
885 (setq errors (generate-new-buffer " *rmail loss*"))
886 (buffer-disable-undo errors)
888 (or rmail-movemail-program
889 (expand-file-name "movemail" exec-directory))
890 nil errors nil file tofile)
891 (if (not (buffer-modified-p errors))
892 ;; No output => movemail won
895 (subst-char-in-region (point-min) (point-max)
897 (goto-char (point-max))
898 (skip-chars-backward " \t")
899 (delete-region (point) (point-max))
900 (goto-char (point-min))
901 (if (looking-at "movemail: ")
902 (delete-region (point-min) (match-end 0)))
904 (message (concat "movemail: "
905 (buffer-substring (point-min)
909 (if errors (kill-buffer errors))))))
910 ;; At this point, TOFILE contains the name to read:
911 ;; Either the alternate name (if we renamed)
912 ;; or the actual inbox (if not renaming).
913 (if (file-exists-p tofile)
915 (goto-char (point-max))
916 (setq size (nth 1 (insert-file-contents tofile)))
917 (goto-char (point-max))
918 (or (= (preceding-char) ?\n)
921 (setq delete-files (cons tofile delete-files))))
923 (setq files (cdr files)))
926 ;; the rmail-break-forwarded-messages feature is not implemented
927 (defun rmail-convert-to-babyl-format ()
928 (let ((count 0) start
929 (case-fold-search nil)
930 (invalid-input-resync
932 (message "Invalid Babyl format in inbox!")
934 ;; Try to get back in sync with a real message.
935 (if (re-search-forward
936 (concat mmdf-delim1 "\\|^From") nil t)
938 (goto-char (point-max)))))))
939 (goto-char (point-min))
942 (cond ((looking-at "BABYL OPTIONS:");Babyl header
943 (if (search-forward "\n\^_" nil t)
944 ;; If we find the proper terminator, delete through there.
945 (delete-region (point-min) (point))
946 (funcall invalid-input-resync)
947 (delete-region (point-min) (point))))
948 ;; Babyl format message
950 (or (search-forward "\n\^_" nil t)
951 (funcall invalid-input-resync))
952 (setq count (1+ count))
953 ;; Make sure there is no extra white space after the ^_
954 ;; at the end of the message.
955 ;; Narrowing will make sure that whatever follows the junk
956 ;; will be treated properly.
957 (delete-region (point)
959 (skip-chars-forward " \t\n")
961 (narrow-to-region (point) (point-max)))
963 ((let ((case-fold-search t))
964 (looking-at mmdf-delim1))
965 (let ((case-fold-search t))
966 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
968 (re-search-forward mmdf-delim2 nil t)
969 (replace-match "\^_"))
972 (narrow-to-region start (1- (point)))
973 (goto-char (point-min))
974 (while (search-forward "\n\^_" nil t); single char "\^_"
975 (replace-match "\n^_")))); 2 chars: "^" and "_"
976 (narrow-to-region (point) (point-max))
977 (setq count (1+ count)))
979 ((looking-at "^From ")
981 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
982 (rmail-nuke-pinhead-header)
983 ;; If this message has a Content-Length field,
984 ;; skip to the end of the contents.
985 (let* ((header-end (save-excursion
986 (and (re-search-forward "\n\n" nil t)
990 ;; Get the numeric value from the Content-Length field.
992 ;; Back up to end of prev line,
993 ;; in case the Content-Length field comes first.
995 (and (search-forward "\ncontent-length: "
998 (eol (progn (end-of-line) (point))))
999 (string-to-int (buffer-substring beg eol)))))))
1001 (if (and (natnump size)
1002 (<= (+ header-end size) (point-max))
1003 ;; Make sure this would put us at a position
1004 ;; that we could continue from.
1006 (goto-char (+ header-end size))
1007 (skip-chars-forward "\n")
1009 (and (looking-at "BABYL OPTIONS:")
1010 (search-forward "\n\^_" nil t))
1011 (and (looking-at "\^L")
1012 (search-forward "\n\^_" nil t))
1013 (let ((case-fold-search t))
1014 (looking-at mmdf-delim1))
1015 (looking-at "From "))))
1016 (goto-char (+ header-end size))
1017 (message "Ignoring invalid Content-Length field")
1020 (if (re-search-forward
1021 (concat "^[\^_]?\\("
1022 rmail-unix-mail-delimiter
1025 "^BABYL OPTIONS:\\|"
1026 "\^L\n[01],\\)") nil t)
1027 (goto-char (match-beginning 1))
1028 (goto-char (point-max)))
1029 (setq count (1+ count))
1032 (narrow-to-region start (point))
1033 (goto-char (point-min))
1034 (while (search-forward "\n\^_" nil t); single char
1035 (replace-match "\n^_")))); 2 chars: "^" and "_"
1037 (narrow-to-region (point) (point-max)))
1039 ;; This kludge is because some versions of sendmail.el
1040 ;; insert an extra newline at the beginning that shouldn't
1041 ;; be there. sendmail.el has been fixed, but old versions
1042 ;; may still be in use. -- rms, 7 May 1993.
1043 ((eolp) (delete-char 1))
1044 (t (error "Cannot convert to babyl format")))))
1047 ;; Delete the "From ..." line, creating various other headers with
1048 ;; information from it if they don't already exist. Now puts the
1049 ;; original line into a mail-from: header line for debugging and for
1050 ;; use by the rmail-output function.
1051 (defun rmail-nuke-pinhead-header ()
1054 (let ((start (point))
1057 (search-forward "\n\n")
1059 (goto-char (point-max))
1063 (narrow-to-region start end)
1064 (let ((case-fold-search t))
1066 (setq has-from (search-forward "\nFrom:" nil t))
1068 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
1070 (let ((case-fold-search nil))
1071 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
1075 ;; Keep and reformat the date if we don't
1076 ;; have a Date: field.
1080 "Date: \\3, \\5 \\4 \\9 \\6 "
1082 ;; The timezone could be matched by group 7 or group 10.
1083 ;; If neither of them matched, assume EST, since only
1084 ;; Easterners would be so sloppy.
1085 ;; It's a shame the substitution can't use "\\10".
1087 ((/= (match-beginning 7) (match-end 7)) "\\7")
1088 ((/= (match-beginning 10) (match-end 10))
1089 (buffer-substring (match-beginning 10)
1093 ;; Keep and reformat the sender if we don't
1094 ;; have a From: field.
1100 ;;;; *** Rmail Message Formatting and Header Manipulation ***
1102 (defun rmail-reformat-message (beg end)
1105 (if (/= (following-char) ?0)
1106 (error "Bad format in RMAIL file."))
1107 (let ((buffer-read-only nil)
1108 (delta (- (buffer-size) end)))
1112 (let ((case-fold-search t))
1113 (while (looking-at "Summary-line:\\|Mail-From:")
1115 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
1116 (delete-region (point)
1117 (progn (forward-line 1) (point))))
1118 (let ((str (buffer-substring (point)
1119 (save-excursion (search-forward "\n\n" end 'move)
1121 (insert str "*** EOOH ***\n")
1122 (narrow-to-region (point) (- (buffer-size) delta)))
1123 (goto-char (point-min))
1124 (if rmail-ignored-headers (rmail-clear-headers))
1125 (if rmail-message-filter (funcall rmail-message-filter))))
1127 (defun rmail-clear-headers ()
1128 (if (search-forward "\n\n" nil t)
1130 (narrow-to-region (point-min) (point))
1131 (let ((buffer-read-only nil))
1132 (while (let ((case-fold-search t))
1133 (goto-char (point-min))
1134 (re-search-forward rmail-ignored-headers nil t))
1136 (delete-region (point)
1137 (progn (re-search-forward "\n[^ \t]")
1141 (defun rmail-toggle-header ()
1142 "Show original message header if pruned header currently shown, or vice versa."
1144 (rmail-maybe-set-message-counters)
1145 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1146 (let ((buffer-read-only nil))
1147 (goto-char (point-min))
1149 (if (= (following-char) ?1)
1150 (progn (delete-char 1)
1153 (let ((case-fold-search t))
1154 (while (looking-at "Summary-Line:\\|Mail-From:")
1156 (insert "*** EOOH ***\n")
1158 (search-forward "\n*** EOOH ***\n")
1160 (let ((temp (point)))
1161 (and (search-forward "\n\n" nil t)
1162 (delete-region temp (point))))
1163 (goto-char (point-min))
1164 (search-forward "\n*** EOOH ***\n")
1165 (narrow-to-region (point) (point-max)))
1166 (rmail-reformat-message (point-min) (point-max))))
1167 (rmail-highlight-headers))
1169 ;;;; *** Rmail Attributes and Keywords ***
1171 ;; Make a string describing current message's attributes and keywords
1172 ;; and set it up as the name of a minor mode
1173 ;; so it will appear in the mode line.
1174 (defun rmail-display-labels ()
1175 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
1180 (goto-char (rmail-msgbeg rmail-current-message))
1182 (if (looking-at "[01],")
1184 (narrow-to-region (point) (progn (end-of-line) (point)))
1185 ;; Truly valid BABYL format requires a space before each
1186 ;; attribute or keyword name. Put them in if missing.
1187 (let (buffer-read-only)
1188 (goto-char (point-min))
1189 (while (search-forward "," nil t)
1190 (or (looking-at "[ ,]") (eobp)
1192 (goto-char (point-max))
1193 (if (search-backward ",," nil 'move)
1195 (if (> (point) (1+ (point-min)))
1196 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
1197 (if (> (- (point-max) (point)) 2)
1201 (buffer-substring (+ (point) 3)
1202 (1- (point-max)))))))))))
1203 ;; Note: we don't use save-restriction because that does not work right
1204 ;; if changes are made outside the saved restriction
1205 ;; before that restriction is restored.
1206 (narrow-to-region beg end)
1207 (set-marker beg nil)
1208 (set-marker end nil)))
1209 (while (string-match " +," blurb)
1210 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1211 (substring blurb (match-end 0)))))
1212 (while (string-match ", +" blurb)
1213 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
1214 (substring blurb (match-end 0)))))
1215 (setq mode-line-process
1216 (concat " " rmail-current-message "/" rmail-total-messages
1219 ;; Turn an attribute of a message on or off according to STATE.
1220 ;; ATTR is the name of the attribute, as a string.
1221 ;; MSGNUM is message number to change; nil means current message.
1222 (defun rmail-set-attribute (attr state &optional msgnum)
1223 (let ((omax (point-max-marker))
1224 (omin (point-min-marker))
1225 (buffer-read-only nil))
1226 (or msgnum (setq msgnum rmail-current-message))
1231 (goto-char (+ 3 (rmail-msgbeg msgnum)))
1234 (null (search-backward (concat ", " attr ",")
1235 (prog1 (point) (end-of-line)) t)))))
1236 (or (eq curstate (not (not state)))
1238 (delete-region (point) (1- (match-end 0)))
1241 (insert " " attr ","))))
1242 (if (string= attr "deleted")
1243 (rmail-set-message-deleted-p msgnum state)))
1244 ;; Note: we don't use save-restriction because that does not work right
1245 ;; if changes are made outside the saved restriction
1246 ;; before that restriction is restored.
1247 (narrow-to-region omin omax)
1248 (set-marker omin nil)
1249 (set-marker omax nil)
1250 (if (= msgnum rmail-current-message)
1251 (rmail-display-labels))))))
1253 ;; Return t if the attributes/keywords line of msg number MSG
1254 ;; contains a match for the regexp LABELS.
1255 (defun rmail-message-labels-p (msg labels)
1259 (goto-char (rmail-msgbeg msg))
1261 (re-search-backward labels (prog1 (point) (end-of-line)) t))))
1263 ;;;; *** Rmail Message Selection And Support ***
1265 (defun rmail-msgend (n)
1266 (marker-position (aref rmail-message-vector (1+ n))))
1268 (defun rmail-msgbeg (n)
1269 (marker-position (aref rmail-message-vector n)))
1271 (defun rmail-widen-to-current-msgbeg (function)
1272 "Call FUNCTION with point at start of internal data of current message.
1273 Assumes that bounds were previously narrowed to display the message in Rmail.
1274 The bounds are widened enough to move point where desired, then narrowed
1277 FUNCTION may not change the visible text of the message, but it may
1278 change the invisible header text."
1280 (let ((obeg (- (point-max) (point-min))))
1283 (narrow-to-region (rmail-msgbeg rmail-current-message)
1285 (goto-char (point-min))
1287 ;; Note: we don't use save-restriction because that does not work right
1288 ;; if changes are made outside the saved restriction
1289 ;; before that restriction is restored.
1290 ;; Here we assume that changes made by FUNCTION
1291 ;; occur before the visible region of the message.
1292 (narrow-to-region (- (point-max) obeg) (point-max))))))
1294 (defun rmail-forget-messages ()
1296 (if (vectorp rmail-message-vector)
1298 (v rmail-message-vector)
1301 (move-marker (aref v i) nil)
1303 (setq rmail-message-vector nil)
1304 (setq rmail-deleted-vector nil)))
1306 (defun rmail-maybe-set-message-counters ()
1307 (if (not (and rmail-deleted-vector
1308 rmail-message-vector
1309 rmail-current-message
1310 rmail-total-messages))
1311 (rmail-set-message-counters)))
1313 (defun rmail-count-new-messages (&optional nomsg)
1314 (let* ((case-fold-search nil)
1318 (or nomsg (message "Counting new messages..."))
1319 (goto-char (point-max))
1320 ;; Put at the end of messages-head
1321 ;; the entry for message N+1, which marks
1322 ;; the end of message N. (N = number of messages).
1323 (search-backward "\n\^_")
1325 (setq messages-head (list (point-marker)))
1326 (rmail-set-message-counters-counter (point-min))
1327 (setq rmail-current-message (1+ rmail-total-messages))
1328 (setq rmail-total-messages
1329 (+ rmail-total-messages total-messages))
1330 (setq rmail-message-vector
1331 (vconcat rmail-message-vector (cdr messages-head)))
1332 (aset rmail-message-vector
1333 rmail-current-message (car messages-head))
1334 (setq rmail-deleted-vector
1335 (concat rmail-deleted-vector deleted-head))
1336 (setq rmail-summary-vector
1337 (vconcat rmail-summary-vector (make-vector total-messages nil)))
1338 (goto-char (point-min))
1339 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
1341 (defun rmail-set-message-counters ()
1342 (rmail-forget-messages)
1346 (let* ((point-save (point))
1348 (messages-after-point)
1349 (case-fold-search nil)
1352 (message "Counting messages...")
1353 (goto-char (point-max))
1354 ;; Put at the end of messages-head
1355 ;; the entry for message N+1, which marks
1356 ;; the end of message N. (N = number of messages).
1357 (search-backward "\n\^_" nil t)
1358 (if (/= (point) (point-max)) (forward-char 1))
1359 (setq messages-head (list (point-marker)))
1360 (rmail-set-message-counters-counter (min (point) point-save))
1361 (setq messages-after-point total-messages)
1362 (rmail-set-message-counters-counter)
1363 (setq rmail-total-messages total-messages)
1364 (setq rmail-current-message
1366 (max 1 (- total-messages messages-after-point))))
1367 (setq rmail-message-vector
1368 (apply 'vector (cons (point-min-marker) messages-head))
1369 rmail-deleted-vector (concat "D" deleted-head)
1370 rmail-summary-vector (make-vector rmail-total-messages nil))
1371 (message "Counting messages...done")))))
1373 (defun rmail-set-message-counters-counter (&optional stop)
1374 (while (search-backward "\n\^_\^L\n" stop t)
1376 (setq messages-head (cons (point-marker) messages-head))
1379 (cons (if (search-backward ", deleted,"
1385 (if (zerop (% (setq total-messages (1+ total-messages)) 20))
1386 (message "Counting messages...%d" total-messages))))
1388 (defun rmail-beginning-of-message ()
1389 "Show current message starting from the beginning."
1391 (rmail-show-message rmail-current-message))
1393 (defun rmail-show-message (&optional n)
1394 "Show message number N (prefix argument), counting from start of file.
1395 If summary buffer is currently displayed, update current message there also."
1397 (rmail-maybe-set-message-counters)
1399 (if (zerop rmail-total-messages)
1400 (progn (narrow-to-region (point-min) (1- (point-max)))
1401 (goto-char (point-min))
1402 (setq mode-line-process nil))
1405 (setq n rmail-current-message)
1408 rmail-current-message 1
1409 blurb "No previous message"))
1410 ((> n rmail-total-messages)
1411 (setq n rmail-total-messages
1412 rmail-current-message rmail-total-messages
1413 blurb "No following message"))
1415 (setq rmail-current-message n))))
1416 (let ((beg (rmail-msgbeg n))
1417 (end (rmail-msgend n)))
1420 (if (= (following-char) ?0)
1422 (rmail-reformat-message beg end)
1423 (rmail-set-attribute "unseen" nil))
1424 (search-forward "\n*** EOOH ***\n" end t)
1425 (narrow-to-region (point) end))
1426 (goto-char (point-min))
1427 (rmail-display-labels)
1428 (rmail-highlight-headers)
1429 (if transient-mark-mode (deactivate-mark))
1430 (run-hooks 'rmail-show-message-hook)
1431 ;; If there is a summary buffer, try to move to this message
1432 ;; in that buffer. But don't complain if this message
1433 ;; is not mentioned in the summary.
1434 (if (rmail-summary-exists)
1435 (let ((curr-msg rmail-current-message))
1436 (rmail-select-summary
1437 (rmail-summary-goto-msg curr-msg t t))))
1439 (message blurb))))))
1441 ;; Find all occurrences of certain fields, and highlight them.
1442 (defun rmail-highlight-headers ()
1443 ;; Do this only if the system supports faces.
1444 (if (and (fboundp 'internal-find-face)
1445 rmail-highlighted-headers)
1447 (search-forward "\n\n" nil 'move)
1449 (narrow-to-region (point-min) (point))
1450 (let ((case-fold-search t)
1451 (inhibit-read-only t)
1452 ;; Highlight with boldface if that is available.
1453 ;; Otherwise use the `highlight' face.
1454 (face (or rmail-highlight-face
1455 (if (face-differs-from-default-p 'bold)
1457 ;; List of overlays to reuse.
1458 (overlays rmail-overlay-list))
1459 (goto-char (point-min))
1460 (while (re-search-forward rmail-highlighted-headers nil t)
1461 (skip-chars-forward " \t")
1464 (while (progn (forward-line 1)
1465 (looking-at "[ \t]")))
1466 ;; Back up over newline, then trailing spaces or tabs
1468 (while (member (preceding-char) '(? ?\t))
1471 ;; Reuse an overlay we already have.
1473 (setq overlay (car overlays)
1474 overlays (cdr overlays))
1475 (overlay-put overlay 'face face)
1476 (move-overlay overlay beg (point)))
1477 ;; Make a new overlay and add it to
1478 ;; rmail-overlay-list.
1479 (setq overlay (make-overlay beg (point)))
1480 (overlay-put overlay 'face face)
1481 (setq rmail-overlay-list
1482 (cons overlay rmail-overlay-list))))))))))
1484 (defun rmail-next-message (n)
1485 "Show following message whether deleted or not.
1486 With prefix arg N, moves forward N messages, or backward if N is negative."
1488 (rmail-maybe-set-message-counters)
1489 (rmail-show-message (+ rmail-current-message n)))
1491 (defun rmail-previous-message (n)
1492 "Show previous message whether deleted or not.
1493 With prefix arg N, moves backward N messages, or forward if N is negative."
1495 (rmail-next-message (- n)))
1497 (defun rmail-next-undeleted-message (n)
1498 "Show following non-deleted message.
1499 With prefix arg N, moves forward N non-deleted messages,
1500 or backward if N is negative.
1502 Returns t if a new message is being shown, nil otherwise."
1504 (rmail-maybe-set-message-counters)
1505 (let ((lastwin rmail-current-message)
1506 (current rmail-current-message))
1507 (while (and (> n 0) (< current rmail-total-messages))
1508 (setq current (1+ current))
1509 (if (not (rmail-message-deleted-p current))
1510 (setq lastwin current n (1- n))))
1511 (while (and (< n 0) (> current 1))
1512 (setq current (1- current))
1513 (if (not (rmail-message-deleted-p current))
1514 (setq lastwin current n (1+ n))))
1515 (if (/= lastwin rmail-current-message)
1516 (progn (rmail-show-message lastwin)
1519 (message "No previous nondeleted message"))
1521 (message "No following nondeleted message"))
1524 (defun rmail-previous-undeleted-message (n)
1525 "Show previous non-deleted message.
1526 With prefix argument N, moves backward N non-deleted messages,
1527 or forward if N is negative."
1529 (rmail-next-undeleted-message (- n)))
1531 (defun rmail-first-message ()
1532 "Show first message in file."
1534 (rmail-maybe-set-message-counters)
1535 (rmail-show-message 1))
1537 (defun rmail-last-message ()
1538 "Show last message in file."
1540 (rmail-maybe-set-message-counters)
1541 (rmail-show-message rmail-total-messages))
1543 (defun rmail-what-message ()
1544 (let ((where (point))
1546 (high rmail-total-messages)
1547 (mid (/ rmail-total-messages 2)))
1548 (while (> (- high low) 1)
1549 (if (>= where (rmail-msgbeg mid))
1552 (setq mid (+ low (/ (- high low) 2))))
1553 (if (>= where (rmail-msgbeg high)) high low)))
1555 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
1557 (goto-char (rmail-msgbeg msg))
1558 (search-forward "\n*** EOOH ***\n")
1559 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
1560 (or (string-match recipients (or (mail-fetch-field "To") ""))
1561 (string-match recipients (or (mail-fetch-field "From") ""))
1562 (if (not primary-only)
1563 (string-match recipients (or (mail-fetch-field "Cc") ""))))))
1565 (defun rmail-message-regexp-p (msg regexp)
1566 "Return t, if for message number MSG, regexp REGEXP matches in the header."
1567 (goto-char (rmail-msgbeg msg))
1570 (search-forward "*** EOOH ***" (point-max)) (point))))
1571 (re-search-forward regexp end t)))
1573 (defun rmail-search-backward (regexp &optional n)
1574 "Show message containing next match for REGEXP.
1575 Prefix argument gives repeat count; negative argument means search
1576 backwards (through earlier messages).
1577 Interactively, empty argument means use same regexp used last time."
1579 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1581 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1583 (if rmail-search-last-regexp
1584 (setq prompt (concat prompt
1586 rmail-search-last-regexp
1588 (setq regexp (read-string prompt))
1589 (cond ((not (equal regexp ""))
1590 (setq rmail-search-last-regexp regexp))
1591 ((not rmail-search-last-regexp)
1592 (error "No previous Rmail search string")))
1593 (list rmail-search-last-regexp
1594 (prefix-numeric-value current-prefix-arg))))
1595 (rmail-search regexp (- n)))
1597 (defvar rmail-search-last-regexp nil)
1598 (defun rmail-search (regexp &optional n)
1599 "Show message containing next match for REGEXP.
1600 Prefix argument gives repeat count; negative argument means search
1601 backwards (through earlier messages).
1602 Interactively, empty argument means use same regexp used last time."
1604 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1606 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1608 (if rmail-search-last-regexp
1609 (setq prompt (concat prompt
1611 rmail-search-last-regexp
1613 (setq regexp (read-string prompt))
1614 (cond ((not (equal regexp ""))
1615 (setq rmail-search-last-regexp regexp))
1616 ((not rmail-search-last-regexp)
1617 (error "No previous Rmail search string")))
1618 (list rmail-search-last-regexp
1619 (prefix-numeric-value current-prefix-arg))))
1621 (message "%sRmail search for %s..."
1622 (if (< n 0) "Reverse " "")
1624 (rmail-maybe-set-message-counters)
1625 (let ((omin (point-min))
1630 (msg rmail-current-message))
1635 ;; Check messages one by one, advancing message number up or down
1636 ;; but searching forward through each message.
1638 (while (and (null win) (> msg 1))
1639 (goto-char (rmail-msgbeg (setq msg (1- msg))))
1640 (setq win (re-search-forward
1641 regexp (rmail-msgend msg) t)))
1642 (while (and (null win) (< msg rmail-total-messages))
1643 (goto-char (rmail-msgbeg (setq msg (1+ msg))))
1644 (setq win (re-search-forward regexp (rmail-msgend msg) t))))
1645 (setq n (+ n (if reversep 1 -1)))))
1648 ;; If this is a reverse search and we found a message,
1649 ;; search backward thru this message to position point.
1652 (goto-char (rmail-msgend msg))
1654 regexp (rmail-msgbeg msg) t)))
1656 (rmail-show-message msg)
1657 (message "%sRmail search for %s...done"
1658 (if reversep "Reverse " "")
1662 (narrow-to-region omin omax)
1664 (message "Search failed: %s" regexp)))))
1666 (defun rmail-search-backwards (regexp &optional n)
1667 "Show message containing previous match for REGEXP.
1668 Prefix argument gives repeat count; negative argument means search
1669 forward (through later messages).
1670 Interactively, empty argument means use same regexp used last time."
1672 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1674 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
1676 (if rmail-search-last-regexp
1677 (setq prompt (concat prompt
1679 rmail-search-last-regexp
1681 (setq regexp (read-string prompt))
1682 (cond ((not (equal regexp ""))
1683 (setq rmail-search-last-regexp regexp))
1684 ((not rmail-search-last-regexp)
1685 (error "No previous Rmail search string")))
1686 (list rmail-search-last-regexp
1687 (prefix-numeric-value current-prefix-arg))))
1688 (rmail-search regexp (- (or n -1))))
1690 ;; Show the first message which has the `unseen' attribute.
1691 (defun rmail-first-unseen-message ()
1692 (rmail-maybe-set-message-counters)
1697 (while (and (not found) (< current rmail-total-messages))
1698 (if (rmail-message-labels-p current ", ?\\(unseen\\),")
1699 (setq found current))
1700 (setq current (1+ current))))
1701 ;; Let the caller show the message.
1703 ;; (rmail-show-message found))
1706 ;;;; *** Rmail Message Deletion Commands ***
1708 (defun rmail-message-deleted-p (n)
1709 (= (aref rmail-deleted-vector n) ?D))
1711 (defun rmail-set-message-deleted-p (n state)
1712 (aset rmail-deleted-vector n (if state ?D ?\ )))
1714 (defun rmail-delete-message ()
1715 "Delete this message and stay on it."
1717 (rmail-set-attribute "deleted" t))
1719 (defun rmail-undelete-previous-message ()
1720 "Back up to deleted message, select it, and undelete it."
1722 (let ((msg rmail-current-message))
1723 (while (and (> msg 0)
1724 (not (rmail-message-deleted-p msg)))
1725 (setq msg (1- msg)))
1727 (error "No previous deleted message")
1728 (if (/= msg rmail-current-message)
1729 (rmail-show-message msg))
1730 (rmail-set-attribute "deleted" nil)
1731 (if (rmail-summary-exists)
1733 (set-buffer rmail-summary-buffer)
1734 (rmail-summary-mark-undeleted msg)))
1735 (rmail-maybe-display-summary))))
1737 (defun rmail-delete-forward (&optional backward)
1738 "Delete this message and move to next nondeleted one.
1739 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
1740 With prefix argument, delete and move backward.
1742 Returns t if a new message is displayed after the delete, or nil otherwise."
1744 (rmail-set-attribute "deleted" t)
1745 (let ((del-msg rmail-current-message))
1746 (if (rmail-summary-exists)
1748 (set-buffer rmail-summary-buffer)
1749 (rmail-summary-mark-deleted del-msg)))
1750 (prog1 (rmail-next-undeleted-message (if backward -1 1))
1751 (rmail-maybe-display-summary))))
1753 (defun rmail-delete-backward ()
1754 "Delete this message and move to previous nondeleted one.
1755 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
1757 (rmail-delete-forward t))
1759 (defun rmail-only-expunge ()
1760 "Actually erase all deleted messages in the file."
1762 (message "Expunging deleted messages...")
1763 ;; Discard all undo records for this buffer.
1764 (or (eq buffer-undo-list t)
1765 (setq buffer-undo-list nil))
1766 (rmail-maybe-set-message-counters)
1767 (let* ((omax (- (buffer-size) (point-max)))
1768 (omin (- (buffer-size) (point-min)))
1769 (opoint (if (and (> rmail-current-message 0)
1770 (rmail-message-deleted-p rmail-current-message))
1772 (- (point) (point-min))))
1773 (messages-head (cons (aref rmail-message-vector 0) nil))
1774 (messages-tail messages-head)
1775 ;; Don't make any undo records for the expunging.
1776 (buffer-undo-list t)
1781 (goto-char (point-min))
1784 (total rmail-total-messages)
1785 (new-message-number rmail-current-message)
1787 (buffer-read-only nil)
1788 (messages rmail-message-vector)
1789 (deleted rmail-deleted-vector)
1790 (summary rmail-summary-vector))
1791 (setq rmail-total-messages nil
1792 rmail-current-message nil
1793 rmail-message-vector nil
1794 rmail-deleted-vector nil
1795 rmail-summary-vector nil)
1796 (while (<= number total)
1797 (if (= (aref deleted number) ?D)
1800 (marker-position (aref messages number))
1801 (marker-position (aref messages (1+ number))))
1802 (move-marker (aref messages number) nil)
1803 (if (> new-message-number counter)
1804 (setq new-message-number (1- new-message-number))))
1805 (setq counter (1+ counter))
1807 (setcdr messages-tail
1808 (cons (aref messages number) nil)))
1810 (cons (if (= counter number) (aref summary (1- number)))
1812 (if (zerop (% (setq number (1+ number)) 20))
1813 (message "Expunging deleted messages...%d" number)))
1815 (setcdr messages-tail
1816 (cons (aref messages number) nil)))
1817 (setq rmail-current-message new-message-number
1818 rmail-total-messages counter
1819 rmail-message-vector (apply 'vector messages-head)
1820 rmail-deleted-vector (make-string (1+ counter) ?\ )
1821 rmail-summary-vector (vconcat (nreverse new-summary))
1823 (message "Expunging deleted messages...done")
1825 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
1827 (if (zerop rmail-current-message) 1 nil))
1828 (forward-char opoint))))
1830 (defun rmail-expunge ()
1831 "Erase deleted messages from Rmail file and summary buffer."
1833 (rmail-only-expunge)
1834 (if (rmail-summary-exists)
1835 (rmail-select-summary
1836 (rmail-update-summary))))
1838 ;;;; *** Rmail Mailing Commands ***
1840 (defun rmail-start-mail (&rest args)
1841 (if (and window-system rmail-mail-new-frame)
1843 (apply 'mail-other-frame args)
1844 (modify-frame-parameters (selected-frame)
1845 '((dedicated . t))))
1846 (apply 'mail-other-window args)))
1848 (defun rmail-mail ()
1849 "Send mail in another window.
1850 While composing the message, use \\[mail-yank-original] to yank the
1851 original message into it."
1853 (rmail-start-mail nil nil nil nil nil (current-buffer)))
1855 (defun rmail-continue ()
1856 "Continue composing outgoing message previously being composed."
1858 (rmail-start-mail t))
1860 (defun rmail-reply (just-sender)
1861 "Reply to the current message.
1862 Normally include CC: to all other recipients of original message;
1863 prefix argument means ignore them. While composing the reply,
1864 use \\[mail-yank-original] to yank the original message into it."
1866 (let (from reply-to cc subject date to message-id resent-reply-to)
1870 (goto-char (rmail-msgbeg rmail-current-message))
1872 (if (= (following-char) ?0)
1874 (progn (forward-line 2)
1876 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
1879 (narrow-to-region (point)
1880 (progn (search-forward "\n*** EOOH ***\n")
1881 (beginning-of-line) (point))))
1882 (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
1883 from (mail-fetch-field "from")
1884 reply-to (or resent-reply-to
1885 (mail-fetch-field "reply-to" nil t)
1887 cc (cond (just-sender nil)
1888 (resent-reply-to (mail-fetch-field "resent-cc" t))
1889 (t (mail-fetch-field "cc" nil t)))
1890 subject (or (and resent-reply-to
1891 (mail-fetch-field "resent-subject" t))
1892 (mail-fetch-field "subject"))
1893 date (or (and resent-reply-to
1894 (mail-fetch-field "resent-date" t))
1895 (mail-fetch-field "date"))
1896 to (cond (resent-reply-to
1897 (or (mail-fetch-field "resent-to" t)) "")
1898 ((mail-fetch-field "to" nil t))
1899 ;((mail-fetch-field "apparently-to")) ack gag barf
1901 message-id (cond (resent-reply-to
1902 (mail-fetch-field "resent-message-id" t))
1903 ((mail-fetch-field "message-id"))))))
1904 (and (stringp subject)
1905 (or (string-match (concat "\\`" (regexp-quote rmail-reply-prefix))
1907 (setq subject (concat rmail-reply-prefix subject))))
1908 (rmail-start-mail nil
1909 (mail-strip-quoted-names reply-to)
1911 (rmail-make-in-reply-to-field from date message-id)
1914 (let* ((cc-list (rmail-dont-reply-to
1915 (mail-strip-quoted-names
1916 (if (null cc) to (concat to ", " cc))))))
1917 (if (string= cc-list "") nil cc-list)))
1919 (list (list '(lambda (buf msgnum)
1922 (rmail-set-attribute "answered" t msgnum)))
1923 (current-buffer) rmail-current-message)))))
1925 (defun rmail-make-in-reply-to-field (from date message-id)
1932 (let ((tem (car (rfc822-addresses from))))
1935 (regexp-quote (if (string-match "@[^@]*\\'" tem)
1936 (substring tem 0 (match-beginning 0))
1939 ;; Message-ID is sufficiently informative
1941 (concat message-id " (" tem ")"))
1942 ;; Copy TEM, discarding text properties.
1943 (setq tem (copy-sequence tem))
1944 (set-text-properties 0 (length tem) nil tem)
1945 (setq tem (copy-sequence tem))
1946 ;; Use prin1 to fake RFC822 quoting
1947 (let ((field (prin1-to-string tem)))
1949 (concat field "'s message of " date)
1951 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
1952 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
1953 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
1954 (or (string-match (concat "\\`[ \t]*\\(" bar
1955 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
1956 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
1958 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
1959 bar "\\))[ \t]*\\'")
1960 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
1962 (let ((start (match-beginning 1))
1963 (end (match-end 1)))
1964 ;; Trim whitespace which above regexp match allows
1965 (while (and (< start end)
1966 (memq (aref from start) '(?\t ?\ )))
1967 (setq start (1+ start)))
1968 (while (and (< start end)
1969 (memq (aref from (1- end)) '(?\t ?\ )))
1970 (setq end (1- end)))
1971 (let ((field (substring from start end)))
1972 (if date (setq field (concat "message from " field " on " date)))
1974 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
1975 (concat message-id " (" field ")")
1978 ;; If we can't kludge it simply, do it correctly
1979 (let ((mail-use-rfc822 t))
1980 (rmail-make-in-reply-to-field from date message-id)))))
1982 (defun rmail-forward (resend)
1983 "Forward the current message to another user.
1984 With prefix argument, \"resend\" the message instead of forwarding it;
1985 see the documentation of `rmail-resend'."
1988 (call-interactively 'rmail-resend)
1989 (let ((forward-buffer (current-buffer))
1990 (subject (concat "["
1991 (let ((from (or (mail-fetch-field "From")
1992 (mail-fetch-field ">From"))))
1994 (concat (mail-strip-quoted-names from) ": ")
1996 (or (mail-fetch-field "Subject") "")
1998 ;; If only one window, use it for the mail buffer.
1999 ;; Otherwise, use another window for the mail buffer
2000 ;; so that the Rmail buffer remains visible
2001 ;; and sending the mail will get back to it.
2002 (if (funcall (if (and (not rmail-mail-new-frame) (one-window-p t))
2004 (function rmail-start-mail))
2005 nil nil subject nil nil nil
2006 (list (list (function (lambda (buf msgnum)
2009 (rmail-set-attribute
2010 "forwarded" t msgnum))))
2012 rmail-current-message)))
2014 ;; Insert after header separator--before signature if any.
2015 (goto-char (point-min))
2016 (search-forward-regexp
2017 (concat "^" (regexp-quote mail-header-separator) "$"))
2019 (insert "------- Start of forwarded message -------\n")
2020 (insert-buffer forward-buffer)
2022 (exchange-point-and-mark)
2023 (insert "------- End of forwarded message -------\n")
2025 (exchange-point-and-mark))))))
2027 (defun rmail-resend (address &optional from comment mail-alias-file)
2028 "Resend current message to ADDRESSES.
2029 ADDRESSES should be a single address, a string consisting of several
2030 addresses separated by commas, or a list of addresses.
2032 Optional FROM is the address to resend the message from, and
2033 defaults to the username of the person redistributing the message.
2034 Optional COMMENT is a string that will be inserted as a comment in the
2036 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
2037 typically for purposes of moderating a list."
2038 (interactive "sResend to: ")
2040 (require 'mailalias)
2041 (if (not from) (setq from (user-login-name)))
2042 (let ((tembuf (generate-new-buffer " sendmail temp"))
2043 (mail-header-separator "")
2044 (case-fold-search nil)
2045 (mailbuf (current-buffer)))
2048 ;;>> Copy message into temp buffer
2050 (insert-buffer-substring mailbuf)
2051 (goto-char (point-min))
2052 ;; Delete any Sender field, since that's not specifyable.
2053 ; Only delete Sender fields in the actual header.
2054 (re-search-forward "^$" nil 'move)
2055 ; Using "while" here rather than "if" because some buggy mail
2056 ; software may have inserted multiple Sender fields.
2057 (while (re-search-backward "^Sender:" nil t)
2061 (while (looking-at "[ \t]")
2063 (delete-region beg (point))))
2064 ; Go back to the beginning of the buffer so the Resent- fields
2065 ; are inserted there.
2066 (goto-char (point-min))
2067 ;;>> Insert resent-from:
2068 (insert "Resent-From: " from "\n")
2069 (insert "Resent-Date: " (mail-rfc822-date) "\n")
2070 ;;>> Insert resent-to: and bcc if need be.
2071 (let ((before (point)))
2073 (insert "Resent-Bcc: " (user-login-name) "\n"))
2074 (insert "Resent-To: " (if (stringp address)
2076 (mapconcat 'identity address ",\n\t"))
2079 (expand-mail-aliases before (point))))
2080 ;;>> Set up comment, if any.
2081 (if (and (sequencep comment) (not (zerop (length comment))))
2082 (let ((before (point))
2085 (or (eolp) (insert "\n"))
2086 (setq after (point))
2088 (while (< (point) after)
2089 (insert "Resent-Comment: ")
2091 ;; Don't expand aliases in the destination fields
2092 ;; of the original message.
2094 (funcall send-mail-function)))
2095 (kill-buffer tembuf))
2096 (rmail-set-attribute "resent" t rmail-current-message)))
2098 (defvar mail-unsent-separator
2099 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
2100 "^ *---+ +Returned message +---+ *$\\|"
2101 "^ *---+ +Original message +---+ *$\\|"
2102 "^ *--+ +begin message +--+ *$\\|"
2103 "^ *---+ +Original message follows +---+ *$\\|"
2104 "^|? *---+ +Message text follows: +---+ *|?$")
2105 "A regexp that matches the separator before the text of a failed message.")
2107 (defun rmail-retry-failure ()
2108 "Edit a mail message which is based on the contents of the current message.
2109 For a message rejected by the mail system, extract the interesting headers and
2110 the body of the original message.
2111 The variable `mail-unsent-separator' should match the string that
2112 delimits the returned original message."
2114 (require 'mail-utils)
2115 (let (to subj irp2 cc orig-message)
2117 ;; Narrow down to just the quoted original message
2118 (rmail-beginning-of-message)
2119 (let ((case-fold-search t))
2120 (or (re-search-forward mail-unsent-separator nil t)
2121 (error "Cannot parse this as a failure message")))
2123 (let ((old-end (point-max)))
2124 ;; One message contained a few random lines before the old
2125 ;; message header. The first line of the message started with
2126 ;; two hyphens. A blank line follows these random lines.
2127 (skip-chars-forward "\n")
2128 (if (looking-at "^--")
2130 (search-forward "\n\n")
2131 (skip-chars-forward "\n")))
2132 (narrow-to-region (point) (point-max))
2133 (goto-char (point-min))
2134 (search-forward "\n\n")
2135 (narrow-to-region (point-min) (point))
2136 ;; Now mail-fetch-field will get from headers of the original message,
2137 ;; not from the headers of the rejection.
2138 (setq to (mail-fetch-field "To")
2139 subj (mail-fetch-field "Subject")
2140 irp2 (mail-fetch-field "In-reply-to")
2141 cc (mail-fetch-field "Cc"))
2142 ;; Get the entire text (not headers) of the original message.
2143 (goto-char (point-max))
2146 (buffer-substring (point) old-end)))))
2147 ;; Start sending a new message; default header fields from the original.
2148 ;; Turn off the usual actions for initializing the message body
2149 ;; because we want to get only the text from the failure message.
2150 (let (mail-signature
2151 (mail-setup-hook rmail-retry-setup-hook))
2152 (if (rmail-start-mail nil to subj irp2 cc (current-buffer))
2153 ;; Insert original text as initial text of new draft message.
2155 (goto-char (point-max))
2156 (insert orig-message)
2157 (goto-char (point-min))
2160 (defun rmail-bury ()
2161 "Bury current Rmail buffer and its summary buffer."
2163 ;; This let var was called rmail-buffer, but that interfered
2164 ;; with the buffer-local var used in summary buffers.
2165 (let ((buffer-to-bury (current-buffer)))
2166 (if (rmail-summary-exists)
2168 (while (setq window (get-buffer-window rmail-summary-buffer))
2169 (set-window-buffer window (other-buffer rmail-summary-buffer)))
2170 (bury-buffer rmail-summary-buffer)))
2171 (switch-to-buffer (other-buffer (current-buffer)))
2172 (bury-buffer buffer-to-bury)))
2174 (defun rmail-summary-exists ()
2175 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
2176 In fact, the non-nil value returned is the summary buffer itself."
2177 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2178 rmail-summary-buffer))
2180 (defun rmail-summary-displayed ()
2181 "t iff in RMAIL buffer and an associated summary buffer is displayed."
2182 (and rmail-summary-buffer (get-buffer-window rmail-summary-buffer)))
2184 (defvar rmail-redisplay-summary nil
2185 "*Non-nil means Rmail should show the summary when it changes.
2186 This has an effect only if a summary buffer exists.")
2188 (defvar rmail-summary-window-size nil
2189 "*Non-nil means specify the height for an Rmail summary window.")
2191 ;; Put the summary buffer back on the screen, if user wants that.
2192 (defun rmail-maybe-display-summary ()
2193 (let ((selected (selected-window))
2195 ;; If requested, make sure the summary is displayed.
2196 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2197 rmail-redisplay-summary
2198 (if (get-buffer-window rmail-summary-buffer 0)
2199 ;; It's already in some frame; show that one.
2200 (let ((frame (window-frame
2201 (get-buffer-window rmail-summary-buffer 0))))
2202 (make-frame-visible frame)
2203 (raise-frame frame))
2204 (display-buffer rmail-summary-buffer)))
2205 ;; If requested, set the height of the summary window.
2206 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
2207 rmail-summary-window-size
2208 (setq window (get-buffer-window rmail-summary-buffer))
2209 ;; Don't try to change the size if just one window in frame.
2210 (not (eq window (frame-root-window (window-frame window))))
2213 (select-window window)
2214 (enlarge-window (- rmail-summary-window-size
2216 (select-window selected)))))
2218 ;;;; *** Rmail Specify Inbox Files ***
2220 (autoload 'set-rmail-inbox-list "rmailmsc"
2221 "Set the inbox list of the current RMAIL file to FILE-NAME.
2222 This may be a list of file names separated by commas.
2223 If FILE-NAME is empty, remove any inbox list."
2226 ;;;; *** Rmail Commands for Labels ***
2228 (autoload 'rmail-add-label "rmailkwd"
2229 "Add LABEL to labels associated with current RMAIL message.
2230 Completion is performed over known labels when reading."
2233 (autoload 'rmail-kill-label "rmailkwd"
2234 "Remove LABEL from labels associated with current RMAIL message.
2235 Completion is performed over known labels when reading."
2238 (autoload 'rmail-next-labeled-message "rmailkwd"
2239 "Show next message with LABEL. Defaults to last label used.
2240 With prefix argument N moves forward N messages with this label."
2243 (autoload 'rmail-previous-labeled-message "rmailkwd"
2244 "Show previous message with LABEL. Defaults to last label used.
2245 With prefix argument N moves backward N messages with this label."
2248 (autoload 'rmail-read-label "rmailkwd"
2249 "PROMPT and read with completion an Rmail message label."
2252 ;;;; *** Rmail Edit Mode ***
2254 (autoload 'rmail-edit-current-message "rmailedit"
2255 "Edit the contents of the current message"
2258 ;;;; *** Rmail Sorting ***
2260 (autoload 'rmail-sort-by-date "rmailsort"
2261 "Sort messages of current Rmail file by date.
2262 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2264 (autoload 'rmail-sort-by-subject "rmailsort"
2265 "Sort messages of current Rmail file by subject.
2266 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2268 (autoload 'rmail-sort-by-author "rmailsort"
2269 "Sort messages of current Rmail file by author.
2270 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2272 (autoload 'rmail-sort-by-recipient "rmailsort"
2273 "Sort messages of current Rmail file by recipient.
2274 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2276 (autoload 'rmail-sort-by-correspondent "rmailsort"
2277 "Sort messages of current Rmail file by other correspondent.
2278 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2280 (autoload 'rmail-sort-by-lines "rmailsort"
2281 "Sort messages of current Rmail file by number of lines.
2282 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
2284 (autoload 'rmail-sort-by-keywords "rmailsort"
2285 "Sort messages of current Rmail file by labels.
2286 If prefix argument REVERSE is non-nil, sort them in reverse order.
2287 KEYWORDS is a comma-separated list of labels." t)
2289 ;;;; *** Rmail Summary Mode ***
2291 (autoload 'rmail-summary "rmailsum"
2292 "Display a summary of all messages, one line per message."
2295 (autoload 'rmail-summary-by-labels "rmailsum"
2296 "Display a summary of all messages with one or more LABELS.
2297 LABELS should be a string containing the desired labels, separated by commas."
2300 (autoload 'rmail-summary-by-recipients "rmailsum"
2301 "Display a summary of all messages with the given RECIPIENTS.
2302 Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
2303 is non-nil (prefix arg given), only look in the To and From fields.
2304 RECIPIENTS is a string of regexps separated by commas."
2307 (autoload 'rmail-summary-by-regexp "rmailsum"
2308 "Display a summary of all messages according to regexp REGEXP.
2309 If the regular expression is found in the header of the message
2310 \(including in the date and other lines, as well as the subject line),
2311 Emacs will list the header line in the RMAIL-summary."
2314 (autoload 'rmail-summary-by-topic "rmailsum"
2315 "Display a summary of all messages with the given SUBJECT.
2316 Normally checks the Subject field of headers;
2317 but if WHOLE-MESSAGE is non-nil (prefix arg given),
2318 look in the whole message.
2319 SUBJECT is a string of regexps separated by commas."
2322 ;;;; *** Rmail output messages to files ***
2324 (autoload 'rmail-output-to-rmail-file "rmailout"
2325 "Append the current message to an Rmail file named FILE-NAME.
2326 If the file does not exist, ask if it should be created.
2327 If file is being visited, the message is appended to the Emacs
2328 buffer visiting that file."
2331 (autoload 'rmail-output "rmailout"
2332 "Append this message to Unix mail file named FILE-NAME."
2335 (autoload 'rmail-output-menu "rmailout"
2336 "Output current message to another Rmail file, chosen with a menu."
2339 ;;;; *** Rmail undigestification ***
2341 (autoload 'undigestify-rmail-message "undigest"
2342 "Break up a digest message into its constituent messages.
2343 Leaves original message, deleted, before the undigestified messages."
2348 ;;; rmail.el ends here