Merge branch 'master' into comment-cache
[emacs.git] / lisp / gnus / gnus-ml.el
blob32cf171331762f5519bdf35e1baf0ed736628d70
1 ;;; gnus-ml.el --- Mailing list minor mode for Gnus
3 ;; Copyright (C) 2000-2017 Free Software Foundation, Inc.
5 ;; Author: Julien Gilles <jgilles@free.fr>
6 ;; Keywords: news, mail
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 3 of the License, or
13 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; implement (small subset of) RFC 2369
27 ;;; Code:
29 (require 'gnus)
30 (require 'gnus-msg)
31 (eval-when-compile (require 'cl))
33 ;;; Mailing list minor mode
35 (defvar gnus-mailing-list-mode-map
36 (let ((map (make-sparse-keymap)))
37 (gnus-define-keys map
38 "\C-c\C-nh" gnus-mailing-list-help
39 "\C-c\C-ns" gnus-mailing-list-subscribe
40 "\C-c\C-nu" gnus-mailing-list-unsubscribe
41 "\C-c\C-np" gnus-mailing-list-post
42 "\C-c\C-no" gnus-mailing-list-owner
43 "\C-c\C-na" gnus-mailing-list-archive)
44 map))
46 (defvar gnus-mailing-list-menu)
48 (defun gnus-mailing-list-make-menu-bar ()
49 (unless (boundp 'gnus-mailing-list-menu)
50 (easy-menu-define
51 gnus-mailing-list-menu gnus-mailing-list-mode-map ""
52 '("Mailing-Lists"
53 ["Get help" gnus-mailing-list-help t]
54 ["Subscribe" gnus-mailing-list-subscribe t]
55 ["Unsubscribe" gnus-mailing-list-unsubscribe t]
56 ["Post a message" gnus-mailing-list-post t]
57 ["Mail to owner" gnus-mailing-list-owner t]
58 ["Browse archive" gnus-mailing-list-archive t]))))
60 ;;;###autoload
61 (defun turn-on-gnus-mailing-list-mode ()
62 (when (gnus-group-find-parameter gnus-newsgroup-name 'to-list)
63 (gnus-mailing-list-mode 1)))
65 ;;;###autoload
66 (defun gnus-mailing-list-insinuate (&optional force)
67 "Setup group parameters from List-Post header.
68 If FORCE is non-nil, replace the old ones."
69 (interactive "P")
70 (let ((list-post
71 (with-current-buffer gnus-original-article-buffer
72 (gnus-fetch-field "list-post"))))
73 (if list-post
74 (if (and (not force)
75 (gnus-group-get-parameter gnus-newsgroup-name 'to-list))
76 (gnus-message 1 "to-list is non-nil.")
77 (if (string-match "<mailto:\\([^>]*\\)>" list-post)
78 (setq list-post (match-string 1 list-post)))
79 (gnus-group-add-parameter gnus-newsgroup-name
80 (cons 'to-list list-post))
81 (gnus-mailing-list-mode 1))
82 (gnus-message 1 "no list-post in this message."))))
84 ;;;###autoload
85 (define-minor-mode gnus-mailing-list-mode
86 "Minor mode for providing mailing-list commands.
88 \\{gnus-mailing-list-mode-map}"
89 :lighter " Mailing-List"
90 :keymap gnus-mailing-list-mode-map
91 (cond
92 ((not (derived-mode-p 'gnus-summary-mode))
93 (setq gnus-mailing-list-mode nil))
94 (gnus-mailing-list-mode
95 ;; Set up the menu.
96 (when (gnus-visual-p 'mailing-list-menu 'menu)
97 (gnus-mailing-list-make-menu-bar)))))
99 ;;; Commands
101 (defun gnus-mailing-list-help ()
102 "Get help from mailing list server."
103 (interactive)
104 (let ((list-help
105 (with-current-buffer gnus-original-article-buffer
106 (gnus-fetch-field "list-help"))))
107 (cond (list-help (gnus-mailing-list-message list-help))
108 (t (gnus-message 1 "no list-help in this group")))))
110 (defun gnus-mailing-list-subscribe ()
111 "Subscribe to mailing list."
112 (interactive)
113 (let ((list-subscribe
114 (with-current-buffer gnus-original-article-buffer
115 (gnus-fetch-field "list-subscribe"))))
116 (cond (list-subscribe (gnus-mailing-list-message list-subscribe))
117 (t (gnus-message 1 "no list-subscribe in this group")))))
119 (defun gnus-mailing-list-unsubscribe ()
120 "Unsubscribe from mailing list."
121 (interactive)
122 (let ((list-unsubscribe
123 (with-current-buffer gnus-original-article-buffer
124 (gnus-fetch-field "list-unsubscribe"))))
125 (cond (list-unsubscribe (gnus-mailing-list-message list-unsubscribe))
126 (t (gnus-message 1 "no list-unsubscribe in this group")))))
128 (defun gnus-mailing-list-post ()
129 "Post message (really useful ?)"
130 (interactive)
131 (let ((list-post
132 (with-current-buffer gnus-original-article-buffer
133 (gnus-fetch-field "list-post"))))
134 (cond (list-post (gnus-mailing-list-message list-post))
135 (t (gnus-message 1 "no list-post in this group")))))
137 (defun gnus-mailing-list-owner ()
138 "Mail to the mailing list owner."
139 (interactive)
140 (let ((list-owner
141 (with-current-buffer gnus-original-article-buffer
142 (gnus-fetch-field "list-owner"))))
143 (cond (list-owner (gnus-mailing-list-message list-owner))
144 (t (gnus-message 1 "no list-owner in this group")))))
146 (defun gnus-mailing-list-archive ()
147 "Browse archive."
148 (interactive)
149 (require 'browse-url)
150 (let ((list-archive
151 (with-current-buffer gnus-original-article-buffer
152 (gnus-fetch-field "list-archive"))))
153 (cond (list-archive
154 (if (string-match "<\\(http:[^>]*\\)>" list-archive)
155 (browse-url (match-string 1 list-archive))
156 (browse-url list-archive)))
157 (t (gnus-message 1 "no list-archive in this group")))))
159 ;;; Utility functions
161 (defun gnus-mailing-list-message (address)
162 "Send message to ADDRESS.
163 ADDRESS is specified by a \"mailto:\" URL."
164 (cond
165 ((string-match "<\\(mailto:[^>]*\\)>" address)
166 (require 'gnus-art)
167 (gnus-url-mailto (match-string 1 address)))
168 ;; other case <http://...> to be done.
169 (t nil)))
171 (provide 'gnus-ml)
173 ;;; gnus-ml.el ends here