]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-ml.el
12ff5ea3a034d46ed95add5b4b961ff965ff9de6
[gnu-emacs] / lisp / gnus / gnus-ml.el
1 ;;; gnus-ml.el --- Mailing list minor mode for Gnus
2
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5
6 ;; Author: Julien Gilles <jgilles@free.fr>
7 ;; Keywords: news, mail
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; implement (small subset of) RFC 2369
27
28 ;;; Code:
29
30 (require 'gnus)
31 (require 'gnus-msg)
32 (eval-when-compile (require 'cl))
33 (eval-when-compile
34 (when (featurep 'xemacs)
35 (require 'easy-mmode))) ; for `define-minor-mode'
36
37 ;;; Mailing list minor mode
38
39 (defvar gnus-mailing-list-mode-map
40 (let ((map (make-sparse-keymap)))
41 (gnus-define-keys map
42 "\C-c\C-nh" gnus-mailing-list-help
43 "\C-c\C-ns" gnus-mailing-list-subscribe
44 "\C-c\C-nu" gnus-mailing-list-unsubscribe
45 "\C-c\C-np" gnus-mailing-list-post
46 "\C-c\C-no" gnus-mailing-list-owner
47 "\C-c\C-na" gnus-mailing-list-archive)
48 map))
49
50 (defvar gnus-mailing-list-menu)
51
52 (defun gnus-mailing-list-make-menu-bar ()
53 (unless (boundp 'gnus-mailing-list-menu)
54 (easy-menu-define
55 gnus-mailing-list-menu gnus-mailing-list-mode-map ""
56 '("Mailing-Lists"
57 ["Get help" gnus-mailing-list-help t]
58 ["Subscribe" gnus-mailing-list-subscribe t]
59 ["Unsubscribe" gnus-mailing-list-unsubscribe t]
60 ["Post a message" gnus-mailing-list-post t]
61 ["Mail to owner" gnus-mailing-list-owner t]
62 ["Browse archive" gnus-mailing-list-archive t]))))
63
64 ;;;###autoload
65 (defun turn-on-gnus-mailing-list-mode ()
66 (when (gnus-group-find-parameter gnus-newsgroup-name 'to-list)
67 (gnus-mailing-list-mode 1)))
68
69 ;;;###autoload
70 (defun gnus-mailing-list-insinuate (&optional force)
71 "Setup group parameters from List-Post header.
72 If FORCE is non-nil, replace the old ones."
73 (interactive "P")
74 (let ((list-post
75 (with-current-buffer gnus-original-article-buffer
76 (gnus-fetch-field "list-post"))))
77 (if list-post
78 (if (and (not force)
79 (gnus-group-get-parameter gnus-newsgroup-name 'to-list))
80 (gnus-message 1 "to-list is non-nil.")
81 (if (string-match "<mailto:\\([^>]*\\)>" list-post)
82 (setq list-post (match-string 1 list-post)))
83 (gnus-group-add-parameter gnus-newsgroup-name
84 (cons 'to-list list-post))
85 (gnus-mailing-list-mode 1))
86 (gnus-message 1 "no list-post in this message."))))
87
88 (eval-when-compile
89 (when (featurep 'xemacs)
90 (defvar gnus-mailing-list-mode-hook)
91 (defvar gnus-mailing-list-mode-on-hook)
92 (defvar gnus-mailing-list-mode-off-hook)))
93
94 ;;;###autoload
95 (define-minor-mode gnus-mailing-list-mode
96 "Minor mode for providing mailing-list commands.
97
98 \\{gnus-mailing-list-mode-map}"
99 :lighter " Mailing-List"
100 :keymap gnus-mailing-list-mode-map
101 (cond
102 ((not (derived-mode-p 'gnus-summary-mode))
103 (setq gnus-mailing-list-mode nil))
104 (gnus-mailing-list-mode
105 ;; Set up the menu.
106 (when (gnus-visual-p 'mailing-list-menu 'menu)
107 (gnus-mailing-list-make-menu-bar)))))
108
109 ;;; Commands
110
111 (defun gnus-mailing-list-help ()
112 "Get help from mailing list server."
113 (interactive)
114 (let ((list-help
115 (with-current-buffer gnus-original-article-buffer
116 (gnus-fetch-field "list-help"))))
117 (cond (list-help (gnus-mailing-list-message list-help))
118 (t (gnus-message 1 "no list-help in this group")))))
119
120 (defun gnus-mailing-list-subscribe ()
121 "Subscribe to mailing list."
122 (interactive)
123 (let ((list-subscribe
124 (with-current-buffer gnus-original-article-buffer
125 (gnus-fetch-field "list-subscribe"))))
126 (cond (list-subscribe (gnus-mailing-list-message list-subscribe))
127 (t (gnus-message 1 "no list-subscribe in this group")))))
128
129 (defun gnus-mailing-list-unsubscribe ()
130 "Unsubscribe from mailing list."
131 (interactive)
132 (let ((list-unsubscribe
133 (with-current-buffer gnus-original-article-buffer
134 (gnus-fetch-field "list-unsubscribe"))))
135 (cond (list-unsubscribe (gnus-mailing-list-message list-unsubscribe))
136 (t (gnus-message 1 "no list-unsubscribe in this group")))))
137
138 (defun gnus-mailing-list-post ()
139 "Post message (really useful ?)"
140 (interactive)
141 (let ((list-post
142 (with-current-buffer gnus-original-article-buffer
143 (gnus-fetch-field "list-post"))))
144 (cond (list-post (gnus-mailing-list-message list-post))
145 (t (gnus-message 1 "no list-post in this group")))))
146
147 (defun gnus-mailing-list-owner ()
148 "Mail to the mailing list owner."
149 (interactive)
150 (let ((list-owner
151 (with-current-buffer gnus-original-article-buffer
152 (gnus-fetch-field "list-owner"))))
153 (cond (list-owner (gnus-mailing-list-message list-owner))
154 (t (gnus-message 1 "no list-owner in this group")))))
155
156 (defun gnus-mailing-list-archive ()
157 "Browse archive."
158 (interactive)
159 (require 'browse-url)
160 (let ((list-archive
161 (with-current-buffer gnus-original-article-buffer
162 (gnus-fetch-field "list-archive"))))
163 (cond (list-archive
164 (if (string-match "<\\(http:[^>]*\\)>" list-archive)
165 (browse-url (match-string 1 list-archive))
166 (browse-url list-archive)))
167 (t (gnus-message 1 "no list-archive in this group")))))
168
169 ;;; Utility functions
170
171 (defun gnus-mailing-list-message (address)
172 "Send message to ADDRESS.
173 ADDRESS is specified by a \"mailto:\" URL."
174 (cond
175 ((string-match "<\\(mailto:[^>]*\\)>" address)
176 (require 'gnus-art)
177 (gnus-url-mailto (match-string 1 address)))
178 ;; other case <http://...> to be done.
179 (t nil)))
180
181 (provide 'gnus-ml)
182
183 ;;; gnus-ml.el ends here