1 ;;; gnus-draft.el --- draft message support for Semi-gnus
2 ;; Copyright (C) 1997,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME, offline
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 2, or (at your option)
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; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl))
38 (defvar gnus-draft-mode nil
39 "Minor mode for providing a draft summary buffers.")
41 (defvar gnus-draft-mode-map nil)
43 (unless gnus-draft-mode-map
44 (setq gnus-draft-mode-map (make-sparse-keymap))
46 (gnus-define-keys gnus-draft-mode-map
47 "Dt" gnus-draft-toggle-sending
48 "De" gnus-draft-edit-message
49 "Ds" gnus-draft-send-message
50 "DS" gnus-draft-send-all-messages))
52 (defun gnus-draft-make-menu-bar ()
53 (unless (boundp 'gnus-draft-menu)
55 gnus-draft-menu gnus-draft-mode-map ""
57 ["Toggle whether to send" gnus-draft-toggle-sending t]
58 ["Edit" gnus-draft-edit-message t]
59 ["Send selected message(s)" gnus-draft-send-message t]
60 ["Send all messages" gnus-draft-send-all-messages t]
61 ["Delete draft" gnus-summary-delete-article t]))))
63 (defun gnus-draft-mode (&optional arg)
64 "Minor mode for providing a draft summary buffers.
66 \\{gnus-draft-mode-map}"
68 (when (eq major-mode 'gnus-summary-mode)
69 (when (set (make-local-variable 'gnus-draft-mode)
70 (if (null arg) (not gnus-draft-mode)
71 (> (prefix-numeric-value arg) 0)))
73 (when (gnus-visual-p 'draft-menu 'menu)
74 (gnus-draft-make-menu-bar))
75 (gnus-add-minor-mode 'gnus-draft-mode " Draft" gnus-draft-mode-map)
76 (gnus-run-hooks 'gnus-draft-mode-hook))))
80 (defun gnus-draft-toggle-sending (article)
81 "Toggle whether to send an article or not."
82 (interactive (list (gnus-summary-article-number)))
83 (if (gnus-draft-article-sendable-p article)
85 (push article gnus-newsgroup-unsendable)
86 (gnus-summary-mark-article article gnus-unsendable-mark))
87 (setq gnus-newsgroup-unsendable
88 (delq article gnus-newsgroup-unsendable))
89 (gnus-summary-mark-article article gnus-unread-mark))
90 (gnus-summary-position-point))
92 (defun gnus-draft-edit-message ()
93 "Enter a mail/post buffer to edit and send the draft."
95 (let ((article (gnus-summary-article-number)))
96 (gnus-summary-mark-as-read article gnus-canceled-mark)
97 (gnus-draft-setup article gnus-newsgroup-name)
100 (when (gnus-buffer-exists-p ,gnus-summary-buffer)
102 (set-buffer ,gnus-summary-buffer)
103 (gnus-cache-possibly-remove-article ,article nil nil nil t)))))
104 message-send-actions)))
106 (defun gnus-draft-send-message (&optional n)
107 "Send the current draft."
109 (let ((articles (gnus-summary-work-articles n))
111 (while (setq article (pop articles))
112 (gnus-summary-remove-process-mark article)
113 (unless (memq article gnus-newsgroup-unsendable)
114 (gnus-draft-send article gnus-newsgroup-name)
115 (gnus-summary-mark-article article gnus-canceled-mark)))))
117 (defun gnus-draft-send (article &optional group)
118 "Send message ARTICLE."
119 (gnus-draft-setup article (or group "nndraft:queue"))
120 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me)
122 (message-send-and-exit)))
124 (defun gnus-draft-send-all-messages ()
125 "Send all the sendable drafts."
127 (gnus-uu-mark-buffer)
128 (gnus-draft-send-message))
130 (defun gnus-group-send-drafts ()
131 "Send all sendable articles from the queue group."
133 (gnus-activate-group "nndraft:queue")
135 (let ((articles (nndraft-articles))
136 (unsendable (gnus-uncompress-range
139 (gnus-get-info "nndraft:queue"))))))
141 (while (setq article (pop articles))
142 (unless (memq article unsendable)
143 (gnus-draft-send article))))))
145 ;;; Utility functions
147 (defcustom gnus-draft-decoding-function
150 (mime-edit-decode-buffer nil)
151 (eword-decode-header)
153 "*Function called to decode the message from network representation."
157 ;;;!!!If this is byte-compiled, it fails miserably.
158 ;;;!!!This is because `gnus-setup-message' uses uninterned symbols.
159 ;;;!!!This has been fixed in recent versions of Emacs and XEmacs,
160 ;;;!!!but for the time being, we'll just run this tiny function uncompiled.
163 (defun gnus-draft-setup (narticle group)
164 (gnus-setup-message 'forward
165 (let ((article narticle))
168 (if (not (gnus-request-restore-buffer article group))
169 (error "Couldn't restore the article")
170 ;; Insert the separator.
171 (funcall gnus-draft-decoding-function)
172 (goto-char (point-min))
173 (search-forward "\n\n")
175 (insert mail-header-separator)
177 (message-set-auto-save-file-name))))))
179 (defun gnus-draft-article-sendable-p (article)
180 "Say whether ARTICLE is sendable."
181 (not (memq article gnus-newsgroup-unsendable)))
183 (provide 'gnus-draft)
185 ;;; gnus-draft.el ends here