1 ;;; gnus-vm: vm interface for Gnus
2 ;; Copyright (C) 1994,95 Free Software Foundation, Inc.
4 ;; Author: Per Persson <pp@solace.mh.se>
5 ;; Keywords: news, mail
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;; Major contributors:
26 ;; Christian Limpach <Christian.Limpach@nice.ch>
27 ;; Some code stolen from:
28 ;; Rick Sladkey <jrs@world.std.com>
31 (autoload 'vm-mode "vm")
32 (autoload 'vm-save-message "vm")
33 (autoload 'vm-forward-message "vm")
34 (autoload 'vm-reply "vm")
35 (autoload 'vm-mail "vm"))
37 (defvar gnus-vm-inhibit-window-system nil
38 "Inhibit loading `win-vm' if using a window-system.
39 Has to be set before gnus-vm is loaded.")
41 (or gnus-vm-inhibit-window-system
47 (if (not (featurep 'vm))
52 (defun gnus-vm-make-folder (&optional buffer)
53 (let ((article (or buffer (current-buffer)))
54 (tmp-folder (generate-new-buffer " *tmp-folder*"))
57 (set-buffer tmp-folder)
58 (insert-buffer-substring article start end)
59 (goto-char (point-min))
60 (if (looking-at "^\\(From [^ ]+ \\).*$")
61 (replace-match (concat "\\1" (current-time-string)))
62 (insert "From " gnus-newsgroup-name " "
63 (current-time-string) "\n"))
64 (while (re-search-forward "\n\nFrom " nil t)
65 (replace-match "\n\n>From "))
66 ;; insert a newline, otherwise the last line gets lost
67 (goto-char (point-max))
72 (defun gnus-summary-save-in-vm (&optional folder)
75 (funcall gnus-mail-save-name gnus-newsgroup-name
76 gnus-current-headers gnus-newsgroup-last-mail)))
80 (concat "Save article in VM folder: (default "
81 (file-name-nondirectory default-name) ") ")
82 (file-name-directory default-name)
85 (expand-file-name folder
87 (file-name-directory default-name))))
88 (gnus-make-directory (file-name-directory folder))
89 (set-buffer gnus-article-buffer)
93 (let ((vm-folder (gnus-vm-make-folder)))
94 (vm-save-message folder)
95 (kill-buffer vm-folder))))
96 ;; Remember the directory name to save articles.
97 (setq gnus-newsgroup-last-mail folder)))
99 (defun gnus-mail-forward-using-vm ()
100 "Forward the current message to another user using vm."
101 (let ((gnus-buffer (current-buffer))
102 (subject (concat "[" gnus-newsgroup-name "] "
103 (or (gnus-fetch-field "Subject") ""))))
104 (or (featurep 'win-vm)
105 (if gnus-use-full-window
106 (pop-to-buffer gnus-article-buffer)
107 (switch-to-buffer gnus-article-buffer)))
108 (set-buffer gnus-article-buffer)
112 (let ((vm-folder (gnus-vm-make-folder))
113 (vm-forward-message-hook
114 (append (symbol-value 'vm-forward-message-hook)
117 (mail-position-on-field "Subject")
119 (looking-at "^\\(Subject: \\).*$")
120 (replace-match (concat "\\1" subject))))))))
122 (gnus-vm-init-reply-buffer gnus-buffer)
123 (kill-buffer vm-folder))))))
125 (defun gnus-vm-init-reply-buffer (buffer)
126 (make-local-variable 'gnus-summary-buffer)
127 (setq gnus-summary-buffer buffer)
128 (set 'vm-mail-buffer nil)
129 (use-local-map (copy-keymap (current-local-map)))
130 (local-set-key "\C-c\C-y" 'gnus-yank-article))
132 (defun gnus-mail-reply-using-vm (&optional yank)
133 "Compose reply mail using vm.
134 Optional argument YANK means yank original article.
135 The command \\[vm-yank-message] yank the original message into current buffer."
136 (let ((gnus-buffer (current-buffer)))
137 (set-buffer gnus-article-buffer)
141 (let ((vm-folder (gnus-vm-make-folder gnus-article-buffer)))
143 (gnus-vm-init-reply-buffer gnus-buffer)
144 (setq gnus-buffer (current-buffer))
146 ;; nil will (magically :-)) yank the current article
147 (gnus-yank-article nil))
148 (kill-buffer vm-folder))))
149 (if (featurep 'win-vm) nil
150 (pop-to-buffer gnus-buffer))))
152 (defun gnus-mail-other-window-using-vm ()
153 "Compose mail in the other window using VM."
155 (let ((gnus-buffer (current-buffer)))
157 (gnus-vm-init-reply-buffer gnus-buffer)))
159 (defun gnus-yank-article (article &optional prefix)
160 ;; Based on vm-yank-message by Kyle Jones.
161 "Yank article number N into the current buffer at point.
162 When called interactively N is read from the minibuffer.
164 This command is meant to be used in GNUS created Mail mode buffers;
165 the yanked article comes from the newsgroup containing the article
166 you are replying to or forwarding.
168 All article headers are yanked along with the text. Point is left
169 before the inserted text, the mark after. Any hook functions bound to
170 `mail-citation-hook' are run, after inserting the text and setting
173 Prefix arg means to ignore `mail-citation-hook', don't set the mark,
174 prepend the value of `vm-included-text-prefix' to every yanked line.
175 For backwards compatibility, if `mail-citation-hook' is set to nil,
176 `mail-yank-hooks' is run instead. If that is also nil, a default
182 (setq default (and gnus-summary-buffer
184 (set-buffer gnus-summary-buffer)
185 (and gnus-current-article
186 (int-to-string gnus-current-article))))
188 (format "Yank article number: (default %s) " default)
189 "Yank article number: "))
190 (while (and (not (stringp result)) (zerop result))
191 (setq result (read-string prompt))
192 (and (string= result "") default (setq result default))
193 (or (string-match "^<.*>$" result)
194 (setq result (string-to-int result))))
197 (if gnus-summary-buffer
199 (let ((message (current-buffer))
201 (tmp (generate-new-buffer " *tmp-yank*")))
202 (set-buffer gnus-summary-buffer)
203 ;; Make sure the connection to the server is alive.
204 (or (gnus-server-opened (gnus-find-method-for-group
205 gnus-newsgroup-name))
207 (gnus-check-news-server
208 (gnus-find-method-for-group gnus-newsgroup-name))
209 (gnus-request-group gnus-newsgroup-name t)))
210 (and (stringp article)
211 (let ((gnus-override-method gnus-refer-article-method))
212 (gnus-read-header article)))
213 (gnus-request-article (or article
214 gnus-current-article)
215 gnus-newsgroup-name tmp)
217 (run-hooks 'gnus-article-prepare-hook)
218 ;; Decode MIME message.
219 (if (and gnus-show-mime
220 (gnus-fetch-field "Mime-Version"))
221 (funcall gnus-show-mime-method))
222 ;; Perform the article display hooks.
223 (let ((buffer-read-only nil))
224 (run-hooks 'gnus-article-display-hook))
225 (append-to-buffer message (point-min) (point-max))
231 (not (or mail-citation-hook mail-yank-hooks)))
233 (while (< (point) end)
234 (insert (symbol-value 'vm-included-text-prefix))
238 (mail-citation-hook (run-hooks 'mail-citation-hook))
239 (mail-yank-hooks (run-hooks 'mail-yank-hooks))))))))
243 ;;; gnus-vm.el ends here.