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.
33 (eval-when-compile (require 'cl))
37 (defvar gnus-draft-mode nil
38 "Minor mode for providing a draft summary buffers.")
40 (defvar gnus-draft-mode-map nil)
42 (unless gnus-draft-mode-map
43 (setq gnus-draft-mode-map (make-sparse-keymap))
45 (gnus-define-keys gnus-draft-mode-map
46 "Dt" gnus-draft-toggle-sending
47 "De" gnus-draft-edit-message
48 "Ds" gnus-draft-send-message
49 "DS" gnus-draft-send-all-messages))
51 (defun gnus-draft-make-menu-bar ()
52 (unless (boundp 'gnus-draft-menu)
54 gnus-draft-menu gnus-draft-mode-map ""
56 ["Toggle whether to send" gnus-draft-toggle-sending t]))))
58 (defun gnus-draft-mode (&optional arg)
59 "Minor mode for providing a draft summary buffers.
61 \\{gnus-draft-mode-map}"
63 (when (eq major-mode 'gnus-summary-mode)
64 (when (set (make-local-variable 'gnus-draft-mode)
65 (if (null arg) (not gnus-draft-mode)
66 (> (prefix-numeric-value arg) 0)))
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 (let ((article (gnus-summary-article-number)))
91 (gnus-summary-mark-as-read article gnus-canceled-mark)
92 (gnus-draft-setup article gnus-newsgroup-name)
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 message-send-actions)))
101 (defun gnus-draft-send-message (&optional n)
102 "Send the current draft."
104 (let ((articles (gnus-summary-work-articles n))
106 (while (setq article (pop articles))
107 (gnus-summary-remove-process-mark article)
108 (unless (memq article gnus-newsgroup-unsendable)
109 (gnus-draft-send article gnus-newsgroup-name)
110 (gnus-summary-mark-article article gnus-canceled-mark)))))
112 (defun gnus-draft-send (article &optional group)
113 "Send message ARTICLE."
114 (gnus-draft-setup article (or group "nndraft:queue"))
115 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me))
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 queue group."
127 (gnus-activate-group "nndraft:queue")
129 (let ((articles (nndraft-articles))
130 (unsendable (gnus-uncompress-range
133 (gnus-get-info "nndraft:queue"))))))
135 (while (setq article (pop articles))
136 (unless (memq article unsendable)
137 (gnus-draft-send article))))))
139 ;;; Utility functions
141 (defcustom gnus-draft-decoding-function
144 (mime-edit-decode-buffer nil)
145 (eword-decode-header)
147 "Function called to decode the message from network representation."
151 ;;;!!!If this is byte-compiled, it fails miserably.
152 ;;;!!!I have no idea why.
155 (defun gnus-draft-setup (narticle group)
156 (gnus-setup-message 'forward
157 (let ((article narticle))
160 (message "%s %s" group article)
161 (if (not (gnus-request-restore-buffer article group))
162 (error "Couldn't restore the article")
163 ;; Insert the separator.
164 (funcall gnus-draft-decoding-function)
165 (goto-char (point-min))
166 (search-forward "\n\n")
168 (insert mail-header-separator)
169 (forward-line 1))))))
171 (defun gnus-draft-article-sendable-p (article)
172 "Say whether ARTICLE is sendable."
173 (not (memq article gnus-newsgroup-unsendable)))
175 (provide 'gnus-draft)
177 ;;; gnus-draft.el ends here