Commit | Line | Data |
---|---|---|
eec82323 | 1 | ;;; gnus-vm.el --- vm interface for Gnus |
eec82323 | 2 | |
acaf905b | 3 | ;; Copyright (C) 1994-2012 Free Software Foundation, Inc. |
16409b0b GM |
4 | |
5 | ;; Author: Per Persson <pp@gnu.ai.mit.edu> | |
eec82323 LMI |
6 | ;; Keywords: news, mail |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
5e809f55 | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
eec82323 | 11 | ;; it under the terms of the GNU General Public License as published by |
5e809f55 GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
eec82323 LMI |
14 | |
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
5e809f55 | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
eec82323 LMI |
22 | |
23 | ;;; Commentary: | |
24 | ||
25 | ;; Major contributors: | |
26 | ;; Christian Limpach <Christian.Limpach@nice.ch> | |
27 | ;; Some code stolen from: | |
28 | ;; Rick Sladkey <jrs@world.std.com> | |
29 | ||
30 | ;;; Code: | |
31 | ||
32 | (require 'sendmail) | |
33 | (require 'message) | |
34 | (require 'gnus) | |
35 | (require 'gnus-msg) | |
36 | ||
37 | (eval-when-compile | |
16409b0b | 38 | (require 'cl) |
eec82323 LMI |
39 | (autoload 'vm-mode "vm") |
40 | (autoload 'vm-save-message "vm") | |
41 | (autoload 'vm-forward-message "vm") | |
42 | (autoload 'vm-reply "vm") | |
43 | (autoload 'vm-mail "vm")) | |
44 | ||
45 | (defvar gnus-vm-inhibit-window-system nil | |
46 | "Inhibit loading `win-vm' if using a window-system. | |
47 | Has to be set before gnus-vm is loaded.") | |
48 | ||
16409b0b GM |
49 | (unless gnus-vm-inhibit-window-system |
50 | (ignore-errors | |
51 | (when window-system | |
52 | (require 'win-vm)))) | |
eec82323 LMI |
53 | |
54 | (when (not (featurep 'vm)) | |
55 | (load "vm")) | |
56 | ||
57 | (defun gnus-vm-make-folder (&optional buffer) | |
58 | (let ((article (or buffer (current-buffer))) | |
59 | (tmp-folder (generate-new-buffer " *tmp-folder*")) | |
60 | (start (point-min)) | |
61 | (end (point-max))) | |
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)) | |
73 | (insert "\n") | |
74 | (vm-mode) | |
75 | tmp-folder)) | |
76 | ||
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." | |
83 | (interactive "P") | |
84169620 | 84 | (require 'gnus-art) |
eec82323 LMI |
85 | (let ((gnus-default-article-saver 'gnus-summary-save-in-vm)) |
86 | (gnus-summary-save-article arg))) | |
87 | ||
88 | (defun gnus-summary-save-in-vm (&optional folder) | |
89 | (interactive) | |
90 | (setq folder | |
6748645f LMI |
91 | (gnus-read-save-file-name |
92 | "Save %s in VM folder:" folder | |
93 | gnus-mail-save-name gnus-newsgroup-name | |
94 | gnus-current-headers 'gnus-newsgroup-last-mail)) | |
eec82323 LMI |
95 | (gnus-eval-in-buffer-window gnus-original-article-buffer |
96 | (save-excursion | |
97 | (save-restriction | |
98 | (widen) | |
99 | (let ((vm-folder (gnus-vm-make-folder))) | |
100 | (vm-save-message folder) | |
101 | (kill-buffer vm-folder)))))) | |
102 | ||
103 | (provide 'gnus-vm) | |
104 | ||
715a2ca2 | 105 | ;;; gnus-vm.el ends here |