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 (if (not (set (make-local-variable 'gnus-draft-mode)
64 (if (null arg) (not gnus-draft-mode)
65 (> (prefix-numeric-value arg) 0))))
66 (remove-hook 'gnus-message-setup-hook 'gnus-draft-setup-message)
68 (when (gnus-visual-p 'draft-menu 'menu)
69 (gnus-draft-make-menu-bar))
70 (gnus-add-minor-mode 'gnus-draft-mode " Draft" gnus-draft-mode-map)
71 (run-hooks 'gnus-draft-mode-hook))))
75 (defun gnus-draft-toggle-sending (article)
76 "Toggle whether to send an article or not."
77 (interactive (list (gnus-summary-article-number)))
78 (if (gnus-draft-article-sendable-p article)
80 (push article gnus-newsgroup-unsendable)
81 (gnus-summary-mark-article article gnus-unsendable-mark))
82 (setq gnus-newsgroup-unsendable
83 (delq article gnus-newsgroup-unsendable))
84 (gnus-summary-mark-article article gnus-unread-mark))
85 (gnus-summary-position-point))
87 (defun gnus-draft-edit-message ()
88 "Enter a mail/post buffer to edit and send the draft."
90 (gnus-set-global-variables)
91 (let ((article (gnus-summary-article-number)))
92 (gnus-draft-setup article)
95 (when (buffer-name (get-buffer ,gnus-summary-buffer))
97 (set-buffer (get-buffer ,gnus-summary-buffer))
98 (gnus-cache-possibly-remove-article ,article nil nil nil t)
99 (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
100 message-send-actions)))
102 (defun gnus-draft-send-message (&optional n)
103 "Send the current draft."
105 (gnus-set-global-variables)
106 (let ((articles (gnus-summary-work-articles n))
108 (while (setq article (pop articles))
109 (gnus-summary-remove-process-mark article)
110 (unless (memq article gnus-newsgroup-unsendable)
111 (gnus-draft-send article)
112 (gnus-summary-mark-article article gnus-canceled-mark)))))
114 (defun gnus-draft-send (article)
115 "Send message ARTICLE."
116 (gnus-draft-setup article)
117 (message-send-and-exit))
119 (defun gnus-draft-send-all-messages ()
120 "Send all the sendable drafts."
122 (gnus-uu-mark-buffer)
123 (gnus-draft-send-message))
125 (defun gnus-group-send-drafts ()
126 "Send all sendable articles from the draft group."
128 (gnus-request-group "nndraft:draft")
130 (let ((articles (nndraft-articles))
131 (unsendable (gnus-uncompress-range
132 (cdr (assq 'unsend (gnus-info-marks
133 (gnus-get-info "nndraft:draft"))))))
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:draft")))
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