17493
|
1 ;;; nnfolder.el --- mail folder access for Gnus
|
64754
|
2
|
|
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
100908
|
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
17493
|
5
|
56927
|
6 ;; Author: Simon Josefsson <simon@josefsson.org> (adding MARKS)
|
|
7 ;; ShengHuo Zhu <zsh@cs.rochester.edu> (adding NOV)
|
|
8 ;; Scott Byer <byer@mv.us.adobe.com>
|
24357
|
9 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
|
56927
|
10 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
|
17493
|
11 ;; Keywords: mail
|
|
12
|
|
13 ;; This file is part of GNU Emacs.
|
|
14
|
94662
|
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
|
17493
|
16 ;; it under the terms of the GNU General Public License as published by
|
94662
|
17 ;; the Free Software Foundation, either version 3 of the License, or
|
|
18 ;; (at your option) any later version.
|
17493
|
19
|
|
20 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23 ;; GNU General Public License for more details.
|
|
24
|
|
25 ;; You should have received a copy of the GNU General Public License
|
94662
|
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
17493
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;;; Code:
|
|
31
|
87234
|
32 ;; For Emacs < 22.2.
|
|
33 (eval-and-compile
|
|
34 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
|
|
35
|
17493
|
36 (require 'nnheader)
|
|
37 (require 'message)
|
|
38 (require 'nnmail)
|
|
39 (require 'nnoo)
|
24357
|
40 (eval-when-compile (require 'cl))
|
56927
|
41 (require 'gnus)
|
17493
|
42 (require 'gnus-util)
|
47002
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
diff
changeset
|
43 (require 'gnus-range)
|
17493
|
44
|
95822
|
45 ;; FIXME not explicitly used in this file.
|
95819
|
46 (autoload 'gnus-article-unpropagatable-p "gnus-sum")
|
56927
|
47
|
17493
|
48 (nnoo-declare nnfolder)
|
|
49
|
|
50 (defvoo nnfolder-directory (expand-file-name message-directory)
|
|
51 "The name of the nnfolder directory.")
|
|
52
|
56927
|
53 (defvoo nnfolder-nov-directory nil
|
|
54 "The name of the nnfolder NOV directory.
|
|
55 If nil, `nnfolder-directory' is used.")
|
|
56
|
|
57 (defvoo nnfolder-marks-directory nil
|
|
58 "The name of the nnfolder MARKS directory.
|
|
59 If nil, `nnfolder-directory' is used.")
|
|
60
|
17493
|
61 (defvoo nnfolder-active-file
|
31716
|
62 (nnheader-concat nnfolder-directory "active")
|
17493
|
63 "The name of the active file.")
|
|
64
|
|
65 ;; I renamed this variable to something more in keeping with the general GNU
|
|
66 ;; style. -SLB
|
|
67
|
|
68 (defvoo nnfolder-ignore-active-file nil
|
32193
|
69 "If non-nil, the active file is ignored.
|
31716
|
70 This causes nnfolder to do some extra work in order to determine the
|
|
71 true active ranges of an mbox file. Note that the active file is
|
32193
|
72 still saved, but its values are not used. This costs some extra time
|
31716
|
73 when scanning an mbox when opening it.")
|
17493
|
74
|
|
75 (defvoo nnfolder-distrust-mbox nil
|
31716
|
76 "If non-nil, the folder will be distrusted.
|
|
77 This means that nnfolder will not trust the user with respect to
|
|
78 inserting unaccounted for mail in the middle of an mbox file. This
|
|
79 can greatly slow down scans, which now must scan the entire file for
|
|
80 unmarked messages. When nil, scans occur forward from the last marked
|
|
81 message, a huge time saver for large mailboxes.")
|
17493
|
82
|
|
83 (defvoo nnfolder-newsgroups-file
|
31716
|
84 (concat (file-name-as-directory nnfolder-directory) "newsgroups")
|
17493
|
85 "Mail newsgroups description file.")
|
|
86
|
|
87 (defvoo nnfolder-get-new-mail t
|
|
88 "If non-nil, nnfolder will check the incoming mail file and split the mail.")
|
|
89
|
|
90 (defvoo nnfolder-prepare-save-mail-hook nil
|
|
91 "Hook run narrowed to an article before saving.")
|
|
92
|
|
93 (defvoo nnfolder-save-buffer-hook nil
|
|
94 "Hook run before saving the nnfolder mbox buffer.")
|
|
95
|
56927
|
96
|
17493
|
97 (defvoo nnfolder-inhibit-expiry nil
|
|
98 "If non-nil, inhibit expiry.")
|
|
99
|
|
100
|
|
101
|
56927
|
102 (defconst nnfolder-version "nnfolder 2.0"
|
17493
|
103 "nnfolder version.")
|
|
104
|
|
105 (defconst nnfolder-article-marker "X-Gnus-Article-Number: "
|
|
106 "String used to demarcate what the article number for a message is.")
|
|
107
|
|
108 (defvoo nnfolder-current-group nil)
|
|
109 (defvoo nnfolder-current-buffer nil)
|
|
110 (defvoo nnfolder-status-string "")
|
|
111 (defvoo nnfolder-group-alist nil)
|
|
112 (defvoo nnfolder-buffer-alist nil)
|
|
113 (defvoo nnfolder-scantime-alist nil)
|
|
114 (defvoo nnfolder-active-timestamp nil)
|
31716
|
115 (defvoo nnfolder-active-file-coding-system mm-text-coding-system)
|
49598
|
116 (defvoo nnfolder-active-file-coding-system-for-write
|
31716
|
117 nnmail-active-file-coding-system)
|
|
118 (defvoo nnfolder-file-coding-system mm-text-coding-system)
|
|
119 (defvoo nnfolder-file-coding-system-for-write nnheader-file-coding-system
|
|
120 "Coding system for save nnfolder file.
|
56927
|
121 if nil, `nnfolder-file-coding-system' is used.") ; FIXME: fill-in the doc-string of this variable
|
|
122
|
|
123 (defvoo nnfolder-nov-is-evil nil
|
|
124 "If non-nil, Gnus will never generate and use nov databases for mail groups.
|
|
125 Using nov databases will speed up header fetching considerably.
|
|
126 This variable shouldn't be flipped much. If you have, for some reason,
|
|
127 set this to t, and want to set it to nil again, you should always run
|
|
128 the `nnfolder-generate-active-file' command. The function will go
|
|
129 through all nnfolder directories and generate nov databases for them
|
|
130 all. This may very well take some time.")
|
|
131
|
|
132 (defvoo nnfolder-nov-file-suffix ".nov")
|
|
133
|
|
134 (defvoo nnfolder-nov-buffer-alist nil)
|
|
135
|
|
136 (defvar nnfolder-nov-buffer-file-name nil)
|
|
137
|
|
138 (defvoo nnfolder-marks-is-evil nil
|
|
139 "If non-nil, Gnus will never generate and use marks file for mail groups.
|
|
140 Using marks files makes it possible to backup and restore mail groups
|
|
141 separately from `.newsrc.eld'. If you have, for some reason, set
|
|
142 this to t, and want to set it to nil again, you should always remove
|
|
143 the corresponding marks file (usually base nnfolder file name
|
|
144 concatenated with `.mrk', but see `nnfolder-marks-file-suffix') for
|
|
145 the group. Then the marks file will be regenerated properly by Gnus.")
|
|
146
|
|
147 (defvoo nnfolder-marks nil)
|
|
148
|
|
149 (defvoo nnfolder-marks-file-suffix ".mrk")
|
|
150
|
|
151 (defvar nnfolder-marks-modtime (gnus-make-hashtable))
|
17493
|
152
|
|
153
|
|
154
|
|
155 ;;; Interface functions
|
|
156
|
|
157 (nnoo-define-basics nnfolder)
|
|
158
|
|
159 (deffoo nnfolder-retrieve-headers (articles &optional group server fetch-old)
|
|
160 (save-excursion
|
|
161 (set-buffer nntp-server-buffer)
|
|
162 (erase-buffer)
|
56927
|
163 (let (article start stop num)
|
17493
|
164 (nnfolder-possibly-change-group group server)
|
|
165 (when nnfolder-current-buffer
|
|
166 (set-buffer nnfolder-current-buffer)
|
|
167 (goto-char (point-min))
|
|
168 (if (stringp (car articles))
|
|
169 'headers
|
56927
|
170 (if (nnfolder-retrieve-headers-with-nov articles fetch-old)
|
|
171 'nov
|
|
172 (setq articles (gnus-sorted-intersection
|
|
173 ;; Is ARTICLES sorted?
|
|
174 (sort articles '<)
|
|
175 (nnfolder-existing-articles)))
|
|
176 (while (setq article (pop articles))
|
|
177 (set-buffer nnfolder-current-buffer)
|
|
178 (cond ((nnfolder-goto-article article)
|
|
179 (setq start (point))
|
|
180 (setq stop (if (search-forward "\n\n" nil t)
|
|
181 (1- (point))
|
|
182 (point-max)))
|
|
183 (set-buffer nntp-server-buffer)
|
|
184 (insert (format "221 %d Article retrieved.\n" article))
|
|
185 (insert-buffer-substring nnfolder-current-buffer
|
|
186 start stop)
|
|
187 (goto-char (point-max))
|
|
188 (insert ".\n"))
|
17493
|
189
|
56927
|
190 ;; If we couldn't find this article, skip over ranges
|
|
191 ;; of missing articles so we don't search the whole file
|
|
192 ;; for each of them.
|
|
193 ((numberp article)
|
|
194 (setq start (point))
|
|
195 (and
|
|
196 ;; Check that we are either at BOF or after an
|
|
197 ;; article with a lower number. We do this so we
|
|
198 ;; won't be confused by out-of-order article numbers,
|
|
199 ;; as caused by active file bogosity.
|
|
200 (cond
|
|
201 ((bobp))
|
|
202 ((search-backward (concat "\n" nnfolder-article-marker)
|
|
203 nil t)
|
|
204 (goto-char (match-end 0))
|
62907
|
205 (setq num (string-to-number
|
56927
|
206 (buffer-substring
|
85712
|
207 (point) (point-at-eol))))
|
56927
|
208 (goto-char start)
|
|
209 (< num article)))
|
|
210 ;; Check that we are before an article with a
|
|
211 ;; higher number.
|
|
212 (search-forward (concat "\n" nnfolder-article-marker)
|
|
213 nil t)
|
|
214 (progn
|
62907
|
215 (setq num (string-to-number
|
56927
|
216 (buffer-substring
|
85712
|
217 (point) (point-at-eol))))
|
56927
|
218 (> num article))
|
|
219 ;; Discard any article numbers before the one we're
|
|
220 ;; now looking at.
|
|
221 (while (and articles
|
|
222 (< (car articles) num))
|
|
223 (setq articles (cdr articles))))
|
|
224 (goto-char start))))
|
|
225 (set-buffer nntp-server-buffer)
|
|
226 (nnheader-fold-continuation-lines)
|
|
227 'headers))))))
|
17493
|
228
|
|
229 (deffoo nnfolder-open-server (server &optional defs)
|
|
230 (nnoo-change-server 'nnfolder server defs)
|
|
231 (nnmail-activate 'nnfolder t)
|
|
232 (gnus-make-directory nnfolder-directory)
|
56927
|
233 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
|
|
234 (and nnfolder-nov-directory
|
|
235 (gnus-make-directory nnfolder-nov-directory)))
|
|
236 (unless nnfolder-marks-is-evil
|
|
237 (and nnfolder-marks-directory
|
|
238 (gnus-make-directory nnfolder-marks-directory)))
|
17493
|
239 (cond
|
|
240 ((not (file-exists-p nnfolder-directory))
|
|
241 (nnfolder-close-server)
|
|
242 (nnheader-report 'nnfolder "Couldn't create directory: %s"
|
|
243 nnfolder-directory))
|
|
244 ((not (file-directory-p (file-truename nnfolder-directory)))
|
|
245 (nnfolder-close-server)
|
|
246 (nnheader-report 'nnfolder "Not a directory: %s" nnfolder-directory))
|
|
247 (t
|
|
248 (nnmail-activate 'nnfolder)
|
|
249 (nnheader-report 'nnfolder "Opened server %s using directory %s"
|
|
250 server nnfolder-directory)
|
|
251 t)))
|
|
252
|
|
253 (deffoo nnfolder-request-close ()
|
|
254 (let ((alist nnfolder-buffer-alist))
|
|
255 (while alist
|
|
256 (nnfolder-close-group (caar alist) nil t)
|
|
257 (setq alist (cdr alist))))
|
|
258 (nnoo-close-server 'nnfolder)
|
|
259 (setq nnfolder-buffer-alist nil
|
|
260 nnfolder-group-alist nil))
|
|
261
|
|
262 (deffoo nnfolder-request-article (article &optional group server buffer)
|
|
263 (nnfolder-possibly-change-group group server)
|
|
264 (save-excursion
|
|
265 (set-buffer nnfolder-current-buffer)
|
|
266 (goto-char (point-min))
|
24357
|
267 (when (nnfolder-goto-article article)
|
17493
|
268 (let (start stop)
|
|
269 (setq start (point))
|
|
270 (forward-line 1)
|
|
271 (unless (and (nnmail-search-unix-mail-delim)
|
|
272 (forward-line -1))
|
|
273 (goto-char (point-max)))
|
|
274 (setq stop (point))
|
|
275 (let ((nntp-server-buffer (or buffer nntp-server-buffer)))
|
|
276 (set-buffer nntp-server-buffer)
|
|
277 (erase-buffer)
|
|
278 (insert-buffer-substring nnfolder-current-buffer start stop)
|
|
279 (goto-char (point-min))
|
|
280 (while (looking-at "From ")
|
|
281 (delete-char 5)
|
|
282 (insert "X-From-Line: ")
|
|
283 (forward-line 1))
|
|
284 (if (numberp article)
|
|
285 (cons nnfolder-current-group article)
|
|
286 (goto-char (point-min))
|
|
287 (cons nnfolder-current-group
|
49598
|
288 (if (search-forward (concat "\n" nnfolder-article-marker)
|
31716
|
289 nil t)
|
62907
|
290 (string-to-number (buffer-substring
|
85712
|
291 (point) (point-at-eol)))
|
31716
|
292 -1))))))))
|
17493
|
293
|
|
294 (deffoo nnfolder-request-group (group &optional server dont-check)
|
|
295 (nnfolder-possibly-change-group group server t)
|
|
296 (save-excursion
|
85712
|
297 (cond ((not (assoc group nnfolder-group-alist))
|
|
298 (nnheader-report 'nnfolder "No such group: %s" group))
|
|
299 ((file-directory-p (nnfolder-group-pathname group))
|
|
300 (nnheader-report 'nnfolder "%s is a directory"
|
|
301 (file-name-as-directory
|
|
302 (let ((nnmail-pathname-coding-system nil))
|
|
303 (nnfolder-group-pathname group)))))
|
|
304 (dont-check
|
|
305 (nnheader-report 'nnfolder "Selected group %s" group)
|
|
306 t)
|
|
307 (t
|
|
308 (let* ((active (assoc group nnfolder-group-alist))
|
|
309 (group (car active))
|
|
310 (range (cadr active)))
|
|
311 (cond
|
|
312 ((null active)
|
|
313 (nnheader-report 'nnfolder "No such group: %s" group))
|
|
314 ((null nnfolder-current-group)
|
|
315 (nnheader-report 'nnfolder "Empty group: %s" group))
|
|
316 (t
|
|
317 (nnheader-report 'nnfolder "Selected group %s" group)
|
|
318 (nnheader-insert "211 %d %d %d %s\n"
|
|
319 (1+ (- (cdr range) (car range)))
|
|
320 (car range) (cdr range) group))))))))
|
17493
|
321
|
|
322 (deffoo nnfolder-request-scan (&optional group server)
|
|
323 (nnfolder-possibly-change-group nil server)
|
|
324 (when nnfolder-get-new-mail
|
|
325 (nnfolder-possibly-change-group group server)
|
|
326 (nnmail-get-new-mail
|
|
327 'nnfolder
|
|
328 (lambda ()
|
|
329 (let ((bufs nnfolder-buffer-alist))
|
|
330 (save-excursion
|
|
331 (while bufs
|
|
332 (if (not (gnus-buffer-live-p (nth 1 (car bufs))))
|
|
333 (setq nnfolder-buffer-alist
|
|
334 (delq (car bufs) nnfolder-buffer-alist))
|
|
335 (set-buffer (nth 1 (car bufs)))
|
|
336 (nnfolder-save-buffer)
|
|
337 (kill-buffer (current-buffer)))
|
|
338 (setq bufs (cdr bufs))))))
|
|
339 nnfolder-directory
|
|
340 group)))
|
|
341
|
|
342 ;; Don't close the buffer if we're not shutting down the server. This way,
|
|
343 ;; we can keep the buffer in the group buffer cache, and not have to grovel
|
|
344 ;; over the buffer again unless we add new mail to it or modify it in some
|
|
345 ;; way.
|
|
346
|
|
347 (deffoo nnfolder-close-group (group &optional server force)
|
|
348 ;; Make sure we _had_ the group open.
|
|
349 (when (or (assoc group nnfolder-buffer-alist)
|
|
350 (equal group nnfolder-current-group))
|
|
351 (let ((inf (assoc group nnfolder-buffer-alist)))
|
|
352 (when inf
|
|
353 (when (and nnfolder-current-group
|
|
354 nnfolder-current-buffer)
|
|
355 (push (list nnfolder-current-group nnfolder-current-buffer)
|
|
356 nnfolder-buffer-alist))
|
|
357 (setq nnfolder-buffer-alist
|
|
358 (delq inf nnfolder-buffer-alist))
|
|
359 (setq nnfolder-current-buffer (cadr inf)
|
|
360 nnfolder-current-group (car inf))))
|
|
361 (when (and nnfolder-current-buffer
|
|
362 (buffer-name nnfolder-current-buffer))
|
|
363 (save-excursion
|
|
364 (set-buffer nnfolder-current-buffer)
|
|
365 ;; If the buffer was modified, write the file out now.
|
|
366 (nnfolder-save-buffer)
|
|
367 ;; If we're shutting the server down, we need to kill the
|
|
368 ;; buffer and remove it from the open buffer list. Or, of
|
|
369 ;; course, if we're trying to minimize our space impact.
|
|
370 (kill-buffer (current-buffer))
|
|
371 (setq nnfolder-buffer-alist (delq (assoc group nnfolder-buffer-alist)
|
|
372 nnfolder-buffer-alist)))))
|
|
373 (setq nnfolder-current-group nil
|
|
374 nnfolder-current-buffer nil)
|
|
375 t)
|
|
376
|
|
377 (deffoo nnfolder-request-create-group (group &optional server args)
|
|
378 (nnfolder-possibly-change-group nil server)
|
|
379 (nnmail-activate 'nnfolder)
|
85712
|
380 (cond ((zerop (length group))
|
|
381 (nnheader-report 'nnfolder "Invalid (empty) group name"))
|
|
382 ((file-directory-p (nnfolder-group-pathname group))
|
|
383 (nnheader-report 'nnfolder "%s is a directory"
|
|
384 (file-name-as-directory
|
|
385 (let ((nnmail-pathname-coding-system nil))
|
|
386 (nnfolder-group-pathname group)))))
|
|
387 ((assoc group nnfolder-group-alist)
|
|
388 t)
|
|
389 (t
|
|
390 (push (list group (cons 1 0)) nnfolder-group-alist)
|
|
391 (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
|
|
392 (save-current-buffer
|
|
393 (nnfolder-read-folder group))
|
|
394 t)))
|
17493
|
395
|
|
396 (deffoo nnfolder-request-list (&optional server)
|
|
397 (nnfolder-possibly-change-group nil server)
|
|
398 (save-excursion
|
31716
|
399 (let ((nnmail-file-coding-system nnfolder-active-file-coding-system))
|
19597
|
400 (nnmail-find-file nnfolder-active-file)
|
|
401 (setq nnfolder-group-alist (nnmail-get-active)))
|
17493
|
402 t))
|
|
403
|
|
404 (deffoo nnfolder-request-newgroups (date &optional server)
|
|
405 (nnfolder-possibly-change-group nil server)
|
|
406 (nnfolder-request-list server))
|
|
407
|
|
408 (deffoo nnfolder-request-list-newsgroups (&optional server)
|
|
409 (nnfolder-possibly-change-group nil server)
|
|
410 (save-excursion
|
31716
|
411 (let ((nnmail-file-coding-system nnfolder-file-coding-system))
|
|
412 (nnmail-find-file nnfolder-newsgroups-file))))
|
|
413
|
|
414 ;; Return a list consisting of all article numbers existing in the
|
|
415 ;; current folder.
|
|
416
|
|
417 (defun nnfolder-existing-articles ()
|
|
418 (save-excursion
|
|
419 (when nnfolder-current-buffer
|
|
420 (set-buffer nnfolder-current-buffer)
|
|
421 (goto-char (point-min))
|
|
422 (let ((marker (concat "\n" nnfolder-article-marker))
|
|
423 (number "[0-9]+")
|
|
424 numbers)
|
|
425 (while (and (search-forward marker nil t)
|
|
426 (re-search-forward number nil t))
|
|
427 (let ((newnum (string-to-number (match-string 0))))
|
|
428 (if (nnmail-within-headers-p)
|
|
429 (push newnum numbers))))
|
56927
|
430 ;; The article numbers are increasing, so this result is sorted.
|
|
431 (nreverse numbers)))))
|
17493
|
432
|
87234
|
433 (autoload 'gnus-request-group "gnus-int")
|
|
434 (declare-function gnus-request-create-group "gnus-int"
|
|
435 (group &optional gnus-command-method args))
|
|
436
|
85712
|
437 (deffoo nnfolder-request-expire-articles (articles newsgroup
|
|
438 &optional server force)
|
17493
|
439 (nnfolder-possibly-change-group newsgroup server)
|
85712
|
440 (let ((is-old t)
|
|
441 ;; The articles we have deleted so far.
|
|
442 (deleted-articles nil)
|
|
443 ;; The articles that really exist and will
|
|
444 ;; be expired if they are old enough.
|
|
445 (maybe-expirable
|
|
446 (gnus-sorted-intersection articles (nnfolder-existing-articles)))
|
|
447 target)
|
17493
|
448 (nnmail-activate 'nnfolder)
|
|
449
|
|
450 (save-excursion
|
|
451 (set-buffer nnfolder-current-buffer)
|
31716
|
452 ;; Since messages are sorted in arrival order and expired in the
|
|
453 ;; same order, we can stop as soon as we find a message that is
|
|
454 ;; too old.
|
|
455 (while (and maybe-expirable is-old)
|
17493
|
456 (goto-char (point-min))
|
31716
|
457 (when (and (nnfolder-goto-article (car maybe-expirable))
|
|
458 (search-forward (concat "\n" nnfolder-article-marker)
|
|
459 nil t))
|
|
460 (forward-sexp)
|
|
461 (when (setq is-old
|
|
462 (nnmail-expired-article-p
|
|
463 newsgroup
|
|
464 (buffer-substring
|
|
465 (point) (progn (end-of-line) (point)))
|
|
466 force nnfolder-inhibit-expiry))
|
85712
|
467 (setq target nnmail-expiry-target)
|
|
468 (unless (eq target 'delete)
|
47002
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
diff
changeset
|
469 (with-temp-buffer
|
49598
|
470 (nnfolder-request-article (car maybe-expirable)
|
47002
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
diff
changeset
|
471 newsgroup server (current-buffer))
|
56927
|
472 (let ((nnfolder-current-directory nil))
|
85712
|
473 (when (functionp target)
|
|
474 (setq target (funcall target newsgroup)))
|
98470
|
475 (when (and target (not (eq target 'delete)))
|
|
476 (if (or (gnus-request-group target)
|
|
477 (gnus-request-create-group target))
|
|
478 (nnmail-expiry-target-group target newsgroup)
|
|
479 (setq target nil)))))
|
56927
|
480 (nnfolder-possibly-change-group newsgroup server))
|
85712
|
481 (when target
|
|
482 (nnheader-message 5 "Deleting article %d in %s..."
|
|
483 (car maybe-expirable) newsgroup)
|
|
484 (nnfolder-delete-mail)
|
|
485 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
|
|
486 (nnfolder-nov-delete-article newsgroup (car maybe-expirable)))
|
|
487 ;; Must remember which articles were actually deleted
|
|
488 (push (car maybe-expirable) deleted-articles))))
|
31716
|
489 (setq maybe-expirable (cdr maybe-expirable)))
|
17493
|
490 (unless nnfolder-inhibit-expiry
|
|
491 (nnheader-message 5 "Deleting articles...done"))
|
|
492 (nnfolder-save-buffer)
|
|
493 (nnfolder-adjust-min-active newsgroup)
|
31716
|
494 (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
|
56927
|
495 (gnus-sorted-difference articles (nreverse deleted-articles)))))
|
17493
|
496
|
85712
|
497 (deffoo nnfolder-request-move-article (article group server accept-form
|
|
498 &optional last move-is-internal)
|
24357
|
499 (save-excursion
|
|
500 (let ((buf (get-buffer-create " *nnfolder move*"))
|
|
501 result)
|
|
502 (and
|
|
503 (nnfolder-request-article article group server)
|
|
504 (save-excursion
|
|
505 (set-buffer buf)
|
|
506 (erase-buffer)
|
|
507 (insert-buffer-substring nntp-server-buffer)
|
|
508 (goto-char (point-min))
|
|
509 (while (re-search-forward
|
|
510 (concat "^" nnfolder-article-marker)
|
49598
|
511 (save-excursion (and (search-forward "\n\n" nil t) (point)))
|
31716
|
512 t)
|
56927
|
513 (gnus-delete-line))
|
24357
|
514 (setq result (eval accept-form))
|
|
515 (kill-buffer buf)
|
|
516 result)
|
|
517 (save-excursion
|
|
518 (nnfolder-possibly-change-group group server)
|
|
519 (set-buffer nnfolder-current-buffer)
|
|
520 (goto-char (point-min))
|
|
521 (when (nnfolder-goto-article article)
|
|
522 (nnfolder-delete-mail))
|
56927
|
523 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
|
|
524 (nnfolder-nov-delete-article group article))
|
24357
|
525 (when last
|
|
526 (nnfolder-save-buffer)
|
|
527 (nnfolder-adjust-min-active group)
|
31716
|
528 (nnfolder-save-active nnfolder-group-alist nnfolder-active-file))))
|
24357
|
529 result)))
|
17493
|
530
|
|
531 (deffoo nnfolder-request-accept-article (group &optional server last)
|
24357
|
532 (save-excursion
|
|
533 (nnfolder-possibly-change-group group server)
|
|
534 (nnmail-check-syntax)
|
|
535 (let ((buf (current-buffer))
|
|
536 result art-group)
|
|
537 (goto-char (point-min))
|
|
538 (when (looking-at "X-From-Line: ")
|
49993
|
539 (replace-match "From ")
|
|
540 (while (progn (forward-line) (looking-at "[ \t]"))
|
|
541 (delete-char -1)))
|
56927
|
542 (with-temp-buffer
|
|
543 (let ((nnmail-file-coding-system nnfolder-active-file-coding-system)
|
|
544 (nntp-server-buffer (current-buffer)))
|
|
545 (nnmail-find-file nnfolder-active-file)
|
|
546 (setq nnfolder-group-alist (nnmail-parse-active))))
|
|
547 (save-excursion
|
|
548 (goto-char (point-min))
|
|
549 (if (search-forward "\n\n" nil t)
|
|
550 (forward-line -1)
|
|
551 (goto-char (point-max)))
|
|
552 (while (re-search-backward (concat "^" nnfolder-article-marker) nil t)
|
|
553 (delete-region (point) (progn (forward-line 1) (point))))
|
|
554 (when nnmail-cache-accepted-message-ids
|
|
555 (nnmail-cache-insert (nnmail-fetch-field "message-id")
|
|
556 group
|
|
557 (nnmail-fetch-field "subject")
|
|
558 (nnmail-fetch-field "from")))
|
|
559 (setq result (if (stringp group)
|
|
560 (list (cons group (nnfolder-active-number group)))
|
|
561 (setq art-group
|
|
562 (nnmail-article-group 'nnfolder-active-number))))
|
|
563 (if (and (null result)
|
|
564 (yes-or-no-p "Moved to `junk' group; delete article? "))
|
|
565 (setq result 'junk)
|
|
566 (setq result
|
|
567 (car (nnfolder-save-mail result)))))
|
|
568 (when last
|
|
569 (save-excursion
|
|
570 (nnfolder-possibly-change-folder (or (caar art-group) group))
|
|
571 (nnfolder-save-buffer)
|
|
572 (when nnmail-cache-accepted-message-ids
|
|
573 (nnmail-cache-close))))
|
31716
|
574 (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
|
24357
|
575 (unless result
|
|
576 (nnheader-report 'nnfolder "Couldn't store article"))
|
|
577 result)))
|
17493
|
578
|
|
579 (deffoo nnfolder-request-replace-article (article group buffer)
|
|
580 (nnfolder-possibly-change-group group)
|
|
581 (save-excursion
|
24357
|
582 (set-buffer buffer)
|
|
583 (goto-char (point-min))
|
56927
|
584 (if (not (looking-at "X-From-Line: "))
|
|
585 (insert "From nobody " (current-time-string) "\n")
|
|
586 (replace-match "From ")
|
|
587 (forward-line 1)
|
|
588 (while (looking-at "[ \t]")
|
|
589 (delete-char -1)
|
|
590 (forward-line 1)))
|
24357
|
591 (nnfolder-normalize-buffer)
|
17493
|
592 (set-buffer nnfolder-current-buffer)
|
|
593 (goto-char (point-min))
|
24357
|
594 (if (not (nnfolder-goto-article article))
|
17493
|
595 nil
|
24357
|
596 (nnfolder-delete-mail)
|
17493
|
597 (insert-buffer-substring buffer)
|
56927
|
598 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
|
|
599 (save-excursion
|
|
600 (set-buffer buffer)
|
|
601 (let ((headers (nnfolder-parse-head article
|
|
602 (point-min) (point-max))))
|
|
603 (with-current-buffer (nnfolder-open-nov group)
|
|
604 (if (nnheader-find-nov-line article)
|
|
605 (delete-region (point) (progn (forward-line 1) (point))))
|
|
606 (nnheader-insert-nov headers)))))
|
17493
|
607 (nnfolder-save-buffer)
|
|
608 t)))
|
|
609
|
|
610 (deffoo nnfolder-request-delete-group (group &optional force server)
|
|
611 (nnfolder-close-group group server t)
|
|
612 ;; Delete all articles in GROUP.
|
|
613 (if (not force)
|
|
614 () ; Don't delete the articles.
|
|
615 ;; Delete the file that holds the group.
|
56927
|
616 (let ((data (nnfolder-group-pathname group))
|
|
617 (nov (nnfolder-group-nov-pathname group))
|
|
618 (mrk (nnfolder-group-marks-pathname group)))
|
|
619 (ignore-errors (delete-file data))
|
|
620 (ignore-errors (delete-file nov))
|
|
621 (ignore-errors (delete-file mrk))))
|
17493
|
622 ;; Remove the group from all structures.
|
|
623 (setq nnfolder-group-alist
|
|
624 (delq (assoc group nnfolder-group-alist) nnfolder-group-alist)
|
|
625 nnfolder-current-group nil
|
|
626 nnfolder-current-buffer nil)
|
|
627 ;; Save the active file.
|
31716
|
628 (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
|
17493
|
629 t)
|
|
630
|
|
631 (deffoo nnfolder-request-rename-group (group new-name &optional server)
|
|
632 (nnfolder-possibly-change-group group server)
|
|
633 (save-excursion
|
|
634 (set-buffer nnfolder-current-buffer)
|
|
635 (and (file-writable-p buffer-file-name)
|
|
636 (ignore-errors
|
56927
|
637 (let ((new-file (nnfolder-group-pathname new-name)))
|
|
638 (gnus-make-directory (file-name-directory new-file))
|
|
639 (rename-file buffer-file-name new-file)
|
|
640 (when (file-exists-p (nnfolder-group-nov-pathname group))
|
|
641 (setq new-file (nnfolder-group-nov-pathname new-name))
|
|
642 (gnus-make-directory (file-name-directory new-file))
|
|
643 (rename-file (nnfolder-group-nov-pathname group) new-file))
|
|
644 (when (file-exists-p (nnfolder-group-marks-pathname group))
|
|
645 (setq new-file (nnfolder-group-marks-pathname new-name))
|
|
646 (gnus-make-directory (file-name-directory new-file))
|
|
647 (rename-file (nnfolder-group-marks-pathname group) new-file)))
|
17493
|
648 t)
|
|
649 ;; That went ok, so we change the internal structures.
|
|
650 (let ((entry (assoc group nnfolder-group-alist)))
|
|
651 (and entry (setcar entry new-name))
|
|
652 (setq nnfolder-current-buffer nil
|
|
653 nnfolder-current-group nil)
|
|
654 ;; Save the new group alist.
|
31716
|
655 (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
|
17493
|
656 ;; We kill the buffer instead of renaming it and stuff.
|
|
657 (kill-buffer (current-buffer))
|
|
658 t))))
|
|
659
|
56927
|
660 (deffoo nnfolder-request-regenerate (server)
|
19969
|
661 (nnfolder-possibly-change-group nil server)
|
|
662 (nnfolder-generate-active-file)
|
|
663 t)
|
|
664
|
17493
|
665
|
|
666 ;;; Internal functions.
|
|
667
|
|
668 (defun nnfolder-adjust-min-active (group)
|
|
669 ;; Find the lowest active article in this group.
|
|
670 (let* ((active (cadr (assoc group nnfolder-group-alist)))
|
|
671 (marker (concat "\n" nnfolder-article-marker))
|
|
672 (number "[0-9]+")
|
|
673 (activemin (cdr active)))
|
|
674 (save-excursion
|
|
675 (set-buffer nnfolder-current-buffer)
|
|
676 (goto-char (point-min))
|
|
677 (while (and (search-forward marker nil t)
|
|
678 (re-search-forward number nil t))
|
24357
|
679 (let ((newnum (string-to-number (match-string 0))))
|
|
680 (if (nnmail-within-headers-p)
|
|
681 (setq activemin (min activemin newnum)))))
|
17493
|
682 (setcar active activemin))))
|
|
683
|
|
684 (defun nnfolder-article-string (article)
|
|
685 (if (numberp article)
|
|
686 (concat "\n" nnfolder-article-marker (int-to-string article) " ")
|
|
687 (concat "\nMessage-ID: " article)))
|
|
688
|
24357
|
689 (defun nnfolder-goto-article (article)
|
|
690 "Place point at the start of the headers of ARTICLE.
|
|
691 ARTICLE can be an article number or a Message-ID.
|
|
692 Returns t if successful, nil otherwise."
|
|
693 (let ((art-string (nnfolder-article-string article))
|
|
694 start found)
|
|
695 ;; It is likely that we are at or before the delimiter line.
|
|
696 ;; We therefore go to the end of the previous line, and start
|
|
697 ;; searching from there.
|
|
698 (beginning-of-line)
|
|
699 (unless (bobp)
|
|
700 (forward-char -1))
|
|
701 (setq start (point))
|
|
702 ;; First search forward.
|
|
703 (while (and (setq found (search-forward art-string nil t))
|
|
704 (not (nnmail-within-headers-p))))
|
|
705 ;; If unsuccessful, search backward from where we started,
|
|
706 (unless found
|
|
707 (goto-char start)
|
|
708 (while (and (setq found (search-backward art-string nil t))
|
|
709 (not (nnmail-within-headers-p)))))
|
|
710 (when found
|
|
711 (nnmail-search-unix-mail-delim-backward))))
|
|
712
|
|
713 (defun nnfolder-delete-mail (&optional leave-delim)
|
|
714 "Delete the message that point is in.
|
|
715 If optional argument LEAVE-DELIM is t, then mailbox delimiter is not
|
|
716 deleted. Point is left where the deleted region was."
|
31716
|
717 (save-restriction
|
|
718 (narrow-to-region
|
|
719 (save-excursion
|
|
720 ;; In case point is at the beginning of the message already.
|
|
721 (forward-line 1)
|
|
722 (nnmail-search-unix-mail-delim-backward)
|
|
723 (if leave-delim (progn (forward-line 1) (point))
|
|
724 (point)))
|
|
725 (progn
|
|
726 (forward-line 1)
|
|
727 (if (nnmail-search-unix-mail-delim)
|
|
728 (point)
|
|
729 (point-max))))
|
|
730 (run-hooks 'nnfolder-delete-mail-hook)
|
|
731 (delete-region (point-min) (point-max))))
|
17493
|
732
|
|
733 (defun nnfolder-possibly-change-group (group &optional server dont-check)
|
|
734 ;; Change servers.
|
|
735 (when (and server
|
|
736 (not (nnfolder-server-opened server)))
|
|
737 (nnfolder-open-server server))
|
|
738 (unless (gnus-buffer-live-p nnfolder-current-buffer)
|
|
739 (setq nnfolder-current-buffer nil
|
|
740 nnfolder-current-group nil))
|
|
741 ;; Change group.
|
56927
|
742 (let ((file-name-coding-system nnmail-pathname-coding-system))
|
|
743 (when (and group
|
|
744 (not (equal group nnfolder-current-group))
|
|
745 (progn
|
|
746 (nnmail-activate 'nnfolder)
|
|
747 (and (assoc group nnfolder-group-alist)
|
|
748 (file-exists-p (nnfolder-group-pathname group)))))
|
19597
|
749 (if dont-check
|
19969
|
750 (setq nnfolder-current-group group
|
|
751 nnfolder-current-buffer nil)
|
19597
|
752 (let (inf file)
|
56927
|
753 ;; If we have to change groups, see if we don't already have
|
|
754 ;; the folder in memory. If we do, verify the modtime and
|
|
755 ;; destroy the folder if needed so we can rescan it.
|
19969
|
756 (setq nnfolder-current-buffer
|
|
757 (nth 1 (assoc group nnfolder-buffer-alist)))
|
|
758
|
56927
|
759 ;; If the buffer is not live, make sure it isn't in the
|
|
760 ;; alist. If it is live, verify that nobody else has
|
|
761 ;; touched the file since last time.
|
19597
|
762 (when (and nnfolder-current-buffer
|
|
763 (not (gnus-buffer-live-p nnfolder-current-buffer)))
|
|
764 (setq nnfolder-buffer-alist (delq inf nnfolder-buffer-alist)
|
|
765 nnfolder-current-buffer nil))
|
19969
|
766
|
19597
|
767 (setq nnfolder-current-group group)
|
19969
|
768
|
19597
|
769 (when (or (not nnfolder-current-buffer)
|
24357
|
770 (not (verify-visited-file-modtime
|
|
771 nnfolder-current-buffer)))
|
19597
|
772 (save-excursion
|
|
773 (setq file (nnfolder-group-pathname group))
|
|
774 ;; See whether we need to create the new file.
|
|
775 (unless (file-exists-p file)
|
|
776 (gnus-make-directory (file-name-directory file))
|
49598
|
777 (let ((nnmail-file-coding-system
|
31716
|
778 (or nnfolder-file-coding-system-for-write
|
|
779 nnfolder-file-coding-system-for-write)))
|
44513
ce14b691fc8b
(nnfolder-possibly-change-group): Don't assume point-min == 1.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
780 (nnmail-write-region (point-min) (point-min)
|
ce14b691fc8b
(nnfolder-possibly-change-group): Don't assume point-min == 1.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
781 file t 'nomesg)))
|
19597
|
782 (when (setq nnfolder-current-buffer (nnfolder-read-folder group))
|
|
783 (set-buffer nnfolder-current-buffer)
|
|
784 (push (list group nnfolder-current-buffer)
|
|
785 nnfolder-buffer-alist)))))))))
|
17493
|
786
|
|
787 (defun nnfolder-save-mail (group-art-list)
|
|
788 "Called narrowed to an article."
|
|
789 (let* (save-list group-art)
|
|
790 (goto-char (point-min))
|
|
791 ;; The From line may have been quoted by movemail.
|
31716
|
792 (when (looking-at ">From")
|
17493
|
793 (delete-char 1))
|
|
794 ;; This might come from somewhere else.
|
31716
|
795 (unless (looking-at "From ")
|
17493
|
796 (insert "From nobody " (current-time-string) "\n")
|
|
797 (goto-char (point-min)))
|
31716
|
798 ;; Quote all "From " lines in the article.
|
24357
|
799 (forward-line 1)
|
17493
|
800 (let (case-fold-search)
|
|
801 (while (re-search-forward "^From " nil t)
|
|
802 (beginning-of-line)
|
|
803 (insert "> ")))
|
|
804 (setq save-list group-art-list)
|
|
805 (nnmail-insert-lines)
|
|
806 (nnmail-insert-xref group-art-list)
|
|
807 (run-hooks 'nnmail-prepare-save-mail-hook)
|
|
808 (run-hooks 'nnfolder-prepare-save-mail-hook)
|
|
809
|
|
810 ;; Insert the mail into each of the destination groups.
|
|
811 (while (setq group-art (pop group-art-list))
|
|
812 ;; Kill any previous newsgroup markers.
|
|
813 (goto-char (point-min))
|
31716
|
814 (if (search-forward "\n\n" nil t)
|
|
815 (forward-line -1)
|
|
816 (goto-char (point-max)))
|
17493
|
817 (while (search-backward (concat "\n" nnfolder-article-marker) nil t)
|
|
818 (delete-region (1+ (point)) (progn (forward-line 2) (point))))
|
|
819
|
|
820 ;; Insert the new newsgroup marker.
|
|
821 (nnfolder-insert-newsgroup-line group-art)
|
|
822
|
|
823 (save-excursion
|
|
824 (let ((beg (point-min))
|
|
825 (end (point-max))
|
|
826 (obuf (current-buffer)))
|
|
827 (nnfolder-possibly-change-folder (car group-art))
|
|
828 (let ((buffer-read-only nil))
|
24357
|
829 (nnfolder-normalize-buffer)
|
56927
|
830 (insert-buffer-substring obuf beg end))
|
|
831 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
|
|
832 (set-buffer obuf)
|
|
833 (nnfolder-add-nov (car group-art) (cdr group-art)
|
|
834 (nnfolder-parse-head nil beg end))))))
|
17493
|
835
|
|
836 ;; Did we save it anywhere?
|
|
837 save-list))
|
|
838
|
24357
|
839 (defun nnfolder-normalize-buffer ()
|
|
840 "Make sure there are two newlines at the end of the buffer."
|
|
841 (goto-char (point-max))
|
|
842 (skip-chars-backward "\n")
|
|
843 (delete-region (point) (point-max))
|
56927
|
844 (unless (bobp)
|
|
845 (insert "\n\n")))
|
24357
|
846
|
17493
|
847 (defun nnfolder-insert-newsgroup-line (group-art)
|
|
848 (save-excursion
|
|
849 (goto-char (point-min))
|
31716
|
850 (unless (search-forward "\n\n" nil t)
|
|
851 (goto-char (point-max))
|
|
852 (insert "\n"))
|
|
853 (forward-char -1)
|
|
854 (insert (format (concat nnfolder-article-marker "%d %s\n")
|
68762
|
855 (cdr group-art) (message-make-date)))))
|
17493
|
856
|
|
857 (defun nnfolder-active-number (group)
|
|
858 ;; Find the next article number in GROUP.
|
|
859 (let ((active (cadr (assoc group nnfolder-group-alist))))
|
|
860 (if active
|
|
861 (setcdr active (1+ (cdr active)))
|
|
862 ;; This group is new, so we create a new entry for it.
|
|
863 ;; This might be a bit naughty... creating groups on the drop of
|
|
864 ;; a hat, but I don't know...
|
|
865 (push (list group (setq active (cons 1 1)))
|
|
866 nnfolder-group-alist))
|
|
867 (cdr active)))
|
|
868
|
|
869 (defun nnfolder-possibly-change-folder (group)
|
|
870 (let ((inf (assoc group nnfolder-buffer-alist)))
|
|
871 (if (and inf
|
|
872 (gnus-buffer-live-p (cadr inf)))
|
|
873 (set-buffer (cadr inf))
|
|
874 (when inf
|
|
875 (setq nnfolder-buffer-alist (delq inf nnfolder-buffer-alist)))
|
|
876 (when nnfolder-group-alist
|
31716
|
877 (nnfolder-save-active nnfolder-group-alist nnfolder-active-file))
|
17493
|
878 (push (list group (nnfolder-read-folder group))
|
|
879 nnfolder-buffer-alist))))
|
|
880
|
56927
|
881 ;; This method has a problem if you've accidentally let the active
|
|
882 ;; list get out of sync with the files. This could happen, say, if
|
|
883 ;; you've accidentally gotten new mail with something other than Gnus
|
|
884 ;; (but why would _that_ ever happen? :-). In that case, we will be
|
|
885 ;; in the middle of processing the file, ready to add new X-Gnus
|
|
886 ;; article number markers, and we'll run across a message with no ID
|
|
887 ;; yet - the active list _may_not_ be ready for us yet.
|
17493
|
888
|
56927
|
889 ;; To handle this, I'm modifying this routine to maintain the maximum
|
|
890 ;; ID seen so far, and when we hit a message with no ID, we will
|
|
891 ;; _manually_ scan the rest of the message looking for any more,
|
|
892 ;; possibly higher IDs. We'll assume the maximum that we find is the
|
|
893 ;; highest active. Note that this shouldn't cost us much extra time
|
|
894 ;; at all, but will be a lot less vulnerable to glitches between the
|
|
895 ;; mbox and the active file.
|
17493
|
896
|
|
897 (defun nnfolder-read-folder (group)
|
|
898 (let* ((file (nnfolder-group-pathname group))
|
56927
|
899 (nov (nnfolder-group-nov-pathname group))
|
31716
|
900 (buffer (set-buffer
|
49598
|
901 (let ((nnheader-file-coding-system
|
31716
|
902 nnfolder-file-coding-system))
|
60239
|
903 (nnheader-find-file-noselect file t)))))
|
38382
|
904 (mm-enable-multibyte) ;; Use multibyte buffer for future copying.
|
62989
62869b151347
(nnfolder-read-folder): Make sure that undo information is never recorded.
Lute Kamstra <lute@gnu.org>
diff
changeset
|
905 (buffer-disable-undo)
|
17493
|
906 (if (equal (cadr (assoc group nnfolder-scantime-alist))
|
|
907 (nth 5 (file-attributes file)))
|
|
908 ;; This looks up-to-date, so we don't do any scanning.
|
24357
|
909 (if (file-exists-p file)
|
|
910 buffer
|
|
911 (push (list group buffer) nnfolder-buffer-alist)
|
|
912 (set-buffer-modified-p t)
|
31716
|
913 (nnfolder-save-buffer))
|
17493
|
914 ;; Parse the damn thing.
|
|
915 (save-excursion
|
31716
|
916 (goto-char (point-min))
|
|
917 ;; Remove any blank lines at the start.
|
|
918 (while (eq (following-char) ?\n)
|
|
919 (delete-char 1))
|
17493
|
920 (nnmail-activate 'nnfolder)
|
|
921 ;; Read in the file.
|
31716
|
922 (let ((delim "^From ")
|
17493
|
923 (marker (concat "\n" nnfolder-article-marker))
|
|
924 (number "[0-9]+")
|
|
925 (active (or (cadr (assoc group nnfolder-group-alist))
|
|
926 (cons 1 0)))
|
|
927 (scantime (assoc group nnfolder-scantime-alist))
|
101165
|
928 (minid (or (and (boundp 'most-positive-fixnum)
|
|
929 most-positive-fixnum)
|
|
930 (lsh -1 -1)))
|
17493
|
931 maxid start end newscantime
|
56927
|
932 novbuf articles newnum
|
17493
|
933 buffer-read-only)
|
|
934 (setq maxid (cdr active))
|
56927
|
935
|
|
936 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil
|
|
937 (and (file-exists-p nov)
|
|
938 (file-newer-than-file-p nov file)))
|
|
939 (unless (file-exists-p nov)
|
|
940 (gnus-make-directory (file-name-directory nov)))
|
|
941 (with-current-buffer
|
|
942 (setq novbuf (nnfolder-open-nov group))
|
|
943 (goto-char (point-min))
|
|
944 (while (not (eobp))
|
|
945 (push (read novbuf) articles)
|
|
946 (forward-line 1))
|
|
947 (setq articles (nreverse articles))))
|
17493
|
948 (goto-char (point-min))
|
|
949
|
56927
|
950 ;; Anytime the active number is 1 or 0, it is suspect. In
|
|
951 ;; that case, search the file manually to find the active
|
|
952 ;; number. Or, of course, if we're being paranoid. (This
|
|
953 ;; would also be the place to build other lists from the
|
|
954 ;; header markers, such as expunge lists, etc., if we ever
|
|
955 ;; desired to abandon the active file entirely for mboxes.)
|
17493
|
956 (when (or nnfolder-ignore-active-file
|
56927
|
957 novbuf
|
17493
|
958 (< maxid 2))
|
|
959 (while (and (search-forward marker nil t)
|
56927
|
960 (looking-at number))
|
|
961 (setq newnum (string-to-number (match-string 0)))
|
|
962 (when (nnmail-within-headers-p)
|
|
963 (setq maxid (max maxid newnum)
|
|
964 minid (min minid newnum))
|
|
965 (when novbuf
|
|
966 (if (memq newnum articles)
|
|
967 (setq articles (delq newnum articles))
|
|
968 (let ((headers (nnfolder-parse-head newnum)))
|
|
969 (with-current-buffer novbuf
|
|
970 (nnheader-find-nov-line newnum)
|
|
971 (nnheader-insert-nov headers)))))))
|
|
972 (when (and novbuf articles)
|
|
973 (with-current-buffer novbuf
|
|
974 (dolist (article articles)
|
|
975 (when (nnheader-find-nov-line article)
|
|
976 (delete-region (point)
|
|
977 (progn (forward-line 1) (point)))))))
|
17493
|
978 (setcar active (max 1 (min minid maxid)))
|
|
979 (setcdr active (max maxid (cdr active)))
|
|
980 (goto-char (point-min)))
|
|
981
|
56927
|
982 ;; As long as we trust that the user will only insert
|
|
983 ;; unmarked mail at the end, go to the end and search
|
|
984 ;; backwards for the last marker. Find the start of that
|
|
985 ;; message, and begin to search for unmarked messages from
|
|
986 ;; there.
|
17493
|
987 (when (not (or nnfolder-distrust-mbox
|
|
988 (< maxid 2)))
|
|
989 (goto-char (point-max))
|
|
990 (unless (re-search-backward marker nil t)
|
|
991 (goto-char (point-min)))
|
56927
|
992 ;;(when (nnmail-search-unix-mail-delim)
|
|
993 ;; (goto-char (point-min)))
|
|
994 )
|
17493
|
995
|
56927
|
996 ;; Keep track of the active number on our own, and insert it
|
|
997 ;; back into the active list when we're done. Also, prime
|
|
998 ;; the pump to cut down on the number of searches we do.
|
17493
|
999 (unless (nnmail-search-unix-mail-delim)
|
|
1000 (goto-char (point-max)))
|
|
1001 (setq end (point-marker))
|
|
1002 (while (not (= end (point-max)))
|
|
1003 (setq start (marker-position end))
|
|
1004 (goto-char end)
|
56927
|
1005 ;; There may be more than one "From " line, so we skip past
|
17493
|
1006 ;; them.
|
|
1007 (while (looking-at delim)
|
|
1008 (forward-line 1))
|
|
1009 (set-marker end (if (nnmail-search-unix-mail-delim)
|
|
1010 (point)
|
|
1011 (point-max)))
|
|
1012 (goto-char start)
|
|
1013 (when (not (search-forward marker end t))
|
|
1014 (narrow-to-region start end)
|
|
1015 (nnmail-insert-lines)
|
|
1016 (nnfolder-insert-newsgroup-line
|
56927
|
1017 (cons nil
|
|
1018 (setq newnum
|
|
1019 (nnfolder-active-number group))))
|
|
1020 (when novbuf
|
|
1021 (let ((headers (nnfolder-parse-head newnum (point-min)
|
|
1022 (point-max))))
|
|
1023 (with-current-buffer novbuf
|
|
1024 (goto-char (point-max))
|
|
1025 (nnheader-insert-nov headers))))
|
17493
|
1026 (widen)))
|
|
1027
|
|
1028 (set-marker end nil)
|
56927
|
1029 ;; Make absolutely sure that the active list reflects
|
|
1030 ;; reality!
|
31716
|
1031 (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
|
56927
|
1032
|
17493
|
1033 ;; Set the scantime for this group.
|
|
1034 (setq newscantime (visited-file-modtime))
|
|
1035 (if scantime
|
|
1036 (setcdr scantime (list newscantime))
|
56927
|
1037 (push (list group newscantime)
|
17493
|
1038 nnfolder-scantime-alist))
|
56927
|
1039 ;; Save nov.
|
|
1040 (when novbuf
|
|
1041 (nnfolder-save-nov))
|
17493
|
1042 (current-buffer))))))
|
|
1043
|
|
1044 ;;;###autoload
|
|
1045 (defun nnfolder-generate-active-file ()
|
31716
|
1046 "Look for mbox folders in the nnfolder directory and make them into groups.
|
|
1047 This command does not work if you use short group names."
|
17493
|
1048 (interactive)
|
|
1049 (nnmail-activate 'nnfolder)
|
56927
|
1050 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
|
|
1051 (dolist (file (directory-files (or nnfolder-nov-directory
|
|
1052 nnfolder-directory)
|
|
1053 t
|
|
1054 (concat
|
|
1055 (regexp-quote nnfolder-nov-file-suffix)
|
|
1056 "$")))
|
|
1057 (when (not (message-mail-file-mbox-p file))
|
|
1058 (ignore-errors
|
|
1059 (delete-file file)))))
|
85712
|
1060 (dolist (file (directory-files nnfolder-directory))
|
17493
|
1061 (when (and (not (backup-file-name-p file))
|
56927
|
1062 (message-mail-file-mbox-p
|
17493
|
1063 (nnheader-concat nnfolder-directory file)))
|
56927
|
1064 (let ((oldgroup (assoc file nnfolder-group-alist)))
|
|
1065 (if oldgroup
|
|
1066 (nnheader-message 5 "Refreshing group %s..." file)
|
|
1067 (nnheader-message 5 "Adding group %s..." file))
|
19495
|
1068 (if oldgroup
|
|
1069 (setq nnfolder-group-alist
|
|
1070 (delq oldgroup (copy-sequence nnfolder-group-alist))))
|
56927
|
1071 (push (list file (cons 1 0)) nnfolder-group-alist)
|
|
1072 (nnfolder-possibly-change-folder file)
|
|
1073 (nnfolder-possibly-change-group file)
|
|
1074 (nnfolder-close-group file))))
|
85712
|
1075 (nnheader-message 5 ""))
|
17493
|
1076
|
|
1077 (defun nnfolder-group-pathname (group)
|
49274
|
1078 "Make file name for GROUP."
|
31716
|
1079 (setq group
|
|
1080 (mm-encode-coding-string group nnmail-pathname-coding-system))
|
17493
|
1081 (let ((dir (file-name-as-directory (expand-file-name nnfolder-directory))))
|
|
1082 ;; If this file exists, we use it directly.
|
|
1083 (if (or nnmail-use-long-file-names
|
|
1084 (file-exists-p (concat dir group)))
|
|
1085 (concat dir group)
|
|
1086 ;; If not, we translate dots into slashes.
|
|
1087 (concat dir (nnheader-replace-chars-in-string group ?. ?/)))))
|
|
1088
|
56927
|
1089 (defun nnfolder-group-nov-pathname (group)
|
|
1090 "Make pathname for GROUP NOV."
|
|
1091 (let ((nnfolder-directory
|
|
1092 (or nnfolder-nov-directory nnfolder-directory)))
|
|
1093 (concat (nnfolder-group-pathname group) nnfolder-nov-file-suffix)))
|
|
1094
|
17493
|
1095 (defun nnfolder-save-buffer ()
|
|
1096 "Save the buffer."
|
|
1097 (when (buffer-modified-p)
|
|
1098 (run-hooks 'nnfolder-save-buffer-hook)
|
19969
|
1099 (gnus-make-directory (file-name-directory (buffer-file-name)))
|
49598
|
1100 (let ((coding-system-for-write
|
31716
|
1101 (or nnfolder-file-coding-system-for-write
|
85712
|
1102 nnfolder-file-coding-system))
|
|
1103 (copyright-update nil))
|
56927
|
1104 (save-buffer)))
|
|
1105 (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
|
|
1106 (nnfolder-save-nov)))
|
31716
|
1107
|
|
1108 (defun nnfolder-save-active (group-alist active-file)
|
|
1109 (let ((nnmail-active-file-coding-system
|
|
1110 (or nnfolder-active-file-coding-system-for-write
|
|
1111 nnfolder-active-file-coding-system)))
|
|
1112 (nnmail-save-active group-alist active-file)))
|
17493
|
1113
|
56927
|
1114 (defun nnfolder-open-nov (group)
|
|
1115 (or (cdr (assoc group nnfolder-nov-buffer-alist))
|
|
1116 (let ((buffer (get-buffer-create (format " *nnfolder overview %s*" group))))
|
|
1117 (save-excursion
|
|
1118 (set-buffer buffer)
|
|
1119 (set (make-local-variable 'nnfolder-nov-buffer-file-name)
|
|
1120 (nnfolder-group-nov-pathname group))
|
|
1121 (erase-buffer)
|
|
1122 (when (file-exists-p nnfolder-nov-buffer-file-name)
|
|
1123 (nnheader-insert-file-contents nnfolder-nov-buffer-file-name)))
|
|
1124 (push (cons group buffer) nnfolder-nov-buffer-alist)
|
|
1125 buffer)))
|
|
1126
|
|
1127 (defun nnfolder-save-nov ()
|
|
1128 (save-excursion
|
|
1129 (while nnfolder-nov-buffer-alist
|
|
1130 (when (buffer-name (cdar nnfolder-nov-buffer-alist))
|
|
1131 (set-buffer (cdar nnfolder-nov-buffer-alist))
|
|
1132 (when (buffer-modified-p)
|
|
1133 (gnus-make-directory (file-name-directory
|
|
1134 nnfolder-nov-buffer-file-name))
|
|
1135 (nnmail-write-region 1 (point-max) nnfolder-nov-buffer-file-name
|
|
1136 nil 'nomesg))
|
|
1137 (set-buffer-modified-p nil)
|
|
1138 (kill-buffer (current-buffer)))
|
|
1139 (setq nnfolder-nov-buffer-alist (cdr nnfolder-nov-buffer-alist)))))
|
|
1140
|
|
1141 (defun nnfolder-nov-delete-article (group article)
|
|
1142 (save-excursion
|
|
1143 (set-buffer (nnfolder-open-nov group))
|
|
1144 (when (nnheader-find-nov-line article)
|
|
1145 (delete-region (point) (progn (forward-line 1) (point))))
|
|
1146 t))
|
|
1147
|
|
1148 (defun nnfolder-retrieve-headers-with-nov (articles &optional fetch-old)
|
|
1149 (if (or gnus-nov-is-evil nnfolder-nov-is-evil)
|
|
1150 nil
|
|
1151 (let ((nov (nnfolder-group-nov-pathname nnfolder-current-group)))
|
|
1152 (when (file-exists-p nov)
|
|
1153 (save-excursion
|
|
1154 (set-buffer nntp-server-buffer)
|
|
1155 (erase-buffer)
|
|
1156 (nnheader-insert-file-contents nov)
|
|
1157 (if (and fetch-old
|
|
1158 (not (numberp fetch-old)))
|
|
1159 t ; Don't remove anything.
|
|
1160 (nnheader-nov-delete-outside-range
|
|
1161 (if fetch-old (max 1 (- (car articles) fetch-old))
|
|
1162 (car articles))
|
|
1163 (car (last articles)))
|
|
1164 t))))))
|
|
1165
|
|
1166 (defun nnfolder-parse-head (&optional number b e)
|
|
1167 "Parse the head of the current buffer."
|
|
1168 (let ((buf (current-buffer))
|
|
1169 chars)
|
|
1170 (save-excursion
|
|
1171 (unless b
|
|
1172 (setq b (if (nnmail-search-unix-mail-delim-backward)
|
|
1173 (point) (point-min)))
|
|
1174 (forward-line 1)
|
|
1175 (setq e (if (nnmail-search-unix-mail-delim)
|
|
1176 (point) (point-max))))
|
|
1177 (setq chars (- e b))
|
|
1178 (unless (zerop chars)
|
|
1179 (goto-char b)
|
|
1180 (if (search-forward "\n\n" e t) (setq e (1- (point)))))
|
|
1181 (with-temp-buffer
|
|
1182 (insert-buffer-substring buf b e)
|
|
1183 (let ((headers (nnheader-parse-naked-head)))
|
|
1184 (mail-header-set-chars headers chars)
|
|
1185 (mail-header-set-number headers number)
|
|
1186 headers)))))
|
|
1187
|
|
1188 (defun nnfolder-add-nov (group article headers)
|
|
1189 "Add a nov line for the GROUP base."
|
|
1190 (save-excursion
|
|
1191 (set-buffer (nnfolder-open-nov group))
|
|
1192 (goto-char (point-max))
|
|
1193 (mail-header-set-number headers article)
|
|
1194 (nnheader-insert-nov headers)))
|
|
1195
|
|
1196 (deffoo nnfolder-request-set-mark (group actions &optional server)
|
|
1197 (when (and server
|
|
1198 (not (nnfolder-server-opened server)))
|
|
1199 (nnfolder-open-server server))
|
|
1200 (unless nnfolder-marks-is-evil
|
|
1201 (nnfolder-open-marks group server)
|
|
1202 (dolist (action actions)
|
|
1203 (let ((range (nth 0 action))
|
|
1204 (what (nth 1 action))
|
|
1205 (marks (nth 2 action)))
|
57265
|
1206 (assert (or (eq what 'add) (eq what 'del)) nil
|
56927
|
1207 "Unknown request-set-mark action: %s" what)
|
|
1208 (dolist (mark marks)
|
|
1209 (setq nnfolder-marks (gnus-update-alist-soft
|
|
1210 mark
|
|
1211 (funcall (if (eq what 'add) 'gnus-range-add
|
|
1212 'gnus-remove-from-range)
|
|
1213 (cdr (assoc mark nnfolder-marks)) range)
|
|
1214 nnfolder-marks)))))
|
|
1215 (nnfolder-save-marks group server))
|
|
1216 nil)
|
|
1217
|
|
1218 (deffoo nnfolder-request-update-info (group info &optional server)
|
|
1219 ;; Change servers.
|
|
1220 (when (and server
|
|
1221 (not (nnfolder-server-opened server)))
|
|
1222 (nnfolder-open-server server))
|
|
1223 (when (and (not nnfolder-marks-is-evil) (nnfolder-marks-changed-p group))
|
|
1224 (nnheader-message 8 "Updating marks for %s..." group)
|
|
1225 (nnfolder-open-marks group server)
|
|
1226 ;; Update info using `nnfolder-marks'.
|
85712
|
1227 (mapc (lambda (pred)
|
|
1228 (unless (memq (cdr pred) gnus-article-unpropagated-mark-lists)
|
|
1229 (gnus-info-set-marks
|
|
1230 info
|
|
1231 (gnus-update-alist-soft
|
|
1232 (cdr pred)
|
|
1233 (cdr (assq (cdr pred) nnfolder-marks))
|
|
1234 (gnus-info-marks info))
|
|
1235 t)))
|
|
1236 gnus-article-mark-lists)
|
56927
|
1237 (let ((seen (cdr (assq 'read nnfolder-marks))))
|
|
1238 (gnus-info-set-read info
|
|
1239 (if (and (integerp (car seen))
|
|
1240 (null (cdr seen)))
|
|
1241 (list (cons (car seen) (car seen)))
|
|
1242 seen)))
|
|
1243 (nnheader-message 8 "Updating marks for %s...done" group))
|
|
1244 info)
|
|
1245
|
|
1246 (defun nnfolder-group-marks-pathname (group)
|
|
1247 "Make pathname for GROUP NOV."
|
|
1248 (let ((nnfolder-directory (or nnfolder-marks-directory nnfolder-directory)))
|
|
1249 (concat (nnfolder-group-pathname group) nnfolder-marks-file-suffix)))
|
|
1250
|
|
1251 (defun nnfolder-marks-changed-p (group)
|
|
1252 (let ((file (nnfolder-group-marks-pathname group)))
|
|
1253 (if (null (gnus-gethash file nnfolder-marks-modtime))
|
|
1254 t ;; never looked at marks file, assume it has changed
|
|
1255 (not (equal (gnus-gethash file nnfolder-marks-modtime)
|
|
1256 (nth 5 (file-attributes file)))))))
|
|
1257
|
|
1258 (defun nnfolder-save-marks (group server)
|
|
1259 (let ((file-name-coding-system nnmail-pathname-coding-system)
|
|
1260 (file (nnfolder-group-marks-pathname group)))
|
|
1261 (condition-case err
|
|
1262 (progn
|
|
1263 (with-temp-file file
|
|
1264 (erase-buffer)
|
|
1265 (gnus-prin1 nnfolder-marks)
|
|
1266 (insert "\n"))
|
|
1267 (gnus-sethash file
|
|
1268 (nth 5 (file-attributes file))
|
|
1269 nnfolder-marks-modtime))
|
|
1270 (error (or (gnus-yes-or-no-p
|
|
1271 (format "Could not write to %s (%s). Continue? " file err))
|
58223
d6cec97fa4c1
(nnfolder-save-marks): Add missing format field in call to `error'.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
1272 (error "Cannot write to %s (%s)" file err))))))
|
56927
|
1273
|
|
1274 (defun nnfolder-open-marks (group server)
|
|
1275 (let ((file (nnfolder-group-marks-pathname group)))
|
|
1276 (if (file-exists-p file)
|
|
1277 (condition-case err
|
|
1278 (with-temp-buffer
|
|
1279 (gnus-sethash file (nth 5 (file-attributes file))
|
|
1280 nnfolder-marks-modtime)
|
|
1281 (nnheader-insert-file-contents file)
|
|
1282 (setq nnfolder-marks (read (current-buffer)))
|
|
1283 (dolist (el gnus-article-unpropagated-mark-lists)
|
|
1284 (setq nnfolder-marks (gnus-remassoc el nnfolder-marks))))
|
|
1285 (error (or (gnus-yes-or-no-p
|
|
1286 (format "Error reading nnfolder marks file %s (%s). Continuing will use marks from .newsrc.eld. Continue? " file err))
|
|
1287 (error "Cannot read nnfolder marks file %s (%s)" file err))))
|
|
1288 ;; User didn't have a .marks file. Probably first time
|
|
1289 ;; user of the .marks stuff. Bootstrap it from .newsrc.eld.
|
|
1290 (let ((info (gnus-get-info
|
|
1291 (gnus-group-prefixed-name
|
|
1292 group
|
|
1293 (gnus-server-to-method (format "nnfolder:%s" server))))))
|
|
1294 (nnheader-message 7 "Bootstrapping marks for %s..." group)
|
|
1295 (setq nnfolder-marks (gnus-info-marks info))
|
|
1296 (push (cons 'read (gnus-info-read info)) nnfolder-marks)
|
|
1297 (dolist (el gnus-article-unpropagated-mark-lists)
|
|
1298 (setq nnfolder-marks (gnus-remassoc el nnfolder-marks)))
|
|
1299 (nnfolder-save-marks group server)
|
|
1300 (nnheader-message 7 "Bootstrapping marks for %s...done" group)))))
|
|
1301
|
17493
|
1302 (provide 'nnfolder)
|
|
1303
|
93975
|
1304 ;; arch-tag: a040d0f4-4f4e-445f-8972-839575c5f7e6
|
17493
|
1305 ;;; nnfolder.el ends here
|