gnus-vm.el 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ;;; gnus-vm.el --- vm interface for Gnus
  2. ;; Copyright (C) 1994-2015 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. (defvar gnus-vm-inhibit-window-system nil
  31. "Inhibit loading `win-vm' if using a window-system.
  32. Has to be set before gnus-vm is loaded.")
  33. (unless gnus-vm-inhibit-window-system
  34. (ignore-errors
  35. (when window-system
  36. (require 'win-vm))))
  37. (defun gnus-vm-make-folder (&optional buffer)
  38. (require 'vm)
  39. (let ((article (or buffer (current-buffer)))
  40. (tmp-folder (generate-new-buffer " *tmp-folder*"))
  41. (start (point-min))
  42. (end (point-max)))
  43. (set-buffer tmp-folder)
  44. (insert-buffer-substring article start end)
  45. (goto-char (point-min))
  46. (if (looking-at "^\\(From [^ ]+ \\).*$")
  47. (replace-match (concat "\\1" (current-time-string)))
  48. (insert "From " gnus-newsgroup-name " "
  49. (current-time-string) "\n"))
  50. (while (re-search-forward "\n\nFrom " nil t)
  51. (replace-match "\n\n>From "))
  52. ;; insert a newline, otherwise the last line gets lost
  53. (goto-char (point-max))
  54. (insert "\n")
  55. (vm-mode)
  56. tmp-folder))
  57. (defun gnus-summary-save-article-vm (&optional arg)
  58. "Append the current article to a vm folder.
  59. If N is a positive number, save the N next articles.
  60. If N is a negative number, save the N previous articles.
  61. If N is nil and any articles have been marked with the process mark,
  62. save those articles instead."
  63. (interactive "P")
  64. (require 'gnus-art)
  65. (let ((gnus-default-article-saver 'gnus-summary-save-in-vm))
  66. (gnus-summary-save-article arg)))
  67. (defun gnus-summary-save-in-vm (&optional folder)
  68. (interactive)
  69. (require 'vm)
  70. (setq folder
  71. (gnus-read-save-file-name
  72. "Save %s in VM folder:" folder
  73. gnus-mail-save-name gnus-newsgroup-name
  74. gnus-current-headers 'gnus-newsgroup-last-mail))
  75. (gnus-eval-in-buffer-window gnus-original-article-buffer
  76. (save-excursion
  77. (save-restriction
  78. (widen)
  79. (let ((vm-folder (gnus-vm-make-folder)))
  80. (vm-save-message folder)
  81. (kill-buffer vm-folder))))))
  82. (provide 'gnus-vm)
  83. ;;; gnus-vm.el ends here