gnus-ml.el 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ;;; gnus-ml.el --- Mailing list minor mode for Gnus
  2. ;; Copyright (C) 2000-2012 Free Software Foundation, Inc.
  3. ;; Author: Julien Gilles <jgilles@free.fr>
  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. ;; implement (small subset of) RFC 2369
  18. ;;; Code:
  19. (require 'gnus)
  20. (require 'gnus-msg)
  21. (eval-when-compile (require 'cl))
  22. (eval-when-compile
  23. (when (featurep 'xemacs)
  24. (require 'easy-mmode))) ; for `define-minor-mode'
  25. ;;; Mailing list minor mode
  26. (defvar gnus-mailing-list-mode-map
  27. (let ((map (make-sparse-keymap)))
  28. (gnus-define-keys map
  29. "\C-c\C-nh" gnus-mailing-list-help
  30. "\C-c\C-ns" gnus-mailing-list-subscribe
  31. "\C-c\C-nu" gnus-mailing-list-unsubscribe
  32. "\C-c\C-np" gnus-mailing-list-post
  33. "\C-c\C-no" gnus-mailing-list-owner
  34. "\C-c\C-na" gnus-mailing-list-archive)
  35. map))
  36. (defvar gnus-mailing-list-menu)
  37. (defun gnus-mailing-list-make-menu-bar ()
  38. (unless (boundp 'gnus-mailing-list-menu)
  39. (easy-menu-define
  40. gnus-mailing-list-menu gnus-mailing-list-mode-map ""
  41. '("Mailing-Lists"
  42. ["Get help" gnus-mailing-list-help t]
  43. ["Subscribe" gnus-mailing-list-subscribe t]
  44. ["Unsubscribe" gnus-mailing-list-unsubscribe t]
  45. ["Post a message" gnus-mailing-list-post t]
  46. ["Mail to owner" gnus-mailing-list-owner t]
  47. ["Browse archive" gnus-mailing-list-archive t]))))
  48. ;;;###autoload
  49. (defun turn-on-gnus-mailing-list-mode ()
  50. (when (gnus-group-find-parameter gnus-newsgroup-name 'to-list)
  51. (gnus-mailing-list-mode 1)))
  52. ;;;###autoload
  53. (defun gnus-mailing-list-insinuate (&optional force)
  54. "Setup group parameters from List-Post header.
  55. If FORCE is non-nil, replace the old ones."
  56. (interactive "P")
  57. (let ((list-post
  58. (with-current-buffer gnus-original-article-buffer
  59. (gnus-fetch-field "list-post"))))
  60. (if list-post
  61. (if (and (not force)
  62. (gnus-group-get-parameter gnus-newsgroup-name 'to-list))
  63. (gnus-message 1 "to-list is non-nil.")
  64. (if (string-match "<mailto:\\([^>]*\\)>" list-post)
  65. (setq list-post (match-string 1 list-post)))
  66. (gnus-group-add-parameter gnus-newsgroup-name
  67. (cons 'to-list list-post))
  68. (gnus-mailing-list-mode 1))
  69. (gnus-message 1 "no list-post in this message."))))
  70. (eval-when-compile
  71. (when (featurep 'xemacs)
  72. (defvar gnus-mailing-list-mode-hook)
  73. (defvar gnus-mailing-list-mode-on-hook)
  74. (defvar gnus-mailing-list-mode-off-hook)))
  75. ;;;###autoload
  76. (define-minor-mode gnus-mailing-list-mode
  77. "Minor mode for providing mailing-list commands.
  78. \\{gnus-mailing-list-mode-map}"
  79. :lighter " Mailing-List"
  80. :keymap gnus-mailing-list-mode-map
  81. (cond
  82. ((not (derived-mode-p 'gnus-summary-mode))
  83. (setq gnus-mailing-list-mode nil))
  84. (gnus-mailing-list-mode
  85. ;; Set up the menu.
  86. (when (gnus-visual-p 'mailing-list-menu 'menu)
  87. (gnus-mailing-list-make-menu-bar)))))
  88. ;;; Commands
  89. (defun gnus-mailing-list-help ()
  90. "Get help from mailing list server."
  91. (interactive)
  92. (let ((list-help
  93. (with-current-buffer gnus-original-article-buffer
  94. (gnus-fetch-field "list-help"))))
  95. (cond (list-help (gnus-mailing-list-message list-help))
  96. (t (gnus-message 1 "no list-help in this group")))))
  97. (defun gnus-mailing-list-subscribe ()
  98. "Subscribe to mailing list."
  99. (interactive)
  100. (let ((list-subscribe
  101. (with-current-buffer gnus-original-article-buffer
  102. (gnus-fetch-field "list-subscribe"))))
  103. (cond (list-subscribe (gnus-mailing-list-message list-subscribe))
  104. (t (gnus-message 1 "no list-subscribe in this group")))))
  105. (defun gnus-mailing-list-unsubscribe ()
  106. "Unsubscribe from mailing list."
  107. (interactive)
  108. (let ((list-unsubscribe
  109. (with-current-buffer gnus-original-article-buffer
  110. (gnus-fetch-field "list-unsubscribe"))))
  111. (cond (list-unsubscribe (gnus-mailing-list-message list-unsubscribe))
  112. (t (gnus-message 1 "no list-unsubscribe in this group")))))
  113. (defun gnus-mailing-list-post ()
  114. "Post message (really useful ?)"
  115. (interactive)
  116. (let ((list-post
  117. (with-current-buffer gnus-original-article-buffer
  118. (gnus-fetch-field "list-post"))))
  119. (cond (list-post (gnus-mailing-list-message list-post))
  120. (t (gnus-message 1 "no list-post in this group")))))
  121. (defun gnus-mailing-list-owner ()
  122. "Mail to the mailing list owner."
  123. (interactive)
  124. (let ((list-owner
  125. (with-current-buffer gnus-original-article-buffer
  126. (gnus-fetch-field "list-owner"))))
  127. (cond (list-owner (gnus-mailing-list-message list-owner))
  128. (t (gnus-message 1 "no list-owner in this group")))))
  129. (defun gnus-mailing-list-archive ()
  130. "Browse archive."
  131. (interactive)
  132. (require 'browse-url)
  133. (let ((list-archive
  134. (with-current-buffer gnus-original-article-buffer
  135. (gnus-fetch-field "list-archive"))))
  136. (cond (list-archive
  137. (if (string-match "<\\(http:[^>]*\\)>" list-archive)
  138. (browse-url (match-string 1 list-archive))
  139. (browse-url list-archive)))
  140. (t (gnus-message 1 "no list-archive in this group")))))
  141. ;;; Utility functions
  142. (defun gnus-mailing-list-message (address)
  143. "Send message to ADDRESS.
  144. ADDRESS is specified by a \"mailto:\" URL."
  145. (cond
  146. ((string-match "<\\(mailto:[^>]*\\)>" address)
  147. (require 'gnus-art)
  148. (gnus-url-mailto (match-string 1 address)))
  149. ;; other case <http://...> to be done.
  150. (t nil)))
  151. (provide 'gnus-ml)
  152. ;;; gnus-ml.el ends here