home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / a2.0bemacs-src.lha / Emacs-19.25 / lisp / rmail.el < prev    next >
Encoding:
Text File  |  1994-05-27  |  82.0 KB  |  2,280 lines

  1. ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
  2.  
  3. ;; Copyright (C) 1985,86,87,88,93,94 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: mail
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  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)
  13. ;; any later version.
  14.  
  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.
  19.  
  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.
  23.  
  24. ;;; Code:
  25.  
  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.
  30.  
  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.
  36. ;;
  37.  
  38. (require 'mail-utils)
  39.  
  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))
  44.  
  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")
  51. ;  "")
  52.  
  53. ;;;###autoload
  54. (defvar rmail-dont-reply-to-names nil "\
  55. *A regexp specifying names to prune of reply to messages.
  56. A value of nil means exclude your own name only.")
  57.  
  58. ;;;###autoload
  59. (defvar rmail-default-dont-reply-to-names "info-" "\
  60. A regular expression specifying part of the value of the default value of
  61. the variable `rmail-dont-reply-to-names', for when the user does not set
  62. `rmail-dont-reply-to-names' explicitly.  (The other part of the default
  63. value is the user's name.)
  64. It is useful to set this variable in the site customization file.")
  65.  
  66. ;;;###autoload
  67. (defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:\\|^message-id:\\|^summary-line:" "\
  68. *Regexp to match Header fields that rmail should normally hide.")
  69.  
  70. ;;;###autoload
  71. (defvar rmail-highlighted-headers "^From:\\|^Subject:" "\
  72. *Regexp to match Header fields that rmail should normally highlight.")
  73.  
  74. ;;;###autoload
  75. (defvar rmail-delete-after-output nil "\
  76. *Non-nil means automatically delete a message that is copied to a file.")
  77.  
  78. ;;;###autoload
  79. (defvar rmail-primary-inbox-list nil "\
  80. *List of files which are inboxes for user's primary mail file `~/RMAIL'.
  81. `nil' means the default, which is (\"/usr/spool/mail/$USER\")
  82. \(the name varies depending on the operating system,
  83. and the value of the environment variable MAIL overrides it).")
  84.  
  85. ;;;###autoload
  86. (defvar rmail-mail-new-frame nil
  87.   "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
  88.  
  89. ;;;###autoload
  90. (defvar rmail-retry-setup-hook nil
  91.   "Hook that `rmail-retry-failure' uses in place of `mail-setup-hook'.")
  92.  
  93. ;;;###autoload
  94. (defvar rmail-secondary-file-directory "~/"
  95.   "*Directory for additional secondary Rmail files.")
  96. ;;;###autoload
  97. (defvar rmail-secondary-file-regexp "\\.xmail$"
  98.   "*Regexp for which files are secondary Rmail files.")
  99.  
  100. ;; These may be altered by site-init.el to match the format of mmdf files
  101. ;;  delimiting used on a given host (delim1 and delim2 from the config
  102. ;;  files).
  103.  
  104. (defvar mmdf-delim1 "^\001\001\001\001\n"
  105.   "Regexp marking the start of an mmdf message")
  106. (defvar mmdf-delim2 "^\001\001\001\001\n"
  107.   "Regexp marking the end of an mmdf message")
  108.  
  109. (defvar rmail-message-filter nil
  110.   "If non nil, a filter function for new messages in RMAIL.
  111. Called with region narrowed to the message, including headers.")
  112.  
  113. (defvar rmail-reply-prefix "Re: "
  114.   "String to prepend to Subject line when replying to a message.")
  115.  
  116. (defvar rmail-mode-map nil)
  117.  
  118. (defvar rmail-inbox-list nil)
  119. (defvar rmail-keywords nil)
  120.  
  121. ;; Message counters and markers.  Deleted flags.
  122.  
  123. (defvar rmail-current-message nil)
  124. (defvar rmail-total-messages nil)
  125. (defvar rmail-message-vector nil)
  126. (defvar rmail-deleted-vector nil)
  127.  
  128. (defvar rmail-overlay-list nil)
  129.  
  130. ;; These are used by autoloaded rmail-summary.
  131.  
  132. (defvar rmail-summary-buffer nil)
  133. (defvar rmail-summary-vector nil)
  134.  
  135. ;; `Sticky' default variables.
  136.  
  137. ;; Last individual label specified to a or k.
  138. (defvar rmail-last-label nil)
  139. ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
  140. (defvar rmail-last-multi-labels nil)
  141. (defvar rmail-last-regexp nil)
  142. (defvar rmail-default-file nil
  143.   "*Default file name for \\[rmail-output].")
  144. (defvar rmail-default-rmail-file (expand-file-name "~/XMAIL")
  145.   "*Default file name for \\[rmail-output-to-rmail-file].")
  146.  
  147. ;;; Regexp matching the delimiter of messages in UNIX mail format
  148. ;;; (UNIX From lines), minus the initial ^.  Note that if you change
  149. ;;; this expression, you must change the code in rmail-nuke-pinhead-header
  150. ;;; that knows the exact ordering of the \\( \\) subexpressions.
  151. (defvar rmail-unix-mail-delimiter
  152.   (let ((time-zone-regexp
  153.      (concat "\\([A-Z]?[A-Z][A-Z][A-Z]\\( DST\\)?"
  154.          "\\|[-+]?[0-9][0-9][0-9][0-9]"
  155.          "\\|"
  156.          "\\) *")))
  157.     (concat
  158.      "From "
  159.  
  160.      ;; Username, perhaps with a quoted section that can contain spaces.
  161.      "\\("
  162.      "[^ \n]*"
  163.      "\\(\\|\".*\"[^ \n]*\\)"
  164.      "\\)  ?"
  165.  
  166.      ;; The time the message was sent.
  167.      "\\([^ \n]*\\) *"            ; day of the week
  168.      "\\([^ ]*\\) *"            ; month
  169.      "\\([0-9]*\\) *"            ; day of month
  170.      "\\([0-9:]*\\) *"            ; time of day
  171.  
  172.      ;; Perhaps a time zone, specified by an abbreviation, or by a
  173.      ;; numeric offset.
  174.      time-zone-regexp
  175.  
  176.      ;; The year.
  177.      " [0-9][0-9]\\([0-9]*\\) *"
  178.  
  179.      ;; On some systems the time zone can appear after the year, too.
  180.      time-zone-regexp
  181.  
  182.      ;; Old uucp cruft.
  183.      "\\(remote from .*\\)?"
  184.  
  185.      "\n"))
  186.   nil)
  187.  
  188. ;; Perform BODY in the summary buffer
  189. ;; in such a way that its cursor is properly updated in its own window.
  190. (defmacro rmail-select-summary (&rest body)
  191.   (` (progn (if (rmail-summary-displayed)
  192.         (let ((window (selected-window)))
  193.           (save-excursion
  194.             (unwind-protect
  195.             (progn
  196.               (pop-to-buffer rmail-summary-buffer)
  197.               (,@ body))
  198.               (select-window window))))
  199.           (save-excursion
  200.         (set-buffer rmail-summary-buffer)
  201.         (progn (,@ body))))
  202.         (rmail-maybe-display-summary))))
  203.  
  204. ;;;; *** Rmail Mode ***
  205.  
  206. ;;;###autoload
  207. (defun rmail (&optional file-name-arg)
  208.   "Read and edit incoming mail.
  209. Moves messages into file named by `rmail-file-name' (a babyl format file)
  210.  and edits that file in RMAIL Mode.
  211. Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
  212.  
  213. May be called with file name as argument; then performs rmail editing on
  214. that file, but does not copy any new mail into the file.
  215. Interactively, if you supply a prefix argument, then you
  216. have a chance to specify a file name with the minibuffer."
  217.   (interactive (if current-prefix-arg
  218.            (list (read-file-name "Run rmail on RMAIL file: "
  219.                      nil nil t))))
  220.   (or rmail-default-file
  221.       (setq rmail-default-file (expand-file-name "~/xmail")))
  222.   (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
  223.      (existed (get-file-buffer file-name)))
  224.     ;; Like find-file, but in the case where a buffer existed
  225.     ;; and the file was reverted, recompute the message-data.
  226.     (if (and existed (not (verify-visited-file-modtime existed)))
  227.     (progn
  228.       ;; Don't be confused by apparent local-variables spec
  229.       ;; in the last message in the RMAIL file.
  230.       (let ((enable-local-variables nil))
  231.         (find-file file-name))
  232.       (if (and (verify-visited-file-modtime existed)
  233.            (eq major-mode 'rmail-mode))
  234.           (progn (rmail-forget-messages)
  235.              (rmail-set-message-counters))))
  236.       (let ((enable-local-variables nil))
  237.     (find-file file-name)))
  238.     (if (eq major-mode 'rmail-edit-mode)
  239.     (error "Exit Rmail Edit mode before getting new mail."))
  240.     (if (and existed (> (buffer-size) 0))
  241.     ;; Buffer not new and not empty; ensure in proper mode, but that's all.
  242.     (or (eq major-mode 'rmail-mode)
  243.         (rmail-mode-2))
  244.       (rmail-mode-2)
  245.       ;; Convert all or part to Babyl file if possible.
  246.       (rmail-convert-file)
  247.       (goto-char (point-max))
  248.       (if (null rmail-inbox-list)
  249.       (progn
  250.         (rmail-set-message-counters)
  251.         (rmail-show-message))))
  252.     (let ((existing-unseen (rmail-first-unseen-message)))
  253.       (or file-name-arg
  254.       (rmail-get-new-mail))
  255.       ;; Show the first unseen message, which might be from a previous session
  256.       ;; or might have been just read in by rmail-get-new-mail.  Must
  257.       ;; determine already unseen messages first, as rmail-get-new-mail
  258.       ;; positions on the first new message, thus marking it as seen.
  259.       (rmail-show-message existing-unseen))))
  260.  
  261. ;; Given the value of MAILPATH, return a list of inbox file names.
  262. ;; This is turned off because it is not clear that the user wants
  263. ;; all these inboxes to feed into the primary rmail file.
  264. ; (defun rmail-convert-mailpath (string)
  265. ;   (let (idx list)
  266. ;     (while (setq idx (string-match "[%:]" string))
  267. ;       (let ((this (substring string 0 idx)))
  268. ;     (setq string (substring string (1+ idx)))
  269. ;     (setq list (cons (if (string-match "%" this)
  270. ;                  (substring this 0 (string-match "%" this))
  271. ;                this)
  272. ;              list))))
  273. ;     list))
  274.  
  275. ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
  276. ; will not cause emacs 18.55 problems.
  277.  
  278. (defun rmail-convert-file ()
  279.   (let (convert)
  280.     (widen)
  281.     (goto-char (point-min))
  282.     ;; If file doesn't start like a Babyl file,
  283.     ;; convert it to one, by adding a header and converting each message.
  284.     (cond ((looking-at "BABYL OPTIONS:"))
  285.       ((looking-at "Version: 5\n")
  286.        ;; Losing babyl file made by old version of Rmail.
  287.        ;; Just fix the babyl file header; don't make a new one,
  288.        ;; so we don't lose the Labels: file attribute, etc.
  289.        (let ((buffer-read-only nil))
  290.          (insert "BABYL OPTIONS: -*- rmail -*-\n")))
  291.       ((equal (point-min) (point-max))
  292.        ;; Empty RMAIL file.  Just insert the header.
  293.        (rmail-insert-rmail-file-header))
  294.       (t
  295.        ;; Non-empty file in non-RMAIL format.  Add header and convert.
  296.        (setq convert t)
  297.        (rmail-insert-rmail-file-header)))
  298.     ;; If file was not a Babyl file or if there are
  299.     ;; Unix format messages added at the end,
  300.     ;; convert file as necessary.
  301.     (if (or convert
  302.         (save-excursion
  303.           (goto-char (point-max))
  304.           (search-backward "\^_")
  305.           (forward-char 1)
  306.           (looking-at "\n*From ")))
  307.     (let ((buffer-read-only nil))
  308.       (message "Converting to Babyl format...")
  309.       ;; If file needs conversion, convert it all,
  310.       ;; except for the BABYL header.
  311.       ;; (rmail-convert-to-babyl-format would delete the header.)
  312.       (goto-char (point-min))
  313.       (search-forward "\n\^_" nil t)
  314.       (narrow-to-region (point) (point-max))
  315.       (rmail-convert-to-babyl-format)
  316.       (message "Converting to Babyl format...done")))))
  317.  
  318. ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
  319. ;;; will not cause emacs 18.55 problems.
  320.  
  321. (defun rmail-insert-rmail-file-header ()
  322.   (let ((buffer-read-only nil))
  323.     (insert "BABYL OPTIONS: -*- rmail -*-
  324. Version: 5
  325. Labels:
  326. Note:   This is the header of an rmail file.
  327. Note:   If you are seeing it in rmail,
  328. Note:    it means the file has no messages in it.\n\^_")))
  329.  
  330. (if rmail-mode-map
  331.     nil
  332.   (setq rmail-mode-map (make-keymap))
  333.   (suppress-keymap rmail-mode-map)
  334.   (define-key rmail-mode-map "a"      'rmail-add-label)
  335.   (define-key rmail-mode-map "b"      'rmail-bury)
  336.   (define-key rmail-mode-map "c"      'rmail-continue)
  337.   (define-key rmail-mode-map "d"      'rmail-delete-forward)
  338.   (define-key rmail-mode-map "\C-d"   'rmail-delete-backward)
  339.   (define-key rmail-mode-map "e"      'rmail-edit-current-message)
  340.   (define-key rmail-mode-map "f"      'rmail-forward)
  341.   (define-key rmail-mode-map "g"      'rmail-get-new-mail)
  342.   (define-key rmail-mode-map "h"      'rmail-summary)
  343.   (define-key rmail-mode-map "i"      'rmail-input)
  344.   (define-key rmail-mode-map "j"      'rmail-show-message)
  345.   (define-key rmail-mode-map "k"      'rmail-kill-label)
  346.   (define-key rmail-mode-map "l"      'rmail-summary-by-labels)
  347.   (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
  348.   (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
  349.   (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
  350.   (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
  351.   (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
  352.   (define-key rmail-mode-map "m"      'rmail-mail)
  353.   (define-key rmail-mode-map "\em"    'rmail-retry-failure)
  354.   (define-key rmail-mode-map "n"      'rmail-next-undeleted-message)
  355.   (define-key rmail-mode-map "\en"    'rmail-next-message)
  356.   (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
  357.   (define-key rmail-mode-map "o"      'rmail-output-to-rmail-file)
  358.   (define-key rmail-mode-map "\C-o"   'rmail-output)
  359.   (define-key rmail-mode-map "p"      'rmail-previous-undeleted-message)
  360.   (define-key rmail-mode-map "\ep"    'rmail-previous-message)
  361.   (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
  362.   (define-key rmail-mode-map "q"      'rmail-quit)
  363.   (define-key rmail-mode-map "r"      'rmail-reply)
  364. ;; I find I can't live without the default M-r command -- rms.
  365. ;;  (define-key rmail-mode-map "\er"  'rmail-search-backwards)
  366.   (define-key rmail-mode-map "s"      'rmail-expunge-and-save)
  367.   (define-key rmail-mode-map "\es"    'rmail-search)
  368.   (define-key rmail-mode-map "t"      'rmail-toggle-header)
  369.   (define-key rmail-mode-map "u"      'rmail-undelete-previous-message)
  370.   (define-key rmail-mode-map "w"      'rmail-edit-current-message)
  371.   (define-key rmail-mode-map "x"      'rmail-expunge)
  372.   (define-key rmail-mode-map "."      'rmail-beginning-of-message)
  373.   (define-key rmail-mode-map "<"      'rmail-first-message)
  374.   (define-key rmail-mode-map ">"      'rmail-last-message)
  375.   (define-key rmail-mode-map " "      'scroll-up)
  376.   (define-key rmail-mode-map "\177"   'scroll-down)
  377.   (define-key rmail-mode-map "?"      'describe-mode)
  378.   (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
  379.   (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
  380.   (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
  381.   (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
  382.   (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
  383.   (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
  384.   (define-key rmail-mode-map "\C-c\C-s\C-k" 'rmail-sort-by-keywords)
  385.   )
  386.  
  387. (define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
  388.  
  389. (define-key rmail-mode-map [menu-bar classify]
  390.   (cons "Classify" (make-sparse-keymap "Classify")))
  391.  
  392. (define-key rmail-mode-map [menu-bar classify input-menu]
  393.   '("Input Rmail file (menu)" . rmail-input-menu))
  394.  
  395. (define-key rmail-mode-map [menu-bar classify output-menu]
  396.   '("Output (Rmail menu)" . rmail-output-menu))
  397.  
  398. (define-key rmail-mode-map [menu-bar classify output-inbox]
  399.   '("Output (inbox)" . rmail-output))
  400.  
  401. (define-key rmail-mode-map [menu-bar classify output]
  402.   '("Output (Rmail)" . rmail-output-to-rmail-file))
  403.  
  404. (define-key rmail-mode-map [menu-bar classify kill-label]
  405.   '("Kill Label" . rmail-kill-label))
  406.  
  407. (define-key rmail-mode-map [menu-bar classify add-label]
  408.   '("Add Label" . rmail-add-label))
  409.  
  410. (define-key rmail-mode-map [menu-bar summary]
  411.   (cons "Summary" (make-sparse-keymap "Summary")))
  412.  
  413. (define-key rmail-mode-map [menu-bar summary labels]
  414.   '("By Labels" . rmail-summary-by-labels))
  415.  
  416. (define-key rmail-mode-map [menu-bar summary recipients]
  417.   '("By Recipients" . rmail-summary-by-recipients))
  418.  
  419. (define-key rmail-mode-map [menu-bar summary topic]
  420.   '("By Topic" . rmail-summary-by-topic))
  421.  
  422. (define-key rmail-mode-map [menu-bar summary regexp]
  423.   '("By Regexp" . rmail-summary-by-regexp))
  424.  
  425. (define-key rmail-mode-map [menu-bar summary all]
  426.   '("All" . rmail-summary))
  427.  
  428. (define-key rmail-mode-map [menu-bar mail]
  429.   (cons "Mail" (make-sparse-keymap "Mail")))
  430.  
  431. (define-key rmail-mode-map [menu-bar mail continue]
  432.   '("Continue" . rmail-continue))
  433.  
  434. (define-key rmail-mode-map [menu-bar mail forward]
  435.   '("Forward" . rmail-forward))
  436.  
  437. (define-key rmail-mode-map [menu-bar mail retry]
  438.   '("Retry" . rmail-retry-failure))
  439.  
  440. (define-key rmail-mode-map [menu-bar mail reply]
  441.   '("Reply" . rmail-reply))
  442.  
  443. (define-key rmail-mode-map [menu-bar mail mail]
  444.   '("Mail" . rmail-mail))
  445.  
  446. (define-key rmail-mode-map [menu-bar delete]
  447.   (cons "Delete" (make-sparse-keymap "Delete")))
  448.  
  449. (define-key rmail-mode-map [menu-bar delete expunge/save]
  450.   '("Expunge/Save" . rmail-expunge-and-save))
  451.  
  452. (define-key rmail-mode-map [menu-bar delete expunge]
  453.   '("Expunge" . rmail-expunge))
  454.  
  455. (define-key rmail-mode-map [menu-bar delete undelete]
  456.   '("Undelete" . rmail-undelete-previous-message))
  457.  
  458. (define-key rmail-mode-map [menu-bar delete delete]
  459.   '("Delete" . rmail-delete-forward))
  460.  
  461. (define-key rmail-mode-map [menu-bar move]
  462.   (cons "Move" (make-sparse-keymap "Move")))
  463.  
  464. (define-key rmail-mode-map [menu-bar move search-back]
  465.   '("Search Back" . rmail-search-backward))
  466.  
  467. (define-key rmail-mode-map [menu-bar move search]
  468.   '("Search" . rmail-search))
  469.  
  470. (define-key rmail-mode-map [menu-bar move previous]
  471.   '("Previous Nondeleted" . rmail-previous-undeleted-message))
  472.  
  473. (define-key rmail-mode-map [menu-bar move next]
  474.   '("Next Nondeleted" . rmail-next-undeleted-message))
  475.  
  476. (define-key rmail-mode-map [menu-bar move last]
  477.   '("Last" . rmail-last-message))
  478.  
  479. (define-key rmail-mode-map [menu-bar move first]
  480.   '("First" . rmail-first-message))
  481.  
  482. (define-key rmail-mode-map [menu-bar move previous]
  483.   '("Previous" . rmail-previous-message))
  484.  
  485. (define-key rmail-mode-map [menu-bar move next]
  486.   '("Next" . rmail-next-message))
  487.  
  488. ;; Rmail mode is suitable only for specially formatted data.
  489. (put 'rmail-mode 'mode-class 'special)
  490.  
  491. ;;;###autoload
  492. (defun rmail-mode ()
  493.   "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
  494. All normal editing commands are turned off.
  495. Instead, these commands are available:
  496.  
  497. \\[rmail-beginning-of-message]    Move point to front of this message (same as \\[beginning-of-buffer]).
  498. \\[scroll-up]    Scroll to next screen of this message.
  499. \\[scroll-down]    Scroll to previous screen of this message.
  500. \\[rmail-next-undeleted-message]    Move to Next non-deleted message.
  501. \\[rmail-previous-undeleted-message]    Move to Previous non-deleted message.
  502. \\[rmail-next-message]    Move to Next message whether deleted or not.
  503. \\[rmail-previous-message]    Move to Previous message whether deleted or not.
  504. \\[rmail-first-message]    Move to the first message in Rmail file.
  505. \\[rmail-last-message]    Move to the last message in Rmail file.
  506. \\[rmail-show-message]    Jump to message specified by numeric position in file.
  507. \\[rmail-search]    Search for string and show message it is found in.
  508. \\[rmail-delete-forward]    Delete this message, move to next nondeleted.
  509. \\[rmail-delete-backward]    Delete this message, move to previous nondeleted.
  510. \\[rmail-undelete-previous-message]    Undelete message.  Tries current message, then earlier messages
  511.     till a deleted message is found.
  512. \\[rmail-edit-current-message]    Edit the current message.  \\[rmail-cease-edit] to return to Rmail.
  513. \\[rmail-expunge]    Expunge deleted messages.
  514. \\[rmail-expunge-and-save]    Expunge and save the file.
  515. \\[rmail-quit]       Quit Rmail: expunge, save, then switch to another buffer.
  516. \\[save-buffer] Save without expunging.
  517. \\[rmail-get-new-mail]    Move new mail from system spool directory into this file.
  518. \\[rmail-mail]    Mail a message (same as \\[mail-other-window]).
  519. \\[rmail-continue]    Continue composing outgoing message started before.
  520. \\[rmail-reply]    Reply to this message.  Like \\[rmail-mail] but initializes some fields.
  521. \\[rmail-retry-failure]    Send this message again.  Used on a mailer failure message.
  522. \\[rmail-forward]    Forward this message to another user.
  523. \\[rmail-output-to-rmail-file]       Output this message to an Rmail file (append it).
  524. \\[rmail-output]    Output this message to a Unix-format mail file (append it).
  525. \\[rmail-input]    Input Rmail file.  Run Rmail on that file.
  526. \\[rmail-add-label]    Add label to message.  It will be displayed in the mode line.
  527. \\[rmail-kill-label]    Kill label.  Remove a label from current message.
  528. \\[rmail-next-labeled-message]   Move to Next message with specified label
  529.           (label defaults to last one specified).
  530.           Standard labels: filed, unseen, answered, forwarded, deleted.
  531.           Any other label is present only if you add it with \\[rmail-add-label].
  532. \\[rmail-previous-labeled-message]   Move to Previous message with specified label
  533. \\[rmail-summary]    Show headers buffer, with a one line summary of each message.
  534. \\[rmail-summary-by-labels]    Summarize only messages with particular label(s).
  535. \\[rmail-summary-by-recipients]   Summarize only messages with particular recipient(s).
  536. \\[rmail-summary-by-regexp]   Summarize only messages with particular regexp(s).
  537. \\[rmail-summary-by-topic]   Summarize only messages with subject line regexp(s).
  538. \\[rmail-toggle-header]    Toggle display of complete header."
  539.   (interactive)
  540.   (rmail-mode-2)
  541.   (rmail-set-message-counters)
  542.   (rmail-show-message rmail-total-messages))
  543.  
  544. (defun rmail-mode-2 ()
  545.   (kill-all-local-variables)
  546.   (rmail-mode-1)
  547.   (rmail-variables)
  548.   (run-hooks 'rmail-mode-hook))
  549.  
  550. (defun rmail-mode-1 ()
  551.   (setq major-mode 'rmail-mode)
  552.   (setq mode-name "RMAIL")
  553.   (setq buffer-read-only t)
  554.   ;; No need to auto save RMAIL files in normal circumstances
  555.   ;; because they contain no info except attribute changes
  556.   ;; and deletion of messages.
  557.   ;; The one exception is when messages are copied into an Rmail mode buffer.
  558.   ;; rmail-output-to-rmail-file enables auto save when you do that.
  559.   (setq buffer-auto-save-file-name nil)
  560.   (if (boundp 'mode-line-modified)
  561.       (setq mode-line-modified "--- ")
  562.     (setq mode-line-format
  563.       (cons "--- " (cdr (default-value 'mode-line-format)))))
  564.   (use-local-map rmail-mode-map)
  565.   (set-syntax-table text-mode-syntax-table)
  566.   (setq local-abbrev-table text-mode-abbrev-table))
  567.  
  568. (defun rmail-variables ()
  569.   (make-local-variable 'revert-buffer-function)
  570.   (setq revert-buffer-function 'rmail-revert)
  571.   (make-local-variable 'rmail-last-label)
  572.   (make-local-variable 'rmail-last-regexp)
  573.   (make-local-variable 'rmail-deleted-vector)
  574.   (make-local-variable 'rmail-summary-buffer)
  575.   (make-local-variable 'rmail-summary-vector)
  576.   (make-local-variable 'rmail-current-message)
  577.   (make-local-variable 'rmail-total-messages)
  578.   (make-local-variable 'require-final-newline)
  579.   (setq require-final-newline nil)
  580.   (make-local-variable 'rmail-overlay-list)
  581.   (setq rmail-overlay-list nil)
  582.   (make-local-variable 'version-control)
  583.   (setq version-control 'never)
  584.   (make-local-variable 'file-precious-flag)
  585.   (setq file-precious-flag t)
  586.   (make-local-variable 'rmail-message-vector)
  587.   (make-local-variable 'rmail-inbox-list)
  588.   (setq rmail-inbox-list (rmail-parse-file-inboxes))
  589.   ;; Provide default set of inboxes for primary mail file ~/RMAIL.
  590.   (and (null rmail-inbox-list)
  591.        (or (equal buffer-file-name (expand-file-name rmail-file-name))
  592.        (equal buffer-file-truename
  593.           (abbreviate-file-name (file-truename rmail-file-name))))
  594.        (setq rmail-inbox-list
  595.          (or rmail-primary-inbox-list
  596.          (list (or (getenv "MAIL")
  597.                (concat rmail-spool-directory
  598.                    (user-login-name)))))))
  599.   (make-local-variable 'rmail-keywords)
  600.   ;; this gets generated as needed
  601.   (setq rmail-keywords nil))
  602.  
  603. ;; Handle M-x revert-buffer done in an rmail-mode buffer.
  604. (defun rmail-revert (arg noconfirm)
  605.   (let (revert-buffer-function)
  606.     ;; Call our caller again, but this time it does the default thing.
  607.     (if (revert-buffer arg noconfirm)
  608.     ;; If the user said "yes", and we changed something,
  609.     ;; reparse the messages.
  610.     (progn
  611.       (rmail-convert-file)
  612.       (goto-char (point-max))
  613.       (rmail-set-message-counters)
  614.       (rmail-show-message)))))
  615.  
  616. ;; Return a list of files from this buffer's Mail: option.
  617. ;; Does not assume that messages have been parsed.
  618. ;; Just returns nil if buffer does not look like Babyl format.
  619. (defun rmail-parse-file-inboxes ()
  620.   (save-excursion
  621.     (save-restriction
  622.       (widen)
  623.       (goto-char 1)
  624.       (cond ((looking-at "BABYL OPTIONS:")
  625.          (search-forward "\n\^_" nil 'move)
  626.          (narrow-to-region 1 (point))
  627.          (goto-char 1)
  628.          (if (search-forward "\nMail:" nil t)
  629.          (progn
  630.            (narrow-to-region (point) (progn (end-of-line) (point)))
  631.            (goto-char (point-min))
  632.            (mail-parse-comma-list))))))))
  633.  
  634. (defun rmail-expunge-and-save ()
  635.   "Expunge and save RMAIL file."
  636.   (interactive)
  637.   (rmail-expunge)
  638.   (save-buffer)
  639.   (if (rmail-summary-exists)
  640.       (rmail-select-summary (set-buffer-modified-p nil))))
  641.  
  642. (defun rmail-quit ()
  643.   "Quit out of RMAIL."
  644.   (interactive)
  645.   (rmail-expunge-and-save)
  646.   ;; Don't switch to the summary buffer even if it was recently visible.
  647.   (if rmail-summary-buffer
  648.       (progn
  649.     (replace-buffer-in-windows rmail-summary-buffer)
  650.     (bury-buffer rmail-summary-buffer)))
  651.   (let ((obuf (current-buffer)))
  652.     (replace-buffer-in-windows obuf)
  653.     (bury-buffer obuf)))
  654.  
  655. ;;;###autoload
  656. (defun rmail-input (filename)
  657.   "Run Rmail on file FILENAME."
  658.   (interactive "FRun rmail on RMAIL file: ")
  659.   (rmail filename))
  660.  
  661. ;; Choose a .xmail file in dir rmail-secondary-file-directory.
  662. (defun rmail-secondary-file-menu (event)
  663.   (let ((files (directory-files rmail-secondary-file-directory nil
  664.                 rmail-secondary-file-regexp)))
  665.     (if files
  666.     (let* ((menu (list "Rmail Files"
  667.                (cons "Rmail Files"
  668.                  (mapcar (function (lambda (f) (cons f f)))
  669.                      files))))
  670.            (chosen (x-popup-menu event menu)))
  671.       (if chosen
  672.           (expand-file-name chosen rmail-secondary-file-directory)))
  673.       (message "No files matching %s%s found"
  674.            rmail-secondary-file-directory rmail-secondary-file-regexp)
  675.       nil)))
  676.  
  677.  
  678. (defun rmail-input-menu (event)
  679.   "Choose a new Rmail file to edit, with a menu.
  680. The variables `rmail-secondary-file-directory' and
  681. `rmail-secondary-file-regexp' control which files are offered in the menu."
  682.   (interactive "e")
  683.   (let ((file-name (rmail-secondary-file-menu event)))
  684.     (if file-name
  685.     (rmail-input file-name))))
  686.  
  687. ;;;; *** Rmail input ***
  688.  
  689. ;; RLK feature not added in this version:
  690. ;; argument specifies inbox file or files in various ways.
  691.  
  692. (defun rmail-get-new-mail (&optional file-name)
  693.   "Move any new mail from this RMAIL file's inbox files.
  694. The inbox files can be specified with the file's Mail: option.  The
  695. variable `rmail-primary-inbox-list' specifies the inboxes for your
  696. primary RMAIL file if it has no Mail: option.  By default, this is
  697. your /usr/spool/mail/$USER.
  698.  
  699. You can also specify the file to get new mail from.  In this case, the
  700. file of new mail is not changed or deleted.  Noninteractively, you can
  701. pass the inbox file name as an argument.  Interactively, a prefix
  702. argument causes us to read a file name and use that file as the inbox."
  703.   (interactive
  704.    (list (if current-prefix-arg
  705.          (read-file-name "Get new mail from file: "))))
  706.   (or (verify-visited-file-modtime (current-buffer))
  707.       (progn
  708.     (find-file (buffer-file-name))
  709.     (setq buffer-read-only t)
  710.     (if (verify-visited-file-modtime (current-buffer))
  711.         (rmail-forget-messages))))
  712.   (rmail-maybe-set-message-counters)
  713.   (widen)
  714.   ;; Get rid of all undo records for this buffer.
  715.   (or (eq buffer-undo-list t)
  716.       (setq buffer-undo-list nil))
  717.   (unwind-protect
  718.       (let ((opoint (point))
  719.         (new-messages 0)
  720.         (delete-files ())
  721.         ;; If buffer has not changed yet, and has not been saved yet,
  722.         ;; don't replace the old backup file now.
  723.         (make-backup-files (and make-backup-files (buffer-modified-p)))
  724.         (buffer-read-only nil)
  725.         ;; Don't make undo records for what we do in getting mail.
  726.         (buffer-undo-list t))
  727.     (goto-char (point-max))
  728.     (skip-chars-backward " \t\n")        ; just in case of brain damage
  729.     (delete-region (point) (point-max)) ; caused by require-final-newline
  730.     (save-excursion
  731.       (save-restriction
  732.         (narrow-to-region (point) (point))
  733.         ;; Read in the contents of the inbox files,
  734.         ;; renaming them as necessary,
  735.         ;; and adding to the list of files to delete eventually.
  736.         (if file-name
  737.         (rmail-insert-inbox-text (list file-name) nil)
  738.           (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
  739.         ;; Scan the new text and convert each message to babyl format.
  740.         (goto-char (point-min))
  741.         (save-excursion
  742.           (setq new-messages (rmail-convert-to-babyl-format)))
  743.         (or (zerop new-messages)
  744.         (let (success)
  745.           (widen)
  746.           (search-backward "\n\^_" nil t)
  747.           (narrow-to-region (point) (point-max))
  748.           (goto-char (1+ (point-min)))
  749.           (rmail-count-new-messages)
  750.           (save-buffer)))
  751.         ;; Delete the old files, now that babyl file is saved.
  752.         (while delete-files
  753.           (condition-case ()
  754.           ;; First, try deleting.
  755.           (condition-case ()
  756.               (delete-file (car delete-files))
  757.             (file-error
  758.              ;; If we can't delete it, truncate it.
  759.              (write-region (point) (point) (car delete-files))))
  760.         (file-error nil))
  761.           (setq delete-files (cdr delete-files)))))
  762.     (if (= new-messages 0)
  763.         (progn (goto-char opoint)
  764.            (if (or file-name rmail-inbox-list)
  765.                (message "(No new mail has arrived)")))
  766.       (if (rmail-summary-exists)
  767.           (rmail-select-summary
  768.         (rmail-update-summary)))
  769.       (message "%d new message%s read"
  770.            new-messages (if (= 1 new-messages) "" "s"))
  771.       (and (boundp 'display-time-string)
  772.            (stringp display-time-string)
  773.            (string-match " Mail" display-time-string)
  774.            (setq display-time-string
  775.              (concat
  776.               (substring display-time-string 0 (match-beginning 0))
  777.               (substring display-time-string (match-end 0))))
  778.            (force-mode-line-update 'all))))
  779.     ;; Don't leave the buffer screwed up if we get a disk-full error.
  780.     (rmail-show-message)))
  781.  
  782. (defun rmail-insert-inbox-text (files renamep)
  783.   (let (file tofile delete-files movemail popmail)
  784.     (while files
  785.       (setq file (file-truename
  786.           (expand-file-name (substitute-in-file-name (car files))))
  787.         ;;>> un*x specific <<
  788.         ;; The "+" used to be "~", which is an extremely poor choice;
  789.         ;; it might accidentally be deleted when space is low
  790.         ;; (as happened to me!).
  791.         tofile (concat file "+"))
  792.       ;; If getting from mail spool directory,
  793.       ;; use movemail to move rather than just renaming,
  794.       ;; so as to interlock with the mailer.
  795.       (setq movemail (string= (file-name-directory file)
  796.                   (file-truename rmail-spool-directory))
  797.         popmail (string-match "^po:" (file-name-nondirectory file)))
  798.       (if popmail (setq file (file-name-nondirectory file)
  799.             renamep t))
  800.       (if movemail
  801.       (progn
  802.         (setq tofile (expand-file-name
  803.                ;; Generate name to move to from inbox name,
  804.                ;; in case of multiple inboxes that need moving.
  805.                (concat ".newmail-" (file-name-nondirectory file))
  806.                ;; Use the directory of this rmail file
  807.                ;; because it's a nuisance to use the homedir
  808.                ;; if that is on a full disk and this rmail
  809.                ;; file isn't.
  810.                (file-name-directory
  811.                  (expand-file-name buffer-file-name))))
  812.         ;; On some systems, /usr/spool/mail/foo is a directory
  813.         ;; and the actual inbox is /usr/spool/mail/foo/foo.
  814.         (if (file-directory-p file)
  815.         (setq file (expand-file-name (user-login-name)
  816.                          file)))))
  817.       (if popmail
  818.       (message "Getting mail from post office ...")
  819.     (if (or (and (file-exists-p tofile)
  820.              (/= 0 (nth 7 (file-attributes tofile))))
  821.         (and (file-exists-p file)
  822.              (/= 0 (nth 7 (file-attributes file)))))
  823.         (message "Getting mail from %s..." file)))
  824.       ;; Set TOFILE if have not already done so, and
  825.       ;; rename or copy the file FILE to TOFILE if and as appropriate.
  826.       (cond ((not renamep)
  827.          (setq tofile file))
  828.         ((or (file-exists-p tofile) (and (not popmail)
  829.                          (not (file-exists-p file))))
  830.          nil)
  831.         ((and (not movemail) (not popmail))
  832.          ;; Try copying.  If that fails (perhaps no space),
  833.          ;; rename instead.
  834.          (condition-case nil
  835.          (copy-file file tofile nil)
  836.            (error
  837.         ;; Third arg is t so we can replace existing file TOFILE.
  838.         (rename-file file tofile t)))
  839.          ;; Make the real inbox file empty.
  840.          ;; Leaving it deleted could cause lossage
  841.          ;; because mailers often won't create the file.
  842.          (condition-case ()
  843.          (write-region (point) (point) file)
  844.            (file-error nil)))
  845.         (t
  846.          (let ((errors nil))
  847.            (unwind-protect
  848.            (save-excursion
  849.              (setq errors (generate-new-buffer " *rmail loss*"))
  850.              (buffer-disable-undo errors)
  851.              (call-process
  852.                (expand-file-name "movemail" exec-directory)
  853.                nil errors nil file tofile)
  854.              (if (not (buffer-modified-p errors))
  855.              ;; No output => movemail won
  856.              nil
  857.                (set-buffer errors)
  858.                (subst-char-in-region (point-min) (point-max)
  859.                          ?\n ?\  )
  860.                (goto-char (point-max))
  861.                (skip-chars-backward " \t")
  862.                (delete-region (point) (point-max))
  863.                (goto-char (point-min))
  864.                (if (looking-at "movemail: ")
  865.                (delete-region (point-min) (match-end 0)))
  866.                (beep t)
  867.                (message (concat "movemail: "
  868.                     (buffer-substring (point-min)
  869.                               (point-max))))
  870.                (sit-for 3)
  871.                nil))
  872.          (if errors (kill-buffer errors))))))
  873.       ;; At this point, TOFILE contains the name to read:
  874.       ;; Either the alternate name (if we renamed)
  875.       ;; or the actual inbox (if not renaming).
  876.       (if (file-exists-p tofile)
  877.       (let (size)
  878.         (goto-char (point-max))
  879.         (setq size (nth 1 (insert-file-contents tofile)))
  880.         (goto-char (point-max))
  881.         (or (= (preceding-char) ?\n)
  882.         (zerop size)
  883.         (insert ?\n))
  884.         (setq delete-files (cons tofile delete-files))))
  885.       (message "")
  886.       (setq files (cdr files)))
  887.     delete-files))
  888.  
  889. ;; the  rmail-break-forwarded-messages  feature is not implemented
  890. (defun rmail-convert-to-babyl-format ()
  891.   (let ((count 0) start
  892.     (case-fold-search nil)
  893.     (invalid-input-resync
  894.      (function (lambda ()
  895.              (message "Invalid Babyl format in inbox!")
  896.              (sit-for 1)
  897.              ;; Try to get back in sync with a real message.
  898.              (if (re-search-forward
  899.               (concat mmdf-delim1 "\\|^From") nil t)
  900.              (beginning-of-line)
  901.                (goto-char (point-max)))))))
  902.     (goto-char (point-min))
  903.     (save-restriction
  904.       (while (not (eobp))
  905.     (cond ((looking-at "BABYL OPTIONS:");Babyl header
  906.            (if (search-forward "\n\^_" nil t)
  907.            ;; If we find the proper terminator, delete through there.
  908.            (delete-region (point-min) (point))
  909.          (funcall invalid-input-resync)
  910.          (delete-region (point-min) (point))))
  911.           ;; Babyl format message
  912.           ((looking-at "\^L")
  913.            (or (search-forward "\n\^_" nil t)
  914.            (funcall invalid-input-resync))
  915.            (setq count (1+ count))
  916.            ;; Make sure there is no extra white space after the ^_
  917.            ;; at the end of the message.
  918.            ;; Narrowing will make sure that whatever follows the junk
  919.            ;; will be treated properly.
  920.            (delete-region (point)
  921.                   (save-excursion
  922.                 (skip-chars-forward " \t\n")
  923.                 (point)))
  924.            (narrow-to-region (point) (point-max)))
  925.           ;;*** MMDF format
  926.           ((let ((case-fold-search t))
  927.          (looking-at mmdf-delim1))
  928.            (let ((case-fold-search t))
  929.          (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
  930.          (setq start (point))
  931.          (re-search-forward mmdf-delim2 nil t)
  932.          (replace-match "\^_"))
  933.            (save-excursion
  934.          (save-restriction
  935.            (narrow-to-region start (1- (point)))
  936.            (goto-char (point-min))
  937.            (while (search-forward "\n\^_" nil t); single char "\^_"
  938.              (replace-match "\n^_")))); 2 chars: "^" and "_"
  939.            (narrow-to-region (point) (point-max))
  940.            (setq count (1+ count)))
  941.           ;;*** Mail format
  942.           ((looking-at "^From ")
  943.            (setq start (point))
  944.            (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
  945.            (rmail-nuke-pinhead-header)
  946.            ;; If this message has a Content-Length field,
  947.            ;; skip to the end of the contents.
  948.            (let* ((header-end (save-excursion
  949.                     (and (re-search-forward "\n\n" nil t)
  950.                      (1- (point)))))
  951.               (case-fold-search t)
  952.               (size
  953.                ;; Get the numeric value from the Content-Length field.
  954.                (save-excursion
  955.              ;; Back up to end of prev line,
  956.              ;; in case the Content-Length field comes first.
  957.              (forward-char -1)
  958.              (and (search-forward "\ncontent-length: "
  959.                           header-end t)
  960.                   (let ((beg (point))
  961.                     (eol (progn (end-of-line) (point))))
  962.                 (string-to-int (buffer-substring beg eol)))))))
  963.          (and size
  964.               (if (and (natnump size)
  965.                    (<= (+ header-end size) (point-max))
  966.                    ;; Make sure this would put us at a position
  967.                    ;; that we could continue from.
  968.                    (save-excursion
  969.                  (goto-char (+ header-end size))
  970.                  (skip-chars-forward "\n")
  971.                  (or (eobp)
  972.                      (and (looking-at "BABYL OPTIONS:")
  973.                       (search-forward "\n\^_" nil t))
  974.                      (and (looking-at "\^L")
  975.                       (search-forward "\n\^_" nil t))
  976.                      (let ((case-fold-search t))
  977.                        (looking-at mmdf-delim1))
  978.                      (looking-at "From "))))
  979.               (goto-char (+ header-end size))
  980.             (message "Ignoring invalid Content-Length field")
  981.             (sit-for 1 0 t))))
  982.  
  983.            (if (re-search-forward
  984.             (concat "^[\^_]?\\("
  985.                 rmail-unix-mail-delimiter
  986.                 "\\|"
  987.                 mmdf-delim1 "\\|"
  988.                 "^BABYL OPTIONS:\\|"
  989.                 "\^L\n[01],\\)") nil t)
  990.            (goto-char (match-beginning 1))
  991.          (goto-char (point-max)))
  992.            (setq count (1+ count))
  993.            (save-excursion
  994.          (save-restriction
  995.            (narrow-to-region start (point))
  996.            (goto-char (point-min))
  997.            (while (search-forward "\n\^_" nil t); single char
  998.              (replace-match "\n^_")))); 2 chars: "^" and "_"
  999.            (insert ?\^_)
  1000.            (narrow-to-region (point) (point-max)))
  1001.           ;;
  1002.           ;; This kludge is because some versions of sendmail.el
  1003.           ;; insert an extra newline at the beginning that shouldn't
  1004.           ;; be there.  sendmail.el has been fixed, but old versions
  1005.           ;; may still be in use.  -- rms, 7 May 1993.
  1006.           ((eolp) (delete-char 1))
  1007.           (t (error "Cannot convert to babyl format")))))
  1008.     count))
  1009.  
  1010. ;; Delete the "From ..." line, creating various other headers with
  1011. ;; information from it if they don't already exist.  Now puts the
  1012. ;; original line into a mail-from: header line for debugging and for
  1013. ;; use by the rmail-output function.
  1014. (defun rmail-nuke-pinhead-header ()
  1015.   (save-excursion
  1016.     (save-restriction
  1017.       (let ((start (point))
  1018.           (end (progn
  1019.            (condition-case ()
  1020.                (search-forward "\n\n")
  1021.              (error
  1022.               (goto-char (point-max))
  1023.               (insert "\n\n")))
  1024.            (point)))
  1025.         has-from has-date)
  1026.     (narrow-to-region start end)
  1027.     (let ((case-fold-search t))
  1028.       (goto-char start)
  1029.       (setq has-from (search-forward "\nFrom:" nil t))
  1030.       (goto-char start)
  1031.       (setq has-date (and (search-forward "\nDate:" nil t) (point)))
  1032.       (goto-char start))
  1033.     (let ((case-fold-search nil))
  1034.       (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
  1035.           (replace-match
  1036.         (concat
  1037.           "Mail-from: \\&"
  1038.           ;; Keep and reformat the date if we don't
  1039.           ;;  have a Date: field.
  1040.           (if has-date
  1041.               ""
  1042.             (concat
  1043.              "Date: \\3, \\5 \\4 \\9 \\6 "
  1044.             
  1045.              ;; The timezone could be matched by group 7 or group 10.
  1046.              ;; If neither of them matched, assume EST, since only
  1047.              ;; Easterners would be so sloppy.
  1048.              ;; It's a shame the substitution can't use "\\10".
  1049.              (cond
  1050.               ((/= (match-beginning 7) (match-end 7)) "\\7")
  1051.               ((/= (match-beginning 10) (match-end 10))
  1052.                (buffer-substring (match-beginning 10)
  1053.                      (match-end 10)))
  1054.               (t "EST"))
  1055.              "\n"))
  1056.           ;; Keep and reformat the sender if we don't
  1057.           ;; have a From: field.
  1058.           (if has-from
  1059.               ""
  1060.             "From: \\1\n"))
  1061.         t)))))))
  1062.  
  1063. ;;;; *** Rmail Message Formatting and Header Manipulation ***
  1064.  
  1065. (defun rmail-reformat-message (beg end)
  1066.   (goto-char beg)
  1067.   (forward-line 1)
  1068.   (if (/= (following-char) ?0)
  1069.       (error "Bad format in RMAIL file."))
  1070.   (let ((buffer-read-only nil)
  1071.     (delta (- (buffer-size) end)))
  1072.     (delete-char 1)
  1073.     (insert ?1)
  1074.     (forward-line 1)
  1075.     (let ((case-fold-search t))
  1076.       (while (looking-at "Summary-line:\\|Mail-From:")
  1077.      (forward-line 1)))
  1078.     (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
  1079.     (delete-region (point)
  1080.                (progn (forward-line 1) (point))))
  1081.     (let ((str (buffer-substring (point)
  1082.                  (save-excursion (search-forward "\n\n" end 'move)
  1083.                          (point)))))
  1084.       (insert str "*** EOOH ***\n")
  1085.       (narrow-to-region (point) (- (buffer-size) delta)))
  1086.     (goto-char (point-min))
  1087.     (if rmail-ignored-headers (rmail-clear-headers))
  1088.     (if rmail-message-filter (funcall rmail-message-filter))))
  1089.  
  1090. (defun rmail-clear-headers ()
  1091.   (if (search-forward "\n\n" nil t)
  1092.       (save-restriction
  1093.         (narrow-to-region (point-min) (point))
  1094.     (let ((buffer-read-only nil))
  1095.       (while (let ((case-fold-search t))
  1096.            (goto-char (point-min))
  1097.            (re-search-forward rmail-ignored-headers nil t))
  1098.         (beginning-of-line)
  1099.         (delete-region (point)
  1100.                (progn (re-search-forward "\n[^ \t]")
  1101.                   (forward-char -1)
  1102.                   (point))))))))
  1103.  
  1104. (defun rmail-toggle-header ()
  1105.   "Show original message header if pruned header currently shown, or vice versa."
  1106.   (interactive)
  1107.   (rmail-maybe-set-message-counters)
  1108.   (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
  1109.   (let ((buffer-read-only nil))
  1110.     (goto-char (point-min))
  1111.     (forward-line 1)
  1112.     (if (= (following-char) ?1)
  1113.     (progn (delete-char 1)
  1114.            (insert ?0)
  1115.            (forward-line 1)
  1116.            (let ((case-fold-search t))
  1117.           (while (looking-at "Summary-Line:\\|Mail-From:")
  1118.             (forward-line 1)))
  1119.            (insert "*** EOOH ***\n")
  1120.            (forward-char -1)
  1121.            (search-forward "\n*** EOOH ***\n")
  1122.            (forward-line -1)
  1123.            (let ((temp (point)))
  1124.          (and (search-forward "\n\n" nil t)
  1125.               (delete-region temp (point))))
  1126.            (goto-char (point-min))
  1127.            (search-forward "\n*** EOOH ***\n")
  1128.            (narrow-to-region (point) (point-max)))
  1129.       (rmail-reformat-message (point-min) (point-max))))
  1130.   (rmail-highlight-headers))
  1131.  
  1132. ;;;; *** Rmail Attributes and Keywords ***
  1133.  
  1134. ;; Make a string describing current message's attributes and keywords
  1135. ;; and set it up as the name of a minor mode
  1136. ;; so it will appear in the mode line.
  1137. (defun rmail-display-labels ()
  1138.   (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
  1139.     (save-excursion
  1140.       (unwind-protect
  1141.       (progn
  1142.         (widen)
  1143.         (goto-char (rmail-msgbeg rmail-current-message))
  1144.         (forward-line 1)
  1145.         (if (looking-at "[01],")
  1146.         (progn
  1147.           (narrow-to-region (point) (progn (end-of-line) (point)))
  1148.           ;; Truly valid BABYL format requires a space before each
  1149.           ;; attribute or keyword name.  Put them in if missing.
  1150.           (let (buffer-read-only)
  1151.             (goto-char (point-min))
  1152.             (while (search-forward "," nil t)
  1153.               (or (looking-at "[ ,]") (eobp)
  1154.               (insert " "))))
  1155.           (goto-char (point-max))
  1156.           (if (search-backward ",," nil 'move)
  1157.               (progn
  1158.             (if (> (point) (1+ (point-min)))
  1159.                 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
  1160.             (if (> (- (point-max) (point)) 2)
  1161.                 (setq blurb
  1162.                   (concat blurb
  1163.                       ";"
  1164.                       (buffer-substring (+ (point) 3)
  1165.                                 (1- (point-max)))))))))))
  1166.     ;; Note: we don't use save-restriction because that does not work right
  1167.     ;; if changes are made outside the saved restriction
  1168.     ;; before that restriction is restored.
  1169.     (narrow-to-region beg end)
  1170.     (set-marker beg nil)
  1171.     (set-marker end nil)))
  1172.     (while (string-match " +," blurb)
  1173.       (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
  1174.               (substring blurb (match-end 0)))))
  1175.     (while (string-match ", +" blurb)
  1176.       (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
  1177.               (substring blurb (match-end 0)))))
  1178.     (setq mode-line-process
  1179.       (concat " " rmail-current-message "/" rmail-total-messages
  1180.           blurb))))
  1181.  
  1182. ;; Turn an attribute of a message on or off according to STATE.
  1183. ;; ATTR is the name of the attribute, as a string.
  1184. ;; MSGNUM is message number to change; nil means current message.
  1185. (defun rmail-set-attribute (attr state &optional msgnum)
  1186.   (let ((omax (point-max-marker))
  1187.     (omin (point-min-marker))
  1188.     (buffer-read-only nil))
  1189.     (or msgnum (setq msgnum rmail-current-message))
  1190.     (if (> msgnum 0)
  1191.     (unwind-protect
  1192.         (save-excursion
  1193.           (widen)
  1194.           (goto-char (+ 3 (rmail-msgbeg msgnum)))
  1195.           (let ((curstate
  1196.              (not
  1197.               (null (search-backward (concat ", " attr ",")
  1198.                          (prog1 (point) (end-of-line)) t)))))
  1199.         (or (eq curstate (not (not state)))
  1200.             (if curstate
  1201.             (delete-region (point) (1- (match-end 0)))
  1202.               (beginning-of-line)
  1203.               (forward-char 2)
  1204.               (insert " " attr ","))))
  1205.           (if (string= attr "deleted")
  1206.           (rmail-set-message-deleted-p msgnum state)))
  1207.       ;; Note: we don't use save-restriction because that does not work right
  1208.       ;; if changes are made outside the saved restriction
  1209.       ;; before that restriction is restored.
  1210.       (narrow-to-region omin omax)
  1211.       (set-marker omin nil)
  1212.       (set-marker omax nil)
  1213.       (if (= msgnum rmail-current-message)
  1214.           (rmail-display-labels))))))
  1215.  
  1216. ;; Return t if the attributes/keywords line of msg number MSG
  1217. ;; contains a match for the regexp LABELS.
  1218. (defun rmail-message-labels-p (msg labels)
  1219.   (save-excursion
  1220.     (save-restriction
  1221.       (widen)
  1222.       (goto-char (rmail-msgbeg msg))
  1223.       (forward-char 3)
  1224.       (re-search-backward labels (prog1 (point) (end-of-line)) t))))
  1225.  
  1226. ;;;; *** Rmail Message Selection And Support ***
  1227.  
  1228. (defun rmail-msgend (n)
  1229.   (marker-position (aref rmail-message-vector (1+ n))))
  1230.  
  1231. (defun rmail-msgbeg (n)
  1232.   (marker-position (aref rmail-message-vector n)))
  1233.  
  1234. (defun rmail-widen-to-current-msgbeg (function)
  1235.   "Call FUNCTION with point at start of internal data of current message.
  1236. Assumes that bounds were previously narrowed to display the message in Rmail.
  1237. The bounds are widened enough to move point where desired, then narrowed
  1238. again afterward.
  1239.  
  1240. FUNCTION may not change the visible text of the message, but it may
  1241. change the invisible header text."
  1242.   (save-excursion
  1243.     (let ((obeg (- (point-max) (point-min))))
  1244.       (unwind-protect
  1245.       (progn
  1246.         (narrow-to-region (rmail-msgbeg rmail-current-message)
  1247.                   (point-max))
  1248.         (goto-char (point-min))
  1249.         (funcall function))
  1250.     ;; Note: we don't use save-restriction because that does not work right
  1251.     ;; if changes are made outside the saved restriction
  1252.     ;; before that restriction is restored.
  1253.     ;; Here we assume that changes made by FUNCTION
  1254.     ;; occur before the visible region of the message.
  1255.     (narrow-to-region (- (point-max) obeg) (point-max))))))
  1256.  
  1257. (defun rmail-forget-messages ()
  1258.   (unwind-protect
  1259.       (if (vectorp rmail-message-vector)
  1260.       (let* ((i 0)
  1261.          (v rmail-message-vector)
  1262.          (n (length v)))
  1263.         (while (< i n)
  1264.           (move-marker (aref v i)  nil)
  1265.           (setq i (1+ i)))))
  1266.     (setq rmail-message-vector nil)
  1267.     (setq rmail-deleted-vector nil)))
  1268.  
  1269. (defun rmail-maybe-set-message-counters ()
  1270.   (if (not (and rmail-deleted-vector
  1271.         rmail-message-vector
  1272.         rmail-current-message
  1273.         rmail-total-messages))
  1274.       (rmail-set-message-counters)))
  1275.  
  1276. (defun rmail-count-new-messages (&optional nomsg)
  1277.   (let* ((case-fold-search nil)
  1278.      (total-messages 0)
  1279.      (messages-head nil)
  1280.      (deleted-head nil))
  1281.     (or nomsg (message "Counting new messages..."))
  1282.     (goto-char (point-max))
  1283.     ;; Put at the end of messages-head
  1284.     ;; the entry for message N+1, which marks
  1285.     ;; the end of message N.  (N = number of messages).
  1286.     (search-backward "\n\^_")
  1287.     (forward-char 1)
  1288.     (setq messages-head (list (point-marker)))
  1289.     (rmail-set-message-counters-counter (point-min))
  1290.     (setq rmail-current-message (1+ rmail-total-messages))
  1291.     (setq rmail-total-messages
  1292.       (+ rmail-total-messages total-messages))
  1293.     (setq rmail-message-vector
  1294.       (vconcat rmail-message-vector (cdr messages-head)))
  1295.     (aset rmail-message-vector
  1296.       rmail-current-message (car messages-head))
  1297.     (setq rmail-deleted-vector
  1298.       (concat rmail-deleted-vector deleted-head))
  1299.     (setq rmail-summary-vector
  1300.       (vconcat rmail-summary-vector (make-vector total-messages nil)))
  1301.     (goto-char (point-min))
  1302.     (or nomsg (message "Counting new messages...done (%d)" total-messages))))
  1303.  
  1304. (defun rmail-set-message-counters ()
  1305.   (rmail-forget-messages)
  1306.   (save-excursion
  1307.     (save-restriction
  1308.       (widen)
  1309.       (let* ((point-save (point))
  1310.          (total-messages 0)
  1311.          (messages-after-point)
  1312.          (case-fold-search nil)
  1313.          (messages-head nil)
  1314.          (deleted-head nil))
  1315.     (message "Counting messages...")
  1316.     (goto-char (point-max))
  1317.     ;; Put at the end of messages-head
  1318.     ;; the entry for message N+1, which marks
  1319.     ;; the end of message N.  (N = number of messages).
  1320.     (search-backward "\n\^_" nil t)
  1321.     (if (/= (point) (point-max)) (forward-char 1))
  1322.     (setq messages-head (list (point-marker)))
  1323.     (rmail-set-message-counters-counter (min (point) point-save))
  1324.     (setq messages-after-point total-messages)
  1325.     (rmail-set-message-counters-counter)
  1326.     (setq rmail-total-messages total-messages)
  1327.     (setq rmail-current-message
  1328.           (min total-messages
  1329.            (max 1 (- total-messages messages-after-point))))
  1330.     (setq rmail-message-vector
  1331.           (apply 'vector (cons (point-min-marker) messages-head))
  1332.           rmail-deleted-vector (concat "D" deleted-head)
  1333.           rmail-summary-vector (make-vector rmail-total-messages nil))
  1334.     (message "Counting messages...done")))))
  1335.     
  1336. (defun rmail-set-message-counters-counter (&optional stop)
  1337.   (while (search-backward "\n\^_\^L\n" stop t)
  1338.     (forward-char 1)
  1339.     (setq messages-head (cons (point-marker) messages-head))
  1340.     (save-excursion
  1341.       (setq deleted-head
  1342.         (cons (if (search-backward ", deleted,"
  1343.                        (prog1 (point)
  1344.                      (forward-line 2))
  1345.                        t)
  1346.               ?D ?\ )
  1347.           deleted-head)))
  1348.     (if (zerop (% (setq total-messages (1+ total-messages)) 20))
  1349.     (message "Counting messages...%d" total-messages))))
  1350.  
  1351. (defun rmail-beginning-of-message ()
  1352.   "Show current message starting from the beginning."
  1353.   (interactive)
  1354.   (rmail-show-message rmail-current-message))
  1355.  
  1356. (defun rmail-show-message (&optional n)
  1357.   "Show message number N (prefix argument), counting from start of file.
  1358. If summary buffer is currently displayed, update current message there also."
  1359.   (interactive "p")
  1360.   (rmail-maybe-set-message-counters)
  1361.   (widen)
  1362.   (if (zerop rmail-total-messages)
  1363.       (progn (narrow-to-region (point-min) (1- (point-max)))
  1364.          (goto-char (point-min))
  1365.          (setq mode-line-process nil))
  1366.     (let (blurb)
  1367.       (if (not n)
  1368.       (setq n rmail-current-message)
  1369.     (cond ((<= n 0)
  1370.            (setq n 1
  1371.              rmail-current-message 1
  1372.              blurb "No previous message"))
  1373.           ((> n rmail-total-messages)
  1374.            (setq n rmail-total-messages
  1375.              rmail-current-message rmail-total-messages
  1376.              blurb "No following message"))
  1377.           (t
  1378.            (setq rmail-current-message n))))
  1379.       (let ((beg (rmail-msgbeg n))
  1380.         (end (rmail-msgend n)))
  1381.     (goto-char beg)
  1382.     (forward-line 1)
  1383.     (if (= (following-char) ?0)
  1384.         (progn
  1385.           (rmail-reformat-message beg end)
  1386.           (rmail-set-attribute "unseen" nil))
  1387.       (search-forward "\n*** EOOH ***\n" end t)
  1388.       (narrow-to-region (point) end))
  1389.     (goto-char (point-min))
  1390.     (rmail-display-labels)
  1391.     (rmail-highlight-headers)
  1392.     (if transient-mark-mode (deactivate-mark))
  1393.     (run-hooks 'rmail-show-message-hook)
  1394.     ;; If there is a summary buffer, try to move to this message
  1395.     ;; in that buffer.  But don't complain if this message
  1396.     ;; is not mentioned in the summary.
  1397.     (if (rmail-summary-exists)
  1398.         (let ((curr-msg rmail-current-message))
  1399.           (rmail-select-summary
  1400.            (rmail-summary-goto-msg curr-msg t t))))
  1401.     (if blurb
  1402.         (message blurb))))))
  1403.  
  1404. ;; Find all occurrences of certain fields, and highlight them.
  1405. (defun rmail-highlight-headers ()
  1406.   ;; Do this only if the system supports faces.
  1407.   (if (fboundp 'internal-find-face)
  1408.       (save-excursion
  1409.     (search-forward "\n\n" nil 'move)
  1410.     (save-restriction
  1411.       (narrow-to-region (point-min) (point))
  1412.       (let ((case-fold-search t)
  1413.         (inhibit-read-only t)
  1414.         ;; Highlight with boldface if that is available.
  1415.         ;; Otherwise use the `highlight' face.
  1416.         (face (if (face-differs-from-default-p 'bold)
  1417.               'bold 'highlight))
  1418.         ;; List of overlays to reuse.
  1419.         (overlays rmail-overlay-list))
  1420.         (goto-char (point-min))
  1421.         (while (re-search-forward rmail-highlighted-headers nil t)
  1422.           (skip-syntax-forward " ")
  1423.           (let ((beg (point))
  1424.             overlay)
  1425.         (while (progn (forward-line 1)
  1426.                   (looking-at "[ \t]")))
  1427.         ;; Back up over newline, then trailing spaces or tabs
  1428.         (forward-char -1)
  1429.         (while (member (preceding-char) '(?  ?\t))
  1430.           (forward-char -1))
  1431.         (if overlays
  1432.             ;; Reuse an overlay we already have.
  1433.             (progn
  1434.               (setq overlay (car overlays)
  1435.                 overlays (cdr overlays))
  1436.               (overlay-put overlay 'face face)
  1437.               (move-overlay overlay beg (point)))
  1438.           ;; Make a new overlay and add it to
  1439.           ;; rmail-overlay-list.
  1440.           (setq overlay (make-overlay beg (point)))
  1441.           (overlay-put overlay 'face face)
  1442.           (setq rmail-overlay-list
  1443.             (cons overlay rmail-overlay-list))))))))))
  1444.  
  1445. (defun rmail-next-message (n)
  1446.   "Show following message whether deleted or not.
  1447. With prefix arg N, moves forward N messages, or backward if N is negative."
  1448.   (interactive "p")
  1449.   (rmail-maybe-set-message-counters)
  1450.   (rmail-show-message (+ rmail-current-message n)))
  1451.  
  1452. (defun rmail-previous-message (n)
  1453.   "Show previous message whether deleted or not.
  1454. With prefix arg N, moves backward N messages, or forward if N is negative."
  1455.   (interactive "p")
  1456.   (rmail-next-message (- n)))  
  1457.  
  1458. (defun rmail-next-undeleted-message (n)
  1459.   "Show following non-deleted message.
  1460. With prefix arg N, moves forward N non-deleted messages,
  1461. or backward if N is negative.
  1462.  
  1463. Returns t if a new message is being shown, nil otherwise."
  1464.   (interactive "p")
  1465.   (rmail-maybe-set-message-counters)
  1466.   (let ((lastwin rmail-current-message)
  1467.     (current rmail-current-message))
  1468.     (while (and (> n 0) (< current rmail-total-messages))
  1469.       (setq current (1+ current))
  1470.       (if (not (rmail-message-deleted-p current))
  1471.       (setq lastwin current n (1- n))))
  1472.     (while (and (< n 0) (> current 1))
  1473.       (setq current (1- current))
  1474.       (if (not (rmail-message-deleted-p current))
  1475.       (setq lastwin current n (1+ n))))
  1476.     (if (/= lastwin rmail-current-message)
  1477.      (progn (rmail-show-message lastwin)
  1478.             t)
  1479.       (if (< n 0)
  1480.       (message "No previous nondeleted message"))
  1481.       (if (> n 0)
  1482.       (message "No following nondeleted message"))
  1483.       nil)))
  1484.  
  1485. (defun rmail-previous-undeleted-message (n)
  1486.   "Show previous non-deleted message.
  1487. With prefix argument N, moves backward N non-deleted messages,
  1488. or forward if N is negative."
  1489.   (interactive "p")
  1490.   (rmail-next-undeleted-message (- n)))
  1491.  
  1492. (defun rmail-first-message ()
  1493.   "Show first message in file."
  1494.   (interactive)
  1495.   (rmail-maybe-set-message-counters)
  1496.   (rmail-show-message 1))
  1497.  
  1498. (defun rmail-last-message ()
  1499.   "Show last message in file."
  1500.   (interactive)
  1501.   (rmail-maybe-set-message-counters)
  1502.   (rmail-show-message rmail-total-messages))
  1503.  
  1504. (defun rmail-what-message ()
  1505.   (let ((where (point))
  1506.     (low 1)
  1507.     (high rmail-total-messages)
  1508.     (mid (/ rmail-total-messages 2)))
  1509.     (while (> (- high low) 1)
  1510.       (if (>= where (rmail-msgbeg mid))
  1511.       (setq low mid)
  1512.     (setq high mid))
  1513.       (setq mid (+ low (/ (- high low) 2))))
  1514.     (if (>= where (rmail-msgbeg high)) high low)))
  1515.  
  1516. (defun rmail-message-recipients-p (msg recipients &optional primary-only)
  1517.   (save-restriction
  1518.     (goto-char (rmail-msgbeg msg))
  1519.     (search-forward "\n*** EOOH ***\n")
  1520.     (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
  1521.     (or (string-match recipients (or (mail-fetch-field "To") ""))
  1522.     (string-match recipients (or (mail-fetch-field "From") ""))
  1523.     (if (not primary-only)
  1524.         (string-match recipients (or (mail-fetch-field "Cc") ""))))))
  1525.  
  1526. (defun rmail-message-regexp-p (msg regexp)
  1527.   "Return t, if for message number MSG, regexp REGEXP matches in the header."
  1528.   (goto-char (rmail-msgbeg msg))
  1529.   (let ((end 
  1530.          (save-excursion 
  1531.            (search-forward "*** EOOH ***" (point-max)) (point))))
  1532.     (re-search-forward regexp end t)))
  1533.  
  1534. (defun rmail-search-backward (regexp &optional n)
  1535.   "Show message containing next match for REGEXP.
  1536. Prefix argument gives repeat count; negative argument means search
  1537. backwards (through earlier messages).
  1538. Interactively, empty argument means use same regexp used last time."
  1539.   (interactive
  1540.     (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
  1541.        (prompt
  1542.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1543.        regexp)
  1544.       (if rmail-search-last-regexp
  1545.       (setq prompt (concat prompt
  1546.                    "(default "
  1547.                    rmail-search-last-regexp
  1548.                    ") ")))
  1549.       (setq regexp (read-string prompt))
  1550.       (cond ((not (equal regexp ""))
  1551.          (setq rmail-search-last-regexp regexp))
  1552.         ((not rmail-search-last-regexp)
  1553.          (error "No previous Rmail search string")))
  1554.       (list rmail-search-last-regexp
  1555.         (prefix-numeric-value current-prefix-arg))))
  1556.   (rmail-search regexp (- n)))
  1557.  
  1558. (defvar rmail-search-last-regexp nil)
  1559. (defun rmail-search (regexp &optional n)
  1560.   "Show message containing next match for REGEXP.
  1561. Prefix argument gives repeat count; negative argument means search
  1562. backwards (through earlier messages).
  1563. Interactively, empty argument means use same regexp used last time."
  1564.   (interactive
  1565.     (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
  1566.        (prompt
  1567.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1568.        regexp)
  1569.       (if rmail-search-last-regexp
  1570.       (setq prompt (concat prompt
  1571.                    "(default "
  1572.                    rmail-search-last-regexp
  1573.                    ") ")))
  1574.       (setq regexp (read-string prompt))
  1575.       (cond ((not (equal regexp ""))
  1576.          (setq rmail-search-last-regexp regexp))
  1577.         ((not rmail-search-last-regexp)
  1578.          (error "No previous Rmail search string")))
  1579.       (list rmail-search-last-regexp
  1580.         (prefix-numeric-value current-prefix-arg))))
  1581.   (or n (setq n 1))
  1582.   (message "%sRmail search for %s..."
  1583.        (if (< n 0) "Reverse " "")
  1584.        regexp)
  1585.   (rmail-maybe-set-message-counters)
  1586.   (let ((omin (point-min))
  1587.     (omax (point-max))
  1588.     (opoint (point))
  1589.     win
  1590.     (reversep (< n 0))
  1591.     (msg rmail-current-message))
  1592.     (unwind-protect
  1593.     (progn
  1594.       (widen)
  1595.       (while (/= n 0)
  1596.         ;; Check messages one by one, advancing message number up or down
  1597.         ;; but searching forward through each message.
  1598.         (if reversep
  1599.         (while (and (null win) (> msg 1))
  1600.           (goto-char (rmail-msgbeg (setq msg (1- msg))))
  1601.           (setq win (re-search-forward
  1602.                  regexp (rmail-msgend msg) t)))
  1603.           (while (and (null win) (< msg rmail-total-messages))
  1604.         (goto-char (rmail-msgbeg (setq msg (1+ msg))))
  1605.         (setq win (re-search-forward regexp (rmail-msgend msg) t))))
  1606.         (setq n (+ n (if reversep 1 -1)))))
  1607.       (if win
  1608.       (progn
  1609.         ;; If this is a reverse search and we found a message,
  1610.         ;; search backward thru this message to position point.
  1611.         (if reversep
  1612.         (progn
  1613.           (goto-char (rmail-msgend msg))
  1614.           (re-search-backward
  1615.            regexp (rmail-msgbeg msg) t)))
  1616.         (setq win (point))
  1617.         (rmail-show-message msg)
  1618.         (message "%sRmail search for %s...done"
  1619.              (if reversep "Reverse " "")
  1620.              regexp)
  1621.         (goto-char win))
  1622.     (goto-char opoint)
  1623.     (narrow-to-region omin omax)
  1624.     (ding)
  1625.     (message "Search failed: %s" regexp)))))
  1626.  
  1627. (defun rmail-search-backwards (regexp &optional n)
  1628.   "Show message containing previous match for REGEXP.
  1629. Prefix argument gives repeat count; negative argument means search
  1630. forward (through later messages).
  1631. Interactively, empty argument means use same regexp used last time."
  1632.   (interactive
  1633.     (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
  1634.        (prompt
  1635.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1636.        regexp)
  1637.       (if rmail-search-last-regexp
  1638.       (setq prompt (concat prompt
  1639.                    "(default "
  1640.                    rmail-search-last-regexp
  1641.                    ") ")))
  1642.       (setq regexp (read-string prompt))
  1643.       (cond ((not (equal regexp ""))
  1644.          (setq rmail-search-last-regexp regexp))
  1645.         ((not rmail-search-last-regexp)
  1646.          (error "No previous Rmail search string")))
  1647.       (list rmail-search-last-regexp
  1648.         (prefix-numeric-value current-prefix-arg))))
  1649.   (rmail-search regexp (- (or n -1))))
  1650.  
  1651. ;; Show the first message which has the `unseen' attribute.
  1652. (defun rmail-first-unseen-message ()
  1653.   (rmail-maybe-set-message-counters)
  1654.   (let ((current 1)
  1655.     found)
  1656.     (save-restriction
  1657.       (widen)
  1658.       (while (and (not found) (< current rmail-total-messages))
  1659.     (if (rmail-message-labels-p current ", ?\\(unseen\\),")
  1660.         (setq found current))
  1661.     (setq current (1+ current))))
  1662. ;; Let the caller show the message.
  1663. ;;    (if found
  1664. ;;    (rmail-show-message found))
  1665.     found))
  1666.  
  1667. ;;;; *** Rmail Message Deletion Commands ***
  1668.  
  1669. (defun rmail-message-deleted-p (n)
  1670.   (= (aref rmail-deleted-vector n) ?D))
  1671.  
  1672. (defun rmail-set-message-deleted-p (n state)
  1673.   (aset rmail-deleted-vector n (if state ?D ?\ )))
  1674.  
  1675. (defun rmail-delete-message ()
  1676.   "Delete this message and stay on it."
  1677.   (interactive)
  1678.   (rmail-set-attribute "deleted" t))
  1679.  
  1680. (defun rmail-undelete-previous-message ()
  1681.   "Back up to deleted message, select it, and undelete it."
  1682.   (interactive)
  1683.   (let ((msg rmail-current-message))
  1684.     (while (and (> msg 0)
  1685.         (not (rmail-message-deleted-p msg)))
  1686.       (setq msg (1- msg)))
  1687.     (if (= msg 0)
  1688.     (error "No previous deleted message")
  1689.       (if (/= msg rmail-current-message)
  1690.       (rmail-show-message msg))
  1691.       (rmail-set-attribute "deleted" nil)
  1692.       (if (rmail-summary-exists)
  1693.       (save-excursion
  1694.         (set-buffer rmail-summary-buffer)
  1695.         (rmail-summary-mark-undeleted msg)))
  1696.       (rmail-maybe-display-summary))))
  1697.  
  1698. (defun rmail-delete-forward (&optional backward)
  1699.   "Delete this message and move to next nondeleted one.
  1700. Deleted messages stay in the file until the \\[rmail-expunge] command is given.
  1701. With prefix argument, delete and move backward.
  1702.  
  1703. Returns t if a new message is displayed after the delete, or nil otherwise."
  1704.   (interactive "P")
  1705.   (rmail-set-attribute "deleted" t)
  1706.   (let ((del-msg rmail-current-message))
  1707.     (if (rmail-summary-exists)
  1708.     (save-excursion
  1709.       (set-buffer rmail-summary-buffer)
  1710.       (rmail-summary-mark-deleted del-msg)))
  1711.     (prog1 (rmail-next-undeleted-message (if backward -1 1))
  1712.       (rmail-maybe-display-summary))))
  1713.  
  1714. (defun rmail-delete-backward ()
  1715.   "Delete this message and move to previous nondeleted one.
  1716. Deleted messages stay in the file until the \\[rmail-expunge] command is given."
  1717.   (interactive)
  1718.   (rmail-delete-forward t))
  1719.  
  1720. (defun rmail-only-expunge ()
  1721.   "Actually erase all deleted messages in the file."
  1722.   (interactive)
  1723.   (message "Expunging deleted messages...")
  1724.   ;; Discard all undo records for this buffer.
  1725.   (or (eq buffer-undo-list t)
  1726.       (setq buffer-undo-list nil))
  1727.   (rmail-maybe-set-message-counters)
  1728.   (let* ((omax (- (buffer-size) (point-max)))
  1729.      (omin (- (buffer-size) (point-min)))
  1730.      (opoint (if (and (> rmail-current-message 0)
  1731.               (rmail-message-deleted-p rmail-current-message))
  1732.              0
  1733.            (- (point) (point-min))))
  1734.      (messages-head (cons (aref rmail-message-vector 0) nil))
  1735.      (messages-tail messages-head)
  1736.      ;; Don't make any undo records for the expunging.
  1737.      (buffer-undo-list t)
  1738.      (win))
  1739.     (unwind-protect
  1740.     (save-excursion
  1741.       (widen)
  1742.       (goto-char (point-min))
  1743.       (let ((counter 0)
  1744.         (number 1)
  1745.         (total rmail-total-messages)
  1746.         (new-message-number rmail-current-message)
  1747.         (new-summary nil)
  1748.         (buffer-read-only nil)
  1749.         (messages rmail-message-vector)
  1750.         (deleted rmail-deleted-vector)
  1751.         (summary rmail-summary-vector))
  1752.         (setq rmail-total-messages nil
  1753.           rmail-current-message nil
  1754.           rmail-message-vector nil
  1755.           rmail-deleted-vector nil
  1756.           rmail-summary-vector nil)
  1757.         (while (<= number total)
  1758.           (if (= (aref deleted number) ?D)
  1759.           (progn
  1760.             (delete-region
  1761.               (marker-position (aref messages number))
  1762.               (marker-position (aref messages (1+ number))))
  1763.             (move-marker (aref messages number) nil)
  1764.             (if (> new-message-number counter)
  1765.             (setq new-message-number (1- new-message-number))))
  1766.         (setq counter (1+ counter))
  1767.         (setq messages-tail
  1768.               (setcdr messages-tail
  1769.                   (cons (aref messages number) nil)))
  1770.         (setq new-summary
  1771.               (cons (if (= counter number) (aref summary (1- number)))
  1772.                 new-summary)))
  1773.           (if (zerop (% (setq number (1+ number)) 20))
  1774.           (message "Expunging deleted messages...%d" number)))
  1775.         (setq messages-tail
  1776.           (setcdr messages-tail
  1777.               (cons (aref messages number) nil)))
  1778.         (setq rmail-current-message new-message-number
  1779.           rmail-total-messages counter
  1780.           rmail-message-vector (apply 'vector messages-head)
  1781.           rmail-deleted-vector (make-string (1+ counter) ?\ )
  1782.           rmail-summary-vector (vconcat (nreverse new-summary))
  1783.           win t)))
  1784.       (message "Expunging deleted messages...done")
  1785.       (if (not win)
  1786.       (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
  1787.       (rmail-show-message
  1788.        (if (zerop rmail-current-message) 1 nil))
  1789.       (forward-char opoint))))
  1790.  
  1791. (defun rmail-expunge ()
  1792.   "Erase deleted messages from Rmail file and summary buffer."
  1793.   (interactive)
  1794.   (rmail-only-expunge)
  1795.   (if (rmail-summary-exists)
  1796.       (rmail-select-summary
  1797.     (rmail-update-summary))))
  1798.  
  1799. ;;;; *** Rmail Mailing Commands ***
  1800.  
  1801. (defun rmail-start-mail (&rest args)
  1802.   (if (and window-system rmail-mail-new-frame)
  1803.       (prog1
  1804.     (apply 'mail-other-frame args)
  1805.     (modify-frame-parameters (selected-frame)
  1806.                  '((dedicated . t))))
  1807.     (apply 'mail-other-window args)))
  1808.  
  1809. (defun rmail-mail ()
  1810.   "Send mail in another window.
  1811. While composing the message, use \\[mail-yank-original] to yank the
  1812. original message into it."
  1813.   (interactive)
  1814.   (rmail-start-mail nil nil nil nil nil (current-buffer)))
  1815.  
  1816. (defun rmail-continue ()
  1817.   "Continue composing outgoing message previously being composed."
  1818.   (interactive)
  1819.   (rmail-start-mail t))
  1820.  
  1821. (defun rmail-reply (just-sender)
  1822.   "Reply to the current message.
  1823. Normally include CC: to all other recipients of original message;
  1824. prefix argument means ignore them.  While composing the reply,
  1825. use \\[mail-yank-original] to yank the original message into it."
  1826.   (interactive "P")
  1827.   (let (from reply-to cc subject date to message-id resent-reply-to)
  1828.     (save-excursion
  1829.       (save-restriction
  1830.     (widen)
  1831.     (goto-char (rmail-msgbeg rmail-current-message))
  1832.     (forward-line 1)
  1833.     (if (= (following-char) ?0)
  1834.         (narrow-to-region
  1835.          (progn (forward-line 2)
  1836.             (point))
  1837.          (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
  1838.                     'move)
  1839.             (point)))
  1840.       (narrow-to-region (point)
  1841.                 (progn (search-forward "\n*** EOOH ***\n")
  1842.                    (beginning-of-line) (point))))
  1843.     (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
  1844.           from (mail-fetch-field "from")
  1845.           reply-to (or resent-reply-to
  1846.                (mail-fetch-field "reply-to" nil t)
  1847.                from)
  1848.           cc (cond (just-sender nil)
  1849.                (resent-reply-to (mail-fetch-field "resent-cc" t))
  1850.                (t (mail-fetch-field "cc" nil t)))
  1851.           subject (or (and resent-reply-to
  1852.                    (mail-fetch-field "resent-subject" t))
  1853.               (mail-fetch-field "subject"))
  1854.           date (or (and resent-reply-to
  1855.                 (mail-fetch-field "resent-date" t))
  1856.                (mail-fetch-field "date"))
  1857.           to (cond (resent-reply-to
  1858.             (or (mail-fetch-field "resent-to" t)) "")
  1859.                ((mail-fetch-field "to" nil t))
  1860.                ;((mail-fetch-field "apparently-to")) ack gag barf
  1861.                (t ""))
  1862.           message-id (cond (resent-reply-to
  1863.                 (mail-fetch-field "resent-message-id" t))
  1864.                    ((mail-fetch-field "message-id"))))))
  1865.     (and (stringp subject)
  1866.      (or (string-match (concat "\\`" (regexp-quote rmail-reply-prefix))
  1867.                subject)
  1868.          (setq subject (concat rmail-reply-prefix subject))))
  1869.     (rmail-start-mail nil
  1870.       (mail-strip-quoted-names reply-to)
  1871.       subject
  1872.       (rmail-make-in-reply-to-field from date message-id)
  1873.       (if just-sender
  1874.       nil
  1875.     (let* ((cc-list (rmail-dont-reply-to
  1876.               (mail-strip-quoted-names
  1877.                 (if (null cc) to (concat to ", " cc))))))
  1878.       (if (string= cc-list "") nil cc-list)))
  1879.       (current-buffer)
  1880.       (list (list '(lambda (buf msgnum)
  1881.              (save-excursion
  1882.                (set-buffer buf)
  1883.                (rmail-set-attribute "answered" t msgnum)))
  1884.           (current-buffer) rmail-current-message)))))
  1885.  
  1886. (defun rmail-make-in-reply-to-field (from date message-id)
  1887.   (cond ((not from)
  1888.          (if message-id
  1889.              message-id
  1890.              nil))
  1891.         (mail-use-rfc822
  1892.          (require 'rfc822)
  1893.          (let ((tem (car (rfc822-addresses from))))
  1894.            (if message-id
  1895.                (if (string-match
  1896.                     (regexp-quote (if (string-match "@[^@]*\\'" tem)
  1897.                                       (substring tem 0 (match-beginning 0))
  1898.                                       tem))
  1899.                     message-id)
  1900.                    ;; Message-ID is sufficiently informative
  1901.                    message-id
  1902.                    (concat message-id " (" tem ")"))
  1903.          ;; Copy TEM, discarding text properties.
  1904.          (setq tem (copy-sequence tem))
  1905.          (set-text-properties 0 (length tem) nil tem)
  1906.          (setq tem (copy-sequence tem))
  1907.          ;; Use prin1 to fake RFC822 quoting
  1908.          (let ((field (prin1-to-string tem)))
  1909.            (if date
  1910.            (concat field "'s message of " date)
  1911.            field)))))
  1912.         ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
  1913.                 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
  1914.            ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
  1915.            (or (string-match (concat "\\`[ \t]*\\(" bar
  1916.                                      "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
  1917.                              ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
  1918.                              from)
  1919.                (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
  1920.                                      bar "\\))[ \t]*\\'")
  1921.                              ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
  1922.                              from)))
  1923.          (let ((start (match-beginning 1))
  1924.                (end (match-end 1)))
  1925.            ;; Trim whitespace which above regexp match allows
  1926.            (while (and (< start end)
  1927.                        (memq (aref from start) '(?\t ?\ )))
  1928.              (setq start (1+ start)))
  1929.            (while (and (< start end)
  1930.                        (memq (aref from (1- end)) '(?\t ?\ )))
  1931.              (setq end (1- end)))
  1932.            (let ((field (substring from start end)))
  1933.              (if date (setq field (concat "message from " field " on " date)))
  1934.              (if message-id
  1935.                  ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
  1936.                  (concat message-id " (" field ")")
  1937.                  field))))
  1938.         (t
  1939.          ;; If we can't kludge it simply, do it correctly
  1940.          (let ((mail-use-rfc822 t))
  1941.            (rmail-make-in-reply-to-field from date message-id)))))
  1942.  
  1943. (defun rmail-forward (resend)
  1944.   "Forward the current message to another user.
  1945. With prefix argument, \"resend\" the message instead of forwarding it;
  1946. see the documentation of `rmail-resend'."
  1947.   (interactive "P")
  1948.   (if resend
  1949.       (call-interactively 'rmail-resend)
  1950.     (let ((forward-buffer (current-buffer))
  1951.       (subject (concat "["
  1952.                (let ((from (or (mail-fetch-field "From")
  1953.                        (mail-fetch-field ">From"))))
  1954.                  (if from
  1955.                  (concat (mail-strip-quoted-names from) ": ")
  1956.                    ""))
  1957.                (or (mail-fetch-field "Subject") "")
  1958.                "]")))
  1959.       ;; If only one window, use it for the mail buffer.
  1960.       ;; Otherwise, use another window for the mail buffer
  1961.       ;; so that the Rmail buffer remains visible
  1962.       ;; and sending the mail will get back to it.
  1963.       (if (funcall (if (and (not rmail-mail-new-frame) (one-window-p t))
  1964.                (function mail)
  1965.              (function rmail-start-mail))
  1966.            nil nil subject nil nil nil
  1967.            (list (list (function (lambda (buf msgnum)
  1968.                        (save-excursion
  1969.                          (set-buffer buf)
  1970.                          (rmail-set-attribute
  1971.                           "forwarded" t msgnum))))
  1972.                    (current-buffer)
  1973.                    rmail-current-message)))
  1974.       (save-excursion
  1975.         ;; Insert after header separator--before signature if any.
  1976.         (goto-char (point-min))
  1977.         (search-forward-regexp
  1978.          (concat "^" (regexp-quote mail-header-separator)))
  1979.         (forward-line 1)
  1980.         (insert-buffer forward-buffer))))))
  1981.  
  1982. (defun rmail-resend (address &optional from comment mail-alias-file)
  1983.   "Resend current message to ADDRESSES.
  1984. ADDRESSES should be a single address, a string consisting of several
  1985. addresses separated by commas, or a list of addresses.
  1986.  
  1987. Optional FROM is the address to resend the message from, and
  1988. defaults to the username of the person redistributing the message.
  1989. Optional COMMENT is a string that will be inserted as a comment in the
  1990. resent message.
  1991. Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
  1992. typically for purposes of moderating a list."
  1993.   (interactive "sResend to: ")
  1994.   (require 'sendmail)
  1995.   (require 'mailalias)
  1996.   (if (not from) (setq from (user-login-name)))
  1997.   (let ((tembuf (generate-new-buffer " sendmail temp"))
  1998.     (mail-header-separator "")
  1999.     (case-fold-search nil)
  2000.     (mailbuf (current-buffer)))
  2001.     (unwind-protect
  2002.     (save-excursion
  2003.       ;;>> Copy message into temp buffer
  2004.       (set-buffer tembuf)
  2005.       (insert-buffer-substring mailbuf)
  2006.       (goto-char (point-min))
  2007.       ;; Delete any Sender field, since that's not specifyable.
  2008.       ; Only delete Sender fields in the actual header.
  2009.       (re-search-forward "^$" nil 'move)
  2010.       ; Using "while" here rather than "if" because some buggy mail
  2011.       ; software may have inserted multiple Sender fields.
  2012.       (while (re-search-backward "^Sender:" nil t)
  2013.         (let (beg)
  2014.           (setq beg (point))
  2015.           (forward-line 1)
  2016.           (while (looking-at "[ \t]")
  2017.         (forward-line 1))
  2018.           (delete-region beg (point))))
  2019.       ; Go back to the beginning of the buffer so the Resent- fields
  2020.       ; are inserted there.
  2021.       (goto-char (point-min))
  2022.       ;;>> Insert resent-from:
  2023.       (insert "Resent-From: " from "\n")
  2024.       (insert "Resent-Date: " (mail-rfc822-date) "\n")
  2025.       ;;>> Insert resent-to: and bcc if need be.
  2026.       (let ((before (point)))
  2027.         (if mail-self-blind
  2028.         (insert "Resent-Bcc: " (user-login-name) "\n"))
  2029.         (insert "Resent-To: " (if (stringp address)
  2030.                    address
  2031.                  (mapconcat 'identity address ",\n\t"))
  2032.             "\n")
  2033.         (expand-mail-aliases before (point)))
  2034.       ;;>> Set up comment, if any.
  2035.       (if (and (sequencep comment) (not (zerop (length comment))))
  2036.           (let ((before (point))
  2037.             after)
  2038.         (insert comment)
  2039.         (or (eolp) (insert "\n"))
  2040.         (setq after (point))
  2041.         (goto-char before)
  2042.         (while (< (point) after)
  2043.           (insert "Resent-Comment: ")
  2044.           (forward-line 1))))
  2045.       ;; Don't expand aliases in the destination fields
  2046.       ;; of the original message.
  2047.       (let (mail-aliases)
  2048.         (funcall send-mail-function)))
  2049.       (kill-buffer tembuf))
  2050.     (rmail-set-attribute "resent" t rmail-current-message)))
  2051.  
  2052. (defvar mail-unsent-separator
  2053.   (concat "^ *---+ +Unsent message follows +---+ *$\\|"
  2054.       "^ *---+ +Returned message +---+ *$\\|"
  2055.       "^ *---+ +Original message +---+ *$\\|"
  2056.       "^ *--+ +begin message +--+ *$\\|"
  2057.       "^ *---+ +Original message follows +---+ *$\\|"
  2058.       "^|? *---+ +Message text follows: +---+ *|?$"))
  2059.  
  2060. (defun rmail-retry-failure ()
  2061.   "Edit a mail message which is based on the contents of the current message.
  2062. For a message rejected by the mail system, extract the interesting headers and
  2063. the body of the original message."
  2064.   (interactive)
  2065.   (require 'mail-utils)
  2066.   (let (to subj irp2 cc orig-message)
  2067.     (save-excursion
  2068.       ;; Narrow down to just the quoted original message
  2069.       (rmail-beginning-of-message)
  2070.       (let ((case-fold-search t))
  2071.     (or (re-search-forward mail-unsent-separator nil t)
  2072.         (error "Cannot parse this as a failure message")))
  2073.       (save-restriction
  2074.     (narrow-to-region (point) (point-max))
  2075.     ;; Now mail-fetch-field will get from headers of the original message,
  2076.     ;; not from the headers of the rejection.
  2077.     (setq to   (mail-fetch-field "To")
  2078.           subj (mail-fetch-field "Subject")
  2079.           irp2 (mail-fetch-field "In-reply-to")
  2080.           cc   (mail-fetch-field "Cc"))
  2081.     ;; Get the entire text (not headers) of the original message.
  2082.     (setq orig-message
  2083.           (buffer-substring
  2084.            (progn (search-forward "\n\n") (point))
  2085.            (point-max)))))
  2086.     ;; Start sending a new message; default header fields from the original.
  2087.     ;; Turn off the usual actions for initializing the message body
  2088.     ;; because we want to get only the text from the failure message.
  2089.     (let (mail-signature
  2090.       (mail-setup-hook rmail-retry-setup-hook))
  2091.       (if (rmail-start-mail nil to subj irp2 cc (current-buffer))
  2092.       ;; Insert original text as initial text of new draft message.
  2093.       (progn
  2094.         (goto-char (point-max))
  2095.         (insert orig-message)
  2096.         (goto-char (point-min))
  2097.         (end-of-line))))))
  2098.  
  2099. (defun rmail-bury ()
  2100.   "Bury current Rmail buffer and its summary buffer."
  2101.   (interactive)
  2102.   ;; This let var was called rmail-buffer, but that interfered
  2103.   ;; with the buffer-local var used in summary buffers.
  2104.   (let ((buffer-to-bury (current-buffer)))
  2105.     (if (rmail-summary-exists)
  2106.     (let (window)
  2107.       (while (setq window (get-buffer-window rmail-summary-buffer))
  2108.         (set-window-buffer window (other-buffer rmail-summary-buffer)))
  2109.       (bury-buffer rmail-summary-buffer)))
  2110.     (switch-to-buffer (other-buffer (current-buffer)))
  2111.     (bury-buffer buffer-to-bury)))
  2112.  
  2113. (defun rmail-summary-exists ()
  2114.   "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
  2115. In fact, the non-nil value returned is the summary buffer itself."
  2116.   (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
  2117.        rmail-summary-buffer))
  2118.  
  2119. (defun rmail-summary-displayed ()
  2120.   "t iff in RMAIL buffer and an associated summary buffer is displayed."
  2121.   (and rmail-summary-buffer (get-buffer-window rmail-summary-buffer)))
  2122.  
  2123. (defvar rmail-redisplay-summary nil
  2124.   "*Non-nil means Rmail should show the summary when it changes.
  2125. This has an effect only if a summary buffer exists.")
  2126.  
  2127. (defvar rmail-summary-window-size nil
  2128.   "*Non-nil means specify the height for an Rmail summary window.")
  2129.  
  2130. ;; Put the summary buffer back on the screen, if user wants that.
  2131. (defun rmail-maybe-display-summary ()
  2132.   (let ((selected (selected-window))
  2133.     window)
  2134.     ;; If requested, make sure the summary is displayed.
  2135.     (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
  2136.      rmail-redisplay-summary
  2137.      (display-buffer rmail-summary-buffer))
  2138.     ;; If requested, set the height of the summary window.
  2139.     (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
  2140.      rmail-summary-window-size
  2141.      (setq window (get-buffer-window rmail-summary-buffer))
  2142.      (unwind-protect 
  2143.          (progn
  2144.            (select-window window)
  2145.            (enlarge-window (- rmail-summary-window-size
  2146.                   (window-height))))
  2147.        (select-window selected)))))
  2148.  
  2149. ;;;; *** Rmail Specify Inbox Files ***
  2150.  
  2151. (autoload 'set-rmail-inbox-list "rmailmsc"
  2152.   "Set the inbox list of the current RMAIL file to FILE-NAME.
  2153. This may be a list of file names separated by commas.
  2154. If FILE-NAME is empty, remove any inbox list."
  2155.   t)
  2156.  
  2157. ;;;; *** Rmail Commands for Labels ***
  2158.  
  2159. (autoload 'rmail-add-label "rmailkwd"
  2160.   "Add LABEL to labels associated with current RMAIL message.
  2161. Completion is performed over known labels when reading."
  2162.   t)
  2163.  
  2164. (autoload 'rmail-kill-label "rmailkwd"
  2165.   "Remove LABEL from labels associated with current RMAIL message.
  2166. Completion is performed over known labels when reading."
  2167.   t)
  2168.  
  2169. (autoload 'rmail-next-labeled-message "rmailkwd"
  2170.   "Show next message with LABEL.  Defaults to last label used.
  2171. With prefix argument N moves forward N messages with this label."
  2172.   t)
  2173.  
  2174. (autoload 'rmail-previous-labeled-message "rmailkwd"
  2175.   "Show previous message with LABEL.  Defaults to last label used.
  2176. With prefix argument N moves backward N messages with this label."
  2177.   t)
  2178.  
  2179. (autoload 'rmail-read-label "rmailkwd"
  2180.   "PROMPT and read with completion an Rmail message label."
  2181.   t)
  2182.  
  2183. ;;;; *** Rmail Edit Mode ***
  2184.  
  2185. (autoload 'rmail-edit-current-message "rmailedit"
  2186.   "Edit the contents of the current message"
  2187.   t)
  2188.  
  2189. ;;;; *** Rmail Sorting ***
  2190.  
  2191. (autoload 'rmail-sort-by-date "rmailsort"
  2192.   "Sort messages of current Rmail file by date.
  2193. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2194.  
  2195. (autoload 'rmail-sort-by-subject "rmailsort"
  2196.   "Sort messages of current Rmail file by subject.
  2197. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2198.  
  2199. (autoload 'rmail-sort-by-author "rmailsort"
  2200.   "Sort messages of current Rmail file by author.
  2201. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2202.  
  2203. (autoload 'rmail-sort-by-recipient "rmailsort"
  2204.   "Sort messages of current Rmail file by recipient.
  2205. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2206.  
  2207. (autoload 'rmail-sort-by-correspondent "rmailsort"
  2208.   "Sort messages of current Rmail file by other correspondent.
  2209. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2210.  
  2211. (autoload 'rmail-sort-by-lines "rmailsort"
  2212.   "Sort messages of current Rmail file by number of lines.
  2213. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2214.  
  2215. (autoload 'rmail-sort-by-keywords "rmailsort"
  2216.   "Sort messages of current Rmail file by labels.
  2217. If prefix argument REVERSE is non-nil, sort them in reverse order.
  2218. KEYWORDS is a comma-separated list of labels." t)
  2219.  
  2220. ;;;; *** Rmail Summary Mode ***
  2221.  
  2222. (autoload 'rmail-summary "rmailsum"
  2223.   "Display a summary of all messages, one line per message."
  2224.   t)
  2225.  
  2226. (autoload 'rmail-summary-by-labels "rmailsum"
  2227.   "Display a summary of all messages with one or more LABELS.
  2228. LABELS should be a string containing the desired labels, separated by commas."
  2229.   t)
  2230.  
  2231. (autoload 'rmail-summary-by-recipients "rmailsum"
  2232.   "Display a summary of all messages with the given RECIPIENTS.
  2233. Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
  2234. is non-nil (prefix arg given), only look in the To and From fields.
  2235. RECIPIENTS is a string of regexps separated by commas."
  2236.   t)
  2237.  
  2238. (autoload 'rmail-summary-by-regexp "rmailsum"
  2239.   "Display a summary of all messages according to regexp REGEXP.
  2240. If the regular expression is found in the header of the message
  2241. \(including in the date and other lines, as well as the subject line),
  2242. Emacs will list the header line in the RMAIL-summary."
  2243.   t)
  2244.  
  2245. (autoload 'rmail-summary-by-topic "rmailsum"
  2246.   "Display a summary of all messages with the given SUBJECT.
  2247. Normally checks the Subject field of headers;
  2248. but if WHOLE-MESSAGE is non-nil (prefix arg given), 
  2249.  look in the whole message.
  2250. SUBJECT is a string of regexps separated by commas."
  2251.   t)
  2252.  
  2253. ;;;; *** Rmail output messages to files ***
  2254.  
  2255. (autoload 'rmail-output-to-rmail-file "rmailout"
  2256.   "Append the current message to an Rmail file named FILE-NAME.
  2257. If the file does not exist, ask if it should be created.
  2258. If file is being visited, the message is appended to the Emacs
  2259. buffer visiting that file."
  2260.   t)
  2261.  
  2262. (autoload 'rmail-output "rmailout"
  2263.   "Append this message to Unix mail file named FILE-NAME."
  2264.   t)
  2265.  
  2266. (autoload 'rmail-output-menu "rmailout"
  2267.   "Output current message to another Rmail file, chosen with a menu."
  2268.   t)
  2269.  
  2270. ;;;; *** Rmail undigestification ***
  2271.  
  2272. (autoload 'undigestify-rmail-message "undigest"
  2273.   "Break up a digest message into its constituent messages.
  2274. Leaves original message, deleted, before the undigestified messages."
  2275.   t)
  2276.  
  2277. (provide 'rmail)
  2278.  
  2279. ;;; rmail.el ends here
  2280.