1 ;;; gnus-vm.el --- vm interface for Gnus
2 ;; Copyright (C) 1994,95,96 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 the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; Major contributors:
27 ;; Christian Limpach <Christian.Limpach@nice.ch>
28 ;; Some code stolen from:
29 ;; Rick Sladkey <jrs@world.std.com>
38 (autoload 'vm-mode "vm")
39 (autoload 'vm-save-message "vm")
40 (autoload 'vm-forward-message "vm")
41 (autoload 'vm-reply "vm")
42 (autoload 'vm-mail "vm"))
44 (defvar gnus-vm-inhibit-window-system nil
45 "Inhibit loading `win-vm' if using a window-system.
46 Has to be set before gnus-vm is loaded.")
48 (or gnus-vm-inhibit-window-system
54 (if (not (featurep 'vm))
57 (defun gnus-vm-make-folder (&optional buffer)
58 (let ((article (or buffer (current-buffer)))
59 (tmp-folder (generate-new-buffer " *tmp-folder*"))
62 (set-buffer tmp-folder)
63 (insert-buffer-substring article start end)
64 (goto-char (point-min))
65 (if (looking-at "^\\(From [^ ]+ \\).*$")
66 (replace-match (concat "\\1" (current-time-string)))
67 (insert "From " gnus-newsgroup-name " "
68 (current-time-string) "\n"))
69 (while (re-search-forward "\n\nFrom " nil t)
70 (replace-match "\n\n>From "))
71 ;; insert a newline, otherwise the last line gets lost
72 (goto-char (point-max))
77 (defun gnus-summary-save-article-vm (&optional arg)
78 "Append the current article to a vm folder.
79 If N is a positive number, save the N next articles.
80 If N is a negative number, save the N previous articles.
81 If N is nil and any articles have been marked with the process mark,
82 save those articles instead."
84 (let ((gnus-default-article-saver 'gnus-summary-save-in-vm))
85 (gnus-summary-save-article arg)))
87 (defun gnus-summary-save-in-vm (&optional folder)
90 (funcall gnus-mail-save-name gnus-newsgroup-name
91 gnus-current-headers gnus-newsgroup-last-mail)))
93 (cond ((eq folder 'default) default-name)
95 (t (gnus-read-save-file-name
96 "Save article in VM folder:" default-name))))
97 (gnus-make-directory (file-name-directory folder))
98 (set-buffer gnus-original-article-buffer)
102 (let ((vm-folder (gnus-vm-make-folder)))
103 (vm-save-message folder)
104 (kill-buffer vm-folder))))
105 ;; Remember the directory name to save articles.
106 (setq gnus-newsgroup-last-mail folder)))
108 (defun gnus-vm-mail-setup (to subject in-reply-to cc replybuffer actions)
109 (gnus-sendmail-mail-setup to subject in-reply-to cc replybuffer actions)
112 (defun gnus-mail-forward-using-vm (&optional buffer)
113 "Forward the current message to another user using vm."
114 (let* ((gnus-buffer (or buffer (current-buffer)))
115 (subject (gnus-forward-make-subject gnus-buffer)))
116 (or (featurep 'win-vm)
117 (if gnus-use-full-window
118 (pop-to-buffer gnus-article-buffer)
119 (switch-to-buffer gnus-article-buffer)))
120 (gnus-copy-article-buffer)
121 (set-buffer gnus-article-copy)
125 (let ((vm-folder (gnus-vm-make-folder))
126 (vm-forward-message-hook
127 (append (symbol-value 'vm-forward-message-hook)
130 (mail-position-on-field "Subject")
132 (looking-at "^\\(Subject: \\).*$")
133 (replace-match (concat "\\1" subject))))))))
135 (gnus-vm-init-reply-buffer gnus-buffer)
136 (run-hooks 'gnus-mail-hook)
137 (kill-buffer vm-folder))))))
139 (defun gnus-vm-init-reply-buffer (buffer)
140 (make-local-variable 'gnus-summary-buffer)
141 (setq gnus-summary-buffer buffer)
142 (set 'vm-mail-buffer nil)
143 (use-local-map (copy-keymap (current-local-map)))
144 (local-set-key "\C-c\C-y" 'gnus-yank-article))
146 (defun gnus-mail-reply-using-vm (&optional yank)
147 "Compose reply mail using vm.
148 Optional argument YANK means yank original article.
149 The command \\[vm-yank-message] yank the original message into current buffer."
150 (let ((gnus-buffer (current-buffer)))
151 (gnus-copy-article-buffer)
152 (set-buffer gnus-article-copy)
156 (let ((vm-folder (gnus-vm-make-folder gnus-article-copy)))
158 (gnus-vm-init-reply-buffer gnus-buffer)
159 (setq gnus-buffer (current-buffer))
161 ;; nil will (magically :-)) yank the current article
162 (gnus-yank-article nil))
163 (kill-buffer vm-folder))))
164 (if (featurep 'win-vm) nil
165 (pop-to-buffer gnus-buffer))
166 (run-hooks 'gnus-mail-hook)))
168 (defun gnus-mail-other-window-using-vm ()
169 "Compose mail in the other window using VM."
171 (let ((gnus-buffer (current-buffer)))
173 (gnus-vm-init-reply-buffer gnus-buffer))
174 (run-hooks 'gnus-mail-hook))
176 (defun gnus-yank-article (article &optional prefix)
177 ;; Based on vm-yank-message by Kyle Jones.
178 "Yank article number N into the current buffer at point.
179 When called interactively N is read from the minibuffer.
181 This command is meant to be used in GNUS created Mail mode buffers;
182 the yanked article comes from the newsgroup containing the article
183 you are replying to or forwarding.
185 All article headers are yanked along with the text. Point is left
186 before the inserted text, the mark after. Any hook functions bound to
187 `mail-citation-hook' are run, after inserting the text and setting
190 Prefix arg means to ignore `mail-citation-hook', don't set the mark,
191 prepend the value of `vm-included-text-prefix' to every yanked line.
192 For backwards compatibility, if `mail-citation-hook' is set to nil,
193 `mail-yank-hooks' is run instead. If that is also nil, a default
199 (setq default (and gnus-summary-buffer
201 (set-buffer gnus-summary-buffer)
202 (and gnus-current-article
203 (int-to-string gnus-current-article))))
205 (format "Yank article number: (default %s) " default)
206 "Yank article number: "))
207 (while (and (not (stringp result)) (zerop result))
208 (setq result (read-string prompt))
209 (and (string= result "") default (setq result default))
210 (or (string-match "^<.*>$" result)
211 (setq result (string-to-int result))))
214 (if gnus-summary-buffer
216 (let ((message (current-buffer))
218 (tmp (generate-new-buffer " *tmp-yank*")))
219 (set-buffer gnus-summary-buffer)
220 ;; Make sure the connection to the server is alive.
221 (or (gnus-server-opened (gnus-find-method-for-group
222 gnus-newsgroup-name))
225 (gnus-find-method-for-group gnus-newsgroup-name))
226 (gnus-request-group gnus-newsgroup-name t)))
227 (and (stringp article)
228 (let ((gnus-override-method gnus-refer-article-method))
229 (gnus-read-header article)))
230 (gnus-request-article (or article
231 gnus-current-article)
232 gnus-newsgroup-name tmp)
234 (run-hooks 'gnus-article-prepare-hook)
235 ;; Decode MIME message.
236 (if (and gnus-show-mime
237 (gnus-fetch-field "Mime-Version"))
238 (funcall gnus-show-mime-method))
239 ;; Perform the article display hooks.
240 (let ((buffer-read-only nil))
241 (run-hooks 'gnus-article-display-hook))
242 (append-to-buffer message (point-min) (point-max))
248 (not (or mail-citation-hook mail-yank-hooks)))
250 (while (< (point) end)
251 (insert (symbol-value 'vm-included-text-prefix))
255 (mail-citation-hook (run-hooks 'mail-citation-hook))
256 (mail-yank-hooks (run-hooks 'mail-yank-hooks))))))))
260 ;;; gnus-vm.el ends here.