home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / vm / vm.el < prev    next >
Encoding:
Text File  |  1989-09-11  |  64.3 KB  |  1,731 lines

  1. ;;; UNIX style mail reader for GNU Emacs
  2. ;;; Copyright (C) 1989 Kyle E. Jones
  3. ;;;
  4. ;;; This program is free software; you can redistribute it and/or modify
  5. ;;; it under the terms of the GNU General Public License as published by
  6. ;;; the Free Software Foundation; either version 1, or (at your option)
  7. ;;; any later version.
  8. ;;;
  9. ;;; This program is distributed in the hope that it will be useful,
  10. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;;; GNU General Public License for more details.
  13. ;;;
  14. ;;; You should have received a copy of the GNU General Public License
  15. ;;; along with this program; if not, write to the Free Software
  16. ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. ;; This is a set of Emacs-Lisp commands and support functions for
  19. ;; reading mail.  While a mail reader (RMAIL) is distributed with GNU
  20. ;; Emacs it converts a user's mailbox to BABYL format, a behavior I
  21. ;; find quite unpalatable.
  22. ;;
  23. ;; VM is similar to RMAIL in that it scoops mail from the system mailbox
  24. ;; into a primary inbox for reading, but the similarity ends there.
  25. ;; VM does not reformat the mailbox beyond reordering the headers
  26. ;; according to user preference, and adding a header used internally to
  27. ;; store message attributes.
  28. ;;
  29. ;; Entry points to VM are the commands vm and vm-visit-folder.
  30. ;;
  31. ;; If autoloading then the lines:
  32. ;;   (autoload 'vm "vm" nil t)
  33. ;;   (autoload 'vm-visit-folder "vm" nil t)
  34. ;; should appear in a user's .emacs or in default.el in the lisp
  35. ;; directory of the Emacs distribution.
  36. ;;
  37. ;; VM requires Emacs' etc/movemail to work on your system.
  38.  
  39. (provide 'vm)
  40.  
  41. (defvar vm-primary-inbox "~/INBOX"
  42.   "*Mail is moved from the system mailbox to this file for reading.")
  43.  
  44. (defvar vm-crash-box "~/INBOX.CRASH"
  45.   "*File in which to store mail temporarily while it is transferrred from
  46. the system mailbox to the primary inbox.  If the something happens
  47. during this mail transfer, any missing mail will be found in this file.
  48. VM will do crash recovery from this file automatically at startup, as
  49. necessary.")
  50.  
  51. (defvar vm-spool-files nil
  52.   "*If non-nil this variable's value should be a list of strings naming files
  53. that VM will check for incoming mail instead of the where VM thinks your
  54. system mailbox is.  This variable can be used to specify multiple spool files
  55. or to point VM in the right direction if its notion of your system mailbox is
  56. incorrect.")
  57.  
  58. (defvar vm-visible-headers
  59.   '("From:" "Sender:" "To:" "Apparently-To:" "Cc:" "Subject:" "Date:")
  60.   "*List of headers that should be visible when VM first displays a message.
  61. These should be listed in the order you wish them presented.
  62. Regular expressions are allowed.")
  63.  
  64. (defvar vm-highlighted-header-regexp nil
  65.   "*Regular expression that matches the beginnings of headers that should
  66. be highlighted when a message is first presented.  For exmaple setting
  67. this variable to \"^From\\\\|^Subject\" causes the From: and Subject:
  68. headers to be highlighted.")
  69.  
  70. (defvar vm-preview-lines 0
  71.   "*Non-nil value N causes VM to display the visible headers + N lines of text
  72. from a message when it is first presented.  The message is not actually marked
  73. as read until the message is exposed in its entirety.  Nil causes VM not to
  74. preview a message at all; it is displayed in its entirety when first
  75. presented and is marked as read.")
  76.  
  77. (defvar vm-preview-read-messages t
  78.   "*Non-nil value means to preview messages, even if they've already been read.
  79. A nil value causes VM to preview messages only if new or unread.")
  80.  
  81. (defvar vm-folder-type nil
  82.   "*Value specifies the type of mail folder VM should expect to read and
  83. write.  Nil means expect the UNIX style folders characterized by the
  84. \"\\n\\nFrom \" message separators.  The only other supported value for
  85. this variable is the symbol `mmdf' which causes VM to use
  86. \"^A^A^A^A\\n\" MMDF style leaders and trailers.")
  87.  
  88. (defvar vm-folder-directory nil
  89.   "*Directory where folders of mail are kept.")
  90.  
  91. (defvar vm-confirm-new-folders nil
  92.   "*Non-nil value causes interactive calls to vm-save-message
  93. to ask for confirmation before creating a new folder.")
  94.  
  95. (defvar vm-delete-empty-folders t
  96.   "*Non-nil value causes VM to remove empty (zero length) folder files
  97. after saving them.")
  98.  
  99. (defvar vm-included-text-prefix " > "
  100.   "*String used to prefix included text in replies.")
  101.  
  102. (defvar vm-auto-folder-alist nil
  103.   "*Non-nil value should be an alist that VM will use to choose a default
  104. folder name when messages are saved.  The alist should be of the form
  105. \((HEADER-NAME
  106.    (REGEXP . FOLDER-NAME) ...
  107.   ...))
  108. where HEADER-NAME and REGEXP are strings, and FOLDER-NAME is a string or an s-expression that evaluates to a string.
  109.  
  110. If any part of the contents of the message header named by HEADER-NAME
  111. is matched by the regular expression REGEXP, VM will evaluate the
  112. corresponding FOLDER-NAME and use the result as the default when
  113. prompting for a folder to save the message in.  If trhe resulting folder
  114. name is a relative pathname, then it will resolve to the directory named by
  115. vm-folder-directory, or the default-directory of the currently visited
  116. folder if vm-folder-directory is nil.
  117.  
  118. When FOLDER-NAME is evaluated, the current buffer will contain only the
  119. contents of the header named by HEADER-NAME.  It is safe to modify this
  120. buffer.  You can use the match data from any \\( ... \\) grouping
  121. constructs in REGEXP along with the function buffer-substring to build a
  122. folder name based on the header information.
  123.  
  124. Matching is case sensitive.")
  125.  
  126. (defvar vm-visit-when-saving nil
  127.   "*Non-nil causes VM to visit folders when saving messages.  This means
  128. VM will read the folder into Emacs and append the message to the buffer
  129. instead of appending to the folder file directly.  This behavior is
  130. ideal when folders are encrypted or compressed since appending plaintext
  131. to such files is a ghastly mistake.
  132.  
  133. Note the setting of this variable does not affect how the primary inbox
  134. is accessed, i.e. the primary inbox must be a plaintext file.")
  135.  
  136. (defvar vm-in-reply-to-format "%i"
  137.   "*String which specifies the format of the contents of the In-Reply-To
  138. header that is generated for replies.  See the documentation for the
  139. variable vm-summary-format for information on what this string may
  140. contain.  The format should *not* end with a newline.
  141. Nil means don't put an In-Reply-To: header in replies.")
  142.  
  143. (defvar vm-included-text-attribution-format "%F writes:\n"
  144.   "*String which specifies the format of the attribution that precedes the
  145. included text from a message in a reply.  See the documentation for the
  146. variable vm-summary-format for information on what this string may contain.
  147. Nil means don't attribute included text in replies.")
  148.  
  149. (defvar vm-forwarding-subject-format "forwarded message from %F"
  150.   "*String which specifies the format of the contents of the Subject
  151. header that is generated for a forwarded message.  See the documentation
  152. for the variable vm-summary-format for information on what this string
  153. may contain.  The format should *not* end with a newline.  Nil means
  154. leave the Subject header empty when forwarding.")
  155.  
  156. (defvar vm-summary-format "%2n %a %-17.17F %3m %2d %3l/%-5c \"%s\"\n"
  157.   "*String which specifies the message summary line format.
  158. The string may contain the printf-like `%' conversion specifiers which
  159. substitute information about the message into the final summary line.
  160.  
  161. Recognized specifiers are:
  162.    a - attribute indicators (always three characters wide)
  163.        The first char is  `D', `N', `U' or ` ' for deleted, new, unread
  164.        and read message respectively.
  165.        The second char is `F' for filed (saved) messages.
  166.        The third char is `R' if the message has been replied to.
  167.    c - number of characters in message (ignoring headers)
  168.    d - date of month message sent
  169.    f - author's address
  170.    F - author's full name (same as f if full name not found)
  171.    h - hour message sent
  172.    i - message ID
  173.    l - number of lines in message (ignoring headers)
  174.    m - month message sent
  175.    n - message number
  176.    s - message subject
  177.    w - day of the week message sent
  178.    y - year message sent
  179.    z - timezone of date when the message was sent
  180.  
  181. Use %% to get a single %.
  182.  
  183. A numeric field width may be specified between the `%' and the specifier;
  184. this causes right justification of the substituted string.  A negative field
  185. width causes left justification.
  186.  
  187. The field width may be followed by a `.' and a number specifying the maximum
  188. allowed length of the substituted string.  If the string is longer than this
  189. value it is truncated.
  190.  
  191. The summary format need not be one line per message but it must end with
  192. a newline, otherwise the message pointer will not be displayed correctly
  193. in the summary window.")
  194.  
  195. (defvar vm-mail-window-percentage 75
  196.   "*Percentage of the screen that should be used to show mail messages.
  197. The rest of the screen will be used by the summary buffer, if displayed.")
  198.  
  199. (defvar vm-mutable-windows t
  200.   "*This variable's value controls VM's window usage.
  201.  
  202. A value of t gives VM free run of the Emacs display; it will commandeer
  203. the entire screen for its purposes.
  204.  
  205. A value of nil restricts VM's window usage to the window from which
  206. it was invoked.  VM will not create, delete, or use any other windows,
  207. nor will it resize it's own window.
  208.  
  209. A value that is neither t nor nil allows VM to use other windows, but it
  210. will not create new ones, or resize or delete the current ones.")
  211.  
  212. (defvar vm-startup-with-summary nil
  213.   "*Value tells VM what to display when a folder is visited.
  214. Nil means display folder only, t means display the summary only.  A
  215. value that is neither t not nil means to display both folder and summary.
  216. The latter only works if the variable pop-up-windows's value is non-nil.
  217. See the documentation for vm-mail-window-percentage to see how to change how
  218. the screen is apportioned between the folder and summary windows.")
  219.  
  220. (defvar vm-follow-summary-cursor nil
  221.   "*Non-nil value causes VM to select the message under the cursor in the
  222. summary window before executing commands that operate on the current message.
  223. This occurs only when the summary buffer window is the selected window.")
  224.  
  225. (defvar vm-group-by nil
  226.   "*Non-nil value tells VM how to group message presentation.
  227. Currently, the valid non-nil values for this variable are
  228.   \"subject\", which causes messages with the same subject (ignoring
  229.     Re:'s) to be presented together,
  230.   \"author\", which causes messages with the same author to be presented
  231.     together, and
  232.   \"date-sent\", which causes message sent on the same day to be
  233.     presented together.
  234.   \"arrival-time\" which appears only for completeness, this is the
  235.     default behavior and is the same as nil.
  236.  
  237. The ordering of the messages in the folder itself is not altered, messages
  238. are simply numbered and ordered differently internally.")
  239.  
  240. (defvar vm-skip-deleted-messages t
  241.   "*Non-nil value causes VM's `n' and 'p' commands to skip over
  242. deleted messages.  If all messages are marked deleted then this variable
  243. is, of course, ignored.")
  244.  
  245. (defvar vm-skip-read-messages nil
  246.   "*Non-nil value causes VM's `n' and `p' commands to skip over
  247. message that have already been read in favor of new or unread messages.
  248. If there are no unread message then this variable is, of course, ignored.")
  249.  
  250. (defvar vm-move-after-deleting nil
  251.   "*Non-nil value causes VM's `d' command to automatically invoke
  252. vm-next-message or vm-previous-message after deleting, to move
  253. past the deleted messages.")
  254.  
  255. (defvar vm-delete-after-saving nil
  256.   "*Non-nil value causes VM automatically to mark messages for deletion
  257. after successfully saving them to a folder.")
  258.  
  259. (defvar vm-circular-folders 0
  260.   "*Value determines whether VM folders will be considered circular by
  261. various commands.  `Circular' means VM will wrap from the end of the folder
  262. to the start and vice versa when moving the message pointer or deleting,
  263. undeleting or saving messages before or after the current message.
  264.  
  265. A value of t causes all VM commands to consider folders circular.
  266.  
  267. A value of nil causes all of VM commands to signal an error if the start
  268. or end of the folder would have to be passed to complete the command.
  269. For movement commands, this occurs after the message pointer has been
  270. moved as far it can go.  For other commands the error occurs before any
  271. part of the command has been executed, i.e. no moves, saves, etc. will
  272. be done unless they can be done in their entirety.
  273.  
  274. A value that is not nil and not t causes only VM's movement commands to
  275. consider folders circular.  Saves, deletes and undeleted command will
  276. behave the same as if the value is nil.")
  277.  
  278. (defvar vm-search-using-regexps nil
  279.   "*Non-nil value causes VM's search command will interpret user input as a
  280. regular expression instead of as a literal string.")
  281.  
  282. (defvar vm-mode-hooks nil
  283.   "*List of hook functions to run when a buffer enters vm-mode.
  284. These hook functions should generally be used to set key bindings
  285. and local variables.  Mucking about in the folder buffer is certainly
  286. possible but it is not encouraged.")
  287.  
  288. (defvar vm-berkeley-mail-compatibility
  289.   (memq system-type '(berkeley-unix))
  290.   "*Non-nil means to read and write BSD Mail(1) style Status: headers.
  291. This makes sense if you plan to use VM to read mail archives created by
  292. Mail.")
  293.  
  294. (defvar vm-gargle-uucp nil
  295.   "*Non-nil value means to use a crufty regular expression that does
  296. surprisingly well at beautifying UUCP addresses that are substitued for
  297. %f as part of summary and attribution formats.")
  298.  
  299. (defvar vm-strip-reply-headers nil
  300.   "*Non-nil value causes VM to strip away all comments and extraneous text
  301. from the headers generated in reply messages.  If you use the \"fakemail\"
  302. program as distributed with Emacs, you probably want to set this variable to
  303. to t, because as of Emacs v18.52 \"fakemail\" could not handle unstripped
  304. headers.")
  305.  
  306. (defvar vm-rfc934-forwarding t
  307.   "*Non-nil value causes VM to use char stuffing as described in RFC 934
  308. when packaging a message to be forwarded.  This will allow the recipient
  309. to use a standard bursting agent on the message and act upon it as if it
  310. were sent directly.")
  311.  
  312. (defvar vm-inhibit-startup-message nil
  313.   "*Non-nil causes VM not to display its copyright notice, disclaimers
  314. etc. when started in the usual way.")
  315.  
  316. (defvar mail-yank-hooks nil
  317.   "*List of hooks functions called after yanking a message into a *mail*
  318. buffer.")
  319.  
  320. (defvar vm-mode-map nil
  321.   "Keymap for VM mode and VM Summary mode.")
  322.  
  323. (defconst vm-version "4.41"
  324.   "Version number of VM.")
  325.  
  326. ;; internal vars
  327. (defvar vm-message-list nil)
  328. (make-variable-buffer-local 'vm-message-list)
  329. (defvar vm-message-pointer nil)
  330. (make-variable-buffer-local 'vm-message-pointer)
  331. (defvar vm-last-message-pointer nil)
  332. (make-variable-buffer-local 'vm-last-message-pointer)
  333. (defvar vm-primary-inbox-p nil)
  334. (make-variable-buffer-local 'vm-primary-inbox-p)
  335. (defvar vm-visible-header-alist nil)
  336. (make-variable-buffer-local 'vm-visible-header-alist)
  337. (defvar vm-mail-buffer nil)
  338. (make-variable-buffer-local 'vm-mail-buffer)
  339. (defvar vm-summary-buffer nil)
  340. (make-variable-buffer-local 'vm-summary-buffer)
  341. (defvar vm-system-state nil)
  342. (make-variable-buffer-local 'vm-system-state)
  343. (defvar vm-undo-record-list nil)
  344. (make-variable-buffer-local 'vm-undo-record-list)
  345. (defvar vm-undo-record-pointer nil)
  346. (make-variable-buffer-local 'vm-undo-record-pointer)
  347. (defvar vm-messages-needing-display-update nil)
  348. (make-variable-buffer-local 'vm-messages-needing-display-update)
  349. (defvar vm-current-grouping nil)
  350. (make-variable-buffer-local 'vm-current-grouping)
  351. (defvar vm-last-save-folder nil)
  352. (make-variable-buffer-local 'vm-last-save-folder)
  353. (defvar vm-last-pipe-command nil)
  354. (make-variable-buffer-local 'vm-last-pipe-command)
  355. (defvar vm-messages-not-on-disk 0)
  356. (make-variable-buffer-local 'vm-messages-not-on-disk)
  357. (defvar vm-inhibit-write-file-hook nil)
  358. (defvar vm-session-beginning t)
  359. (defconst vm-spool-directory
  360.   (or (and (boundp 'rmail-spool-directory) rmail-spool-directory)
  361.       "/usr/spool/mail"))
  362. (defconst vm-attributes-header-regexp
  363.   "^X-VM-Attributes:\\(.*\n\\([ \t]+.*\n\\)*\\)")
  364. (defconst vm-attributes-header "X-VM-Attributes:")
  365. (defconst vm-berkeley-mail-status-header "Status: ")
  366. (defconst vm-berkeley-mail-status-header-regexp "^Status: ..?\n")
  367. (defconst vm-generic-header-regexp "^[^:\n]+:\\(.*\n\\([ \t]+.*\n\\)*\\)")
  368. (defconst vm-header-regexp-format "^%s:[ \t]*\\(.*\\(\n[ \t]+.*\\)*\\)")
  369. (defconst vm-supported-groupings-alist
  370.   '(("arrival-time") ("subject") ("author") ("date-sent")))
  371. (defconst vm-total-count 0)
  372. (defconst vm-new-count 0)
  373. (defconst vm-unread-count 0)
  374. ;; for the mode line
  375. (defvar vm-ml-message-number nil)
  376. (make-variable-buffer-local 'vm-ml-message-number)
  377. (defvar vm-ml-highest-message-number nil)
  378. (make-variable-buffer-local 'vm-ml-highest-message-number)
  379. (defvar vm-ml-attributes-string nil)
  380. (make-variable-buffer-local 'vm-ml-attributes-string)
  381.  
  382. ;; general purpose macros and functions
  383. (defmacro vm-marker (pos &optional buffer)
  384.   (list 'set-marker '(make-marker) pos buffer))
  385.  
  386. (defmacro vm-increment (variable)
  387.   (list 'setq variable (list '1+ variable)))
  388.  
  389. (defmacro vm-decrement (variable)
  390.   (list 'setq variable (list '1- variable)))
  391.  
  392. (defun vm-abs (n) (if (< n 0) (- n) n))
  393.  
  394. ;; save-restriction flubs restoring the clipping region if you
  395. ;; (widen) and modify text outside the old region.
  396. ;; This should do it right.
  397. (defmacro vm-save-restriction (&rest forms)
  398.   (let ((vm-sr-clip (make-symbol "vm-sr-clip"))
  399.     (vm-sr-min (make-symbol "vm-sr-min"))
  400.     (vm-sr-max (make-symbol "vm-sr-max")))
  401.     (list 'let (list (list vm-sr-clip '(> (buffer-size)
  402.                       (- (point-max) (point-min)))))
  403.       (list 'and vm-sr-clip
  404.         (list 'setq vm-sr-min '(set-marker (make-marker) (point-min)))
  405.         (list 'setq vm-sr-max '(set-marker (make-marker) (point-max))))
  406.       (list 'unwind-protect (cons 'progn forms)
  407.         '(widen)
  408.         (list 'and vm-sr-clip
  409.               (list 'progn
  410.                 (list 'narrow-to-region vm-sr-min vm-sr-max)
  411.                 (list 'set-marker vm-sr-min nil)
  412.                 (list 'set-marker vm-sr-max nil)))))))
  413.  
  414. ;; macros and functions dealing with accessing messages struct fields
  415. (defun vm-make-message () (make-vector 20 nil))
  416.  
  417. ;; where message begins (From_ line)
  418. (defmacro vm-start-of (message) (list 'aref message 0))
  419. ;; where visible headers start
  420. (defun vm-vheaders-of (message)
  421.   (or (aref message 1)
  422.       (progn (vm-reorder-message-headers message)
  423.          (aref message 1))))
  424. ;; where text section starts
  425. (defmacro vm-text-of (message) (list 'aref message 2))
  426. ;; where message ends
  427. (defmacro vm-end-of (message) (list 'aref message 3))
  428. ;; message number
  429. (defmacro vm-number-of (message) (list 'aref message 4))
  430. ;; message attribute vector
  431. (defmacro vm-attributes-of (message) (list 'aref message 5))
  432. (defmacro vm-new-flag (message) (list 'aref (list 'aref message 5) 0))
  433. (defmacro vm-unread-flag (message) (list 'aref (list 'aref message 5) 1))
  434. (defmacro vm-deleted-flag (message) (list 'aref (list 'aref message 5) 2))
  435. (defmacro vm-filed-flag (message) (list 'aref (list 'aref message 5) 3))
  436. (defmacro vm-replied-flag (message) (list 'aref (list 'aref message 5) 4))
  437. ;; message size in bytes (as a string)
  438. (defmacro vm-byte-count-of (message) (list 'aref message 6))
  439. ;; weekday sent
  440. (defmacro vm-weekday-of (message) (list 'aref message 7))
  441. ;; month day
  442. (defmacro vm-monthday-of (message) (list 'aref message 8))
  443. ;; month sent
  444. (defmacro vm-month-of (message) (list 'aref message 9))
  445. ;; year sent
  446. (defmacro vm-year-of (message) (list 'aref message 10))
  447. ;; hour sent
  448. (defmacro vm-hour-of (message) (list 'aref message 11))
  449. ;; timezone
  450. (defmacro vm-zone-of (message) (list 'aref message 12))
  451. ;; message author's full name (Full-Name: or gouged from From:)
  452. (defmacro vm-full-name-of (message) (list 'aref message 13))
  453. ;; message author address (gouged from From:)
  454. (defmacro vm-from-of (message) (list 'aref message 14))
  455. ;; message ID (Message-Id:)
  456. (defmacro vm-message-id-of (message) (list 'aref message 15))
  457. ;; number of lines in message (as a string)
  458. (defmacro vm-line-count-of (message) (list 'aref message 16))
  459. ;; message subject (Subject:)
  460. (defmacro vm-subject-of (message) (list 'aref message 17))
  461. (defmacro vm-su-start-of (message) (list 'aref message 18))
  462. (defmacro vm-su-end-of (message) (list 'aref message 19))
  463.  
  464. (defmacro vm-set-start-of (message start) (list 'aset message 0 start))
  465. (defmacro vm-set-vheaders-of (message vh) (list 'aset message 1 vh))
  466. (defmacro vm-set-text-of (message text) (list 'aset message 2 text))
  467. (defmacro vm-set-end-of (message end) (list 'aset message 3 end))
  468. (defmacro vm-set-number-of (message n) (list 'aset message 4 n))
  469. (defmacro vm-set-attributes-of (message attrs) (list 'aset message 5 attrs))
  470. (defmacro vm-set-byte-count-of (message count) (list 'aset message 6 count))
  471. (defmacro vm-set-weekday-of (message val) (list 'aset message 7 val))
  472. (defmacro vm-set-monthday-of (message val) (list 'aset message 8 val))
  473. (defmacro vm-set-month-of (message val) (list 'aset message 9 val))
  474. (defmacro vm-set-year-of (message val) (list 'aset message 10 val))
  475. (defmacro vm-set-hour-of (message val) (list 'aset message 11 val))
  476. (defmacro vm-set-zone-of (message val) (list 'aset message 12 val))
  477. (defmacro vm-set-full-name-of (message author) (list 'aset message 13 author))
  478. (defmacro vm-set-from-of (message author) (list 'aset message 14 author))
  479. (defmacro vm-set-message-id-of (message id) (list 'aset message 15 id))
  480. (defmacro vm-set-line-count-of (message count) (list 'aset message 16 count))
  481. (defmacro vm-set-subject-of (message subject) (list 'aset message 17 subject))
  482. (defmacro vm-set-su-start-of (message start) (list 'aset message 18 start))
  483. (defmacro vm-set-su-end-of (message end) (list 'aset message 19 end))
  484.  
  485. (defun vm-text-end-of (message)
  486.   (- (vm-end-of message)
  487.      (cond ((eq vm-folder-type 'mmdf) 5)
  488.        (t 1))))
  489.  
  490. ;; The remaining routines in this group are part of the undo system.
  491.  
  492. ;; init
  493. (if vm-mode-map
  494.     ()
  495.   (setq vm-mode-map (make-keymap))
  496.   (suppress-keymap vm-mode-map)
  497.   (define-key vm-mode-map "h" 'vm-summarize)
  498.   (define-key vm-mode-map "\M-n" 'vm-next-unread-message)
  499.   (define-key vm-mode-map "\M-p" 'vm-previous-unread-message)
  500.   (define-key vm-mode-map "n" 'vm-next-message)
  501.   (define-key vm-mode-map "p" 'vm-previous-message)
  502.   (define-key vm-mode-map "N" 'vm-Next-message)
  503.   (define-key vm-mode-map "P" 'vm-Previous-message)
  504.   (define-key vm-mode-map "\t" 'vm-goto-message-last-seen)
  505.   (define-key vm-mode-map "\r" 'vm-goto-message)
  506.   (define-key vm-mode-map "t" 'vm-expose-hidden-headers)
  507.   (define-key vm-mode-map " " 'vm-scroll-forward)
  508.   (define-key vm-mode-map "b" 'vm-scroll-backward)
  509.   (define-key vm-mode-map "\C-?" 'vm-scroll-backward)
  510.   (define-key vm-mode-map "d" 'vm-delete-message)
  511.   (define-key vm-mode-map "u" 'vm-undelete-message)
  512.   (define-key vm-mode-map "k" 'vm-kill-subject)
  513.   (define-key vm-mode-map "f" 'vm-followup)
  514.   (define-key vm-mode-map "F" 'vm-followup-include-text)
  515.   (define-key vm-mode-map "r" 'vm-reply)
  516.   (define-key vm-mode-map "R" 'vm-reply-include-text)
  517.   (define-key vm-mode-map "z" 'vm-forward-message)
  518.   (define-key vm-mode-map "@" 'vm-send-digest)
  519.   (define-key vm-mode-map "*" 'vm-burst-digest)
  520.   (define-key vm-mode-map "m" 'vm-mail)
  521.   (define-key vm-mode-map "g" 'vm-get-new-mail)
  522.   (define-key vm-mode-map "G" 'vm-group-messages)
  523.   (define-key vm-mode-map "v" 'vm-visit-folder)
  524.   (define-key vm-mode-map "s" 'vm-save-message)
  525.   (define-key vm-mode-map "w" 'vm-save-message-sans-headers)
  526.   (define-key vm-mode-map "A" 'vm-auto-archive-messages)
  527.   (define-key vm-mode-map "S" 'vm-save-folder)
  528.   (define-key vm-mode-map "|" 'vm-pipe-message-to-command)
  529.   (define-key vm-mode-map "#" 'vm-expunge-folder)
  530.   (define-key vm-mode-map "q" 'vm-quit)
  531.   (define-key vm-mode-map "x" 'vm-quit-no-change)
  532.   (define-key vm-mode-map "?" 'vm-help)
  533.   (define-key vm-mode-map "\C-_" 'vm-undo)
  534.   (define-key vm-mode-map "\C-xu" 'vm-undo)
  535.   (define-key vm-mode-map "!" 'shell-command)
  536.   (define-key vm-mode-map "<" 'beginning-of-buffer)
  537.   (define-key vm-mode-map ">" 'vm-end-of-message)
  538.   (define-key vm-mode-map "\M-s" 'vm-isearch-forward)
  539.   (define-key vm-mode-map "=" 'vm-summarize)
  540.   (define-key vm-mode-map "\M-C" 'vm-show-copying-restrictions)
  541.   (define-key vm-mode-map "\M-W" 'vm-show-no-warranty))
  542.  
  543. (defun vm-mark-for-display-update (message)
  544.   (if (not (memq message vm-messages-needing-display-update))
  545.       (setq vm-messages-needing-display-update
  546.         (cons message vm-messages-needing-display-update))))
  547.  
  548. (defun vm-last (list) (while (cdr-safe list) (setq list (cdr list))) list)
  549.  
  550. (put 'folder-empty 'error-conditions '(folder-empty error))
  551. (put 'folder-empty 'error-message "Folder is empty")
  552.  
  553. (defun vm-error-if-folder-empty ()
  554.   (while (null vm-message-list)
  555.     (signal 'folder-empty nil)))
  556.  
  557. (defun vm-proportion-windows ()
  558.   (if vm-mail-buffer
  559.       (set-buffer vm-mail-buffer))
  560.   (if (not (one-window-p t))
  561.       (let ((mail-w (get-buffer-window (current-buffer)))
  562.         (n (- (window-height (get-buffer-window (current-buffer)))
  563.           (/ (* vm-mail-window-percentage
  564.             (- (screen-height)
  565.                (window-height (minibuffer-window))))
  566.              100)))
  567.         (old-w (selected-window)))
  568.     (if mail-w
  569.         (save-excursion
  570.           (select-window mail-w)
  571.           (shrink-window n)
  572.           (select-window old-w))))))
  573.  
  574. (defun vm-number-messages ()
  575.   (let ((n 1) (message-list vm-message-list))
  576.     (while message-list
  577.       (vm-set-number-of (car message-list) (int-to-string n))
  578.       (setq n (1+ n) message-list (cdr message-list)))
  579.     (setq vm-ml-highest-message-number (int-to-string (1- n)))))
  580.  
  581. (defun vm-match-visible-header (alist)
  582.   (catch 'match
  583.     (while alist
  584.       (if (looking-at (car (car alist)))
  585.       (throw 'match (car alist)))
  586.       (setq alist (cdr alist)))
  587.     nil))
  588.  
  589. (defun vm-delete-header ()
  590.   (if (looking-at vm-generic-header-regexp)
  591.       (delete-region (match-beginning 0) (match-end 0))))
  592.  
  593. ;; Build a chain of message structures.
  594. ;; Find the start and end of each message and fill end the relevant
  595. ;; fields in the message structures.
  596.  
  597. (defun vm-build-message-list ()
  598.   (save-excursion
  599.     (vm-build-visible-header-alist)
  600.     (let (tail-cons message prev-message case-fold-search marker
  601.       start-regexp sep-pattern trailer-length)
  602.       (if (eq vm-folder-type 'mmdf)
  603.       (setq start-regexp "^\001\001\001\001\n"
  604.         separator-string "\n\001\001\001\001\n\001\001\001\001"
  605.         trailer-length 6)
  606.     (setq start-regexp "^From "
  607.           separator-string "\n\nFrom "
  608.           trailer-length 2))
  609.       (if vm-message-list
  610.       (let ((mp vm-message-list)
  611.         (end (point-min)))
  612.         (while mp
  613.           (if (< end (vm-end-of (car mp)))
  614.           (setq end (vm-end-of (car mp))))
  615.           (setq mp (cdr mp)))
  616.         ;; move back past trailer so separator-string will match below
  617.         (goto-char (- end trailer-length))
  618.         (setq tail-cons (vm-last vm-message-list)))
  619.     (goto-char (point-min))
  620.     (if (looking-at start-regexp)
  621.         (progn
  622.           (setq message (vm-make-message) prev-message message)
  623.           (vm-set-start-of message (vm-marker (match-beginning 0)))
  624.           (setq vm-message-list (list message)
  625.             tail-cons vm-message-list))))
  626.       (while (search-forward separator-string nil t)
  627.     (setq marker (vm-marker (+ trailer-length (match-beginning 0)))
  628.           message (vm-make-message))
  629.     (vm-set-start-of message marker)
  630.     (if prev-message
  631.         (vm-set-end-of prev-message marker))
  632.     (if tail-cons
  633.         (progn
  634.           (setcdr tail-cons (list message))
  635.           (setq tail-cons (cdr tail-cons)
  636.             prev-message message))
  637.       (setq vm-message-list (list message)
  638.         tail-cons vm-message-list
  639.         prev-message message)))
  640.       (if prev-message
  641.       (vm-set-end-of prev-message (vm-marker (point-max)))))))
  642.  
  643. (defun vm-build-visible-header-alist ()
  644.   (let ((header-alist (cons nil nil))
  645.     (vheaders vm-visible-headers)
  646.     list)
  647.     (setq list header-alist)
  648.     (while vheaders
  649.       (setcdr list (cons (cons (car vheaders) nil) nil))
  650.       (setq list (cdr list) vheaders (cdr vheaders)))
  651.     (setq vm-visible-header-alist (cdr header-alist))))
  652.  
  653. ;; Group the headers that the user wants to see at the end of the headers
  654. ;; section so we can narrow to them.  The vheaders field of the
  655. ;; message struct is set.  This function is called on demand whenever
  656. ;; a vheaders field is discovered to be nil for a particular message.
  657.  
  658. (defun vm-reorder-message-headers (message)
  659.   (save-excursion
  660.     (vm-save-restriction
  661.      (let ((header-alist vm-visible-header-alist)
  662.        list buffer-read-only match-end-0
  663.        (inhibit-quit t)
  664.        (old-buffer-modified-p (buffer-modified-p)))
  665.        (goto-char (vm-start-of message))
  666.        (forward-line)
  667.        (while (and (not (= (following-char) ?\n))
  668.            (looking-at vm-generic-header-regexp))
  669.      (setq match-end-0 (match-end 0)
  670.            list (vm-match-visible-header header-alist))
  671.      (if (null list)
  672.          (goto-char match-end-0)
  673.        (if (cdr list)
  674.            (setcdr list 
  675.                (concat
  676.             (cdr list)
  677.             (buffer-substring (point) match-end-0)))
  678.          (setcdr list (buffer-substring (point) match-end-0)))
  679.        (delete-region (point) match-end-0)))
  680.        (vm-set-vheaders-of message (point-marker))
  681.        (setq list header-alist)
  682.        (while list
  683.      (if (cdr (car list))
  684.          (progn
  685.            (insert (cdr (car list)))
  686.            (setcdr (car list) nil)))
  687.      (setq list (cdr list)))
  688.        (set-buffer-modified-p old-buffer-modified-p)))))
  689.  
  690. ;; Read the attribute headers from the messages and store their contents
  691. ;; in attributes fields of the message structures.  If a message has no
  692. ;; attributes header assume it is new.  If a message already has
  693. ;; attributes don't bother checking the headers.
  694. ;;
  695. ;; Stores the position where the message text begins in the message struct.
  696.  
  697. (defun vm-read-attributes ()
  698.   (save-excursion
  699.     (let ((mp vm-message-list))
  700.       (setq vm-new-count 0
  701.         vm-unread-count 0
  702.         vm-total-count 0)
  703.       (while mp
  704.     (vm-increment vm-total-count)
  705.     (if (vm-attributes-of (car mp))
  706.         ()
  707.       (goto-char (vm-start-of (car mp)))
  708.       (search-forward "\n\n" (vm-text-end-of (car mp)) 0)
  709.       (vm-set-text-of (car mp) (point-marker))
  710.       (goto-char (vm-start-of (car mp)))
  711.       (cond ((re-search-forward vm-attributes-header-regexp
  712.                     (vm-text-of (car mp)) t)
  713.          (goto-char (match-beginning 1))
  714.          (vm-set-attributes-of (car mp)
  715.                        (condition-case ()
  716.                        (read (current-buffer))
  717.                      (error (vector t nil nil nil nil))))
  718.          ;; If attributes are unrecogniable just assume the
  719.          ;; message is new.
  720.          (cond ((or (not (vectorp (vm-attributes-of (car mp))))
  721.                 (not (= (length (vm-attributes-of (car mp)))
  722.                     5)))
  723.             (vm-set-attributes-of (car mp)
  724.                           (vector t nil nil nil nil)))))
  725.         ((and vm-berkeley-mail-compatibility
  726.               (re-search-forward vm-berkeley-mail-status-header-regexp
  727.                      (vm-text-of (car mp)) t))
  728.          (vm-set-attributes-of (car mp) (vector nil (looking-at "R")
  729.                             nil nil nil)))
  730.         (t
  731.          (vm-set-attributes-of (car mp) (vector t nil nil nil nil)))))
  732.     (cond ((vm-deleted-flag (car mp))) ; don't count deleted messages
  733.           ((vm-new-flag (car mp))
  734.            (vm-increment vm-new-count))
  735.           ((vm-unread-flag (car mp))
  736.            (vm-increment vm-unread-count)))
  737.     (setq mp (cdr mp))))))
  738.  
  739. ;; Stuff the messages attributes back into the messages as headers.
  740. (defun vm-stuff-attributes ()
  741.   (save-excursion
  742.     (vm-save-restriction
  743.      (widen)
  744.      (let ((mp vm-message-list) attributes buffer-read-only
  745.        (old-buffer-modified-p (buffer-modified-p)))
  746.        (while mp
  747.      (setq attributes (vm-attributes-of (car mp)))
  748.      (goto-char (vm-start-of (car mp)))
  749.      (if (re-search-forward vm-attributes-header-regexp
  750.                 (vm-text-of (car mp)) t)
  751.          (delete-region (match-beginning 0) (match-end 0)))
  752.      (cond (vm-berkeley-mail-compatibility
  753.         (goto-char (vm-start-of (car mp)))
  754.         (if (re-search-forward vm-berkeley-mail-status-header-regexp
  755.                        (vm-text-of (car mp)) t)
  756.             (delete-region (match-beginning 0) (match-end 0)))
  757.         (cond ((not (vm-new-flag (car mp)))
  758.                (goto-char (vm-start-of (car mp)))
  759.                (forward-line)
  760.                (insert-before-markers
  761.             vm-berkeley-mail-status-header
  762.             (if (vm-unread-flag (car mp)) "" "R")
  763.             "O\n")))))
  764.      (goto-char (vm-start-of (car mp)))
  765.      (forward-line)
  766.      (insert-before-markers vm-attributes-header " "
  767.                 (prin1-to-string attributes) "\n")
  768.      (setq mp (cdr mp)))
  769.        (set-buffer-modified-p old-buffer-modified-p)))))
  770.       
  771. ;; Remove any message marked for deletion from the buffer and the
  772. ;; message list.
  773. (defun vm-gobble-deleted-messages ()
  774.   (save-excursion
  775.     (vm-save-restriction
  776.      (widen)
  777.      (let ((mp vm-message-list) prev buffer-read-only did-gobble)
  778.        (while mp
  779.      (if (not (vm-deleted-flag (car mp)))
  780.          (setq prev mp)
  781.        (setq did-gobble t)
  782.        (delete-region (vm-start-of (car mp))
  783.               (vm-end-of (car mp)))
  784.        (if (null prev)
  785.            (setq vm-message-list (cdr vm-message-list))
  786.          (setcdr prev (cdr mp))))
  787.      (setq mp (cdr mp)))
  788.        (if did-gobble
  789.        (progn
  790.          (vm-clear-expunge-invalidated-undos)
  791.          (if (null vm-message-list)
  792.          (setq overlay-arrow-position nil))
  793.          (cond ((and vm-last-message-pointer
  794.              (vm-deleted-flag (car vm-last-message-pointer)))
  795.             (setq vm-last-message-pointer nil)))
  796.          (cond ((and vm-message-pointer
  797.              (vm-deleted-flag (car vm-message-pointer)))
  798.             (setq vm-system-state nil)
  799.             (setq mp (cdr vm-message-pointer))
  800.             (while (and mp (vm-deleted-flag (car mp)))
  801.               (setq mp (cdr mp)))
  802.             (setq vm-message-pointer
  803.               (or mp (vm-last vm-message-list)))))
  804.          did-gobble ))))))
  805.  
  806. (defun vm-change-all-new-to-unread ()
  807.   (let ((mp vm-message-list))
  808.     (while mp
  809.       (if (vm-new-flag (car mp))
  810.       (progn
  811.         (vm-set-new-flag (car mp) nil)
  812.         (vm-set-unread-flag (car mp) t)))
  813.       (setq mp (cdr mp)))))
  814.  
  815. (defun vm-update-summary-and-mode-line ()
  816.   (setq vm-ml-message-number (vm-number-of (car vm-message-pointer)))
  817.   (cond ((vm-new-flag (car vm-message-pointer))
  818.      (setq vm-ml-attributes-string "new"))
  819.     ((vm-unread-flag (car vm-message-pointer))
  820.      (setq vm-ml-attributes-string "unread"))
  821.     (t (setq vm-ml-attributes-string "read")))
  822.   (cond ((vm-filed-flag (car vm-message-pointer))
  823.      (setq vm-ml-attributes-string
  824.            (concat vm-ml-attributes-string " filed"))))
  825.   (cond ((vm-replied-flag (car vm-message-pointer))
  826.      (setq vm-ml-attributes-string
  827.            (concat vm-ml-attributes-string " replied"))))
  828.   (cond ((vm-deleted-flag (car vm-message-pointer))
  829.      (setq vm-ml-attributes-string
  830.            (concat vm-ml-attributes-string " deleted"))))
  831.   (while vm-messages-needing-display-update
  832.     (vm-update-message-summary vm-messages-needing-display-update)
  833.     (setq vm-messages-needing-display-update
  834.       (cdr vm-messages-needing-display-update)))
  835.   (save-excursion
  836.     (set-buffer (other-buffer))
  837.     (set-buffer-modified-p (buffer-modified-p))))
  838.  
  839. (defun vm-goto-message (n)
  840.   "Go to the message numbered N.
  841. Interactively N is the prefix argument.  If no prefix arg is provided
  842. N is prompted for in the minibuffer."
  843.   (interactive "NGo to message: ")
  844.   (if vm-mail-buffer
  845.       (set-buffer vm-mail-buffer))
  846.   (vm-error-if-folder-empty)
  847.   (let ((cons (nthcdr (1- n) vm-message-list)))
  848.     (if (null cons)
  849.     (error "No such message."))
  850.     (if (eq vm-message-pointer cons)
  851.     (vm-preview-current-message)
  852.       (setq vm-last-message-pointer vm-message-pointer
  853.         vm-message-pointer cons)
  854.       (vm-set-summary-pointer (car vm-message-pointer))
  855.       (vm-preview-current-message))))
  856.  
  857. (defun vm-goto-message-last-seen ()
  858.   "Go to the message last previewed."
  859.   (interactive)
  860.   (if vm-mail-buffer
  861.       (set-buffer vm-mail-buffer))
  862.   (vm-error-if-folder-empty)
  863.   (if vm-last-message-pointer
  864.       (let (tmp)
  865.     (setq tmp vm-message-pointer
  866.           vm-message-pointer vm-last-message-pointer
  867.           vm-last-message-pointer tmp)
  868.     (vm-set-summary-pointer (car vm-message-pointer))
  869.     (vm-preview-current-message))))
  870.  
  871. (put 'beginning-of-folder 'error-conditions '(beginning-of-folder error))
  872. (put 'beginning-of-folder 'error-message "Beginning of folder")
  873. (put 'end-of-folder 'error-conditions '(end-of-folder error))
  874. (put 'end-of-folder 'error-message "End of folder")
  875.  
  876. (defun vm-check-count (count)
  877.   (if (>= count 0)
  878.       (if (< (length vm-message-pointer) count)
  879.       (signal 'end-of-folder nil))
  880.     (if (< (1+ (- (length vm-message-list) (length vm-message-pointer)))
  881.        (vm-abs count))
  882.     (signal 'beginning-of-folder nil))))
  883.  
  884. (defun vm-move-message-pointer (direction)
  885.   (let ((mp vm-message-pointer))
  886.     (if (eq direction 'forward)
  887.     (progn
  888.       (setq mp (cdr mp))
  889.       (if (null mp)
  890.           (if vm-circular-folders
  891.           (setq mp vm-message-list)
  892.         (signal 'end-of-folder nil))))
  893.       (if (eq mp vm-message-list)
  894.       (if vm-circular-folders
  895.           (setq mp (vm-last vm-message-list))
  896.         (signal 'beginning-of-folder nil))
  897.     (setq mp (let ((curr vm-message-list))
  898.            (while (not (eq (cdr curr) mp))
  899.              (setq curr (cdr curr)))
  900.            curr))))
  901.     (setq vm-message-pointer mp)))
  902.  
  903. (defun vm-should-skip-message (mp)
  904.   (or (and vm-skip-deleted-messages
  905.        (vm-deleted-flag (car mp)))
  906.       (and vm-skip-read-messages
  907.        (or (vm-deleted-flag (car mp))
  908.            (not (or (vm-new-flag (car mp))
  909.             (vm-unread-flag (car mp))))))))
  910.  
  911. (defun vm-next-message (&optional count retry)
  912.   "Go forward one message and preview it.
  913. With prefix arg COUNT, go forward COUNT messages.  A negative COUNT
  914. means go backward.  If the absolute value of COUNT > 1 the values of the
  915. variables vm-skip-deleted-messages and vm-skip-read-messages are
  916. ignored."
  917.   (interactive "p\np")
  918.   (if vm-mail-buffer
  919.       (set-buffer vm-mail-buffer))
  920.   (vm-error-if-folder-empty)
  921.   (or count (setq count 1))
  922.   (let ((oldmp vm-message-pointer)
  923.     (error)
  924.     (direction (if (> count 0) 'forward 'backward))
  925.     (count (vm-abs count)))
  926.     (cond
  927.      ((null vm-message-pointer)
  928.       (setq vm-message-pointer vm-message-list))
  929.      ((/= count 1)
  930.       (condition-case ()
  931.       (while (not (zerop count))
  932.         (vm-move-message-pointer direction)
  933.         (vm-decrement count))
  934.     (beginning-of-folder (setq error 'beginning-of-folder))
  935.     (end-of-folder (setq error 'end-of-folder))))
  936.      (t
  937.       (condition-case ()
  938.       (progn
  939.         (vm-move-message-pointer direction)
  940.         (while (and (not (eq oldmp vm-message-pointer))
  941.             (vm-should-skip-message vm-message-pointer))
  942.           (vm-move-message-pointer direction))
  943.         ;; Retry the move if we've gone a complete circle and we should
  944.         ;; skip the current message and there are other messages.
  945.         (and (eq vm-message-pointer oldmp) retry (cdr vm-message-list)
  946.          (vm-should-skip-message vm-message-pointer)
  947.          (vm-move-message-pointer direction)))
  948.     (beginning-of-folder
  949.      (setq vm-message-pointer oldmp)
  950.      (if retry
  951.          (vm-move-message-pointer direction)
  952.        (setq error 'beginning-of-folder)))
  953.     (end-of-folder
  954.      (setq vm-message-pointer oldmp)
  955.      (if retry
  956.          (vm-move-message-pointer direction)
  957.        (setq error 'end-of-folder))))))
  958.     (if (not (eq vm-message-pointer oldmp))
  959.     (progn
  960.       (setq vm-last-message-pointer oldmp)
  961.       (vm-set-summary-pointer (car vm-message-pointer))
  962.       (vm-preview-current-message)))
  963.     (if error
  964.     (signal error nil))))
  965.  
  966. (defun vm-previous-message (&optional count retry)
  967.   "Go back one message and preview it.
  968. With prefix arg COUNT, go backward COUNT messages.  A negative COUNT
  969. means go forward.  If the absolute value of COUNT > 1 the values of the
  970. variables vm-skip-deleted-messages and vm-skip-read-messages are
  971. ignored."
  972.   (interactive "p\np")
  973.   (or count (setq count 1))
  974.   (vm-next-message (- count) retry))
  975.  
  976. (defun vm-Next-message (&optional count)
  977.   "Like vm-next-message but will not skip messages."
  978.   (interactive "p")
  979.   (let (vm-skip-deleted-messages vm-skip-read-messages)
  980.     (vm-next-message count)))
  981.  
  982. (defun vm-Previous-message (&optional count)
  983.   "Like vm-previous-message but will not skip messages."
  984.   (interactive "p")
  985.   (let (vm-skip-deleted-messages vm-skip-read-messages)
  986.     (vm-previous-message count)))
  987.  
  988. (defun vm-next-unread-message ()
  989.   "Move forward to the nearest new or unread message, if there is one."
  990.   (interactive)
  991.   (if vm-mail-buffer
  992.       (set-buffer vm-mail-buffer))
  993.   (condition-case ()
  994.       (let ((vm-skip-read-messages t)
  995.         (oldmp vm-message-pointer))
  996.     (vm-next-message)
  997.     ;; in case vm-circular-folder is non-nil
  998.     (and (eq vm-message-pointer oldmp) (signal 'end-of-folder nil)))
  999.     (end-of-folder (error "No next unread message"))))
  1000.  
  1001. (defun vm-previous-unread-message ()
  1002.   "Move backward to the nearest new or unread message, if there is one."
  1003.   (interactive)
  1004.   (if vm-mail-buffer
  1005.       (set-buffer vm-mail-buffer))
  1006.   (condition-case ()
  1007.       (let ((vm-skip-read-messages t)
  1008.         (oldmp vm-message-pointer))
  1009.     (vm-previous-message)
  1010.     ;; in case vm-circular-folder is non-nil
  1011.     (and (eq vm-message-pointer oldmp) (signal 'beginning-of-folder nil)))
  1012.     (beginning-of-folder (error "No previous unread message"))))
  1013.  
  1014. (defun vm-preview-current-message ()
  1015.   (setq vm-system-state 'previewing)
  1016.   (widen)
  1017.   (narrow-to-region
  1018.    (vm-vheaders-of (car vm-message-pointer))
  1019.    (if vm-preview-lines
  1020.        (min
  1021.     (vm-text-end-of (car vm-message-pointer))
  1022.     (save-excursion
  1023.       (goto-char (vm-text-of (car vm-message-pointer)))
  1024.       (forward-line (if (natnump vm-preview-lines) vm-preview-lines 0))
  1025.       (point)))
  1026.      (vm-text-of (car vm-message-pointer))))
  1027.   (let ((w (get-buffer-window (current-buffer))))
  1028.     (and w (progn (set-window-start w (point-min))
  1029.           (set-window-point w (point-max))))
  1030.     (and w vm-highlighted-header-regexp
  1031.      (progn
  1032.        (save-restriction
  1033.          (narrow-to-region (point) (point))
  1034.          (sit-for 0))
  1035.        (goto-char (point-min))
  1036.        (while (re-search-forward vm-highlighted-header-regexp nil t)
  1037.          (save-restriction
  1038.            (goto-char (match-beginning 0))
  1039.            (looking-at vm-generic-header-regexp)
  1040.            (goto-char (match-beginning 1))
  1041.            (narrow-to-region (point-min) (point))
  1042.            (sit-for 0)
  1043.            (setq inverse-video t)
  1044.            (widen)
  1045.            (narrow-to-region (point-min) (match-end 1))
  1046.            (sit-for 0)
  1047.            (setq inverse-video nil)
  1048.            (goto-char (match-end 0)))))))
  1049.   (goto-char (point-max))
  1050.   ;; De Morgan's Theorems could clear away most of the following negations,
  1051.   ;; but the resulting code would be horribly obfuscated.
  1052.   (if (or (null vm-preview-lines)
  1053.       (and (not vm-preview-read-messages)
  1054.            (not (vm-new-flag (car vm-message-pointer)))
  1055.            (not (vm-unread-flag (car vm-message-pointer)))))
  1056.       ;; Don't sit and howl unless the mail buffer is visible.
  1057.       (vm-show-current-message (get-buffer-window (current-buffer)))
  1058.     (vm-update-summary-and-mode-line)))
  1059.  
  1060. (defun vm-show-current-message (&optional sit-and-howl)
  1061.   (setq vm-system-state 'reading)
  1062.   (save-excursion
  1063.     (goto-char (point-min))
  1064.     (widen)
  1065.     (narrow-to-region (point) (vm-text-end-of (car vm-message-pointer))))
  1066.   (cond ((vm-new-flag (car vm-message-pointer))
  1067.      (vm-set-new-flag (car vm-message-pointer) nil))
  1068.     ((vm-unread-flag (car vm-message-pointer))
  1069.      (vm-set-unread-flag (car vm-message-pointer) nil)))
  1070.   (vm-update-summary-and-mode-line)
  1071.   (cond (sit-and-howl
  1072.      (sit-for 0)
  1073.      (vm-howl-if-eom-visible))))
  1074.  
  1075. (defun vm-expose-hidden-headers ()
  1076.   "Expose headers omitted from vm-visible-headers."
  1077.   (interactive)
  1078.   (vm-follow-summary-cursor)
  1079.   (if vm-mail-buffer
  1080.       (set-buffer vm-mail-buffer))
  1081.   (vm-error-if-folder-empty)
  1082.   (save-excursion
  1083.     (goto-char (point-max))
  1084.     (widen)
  1085.     (narrow-to-region (point) (vm-start-of (car vm-message-pointer)))
  1086.     (let (w)
  1087.       (and (setq w (get-buffer-window (current-buffer)))
  1088.        (= (window-start w) (vm-vheaders-of (car vm-message-pointer)))
  1089.        (set-window-start w (vm-start-of (car vm-message-pointer)))))))
  1090.  
  1091. (defun vm-howl-if-eom-visible ()
  1092.   (let ((w (get-buffer-window (current-buffer))))
  1093.     (and w (pos-visible-in-window-p (point-max) w)
  1094.      (message "End of message %s from %s"
  1095.           (vm-number-of (car vm-message-pointer))
  1096.           (vm-su-full-name (car vm-message-pointer))))))
  1097.  
  1098. ;; message-changed is an old-fashoined local variable.
  1099. (defun vm-scroll-forward (&optional arg message-changed)
  1100.   "Scroll forward a screenful of text.
  1101. If the current message is being previewed, the message body is revealed.
  1102. If at the end of the current message, move to the next message."
  1103.   (interactive "P")
  1104.   (setq message-changed (vm-follow-summary-cursor))
  1105.   (if vm-mail-buffer
  1106.       (set-buffer vm-mail-buffer))
  1107.   (vm-error-if-folder-empty)
  1108.   (if (null (get-buffer-window (current-buffer)))
  1109.       (progn
  1110.     (if vm-mutable-windows
  1111.         (let ((pop-up-windows
  1112.            (and pop-up-windows (eq vm-mutable-windows t))))
  1113.           (display-buffer (current-buffer)))
  1114.       (switch-to-buffer (current-buffer)))
  1115.     (if (and vm-summary-buffer (get-buffer-window vm-summary-buffer)
  1116.          (eq vm-mutable-windows t))
  1117.         (vm-proportion-windows))
  1118.     (if (eq vm-system-state 'previewing)
  1119.         (vm-show-current-message t)
  1120.       (vm-howl-if-eom-visible)))
  1121.     (if (eq vm-system-state 'previewing)
  1122.     (vm-show-current-message t)
  1123.       (if message-changed
  1124.       (vm-howl-if-eom-visible)
  1125.     (let ((w (get-buffer-window (current-buffer)))
  1126.           (old-w (selected-window)))
  1127.       (unwind-protect
  1128.           (progn
  1129.         (select-window w)
  1130.         (if (not (eq (condition-case () (scroll-up arg)
  1131.                    (end-of-buffer (if (null arg)
  1132.                           (progn
  1133.                             (vm-next-message)
  1134.                             'next-message))))
  1135.                  'next-message))
  1136.             (vm-howl-if-eom-visible)))
  1137.         (select-window old-w)))))))
  1138.  
  1139. (defun vm-scroll-backward (&optional arg)
  1140.   "Scroll backward a screenful of text."
  1141.   (interactive "P")
  1142.   (vm-follow-summary-cursor)
  1143.   (if vm-mail-buffer
  1144.       (set-buffer vm-mail-buffer))
  1145.   (vm-error-if-folder-empty)
  1146.   (if (null (get-buffer-window (current-buffer)))
  1147.       (progn
  1148.     (if vm-mutable-windows
  1149.         (let ((pop-up-windows
  1150.            (and pop-up-windows (eq vm-mutable-windows t))))
  1151.           (display-buffer (current-buffer)))
  1152.       (switch-to-buffer (current-buffer)))
  1153.     (if (and vm-summary-buffer (get-buffer-window vm-summary-buffer)
  1154.          (eq vm-mutable-windows t))
  1155.         (vm-proportion-windows)))
  1156.     (let ((w (get-buffer-window (current-buffer)))
  1157.       (old-w (selected-window)))
  1158.       (unwind-protect
  1159.       (progn
  1160.         (select-window w)
  1161.         (scroll-down arg))
  1162.     (select-window old-w)))))
  1163.  
  1164. (defun vm-end-of-message ()
  1165.   "Displays the end of the current message, exposing and marking it read
  1166. as necessary."
  1167.   (interactive)
  1168.   (vm-follow-summary-cursor)
  1169.   (if vm-mail-buffer
  1170.       (set-buffer vm-mail-buffer))
  1171.   (vm-error-if-folder-empty)
  1172.   (if (eq vm-system-state 'previewing)
  1173.       (vm-show-current-message))
  1174.   (goto-char (point-max))
  1175.   (vm-howl-if-eom-visible))
  1176.  
  1177. (defun vm-quit-no-change ()
  1178.   "Exit VM without saving changes made to the folder."
  1179.   (interactive)
  1180.   (vm-quit t))
  1181.  
  1182. (defun vm-quit (&optional no-change)
  1183.   "Quit VM, saving changes and expunging messages marked for deletion.
  1184. New messages are changed to unread."
  1185.   (interactive)
  1186.   (if vm-mail-buffer
  1187.       (set-buffer vm-mail-buffer))
  1188.   (and no-change (buffer-modified-p)
  1189.        (not (zerop vm-messages-not-on-disk))
  1190.        ;; Folder may have been saved with C-x C-s and atriutes may have
  1191.        ;; been changed after that; in that case vm-messages-not-on-disk
  1192.        ;; would not have been zeroed.  However, all modification flag
  1193.        ;; undos are cleared if VM actually modifies the folder buffer
  1194.        ;; (as opposed to the folder's attributes), so this can be used
  1195.        ;; to verify that there are indeed unsaved messages.
  1196.        (null (assq 'set-buffer-modified-p vm-undo-record-list))
  1197.        (not (y-or-n-p
  1198.          (format "%d message%s have not been saved to disk, exit anyway? "
  1199.              vm-messages-not-on-disk
  1200.              (if (= 1 vm-messages-not-on-disk) "" "s"))))
  1201.        (error "Aborted"))
  1202.   (let ((inhibit-quit t))
  1203.     (if (not no-change)
  1204.     (vm-change-all-new-to-unread))
  1205.     (if (and (buffer-modified-p) (not no-change))
  1206.     (vm-save-folder t))
  1207.     (let ((summary-buffer vm-summary-buffer)
  1208.       (mail-buffer (current-buffer)))
  1209.       (if summary-buffer
  1210.       (progn
  1211.         (setq overlay-arrow-position nil)
  1212.         (if (eq vm-mutable-windows t)
  1213.         (delete-windows-on vm-summary-buffer))
  1214.         (kill-buffer summary-buffer)))
  1215.       (set-buffer mail-buffer)
  1216.       (set-buffer-modified-p nil)
  1217.       (kill-buffer (current-buffer)))
  1218.     ;; Make sure we are now dealing with the buffer and window that
  1219.     ;; would be selected were we to give up control now.
  1220.     (set-buffer (window-buffer (selected-window)))
  1221.     ;; If we land on a buffer that VM knows about
  1222.     ;; do some nice things for the user, if we're allowed.
  1223.     (cond ((and (eq major-mode 'vm-mode) (eq vm-mutable-windows t))
  1224.        (if (null vm-startup-with-summary)
  1225.            (delete-other-windows)
  1226.          (condition-case () (vm-summarize t) (error nil))
  1227.          (and (not (eq major-mode 'vm-summary-mode))
  1228.           (eq vm-startup-with-summary t)
  1229.           (not (one-window-p t))
  1230.           vm-summary-buffer
  1231.           (get-buffer-window vm-summary-buffer)
  1232.           (progn
  1233.             (select-window (get-buffer-window vm-summary-buffer))
  1234.             (delete-other-windows)))))
  1235.       ((eq major-mode 'vm-summary-mode)
  1236.        (cond ((eq vm-startup-with-summary nil)
  1237.           (switch-to-buffer vm-mail-buffer)
  1238.           (and (not (one-window-p t)) (eq vm-mutable-windows t)
  1239.                (delete-other-windows)))
  1240.          ((not (eq vm-startup-with-summary t))
  1241.           (let ((pop-up-windows
  1242.              (and pop-up-windows (eq vm-mutable-windows t))))
  1243.             (display-buffer vm-mail-buffer))
  1244.           (if (eq vm-mutable-windows t)
  1245.               (if (eq major-mode 'vm-summary-mode)
  1246.               (vm-proportion-windows)
  1247.             (switch-to-buffer vm-summary-buffer))))
  1248.          ((eq vm-mutable-windows t)
  1249.           (delete-other-windows)))))))
  1250.  
  1251. ;; This allows C-x C-s to do the right thing for VM mail buffers.
  1252. ;; Note that deleted messages are not expunged.
  1253. (defun vm-write-file-hook ()
  1254.   (if (not (eq major-mode 'vm-mode))
  1255.       ()
  1256.     (if vm-inhibit-write-file-hook
  1257.     ()
  1258.       ;; The vm-save-restriction isn't really necessary here (since
  1259.       ;; vm-stuff-atributes cleans up after itself) but should remain
  1260.       ;; as a safeguard against the time when other stuff is added here.
  1261.       (vm-save-restriction
  1262.        (let ((inhibit-quit t)
  1263.          (buffer-read-only))
  1264.      (vm-stuff-attributes)
  1265.      nil )))))
  1266.  
  1267. (defun vm-save-folder (&optional quitting)
  1268.   "Save current folder to disk."
  1269.   (interactive)
  1270.   (if vm-mail-buffer
  1271.       (set-buffer vm-mail-buffer))
  1272.   (if (buffer-modified-p)
  1273.       (let ((inhibit-quit t))
  1274.     ;; may get error if folder is emptied by the expunge.
  1275.     (condition-case ()
  1276.         (vm-expunge-folder quitting t)
  1277.       (error nil))
  1278.     (vm-stuff-attributes)
  1279.     (let ((vm-inhibit-write-file-hook t))
  1280.       (save-buffer))
  1281.     (setq vm-messages-not-on-disk 0)
  1282.     (and (zerop (buffer-size)) vm-delete-empty-folders
  1283.          (condition-case ()
  1284.          (progn
  1285.            (delete-file buffer-file-name)
  1286.            (message "%s removed" buffer-file-name))
  1287.            (error nil)))
  1288.     (if (not quitting)
  1289.         (if vm-message-pointer
  1290.         (vm-update-summary-and-mode-line)
  1291.           (vm-next-message))))))
  1292.  
  1293. (defun vm-visit-folder (folder)
  1294.   "Visit a mail file.
  1295. VM will parse and present its messages to you in the usual way."
  1296.   (interactive
  1297.    (list (read-file-name
  1298.       "Visit folder: " (if vm-folder-directory
  1299.                    (expand-file-name vm-folder-directory)
  1300.                  default-directory) nil t)))
  1301.   (if vm-mail-buffer
  1302.       (set-buffer vm-mail-buffer))
  1303.   (vm folder))
  1304.  
  1305. (defun vm-help ()
  1306.   "Display VM command and variable information."
  1307.   (interactive)
  1308.   (if (and vm-mail-buffer (get-buffer-window vm-mail-buffer))
  1309.       (set-buffer vm-mail-buffer))
  1310.   (let ((pop-up-windows (and pop-up-windows (eq vm-mutable-windows t))))
  1311.     (cond
  1312.      ((eq last-command 'vm-help)
  1313.       (describe-mode))
  1314.      ((eq vm-system-state 'previewing)
  1315.       (message "Type SPC to read message, n previews next message   (? gives more help)"))
  1316.      ((eq vm-system-state 'reading)
  1317.       (message "SPC and b scroll, (d)elete, (s)ave, (n)ext, (r)eply   (? gives more help)"))
  1318.      (t (describe-mode)))))
  1319.  
  1320. (defun vm-move-mail (source destination)
  1321.   (call-process "movemail" nil nil nil (expand-file-name source)
  1322.         (expand-file-name destination)))
  1323.  
  1324. (defun vm-gobble-crash-box ()
  1325.   (save-excursion
  1326.     (vm-save-restriction
  1327.      (widen)
  1328.      (let ((opoint-max (point-max)) crash-buf buffer-read-only
  1329.        (old-buffer-modified-p (buffer-modified-p))
  1330.        ;; crash box could contain a letter bomb...
  1331.        ;; force user notification of file variables.
  1332.        (inhibit-local-variables t))
  1333.        (setq crash-buf (find-file-noselect vm-crash-box))
  1334.        (goto-char (point-max))
  1335.        (insert-buffer-substring crash-buf
  1336.                 1 (1+ (save-excursion
  1337.                     (set-buffer crash-buf)
  1338.                     (widen)
  1339.                     (buffer-size))))
  1340.        (write-region opoint-max (point-max) buffer-file-name t t)
  1341.        (backup-buffer)
  1342.        ;; make sure primary inbox is private.  384 = octal 600
  1343.        (condition-case () (set-file-modes buffer-file-name 384) (error nil))
  1344.        (set-buffer-modified-p old-buffer-modified-p)
  1345.        (kill-buffer crash-buf)
  1346.        (condition-case () (delete-file vm-crash-box)
  1347.      (error nil))))))
  1348.  
  1349. (defun vm-get-spooled-mail ()
  1350.   (let ((spool-files (or vm-spool-files
  1351.              (list (concat vm-spool-directory (user-login-name)))))
  1352.     (inhibit-quit t)
  1353.     (got-mail))
  1354.     (if (file-exists-p vm-crash-box)
  1355.     (progn
  1356.       (message "Recovering messages from crash box...")
  1357.       (vm-gobble-crash-box)
  1358.       (message "Recovering messages from crash box... done")
  1359.       (setq got-mail t)))
  1360.     (while spool-files
  1361.       (if (file-readable-p (car spool-files))
  1362.       (progn
  1363.         (message "Getting new mail from %s..." (car spool-files))
  1364.         (vm-move-mail (car spool-files) vm-crash-box)
  1365.         (vm-gobble-crash-box)
  1366.         (message "Getting new mail from %s... done" (car spool-files))
  1367.         (setq got-mail t)))
  1368.       (setq spool-files (cdr spool-files)))
  1369.     got-mail ))
  1370.  
  1371. (defun vm-get-new-mail ()
  1372.   "Move any new mail that has arrived in the system mailbox into the
  1373. primary inbox.  New mail is appended to the disk and buffer copies of
  1374. the primary inbox.
  1375.  
  1376. This command is valid only from the primary inbox buffer."
  1377.   (interactive)
  1378.   (if vm-mail-buffer
  1379.       (set-buffer vm-mail-buffer))
  1380.   (if (not vm-primary-inbox-p)
  1381.       (error "This is not your primary inbox."))
  1382.   (if (not (and (vm-get-spooled-mail) (vm-assimilate-new-messages)))
  1383.       (message "No new mail.")
  1384.     (vm-emit-totals-blurb)
  1385.     ;; If there's a current grouping, then the summary has already
  1386.     ;; been redone in vm-group-messages.
  1387.     (if (and vm-summary-buffer (not vm-current-grouping))
  1388.     (progn
  1389.       (vm-do-summary)
  1390.       (vm-emit-totals-blurb)))
  1391.     (vm-thoughtfully-select-message)
  1392.     (if vm-summary-buffer
  1393.     (vm-set-summary-pointer (car vm-message-pointer)))))
  1394.  
  1395. (defun vm-emit-totals-blurb ()
  1396.   (message "%d message%s, %d new, %d unread."
  1397.        vm-total-count (if (= vm-total-count 1) "" "s")
  1398.        vm-new-count vm-unread-count))
  1399.  
  1400. (defun vm-find-first-unread-message ()
  1401.   (let (mp unread-mp)
  1402.     (setq mp vm-message-list)
  1403.     (while mp
  1404.       (if (and (vm-new-flag (car mp)) (not (vm-deleted-flag (car mp))))
  1405.       (setq unread-mp mp mp nil)
  1406.     (setq mp (cdr mp))))
  1407.     (if (null unread-mp)
  1408.     (progn
  1409.       (setq mp vm-message-list)
  1410.       (while mp
  1411.         (if (and (vm-unread-flag (car mp))
  1412.              (not (vm-deleted-flag (car mp))))
  1413.         (setq unread-mp mp mp nil)
  1414.           (setq mp (cdr mp))))))
  1415.     unread-mp))
  1416.  
  1417. ;; returns non-nil if there were any new messages
  1418. (defun vm-assimilate-new-messages ()
  1419.   (let ((tail-cons (vm-last vm-message-list))
  1420.     (new-messages-p (null vm-message-pointer)))
  1421.     (vm-save-restriction
  1422.      (widen)
  1423.      (vm-build-message-list)
  1424.      (vm-read-attributes)
  1425.      (setq new-messages-p (or new-messages-p (cdr tail-cons)))
  1426.      (if (and vm-current-grouping new-messages-p)
  1427.      (condition-case data
  1428.          (vm-group-messages vm-current-grouping)
  1429.        ;; presumably an unsupported grouping
  1430.        (error (message (car (cdr data)))
  1431.           (sleep-for 2)
  1432.           (vm-number-messages)))
  1433.        (vm-number-messages)))
  1434.     new-messages-p ))
  1435.  
  1436. (defun vm-thoughtfully-select-message ()
  1437.   ;; This is called after new messages have been assimilated in a folder.
  1438.   ;; We move to a new message only if the user is not "reading" the current
  1439.   ;; message, or if there is no current message.
  1440.   ;;
  1441.   ;; Most of the complications in the `if' test below are due to the presence
  1442.   ;; of the variables vm-preview-lines and vm-preview-read-messages.
  1443.   ;; These can cause previewing never to be done, or not be done for
  1444.   ;; specific messages.  In these cases VM assumes a user is "reading"
  1445.   ;; an exposed message if the top of the message is not visible in the
  1446.   ;; folder buffer window.
  1447.   (if (or (null vm-message-pointer)
  1448.       (not (eq vm-system-state 'reading))
  1449.       (and (or (null vm-preview-lines)
  1450.            (and (not vm-preview-read-messages)
  1451.             (not (vm-new-flag (car vm-message-pointer)))
  1452.             (not (vm-unread-flag (car vm-message-pointer)))))
  1453.            (let ((w (get-buffer-window (current-buffer))))
  1454.          (and w (pos-visible-in-window-p (point-min) w)))))
  1455.       (let ((mp (vm-find-first-unread-message)))
  1456.     (if mp
  1457.         (progn
  1458.           (if vm-message-pointer
  1459.           (setq vm-last-message-pointer vm-message-pointer
  1460.             vm-message-pointer mp)
  1461.         (setq vm-message-pointer mp))
  1462.           (vm-preview-current-message))
  1463.       (if (null vm-message-pointer)
  1464.           (vm-Next-message))))))
  1465.  
  1466. (defun vm-display-startup-message ()
  1467.   (if (sit-for 5)
  1468.       (let ((lines
  1469.          '(
  1470. "You may give out copies of VM.  Type \\[vm-show-copying-restrictions] to see the conditions"
  1471. "VM comes with ABSOLUTELY NO WARRANTY; type \\[vm-show-no-warranty] for full details"
  1472.            )))
  1473.     (message "VM %s, Copyright (C) 1989 Kyle E. Jones; type ? for help"
  1474.          vm-version)
  1475.     (while (and (sit-for 4) lines)
  1476.       (message (substitute-command-keys (car lines)))
  1477.       (setq lines (cdr lines)))))
  1478.   (message ""))
  1479.  
  1480. (defun vm (&optional folder)
  1481.   "Read mail under Emacs.
  1482. Optional first arg FOLDER specifies the folder to visit.  It defaults
  1483. to the value of vm-primary-inbox.  The folder buffer is put into VM
  1484. mode, a major mode for reading mail.
  1485.  
  1486. Visiting the primary inbox causes any contents of the system mailbox to
  1487. be moved and appended to the resulting buffer.
  1488.  
  1489. All the messages can be read by repeatedly pressing SPC.  Messages are
  1490. marked for deletion with `d', and saved to a folder with `s'.  Quitting
  1491. VM with `q' expunges messages marked for deletion and saves the buffered
  1492. folder to disk.
  1493.  
  1494. See the documentation for vm-mode for more information."
  1495.   (interactive)
  1496.   (if vm-session-beginning
  1497.       (progn
  1498.     (random t)
  1499.     (load "vm-undo")
  1500.     (load "vm-summary")))
  1501.   (if vm-mail-buffer
  1502.       (set-buffer vm-mail-buffer))
  1503.   ;; set inhibit-local-varaibles non-nil to protect
  1504.   ;; against letter bombs.
  1505.   (let ((inhibit-local-variables t))
  1506.     (setq mail-buffer (find-file-noselect
  1507.                (or folder (expand-file-name vm-primary-inbox))))
  1508.     (set-buffer mail-buffer)
  1509.     (or (buffer-modified-p) (setq vm-messages-not-on-disk 0))
  1510.     (let ((first-time (not (eq major-mode 'vm-mode)))
  1511.       (inhibit-quit t))
  1512.       (if first-time
  1513.       (progn
  1514.         (buffer-flush-undo (current-buffer))
  1515.         (abbrev-mode 0)
  1516.         (auto-fill-mode 0)
  1517.         (vm-mode)))
  1518.       (if (or (and vm-primary-inbox-p (vm-get-spooled-mail)) first-time)
  1519.       (progn
  1520.         (vm-assimilate-new-messages)
  1521.         ;; Can't allow a folder-empty error here because execution
  1522.         ;; would abort before the session startup code below.
  1523.         (if (null vm-message-list)
  1524.         (message "Folder is empty.")
  1525.           (vm-emit-totals-blurb)
  1526.           ;; If there's a current grouping, then the summary has already
  1527.           ;; been redone in vm-group-messages.
  1528.           (if (and vm-summary-buffer (not vm-current-grouping))
  1529.           (progn
  1530.             (vm-do-summary)
  1531.             ;; The summary update messages erased this info
  1532.             ;; from the echo area.
  1533.             (vm-emit-totals-blurb)))
  1534.           (save-window-excursion
  1535.         ;; Make sure the mail buffer is not visible.  This is
  1536.         ;; needed to insure that if vm-preview-lines is nil, the
  1537.         ;; mail window won't be momentarily displayed and then
  1538.         ;; disappear behind the summary window, if
  1539.         ;; vm-startup-with-summary is t.
  1540.         (if (get-buffer-window mail-buffer)
  1541.             (if (one-window-p)
  1542.             (switch-to-buffer (other-buffer))
  1543.               (delete-windows-on mail-buffer)))
  1544.         (set-buffer mail-buffer)
  1545.         (vm-thoughtfully-select-message))
  1546.           (if vm-summary-buffer
  1547.           (vm-set-summary-pointer (car vm-message-pointer))))))
  1548.       (switch-to-buffer mail-buffer)
  1549.       (if (and vm-message-list vm-startup-with-summary)
  1550.       (progn
  1551.         (vm-summarize t)
  1552.         (vm-emit-totals-blurb)
  1553.         (and (eq vm-startup-with-summary t)
  1554.          (eq vm-mutable-windows t)
  1555.          (if (eq major-mode 'vm-summary-mode)
  1556.              (delete-other-windows)
  1557.            (select-window (get-buffer-window vm-summary-buffer))
  1558.            (delete-other-windows))))
  1559.     (if (eq vm-mutable-windows t)
  1560.         (delete-other-windows)))
  1561.       (if vm-session-beginning
  1562.       (progn
  1563.         (setq vm-session-beginning nil)
  1564.         (or vm-inhibit-startup-message folder
  1565.         (vm-display-startup-message))
  1566.         (if (and vm-message-list (not (input-pending-p)))
  1567.         (vm-emit-totals-blurb)))))))
  1568.  
  1569. (defun vm-mode ()
  1570.   "Major mode for reading mail.
  1571.  
  1572. Commands:
  1573.    h - summarize folder contents
  1574.  
  1575.    n - go to next message
  1576.    p - go to previous message
  1577.    N - like `n' but ignores skip-variable settings
  1578.    P - like `p' but ignores skip-variable settings
  1579.  M-n - go to next unread message
  1580.  M-p - go to previous unread message
  1581.  RET - go to numbered message (uses prefix arg or prompts in minibuffer)
  1582.  TAB - go to last message seen
  1583.  M-s - incremental search through the folder
  1584.  
  1585.    t - display hidden headers
  1586.  SPC - scroll forward a page (if at end of message, then display next message)
  1587.    b - scroll backward a page
  1588.    > - go to end of current message
  1589.  
  1590.    d - delete current message (mark as deleted)
  1591.    u - undelete
  1592.    k - mark for deletion all messages with same subject as the current message
  1593.  
  1594.    r - reply (only to the sender of the message)
  1595.    R - reply with included text for current message
  1596.    f - followup (reply to all recipients of message)
  1597.    F - followup with included text from the current message
  1598.    z - forward the current message
  1599.    m - send a message
  1600.  
  1601.    @ - digestify and mail entire folder contents (the folder is not modified)
  1602.    * - burst a digest into indivdual messages, and append and assimilate these
  1603.        message into the current folder.
  1604.  
  1605.    G - group messages according to some criteria
  1606.  
  1607.    g - get any new mail that has arrived in the system mailbox
  1608.        (new mail is appended to the disk and buffer copies of the
  1609.        primary inbox.)
  1610.    v - visit another mail folder
  1611.  
  1612.    s - save current message in a folder (appends if folder already exists)
  1613.    w - write current message to a file without its headers (appends if exists)
  1614.    S - save entire folder to disk, expunging deleted messages
  1615.    A - save unfiled messages to their vm-auto-folder-alist specified folders
  1616.    # - expunge deleted messages (without saving folder)
  1617.    q - quit VM, deleted messages are expunged, folder saved to disk
  1618.    x - exit VM with no change to the folder
  1619.  
  1620.  C-_ - undo, special undo that retracts the most recent
  1621.              changes in message attributes.  Expunges and saves
  1622.              cannot be undone.
  1623.  
  1624.    ? - help
  1625.  
  1626.    ! - run a shell command
  1627.    | - run a shell command with the current message as input
  1628.  
  1629.  M-c - view conditions under which youmay redistribute of VM
  1630.  M-w - view the details of VM's lack of a warranty
  1631.  
  1632. Variables:
  1633.    vm-auto-folder-alist
  1634.    vm-berkeley-mail-compatibility
  1635.    vm-circular-folders
  1636.    vm-confirm-new-folders
  1637.    vm-crash-box
  1638.    vm-delete-after-saving
  1639.    vm-delete-empty-folders
  1640.    vm-folder-directory
  1641.    vm-folder-type
  1642.    vm-follow-summary-cursor
  1643.    vm-forwarding-subject-format
  1644.    vm-gargle-uucp
  1645.    vm-group-by
  1646.    vm-highlighted-header-regexp
  1647.    vm-in-reply-to-format
  1648.    vm-included-text-attribution-format
  1649.    vm-included-text-prefix
  1650.    vm-inhibit-startup-message
  1651.    vm-mail-window-percentage
  1652.    vm-mode-hooks
  1653.    vm-move-after-deleting
  1654.    vm-mutable-windows
  1655.    vm-preview-lines
  1656.    vm-preview-read-messages
  1657.    vm-primary-inbox
  1658.    vm-rfc934-forwarding
  1659.    vm-search-using-regexps
  1660.    vm-skip-deleted-messages
  1661.    vm-skip-read-messages
  1662.    vm-spool-files
  1663.    vm-startup-with-summary
  1664.    vm-strip-reply-headers
  1665.    vm-summary-format
  1666.    vm-visible-headers
  1667.    vm-visit-when-saving"
  1668.   (widen)
  1669.   (make-local-variable 'require-final-newline)
  1670.   (make-local-variable 'file-precious-flag)
  1671.   (setq
  1672.    buffer-read-only nil
  1673.    case-fold-search t
  1674.    file-precious-flag t
  1675.    major-mode 'vm-mode
  1676.    mode-line-format
  1677.    '("" mode-line-modified mode-line-buffer-identification "   "
  1678.      global-mode-string
  1679.      (vm-message-list
  1680.       ("   %[(" vm-ml-attributes-string ")%]----")
  1681.       ("   %[()%]----"))
  1682.      (-3 . "%p") "-%-")
  1683.    mode-line-buffer-identification
  1684.    '("VM " vm-version ": %b"
  1685.      (vm-message-list
  1686.       ("   " vm-ml-message-number
  1687.        " (of " vm-ml-highest-message-number ")")
  1688.       "  (no messages)"))
  1689.    mode-name "VM"
  1690.    require-final-newline nil
  1691.    vm-current-grouping vm-group-by
  1692.    vm-primary-inbox-p (equal buffer-file-name
  1693.                  (expand-file-name vm-primary-inbox)))
  1694.   (use-local-map vm-mode-map)
  1695.   (run-hooks 'vm-mode-hooks))
  1696.  
  1697. (put 'vm-mode 'mode-class 'special)
  1698.  
  1699. (autoload 'vm-group-messages "vm-group" nil t)
  1700.  
  1701. (autoload 'vm-reply "vm-reply" nil t)
  1702. (autoload 'vm-reply-include-text "vm-reply" nil t)
  1703. (autoload 'vm-followup "vm-reply" nil t)
  1704. (autoload 'vm-followup-include-text "vm-reply" nil t)
  1705. (autoload 'vm-mail "vm-reply" nil t)
  1706. (autoload 'vm-forward-message "vm-reply" nil t)
  1707. (autoload 'vm-send-digest "vm-reply" nil t)
  1708.  
  1709. (autoload 'vm-isearch-forward "vm-search" nil t)
  1710.  
  1711. (autoload 'vm-burst-digest "vm-digest" nil t)
  1712. (autoload 'vm-rfc934-char-stuff-region "vm-digest")
  1713. (autoload 'vm-digestify-region "vm-digest")
  1714.  
  1715. (autoload 'vm-show-no-warranty "vm-license" nil t)
  1716. (autoload 'vm-show-copying-restrictions "vm-license" nil t)
  1717.  
  1718. (autoload 'vm-auto-archive-messages "vm-save" nil t)
  1719. (autoload 'vm-save-message "vm-save" nil t)
  1720. (autoload 'vm-save-message-sans-headers "vm-save" nil t)
  1721. (autoload 'vm-pipe-message-to-command "vm-save" nil t)
  1722.  
  1723. (autoload 'vm-delete-message "vm-delete" nil t)
  1724. (autoload 'vm-undelete-message "vm-delete" nil t)
  1725. (autoload 'vm-kill-subject "vm-delete" nil t)
  1726. (autoload 'vm-expunge-folder "vm-delete" nil t)
  1727.  
  1728. (if (not (memq 'vm-write-file-hook write-file-hooks))
  1729.     (setq write-file-hooks
  1730.       (cons 'vm-write-file-hook write-file-hooks)))
  1731.