home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / emacs-15.0.3 / lisp / rmail.el < prev    next >
Lisp/Scheme  |  1990-07-19  |  49KB  |  1,366 lines

  1. ;; "RMAIL" mail reader for Emacs.
  2. ;; Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is distributed in the hope that it will be useful,
  7. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  8. ;; accepts responsibility to anyone for the consequences of using it
  9. ;; or for whether it serves any particular purpose or works at all,
  10. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  11. ;; License for full details.
  12.  
  13. ;; Everyone is granted permission to copy, modify and redistribute
  14. ;; GNU Emacs, but only under the conditions described in the
  15. ;; GNU Emacs General Public License.   A copy of this license is
  16. ;; supposed to have been given to you along with GNU Emacs so you
  17. ;; can know your rights and responsibilities.  It should be in a
  18. ;; file named COPYING.  Among other things, the copyright notice
  19. ;; and this notice must be preserved on all copies.
  20.  
  21.  
  22. ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
  23. ;;   New features include attribute and keyword support, message
  24. ;;   selection by dispatch table, summary by attributes and keywords,
  25. ;;   expunging by dispatch table, sticky options for file commands.
  26.  
  27. (require 'mail-utils)
  28. (provide 'rmail)
  29.  
  30. ; these variables now declared in loaddefs or paths.el
  31. ;(defvar rmail-spool-directory "/usr/spool/mail/"
  32. ;  "This is the name of the directory used by the system mailer for\n\
  33. ;delivering new mail.  It's name should end with a slash.")
  34. ;(defvar rmail-dont-reply-to-names
  35. ;  nil
  36. ;  "*A regexp specifying names to prune of reply to messages.
  37. ;nil means dont reply to yourself.")
  38. ;(defvar rmail-ignored-headers
  39. ;   "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^message-id:\\|^summary-line:"
  40. ;   "*Gubbish headers one would rather not see.")
  41. ;(defvar rmail-file-name
  42. ;  (expand-file-name "~/RMAIL")
  43. ;  "")
  44. ;
  45. ;(defvar rmail-delete-after-output nil
  46. ;  "*Non-nil means automatically delete a message that is copied to a file.")
  47. ;
  48. ;(defvar rmail-primary-inbox-list 
  49. ;  '("/usr/spool/mail/$USER" "~/mbox")
  50. ; "")
  51.  
  52. ;; these may be altered by site-init.el to match the format of mmdf files
  53. ;;  delimitation used on a given host (delim1 and delim2 from the config
  54. ;;  files)
  55.  
  56. (defvar mmdf-delim1 "^\001\001\001\001\n"
  57.   "Regexp marking the start of an mmdf message")
  58. (defvar mmdf-delim2 "^\001\001\001\001\n"
  59.   "Regexp marking the end of an mmdf message")
  60.  
  61. (defvar rmail-message-filter nil
  62.   "If non nil, is a filter function for new headers in RMAIL.
  63. Called with region narrowed to unformatted header.")
  64.  
  65. (defvar rmail-mode-map nil)
  66.  
  67. ;; Message counters and markers.  Deleted flags.
  68.  
  69. (defvar rmail-current-message nil)
  70. (defvar rmail-total-messages nil)
  71. (defvar rmail-message-vector nil)
  72. (defvar rmail-deleted-vector nil)
  73.  
  74. ;; These are used by autoloaded rmail-summary.
  75.  
  76. (defvar rmail-summary-buffer nil)
  77. (defvar rmail-summary-vector nil)
  78.  
  79. ;; `Sticky' default variables.
  80.  
  81. ;; Last individual label specified to a or k.
  82. (defvar rmail-last-label nil)
  83. ;; Last set of labels specified to C-M-n or C-M-p or C-M-l.
  84. (defvar rmail-last-multi-labels nil)
  85. (defvar rmail-last-file nil)
  86. (defvar rmail-last-rmail-file nil)
  87.  
  88. ;;;; *** Rmail Mode ***
  89.  
  90. (defun rmail (&optional file-name-arg)
  91.   "Read and edit incoming mail.
  92. Moves messages into file named by  rmail-file-name  (a babyl format file)
  93.  and edits that file in RMAIL Mode.
  94. Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
  95.  
  96. May be called with filename as argument;
  97. then performs rmail editing on that file,
  98. but does not copy any new mail into the file."
  99.   (interactive (if current-prefix-arg
  100.            (list (read-file-name "Run rmail on RMAIL file: "
  101.                      nil nil t))))
  102.   (or rmail-last-file
  103.       (setq rmail-last-file (expand-file-name "~/xmail")))
  104.   (or rmail-last-rmail-file
  105.       (setq rmail-last-rmail-file (expand-file-name "~/XMAIL")))
  106.   (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
  107.      (existed (get-file-buffer file-name))
  108.      ;; Don't be confused by apparent local-variables spec
  109.      ;; in the last message in the RMAIL file.
  110.      (inhibit-local-variables t))
  111.     ;; Like find-file, but in the case where a buffer existed
  112.     ;; and the file was reverted, recompute the message-data.
  113.     (if (and existed (not (verify-visited-file-modtime existed)))
  114.     (progn
  115.       (find-file file-name)
  116.       (if (and (verify-visited-file-modtime existed)
  117.            (eq major-mode 'rmail-mode))
  118.           (progn (rmail-forget-messages)
  119.              (rmail-set-message-counters))))
  120.       (find-file file-name))
  121.     (if (eq major-mode 'rmail-edit-mode)
  122.     (error "exit rmail-edit-mode before getting new mail"))
  123.     (if (and existed (eq major-mode 'rmail-mode))
  124.     nil
  125.       (rmail-mode)
  126.       ;; Provide default set of inboxes for primary mail file ~/RMAIL.
  127.       (and (null rmail-inbox-list)
  128.        (null file-name-arg)
  129.        (setq rmail-inbox-list
  130.          (or rmail-primary-inbox-list
  131.              (list "~/mbox"
  132.                (concat rmail-spool-directory
  133.                    (or (getenv "LOGNAME")
  134.                        (getenv "USER")
  135.                        (user-login-name)))))))
  136.       ;; Convert all or part to Babyl file if possible.
  137.       (rmail-convert-file)
  138.       (goto-char (point-max))
  139.       (if (null rmail-inbox-list)
  140.       (progn
  141.         (rmail-set-message-counters)
  142.         (rmail-show-message))))
  143.     (rmail-get-new-mail)))
  144.  
  145. (defun rmail-convert-file ()
  146.   (let (convert)
  147.     (widen)
  148.     (goto-char (point-min))
  149.     ;; If file doesn't start like a Babyl file,
  150.     ;; convert it to one, by adding a header and converting each message.
  151.     (cond ((looking-at "BABYL OPTIONS:"))
  152.       ((looking-at "Version: 5\n")
  153.        ;; Losing babyl file made by old version of Rmail.
  154.        ;; Just fix the babyl file header; don't make a new one,
  155.        ;; so we don't lose the Labels: file attribute, etc.
  156.        (let ((buffer-read-only nil))
  157.          (insert "BABYL OPTIONS:\n")))
  158.       (t
  159.        (setq convert t)
  160.        (rmail-insert-rmail-file-header)))
  161.     ;; If file was not a Babyl file or if there are
  162.     ;; Unix format messages added at the end,
  163.     ;; convert file as necessary.
  164.     (if (or convert
  165.         (progn (goto-char (point-max))
  166.            (search-backward "\^_")
  167.            (forward-char 1)
  168.            (looking-at "\n*From ")))
  169.     (let ((buffer-read-only nil))
  170.       (message "Converting to Babyl format...")
  171.       (narrow-to-region (point) (point-max))
  172.       (rmail-convert-to-babyl-format)
  173.       (message "Converting to Babyl format...done")))))
  174.  
  175. (defun rmail-insert-rmail-file-header ()
  176.   (let ((buffer-read-only nil))
  177.     (insert "BABYL OPTIONS:
  178. Version: 5
  179. Labels:
  180. Note:   This is the header of an rmail file.
  181. Note:   If you are seeing it in rmail,
  182. Note:    it means the file has no messages in it.\n\^_")))
  183.  
  184. (if rmail-mode-map
  185.     nil
  186.   (setq rmail-mode-map (make-keymap))
  187.   (suppress-keymap rmail-mode-map)
  188.   (define-key rmail-mode-map "." 'rmail-beginning-of-message)
  189.   (define-key rmail-mode-map " " 'scroll-up)
  190.   (define-key rmail-mode-map "\177" 'scroll-down)
  191.   (define-key rmail-mode-map "n" 'rmail-next-undeleted-message)
  192.   (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message)
  193.   (define-key rmail-mode-map "\en" 'rmail-next-message)
  194.   (define-key rmail-mode-map "\ep" 'rmail-previous-message)
  195.   (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
  196.   (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
  197.   (define-key rmail-mode-map "a" 'rmail-add-label)
  198.   (define-key rmail-mode-map "k" 'rmail-kill-label)
  199.   (define-key rmail-mode-map "d" 'rmail-delete-forward)
  200.   (define-key rmail-mode-map "u" 'rmail-undelete-previous-message)
  201.   (define-key rmail-mode-map "e" 'rmail-expunge)
  202.   (define-key rmail-mode-map "x" 'rmail-expunge)
  203.   (define-key rmail-mode-map "s" 'rmail-expunge-and-save)
  204.   (define-key rmail-mode-map "g" 'rmail-get-new-mail)
  205.   (define-key rmail-mode-map "h" 'rmail-summary)
  206.   (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
  207.   (define-key rmail-mode-map "l" 'rmail-summary-by-labels)
  208.   (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
  209.   (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
  210.   (define-key rmail-mode-map "t" 'rmail-toggle-header)
  211.   (define-key rmail-mode-map "m" 'rmail-mail)
  212.   (define-key rmail-mode-map "r" 'rmail-reply)
  213.   (define-key rmail-mode-map "c" 'rmail-continue)
  214.   (define-key rmail-mode-map "f" 'rmail-forward)
  215.   (define-key rmail-mode-map "\es" 'rmail-search)
  216.   (define-key rmail-mode-map "j" 'rmail-show-message)
  217.   (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file)
  218.   (define-key rmail-mode-map "\C-o" 'rmail-output)
  219.   (define-key rmail-mode-map "i" 'rmail-input)
  220.   (define-key rmail-mode-map "q" 'rmail-quit)
  221.   (define-key rmail-mode-map ">" 'rmail-last-message)
  222.   (define-key rmail-mode-map "?" 'describe-mode)
  223.   (define-key rmail-mode-map "w" 'rmail-edit-current-message)
  224.   (define-key rmail-mode-map "\C-d" 'rmail-delete-backward))
  225.  
  226. ;; Rmail mode is suitable only for specially formatted data.
  227. (put 'rmail-mode 'mode-class 'special)
  228.  
  229. (defun rmail-mode ()
  230.   "Rmail Mode is used by \\[rmail] for editing Rmail files.
  231. All normal editing commands are turned off.
  232. Instead, these commands are available:
  233.  
  234. .    Move point to front of this message (same as \\[beginning-of-buffer]).
  235. SPC    Scroll to next screen of this message.
  236. DEL    Scroll to previous screen of this message.
  237. n    Move to Next non-deleted message.
  238. p    Move to Previous non-deleted message.
  239. M-n    Move to Next message whether deleted or not.
  240. M-p    Move to Previous message whether deleted or not.
  241. >    Move to the last message in Rmail file.
  242. j    Jump to message specified by numeric position in file.
  243. M-s    Search for string and show message it is found in.
  244. d    Delete this message, move to next nondeleted.
  245. C-d    Delete this message, move to previous nondeleted.
  246. u    Undelete message.  Tries current message, then earlier messages
  247.     till a deleted message is found.
  248. e    Expunge deleted messages.
  249. s    Expunge and save the file.
  250. q       Quit Rmail: expunge, save, then switch to another buffer.
  251. C-x C-s Save without expunging.
  252. g    Move new mail from system spool directory or mbox into this file.
  253. m    Mail a message (same as \\[mail-other-window]).
  254. c    Continue composing outgoing message started before.
  255. r    Reply to this message.  Like m but initializes some fields.
  256. f    Forward this message to another user.
  257. o       Output this message to an Rmail file (append it).
  258. C-o    Output this message to a Unix-format mail file (append it).
  259. i    Input Rmail file.  Run Rmail on that file.
  260. a    Add label to message.  It will be displayed in the mode line.
  261. k    Kill label.  Remove a label from current message.
  262. C-M-n   Move to Next message with specified label
  263.           (label defaults to last one specified).
  264.           Standard labels: filed, unseen, answered, forwarded, deleted.
  265.           Any other label is present only if you add it with `a'.
  266. C-M-p   Move to Previous message with specified label
  267. C-M-h    Show headers buffer, with a one line summary of each message.
  268. C-M-l    Like h only just messages with particular label(s) are summarized.
  269. C-M-r   Like h only just messages with particular recipient(s) are summarized.
  270. t    Toggle header, show Rmail header if unformatted or vice versa.
  271. w    Edit the current message.  C-c C-c to return to Rmail."
  272.   (interactive)
  273.   (kill-all-local-variables)
  274.   (rmail-mode-1)
  275.   (rmail-variables)
  276.   (run-hooks 'rmail-mode-hook))
  277.  
  278. (defun rmail-mode-1 ()
  279.   (setq major-mode 'rmail-mode)
  280.   (setq mode-name "RMAIL")
  281.   (setq buffer-read-only t)
  282.   ;; No need to auto save RMAIL files.
  283.   (setq buffer-auto-save-file-name nil)
  284.   (if (boundp 'mode-line-modified)
  285.       (setq mode-line-modified "--- ")
  286.     (setq mode-line-format
  287.       (cons "--- " (cdr (default-value 'mode-line-format)))))
  288.   (use-local-map rmail-mode-map)
  289.   (set-syntax-table text-mode-syntax-table)
  290.   (setq local-abbrev-table text-mode-abbrev-table))
  291.  
  292. (defun rmail-variables ()
  293.   (make-local-variable 'revert-buffer-function)
  294.   (setq revert-buffer-function 'rmail-revert)
  295.   (make-local-variable 'rmail-last-label)
  296.   (make-local-variable 'rmail-deleted-vector)
  297.   (make-local-variable 'rmail-keywords)
  298.   (make-local-variable 'rmail-summary-buffer)
  299.   (make-local-variable 'rmail-summary-vector)
  300.   (make-local-variable 'rmail-current-message)
  301.   (make-local-variable 'rmail-total-messages)
  302.   (make-local-variable 'require-final-newline)
  303.   (setq require-final-newline nil)
  304.   (make-local-variable 'version-control)
  305.   (setq version-control 'never)
  306.   (make-local-variable 'file-precious-flag)
  307.   (setq file-precious-flag t)
  308.   (make-local-variable 'rmail-message-vector)
  309.   (make-local-variable 'rmail-last-file)
  310.   (make-local-variable 'rmail-inbox-list)
  311.   (setq rmail-inbox-list (rmail-parse-file-inboxes))
  312.   (make-local-variable 'rmail-keywords)
  313.   ;; this gets generated as needed
  314.   (setq rmail-keywords nil))
  315.  
  316. ;; Handle M-x revert-buffer done in an rmail-mode buffer.
  317. (defun rmail-revert (arg noconfirm)
  318.   (let (revert-buffer-function)
  319.     ;; Call our caller again, but this time it does the default thing.
  320.     (if (revert-buffer arg noconfirm)
  321.     ;; If the user said "yes", and we changed something,
  322.     ;; reparse the messages.
  323.     (progn
  324.       (rmail-convert-file)
  325.       (goto-char (point-max))
  326.       (rmail-set-message-counters)
  327.       (rmail-show-message)))))
  328.  
  329. ;; Return a list of files from this buffer's Mail: option.
  330. ;; Does not assume that messages have been parsed.
  331. ;; Just returns nil if buffer does not look like Babyl format.
  332. (defun rmail-parse-file-inboxes ()
  333.   (save-excursion
  334.     (save-restriction
  335.       (widen)
  336.       (goto-char 1)
  337.       (cond ((looking-at "Babyl options:")
  338.          (search-forward "\^_" nil 'move)
  339.          (narrow-to-region 1 (point))
  340.          (goto-char 1)
  341.          (if (search-forward "\nMail:" nil t)
  342.          (progn
  343.            (narrow-to-region (point) (progn (end-of-line) (point)))
  344.            (goto-char (point-min))
  345.            (mail-parse-comma-list))))))))
  346.  
  347. (defun rmail-expunge-and-save ()
  348.   "Expunge and save RMAIL file."
  349.   (interactive)
  350.   (rmail-expunge)
  351.   (save-buffer))
  352.  
  353. (defun rmail-quit ()
  354.   "Quit out of RMAIL."
  355.   (interactive)
  356.   (rmail-expunge-and-save)
  357.   ;; Don't switch to the summary buffer even if it was recently visible.
  358.   (if rmail-summary-buffer
  359.       (bury-buffer rmail-summary-buffer))
  360.   (let ((obuf (current-buffer)))
  361.     (switch-to-buffer (other-buffer))
  362.     (bury-buffer obuf)))
  363.  
  364. (defun rmail-input (filename)
  365.   "Run RMAIL on file FILENAME."
  366.   (interactive "FRun rmail on RMAIL file: ")
  367.   (rmail filename))
  368.  
  369.  
  370. ;;;; *** Rmail input ***
  371.  
  372. ;; RLK feature not added in this version:
  373. ;; argument specifies inbox file or files in various ways.
  374.  
  375. (defun rmail-get-new-mail (&optional file-name)
  376.   "Move any new mail from this RMAIL file's inbox files.
  377. The inbox files can be specified with the file's Mail: option.
  378. The variable rmail-primary-inbox-list specifies the inboxes for
  379. your primary RMAIL file if it has no Mail: option.
  380. These are normally your ~/mbox and your /usr/spool/mail/$USER.
  381.  
  382. You can also specify the file to get new mail from.  In this
  383. case, the file of new mail is not changed or deleted.
  384. Noninteractively, you can pass the inbox file name as an argument.
  385. Interactively, a prefix argument causes us to read a file name
  386. and use that file as the inbox."
  387.   (interactive
  388.    (list (if current-prefix-arg
  389.          (read-file-name "Get new mail from file: "))))
  390.   (or (verify-visited-file-modtime (current-buffer))
  391.       (progn
  392.     (find-file (buffer-file-name))
  393.     (if (verify-visited-file-modtime (current-buffer))
  394.         (rmail-forget-messages))))
  395.   (rmail-maybe-set-message-counters)
  396.   (widen)
  397.   (unwind-protect
  398.       (let ((opoint (point))
  399.         (new-messages 0)
  400.         (delete-files ())
  401.         ;; If buffer has not changed yet, and has not been saved yet,
  402.         ;; don't replace the old backup file now.
  403.         (make-backup-files (and make-backup-files (buffer-modified-p)))
  404.         (buffer-read-only nil))
  405.     (goto-char (point-max))
  406.     (skip-chars-backward " \t\n")    ; just in case of brain damage
  407.     (delete-region (point) (point-max))    ; caused by require-final-newline
  408.     (save-excursion
  409.       (save-restriction
  410.         (narrow-to-region (point) (point))
  411.         ;; Read in the contents of the inbox files,
  412.         ;; renaming them as necessary,
  413.         ;; and adding to the list of files to delete eventually.
  414.         (if file-name
  415.         (rmail-insert-inbox-text (list file-name) nil)
  416.           (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
  417.         ;; Scan the new text and convert each message to babyl format.
  418.         (goto-char (point-min))
  419.         (save-excursion
  420.           (setq new-messages (rmail-convert-to-babyl-format)))
  421.         (or (zerop new-messages)
  422.         (let (success)
  423.           (widen)
  424.           (search-backward "\^_")
  425.           (narrow-to-region (point) (point-max))
  426.           (goto-char (1+ (point-min)))
  427.           (rmail-count-new-messages)
  428.           (save-buffer)))
  429.         ;; Delete the old files, now that babyl file is saved.
  430.         (while delete-files
  431.           (condition-case ()
  432.           (delete-file (car delete-files))
  433.         (file-error nil))
  434.           (setq delete-files (cdr delete-files)))))
  435.     (if (= new-messages 0)
  436.         (progn (goto-char opoint)
  437.            (if (or file-name rmail-inbox-list)
  438.                (message "(No new mail has arrived)")))
  439.         (message "%d new message%s read"
  440.              new-messages (if (= 1 new-messages) "" "s"))))
  441.     ;; Don't leave the buffer screwed up if we get a disk-full error.
  442.     (rmail-show-message)))
  443.  
  444. (defun rmail-insert-inbox-text (files renamep)
  445.   (let (file tofile delete-files movemail)
  446.     (while files
  447.       (setq file (expand-file-name (substitute-in-file-name (car files)))
  448.         ;;>> un*x specific <<
  449.         tofile (concat file "~"))
  450.       ;; If getting from mail spool directory,
  451.       ;; use movemail to move rather than renaming.
  452.       (setq movemail (equal (file-name-directory file) rmail-spool-directory))
  453.       (if movemail
  454.       (progn
  455.         (setq tofile (expand-file-name
  456.                ".newmail"
  457.                (file-name-directory
  458.                  (expand-file-name rmail-file-name))))
  459.         ;; On some systems, /usr/spool/mail/foo is a directory
  460.         ;; and the actual inbox is /usr/spool/mail/foo/foo.
  461.         (if (file-directory-p file)
  462.         (setq file (expand-file-name (or (getenv "LOGNAME")
  463.                          (getenv "USER")
  464.                          (user-login-name))
  465.                          file)))))
  466.       (if (or (file-exists-p tofile) (file-exists-p file))
  467.       (message "Getting mail from %s..." file))
  468.       ;; Set TOFILE if have not already done so, and
  469.       ;; rename or copy the file FILE to TOFILE if and as appropriate.
  470.       (cond ((not renamep)
  471.          (setq tofile file))
  472.         ((or (file-exists-p tofile) (not (file-exists-p file)))
  473.          nil)
  474.         ((not movemail)
  475.          (rename-file file tofile nil))
  476.         (t
  477.          (let ((errors nil))
  478.            (unwind-protect
  479.            (save-excursion
  480.              (setq errors (generate-new-buffer " *rmail loss*"))
  481.              (buffer-flush-undo errors)
  482.              (call-process
  483.                (expand-file-name "movemail" exec-directory)
  484.                nil errors nil file tofile)
  485.              (if (not (buffer-modified-p errors))
  486.              ;; No output => movemail won
  487.              nil
  488.                (set-buffer errors)
  489.                (subst-char-in-region (point-min) (point-max)
  490.                          ?\n ?\  )
  491.                (goto-char (point-max))
  492.                (skip-chars-backward " \t")
  493.                (delete-region (point) (point-max))
  494.                (goto-char (point-min))
  495.                (if (looking-at "movemail: ")
  496.                (delete-region (point-min) (match-end 0)))
  497.                (signal 'file-error
  498.                    (list "movemail"
  499.                      (buffer-substring (point-min)
  500.                                (point-max))
  501.                      ;file tofile
  502.                      ))))
  503.          (if errors (kill-buffer errors))))))
  504.       ;; At this point, TOFILE contains the name to read:
  505.       ;; Either the alternate name (if we renamed)
  506.       ;; or the actual inbox (if not renaming).
  507.       (if (file-exists-p tofile)
  508.       (progn (goto-char (point-max))
  509.          (insert-file-contents tofile)
  510.          (goto-char (point-max))
  511.          (or (= (preceding-char) ?\n)
  512.              (insert ?\n))
  513.          (setq delete-files (cons tofile delete-files))))
  514.       (message "")
  515.       (setq files (cdr files)))
  516.     delete-files))
  517.  
  518. ;; the  rmail-break-forwarded-messages  feature is not implemented
  519. (defun rmail-convert-to-babyl-format ()
  520.   (let ((count 0) start
  521.     (case-fold-search nil))
  522.     (goto-char (point-min))
  523.     (save-restriction
  524.       (while (not (eobp))
  525.     (cond ((looking-at "Babyl Options:");Babyl header
  526.            (search-forward "\n\^_")
  527.            (delete-region (point-min) (point)))
  528.           ;; Babyl format message
  529.           ((looking-at "\^L")
  530.            (or (search-forward "\n\^_" nil t)
  531.            (progn
  532.              (message "Invalid Babyl format in inbox!")
  533.              (sit-for 1)
  534.              (goto-char (point-max))))
  535.            (setq count (1+ count))
  536.            (skip-chars-forward " \t\n")
  537.            (narrow-to-region (point) (point-max)))
  538.           ;;*** MMDF format
  539.           ((let ((case-fold-search t))
  540.          (looking-at mmdf-delim1))
  541.            (let ((case-fold-search t))
  542.          (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
  543.          (setq start (point))
  544.          (re-search-forward mmdf-delim2 nil t)
  545.          (replace-match "\^_"))
  546.            (save-excursion
  547.          (save-restriction
  548.            (narrow-to-region start (1- (point)))
  549.            (goto-char (point-min))
  550.            (while (search-forward "\n\^_" nil t) ; single char "\^_"
  551.              (replace-match "\n^_")))) ; 2 chars: "^" and "_"
  552.            (narrow-to-region (point) (point-max))
  553.            (setq count (1+ count)))
  554.           ;;*** Mail format
  555.           ((looking-at "^From ")
  556.            (setq start (point))
  557.            (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
  558.            (rmail-nuke-pinhead-header)
  559.            (if (re-search-forward
  560.             (concat "^[\^_]?\\("
  561.                 "From [^ \n]*\\(\\|\".*\"[^ \n]*\\)  ?[^ \n]* [^ \n]* *"
  562.                 "[0-9]* [0-9:]*\\( ?[A-Z]?[A-Z][A-Z]T\\| ?[-+]?[0-9][0-9][0-9][0-9]\\|\\) " ; EDT, -0500
  563.                 "19[0-9]* *$\\|"
  564.                 mmdf-delim1 "\\|"
  565.                 "^Babyl Options:\\|"
  566.                 "\^L\n[01],\\)") nil t)
  567.            (goto-char (match-beginning 1))
  568.          (goto-char (point-max)))
  569.            (setq count (1+ count))
  570.            (save-excursion
  571.          (save-restriction
  572.            (narrow-to-region start (point))
  573.            (goto-char (point-min))
  574.            (while (search-forward "\n\^_" nil t); single char
  575.              (replace-match "\n^_")))); 2 chars: "^" and "_"
  576.            (insert ?\^_)
  577.            (narrow-to-region (point) (point-max)))
  578.           ;;
  579.           ;;This is a kludge, in case we're wrong about mmdf not
  580.           ;;allowing anything in between.  If it loses, we'll have
  581.           ;;to look for something else
  582.           (t (delete-char 1)))))
  583.     count))
  584.  
  585. (defun rmail-nuke-pinhead-header ()
  586.   (save-excursion
  587.     (save-restriction
  588.       (let ((start (point))
  589.           (end (progn
  590.            (condition-case ()
  591.                (search-forward "\n\n")
  592.              (error
  593.               (goto-char (point-max))
  594.               (insert "\n\n")))
  595.            (point)))
  596.         has-from has-date)
  597.     (narrow-to-region start end)
  598.     (let ((case-fold-search t))
  599.       (goto-char start)
  600.       (setq has-from (search-forward "\nFrom:" nil t))
  601.       (goto-char start)
  602.       (setq has-date (and (search-forward "\nDate:" nil t) (point)))
  603.       (goto-char start))
  604.     (let ((case-fold-search nil))
  605.       (if (re-search-forward
  606.            "^From \\([^ ]*\\(\\|\".*\"[^ ]*\\)\\)  ?\\([^ ]*\\) \\([^ ]*\\) *\\([0-9]*\\) \\([0-9:]*\\)\\( ?[A-Z]?[A-Z][A-Z]T\\| ?[-+]?[0-9][0-9][0-9][0-9]\\|\\) 19\\([0-9]*\\) *\n" nil t)
  607.           (replace-match
  608.         (concat
  609.           ;; Keep and reformat the date if we don't
  610.           ;;  have a Date: field.
  611.           (if has-date
  612.               ""
  613.             ;; If no time zone specified, assume est.
  614.             (if (= (match-beginning 7) (match-end 7))
  615.             "Date: \\3, \\5 \\4 \\8 \\6 EST\n"
  616.             "Date: \\3, \\5 \\4 \\8 \\6\\7\n"))
  617.           ;; Keep and reformat the sender if we don't
  618.           ;; have a From: field.
  619.           (if has-from
  620.               ""
  621.             "From: \\1\n")))))))))
  622.  
  623. ;;;; *** Rmail Message Formatting and Header Manipulation ***
  624.  
  625. (defun rmail-reformat-message (beg end)
  626.   (goto-char beg)
  627.   (forward-line 1)
  628.   (if (/= (following-char) ?0)
  629.       (error "Bad format in RMAIL file."))
  630.   (let ((buffer-read-only nil)
  631.     (delta (- (buffer-size) end)))
  632.     (delete-char 1)
  633.     (insert ?1)
  634.     (forward-line 1)
  635.     (if (looking-at "Summary-line: ")
  636.     (forward-line 1))
  637.     (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
  638.     (delete-region (point)
  639.                (progn (forward-line 1) (point))))
  640.     (let ((str (buffer-substring (point)
  641.                  (save-excursion (search-forward "\n\n" end 'move)
  642.                          (point)))))
  643.       (insert str "*** EOOH ***\n")
  644.       (narrow-to-region (point) (- (buffer-size) delta)))
  645.     (goto-char (point-min))
  646.     (if rmail-ignored-headers (rmail-clear-headers))
  647.     (if rmail-message-filter (funcall rmail-message-filter))))
  648.  
  649. (defun rmail-clear-headers ()
  650.   (if (search-forward "\n\n" nil t)
  651.       (save-restriction
  652.         (narrow-to-region (point-min) (point))
  653.     (let ((buffer-read-only nil))
  654.       (while (let ((case-fold-search t))
  655.            (goto-char (point-min))
  656.            (re-search-forward rmail-ignored-headers nil t))
  657.         (beginning-of-line)
  658.         (delete-region (point)
  659.                (progn (re-search-forward "\n[^ \t]")
  660.                   (forward-char -1)
  661.                   (point))))))))
  662.  
  663. (defun rmail-toggle-header ()
  664.   "Show original message header if pruned header currently shown, or vice versa."
  665.   (interactive)
  666.   (rmail-maybe-set-message-counters)
  667.   (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
  668.   (let ((buffer-read-only nil))
  669.     (goto-char (point-min))
  670.     (forward-line 1)
  671.     (if (= (following-char) ?1)
  672.     (progn (delete-char 1)
  673.            (insert ?0)
  674.            (forward-line 1)
  675.            (if (looking-at "Summary-Line:")
  676.            (forward-line 1))
  677.            (insert "*** EOOH ***\n")
  678.            (forward-char -1)
  679.            (search-forward "\n*** EOOH ***\n")
  680.            (forward-line -1)
  681.            (let ((temp (point)))
  682.          (and (search-forward "\n\n" nil t)
  683.               (delete-region temp (point))))
  684.            (goto-char (point-min))
  685.            (search-forward "\n*** EOOH ***\n")
  686.            (narrow-to-region (point) (point-max)))
  687.       (rmail-reformat-message (point-min) (point-max)))))
  688.  
  689. ;;;; *** Rmail Attributes and Keywords ***
  690.  
  691. ;; Make a string describing current message's attributes and keywords
  692. ;; and set it up as the name of a minor mode
  693. ;; so it will appear in the mode line.
  694. (defun rmail-display-labels ()
  695.   (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
  696.     (save-excursion
  697.       (unwind-protect
  698.       (progn
  699.         (widen)
  700.         (goto-char (rmail-msgbeg rmail-current-message))
  701.         (forward-line 1)
  702.         (if (looking-at "[01],")
  703.         (progn
  704.           (narrow-to-region (point) (progn (end-of-line) (point)))
  705.           ;; Truly valid BABYL format requires a space before each
  706.           ;; attribute or keyword name.  Put them in if missing.
  707.           (let (buffer-read-only)
  708.             (goto-char (point-min))
  709.             (while (search-forward "," nil t)
  710.               (or (looking-at "[ ,]") (eobp)
  711.               (insert " "))))
  712.           (goto-char (point-max))
  713.           (if (search-backward ",," nil 'move)
  714.               (progn
  715.             (if (> (point) (1+ (point-min)))
  716.                 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
  717.             (if (> (- (point-max) (point)) 2)
  718.                 (setq blurb
  719.                   (concat blurb
  720.                       ";"
  721.                       (buffer-substring (+ (point) 3)
  722.                                 (1- (point-max)))))))))))
  723.     (narrow-to-region beg end)
  724.     (set-marker beg nil)
  725.     (set-marker end nil)))
  726.     (while (string-match " +," blurb)
  727.       (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
  728.               (substring blurb (match-end 0)))))
  729.     (while (string-match ", +" blurb)
  730.       (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
  731.               (substring blurb (match-end 0)))))
  732.     (setq mode-line-process
  733.       (concat " " rmail-current-message "/" rmail-total-messages
  734.           blurb))))
  735.  
  736. ;; Turn an attribute of the current message on or off according to STATE.
  737. ;; ATTR is the name of the attribute, as a string.
  738. (defun rmail-set-attribute (attr state)
  739.   (let ((omax (- (buffer-size) (point-max)))
  740.     (omin (- (buffer-size) (point-min)))
  741.     (buffer-read-only nil))
  742.     (unwind-protect
  743.     (save-excursion
  744.       (widen)
  745.       (goto-char (+ 3 (rmail-msgbeg rmail-current-message)))
  746.       (let ((curstate (search-backward (concat ", " attr ",")
  747.                        (prog1 (point) (end-of-line)) t)))
  748.         (or (eq curstate (not (not state)))
  749.         (if curstate
  750.             (delete-region (point) (1- (match-end 0)))
  751.           (beginning-of-line)
  752.           (forward-char 2)
  753.           (insert " " attr ","))))
  754.       (if (string= attr "deleted")
  755.           (rmail-set-message-deleted-p rmail-current-message state)))
  756.       (narrow-to-region (max 1 (- (buffer-size) omin))
  757.             (- (buffer-size) omax))
  758.       (rmail-display-labels))))
  759.  
  760. ;; Return t if the attributes/keywords line of msg number MSG
  761. ;; contains a match for the regexp LABELS.
  762. (defun rmail-message-labels-p (msg labels)
  763.   (goto-char (rmail-msgbeg msg))
  764.   (forward-char 3)
  765.   (re-search-backward labels (prog1 (point) (end-of-line)) t))
  766.  
  767. ;;;; *** Rmail Message Selection And Support ***
  768.  
  769. (defun rmail-msgend (n)
  770.   (marker-position (aref rmail-message-vector (1+ n))))
  771.  
  772. (defun rmail-msgbeg (n)
  773.   (marker-position (aref rmail-message-vector n)))
  774.  
  775. (defun rmail-widen-to-current-msgbeg (function)
  776.   "Call FUNCTION with point at start of internal data of current message.
  777. Assumes that bounds were previously narrowed to display the message in Rmail.
  778. The bounds are widened enough to move point where desired,
  779. then narrowed again afterward.
  780. Assumes that the visible text of the message is not changed by FUNCTION."
  781.   (save-excursion
  782.     (let ((obeg (- (point-max) (point-min)))
  783.       (unwind-protect
  784.       (progn
  785.         (narrow-to-region (rmail-msgbeg rmail-current-message)
  786.                   (point-max))
  787.         (goto-char (point-min))
  788.         (funcall function))
  789.     (narrow-to-region (- (point-max) obeg) (point-max)))))))
  790.  
  791. (defun rmail-forget-messages ()
  792.   (unwind-protect
  793.       (if (vectorp rmail-message-vector)
  794.       (let* ((i 0)
  795.          (v rmail-message-vector)
  796.          (n (length v)))
  797.         (while (< i n)
  798.           (move-marker (aref v i)  nil)
  799.           (setq i (1+ i)))))
  800.     (setq rmail-message-vector nil)
  801.     (setq rmail-deleted-vector nil)))
  802.  
  803. (defun rmail-maybe-set-message-counters ()
  804.   (if (not (and rmail-deleted-vector
  805.         rmail-message-vector
  806.         rmail-current-message
  807.         rmail-total-messages))
  808.       (rmail-set-message-counters)))
  809.  
  810. (defun rmail-count-new-messages (&optional nomsg)
  811.   (let* ((case-fold-search nil)
  812.      (total-messages 0)
  813.      (messages-head nil)
  814.      (deleted-head nil))
  815.     (or nomsg (message "Counting new messages..."))
  816.     (goto-char (point-max))
  817.     ;; Put at the end of messages-head
  818.     ;; the entry for message N+1, which marks
  819.     ;; the end of message N.  (N = number of messages).
  820.     (search-backward "\^_")
  821.     (setq messages-head (list (point-marker)))
  822.     (rmail-set-message-counters-counter (point-min))
  823.     (setq rmail-current-message (1+ rmail-total-messages))
  824.     (setq rmail-total-messages
  825.       (+ rmail-total-messages total-messages))
  826.     (setq rmail-message-vector
  827.       (vconcat rmail-message-vector (cdr messages-head)))
  828.     (aset rmail-message-vector
  829.       rmail-current-message (car messages-head))
  830.     (setq rmail-deleted-vector
  831.       (concat rmail-deleted-vector deleted-head))
  832.     (setq rmail-summary-vector
  833.       (vconcat rmail-summary-vector (make-vector total-messages nil)))
  834.     (goto-char (point-min))
  835.     (or nomsg (message "Counting new messages...done (%d)" total-messages))))
  836.  
  837. (defun rmail-set-message-counters ()
  838.   (rmail-forget-messages)
  839.   (save-excursion
  840.     (save-restriction
  841.       (widen)
  842.       (let* ((point-save (point))
  843.          (total-messages 0)
  844.          (messages-after-point)
  845.          (case-fold-search nil)
  846.          (messages-head nil)
  847.          (deleted-head nil))
  848.     (message "Counting messages...")
  849.     (goto-char (point-max))
  850.     ;; Put at the end of messages-head
  851.     ;; the entry for message N+1, which marks
  852.     ;; the end of message N.  (N = number of messages).
  853.     (search-backward "\^_")
  854.     (setq messages-head (list (point-marker)))
  855.     (rmail-set-message-counters-counter (min (point) point-save))
  856.     (setq messages-after-point total-messages)
  857.     (rmail-set-message-counters-counter)
  858.     (setq rmail-total-messages total-messages)
  859.     (setq rmail-current-message
  860.           (min total-messages
  861.            (max 1 (- total-messages messages-after-point))))
  862.     (setq rmail-message-vector
  863.           (apply 'vector (cons (point-min-marker) messages-head))
  864.           rmail-deleted-vector (concat "D" deleted-head)
  865.           rmail-summary-vector (make-vector rmail-total-messages nil))
  866.     (message "Counting messages...done")))))
  867.     
  868. (defun rmail-set-message-counters-counter (&optional stop)
  869.   (while (search-backward "\^_\^L\n" stop t)
  870.     (setq messages-head (cons (point-marker) messages-head))
  871.     (save-excursion
  872.       (setq deleted-head
  873.         (cons (if (search-backward ", deleted,"
  874.                        (prog1 (point)
  875.                      (forward-line 2))
  876.                        t)
  877.               ?D ?\ )
  878.           deleted-head)))
  879.     (if (zerop (% (setq total-messages (1+ total-messages)) 20))
  880.     (message "Counting messages...%d" total-messages))))
  881.  
  882. (defun rmail-beginning-of-message ()
  883.   "Show current message starting from the beginning."
  884.   (interactive)
  885.   (rmail-show-message rmail-current-message))
  886.  
  887. (defun rmail-show-message (&optional n)
  888.   "Show message number N (prefix argument), counting from start of file."
  889.   (interactive "p")
  890.   (rmail-maybe-set-message-counters)
  891.   (widen)
  892.   (if (zerop rmail-total-messages)
  893.       (progn (narrow-to-region (point-min) (1- (point-max)))
  894.          (goto-char (point-min))
  895.          (setq mode-line-process nil))
  896.     (let (blurb)
  897.       (if (not n)
  898.       (setq n rmail-current-message)
  899.     (cond ((<= n 0)
  900.            (setq n 1
  901.              rmail-current-message 1
  902.              blurb "No previous message"))
  903.           ((> n rmail-total-messages)
  904.            (setq n rmail-total-messages
  905.              rmail-current-message rmail-total-messages
  906.              blurb "No following message"))
  907.           (t
  908.            (setq rmail-current-message n))))
  909.       (let ((beg (rmail-msgbeg n))
  910.         (end (rmail-msgend n)))
  911.     (goto-char beg)
  912.     (forward-line 1)
  913.     (if (= (following-char) ?0)
  914.         (progn
  915.           (rmail-reformat-message beg end)
  916.           (rmail-set-attribute "unseen" nil))
  917.       (search-forward "\n*** EOOH ***\n" end t)
  918.       (narrow-to-region (point) end))
  919.     (goto-char (point-min))
  920.     (rmail-display-labels)
  921.     (run-hooks 'rmail-show-message-hook)
  922.     (if blurb
  923.         (message blurb))))))
  924.  
  925. (defun rmail-next-message (n)
  926.   "Show following message whether deleted or not.
  927. With prefix argument N, moves forward N messages,
  928. or backward if N is negative."
  929.   (interactive "p")
  930.   (rmail-maybe-set-message-counters)
  931.   (rmail-show-message (+ rmail-current-message n)))
  932.  
  933. (defun rmail-previous-message (n)
  934.   "Show previous message whether deleted or not.
  935. With prefix argument N, moves backward N messages,
  936. or forward if N is negative."
  937.   (interactive "p")
  938.   (rmail-next-message (- n)))  
  939.  
  940. (defun rmail-next-undeleted-message (n)
  941.   "Show following non-deleted message.
  942. With prefix argument N, moves forward N non-deleted messages,
  943. or backward if N is negative."
  944.   (interactive "p")
  945.   (rmail-maybe-set-message-counters)
  946.   (let ((lastwin rmail-current-message)
  947.     (current rmail-current-message))
  948.     (while (and (> n 0) (< current rmail-total-messages))
  949.       (setq current (1+ current))
  950.       (if (not (rmail-message-deleted-p current))
  951.       (setq lastwin current n (1- n))))
  952.     (while (and (< n 0) (> current 1))
  953.       (setq current (1- current))
  954.       (if (not (rmail-message-deleted-p current))
  955.       (setq lastwin current n (1+ n))))
  956.     (if (/= lastwin rmail-current-message)
  957.     (rmail-show-message lastwin))
  958.     (if (< n 0)
  959.     (message "No previous nondeleted message"))
  960.     (if (> n 0)
  961.     (message "No following nondeleted message"))))
  962.  
  963. (defun rmail-previous-undeleted-message (n)
  964.   "Show previous non-deleted message.
  965. With prefix argument N, moves backward N non-deleted messages,
  966. or forward if N is negative."
  967.   (interactive "p")
  968.   (rmail-next-undeleted-message (- n)))
  969.  
  970. (defun rmail-last-message ()
  971.   "Show last message in file."
  972.   (interactive)
  973.   (rmail-maybe-set-message-counters)
  974.   (rmail-show-message rmail-total-messages))
  975.  
  976. (defun rmail-what-message ()
  977.   (let ((where (point))
  978.     (low 1)
  979.     (high rmail-total-messages)
  980.     (mid (/ rmail-total-messages 2)))
  981.     (while (> (- high low) 1)
  982.       (if (>= where (rmail-msgbeg mid))
  983.       (setq low mid)
  984.     (setq high mid))
  985.       (setq mid (+ low (/ (- high low) 2))))
  986.     (if (>= where (rmail-msgbeg high)) high low)))
  987.  
  988. (defvar rmail-search-last-regexp nil)
  989. (defun rmail-search (regexp &optional reversep)
  990.   "Show message containing next match for REGEXP.
  991. Search in reverse (earlier messages) with non-nil 2nd arg REVERSEP.
  992. Interactively, empty argument means use same regexp used last time,
  993. and reverse search is specified by a negative numeric arg."
  994.   (interactive
  995.     (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
  996.        (prompt (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  997.        regexp)
  998.       (if rmail-search-last-regexp
  999.       (setq prompt (concat prompt
  1000.                    "(default "
  1001.                    rmail-search-last-regexp
  1002.                    ") ")))
  1003.       (setq regexp (read-string prompt))
  1004.       (cond ((not (equal regexp ""))
  1005.          (setq rmail-search-last-regexp regexp))
  1006.         ((not rmail-search-last-regexp)
  1007.          (error "No previous Rmail search string")))
  1008.       (list rmail-search-last-regexp reversep)))
  1009.   (message "%sRmail search for %s..."
  1010.        (if reversep "Reverse " "")
  1011.        regexp)
  1012.   (let ((omin (point-min))
  1013.     (omax (point-max))
  1014.     (opoint (point))
  1015.     win
  1016.     (msg rmail-current-message))
  1017.     (unwind-protect
  1018.     (progn
  1019.       (widen)
  1020.       ;; Check messages one by one, advancing message number up or down
  1021.       ;; but searching forward through each message.
  1022.       (if reversep
  1023.           (while (and (null win) (> msg 1))
  1024.         (goto-char (rmail-msgbeg (setq msg (1- msg))))
  1025.         (setq win (re-search-forward
  1026.                regexp (rmail-msgend msg) t)))
  1027.         (while (and (null win) (< msg rmail-total-messages))
  1028.           (goto-char (rmail-msgbeg (setq msg (1+ msg))))
  1029.           (setq win (re-search-forward regexp (rmail-msgend msg) t)))))
  1030.       (if win
  1031.       (progn
  1032.         ;; If this is a reverse search and we found a message,
  1033.         ;; search backward thru this message to position point.
  1034.         (if reversep
  1035.         (progn
  1036.           (goto-char (rmail-msgend msg))
  1037.           (re-search-backward
  1038.            regexp (rmail-msgbeg msg) t)))
  1039.         (setq win (point))
  1040.         (rmail-show-message msg)
  1041.         (message "%sRmail search for %s...done"
  1042.              (if reversep "Reverse " "")
  1043.              regexp)
  1044.         (goto-char win))
  1045.     (goto-char opoint)
  1046.     (narrow-to-region omin omax)
  1047.     (ding)
  1048.     (message "Searched failed: %s" regexp)))))
  1049.  
  1050. ;;;; *** Rmail Message Deletion Commands ***
  1051.  
  1052. (defun rmail-message-deleted-p (n)
  1053.   (= (aref rmail-deleted-vector n) ?D))
  1054.  
  1055. (defun rmail-set-message-deleted-p (n state)
  1056.   (aset rmail-deleted-vector n (if state ?D ?\ )))
  1057.  
  1058. (defun rmail-delete-message ()
  1059.   "Delete this message and stay on it."
  1060.   (interactive)
  1061.   (rmail-set-attribute "deleted" t))
  1062.  
  1063. (defun rmail-undelete-previous-message ()
  1064.   "Back up to deleted message, select it, and undelete it."
  1065.   (interactive)
  1066.   (let ((msg rmail-current-message))
  1067.     (while (and (> msg 0)
  1068.         (not (rmail-message-deleted-p msg)))
  1069.       (setq msg (1- msg)))
  1070.     (if (= msg 0)
  1071.     (error "No previous deleted message")
  1072.       (if (/= msg rmail-current-message)
  1073.       (rmail-show-message msg))
  1074.       (rmail-set-attribute "deleted" nil))))
  1075.  
  1076. (defun rmail-delete-forward (&optional backward)
  1077.   "Delete this message and move to next nondeleted one.
  1078. Deleted messages stay in the file until the \\[rmail-expunge] command is given.
  1079. With prefix argument, delete and move backward."
  1080.   (interactive "P")
  1081.   (rmail-set-attribute "deleted" t)
  1082.   (rmail-next-undeleted-message (if backward -1 1)))
  1083.  
  1084. (defun rmail-delete-backward ()
  1085.   "Delete this message and move to previous nondeleted one.
  1086. Deleted messages stay in the file until the \\[rmail-expunge] command is given."
  1087.   (interactive)
  1088.   (rmail-delete-forward t))
  1089.  
  1090. (defun rmail-expunge ()
  1091.   "Actually erase all deleted messages in the file."
  1092.   (interactive)
  1093.   (message "Expunging deleted messages...")
  1094.   (rmail-maybe-set-message-counters)
  1095.   (let* ((omax (- (buffer-size) (point-max)))
  1096.      (omin (- (buffer-size) (point-min)))
  1097.      (opoint (if (and (> rmail-current-message 0)
  1098.               (= ?D (aref rmail-deleted-vector rmail-current-message)))
  1099.              0 (- (point) (point-min))))
  1100.      (messages-head (cons (aref rmail-message-vector 0) nil))
  1101.      (messages-tail messages-head)
  1102.      (win))
  1103.     (unwind-protect
  1104.     (save-excursion
  1105.       (widen)
  1106.       (goto-char (point-min))
  1107.       (let ((counter 0)
  1108.         (number 1)
  1109.         (total rmail-total-messages)
  1110.         (new-message-number rmail-current-message)
  1111.         (new-summary nil)
  1112.         (buffer-read-only nil)
  1113.         (messages rmail-message-vector)
  1114.         (deleted rmail-deleted-vector)
  1115.         (summary rmail-summary-vector))
  1116.         (setq rmail-total-messages nil
  1117.           rmail-current-message nil
  1118.           rmail-message-vector nil
  1119.           rmail-deleted-vector nil
  1120.           rmail-summary-vector nil)
  1121.         (while (<= number total)
  1122.           (if (= (aref deleted number) ?D)
  1123.           (progn
  1124.             (delete-region
  1125.               (marker-position (aref messages number))
  1126.               (marker-position (aref messages (1+ number))))
  1127.             (move-marker (aref messages number) nil)
  1128.             (if (> new-message-number counter)
  1129.             (setq new-message-number (1- new-message-number))))
  1130.         (setq counter (1+ counter))
  1131.         (setq messages-tail
  1132.               (setcdr messages-tail
  1133.                   (cons (aref messages number) nil)))
  1134.         (setq new-summary
  1135.               (cons (if (= counter number) (aref summary (1- number)))
  1136.                 new-summary)))
  1137.           (if (zerop (% (setq number (1+ number)) 20))
  1138.           (message "Expunging deleted messages...%d" number)))
  1139.         (setq messages-tail
  1140.           (setcdr messages-tail
  1141.               (cons (aref messages number) nil)))
  1142.         (setq rmail-current-message new-message-number
  1143.           rmail-total-messages counter
  1144.           rmail-message-vector (apply 'vector messages-head)
  1145.           rmail-deleted-vector (make-string (1+ counter) ?\ )
  1146.           rmail-summary-vector (vconcat (nreverse new-summary))
  1147.           win t)))
  1148.       (message "Expunging deleted messages...done")
  1149.       (if (not win)
  1150.       (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
  1151.       (rmail-show-message
  1152.        (if (zerop rmail-current-message) 1 nil))
  1153.       (forward-char opoint))))
  1154.  
  1155. ;;;; *** Rmail Mailing Commands ***
  1156.  
  1157. (defun rmail-mail ()
  1158.   "Send mail in another window.
  1159. While composing the message, use \\[mail-yank-original] to yank the
  1160. original message into it."
  1161.   (interactive)
  1162.   (mail-other-window nil nil nil nil nil (current-buffer)))
  1163.  
  1164. (defun rmail-continue ()
  1165.   "Continue composing outgoing message previously being composed."
  1166.   (interactive)
  1167.   (mail-other-window t))
  1168.  
  1169. (defun rmail-reply (just-sender)
  1170.   "Reply to the current message.
  1171. Normally include CC: to all other recipients of original message;
  1172. prefix argument means ignore them.
  1173. While composing the reply, use \\[mail-yank-original] to yank the
  1174. original message into it."
  1175.   (interactive "P")
  1176.   ;;>> this gets set even if we abort. Can't do anything about it, though.
  1177.   (rmail-set-attribute "answered" t)
  1178.   (rmail-display-labels)
  1179.   (let (from reply-to cc subject date to message-id resent-reply-to)
  1180.     (save-excursion
  1181.       (save-restriction
  1182.     (widen)
  1183.     (goto-char (rmail-msgbeg rmail-current-message))
  1184.     (forward-line 1)
  1185.     (if (= (following-char) ?0)
  1186.         (narrow-to-region
  1187.          (progn (forward-line 2)
  1188.             (point))
  1189.          (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
  1190.                     'move)
  1191.             (point)))
  1192.       (narrow-to-region (point)
  1193.                 (progn (search-forward "\n*** EOOH ***\n")
  1194.                    (beginning-of-line) (point))))
  1195.     (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
  1196.           from (mail-fetch-field "from")
  1197.           reply-to (or resent-reply-to
  1198.                (mail-fetch-field "reply-to" nil t)
  1199.                from)
  1200.           cc (cond (just-sender nil)
  1201.                (resent-reply-to (mail-fetch-field "resent-cc" t))
  1202.                (t (mail-fetch-field "cc" nil t)))
  1203.           subject (or (and resent-reply-to
  1204.                    (mail-fetch-field "resent-subject" t))
  1205.               (mail-fetch-field "subject"))
  1206.           date (cond (resent-reply-to
  1207.               (mail-fetch-field "resent-date" t))
  1208.              ((mail-fetch-field "date")))
  1209.           to (cond (resent-reply-to
  1210.             (mail-fetch-field "resent-to" t))
  1211.                ((mail-fetch-field "to" nil t))
  1212.                ;((mail-fetch-field "apparently-to")) ack gag barf
  1213.                (t ""))
  1214.           message-id (cond (resent-reply-to
  1215.                 (mail-fetch-field "resent-message-id" t))
  1216.                    ((mail-fetch-field "message-id"))))))
  1217.     (and subject
  1218.      (string-match "\\`Re: " subject)
  1219.      (setq subject (substring subject 4)))
  1220.     (mail-other-window nil
  1221.       (mail-strip-quoted-names reply-to)
  1222.       subject
  1223.       (rmail-make-in-reply-to-field from date message-id)
  1224.       (if just-sender
  1225.       nil
  1226.     (let* ((cc-list (rmail-dont-reply-to
  1227.               (mail-strip-quoted-names
  1228.                 (if (null cc) to (concat to ", " cc))))))
  1229.       (if (string= cc-list "") nil cc-list)))
  1230.       (current-buffer))))
  1231.  
  1232. (defun rmail-make-in-reply-to-field (from date message-id)
  1233.   (if mail-use-rfc822 (require 'rfc822))
  1234.   (let (field)
  1235.     (if (and mail-use-rfc822 from)
  1236.     (let ((tem (car (rfc822-addresses from))))
  1237.       (and message-id
  1238.            (setq field (if (string-match
  1239.                  (regexp-quote
  1240.                    (if (string-match "@[^@]*\\'" tem)
  1241.                        (substring tem
  1242.                           0 (match-beginning 0))
  1243.                        tem))
  1244.                  message-id)
  1245.                    message-id
  1246.                    (concat message-id " \"" tem "\""))
  1247.              message-id nil date nil))
  1248.       (or field
  1249.           (setq field (prin1-to-string tem))))
  1250. ;    (if message-id
  1251. ;        (setq field message-id message-id nil date nil)
  1252. ;        (setq field (car (rfc882-addresses from))))
  1253.     )
  1254.     (or field
  1255.     (not from)
  1256.     ;; Compute the sender for the in-reply-to; prefer full name.
  1257.     (let* ((stop-pos (string-match "  *at \\|  *@ \\|  *<" from))
  1258.            (start-pos (if stop-pos 0
  1259.                 ;;>> this loses on nested ()'s
  1260.                 (let ((pos (string-match " *(" from)))
  1261.                   (if (not pos) nil
  1262.                 (setq stop-pos (string-match ")" from pos))
  1263.                 (if (zerop pos) 0 (+ 2 pos)))))))
  1264.       (setq field (if stop-pos
  1265.               (substring from start-pos stop-pos)
  1266.               from))))
  1267.     (if date (setq field (concat field "'s message of " date)))
  1268.     (if message-id (setq field (concat field " " message-id)))
  1269.     field))
  1270.  
  1271. (defun rmail-forward ()
  1272.   "Forward the current message to another user."
  1273.   (interactive)
  1274.   ;;>> this gets set even if we abort. Can't do anything about it, though.
  1275.   (rmail-set-attribute "forwarded" t)
  1276.   (let ((forward-buffer (current-buffer))
  1277.     (subject (concat "["
  1278.              (mail-strip-quoted-names (mail-fetch-field "From"))
  1279.              ": " (or (mail-fetch-field "Subject") "") "]")))
  1280.     ;; If only one window, use it for the mail buffer.
  1281.     ;; Otherwise, use another window for the mail buffer
  1282.     ;; so that the Rmail buffer remains visible
  1283.     ;; and sending the mail will get back to it.
  1284.     (if (if (one-window-p t)
  1285.         (mail nil nil subject)
  1286.       (mail-other-window nil nil subject))
  1287.     (save-excursion
  1288.       (goto-char (point-max))
  1289.       (forward-line 1)
  1290.       (insert-buffer forward-buffer)))))
  1291.  
  1292. ;;;; *** Rmail Specify Inbox Files ***
  1293.  
  1294. (autoload 'set-rmail-inbox-list "rmailmsc"
  1295.   "Set the inbox list of the current RMAIL file to FILE-NAME.
  1296. This may be a list of file names separated by commas.
  1297. If FILE-NAME is empty, remove any inbox list."
  1298.   t)
  1299.  
  1300. ;;;; *** Rmail Commands for Labels ***
  1301.  
  1302. (autoload 'rmail-add-label "rmailkwd"
  1303.   "Add LABEL to labels associated with current RMAIL message.
  1304. Completion is performed over known labels when reading."
  1305.   t)
  1306.  
  1307. (autoload 'rmail-kill-label "rmailkwd"
  1308.   "Remove LABEL from labels associated with current RMAIL message.
  1309. Completion is performed over known labels when reading."
  1310.   t)
  1311.  
  1312. (autoload 'rmail-next-labeled-message "rmailkwd"
  1313.   "Show next message with LABEL.  Defaults to last label used.
  1314. With prefix argument N moves forward N messages with this label."
  1315.   t)
  1316.  
  1317. (autoload 'rmail-previous-labeled-message "rmailkwd"
  1318.   "Show previous message with LABEL.  Defaults to last label used.
  1319. With prefix argument N moves backward N messages with this label."
  1320.   t)
  1321.  
  1322. ;;;; *** Rmail Edit Mode ***
  1323.  
  1324. (autoload 'rmail-edit-current-message "rmailedit"
  1325.   "Edit the contents of the current message"
  1326.   t)
  1327.  
  1328. ;;;; *** Rmail Summary Mode ***
  1329.  
  1330. (autoload 'rmail-summary "rmailsum"
  1331.   "Display a summary of all messages, one line per message."
  1332.   t)
  1333.  
  1334. (autoload 'rmail-summary-by-labels "rmailsum"
  1335.   "Display a summary of all messages with one or more LABELS.
  1336. LABELS should be a string containing the desired labels, separated by commas."
  1337.   t)
  1338.  
  1339. (autoload 'rmail-summary-by-recipients "rmailsum"
  1340.   "Display a summary of all messages with the given RECIPIENTS.
  1341. Normally checks the To, From and Cc fields of headers;
  1342. but if PRIMARY-ONLY is non-nil (prefix arg given),
  1343.  only look in the To and From fields.
  1344. RECIPIENTS is a string of names separated by commas."
  1345.   t)
  1346.  
  1347. ;;;; *** Rmail output messages to files ***
  1348.  
  1349. (autoload 'rmail-output-to-rmail-file "rmailout"
  1350.   "Append the current message to an Rmail file named FILE-NAME.
  1351. If the file does not exist, ask if it should be created.
  1352. If file is being visited, the message is appended to the Emacs
  1353. buffer visiting that file."
  1354.   t)
  1355.  
  1356. (autoload 'rmail-output "rmailout"
  1357.   "Append this message to Unix mail file named FILE-NAME."
  1358.   t)
  1359.  
  1360. ;;;; *** Rmail undigestification ***
  1361.  
  1362. (autoload 'undigestify-rmail-message "undigest"
  1363.   "Break up a digest message into its constituent messages.
  1364. Leaves original message, deleted, before the undigestified messages."
  1365.   t)
  1366.