1 ;;; gnus-draft.el --- draft message support for Semi-gnus
2 ;; Copyright (C) 1997 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]))))
59 (defun gnus-draft-mode (&optional arg)
60 "Minor mode for providing a draft summary buffers.
62 \\{gnus-draft-mode-map}"
64 (when (eq major-mode 'gnus-summary-mode)
65 (when (set (make-local-variable 'gnus-draft-mode)
66 (if (null arg) (not gnus-draft-mode)
67 (> (prefix-numeric-value arg) 0)))
69 (when (gnus-visual-p 'draft-menu 'menu)
70 (gnus-draft-make-menu-bar))
71 (gnus-add-minor-mode 'gnus-draft-mode " Draft" gnus-draft-mode-map)
72 (run-hooks 'gnus-draft-mode-hook))))
76 (defun gnus-draft-toggle-sending (article)
77 "Toggle whether to send an article or not."
78 (interactive (list (gnus-summary-article-number)))
79 (if (gnus-draft-article-sendable-p article)
81 (push article gnus-newsgroup-unsendable)
82 (gnus-summary-mark-article article gnus-unsendable-mark))
83 (setq gnus-newsgroup-unsendable
84 (delq article gnus-newsgroup-unsendable))
85 (gnus-summary-mark-article article gnus-unread-mark))
86 (gnus-summary-position-point))
88 (defun gnus-draft-edit-message ()
89 "Enter a mail/post buffer to edit and send the draft."
91 (let ((article (gnus-summary-article-number)))
92 (gnus-summary-mark-as-read article gnus-canceled-mark)
93 (gnus-draft-setup article gnus-newsgroup-name)
96 (when (buffer-name (get-buffer ,gnus-summary-buffer))
98 (set-buffer (get-buffer ,gnus-summary-buffer))
99 (gnus-cache-possibly-remove-article ,article nil nil nil t)))))
100 message-send-actions)))
102 (defun gnus-draft-send-message (&optional n)
103 "Send the current draft."
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 gnus-newsgroup-name)
111 (gnus-summary-mark-article article gnus-canceled-mark)))))
113 (defun gnus-draft-send (article &optional group)
114 "Send message ARTICLE."
115 (gnus-draft-setup article (or group "nndraft:queue"))
116 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me)
118 (message-send-and-exit)))
120 (defun gnus-draft-send-all-messages ()
121 "Send all the sendable drafts."
123 (gnus-uu-mark-buffer)
124 (gnus-draft-send-message))
126 (defun gnus-group-send-drafts ()
127 "Send all sendable articles from the queue group."
129 (gnus-activate-group "nndraft:queue")
131 (let ((articles (nndraft-articles))
132 (unsendable (gnus-uncompress-range
135 (gnus-get-info "nndraft:queue"))))))
137 (while (setq article (pop articles))
138 (unless (memq article unsendable)
139 (gnus-draft-send article))))))
141 ;;; Utility functions
143 (defcustom gnus-draft-decoding-function
146 (mime-edit-decode-buffer nil)
147 (eword-decode-header)
149 "Function called to decode the message from network representation."
153 ;;;!!!If this is byte-compiled, it fails miserably.
154 ;;;!!!I have no idea why.
157 (defun gnus-draft-setup (narticle group)
158 (gnus-setup-message 'forward
159 (let ((article narticle))
162 (if (not (gnus-request-restore-buffer article group))
163 (error "Couldn't restore the article")
164 ;; Insert the separator.
165 (funcall gnus-draft-decoding-function)
166 (goto-char (point-min))
167 (search-forward "\n\n")
169 (insert mail-header-separator)
171 (message-set-auto-save-file-name))))))
173 (defun gnus-draft-article-sendable-p (article)
174 "Say whether ARTICLE is sendable."
175 (not (memq article gnus-newsgroup-unsendable)))
177 (provide 'gnus-draft)
179 ;;; gnus-draft.el ends here