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