1 ;;; gnus-vm.el --- 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>
37 (autoload 'vm-mode "vm")
38 (autoload 'vm-save-message "vm")
39 (autoload 'vm-forward-message "vm")
40 (autoload 'vm-reply "vm")
41 (autoload 'vm-mail "vm"))
43 (defvar gnus-vm-inhibit-window-system nil
44 "Inhibit loading `win-vm' if using a window-system.
45 Has to be set before gnus-vm is loaded.")
47 (or gnus-vm-inhibit-window-system
53 (if (not (featurep 'vm))
56 (defun gnus-vm-make-folder (&optional buffer)
57 (let ((article (or buffer (current-buffer)))
58 (tmp-folder (generate-new-buffer " *tmp-folder*"))
61 (set-buffer tmp-folder)
62 (insert-buffer-substring article start end)
63 (goto-char (point-min))
64 (if (looking-at "^\\(From [^ ]+ \\).*$")
65 (replace-match (concat "\\1" (current-time-string)))
66 (insert "From " gnus-newsgroup-name " "
67 (current-time-string) "\n"))
68 (while (re-search-forward "\n\nFrom " nil t)
69 (replace-match "\n\n>From "))
70 ;; insert a newline, otherwise the last line gets lost
71 (goto-char (point-max))
76 (defun gnus-summary-save-article-vm (&optional arg)
77 "Append the current article to a vm folder.
78 If N is a positive number, save the N next articles.
79 If N is a negative number, save the N previous articles.
80 If N is nil and any articles have been marked with the process mark,
81 save those articles instead."
83 (let ((gnus-default-article-saver 'gnus-summary-save-in-vm))
84 (gnus-summary-save-article arg)))
86 (defun gnus-summary-save-in-vm (&optional folder)
89 (funcall gnus-mail-save-name gnus-newsgroup-name
90 gnus-current-headers gnus-newsgroup-last-mail)))
94 (concat "Save article in VM folder: (default "
95 (file-name-nondirectory default-name) ") ")
96 (file-name-directory default-name)
99 (expand-file-name folder
101 (file-name-directory default-name))))
102 (gnus-make-directory (file-name-directory folder))
103 (set-buffer gnus-article-buffer)
107 (let ((vm-folder (gnus-vm-make-folder)))
108 (vm-save-message folder)
109 (kill-buffer vm-folder))))
110 ;; Remember the directory name to save articles.
111 (setq gnus-newsgroup-last-mail folder)))
113 (defun gnus-vm-mail-setup (to subject in-reply-to cc replybuffer actions)
114 (gnus-sendmail-mail-setup to subject in-reply-to cc replybuffer actions)
117 (defun gnus-mail-forward-using-vm (&optional buffer)
118 "Forward the current message to another user using vm."
119 (let* ((gnus-buffer (or buffer (current-buffer)))
120 (subject (gnus-forward-make-subject gnus-buffer)))
121 (or (featurep 'win-vm)
122 (if gnus-use-full-window
123 (pop-to-buffer gnus-article-buffer)
124 (switch-to-buffer gnus-article-buffer)))
125 (gnus-copy-article-buffer)
126 (set-buffer gnus-article-copy)
130 (let ((vm-folder (gnus-vm-make-folder))
131 (vm-forward-message-hook
132 (append (symbol-value 'vm-forward-message-hook)
135 (mail-position-on-field "Subject")
137 (looking-at "^\\(Subject: \\).*$")
138 (replace-match (concat "\\1" subject))))))))
140 (gnus-vm-init-reply-buffer gnus-buffer)
141 (run-hooks 'gnus-mail-hook)
142 (kill-buffer vm-folder))))))
144 (defun gnus-vm-init-reply-buffer (buffer)
145 (make-local-variable 'gnus-summary-buffer)
146 (setq gnus-summary-buffer buffer)
147 (set 'vm-mail-buffer nil)
148 (use-local-map (copy-keymap (current-local-map)))
149 (local-set-key "\C-c\C-y" 'gnus-yank-article))
151 (defun gnus-mail-reply-using-vm (&optional yank)
152 "Compose reply mail using vm.
153 Optional argument YANK means yank original article.
154 The command \\[vm-yank-message] yank the original message into current buffer."
155 (let ((gnus-buffer (current-buffer)))
156 (gnus-copy-article-buffer)
157 (set-buffer gnus-article-copy)
161 (let ((vm-folder (gnus-vm-make-folder gnus-article-copy)))
163 (gnus-vm-init-reply-buffer gnus-buffer)
164 (setq gnus-buffer (current-buffer))
166 ;; nil will (magically :-)) yank the current article
167 (gnus-yank-article nil))
168 (kill-buffer vm-folder))))
169 (if (featurep 'win-vm) nil
170 (pop-to-buffer gnus-buffer))
171 (run-hooks 'gnus-mail-hook)))
173 (defun gnus-mail-other-window-using-vm ()
174 "Compose mail in the other window using VM."
176 (let ((gnus-buffer (current-buffer)))
178 (gnus-vm-init-reply-buffer gnus-buffer))
179 (run-hooks 'gnus-mail-hook))
181 (defun gnus-yank-article (article &optional prefix)
182 ;; Based on vm-yank-message by Kyle Jones.
183 "Yank article number N into the current buffer at point.
184 When called interactively N is read from the minibuffer.
186 This command is meant to be used in GNUS created Mail mode buffers;
187 the yanked article comes from the newsgroup containing the article
188 you are replying to or forwarding.
190 All article headers are yanked along with the text. Point is left
191 before the inserted text, the mark after. Any hook functions bound to
192 `mail-citation-hook' are run, after inserting the text and setting
195 Prefix arg means to ignore `mail-citation-hook', don't set the mark,
196 prepend the value of `vm-included-text-prefix' to every yanked line.
197 For backwards compatibility, if `mail-citation-hook' is set to nil,
198 `mail-yank-hooks' is run instead. If that is also nil, a default
204 (setq default (and gnus-summary-buffer
206 (set-buffer gnus-summary-buffer)
207 (and gnus-current-article
208 (int-to-string gnus-current-article))))
210 (format "Yank article number: (default %s) " default)
211 "Yank article number: "))
212 (while (and (not (stringp result)) (zerop result))
213 (setq result (read-string prompt))
214 (and (string= result "") default (setq result default))
215 (or (string-match "^<.*>$" result)
216 (setq result (string-to-int result))))
219 (if gnus-summary-buffer
221 (let ((message (current-buffer))
223 (tmp (generate-new-buffer " *tmp-yank*")))
224 (set-buffer gnus-summary-buffer)
225 ;; Make sure the connection to the server is alive.
226 (or (gnus-server-opened (gnus-find-method-for-group
227 gnus-newsgroup-name))
230 (gnus-find-method-for-group gnus-newsgroup-name))
231 (gnus-request-group gnus-newsgroup-name t)))
232 (and (stringp article)
233 (let ((gnus-override-method gnus-refer-article-method))
234 (gnus-read-header article)))
235 (gnus-request-article (or article
236 gnus-current-article)
237 gnus-newsgroup-name tmp)
239 (run-hooks 'gnus-article-prepare-hook)
240 ;; Decode MIME message.
241 (if (and gnus-show-mime
242 (gnus-fetch-field "Mime-Version"))
243 (funcall gnus-show-mime-method))
244 ;; Perform the article display hooks.
245 (let ((buffer-read-only nil))
246 (run-hooks 'gnus-article-display-hook))
247 (append-to-buffer message (point-min) (point-max))
253 (not (or mail-citation-hook mail-yank-hooks)))
255 (while (< (point) end)
256 (insert (symbol-value 'vm-included-text-prefix))
260 (mail-citation-hook (run-hooks 'mail-citation-hook))
261 (mail-yank-hooks (run-hooks 'mail-yank-hooks))))))))
265 ;;; gnus-vm.el ends here.