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