1 ;;; vm.el --- Entry points for VM
3 ;; Copyright (C) 1994-1998, 2003 Kyle E. Jones
4 ;; Copyright (C) 2003-2006 Robert Widhopf-Fenk
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.
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.
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.
23 ;; This files was vm-startup.el!
26 (defvar enable-multibyte-characters)
31 (defun vm-recover-folder ()
32 "Recover the autosave file for the current folder."
34 (vm-select-folder-buffer)
35 (recover-file (buffer-file-name)))
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.
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
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.
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.
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
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
74 (string-match vm-recognize-imap-maildrops f))
75 (setq access-method 'imap
77 ((and vm-recognize-pop-maildrops
78 ;; f could be a buffer
80 (string-match vm-recognize-pop-maildrops f))
81 (setq access-method 'pop
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)
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.
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
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))
120 ((file-exists-p f-pass)
123 (rename-file f-pass f-nospec)
125 ((file-exists-p f-nopass)
128 (rename-file f-nopass f-nospec)
130 ;; choose the one that exists, password version,
131 ;; nopass version and finally nopass+nospec
133 (cond ((file-exists-p f-pass)
134 (setq folder f-pass))
135 ((file-exists-p f-nopass)
136 (setq folder f-nopass))
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
144 folder (vm-imap-make-filename-for-spec remote-spec))))
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))
158 (inhibit-local-variables t)
159 (enable-local-variables nil)
160 (enable-local-eval nil)
162 (default-enable-multibyte-characters nil)
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
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))
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.
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)))
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)))
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)
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.
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
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
261 (buffer-disable-undo (current-buffer))
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
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
278 (if (not (buffer-modified-p))
279 (setq did-read-index-file (vm-read-index-file-maybe)))))
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)
285 (if (and first-time (not did-read-index-file))
287 (vm-gobble-visible-header-variables)
289 (vm-gobble-pop-retrieved)
290 (vm-gobble-imap-retrieved)
295 (vm-start-itimers-if-needed))
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.
302 (apply 'vm-goto-new-folder-frame-maybe
303 (if folder '(folder) '(primary-folder folder))))
305 ;; raise frame if requested and apply startup window
308 (let ((buffer-to-display (or vm-summary-buffer
309 vm-presentation-buffer
311 (vm-display buffer-to-display buffer-to-display
313 (list (or this-command 'vm) 'startup))
314 (if vm-raise-frame-at-startup
317 ;; say this NOW, before the non-previewers read a message,
318 ;; alter the new message count and confuse themselves.
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)))))
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)
332 (and vm-use-menus (vm-menu-support-possible-p)
333 (vm-menu-install-visited-folders-menu))
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
348 vm-raise-frame-at-startup)
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))
357 (switch-to-buffer (or vm-summary-buffer
358 vm-presentation-buffer
359 (current-buffer)))))))
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)))
370 (run-hooks 'vm-visit-folder-hook)
372 ;; Warn user about auto save file, if appropriate.
373 (if (and full-startup preserve-auto-save-file)
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,
380 (if (or (not full-startup) preserve-auto-save-file)
384 (message totals-blurb))
386 (if (and vm-auto-get-new-mail
387 (not vm-block-new-mail)
388 (not vm-folder-read-only))
390 (message "Checking for new mail for %s..."
391 (or buffer-file-name (buffer-name)))
392 (if (vm-get-spooled-mail t)
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)))
400 ;; Display copyright and copying info.
401 (if (and (interactive-p) (not vm-startup-message-displayed))
403 (vm-display-startup-message)
404 (if (not (input-pending-p))
405 (message totals-blurb)))))))
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)
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)))
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)
430 (let ((vm-frame-per-folder nil)
431 (vm-search-other-frames nil))
432 (vm folder read-only)))
434 (put 'vm-mode 'mode-class 'special)
437 (defun vm-mode (&optional read-only)
438 "Major mode for reading mail.
442 Use M-x vm-submit-bug-report to submit a bug report.
448 Customize VM by setting variables and store them in the file ~/.vm.
451 (vm (current-buffer) read-only)
452 (vm-display nil nil '(vm-mode) '(vm-mode)))
455 (defun vm-visit-folder (folder &optional read-only)
457 VM will parse and present its messages to you in the usual way.
459 First arg FOLDER specifies the mail file to visit. When this
460 command is called interactively the file name is read from the
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
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)
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" "")
482 (format " (default %s)" default)
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)))
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)))
501 access-method 'imap))
503 (let ((default-directory (or vm-folder-directory default-directory)))
504 (setq folder (expand-file-name folder)))))
505 (vm folder read-only access-method)))
508 (defun vm-visit-folder-other-frame (folder &optional read-only)
509 "Like vm-visit-folder, but run in a newly created frame."
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)
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" "")
525 (format " (default %s)" default)
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)))
539 (defun vm-visit-folder-other-window (folder &optional read-only)
540 "Like vm-visit-folder, but run in a different window."
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)
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" "")
556 (format " (default %s)" default)
558 default-directory default nil nil 'vm-folder-history)
559 current-prefix-arg))))
560 (vm-session-initialization)
564 (let ((vm-frame-per-folder nil)
565 (vm-search-other-frames nil))
566 (vm-visit-folder folder read-only)))
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.
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
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
587 (vm-session-initialization)
588 (vm-check-for-killed-folder)
589 (vm-select-folder-buffer-if-possible)
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" "")
600 (format " (default %s)" default)
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))
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."
620 (vm-session-initialization)
621 (vm-check-for-killed-folder)
622 (vm-select-folder-buffer-if-possible)
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" "")
633 (format " (default %s)" default)
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)))
647 (defun vm-visit-pop-folder-other-window (folder &optional read-only)
648 "Like vm-visit-pop-folder, but run in a different window."
651 (vm-session-initialization)
652 (vm-check-for-killed-folder)
653 (vm-select-folder-buffer-if-possible)
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" "")
664 (format " (default %s)" default)
667 current-prefix-arg))))
668 (vm-session-initialization)
672 (let ((vm-frame-per-folder nil)
673 (vm-search-other-frames nil))
674 (vm-visit-pop-folder folder read-only)))
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.
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.
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
695 (vm-session-initialization)
696 (vm-check-for-killed-folder)
697 (vm-select-folder-buffer-if-possible)
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))
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."
717 (vm-session-initialization)
718 (vm-check-for-killed-folder)
719 (vm-select-folder-buffer-if-possible)
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" ""))
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)))
738 (defun vm-visit-imap-folder-other-window (folder &optional read-only)
739 "Like vm-visit-imap-folder, but run in a different window."
742 (vm-session-initialization)
743 (vm-check-for-killed-folder)
744 (vm-select-folder-buffer-if-possible)
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" ""))
752 current-prefix-arg))))
753 (vm-session-initialization)
757 (let ((vm-frame-per-folder nil)
758 (vm-search-other-frames nil))
759 (vm-visit-imap-folder folder read-only)))
761 (put 'vm-virtual-mode 'mode-class 'special)
763 (defun vm-virtual-mode (&rest ignored)
764 "Mode for reading multiple mail folders as one folder.
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
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.")
774 (defvar scroll-in-place)
777 (defun vm-visit-virtual-folder (folder-name &optional read-only bookmark)
779 (let ((last-command last-command)
780 (this-command this-command))
781 (vm-session-initialization)
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 ")"))
793 (set-buffer (get-buffer-create buffer-name))
794 (setq first-time (not (eq major-mode 'vm-virtual-mode)))
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))))
805 (vm-fsfemacs-nonmule-display-8bit-chars)
806 (setq mode-name "VM Virtual"
807 mode-line-format vm-mode-line-format
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"))
835 (let ((mp vm-message-list))
837 (if (eq bookmark (vm-real-message-of (car mp)))
839 (vm-record-and-change-message-pointer
840 vm-message-pointer mp)
841 (vm-preview-current-message)
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)))
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
854 (vm-display nil nil (list this-command) (list this-command 'startup))
855 (vm-toolbar-install-or-uninstall-toolbar)
858 (if (vm-should-generate-summary)
859 (progn (vm-summarize t nil)
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
866 vm-raise-frame-at-startup)
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))
875 (switch-to-buffer (or vm-summary-buffer
876 vm-presentation-buffer
877 (current-buffer)))))))
879 ;; check interactive-p so as not to bog the user down if they
880 ;; run this function from within another function.
882 (not vm-startup-message-displayed)
883 (vm-display-startup-message)
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."
890 (let ((last-command last-command)
891 (this-command this-command))
892 (vm-session-initialization)
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)))
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."
911 (let ((last-command last-command)
912 (this-command this-command))
913 (vm-session-initialization)
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)
923 (let ((vm-frame-per-folder nil)
924 (vm-search-other-frames nil))
925 (vm-visit-virtual-folder folder-name read-only)))
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
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))
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
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))
953 (if (vm-multiple-frames-possible-p)
954 (vm-set-hooks-for-frame-deletion)))
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
962 (vm-session-initialization)
966 (let ((vm-frame-per-composition nil)
967 (vm-search-other-frames nil))
970 (fset 'vm-folders-summary-mode 'vm-mode)
971 (put 'vm-folders-summary-mode 'mode-class 'special)
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."
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)
990 (setq vm-folders-summary-buffer
991 (let ((default-enable-multibyte-characters t))
992 (get-buffer-create "VM Folders Summary")))
994 (set-buffer vm-folders-summary-buffer)
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.
1011 (vm-check-for-killed-folder))
1014 (vm-select-folder-buffer))
1015 (vm-check-for-killed-summary)
1016 (let ((folder-buffer (and (eq major-mode 'vm-mode)
1019 (if (or (null vm-folders-summary-hash) (null folder-buffer)
1020 (null buffer-file-name))
1022 (setq fs (symbol-value (intern-soft (vm-make-folders-summary-key
1024 vm-folders-summary-hash)))
1027 (vm-mark-for-folders-summary-update buffer-file-name)
1028 (set-buffer vm-folders-summary-buffer)
1029 (setq vm-mail-buffer folder-buffer)))))
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))
1044 (defvar mail-send-actions)
1047 (defun vm-compose-mail (&optional to subject other-headers continue
1048 switch-function yank-action
1051 (vm-session-initialization)
1053 (vm-continue-composing-message)
1054 (let ((buffer (vm-mail-internal
1056 (format "message to %s"
1057 (vm-truncate-roman-string to 20))
1060 (goto-char (point-min))
1061 (re-search-forward (concat "^" mail-header-separator "$"))
1063 (while other-headers
1064 (insert (car (car other-headers)))
1065 (while (eq (char-syntax (char-before (point))) ?\ )
1067 (while (eq (char-before (point)) ?:)
1069 (insert ": " (cdr (car other-headers)))
1070 (if (not (eq (char-before (point)) ?\n))
1072 (setq other-headers (cdr other-headers)))
1074 (mail-position-on-field "To"))
1076 (mail-position-on-field "Subject"))
1079 (funcall (or switch-function (function switch-to-buffer))
1084 (apply (car yank-action) (cdr yank-action))
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))))
1094 (defun vm-submit-bug-report ()
1095 "Submit a bug report, with pertinent information to the VM bug list."
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)
1106 (setq varlist (apropos-internal "^\\(vm\\|vmpc\\)-" 'user-variable-p)
1107 varlist (sort varlist
1109 (string-lessp (format "%s" v1) (format "%s" v2)))))
1110 (let ((vars-to-delete '(
1111 ;; passwords might be listed here
1113 vm-imap-auto-expunge-alist
1114 vm-pop-auto-expunge-alist
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))
1129 "Please change the Subject header to a concise bug description.
1131 Consider to post this to the News group gnu.emacs.vm.bug instead.
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.
1136 Please remove these instructions and other stuff which is unrelated to the bug
1137 from your message.")
1139 (goto-char (point-min))
1140 (mail-position-on-field "Subject")
1141 (insert "VM-BUG: "))))
1143 (defun vm-edit-init-file ()
1146 (find-file-other-frame "~/.vm"))
1148 (defun vm-load-init-file (&optional interactive)
1150 (if (or (not vm-init-file-loaded) interactive)
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)))
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."
1162 ((and vm-fsfemacs-p (< emacs-major-version 21))
1163 (error "VM %s must be run on GNU Emacs 21 or a later version."
1166 (defun vm-set-debug-flags ()
1167 (or stack-trace-on-error
1169 (setq stack-trace-on-error
1172 wrong-number-of-arguments
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)
1186 (vm-check-emacs-version)
1190 (require 'vm-message)
1191 (require 'vm-minibuf)
1192 (require 'vm-motion)
1195 (require 'vm-summary)
1198 (require 'vm-folder)
1199 (require 'vm-toolbar)
1200 (require 'vm-window)
1202 (require 'vm-rfaddons)
1203 (if (locate-library "pgg")
1205 (message "vm-pgg disabled since pgg is missing!"))
1206 (add-hook 'kill-emacs-hook 'vm-garbage-collect-global)
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)
1223 (find-face 'vm-monochrome-image)
1224 (facep 'vm-monochrome-image))
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))
1234 (make-face 'vm-image-placeholder)
1235 (if (fboundp 'set-face-stipple)
1236 (set-face-stipple 'vm-image-placeholder
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)))
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"))
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)))
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)
1270 (vm-menu-fsfemacs-menus-p)
1271 (vm-menu-initialize-vm-mode-menu-map))
1272 (setq vm-session-beginning nil))))
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)
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")