Mercurial > emacs
annotate lisp/gnus/gnus-draft.el @ 33067:adc6c04ffe30
*** empty log message ***
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 30 Oct 2000 15:21:36 +0000 |
parents | d4de00df3e68 |
children | e06db3b8e558 |
rev | line source |
---|---|
24358 | 1 ;;; gnus-draft.el --- draft message support for Gnus |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
2 ;; Copyright (C) 1997, 1998, 1999, 2000 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
3 ;; Free Software Foundation, Inc. |
24358 | 4 |
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
32996
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
6 ;; Maintainer: bugs@gnus.org |
24358 | 7 ;; Keywords: news |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;;; Code: | |
29 | |
30 (require 'gnus) | |
31 (require 'gnus-sum) | |
32 (require 'message) | |
33 (require 'gnus-msg) | |
34 (require 'nndraft) | |
35 (require 'gnus-agent) | |
36 (eval-when-compile (require 'cl)) | |
37 | |
38 ;;; Draft minor mode | |
39 | |
40 (defvar gnus-draft-mode nil | |
41 "Minor mode for providing a draft summary buffers.") | |
42 | |
43 (defvar gnus-draft-mode-map nil) | |
44 | |
45 (unless gnus-draft-mode-map | |
46 (setq gnus-draft-mode-map (make-sparse-keymap)) | |
47 | |
48 (gnus-define-keys gnus-draft-mode-map | |
49 "Dt" gnus-draft-toggle-sending | |
50 "De" gnus-draft-edit-message | |
51 "Ds" gnus-draft-send-message | |
52 "DS" gnus-draft-send-all-messages)) | |
53 | |
54 (defun gnus-draft-make-menu-bar () | |
55 (unless (boundp 'gnus-draft-menu) | |
56 (easy-menu-define | |
57 gnus-draft-menu gnus-draft-mode-map "" | |
58 '("Drafts" | |
59 ["Toggle whether to send" gnus-draft-toggle-sending t] | |
60 ["Edit" gnus-draft-edit-message t] | |
61 ["Send selected message(s)" gnus-draft-send-message t] | |
62 ["Send all messages" gnus-draft-send-all-messages t] | |
63 ["Delete draft" gnus-summary-delete-article t])))) | |
64 | |
65 (defun gnus-draft-mode (&optional arg) | |
66 "Minor mode for providing a draft summary buffers. | |
67 | |
68 \\{gnus-draft-mode-map}" | |
69 (interactive "P") | |
70 (when (eq major-mode 'gnus-summary-mode) | |
71 (when (set (make-local-variable 'gnus-draft-mode) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
72 (if (null arg) (not gnus-draft-mode) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
73 (> (prefix-numeric-value arg) 0))) |
24358 | 74 ;; Set up the menu. |
75 (when (gnus-visual-p 'draft-menu 'menu) | |
76 (gnus-draft-make-menu-bar)) | |
77 (gnus-add-minor-mode 'gnus-draft-mode " Draft" gnus-draft-mode-map) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
78 (mml-mode) |
24358 | 79 (gnus-run-hooks 'gnus-draft-mode-hook)))) |
80 | |
81 ;;; Commands | |
82 | |
83 (defun gnus-draft-toggle-sending (article) | |
84 "Toggle whether to send an article or not." | |
85 (interactive (list (gnus-summary-article-number))) | |
86 (if (gnus-draft-article-sendable-p article) | |
87 (progn | |
88 (push article gnus-newsgroup-unsendable) | |
89 (gnus-summary-mark-article article gnus-unsendable-mark)) | |
90 (setq gnus-newsgroup-unsendable | |
91 (delq article gnus-newsgroup-unsendable)) | |
92 (gnus-summary-mark-article article gnus-unread-mark)) | |
93 (gnus-summary-position-point)) | |
94 | |
95 (defun gnus-draft-edit-message () | |
96 "Enter a mail/post buffer to edit and send the draft." | |
97 (interactive) | |
98 (let ((article (gnus-summary-article-number))) | |
99 (gnus-summary-mark-as-read article gnus-canceled-mark) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
100 (gnus-draft-setup article gnus-newsgroup-name t) |
24358 | 101 (set-buffer-modified-p t) |
102 (save-buffer) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
103 (let ((gnus-verbose-backends nil)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
104 (gnus-request-expire-articles (list article) gnus-newsgroup-name t)) |
24358 | 105 (push |
106 `((lambda () | |
107 (when (gnus-buffer-exists-p ,gnus-summary-buffer) | |
108 (save-excursion | |
109 (set-buffer ,gnus-summary-buffer) | |
110 (gnus-cache-possibly-remove-article ,article nil nil nil t))))) | |
111 message-send-actions))) | |
112 | |
113 (defun gnus-draft-send-message (&optional n) | |
114 "Send the current draft." | |
115 (interactive "P") | |
32996
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
116 (let* ((articles (gnus-summary-work-articles n)) |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
117 (total (length articles)) |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
118 article) |
24358 | 119 (while (setq article (pop articles)) |
120 (gnus-summary-remove-process-mark article) | |
121 (unless (memq article gnus-newsgroup-unsendable) | |
32996
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
122 (let ((message-sending-message |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
123 (format "Sending message %d of %d..." |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
124 (- total (length articles)) total))) |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
125 (gnus-draft-send article gnus-newsgroup-name t)) |
24358 | 126 (gnus-summary-mark-article article gnus-canceled-mark))))) |
127 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
128 (defun gnus-draft-send (article &optional group interactive) |
24358 | 129 "Send message ARTICLE." |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
130 (let ((message-syntax-checks (if interactive nil |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
131 'dont-check-for-anything-just-trust-me)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
132 (message-inhibit-body-encoding (or (not group) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
133 (equal group "nndraft:queue") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
134 message-inhibit-body-encoding)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
135 (message-send-hook (and group (not (equal group "nndraft:queue")) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
136 message-send-hook)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
137 (message-setup-hook (and group (not (equal group "nndraft:queue")) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
138 message-setup-hook)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
139 type method) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
140 (gnus-draft-setup article (or group "nndraft:queue")) |
24358 | 141 ;; We read the meta-information that says how and where |
142 ;; this message is to be sent. | |
143 (save-restriction | |
144 (message-narrow-to-head) | |
145 (when (re-search-forward | |
146 (concat "^" (regexp-quote gnus-agent-meta-information-header) ":") | |
147 nil t) | |
148 (setq type (ignore-errors (read (current-buffer))) | |
149 method (ignore-errors (read (current-buffer)))) | |
150 (message-remove-header gnus-agent-meta-information-header))) | |
32996
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
151 ;; Let Agent restore any GCC lines and have message.el perform them. |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
152 (gnus-agent-restore-gcc) |
24358 | 153 ;; Then we send it. If we have no meta-information, we just send |
154 ;; it and let Message figure out how. | |
155 (when (and (or (null method) | |
156 (gnus-server-opened method) | |
157 (gnus-open-server method)) | |
158 (if type | |
159 (let ((message-this-is-news (eq type 'news)) | |
160 (message-this-is-mail (eq type 'mail)) | |
161 (gnus-post-method method) | |
162 (message-post-method method)) | |
163 (message-send-and-exit)) | |
164 (message-send-and-exit))) | |
165 (let ((gnus-verbose-backends nil)) | |
166 (gnus-request-expire-articles | |
167 (list article) (or group "nndraft:queue") t))))) | |
168 | |
169 (defun gnus-draft-send-all-messages () | |
170 "Send all the sendable drafts." | |
171 (interactive) | |
172 (gnus-uu-mark-buffer) | |
173 (gnus-draft-send-message)) | |
174 | |
175 (defun gnus-group-send-drafts () | |
176 "Send all sendable articles from the queue group." | |
177 (interactive) | |
178 (gnus-activate-group "nndraft:queue") | |
179 (save-excursion | |
32996
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
180 (let* ((articles (nndraft-articles)) |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
181 (unsendable (gnus-uncompress-range |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
182 (cdr (assq 'unsend |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
183 (gnus-info-marks |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
184 (gnus-get-info "nndraft:queue")))))) |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
185 (total (length articles)) |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
186 article) |
24358 | 187 (while (setq article (pop articles)) |
188 (unless (memq article unsendable) | |
32996
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
189 (let ((message-sending-message |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
190 (format "Sending message %d of %d..." |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
191 (- total (length articles)) total))) |
d4de00df3e68
2000-10-08 Christoph Conrad <christoph.conrad@gmx.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
192 (gnus-draft-send article))))))) |
24358 | 193 |
194 ;;; Utility functions | |
195 | |
196 ;;;!!!If this is byte-compiled, it fails miserably. | |
197 ;;;!!!This is because `gnus-setup-message' uses uninterned symbols. | |
198 ;;;!!!This has been fixed in recent versions of Emacs and XEmacs, | |
199 ;;;!!!but for the time being, we'll just run this tiny function uncompiled. | |
200 | |
201 (progn | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
202 (defun gnus-draft-setup (narticle group &optional restore) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
203 (gnus-setup-message 'forward |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
204 (let ((article narticle)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
205 (message-mail) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
206 (erase-buffer) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
207 (if (not (gnus-request-restore-buffer article group)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
208 (error "Couldn't restore the article") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
209 (if (and restore (equal group "nndraft:queue")) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
210 (mime-to-mml)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
211 ;; Insert the separator. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
212 (goto-char (point-min)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
213 (search-forward "\n\n") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
214 (forward-char -1) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
215 (insert mail-header-separator) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
216 (forward-line 1) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24358
diff
changeset
|
217 (message-set-auto-save-file-name)))))) |
24358 | 218 |
219 (defun gnus-draft-article-sendable-p (article) | |
220 "Say whether ARTICLE is sendable." | |
221 (not (memq article gnus-newsgroup-unsendable))) | |
222 | |
223 (provide 'gnus-draft) | |
224 | |
225 ;;; gnus-draft.el ends here |