gnus-vm.el 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ;;; gnus-vm.el --- vm interface for Gnus
  2. ;; Copyright (C) 1994-2012 Free Software Foundation, Inc.
  3. ;; Author: Per Persson <pp@gnu.ai.mit.edu>
  4. ;; Keywords: news, mail
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; Major contributors:
  18. ;; Christian Limpach <Christian.Limpach@nice.ch>
  19. ;; Some code stolen from:
  20. ;; Rick Sladkey <jrs@world.std.com>
  21. ;;; Code:
  22. (require 'sendmail)
  23. (require 'message)
  24. (require 'gnus)
  25. (require 'gnus-msg)
  26. (eval-when-compile
  27. (require 'cl)
  28. (autoload 'vm-mode "vm")
  29. (autoload 'vm-save-message "vm")
  30. (autoload 'vm-forward-message "vm")
  31. (autoload 'vm-reply "vm")
  32. (autoload 'vm-mail "vm"))
  33. (defvar gnus-vm-inhibit-window-system nil
  34. "Inhibit loading `win-vm' if using a window-system.
  35. Has to be set before gnus-vm is loaded.")
  36. (unless gnus-vm-inhibit-window-system
  37. (ignore-errors
  38. (when window-system
  39. (require 'win-vm))))
  40. (when (not (featurep 'vm))
  41. (load "vm"))
  42. (defun gnus-vm-make-folder (&optional buffer)
  43. (let ((article (or buffer (current-buffer)))
  44. (tmp-folder (generate-new-buffer " *tmp-folder*"))
  45. (start (point-min))
  46. (end (point-max)))
  47. (set-buffer tmp-folder)
  48. (insert-buffer-substring article start end)
  49. (goto-char (point-min))
  50. (if (looking-at "^\\(From [^ ]+ \\).*$")
  51. (replace-match (concat "\\1" (current-time-string)))
  52. (insert "From " gnus-newsgroup-name " "
  53. (current-time-string) "\n"))
  54. (while (re-search-forward "\n\nFrom " nil t)
  55. (replace-match "\n\n>From "))
  56. ;; insert a newline, otherwise the last line gets lost
  57. (goto-char (point-max))
  58. (insert "\n")
  59. (vm-mode)
  60. tmp-folder))
  61. (defun gnus-summary-save-article-vm (&optional arg)
  62. "Append the current article to a vm folder.
  63. If N is a positive number, save the N next articles.
  64. If N is a negative number, save the N previous articles.
  65. If N is nil and any articles have been marked with the process mark,
  66. save those articles instead."
  67. (interactive "P")
  68. (require 'gnus-art)
  69. (let ((gnus-default-article-saver 'gnus-summary-save-in-vm))
  70. (gnus-summary-save-article arg)))
  71. (defun gnus-summary-save-in-vm (&optional folder)
  72. (interactive)
  73. (setq folder
  74. (gnus-read-save-file-name
  75. "Save %s in VM folder:" folder
  76. gnus-mail-save-name gnus-newsgroup-name
  77. gnus-current-headers 'gnus-newsgroup-last-mail))
  78. (gnus-eval-in-buffer-window gnus-original-article-buffer
  79. (save-excursion
  80. (save-restriction
  81. (widen)
  82. (let ((vm-folder (gnus-vm-make-folder)))
  83. (vm-save-message folder)
  84. (kill-buffer vm-folder))))))
  85. (provide 'gnus-vm)
  86. ;;; gnus-vm.el ends here