1 ;;; gnus-ml.el --- Mailing list minor mode for Gnus
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
5 ;; Author: Julien Gilles <jgilles@free.fr>
8 ;; This file is part of GNU Emacs.
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)
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.
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.
27 ;; implement (small subset of) RFC 2369
31 ;; (add-hook 'gnus-summary-mode-hook 'turn-on-gnus-mailing-list-mode)
37 (eval-when-compile (require 'cl))
39 ;;; Mailing list minor mode
41 (defvar gnus-mailing-list-mode nil
42 "Minor mode for providing mailing-list commands.")
44 (defvar gnus-mailing-list-mode-map nil)
46 (defvar gnus-mailing-list-menu)
48 (unless gnus-mailing-list-mode-map
49 (setq gnus-mailing-list-mode-map (make-sparse-keymap))
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
60 (defun gnus-mailing-list-make-menu-bar ()
61 (unless (boundp 'gnus-mailing-list-menu)
63 gnus-mailing-list-menu gnus-mailing-list-mode-map ""
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]))))
73 (defun turn-on-gnus-mailing-list-mode ()
74 (when (gnus-group-get-parameter gnus-newsgroup-name 'to-list)
75 (gnus-mailing-list-mode 1)))
78 (defun gnus-mailing-list-insinuate (&optional force)
79 "Setup group parameters from List-Post header.
80 If FORCE is non-nil, replace the old ones."
83 (with-current-buffer gnus-original-article-buffer
84 (gnus-fetch-field "list-post"))))
87 (gnus-group-get-parameter gnus-newsgroup-name 'to-list))
88 (gnus-message 1 "to-list is non-nil.")
89 (if (string-match "<mailto:\\([^>]*\\)>" list-post)
90 (setq list-post (match-string 1 list-post)))
91 (gnus-group-add-parameter gnus-newsgroup-name
92 (cons 'to-list list-post))
93 (gnus-mailing-list-mode 1))
94 (gnus-message 1 "no list-post in this message."))))
97 (defun gnus-mailing-list-mode (&optional arg)
98 "Minor mode for providing mailing-list commands.
100 \\{gnus-mailing-list-mode-map}"
102 (when (eq major-mode 'gnus-summary-mode)
103 (when (set (make-local-variable 'gnus-mailing-list-mode)
104 (if (null arg) (not gnus-mailing-list-mode)
105 (> (prefix-numeric-value arg) 0)))
107 (when (gnus-visual-p 'mailing-list-menu 'menu)
108 (gnus-mailing-list-make-menu-bar))
109 (gnus-add-minor-mode 'gnus-mailing-list-mode " Mailing-List" gnus-mailing-list-mode-map)
110 (gnus-run-hooks 'gnus-mailing-list-mode-hook))))
114 (defun gnus-mailing-list-help ()
115 "Get help from mailing list server."
118 (with-current-buffer gnus-original-article-buffer
119 (gnus-fetch-field "list-help"))))
120 (cond (list-help (gnus-mailing-list-message list-help))
121 (t (gnus-message 1 "no list-help in this group")))))
123 (defun gnus-mailing-list-subscribe ()
126 (let ((list-subscribe
127 (with-current-buffer gnus-original-article-buffer
128 (gnus-fetch-field "list-subscribe"))))
129 (cond (list-subscribe (gnus-mailing-list-message list-subscribe))
130 (t (gnus-message 1 "no list-subscribe in this group")))))
132 (defun gnus-mailing-list-unsubscribe ()
135 (let ((list-unsubscribe
136 (with-current-buffer gnus-original-article-buffer
137 (gnus-fetch-field "list-unsubscribe"))))
138 (cond (list-unsubscribe (gnus-mailing-list-message list-unsubscribe))
139 (t (gnus-message 1 "no list-unsubscribe in this group")))))
141 (defun gnus-mailing-list-post ()
142 "Post message (really useful ?)"
145 (with-current-buffer gnus-original-article-buffer
146 (gnus-fetch-field "list-post"))))
147 (cond (list-post (gnus-mailing-list-message list-post))
148 (t (gnus-message 1 "no list-post in this group")))))
150 (defun gnus-mailing-list-owner ()
154 (with-current-buffer gnus-original-article-buffer
155 (gnus-fetch-field "list-owner"))))
156 (cond (list-owner (gnus-mailing-list-message list-owner))
157 (t (gnus-message 1 "no list-owner in this group")))))
159 (defun gnus-mailing-list-archive ()
162 (require 'browse-url)
164 (with-current-buffer gnus-original-article-buffer
165 (gnus-fetch-field "list-archive"))))
167 (if (string-match "<\\(http:[^>]*\\)>" list-archive)
168 (browse-url (match-string 1 list-archive))
169 (browse-url list-archive)))
170 (t (gnus-message 1 "no list-archive in this group")))))
172 ;;; Utility functions
174 (defun gnus-mailing-list-message (address)
182 ((string-match "<mailto:\\([^>]*\\)>" address)
183 (let ((args (match-string 1 address)))
185 ((string-match "\\(.*\\)\\?\\(.*\\)" args)
186 (setq mailto (match-string 1 args))
187 (let ((param (match-string 2 args)))
188 (if (string-match "subject=\\([^&]*\\)" param)
189 (setq subject (match-string 1 param)))
190 (if (string-match "body=\\([^&]*\\)" param)
191 (setq body (match-string 1 param)))
192 (if (string-match "to=\\([^&]*\\)" param)
193 (push (match-string 1 param) to))
195 (t (setq mailto args))))) ; without param
197 ; other case <http://... to be done.
199 (gnus-setup-message 'message (message-mail mailto subject))
205 ;;; gnus-ml.el ends here