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