(defface tooltip): Inherit from variable-pitch.
[emacs.git] / lisp / gnus / gnus-ml.el
blob156250e7f841ddae193a863042e6bef7101decd2
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>
6 ;; Keywords: news
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)
13 ;; any later version.
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.
25 ;;; Commentary:
27 ;; implement (small subset of) RFC 2369
29 ;;; Usage:
31 ;; (add-hook 'gnus-summary-mode-hook 'turn-on-gnus-mailing-list-mode)
33 ;;; Code:
35 (require 'gnus)
36 (require 'gnus-msg)
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)
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]))))
72 ;;;###autoload
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)))
77 ;;;###autoload
78 (defun gnus-mailing-list-mode (&optional arg)
79 "Minor mode for providing mailing-list commands.
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))))
93 ;;; Commands
95 (defun gnus-mailing-list-help ()
96 "Get help from mailing list server."
97 (interactive)
98 (let ((list-help
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")))))
104 (defun gnus-mailing-list-subscribe ()
105 "Subscribe"
106 (interactive)
107 (let ((list-subscribe
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")))))
113 (defun gnus-mailing-list-unsubscribe ()
114 "Unsubscribe"
115 (interactive)
116 (let ((list-unsubscribe
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")))))
122 (defun gnus-mailing-list-post ()
123 "Post message (really useful ?)"
124 (interactive)
125 (let ((list-post
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")))))
131 (defun gnus-mailing-list-owner ()
132 "Mail to the owner"
133 (interactive)
134 (let ((list-owner
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")))))
140 (defun gnus-mailing-list-archive ()
141 "Browse archive"
142 (interactive)
143 (let ((list-archive
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")))))
149 ;;; Utility functions
151 (defun gnus-mailing-list-message (address)
153 (let ((mailto "")
154 (to ())
155 (subject "None")
156 (body "")
158 (cond
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))
172 (t (setq mailto args))))) ; without param
174 ; other case <http://... to be done.
175 (t nil))
176 (gnus-setup-message 'message (message-mail mailto subject))
177 (insert body)
180 (provide 'gnus-ml)
182 ;;; gnus-ml.el ends here