Flymake fix to handle more C++ filenames (Bug#5488).
[emacs.git] / lisp / gnus / gnus-ml.el
blob078a8cfa15ceaff24a1dc15ebb96f1cddabf8990
1 ;;; gnus-ml.el --- Mailing list minor mode for Gnus
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Julien Gilles <jgilles@free.fr>
7 ;; Keywords: news, mail
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; implement (small subset of) RFC 2369
28 ;;; Code:
30 (require 'gnus)
31 (require 'gnus-msg)
32 (eval-when-compile (require 'cl))
34 ;;; Mailing list minor mode
36 (defvar gnus-mailing-list-mode nil
37 "Minor mode for providing mailing-list commands.")
39 (defvar gnus-mailing-list-mode-map nil)
41 (defvar gnus-mailing-list-menu)
43 (unless gnus-mailing-list-mode-map
44 (setq gnus-mailing-list-mode-map (make-sparse-keymap))
46 (gnus-define-keys gnus-mailing-list-mode-map
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
52 "\C-c\C-na" gnus-mailing-list-archive))
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]))))
66 ;;;###autoload
67 (defun turn-on-gnus-mailing-list-mode ()
68 (when (gnus-group-find-parameter gnus-newsgroup-name 'to-list)
69 (gnus-mailing-list-mode 1)))
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."))))
90 ;;;###autoload
91 (defun gnus-mailing-list-mode (&optional arg)
92 "Minor mode for providing mailing-list commands.
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))
103 (add-minor-mode 'gnus-mailing-list-mode " Mailing-List"
104 gnus-mailing-list-mode-map)
105 (gnus-run-hooks 'gnus-mailing-list-mode-hook))))
107 ;;; Commands
109 (defun gnus-mailing-list-help ()
110 "Get help from mailing list server."
111 (interactive)
112 (let ((list-help
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")))))
118 (defun gnus-mailing-list-subscribe ()
119 "Subscribe to mailing list."
120 (interactive)
121 (let ((list-subscribe
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")))))
127 (defun gnus-mailing-list-unsubscribe ()
128 "Unsubscribe from mailing list."
129 (interactive)
130 (let ((list-unsubscribe
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")))))
136 (defun gnus-mailing-list-post ()
137 "Post message (really useful ?)"
138 (interactive)
139 (let ((list-post
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")))))
145 (defun gnus-mailing-list-owner ()
146 "Mail to the mailing list owner."
147 (interactive)
148 (let ((list-owner
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")))))
154 (defun gnus-mailing-list-archive ()
155 "Browse archive."
156 (interactive)
157 (require 'browse-url)
158 (let ((list-archive
159 (with-current-buffer gnus-original-article-buffer
160 (gnus-fetch-field "list-archive"))))
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")))))
167 ;;; Utility functions
169 (defun gnus-mailing-list-message (address)
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)))
179 (provide 'gnus-ml)
181 ;; arch-tag: 936c0fe6-acce-4c16-87d0-eded88078896
182 ;;; gnus-ml.el ends here