Initial Commit
[packages] / xemacs-packages / vm / lisp / vm.el
1 ;;; vm.el --- Entry points for VM
2 ;;
3 ;; Copyright (C) 1994-1998, 2003 Kyle E. Jones
4 ;; Copyright (C) 2003-2006 Robert Widhopf-Fenk
5 ;;
6 ;; This program is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 2 of the License, or
9 ;; (at your option) any later version.
10 ;;
11 ;; This program is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;; GNU General Public License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License along
17 ;; with this program; if not, write to the Free Software Foundation, Inc.,
18 ;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
21 ;;; History:
22 ;;
23 ;; This files was vm-startup.el!
24
25 ;;; Code:
26 (defvar enable-multibyte-characters)
27
28 (require 'vm-version)
29
30 ;;;###autoload
31 (defun vm-recover-folder ()
32 "Recover the autosave file for the current folder."
33   (interactive)
34   (vm-select-folder-buffer)
35   (recover-file (buffer-file-name)))
36
37 ;;;###autoload
38 (defun vm (&optional folder read-only access-method)
39   "Read mail under Emacs.
40 Optional first arg FOLDER specifies the folder to visit.  It defaults
41 to the value of vm-primary-inbox.  The folder buffer is put into VM
42 mode, a major mode for reading mail.
43
44 Prefix arg or optional second arg READ-ONLY non-nil indicates
45 that the folder should be considered read only.  No attribute
46 changes, message additions or deletions will be allowed in the
47 visited folder.
48
49 Visiting the primary inbox normally causes any contents of the system mailbox to
50 be moved and appended to the resulting buffer.  You can disable this automatic fetching of mail by setting `vm-auto-get-new-mail' to nil.
51
52 All the messages can be read by repeatedly pressing SPC.  Use `n'ext and
53 `p'revious to move about in the folder.  Messages are marked for
54 deletion with `d', and saved to another folder with `s'.  Quitting VM
55 with `q' saves the buffered folder to disk, but does not expunge
56 deleted messages.  Use `###' to expunge deleted messages.
57
58 See the documentation for vm-mode for more information."
59   (interactive (list nil current-prefix-arg))
60   (vm-session-initialization)
61   ;; recursive call to vm in order to allow defadvice on its first call
62   (unless (boundp 'vm-session-beginning)
63     (vm folder read-only access-method))
64   ;; set inhibit-local-variables non-nil to protect
65   ;; against letter bombs.
66   ;; set enable-local-variables to nil for newer Emacses
67   (catch 'done
68     ;; deduce the access method if none specified
69     (if (null access-method)
70         (let ((f (or folder vm-primary-inbox)))
71           (cond ((and vm-recognize-imap-maildrops
72                       ;; f could be a buffer
73                       (stringp f)
74                       (string-match vm-recognize-imap-maildrops f))
75                  (setq access-method 'imap
76                        folder f))
77                 ((and vm-recognize-pop-maildrops
78                       ;; f could be a buffer
79                       (stringp f)
80                       (string-match vm-recognize-pop-maildrops f))
81                  (setq access-method 'pop
82                        folder f)))))
83     (let ((full-startup (not (bufferp folder)))
84           (did-read-index-file nil)
85           folder-buffer first-time totals-blurb
86           folder-name remote-spec
87           preserve-auto-save-file)
88       (cond ((eq access-method 'pop)
89              (setq remote-spec (vm-pop-find-spec-for-name folder))
90              (if (null remote-spec)
91                  (error "No such POP folder: %s" folder))
92              (setq folder-name folder)
93              ;; Prior to VM 7.11, we computed the cache filename
94              ;; based on the full POP spec including the password
95              ;; if it was in the spec.  This meant that every
96              ;; time the user changed his password, we'd start
97              ;; visiting the wrong (and probably nonexistent)
98              ;; cache file.
99              ;;
100              ;; To fix this we do two things.  First, migrate the
101              ;; user's caches to the filenames based in the POP
102              ;; sepc without the password.  Second, we visit the
103              ;; old password based filename if it still exists
104              ;; after trying to migrate it.
105              ;;
106              ;; For VM 7.16 we apply the same logic to the access
107              ;; methods, pop, pop-ssh and pop-ssl and to
108              ;; authentication method and service port, which can
109              ;; also change and lead us to visit a nonexistent
110              ;; cache file.  The assumption is that these
111              ;; properties of the connection can change and we'll
112              ;; still be accessing the same mailbox on the
113              ;; server.
114              (let ((f-pass (vm-pop-make-filename-for-spec remote-spec))
115                    (f-nopass (vm-pop-make-filename-for-spec remote-spec t))
116                    (f-nospec (vm-pop-make-filename-for-spec remote-spec t t)))
117                (cond ((or (string= f-pass f-nospec)
118                           (file-exists-p f-nospec))
119                       nil )
120                      ((file-exists-p f-pass)
121                       ;; try to migrate
122                       (condition-case nil
123                           (rename-file f-pass f-nospec)
124                         (error nil)))
125                      ((file-exists-p f-nopass)
126                       ;; try to migrate
127                       (condition-case nil
128                           (rename-file f-nopass f-nospec)
129                         (error nil))))
130                ;; choose the one that exists, password version,
131                ;; nopass version and finally nopass+nospec
132                ;; version.
133                (cond ((file-exists-p f-pass)
134                       (setq folder f-pass))
135                      ((file-exists-p f-nopass)
136                       (setq folder f-nopass))
137                      (t
138                       (setq folder f-nospec)))))
139             ((eq access-method 'imap)
140              (setq remote-spec folder
141                    folder-name (or (nth 3 (vm-imap-parse-spec-to-list
142                                            remote-spec))
143                                    folder)
144                    folder (vm-imap-make-filename-for-spec remote-spec))))
145       (setq folder-buffer
146             (if (bufferp folder)
147                 folder
148               (let ((file (or folder (expand-file-name vm-primary-inbox
149                                                        vm-folder-directory))))
150                 (if (file-directory-p file)
151                     ;; MH code perhaps... ?
152                     (error "%s is a directory" file)
153                   (or (vm-get-file-buffer file)
154                       (let ((default-directory
155                               (or (and vm-folder-directory
156                                        (expand-file-name vm-folder-directory))
157                                   default-directory))
158                             (inhibit-local-variables t)
159                             (enable-local-variables nil)
160                             (enable-local-eval nil)
161                             ;; for Emacs/MULE
162                             (default-enable-multibyte-characters nil)
163                             ;; for XEmacs/Mule
164                             (coding-system-for-read
165                                  (vm-line-ending-coding-system)))
166                         (message "Reading %s..." file)
167                         (prog1 (find-file-noselect file)
168                           ;; update folder history
169                           (let ((item (or remote-spec folder
170                                           vm-primary-inbox)))
171                             (if (not (equal item (car vm-folder-history)))
172                                 (setq vm-folder-history
173                                       (cons item vm-folder-history))))
174                           (message "Reading %s... done" file))))))))
175       (set-buffer folder-buffer)
176       (cond ((memq access-method '(pop imap))
177              (if (not (equal folder-name (buffer-name)))
178                  (rename-buffer folder-name t))))
179       (if (and vm-fsfemacs-mule-p enable-multibyte-characters)
180           (set-buffer-multibyte nil))
181       ;; for MULE
182       ;;
183       ;; If the file coding system is not a no-conversion variant,
184       ;; make it so by encoding all the text, then setting the
185       ;; file coding system and decoding it.  This situation is
186       ;; only possible if a file is visited and then vm-mode is
187       ;; run on it afterwards.
188       ;;
189       ;; There are separate code blocks for FSF Emacs and XEmacs
190       ;; because the coding systems have different names.
191       (defvar buffer-file-coding-system)
192       (if (and (or vm-xemacs-mule-p vm-xemacs-file-coding-p)
193                (not (eq (get-coding-system buffer-file-coding-system)
194                         (get-coding-system 'no-conversion-unix)))
195                (not (eq (get-coding-system buffer-file-coding-system)
196                         (get-coding-system 'no-conversion-dos)))
197                (not (eq (get-coding-system buffer-file-coding-system)
198                         (get-coding-system 'no-conversion-mac)))
199                (not (eq (get-coding-system buffer-file-coding-system)
200                         (get-coding-system 'binary))))
201           (let ((buffer-read-only nil)
202                 (omodified (buffer-modified-p)))
203             (unwind-protect
204                 (progn
205                   (encode-coding-region (point-min) (point-max)
206                                         buffer-file-coding-system)
207                   (set-buffer-file-coding-system 'no-conversion nil)
208                   (decode-coding-region (point-min) (point-max)
209                                         buffer-file-coding-system))
210               (set-buffer-modified-p omodified))))
211       (if (and vm-fsfemacs-mule-p (null buffer-file-coding-system))
212           (set-buffer-file-coding-system 'raw-text nil))
213       (if (and vm-fsfemacs-mule-p
214                (not (eq (coding-system-base buffer-file-coding-system)
215                         (coding-system-base 'raw-text-unix)))
216                (not (eq (coding-system-base buffer-file-coding-system)
217                         (coding-system-base 'raw-text-mac)))
218                (not (eq (coding-system-base buffer-file-coding-system)
219                         (coding-system-base 'raw-text-dos)))
220                (not (eq (coding-system-base buffer-file-coding-system)
221                         (coding-system-base 'no-conversion))))
222           (let ((buffer-read-only nil)
223                 (omodified (buffer-modified-p)))
224             (unwind-protect
225                 (progn
226                   (encode-coding-region (point-min) (point-max)
227                                         buffer-file-coding-system)
228                   (set-buffer-file-coding-system 'raw-text nil)
229                   (decode-coding-region (point-min) (point-max)
230                                         buffer-file-coding-system))
231               (set-buffer-modified-p omodified))))
232       (vm-check-for-killed-summary)
233       (vm-check-for-killed-presentation)
234       ;; If the buffer's not modified then we know that there can be no
235       ;; messages in the folder that are not on disk.
236       (or (buffer-modified-p) (setq vm-messages-not-on-disk 0))
237       (setq first-time (not (eq major-mode 'vm-mode))
238             preserve-auto-save-file (and buffer-file-name
239                                           (not (buffer-modified-p))
240                                           (file-newer-than-file-p
241                                            (make-auto-save-file-name)
242                                            buffer-file-name)))
243       ;; Force the folder to be read only if the auto
244       ;; save file contains information the user might not
245       ;; want overwritten, i.e. recover-file might be
246       ;; desired.  What we want to avoid is an auto-save.
247       ;; Making the folder read only will keep
248       ;; subsequent actions from modifying the buffer in a
249       ;; way that triggers an auto save.
250       ;;
251       ;; Also force the folder read-only if it was read only and
252       ;; not already in vm-mode, since there's probably a good
253       ;; reason for this.
254       (setq vm-folder-read-only (or preserve-auto-save-file read-only
255                                     (default-value 'vm-folder-read-only)
256                                     (and first-time buffer-read-only)))
257       ;; If this is not a VM mode buffer then some initialization
258       ;; needs to be done
259       (if first-time
260           (progn
261             (buffer-disable-undo (current-buffer))
262             (abbrev-mode 0)
263             (auto-fill-mode 0)
264             ;; If an 8-bit message arrives undeclared the 8-bit
265             ;; characters in it should be displayed using the
266             ;; user's default face charset, rather than as octal
267             ;; escapes.
268             (vm-fsfemacs-nonmule-display-8bit-chars)
269             (vm-mode-internal access-method)
270             (cond ((eq access-method 'pop)
271                    (vm-set-folder-pop-maildrop-spec remote-spec))
272                   ((eq access-method 'imap)
273                    (vm-set-folder-imap-maildrop-spec remote-spec)))
274             ;; If the buffer is modified we don't know if the
275             ;; folder format has been changed to be different
276             ;; from index file, so don't read the index file in
277             ;; that case.
278             (if (not (buffer-modified-p))
279                 (setq did-read-index-file (vm-read-index-file-maybe)))))
280
281       ;; builds message list, reads attributes if they weren't
282       ;; read from an index file.
283       (vm-assimilate-new-messages nil (not did-read-index-file) nil t)
284
285       (if (and first-time (not did-read-index-file))
286           (progn
287             (vm-gobble-visible-header-variables)
288             (vm-gobble-bookmark)
289             (vm-gobble-pop-retrieved)
290             (vm-gobble-imap-retrieved)
291             (vm-gobble-summary)
292             (vm-gobble-labels)))
293
294       (if first-time
295           (vm-start-itimers-if-needed))
296
297       ;; make a new frame if the user wants one.  reuse an
298       ;; existing frame that is showing this folder.
299       (if (and full-startup
300                ;; this so that "emacs -f vm" doesn't create a frame.
301                this-command)
302           (apply 'vm-goto-new-folder-frame-maybe
303                  (if folder '(folder) '(primary-folder folder))))
304
305       ;; raise frame if requested and apply startup window
306       ;; configuration.
307       (if full-startup
308           (let ((buffer-to-display (or vm-summary-buffer
309                                        vm-presentation-buffer
310                                        (current-buffer))))
311             (vm-display buffer-to-display buffer-to-display
312                         (list this-command)
313                         (list (or this-command 'vm) 'startup))
314             (if vm-raise-frame-at-startup
315                 (vm-raise-frame))))
316
317       ;; say this NOW, before the non-previewers read a message,
318       ;; alter the new message count and confuse themselves.
319       (if full-startup
320           (progn
321             ;; save blurb so we can repeat it later as necessary.
322             (setq totals-blurb (vm-emit-totals-blurb))
323             (and buffer-file-name
324                  (vm-store-folder-totals buffer-file-name (cdr vm-totals)))))
325
326       (vm-thoughtfully-select-message)
327       (vm-update-summary-and-mode-line)
328       ;; need to do this after any frame creation because the
329       ;; toolbar sets frame-specific height and width specifiers.
330       (vm-toolbar-install-or-uninstall-toolbar)
331
332       (and vm-use-menus (vm-menu-support-possible-p)
333            (vm-menu-install-visited-folders-menu))
334
335       (if full-startup
336           (progn
337             (if (and (vm-should-generate-summary)
338                      ;; don't generate a summary if recover-file is
339                      ;; likely to happen, since recover-file does
340                      ;; not work in a summary buffer.
341                      (not preserve-auto-save-file))
342                 (vm-summarize t nil))
343             ;; raise the summary frame if the user wants frames
344             ;; raised and if there is a summary frame.
345             (if (and vm-summary-buffer
346                      vm-mutable-frames
347                      vm-frame-per-summary
348                      vm-raise-frame-at-startup)
349                 (vm-raise-frame))
350             ;; if vm-mutable-windows is nil, the startup
351             ;; configuration can't be applied, so do
352             ;; something to get a VM buffer on the screen
353             (if vm-mutable-windows
354                 (vm-display nil nil (list this-command)
355                             (list (or this-command 'vm) 'startup))
356               (save-excursion
357                 (switch-to-buffer (or vm-summary-buffer
358                                       vm-presentation-buffer
359                                       (current-buffer)))))))
360
361       (if vm-message-list
362           ;; don't decode MIME if recover-file is
363           ;; likely to happen, since recover-file does
364           ;; not work in a presentation buffer.
365           (let ((vm-auto-decode-mime-messages
366                  (and vm-auto-decode-mime-messages
367                       (not preserve-auto-save-file))))
368             (vm-preview-current-message)))
369
370       (run-hooks 'vm-visit-folder-hook)
371
372       ;; Warn user about auto save file, if appropriate.
373       (if (and full-startup preserve-auto-save-file)
374           (message
375            (substitute-command-keys
376             "Auto save file is newer; consider \\[vm-recover-folder].  FOLDER IS READ ONLY.")))
377       ;; if we're not doing a full startup or if doing more would
378       ;; trash the auto save file that we need to preserve,
379       ;; stop here.
380       (if (or (not full-startup) preserve-auto-save-file)
381           (throw 'done t))
382       
383       (if full-startup
384           (message totals-blurb))
385
386       (if (and vm-auto-get-new-mail
387                (not vm-block-new-mail)
388                (not vm-folder-read-only))
389           (progn
390             (message "Checking for new mail for %s..."
391                      (or buffer-file-name (buffer-name)))
392             (if (vm-get-spooled-mail t)
393                 (progn
394                   (setq totals-blurb (vm-emit-totals-blurb))
395                   (if (vm-thoughtfully-select-message)
396                       (vm-preview-current-message)
397                     (vm-update-summary-and-mode-line))))
398             (message totals-blurb)))
399
400       ;; Display copyright and copying info.
401       (if (and (interactive-p) (not vm-startup-message-displayed))
402           (progn
403             (vm-display-startup-message)
404             (if (not (input-pending-p))
405                 (message totals-blurb)))))))
406
407 ;;;###autoload
408 (defun vm-other-frame (&optional folder read-only)
409   "Like vm, but run in a newly created frame."
410   (interactive (list nil current-prefix-arg))
411   (vm-session-initialization)
412   (if (vm-multiple-frames-possible-p)
413       (if folder
414           (vm-goto-new-frame 'folder)
415         (vm-goto-new-frame 'primary-folder 'folder)))
416   (let ((vm-frame-per-folder nil)
417         (vm-search-other-frames nil))
418     (vm folder read-only))
419   (if (vm-multiple-frames-possible-p)
420       (vm-set-hooks-for-frame-deletion)))
421
422 ;;;###autoload
423 (defun vm-other-window (&optional folder read-only)
424   "Like vm, but run in a different window."
425   (interactive (list nil current-prefix-arg))
426   (vm-session-initialization)
427   (if (one-window-p t)
428       (split-window))
429   (other-window 1)
430   (let ((vm-frame-per-folder nil)
431         (vm-search-other-frames nil))
432     (vm folder read-only)))
433
434 (put 'vm-mode 'mode-class 'special)
435
436 ;;;###autoload
437 (defun vm-mode (&optional read-only)
438   "Major mode for reading mail.
439
440 This is VM.
441
442 Use M-x vm-submit-bug-report to submit a bug report.
443
444 Commands:
445 \\{vm-mode-map}
446
447
448 Customize VM by setting variables and store them in the file ~/.vm.
449 "
450   (interactive "P")
451   (vm (current-buffer) read-only)
452   (vm-display nil nil '(vm-mode) '(vm-mode)))
453
454 ;;;###autoload
455 (defun vm-visit-folder (folder &optional read-only)
456   "Visit a mail file.
457 VM will parse and present its messages to you in the usual way.
458
459 First arg FOLDER specifies the mail file to visit.  When this
460 command is called interactively the file name is read from the
461 minibuffer.
462
463 Prefix arg or optional second arg READ-ONLY non-nil indicates
464 that the folder should be considered read only.  No attribute
465 changes, messages additions or deletions will be allowed in the
466 visited folder."
467   (interactive
468    (save-excursion
469      (vm-session-initialization)
470      (vm-check-for-killed-folder)
471      (vm-select-folder-buffer-if-possible)
472      (let ((default-directory (if vm-folder-directory
473                                   (expand-file-name vm-folder-directory)
474                                 default-directory))
475            (default (or vm-last-visit-folder vm-last-save-folder))
476            (this-command this-command)
477            (last-command last-command))
478        (list (vm-read-file-name
479               (format "Visit%s folder:%s "
480                       (if current-prefix-arg " read only" "")
481                       (if default
482                           (format " (default %s)" default)
483                         ""))
484               default-directory default nil nil 'vm-folder-history)
485              current-prefix-arg))))
486   (vm-session-initialization)
487   (vm-check-for-killed-folder)
488   (vm-select-folder-buffer-if-possible)
489   (vm-check-for-killed-summary)
490   (setq vm-last-visit-folder folder)
491   (let ((access-method nil) foo)
492     (cond ((and (stringp vm-recognize-pop-maildrops)
493                 (string-match vm-recognize-pop-maildrops folder)
494                 (setq foo (vm-pop-find-name-for-spec folder)))
495            (setq folder foo
496                  access-method 'pop))
497           ((and (stringp vm-recognize-imap-maildrops)
498                 (string-match vm-recognize-imap-maildrops folder)
499                 (setq foo (vm-imap-find-name-for-spec folder)))
500            (setq folder foo
501                  access-method 'imap))
502           (t
503            (let ((default-directory (or vm-folder-directory default-directory)))
504              (setq folder (expand-file-name folder)))))
505     (vm folder read-only access-method)))
506
507 ;;;###autoload
508 (defun vm-visit-folder-other-frame (folder &optional read-only)
509   "Like vm-visit-folder, but run in a newly created frame."
510   (interactive
511    (save-excursion
512      (vm-session-initialization)
513      (vm-check-for-killed-folder)
514      (vm-select-folder-buffer-if-possible)
515      (let ((default-directory (if vm-folder-directory
516                                   (expand-file-name vm-folder-directory)
517                                 default-directory))
518            (default (or vm-last-visit-folder vm-last-save-folder))
519            (this-command this-command)
520            (last-command last-command))
521        (list (vm-read-file-name
522               (format "Visit%s folder in other frame:%s "
523                       (if current-prefix-arg " read only" "")
524                       (if default
525                           (format " (default %s)" default)
526                         ""))
527               default-directory default nil nil 'vm-folder-history)
528              current-prefix-arg))))
529   (vm-session-initialization)
530   (if (vm-multiple-frames-possible-p)
531       (vm-goto-new-frame 'folder))
532   (let ((vm-frame-per-folder nil)
533         (vm-search-other-frames nil))
534     (vm-visit-folder folder read-only))
535   (if (vm-multiple-frames-possible-p)
536       (vm-set-hooks-for-frame-deletion)))
537
538 ;;;###autoload
539 (defun vm-visit-folder-other-window (folder &optional read-only)
540   "Like vm-visit-folder, but run in a different window."
541   (interactive
542    (save-excursion
543      (vm-session-initialization)
544      (vm-check-for-killed-folder)
545      (vm-select-folder-buffer-if-possible)
546      (let ((default-directory (if vm-folder-directory
547                                   (expand-file-name vm-folder-directory)
548                                 default-directory))
549            (default (or vm-last-visit-folder vm-last-save-folder))
550            (this-command this-command)
551            (last-command last-command))
552        (list (vm-read-file-name
553               (format "Visit%s folder in other window:%s "
554                       (if current-prefix-arg " read only" "")
555                       (if default
556                           (format " (default %s)" default)
557                         ""))
558               default-directory default nil nil 'vm-folder-history)
559              current-prefix-arg))))
560   (vm-session-initialization)
561   (if (one-window-p t)
562       (split-window))
563   (other-window 1)
564   (let ((vm-frame-per-folder nil)
565         (vm-search-other-frames nil))
566     (vm-visit-folder folder read-only)))
567
568 ;;;###autoload
569 (defun vm-visit-pop-folder (folder &optional read-only)
570   "Visit a POP mailbox.
571 VM will present its messages to you in the usual way.  Messages
572 found in the POP mailbox will be downloaded and stored in a local
573 cache.  If you expunge messages from the cache, the corresponding
574 messages will be expunged from the POP mailbox.
575
576 First arg FOLDER specifies the name of the POP mailbox to visit.
577 You can only visit mailboxes that are specified in `vm-pop-folder-alist'.
578 When this command is called interactively the mailbox name is read from the
579 minibuffer.
580
581 Prefix arg or optional second arg READ-ONLY non-nil indicates
582 that the folder should be considered read only.  No attribute
583 changes, messages additions or deletions will be allowed in the
584 visited folder."
585   (interactive
586    (save-excursion
587      (vm-session-initialization)
588      (vm-check-for-killed-folder)
589      (vm-select-folder-buffer-if-possible)
590      (require 'vm-pop)
591      (let ((completion-list (mapcar (function (lambda (x) (nth 1 x)))
592                                     vm-pop-folder-alist))
593            (default vm-last-visit-pop-folder)
594            (this-command this-command)
595            (last-command last-command))
596        (list (vm-read-string
597               (format "Visit%s POP folder:%s "
598                       (if current-prefix-arg " read only" "")
599                       (if default
600                           (format " (default %s)" default)
601                         ""))
602               completion-list)
603              current-prefix-arg))))
604   (vm-session-initialization)
605   (vm-check-for-killed-folder)
606   (vm-select-folder-buffer-if-possible)
607   (vm-check-for-killed-summary)
608   (if (and (equal folder "") (stringp vm-last-visit-pop-folder))
609       (setq folder vm-last-visit-pop-folder))
610   (if (null (vm-pop-find-spec-for-name folder))
611       (error "No such POP folder: %s" folder))
612   (setq vm-last-visit-pop-folder folder)
613   (vm folder read-only 'pop))
614
615 ;;;###autoload
616 (defun vm-visit-pop-folder-other-frame (folder &optional read-only)
617   "Like vm-visit-pop-folder, but run in a newly created frame."
618   (interactive
619    (save-excursion
620      (vm-session-initialization)
621      (vm-check-for-killed-folder)
622      (vm-select-folder-buffer-if-possible)
623      (require 'vm-pop)
624      (let ((completion-list (mapcar (function (lambda (x) (nth 1 x)))
625                                     vm-pop-folder-alist))
626            (default vm-last-visit-pop-folder)
627            (this-command this-command)
628            (last-command last-command))
629        (list (vm-read-string
630               (format "Visit%s POP folder:%s "
631                       (if current-prefix-arg " read only" "")
632                       (if default
633                           (format " (default %s)" default)
634                         ""))
635               completion-list)
636              current-prefix-arg))))
637   (vm-session-initialization)
638   (if (vm-multiple-frames-possible-p)
639       (vm-goto-new-frame 'folder))
640   (let ((vm-frame-per-folder nil)
641         (vm-search-other-frames nil))
642     (vm-visit-pop-folder folder read-only))
643   (if (vm-multiple-frames-possible-p)
644       (vm-set-hooks-for-frame-deletion)))
645
646 ;;;###autoload
647 (defun vm-visit-pop-folder-other-window (folder &optional read-only)
648   "Like vm-visit-pop-folder, but run in a different window."
649   (interactive
650    (save-excursion
651      (vm-session-initialization)
652      (vm-check-for-killed-folder)
653      (vm-select-folder-buffer-if-possible)
654      (require 'vm-pop)
655      (let ((completion-list (mapcar (function (lambda (x) (nth 1 x)))
656                                     vm-pop-folder-alist))
657            (default vm-last-visit-pop-folder)
658            (this-command this-command)
659            (last-command last-command))
660        (list (vm-read-string
661               (format "Visit%s POP folder:%s "
662                       (if current-prefix-arg " read only" "")
663                       (if default
664                           (format " (default %s)" default)
665                         ""))
666               completion-list)
667              current-prefix-arg))))
668   (vm-session-initialization)
669   (if (one-window-p t)
670       (split-window))
671   (other-window 1)
672   (let ((vm-frame-per-folder nil)
673         (vm-search-other-frames nil))
674     (vm-visit-pop-folder folder read-only)))
675
676 ;;;###autoload
677 (defun vm-visit-imap-folder (folder &optional read-only)
678   "Visit a IMAP mailbox.
679 VM will present its messages to you in the usual way.  Messages
680 found in the IMAP mailbox will be downloaded and stored in a local
681 cache.  If you expunge messages from the cache, the corresponding
682 messages will be expunged from the IMAP mailbox.
683
684 First arg FOLDER specifies the IMAP mailbox to visit.  You can only
685 visit mailboxes on servers that are listed in `vm-imap-server-list'.
686 When this command is called interactively the server and mailbox
687 names are read from the minibuffer.
688
689 Prefix arg or optional second arg READ-ONLY non-nil indicates
690 that the folder should be considered read only.  No attribute
691 changes, messages additions or deletions will be allowed in the
692 visited folder."
693   (interactive
694    (save-excursion
695      (vm-session-initialization)
696      (vm-check-for-killed-folder)
697      (vm-select-folder-buffer-if-possible)
698      (require 'vm-imap)
699      (let ((this-command this-command)
700            (last-command last-command))
701        (list (vm-read-imap-folder-name
702               (format "Visit%s IMAP folder: "
703                       (if current-prefix-arg " read only" ""))
704               vm-imap-server-list t)
705              current-prefix-arg))))
706   (vm-session-initialization)
707   (vm-check-for-killed-folder)
708   (vm-select-folder-buffer-if-possible)
709   (vm-check-for-killed-summary)
710   (vm folder read-only 'imap))
711
712 ;;;###autoload
713 (defun vm-visit-imap-folder-other-frame (folder &optional read-only)
714   "Like vm-visit-imap-folder, but run in a newly created frame."
715   (interactive
716    (save-excursion
717      (vm-session-initialization)
718      (vm-check-for-killed-folder)
719      (vm-select-folder-buffer-if-possible)
720      (require 'vm-imap)
721      (let ((this-command this-command)
722            (last-command last-command))
723        (list (vm-read-imap-folder-name
724               (format "Visit%s IMAP folder: "
725                       (if current-prefix-arg " read only" ""))
726               vm-imap-server-list)
727              current-prefix-arg))))
728   (vm-session-initialization)
729   (if (vm-multiple-frames-possible-p)
730       (vm-goto-new-frame 'folder))
731   (let ((vm-frame-per-folder nil)
732         (vm-search-other-frames nil))
733     (vm-visit-imap-folder folder read-only))
734   (if (vm-multiple-frames-possible-p)
735       (vm-set-hooks-for-frame-deletion)))
736
737 ;;;###autoload
738 (defun vm-visit-imap-folder-other-window (folder &optional read-only)
739   "Like vm-visit-imap-folder, but run in a different window."
740   (interactive
741    (save-excursion
742      (vm-session-initialization)
743      (vm-check-for-killed-folder)
744      (vm-select-folder-buffer-if-possible)
745      (require 'vm-imap)
746      (let ((this-command this-command)
747            (last-command last-command))
748        (list (vm-read-imap-folder-name
749               (format "Visit%s IMAP folder: "
750                       (if current-prefix-arg " read only" ""))
751               vm-imap-server-list)
752              current-prefix-arg))))
753   (vm-session-initialization)
754   (if (one-window-p t)
755       (split-window))
756   (other-window 1)
757   (let ((vm-frame-per-folder nil)
758         (vm-search-other-frames nil))
759     (vm-visit-imap-folder folder read-only)))
760
761 (put 'vm-virtual-mode 'mode-class 'special)
762
763 (defun vm-virtual-mode (&rest ignored)
764   "Mode for reading multiple mail folders as one folder.
765
766 The commands available are the same commands that are found in
767 vm-mode, except that a few of them are not applicable to virtual
768 folders.
769
770 vm-virtual-mode is not a normal major mode.  If you run it, it
771 will not do anything.  The entry point to vm-virtual-mode is
772 vm-visit-virtual-folder.")
773
774 (defvar scroll-in-place)
775
776 ;;;###autoload
777 (defun vm-visit-virtual-folder (folder-name &optional read-only bookmark)
778   (interactive
779    (let ((last-command last-command)
780          (this-command this-command))
781      (vm-session-initialization)
782      (list
783       (vm-read-string (format "Visit%s virtual folder: "
784                               (if current-prefix-arg " read only" ""))
785                       vm-virtual-folder-alist)
786       current-prefix-arg)))
787   (vm-session-initialization)
788   (require 'vm-virtual)
789   (if (not (assoc folder-name vm-virtual-folder-alist))
790       (error "No such virtual folder, %s" folder-name))
791   (let ((buffer-name (concat "(" folder-name ")"))
792         first-time blurb)
793     (set-buffer (get-buffer-create buffer-name))
794     (setq first-time (not (eq major-mode 'vm-virtual-mode)))
795     (if first-time
796         (progn
797           (if (fboundp 'buffer-disable-undo)
798               (buffer-disable-undo (current-buffer))
799             ;; obfuscation to make the v19 compiler not whine
800             ;; about obsolete functions.
801             (let ((x 'buffer-flush-undo))
802               (funcall x (current-buffer))))
803           (abbrev-mode 0)
804           (auto-fill-mode 0)
805           (vm-fsfemacs-nonmule-display-8bit-chars)
806           (setq mode-name "VM Virtual"
807                 mode-line-format vm-mode-line-format
808                 buffer-read-only t
809                 vm-folder-read-only read-only
810                 vm-label-obarray (make-vector 29 0)
811                 vm-virtual-folder-definition
812                   (assoc folder-name vm-virtual-folder-alist))
813           ;; scroll in place messes with scroll-up and this loses
814           (make-local-variable 'scroll-in-place)
815           (setq scroll-in-place nil)
816           (vm-build-virtual-message-list nil)
817           (use-local-map vm-mode-map)
818           (and (vm-menu-support-possible-p)
819                (vm-menu-install-menus))
820           (add-hook 'kill-buffer-hook 'vm-garbage-collect-folder)
821           (add-hook 'kill-buffer-hook 'vm-garbage-collect-message)
822           ;; save this for last in case the user interrupts.
823           ;; an interrupt anywhere before this point will cause
824           ;; everything to be redone next revisit.
825           (setq major-mode 'vm-virtual-mode)
826           (run-hooks 'vm-virtual-mode-hook)
827           ;; must come after the setting of major-mode
828           (setq mode-popup-menu (and vm-use-menus
829                                      (vm-menu-support-possible-p)
830                                      (vm-menu-mode-menu)))
831           (setq blurb (vm-emit-totals-blurb))
832           (if vm-summary-show-threads
833               (vm-sort-messages "thread"))
834           (if bookmark
835               (let ((mp vm-message-list))
836                 (while mp
837                   (if (eq bookmark (vm-real-message-of (car mp)))
838                       (progn
839                         (vm-record-and-change-message-pointer
840                          vm-message-pointer mp)
841                         (vm-preview-current-message)
842                         (setq mp nil))
843                     (setq mp (cdr mp))))))
844           (if (null vm-message-pointer)
845               (if (vm-thoughtfully-select-message)
846                   (vm-preview-current-message)
847                 (vm-update-summary-and-mode-line)))
848           (message blurb)))
849     ;; make a new frame if the user wants one.  reuse an
850     ;; existing frame that is showing this folder.
851     (vm-goto-new-folder-frame-maybe 'folder)
852     (if vm-raise-frame-at-startup
853         (vm-raise-frame))
854     (vm-display nil nil (list this-command) (list this-command 'startup))
855     (vm-toolbar-install-or-uninstall-toolbar)
856     (if first-time
857         (progn
858           (if (vm-should-generate-summary)
859               (progn (vm-summarize t nil)
860                      (message blurb)))
861           ;; raise the summary frame if the user wants frames
862           ;; raised and if there is a summary frame.
863           (if (and vm-summary-buffer
864                    vm-mutable-frames
865                    vm-frame-per-summary
866                    vm-raise-frame-at-startup)
867               (vm-raise-frame))
868           ;; if vm-mutable-windows is nil, the startup
869           ;; configuration can't be applied, so do
870           ;; something to get a VM buffer on the screen
871           (if vm-mutable-windows
872               (vm-display nil nil (list this-command)
873                           (list (or this-command 'vm) 'startup))
874             (save-excursion
875               (switch-to-buffer (or vm-summary-buffer
876                                     vm-presentation-buffer
877                                     (current-buffer)))))))
878
879     ;; check interactive-p so as not to bog the user down if they
880     ;; run this function from within another function.
881     (and (interactive-p)
882          (not vm-startup-message-displayed)
883          (vm-display-startup-message)
884          (message blurb))))
885
886 ;;;###autoload
887 (defun vm-visit-virtual-folder-other-frame (folder-name &optional read-only)
888   "Like vm-visit-virtual-folder, but run in a newly created frame."
889   (interactive
890    (let ((last-command last-command)
891          (this-command this-command))
892      (vm-session-initialization)
893      (list
894       (vm-read-string (format "Visit%s virtual folder in other frame: "
895                               (if current-prefix-arg " read only" ""))
896                       vm-virtual-folder-alist)
897       current-prefix-arg)))
898   (vm-session-initialization)
899   (if (vm-multiple-frames-possible-p)
900       (vm-goto-new-frame 'folder))
901   (let ((vm-frame-per-folder nil)
902         (vm-search-other-frames nil))
903     (vm-visit-virtual-folder folder-name read-only))
904   (if (vm-multiple-frames-possible-p)
905       (vm-set-hooks-for-frame-deletion)))
906
907 ;;;###autoload
908 (defun vm-visit-virtual-folder-other-window (folder-name &optional read-only)
909   "Like vm-visit-virtual-folder, but run in a different window."
910   (interactive
911    (let ((last-command last-command)
912          (this-command this-command))
913      (vm-session-initialization)
914      (list
915       (vm-read-string (format "Visit%s virtual folder in other window: "
916                               (if current-prefix-arg " read only" ""))
917                       vm-virtual-folder-alist)
918       current-prefix-arg)))
919   (vm-session-initialization)
920   (if (one-window-p t)
921       (split-window))
922   (other-window 1)
923   (let ((vm-frame-per-folder nil)
924         (vm-search-other-frames nil))
925     (vm-visit-virtual-folder folder-name read-only)))
926
927 ;;;###autoload
928 (defun vm-mail (&optional to subject)
929   "Send a mail message from within VM, or from without.
930 Optional argument TO is a string that should contain a comma separated
931 recipient list."
932   (interactive)
933   (vm-session-initialization)
934   (vm-check-for-killed-folder)
935   (vm-select-folder-buffer-if-possible)
936   (vm-check-for-killed-summary)
937   (vm-mail-internal nil to subject)
938   (run-hooks 'vm-mail-hook)
939   (run-hooks 'vm-mail-mode-hook))
940
941 ;;;###autoload
942 (defun vm-mail-other-frame (&optional to)
943   "Like vm-mail, but run in a newly created frame.
944 Optional argument TO is a string that should contain a comma separated
945 recipient list."
946   (interactive)
947   (vm-session-initialization)
948   (if (vm-multiple-frames-possible-p)
949       (vm-goto-new-frame 'composition))
950   (let ((vm-frame-per-composition nil)
951         (vm-search-other-frames nil))
952     (vm-mail to))
953   (if (vm-multiple-frames-possible-p)
954       (vm-set-hooks-for-frame-deletion)))
955
956 ;;;###autoload
957 (defun vm-mail-other-window (&optional to)
958   "Like vm-mail, but run in a different window.
959 Optional argument TO is a string that should contain a comma separated
960 recipient list."
961   (interactive)
962   (vm-session-initialization)
963   (if (one-window-p t)
964       (split-window))
965   (other-window 1)
966   (let ((vm-frame-per-composition nil)
967         (vm-search-other-frames nil))
968     (vm-mail to)))
969
970 (fset 'vm-folders-summary-mode 'vm-mode)
971 (put 'vm-folders-summary-mode 'mode-class 'special)
972
973
974 ;;;###autoload
975 (defun vm-folders-summarize (&optional display raise)
976   "Generate a summary of the folders in your folder directories.
977 Set `vm-folders-summary-directories' to specify the folder directories.
978 Press RETURN or click mouse button 2 on an entry in the folders
979 summary buffer to select a folder."
980   (interactive "p\np")
981   (vm-session-initialization)
982   (vm-check-for-killed-summary)
983   (if (not (featurep 'berkeley-db))
984       (error "Berkeley DB support needed to run this command"))
985   (if (null vm-folders-summary-database)
986       (error "'vm-folders-summary-database' must be non-nil to run this command"))
987   (if (null vm-folders-summary-buffer)
988       (let ((folder-buffer (and (eq major-mode 'vm-mode)
989                                 (current-buffer))))
990         (setq vm-folders-summary-buffer
991               (let ((default-enable-multibyte-characters t))
992                 (get-buffer-create "VM Folders Summary")))
993         (save-excursion
994           (set-buffer vm-folders-summary-buffer)
995           (abbrev-mode 0)
996           (auto-fill-mode 0)
997           (vm-fsfemacs-nonmule-display-8bit-chars)
998           (if (fboundp 'buffer-disable-undo)
999               (buffer-disable-undo (current-buffer))
1000             ;; obfuscation to make the v19 compiler not whine
1001             ;; about obsolete functions.
1002             (let ((x 'buffer-flush-undo))
1003               (funcall x (current-buffer))))
1004           (vm-folders-summary-mode-internal))
1005         (vm-make-folders-summary-associative-hashes)
1006         (vm-do-folders-summary)))
1007   ;; if this command was run from a VM related buffer, select
1008   ;; the folder buffer in the folders summary, but only if that
1009   ;; folder has an entry there.
1010   (and vm-mail-buffer
1011        (vm-check-for-killed-folder))
1012   (save-excursion
1013     (and vm-mail-buffer
1014          (vm-select-folder-buffer))
1015     (vm-check-for-killed-summary)
1016     (let ((folder-buffer (and (eq major-mode 'vm-mode)
1017                               (current-buffer)))
1018           fs )
1019       (if (or (null vm-folders-summary-hash) (null folder-buffer)
1020               (null buffer-file-name))
1021           nil
1022         (setq fs (symbol-value (intern-soft (vm-make-folders-summary-key
1023                                              buffer-file-name)
1024                                             vm-folders-summary-hash)))
1025         (if (null fs)
1026             nil
1027           (vm-mark-for-folders-summary-update buffer-file-name)
1028           (set-buffer vm-folders-summary-buffer)
1029           (setq vm-mail-buffer folder-buffer)))))
1030   (if display
1031       (save-excursion
1032         (vm-goto-new-folders-summary-frame-maybe)
1033         (vm-display vm-folders-summary-buffer t
1034                     '(vm-folders-summarize)
1035                     (list this-command) (not raise))
1036         ;; need to do this after any frame creation because the
1037         ;; toolbar sets frame-specific height and width specifiers.
1038         (set-buffer vm-folders-summary-buffer)
1039         (vm-toolbar-install-or-uninstall-toolbar))
1040     (vm-display nil nil '(vm-folders-summarize)
1041                 (list this-command)))
1042   (vm-update-summary-and-mode-line))
1043
1044 (defvar mail-send-actions)
1045
1046 ;;;###autoload
1047 (defun vm-compose-mail (&optional to subject other-headers continue
1048                         switch-function yank-action
1049                         send-actions)
1050   (interactive)
1051   (vm-session-initialization)
1052   (if continue
1053       (vm-continue-composing-message)
1054     (let ((buffer (vm-mail-internal
1055                    (if to
1056                        (format "message to %s"
1057                                (vm-truncate-roman-string to 20))
1058                      nil)
1059                    to subject)))
1060       (goto-char (point-min))
1061       (re-search-forward (concat "^" mail-header-separator "$"))
1062       (beginning-of-line)
1063       (while other-headers
1064         (insert (car (car other-headers)))
1065         (while (eq (char-syntax (char-before (point))) ?\ )
1066           (delete-char -1))
1067         (while (eq (char-before (point)) ?:)
1068           (delete-char -1))
1069         (insert ": " (cdr (car other-headers)))
1070         (if (not (eq (char-before (point)) ?\n))
1071             (insert "\n"))
1072         (setq other-headers (cdr other-headers)))
1073       (cond ((null to)
1074              (mail-position-on-field "To"))
1075             ((null subject)
1076              (mail-position-on-field "Subject"))
1077             (t
1078              (mail-text)))
1079       (funcall (or switch-function (function switch-to-buffer))
1080                (current-buffer))
1081       (if yank-action
1082           (save-excursion
1083             (mail-text)
1084             (apply (car yank-action) (cdr yank-action))
1085             (push-mark (point))
1086             (mail-text)
1087             (cond (mail-citation-hook (run-hooks 'mail-citation-hook))
1088                   (mail-yank-hooks (run-hooks 'mail-yank-hooks))
1089                   (t (vm-mail-yank-default)))))
1090       (make-local-variable 'mail-send-actions)
1091       (setq mail-send-actions send-actions))))
1092
1093 ;;;###autoload
1094 (defun vm-submit-bug-report ()
1095   "Submit a bug report, with pertinent information to the VM bug list."
1096   (interactive)
1097   (require 'reporter)
1098   (vm-session-initialization)
1099   ;; Use VM to send the bug report.  Could be trouble if vm-mail
1100   ;; is what the user wants to complain about.  But most of the
1101   ;; time we'll be fine and users like to use MIME to attach
1102   ;; stuff to the reports.
1103   (let ((reporter-mailer '(vm-mail))
1104         (mail-user-agent 'vm-user-agent)
1105         varlist)
1106     (setq varlist (apropos-internal "^\\(vm\\|vmpc\\)-" 'user-variable-p)
1107           varlist (sort varlist
1108                         (lambda (v1 v2)
1109                           (string-lessp (format "%s" v1) (format "%s" v2)))))
1110     (let ((vars-to-delete '(
1111                             ;; passwords might be listed here
1112                             vm-spool-files
1113                             vm-imap-auto-expunge-alist
1114                             vm-pop-auto-expunge-alist
1115                             vm-pop-folder-alist
1116                             )))
1117       (while vars-to-delete
1118         (setq varlist (delete (car vars-to-delete) varlist)
1119               vars-to-delete (cdr vars-to-delete))))
1120     ;; see what the user had loaded
1121     (setq varlist (append (list 'features) varlist))
1122     (delete-other-windows)
1123     (reporter-submit-bug-report
1124      vm-maintainer-address
1125      (concat "VM " (vm-version))
1126      varlist
1127      nil
1128      nil
1129      "Please change the Subject header to a concise bug description.
1130
1131 Consider to post this to the News group gnu.emacs.vm.bug instead.
1132
1133 In this report, remember to cover the basics, that is, what you expected to
1134 happen and what in fact did happen and how to reproduce it.
1135
1136 Please remove these instructions and other stuff which is unrelated to the bug
1137 from your message.")
1138     (save-excursion
1139       (goto-char (point-min))
1140       (mail-position-on-field "Subject")
1141       (insert "VM-BUG: "))))
1142
1143 (defun vm-edit-init-file ()
1144   "Edit the ~/.vm."
1145   (interactive)
1146   (find-file-other-frame "~/.vm"))
1147
1148 (defun vm-load-init-file (&optional interactive)
1149   (interactive "p")
1150   (if (or (not vm-init-file-loaded) interactive)
1151       (progn
1152         (and vm-init-file
1153              (load vm-init-file (not interactive) (not interactive) t))
1154         (and vm-preferences-file (load vm-preferences-file t t t))))
1155   (setq vm-init-file-loaded t)
1156   (vm-display nil nil '(vm-load-init-file) '(vm-load-init-file)))
1157
1158 (defun vm-check-emacs-version ()
1159   (cond ((and vm-xemacs-p (< emacs-major-version 21))
1160          (error "VM %s must be run on XEmacs 21 or a later version."
1161                 (vm-version)))
1162         ((and vm-fsfemacs-p (< emacs-major-version 21))
1163          (error "VM %s must be run on GNU Emacs 21 or a later version."
1164                 (vm-version)))))
1165
1166 (defun vm-set-debug-flags ()
1167   (or stack-trace-on-error
1168       debug-on-error
1169       (setq stack-trace-on-error
1170             '(
1171               wrong-type-argument
1172               wrong-number-of-arguments
1173               args-out-of-range
1174               void-function
1175               void-variable
1176               invalid-function
1177              ))))
1178
1179 (defun vm-session-initialization ()
1180   ;;  (vm-set-debug-flags)
1181   ;; If this is the first time VM has been run in this Emacs session,
1182   ;; do some necessary preparations.
1183   (if (or (not (boundp 'vm-session-beginning))
1184           vm-session-beginning)
1185       (progn
1186         (vm-check-emacs-version)
1187         (require 'vm-vars)
1188         (require 'vm-macro)
1189         (require 'vm-misc)
1190         (require 'vm-message)
1191         (require 'vm-minibuf)
1192         (require 'vm-motion)
1193         (require 'vm-page)
1194         (require 'vm-mouse)
1195         (require 'vm-summary)
1196         (require 'vm-undo)
1197         (require 'vm-mime)
1198         (require 'vm-folder)
1199         (require 'vm-toolbar)
1200         (require 'vm-window)
1201         (require 'vm-menu)
1202         (require 'vm-rfaddons)
1203         (if (locate-library "pgg")
1204             (require 'vm-pgg)
1205           (message "vm-pgg disabled since pgg is missing!"))
1206         (add-hook 'kill-emacs-hook 'vm-garbage-collect-global)
1207         (random t)
1208         (vm-load-init-file)
1209         (when vm-enable-addons
1210           (vm-rfaddons-infect-vm 0 vm-enable-addons)
1211           (when (or (eq t vm-enable-addons)
1212                     (member 'summary-faces vm-enable-addons))
1213             (require 'vm-summary-faces)
1214             (vm-summary-faces-mode 1)))
1215         (if (not vm-window-configuration-file)
1216             (setq vm-window-configurations vm-default-window-configuration)
1217           (or (vm-load-window-configurations vm-window-configuration-file)
1218               (setq vm-window-configurations vm-default-window-configuration)))
1219         (setq vm-buffers-needing-display-update (make-vector 29 0))
1220         (setq vm-buffers-needing-undo-boundaries (make-vector 29 0))
1221         (add-hook 'post-command-hook 'vm-add-undo-boundaries)
1222         (if (if vm-xemacs-p
1223                 (find-face 'vm-monochrome-image)
1224               (facep 'vm-monochrome-image))
1225             nil
1226           (make-face 'vm-monochrome-image)
1227           (set-face-background 'vm-monochrome-image "white")
1228           (set-face-foreground 'vm-monochrome-image "black"))
1229         (if (or (not vm-fsfemacs-p)
1230                 ;; don't need this face under Emacs 21.
1231                 (fboundp 'image-type-available-p)
1232                 (facep 'vm-image-placeholder))
1233             nil
1234           (make-face 'vm-image-placeholder)
1235           (if (fboundp 'set-face-stipple)
1236               (set-face-stipple 'vm-image-placeholder
1237                                 (list 16 16
1238                                       (concat "UU\377\377UU\377\377UU\377\377"
1239                                               "UU\377\377UU\377\377UU\377\377"
1240                                               "UU\377\377UU\377\377")))))
1241         ;; default value of vm-mime-button-face is 'gui-button-face
1242         ;; this face doesn't exist by default in FSF Emacs 19.34.
1243         ;; Create it and initialize it to something reasonable.
1244         (if (and vm-fsfemacs-p (featurep 'faces)
1245                  (not (facep 'gui-button-face)))
1246             (progn
1247               (make-face 'gui-button-face)
1248               (cond ((eq window-system 'x)
1249                      (set-face-foreground 'gui-button-face "black")
1250                      (set-face-background 'gui-button-face "gray75"))
1251                     (t
1252                      ;; use primary color names, since fancier
1253                      ;; names may not be valid.
1254                      (set-face-foreground 'gui-button-face "white")
1255                      (set-face-background 'gui-button-face "red")))))
1256         ;; gui-button-face might not exist under XEmacs either.
1257         ;; This can happen if XEmacs is built without window
1258         ;; system support.  In any case, create it anyway.
1259         (if (and vm-xemacs-p (not (find-face 'gui-button-face)))
1260             (progn
1261               (make-face 'gui-button-face)
1262               (set-face-foreground 'gui-button-face "black" nil '(win))
1263               (set-face-background 'gui-button-face "gray75" nil '(win))
1264               (set-face-foreground 'gui-button-face "white" nil '(tty))
1265               (set-face-background 'gui-button-face "red" nil '(tty))))
1266         (and (vm-mouse-support-possible-p)
1267              (vm-mouse-install-mouse))
1268         (and (vm-menu-support-possible-p)
1269              vm-use-menus
1270              (vm-menu-fsfemacs-menus-p)
1271              (vm-menu-initialize-vm-mode-menu-map))
1272         (setq vm-session-beginning nil))))
1273
1274 ;;;###autoload
1275 (if (fboundp 'define-mail-user-agent)
1276     (define-mail-user-agent 'vm-user-agent
1277       (function vm-compose-mail)        ; compose function
1278       (function vm-mail-send-and-exit)  ; send function
1279       nil                               ; abort function (kill-buffer)
1280       nil)                              ; hook variable (mail-send-hook)
1281 )
1282
1283 (autoload 'reporter-submit-bug-report "reporter")
1284 (autoload 'timezone-make-date-sortable "timezone")
1285 (autoload 'rfc822-addresses "rfc822")
1286 (autoload 'mail-strip-quoted-names "mail-utils")
1287 (autoload 'mail-fetch-field "mail-utils")
1288 (autoload 'mail-position-on-field "mail-utils")
1289 (autoload 'mail-send "sendmail")
1290 (autoload 'mail-mode "sendmail")
1291 (autoload 'mail-extract-address-components "mail-extr")
1292 (autoload 'set-tapestry "tapestry")
1293 (autoload 'tapestry "tapestry")
1294 (autoload 'tapestry-replace-tapestry-element "tapestry")
1295 (autoload 'tapestry-nullify-tapestry-elements "tapestry")
1296 (autoload 'tapestry-remove-frame-parameters "tapestry")
1297 (autoload 'vm-easy-menu-define "vm-easymenu" nil 'macro)
1298 (autoload 'vm-easy-menu-do-define "vm-easymenu")
1299
1300 (provide 'vm)
1301
1302 ;;; vm.el ends here