1 ;;; gnus-draft.el --- draft message support for Gnus
2 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
32 (eval-when-compile (require 'cl))
36 (defvar gnus-draft-mode nil
37 "Minor mode for providing a draft summary buffers.")
39 (defvar gnus-draft-mode-map nil)
41 (unless gnus-draft-mode-map
42 (setq gnus-draft-mode-map (make-sparse-keymap))
44 (gnus-define-keys gnus-draft-mode-map
45 "Dt" gnus-draft-toggle-sending
46 "De" gnus-draft-edit-message
47 "Ds" gnus-draft-send-message
48 "DS" gnus-draft-send-all-messages))
50 (defun gnus-draft-make-menu-bar ()
51 (unless (boundp 'gnus-draft-menu)
53 gnus-draft-menu gnus-draft-mode-map ""
55 ["Toggle whether to send" gnus-draft-toggle-sending t]))))
57 (defun gnus-draft-mode (&optional arg)
58 "Minor mode for providing a draft summary buffers.
60 \\{gnus-draft-mode-map}"
62 (when (eq major-mode 'gnus-summary-mode)
63 (when (set (make-local-variable 'gnus-draft-mode)
64 (if (null arg) (not gnus-draft-mode)
65 (> (prefix-numeric-value arg) 0)))
67 (when (gnus-visual-p 'draft-menu 'menu)
68 (gnus-draft-make-menu-bar))
69 (gnus-add-minor-mode 'gnus-draft-mode " Draft" gnus-draft-mode-map)
70 (run-hooks 'gnus-draft-mode-hook))))
74 (defun gnus-draft-toggle-sending (article)
75 "Toggle whether to send an article or not."
76 (interactive (list (gnus-summary-article-number)))
77 (if (gnus-draft-article-sendable-p article)
79 (push article gnus-newsgroup-unsendable)
80 (gnus-summary-mark-article article gnus-unsendable-mark))
81 (setq gnus-newsgroup-unsendable
82 (delq article gnus-newsgroup-unsendable))
83 (gnus-summary-mark-article article gnus-unread-mark))
84 (gnus-summary-position-point))
86 (defun gnus-draft-edit-message ()
87 "Enter a mail/post buffer to edit and send the draft."
89 (gnus-set-global-variables)
90 (let ((article (gnus-summary-article-number)))
91 (gnus-draft-setup article)
94 (when (buffer-name (get-buffer ,gnus-summary-buffer))
96 (set-buffer (get-buffer ,gnus-summary-buffer))
97 (gnus-cache-possibly-remove-article ,article nil nil nil t)
98 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
99 message-send-actions)))
101 (defun gnus-draft-send-message (&optional n)
102 "Send the current draft."
104 (gnus-set-global-variables)
105 (let ((articles (gnus-summary-work-articles n))
107 (while (setq article (pop articles))
108 (gnus-summary-remove-process-mark article)
109 (unless (memq article gnus-newsgroup-unsendable)
110 (gnus-draft-send article)
111 (gnus-summary-mark-article article gnus-canceled-mark)))))
113 (defun gnus-draft-send (article)
114 "Send message ARTICLE."
115 (gnus-draft-setup article)
116 (message-send-and-exit))
118 (defun gnus-draft-send-all-messages ()
119 "Send all the sendable drafts."
121 (gnus-uu-mark-buffer)
122 (gnus-draft-send-message))
124 (defun gnus-group-send-drafts ()
125 "Send all sendable articles from the draft group."
127 (gnus-request-group "nndraft:drafts")
129 (let ((articles (nndraft-articles))
130 (unsendable (gnus-uncompress-range
133 (gnus-get-info "nndraft:drafts"))))))
135 (while (setq article (pop articles))
136 (unless (memq article unsendable)
137 (gnus-draft-send article))))))
139 ;;; Utility functions
141 (defun gnus-draft-setup (article)
142 (gnus-setup-message 'forward
145 (if (not (gnus-request-restore-buffer
146 article (or gnus-newsgroup-name "nndraft:drafts")))
147 (error "Couldn't restore the article")
148 ;; Insert the separator.
149 (goto-char (point-min))
150 (search-forward "\n\n")
152 (insert mail-header-separator)
156 (defun gnus-draft-article-sendable-p (article)
157 "Say whether ARTICLE is sendable."
158 (not (memq article gnus-newsgroup-unsendable)))
160 (provide 'gnus-draft)
162 ;;; gnus-draft.el ends here