Commit | Line | Data |
---|---|---|
715a2ca2 | 1 | ;;; gnus-ml.el --- mailing list minor mode for Gnus |
c113de23 GM |
2 | |
3 | ;; Copyright (C) 2000 Free Software Foundation, Inc. | |
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 | ||
1464e703 DL |
29 | ;;; Usage: |
30 | ||
31 | ;; (add-hook 'gnus-summary-mode-hook 'turn-on-gnus-mailing-list-mode) | |
32 | ||
c113de23 GM |
33 | ;;; Code: |
34 | ||
35 | (require 'gnus) | |
1464e703 | 36 | (require 'gnus-msg) |
c113de23 GM |
37 | (eval-when-compile (require 'cl)) |
38 | ||
39 | ;;; Mailing list minor mode | |
40 | ||
41 | (defvar gnus-mailing-list-mode nil | |
42 | "Minor mode for providing mailing-list commands.") | |
43 | ||
44 | (defvar gnus-mailing-list-mode-map nil) | |
45 | ||
1464e703 DL |
46 | (defvar gnus-mailing-list-menu) |
47 | ||
c113de23 GM |
48 | (unless gnus-mailing-list-mode-map |
49 | (setq gnus-mailing-list-mode-map (make-sparse-keymap)) | |
50 | ||
51 | (gnus-define-keys gnus-mailing-list-mode-map | |
52 | "\C-nh" gnus-mailing-list-help | |
53 | "\C-ns" gnus-mailing-list-subscribe | |
54 | "\C-nu" gnus-mailing-list-unsubscribe | |
55 | "\C-np" gnus-mailing-list-post | |
56 | "\C-no" gnus-mailing-list-owner | |
57 | "\C-na" gnus-mailing-list-archive | |
58 | )) | |
59 | ||
60 | (defun gnus-mailing-list-make-menu-bar () | |
61 | (unless (boundp 'gnus-mailing-list-menu) | |
62 | (easy-menu-define | |
63 | gnus-mailing-list-menu gnus-mailing-list-mode-map "" | |
64 | '("Mailing-Lists" | |
65 | ["Get help" gnus-mailing-list-help t] | |
66 | ["Subscribe" gnus-mailing-list-subscribe t] | |
67 | ["Unsubscribe" gnus-mailing-list-unsubscribe t] | |
68 | ["Post a message" gnus-mailing-list-post t] | |
69 | ["Mail to owner" gnus-mailing-list-owner t] | |
70 | ["Browse archive" gnus-mailing-list-archive t])))) | |
71 | ||
1464e703 | 72 | ;;;###autoload |
c113de23 | 73 | (defun turn-on-gnus-mailing-list-mode () |
1464e703 | 74 | (when (gnus-group-get-parameter gnus-newsgroup-name 'to-list) |
c113de23 GM |
75 | (gnus-mailing-list-mode 1))) |
76 | ||
1464e703 | 77 | ;;;###autoload |
c113de23 GM |
78 | (defun gnus-mailing-list-mode (&optional arg) |
79 | "Minor mode for providing mailing-list commands. | |
80 | ||
81 | \\{gnus-mailing-list-mode-map}" | |
82 | (interactive "P") | |
83 | (when (eq major-mode 'gnus-summary-mode) | |
84 | (when (set (make-local-variable 'gnus-mailing-list-mode) | |
85 | (if (null arg) (not gnus-mailing-list-mode) | |
86 | (> (prefix-numeric-value arg) 0))) | |
87 | ;; Set up the menu. | |
88 | (when (gnus-visual-p 'mailing-list-menu 'menu) | |
89 | (gnus-mailing-list-make-menu-bar)) | |
90 | (gnus-add-minor-mode 'gnus-mailing-list-mode " Mailing-List" gnus-mailing-list-mode-map) | |
91 | (gnus-run-hooks 'gnus-mailing-list-mode-hook)))) | |
92 | ||
93 | ;;; Commands | |
94 | ||
95 | (defun gnus-mailing-list-help () | |
96 | "Get help from mailing list server." | |
a1506d29 JB |
97 | (interactive) |
98 | (let ((list-help | |
1464e703 DL |
99 | (with-current-buffer gnus-original-article-buffer |
100 | (gnus-fetch-field "list-help")))) | |
101 | (cond (list-help (gnus-mailing-list-message list-help)) | |
102 | (t (gnus-message 1 "no list-help in this group"))))) | |
c113de23 GM |
103 | |
104 | (defun gnus-mailing-list-subscribe () | |
105 | "Subscribe" | |
106 | (interactive) | |
a1506d29 | 107 | (let ((list-subscribe |
1464e703 DL |
108 | (with-current-buffer gnus-original-article-buffer |
109 | (gnus-fetch-field "list-subscribe")))) | |
110 | (cond (list-subscribe (gnus-mailing-list-message list-subscribe)) | |
111 | (t (gnus-message 1 "no list-subscribe in this group"))))) | |
c113de23 GM |
112 | |
113 | (defun gnus-mailing-list-unsubscribe () | |
114 | "Unsubscribe" | |
115 | (interactive) | |
a1506d29 | 116 | (let ((list-unsubscribe |
1464e703 DL |
117 | (with-current-buffer gnus-original-article-buffer |
118 | (gnus-fetch-field "list-unsubscribe")))) | |
119 | (cond (list-unsubscribe (gnus-mailing-list-message list-unsubscribe)) | |
120 | (t (gnus-message 1 "no list-unsubscribe in this group"))))) | |
c113de23 GM |
121 | |
122 | (defun gnus-mailing-list-post () | |
123 | "Post message (really useful ?)" | |
124 | (interactive) | |
a1506d29 | 125 | (let ((list-post |
1464e703 DL |
126 | (with-current-buffer gnus-original-article-buffer |
127 | (gnus-fetch-field "list-post")))) | |
128 | (cond (list-post (gnus-mailing-list-message list-post)) | |
129 | (t (gnus-message 1 "no list-post in this group"))))) | |
c113de23 GM |
130 | |
131 | (defun gnus-mailing-list-owner () | |
132 | "Mail to the owner" | |
133 | (interactive) | |
a1506d29 | 134 | (let ((list-owner |
1464e703 DL |
135 | (with-current-buffer gnus-original-article-buffer |
136 | (gnus-fetch-field "list-owner")))) | |
137 | (cond (list-owner (gnus-mailing-list-message list-owner)) | |
138 | (t (gnus-message 1 "no list-owner in this group"))))) | |
c113de23 GM |
139 | |
140 | (defun gnus-mailing-list-archive () | |
141 | "Browse archive" | |
142 | (interactive) | |
a1506d29 | 143 | (let ((list-archive |
1464e703 DL |
144 | (with-current-buffer gnus-original-article-buffer |
145 | (gnus-fetch-field "list-archive")))) | |
146 | (cond (list-archive (gnus-mailing-list-message list-archive)) | |
147 | (t (gnus-message 1 "no list-owner in this group"))))) | |
c113de23 GM |
148 | |
149 | ;;; Utility functions | |
150 | ||
c113de23 GM |
151 | (defun gnus-mailing-list-message (address) |
152 | "" | |
153 | (let ((mailto "") | |
154 | (to ()) | |
155 | (subject "None") | |
156 | (body "") | |
157 | ) | |
a1506d29 | 158 | (cond |
c113de23 GM |
159 | ((string-match "<mailto:\\([^>]*\\)>" address) |
160 | (let ((args (match-string 1 address))) | |
161 | (cond ; with param | |
162 | ((string-match "\\(.*\\)\\?\\(.*\\)" args) | |
163 | (setq mailto (match-string 1 args)) | |
164 | (let ((param (match-string 2 args))) | |
165 | (if (string-match "subject=\\([^&]*\\)" param) | |
166 | (setq subject (match-string 1 param))) | |
167 | (if (string-match "body=\\([^&]*\\)" param) | |
168 | (setq body (match-string 1 param))) | |
169 | (if (string-match "to=\\([^&]*\\)" param) | |
170 | (push (match-string 1 param) to)) | |
a1506d29 | 171 | )) |
c113de23 | 172 | (t (setq mailto args))))) ; without param |
a1506d29 | 173 | |
c113de23 GM |
174 | ; other case <http://... to be done. |
175 | (t nil)) | |
176 | (gnus-setup-message 'message (message-mail mailto subject)) | |
177 | (insert body) | |
178 | )) | |
179 | ||
180 | (provide 'gnus-ml) | |
181 | ||
182 | ;;; gnus-ml.el ends here |