1 ;;; gnus-vm.el --- vm interface for Gnus
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005 Free Software Foundation, Inc.
6 ;; Author: Per Persson <pp@gnu.ai.mit.edu>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: news, mail
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; Major contributors:
30 ;; Christian Limpach <Christian.Limpach@nice.ch>
31 ;; Some code stolen from:
32 ;; Rick Sladkey <jrs@world.std.com>
36 (eval-when-compile (require 'cl))
41 (autoload 'vm-mode "vm")
42 (autoload 'vm-read-file-name "vm")
43 (autoload 'vm-save-message "vm"))
45 (when (not (featurep 'vm))
48 (defvar vm-folder-directory)
49 (defvar vm-folder-history)
50 (defvar vm-primary-inbox)
51 (defvar vm-use-toolbar)
53 (defun gnus-vm-make-folder (&optional buffer)
54 (let ((article (or buffer (current-buffer)))
55 (tmp-folder (generate-new-buffer " *tmp-folder*"))
58 (set-buffer tmp-folder)
59 (insert-buffer-substring article start end)
60 (goto-char (point-min))
61 (if (looking-at "^\\(From [^ ]+ \\).*$")
62 (replace-match (concat "\\1" (current-time-string)))
63 (insert "From " gnus-newsgroup-name " "
64 (current-time-string) "\n"))
65 (while (re-search-forward "\n\nFrom " nil t)
66 (replace-match "\n\n>From "))
67 ;; insert a newline, otherwise the last line gets lost
68 (goto-char (point-max))
70 (let (mime-display-header-hook
71 mime-display-text/plain-hook mime-text-decode-hook
72 mime-view-define-keymap-hook mime-view-mode-hook)
76 (defvar gnus-summary-save-article-vm-folder nil)
77 (defvar gnus-summary-save-article-vm-count nil)
79 (defun gnus-summary-save-article-vm (&optional arg folder)
80 "Append the current article to a vm folder.
81 If N is a positive number, save the N next articles.
82 If N is a negative number, save the N previous articles.
83 If N is nil and any articles have been marked with the process mark,
84 save those articles instead."
86 (let ((prefix-arg current-prefix-arg)
87 articles marks default-folder)
88 (setq default-folder (or (car vm-folder-history) vm-primary-inbox))
89 (if (numberp prefix-arg)
90 (setq articles prefix-arg)
91 (setq marks (delq nil (gnus-summary-work-articles nil))
92 articles (length marks)))
95 (unless (zerop articles)
98 "Save %s in VM folder: "
99 (cond ((eq 1 articles)
100 (if (or (not marks) (eq gnus-current-article (car marks)))
102 "the marked article"))
105 (format "the marked %d articles" articles)
106 (format "the %d next articles" articles)))
108 (format "the %d previous articles" (- articles)))))
109 (if default-folder "" vm-folder-directory)
110 nil nil default-folder 'vm-folder-history)))))
113 (error "No articles to be saved"))
114 (unless (setq folder (or folder gnus-summary-save-article-vm-folder))
115 (error "No VM folder is specified")))
118 (setq gnus-summary-save-article-vm-folder folder
119 gnus-summary-save-article-vm-count 0)
120 (let ((gnus-default-article-saver 'gnus-summary-save-in-vm)
121 mime-display-header-hook mime-display-text/plain-hook
122 mime-text-decode-hook mime-view-define-keymap-hook
124 (gnus-summary-save-article arg))
125 (cond ((eq 1 gnus-summary-save-article-vm-count)
126 (message "One article is saved in %s" folder))
127 ((< 0 gnus-summary-save-article-vm-count)
128 (message "%d articles are saved in %s"
129 gnus-summary-save-article-vm-count folder))
131 (message "Maybe no articles are saved in %s" folder))))
132 (setq gnus-summary-save-article-vm-folder nil
133 gnus-summary-save-article-vm-count nil)))
135 (defun gnus-summary-save-in-vm (&optional folder)
137 (let (default-folder)
138 (setq default-folder (or (car vm-folder-history) vm-primary-inbox))
139 (list (vm-read-file-name "Save this article in VM folder: "
140 (if default-folder "" vm-folder-directory)
141 nil nil default-folder 'vm-folder-history))))
142 (unless (interactive-p)
143 (setq folder (or folder gnus-summary-save-article-vm-folder)))
145 (error "No VM folder is specified"))
146 (unless (interactive-p)
147 (message "Saving the article %d in %s..." gnus-current-article folder)
148 (when (numberp gnus-summary-save-article-vm-count)
149 (incf gnus-summary-save-article-vm-count)))
150 (save-window-excursion
151 (apply 'gnus-summary-select-article gnus-show-all-headers
152 (unless (interactive-p)
153 (list nil nil gnus-current-article)))
154 (gnus-eval-in-buffer-window gnus-original-article-buffer
158 (let* ((vm-use-toolbar nil)
159 (vm-folder (gnus-vm-make-folder)))
160 (vm-save-message folder)
161 (when (interactive-p)
162 (message "This article is saved in %s" folder))
163 (kill-buffer vm-folder)))))))
167 ;;; gnus-vm.el ends here