comparison lisp/gnus/nndraft.el @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 9968f55ad26e
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 ;;; nndraft.el --- draft article access for Gnus 1 ;;; nndraft.el --- draft article access for Gnus
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 2
3 ;; Free Software Foundation, Inc. 3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005 Free Software Foundation, Inc.
4 5
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> 6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news 7 ;; Keywords: news
7 8
8 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details. 19 ;; GNU General Public License for more details.
19 20
20 ;; You should have received a copy of the GNU General Public License 21 ;; 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 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02111-1307, USA. 24 ;; Boston, MA 02110-1301, USA.
24 25
25 ;;; Commentary: 26 ;;; Commentary:
26 27
27 ;;; Code: 28 ;;; Code:
28 29
30 (require 'nnmail) 31 (require 'nnmail)
31 (require 'gnus-start) 32 (require 'gnus-start)
32 (require 'nnmh) 33 (require 'nnmh)
33 (require 'nnoo) 34 (require 'nnoo)
34 (require 'mm-util) 35 (require 'mm-util)
35 (eval-when-compile 36 (eval-when-compile (require 'cl))
36 (require 'cl)
37 ;; This is just to shut up the byte-compiler.
38 (fset 'nndraft-request-group 'ignore))
39 37
40 (nnoo-declare nndraft 38 (nnoo-declare nndraft
41 nnmh) 39 nnmh)
42 40
43 (defvoo nndraft-directory (nnheader-concat gnus-directory "drafts/") 41 (defvoo nndraft-directory (nnheader-concat gnus-directory "drafts/")
111 (newest (if (file-newer-than-file-p file auto) file auto)) 109 (newest (if (file-newer-than-file-p file auto) file auto))
112 (nntp-server-buffer (or buffer nntp-server-buffer))) 110 (nntp-server-buffer (or buffer nntp-server-buffer)))
113 (when (and (file-exists-p newest) 111 (when (and (file-exists-p newest)
114 (let ((nnmail-file-coding-system 112 (let ((nnmail-file-coding-system
115 (if (file-newer-than-file-p file auto) 113 (if (file-newer-than-file-p file auto)
116 (if (equal group "drafts") 114 (if (member group '("drafts" "delayed"))
117 message-draft-coding-system 115 message-draft-coding-system
118 mm-text-coding-system) 116 mm-text-coding-system)
119 mm-auto-save-coding-system))) 117 mm-auto-save-coding-system)))
120 (nnmail-find-file newest))) 118 (nnmail-find-file newest)))
121 (save-excursion 119 (save-excursion
122 (set-buffer nntp-server-buffer) 120 (set-buffer nntp-server-buffer)
123 (goto-char (point-min)) 121 (goto-char (point-min))
124 ;; If there's a mail header separator in this file, 122 ;; If there's a mail header separator in this file,
125 ;; we remove it. 123 ;; we remove it.
126 (when (re-search-forward 124 (when (re-search-forward
127 (concat "^" mail-header-separator "$") nil t) 125 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
128 (replace-match "" t t))) 126 (replace-match "" t t)))
129 t)))) 127 t))))
130 128
131 (deffoo nndraft-request-restore-buffer (article &optional group server) 129 (deffoo nndraft-request-restore-buffer (article &optional group server)
132 "Request a new buffer that is restored to the state of ARTICLE." 130 "Request a new buffer that is restored to the state of ARTICLE."
133 (nndraft-possibly-change-group group) 131 (nndraft-possibly-change-group group)
134 (when (nndraft-request-article article group server (current-buffer)) 132 (when (nndraft-request-article article group server (current-buffer))
135 (message-remove-header "xref") 133 (message-remove-header "xref")
136 (message-remove-header "lines") 134 (message-remove-header "lines")
135 ;; Articles in nndraft:queue are considered as sent messages. The
136 ;; Date field should be the time when they are sent.
137 ;;(message-remove-header "date")
137 t)) 138 t))
138 139
139 (deffoo nndraft-request-update-info (group info &optional server) 140 (deffoo nndraft-request-update-info (group info &optional server)
140 (nndraft-possibly-change-group group) 141 (nndraft-possibly-change-group group)
141 (gnus-info-set-read 142 (gnus-info-set-read
149 (if (assq 'unsend marks) 150 (if (assq 'unsend marks)
150 (list (assq 'unsend marks)) 151 (list (assq 'unsend marks))
151 nil)))) 152 nil))))
152 t) 153 t)
153 154
155 (defun nndraft-generate-headers ()
156 (save-excursion
157 (message-generate-headers
158 (message-headers-to-generate
159 message-required-headers message-draft-headers nil))))
160
154 (deffoo nndraft-request-associate-buffer (group) 161 (deffoo nndraft-request-associate-buffer (group)
155 "Associate the current buffer with some article in the draft group." 162 "Associate the current buffer with some article in the draft group."
156 (nndraft-open-server "") 163 (nndraft-open-server "")
157 (nndraft-request-group group) 164 (nndraft-request-group group)
158 (nndraft-possibly-change-group group) 165 (nndraft-possibly-change-group group)
165 group (nnoo-current-server 'nndraft) t 'noinsert) 172 group (nnoo-current-server 'nndraft) t 'noinsert)
166 file (nndraft-article-filename article))) 173 file (nndraft-article-filename article)))
167 (setq buffer-file-name (expand-file-name file) 174 (setq buffer-file-name (expand-file-name file)
168 buffer-auto-save-file-name (make-auto-save-file-name)) 175 buffer-auto-save-file-name (make-auto-save-file-name))
169 (clear-visited-file-modtime) 176 (clear-visited-file-modtime)
177 (let ((hook (if (boundp 'write-contents-functions)
178 'write-contents-functions
179 'write-contents-hooks)))
180 (gnus-make-local-hook hook)
181 (add-hook hook 'nndraft-generate-headers nil t))
170 article)) 182 article))
183
184 (deffoo nndraft-request-group (group &optional server dont-check)
185 (nndraft-possibly-change-group group)
186 (unless dont-check
187 (let* ((pathname (nnmail-group-pathname group nndraft-directory))
188 (file-name-coding-system nnmail-pathname-coding-system)
189 dir file)
190 (nnheader-re-read-dir pathname)
191 (setq dir (mapcar (lambda (name) (string-to-number (substring name 1)))
192 (ignore-errors (directory-files
193 pathname nil "^#[0-9]+#$" t))))
194 (dolist (n dir)
195 (unless (file-exists-p
196 (setq file (expand-file-name (int-to-string n) pathname)))
197 (rename-file (nndraft-auto-save-file-name file) file)))))
198 (nnoo-parent-function 'nndraft
199 'nnmh-request-group
200 (list group server dont-check)))
201
202 (deffoo nndraft-request-move-article (article group server
203 accept-form &optional last)
204 (nndraft-possibly-change-group group)
205 (let ((buf (get-buffer-create " *nndraft move*"))
206 result)
207 (and
208 (nndraft-request-article article group server)
209 (save-excursion
210 (set-buffer buf)
211 (erase-buffer)
212 (insert-buffer-substring nntp-server-buffer)
213 (setq result (eval accept-form))
214 (kill-buffer (current-buffer))
215 result)
216 (null (nndraft-request-expire-articles (list article) group server 'force))
217 result)))
171 218
172 (deffoo nndraft-request-expire-articles (articles group &optional server force) 219 (deffoo nndraft-request-expire-articles (articles group &optional server force)
173 (nndraft-possibly-change-group group) 220 (nndraft-possibly-change-group group)
174 (let* ((nnmh-allow-delete-final t) 221 (let* ((nnmh-allow-delete-final t)
175 (res (nnoo-parent-function 'nndraft 222 (res (nnoo-parent-function 'nndraft
199 (list group server last noinsert)))) 246 (list group server last noinsert))))
200 247
201 (deffoo nndraft-request-replace-article (article group buffer) 248 (deffoo nndraft-request-replace-article (article group buffer)
202 (nndraft-possibly-change-group group) 249 (nndraft-possibly-change-group group)
203 (let ((nnmail-file-coding-system 250 (let ((nnmail-file-coding-system
204 (if (equal group "drafts") 251 (if (member group '("drafts" "delayed"))
205 mm-auto-save-coding-system 252 message-draft-coding-system
206 mm-text-coding-system))) 253 mm-text-coding-system)))
207 (nnoo-parent-function 'nndraft 'nnmh-request-replace-article 254 (nnoo-parent-function 'nndraft 'nnmh-request-replace-article
208 (list article group buffer)))) 255 (list article group buffer))))
209 256
210 (deffoo nndraft-request-create-group (group &optional server args) 257 (deffoo nndraft-request-create-group (group &optional server args)
247 294
248 (defun nndraft-articles () 295 (defun nndraft-articles ()
249 "Return the list of messages in the group." 296 "Return the list of messages in the group."
250 (gnus-make-directory nndraft-current-directory) 297 (gnus-make-directory nndraft-current-directory)
251 (sort 298 (sort
252 (mapcar 'string-to-int 299 (mapcar 'string-to-number
253 (directory-files nndraft-current-directory nil "\\`[0-9]+\\'" t)) 300 (directory-files nndraft-current-directory nil "\\`[0-9]+\\'" t))
254 '<)) 301 '<))
255 302
256 (nnoo-import nndraft 303 (nnoo-import nndraft
257 (nnmh 304 (nnmh
258 nnmh-retrieve-headers 305 nnmh-retrieve-headers
259 nnmh-request-group 306 nnmh-request-group
260 nnmh-close-group 307 nnmh-close-group
261 nnmh-request-list 308 nnmh-request-list
262 nnmh-request-newsgroups 309 nnmh-request-newsgroups))
263 nnmh-request-move-article))
264 310
265 (provide 'nndraft) 311 (provide 'nndraft)
266 312
313 ;;; arch-tag: 3ce26ca0-41cb-48b1-8703-4dad35e188aa
267 ;;; nndraft.el ends here 314 ;;; nndraft.el ends here