(nnml-generate-nov-databases-directory): Document no-active
[gnus] / lisp / nnml.el
1 ;;; nnml.el --- mail spool access for Gnus
2
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;;   2004, 2005, 2006 Free Software Foundation, Inc.
5
6 ;; Authors: Didier Verna <didier@xemacs.org> (adding compaction)
7 ;;      Simon Josefsson <simon@josefsson.org> (adding MARKS)
8 ;;      Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;;      Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
10 ;; Keywords: news, mail
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28
29 ;;; Commentary:
30
31 ;; Based on nnspool.el by Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>.
32 ;; For an overview of what the interface functions do, please see the
33 ;; Gnus sources.
34
35 ;;; Code:
36
37 (require 'gnus)
38 (require 'nnheader)
39 (require 'nnmail)
40 (require 'nnoo)
41 (eval-when-compile (require 'cl))
42
43 (eval-and-compile
44   (autoload 'gnus-article-unpropagatable-p "gnus-sum")
45   (autoload 'gnus-backlog-remove-article "gnus-bcklg"))
46
47 (nnoo-declare nnml)
48
49 (defvoo nnml-directory message-directory
50   "Spool directory for the nnml mail backend.")
51
52 (defvoo nnml-active-file
53     (expand-file-name "active" nnml-directory)
54   "Mail active file.")
55
56 (defvoo nnml-newsgroups-file
57     (expand-file-name "newsgroups" nnml-directory)
58   "Mail newsgroups description file.")
59
60 (defvoo nnml-get-new-mail t
61   "If non-nil, nnml will check the incoming mail file and split the mail.")
62
63 (defvoo nnml-nov-is-evil nil
64   "If non-nil, Gnus will never generate and use nov databases for mail spools.
65 Using nov databases will speed up header fetching considerably.
66 This variable shouldn't be flipped much.  If you have, for some reason,
67 set this to t, and want to set it to nil again, you should always run
68 the `nnml-generate-nov-databases' command.  The function will go
69 through all nnml directories and generate nov databases for them
70 all.  This may very well take some time.")
71
72 (defvoo nnml-marks-is-evil nil
73   "If non-nil, Gnus will never generate and use marks file for mail spools.
74 Using marks files makes it possible to backup and restore mail groups
75 separately from `.newsrc.eld'.  If you have, for some reason, set this
76 to t, and want to set it to nil again, you should always remove the
77 corresponding marks file (usually named `.marks' in the nnml group
78 directory, but see `nnml-marks-file-name') for the group.  Then the
79 marks file will be regenerated properly by Gnus.")
80
81 (defvoo nnml-prepare-save-mail-hook nil
82   "Hook run narrowed to an article before saving.")
83
84 (defvoo nnml-inhibit-expiry nil
85   "If non-nil, inhibit expiry.")
86
87 (defvoo nnml-use-compressed-files nil
88   "If non-nil, allow using compressed message files.
89
90 If it is a string, use it as the file extension which specifies
91 the comression program.  You can set it to \".bz2\" if your Emacs
92 supports auto-compression using the bzip2 program.  A value of t
93 is equivalent to \".gz\".")
94
95 (defvoo nnml-compressed-files-size-threshold 1000
96   "Default size threshold for compressed message files.
97 Message files with bodies larger than that many characters will
98 be automatically compressed if `nnml-use-compressed-files' is
99 non-nil.")
100
101 \f
102
103 (defconst nnml-version "nnml 1.0"
104   "nnml version.")
105
106 (defvoo nnml-nov-file-name ".overview")
107 (defvoo nnml-marks-file-name ".marks")
108
109 (defvoo nnml-current-directory nil)
110 (defvoo nnml-current-group nil)
111 (defvoo nnml-status-string "")
112 (defvoo nnml-nov-buffer-alist nil)
113 (defvoo nnml-group-alist nil)
114 (defvoo nnml-active-timestamp nil)
115 (defvoo nnml-article-file-alist nil)
116
117 (defvoo nnml-generate-active-function 'nnml-generate-active-info)
118
119 (defvar nnml-nov-buffer-file-name nil)
120
121 (defvoo nnml-file-coding-system nnmail-file-coding-system)
122
123 (defvoo nnml-marks nil)
124
125 (defvar nnml-marks-modtime (gnus-make-hashtable))
126
127 \f
128 ;;; Interface functions.
129
130 (nnoo-define-basics nnml)
131
132 (deffoo nnml-retrieve-headers (sequence &optional group server fetch-old)
133   (when (nnml-possibly-change-directory group server)
134     (save-excursion
135       (set-buffer nntp-server-buffer)
136       (erase-buffer)
137       (let* ((file nil)
138              (number (length sequence))
139              (count 0)
140              (file-name-coding-system nnmail-pathname-coding-system)
141              beg article)
142         (if (stringp (car sequence))
143             'headers
144           (if (nnml-retrieve-headers-with-nov sequence fetch-old)
145               'nov
146             (while sequence
147               (setq article (car sequence))
148               (setq file (nnml-article-to-file article))
149               (when (and file
150                          (file-exists-p file)
151                          (not (file-directory-p file)))
152                 (insert (format "221 %d Article retrieved.\n" article))
153                 (setq beg (point))
154                 (nnheader-insert-head file)
155                 (goto-char beg)
156                 (if (re-search-forward "\n\r?\n" nil t)
157                     (forward-char -1)
158                   (goto-char (point-max))
159                   (insert "\n\n"))
160                 (insert ".\n")
161                 (delete-region (point) (point-max)))
162               (setq sequence (cdr sequence))
163               (setq count (1+ count))
164               (and (numberp nnmail-large-newsgroup)
165                    (> number nnmail-large-newsgroup)
166                    (zerop (% count 20))
167                    (nnheader-message 6 "nnml: Receiving headers... %d%%"
168                                      (/ (* count 100) number))))
169
170             (and (numberp nnmail-large-newsgroup)
171                  (> number nnmail-large-newsgroup)
172                  (nnheader-message 6 "nnml: Receiving headers...done"))
173
174             (nnheader-fold-continuation-lines)
175             'headers))))))
176
177 (deffoo nnml-open-server (server &optional defs)
178   (nnoo-change-server 'nnml server defs)
179   (when (not (file-exists-p nnml-directory))
180     (ignore-errors (make-directory nnml-directory t)))
181   (cond
182    ((not (file-exists-p nnml-directory))
183     (nnml-close-server)
184     (nnheader-report 'nnml "Couldn't create directory: %s" nnml-directory))
185    ((not (file-directory-p (file-truename nnml-directory)))
186     (nnml-close-server)
187     (nnheader-report 'nnml "Not a directory: %s" nnml-directory))
188    (t
189     (nnheader-report 'nnml "Opened server %s using directory %s"
190                      server nnml-directory)
191     t)))
192
193 (deffoo nnml-request-regenerate (server)
194   (nnml-possibly-change-directory nil server)
195   (nnml-generate-nov-databases server)
196   t)
197
198 (deffoo nnml-request-article (id &optional group server buffer)
199   (nnml-possibly-change-directory group server)
200   (let* ((nntp-server-buffer (or buffer nntp-server-buffer))
201          (file-name-coding-system nnmail-pathname-coding-system)
202          path gpath group-num)
203     (if (stringp id)
204         (when (and (setq group-num (nnml-find-group-number id))
205                    (cdr
206                     (assq (cdr group-num)
207                           (nnheader-article-to-file-alist
208                            (setq gpath
209                                  (nnmail-group-pathname
210                                   (car group-num)
211                                   nnml-directory))))))
212           (setq path (concat gpath (int-to-string (cdr group-num)))))
213       (setq path (nnml-article-to-file id)))
214     (cond
215      ((not path)
216       (nnheader-report 'nnml "No such article: %s" id))
217      ((not (file-exists-p path))
218       (nnheader-report 'nnml "No such file: %s" path))
219      ((file-directory-p path)
220       (nnheader-report 'nnml "File is a directory: %s" path))
221      ((not (save-excursion (let ((nnmail-file-coding-system
222                                   nnml-file-coding-system))
223                              (nnmail-find-file path))))
224       (nnheader-report 'nnml "Couldn't read file: %s" path))
225      (t
226       (nnheader-report 'nnml "Article %s retrieved" id)
227       ;; We return the article number.
228       (cons (if group-num (car group-num) group)
229             (string-to-number (file-name-nondirectory path)))))))
230
231 (deffoo nnml-request-group (group &optional server dont-check)
232   (let ((file-name-coding-system nnmail-pathname-coding-system))
233     (cond
234      ((not (nnml-possibly-change-directory group server))
235       (nnheader-report 'nnml "Invalid group (no such directory)"))
236      ((not (file-exists-p nnml-current-directory))
237       (nnheader-report 'nnml "Directory %s does not exist"
238                        nnml-current-directory))
239      ((not (file-directory-p nnml-current-directory))
240       (nnheader-report 'nnml "%s is not a directory" nnml-current-directory))
241      (dont-check
242       (nnheader-report 'nnml "Group %s selected" group)
243       t)
244      (t
245       (nnheader-re-read-dir nnml-current-directory)
246       (nnmail-activate 'nnml)
247       (let ((active (nth 1 (assoc group nnml-group-alist))))
248         (if (not active)
249             (nnheader-report 'nnml "No such group: %s" group)
250           (nnheader-report 'nnml "Selected group %s" group)
251           (nnheader-insert "211 %d %d %d %s\n"
252                            (max (1+ (- (cdr active) (car active))) 0)
253                            (car active) (cdr active) group)))))))
254
255 (deffoo nnml-request-scan (&optional group server)
256   (setq nnml-article-file-alist nil)
257   (nnml-possibly-change-directory group server)
258   (nnmail-get-new-mail 'nnml 'nnml-save-nov nnml-directory group))
259
260 (deffoo nnml-close-group (group &optional server)
261   (setq nnml-article-file-alist nil)
262   t)
263
264 (deffoo nnml-request-create-group (group &optional server args)
265   (nnml-possibly-change-directory nil server)
266   (nnmail-activate 'nnml)
267   (cond
268    ((assoc group nnml-group-alist)
269     t)
270    ((and (file-exists-p (nnmail-group-pathname group nnml-directory))
271          (not (file-directory-p (nnmail-group-pathname group nnml-directory))))
272     (nnheader-report 'nnml "%s is a file"
273                      (nnmail-group-pathname group nnml-directory)))
274    (t
275     (let (active)
276       (push (list group (setq active (cons 1 0)))
277             nnml-group-alist)
278       (nnml-possibly-create-directory group)
279       (nnml-possibly-change-directory group server)
280       (let ((articles (nnml-directory-articles nnml-current-directory)))
281         (when articles
282           (setcar active (apply 'min articles))
283           (setcdr active (apply 'max articles))))
284       (nnmail-save-active nnml-group-alist nnml-active-file)
285       t))))
286
287 (deffoo nnml-request-list (&optional server)
288   (save-excursion
289     (let ((nnmail-file-coding-system nnmail-active-file-coding-system)
290           (file-name-coding-system nnmail-pathname-coding-system))
291       (nnmail-find-file nnml-active-file))
292     (setq nnml-group-alist (nnmail-get-active))
293     t))
294
295 (deffoo nnml-request-newgroups (date &optional server)
296   (nnml-request-list server))
297
298 (deffoo nnml-request-list-newsgroups (&optional server)
299   (save-excursion
300     (nnmail-find-file nnml-newsgroups-file)))
301
302 (deffoo nnml-request-expire-articles (articles group &optional server force)
303   (nnml-possibly-change-directory group server)
304   (let ((active-articles
305          (nnml-directory-articles nnml-current-directory))
306         (is-old t)
307         article rest mod-time number)
308     (nnmail-activate 'nnml)
309
310     (setq active-articles (sort active-articles '<))
311     ;; Articles not listed in active-articles are already gone,
312     ;; so don't try to expire them.
313     (setq articles (gnus-sorted-intersection articles active-articles))
314
315     (while (and articles is-old)
316       (if (and (setq article (nnml-article-to-file
317                               (setq number (pop articles))))
318                (setq mod-time (nth 5 (file-attributes article)))
319                (nnml-deletable-article-p group number)
320                (setq is-old (nnmail-expired-article-p group mod-time force
321                                                       nnml-inhibit-expiry)))
322           (progn
323             ;; Allow a special target group.
324             (unless (eq nnmail-expiry-target 'delete)
325               (with-temp-buffer
326                 (nnml-request-article number group server (current-buffer))
327                 (let (nnml-current-directory
328                       nnml-current-group
329                       nnml-article-file-alist)
330                   (nnmail-expiry-target-group nnmail-expiry-target group)))
331               ;; Maybe directory is changed during nnmail-expiry-target-group.
332               (nnml-possibly-change-directory group server))
333             (nnheader-message 5 "Deleting article %s in %s"
334                               number group)
335             (condition-case ()
336                 (funcall nnmail-delete-file-function article)
337               (file-error
338                (push number rest)))
339             (setq active-articles (delq number active-articles))
340             (nnml-nov-delete-article group number))
341         (push number rest)))
342     (let ((active (nth 1 (assoc group nnml-group-alist))))
343       (when active
344         (setcar active (or (and active-articles
345                                 (apply 'min active-articles))
346                            (1+ (cdr active)))))
347       (nnmail-save-active nnml-group-alist nnml-active-file))
348     (nnml-save-nov)
349     (nconc rest articles)))
350
351 (deffoo nnml-request-move-article
352     (article group server accept-form &optional last move-is-internal)
353   (let ((buf (get-buffer-create " *nnml move*"))
354         result)
355     (nnml-possibly-change-directory group server)
356     (nnml-update-file-alist)
357     (and
358      (nnml-deletable-article-p group article)
359      (nnml-request-article article group server)
360      (let (nnml-current-directory
361            nnml-current-group
362            nnml-article-file-alist)
363        (save-excursion
364          (set-buffer buf)
365          (insert-buffer-substring nntp-server-buffer)
366          (setq result (eval accept-form))
367          (kill-buffer (current-buffer))
368          result))
369      (progn
370        (nnml-possibly-change-directory group server)
371        (condition-case ()
372            (funcall nnmail-delete-file-function
373                     (nnml-article-to-file  article))
374          (file-error nil))
375        (nnml-nov-delete-article group article)
376        (when last
377          (nnml-save-nov)
378          (nnmail-save-active nnml-group-alist nnml-active-file))))
379     result))
380
381 (deffoo nnml-request-accept-article (group &optional server last)
382   (nnml-possibly-change-directory group server)
383   (nnmail-check-syntax)
384   (let (result)
385     (when nnmail-cache-accepted-message-ids
386       (nnmail-cache-insert (nnmail-fetch-field "message-id")
387                            group
388                            (nnmail-fetch-field "subject")
389                            (nnmail-fetch-field "from")))
390     (if (stringp group)
391         (and
392          (nnmail-activate 'nnml)
393          (setq result (car (nnml-save-mail
394                             (list (cons group (nnml-active-number group))))))
395          (progn
396            (nnmail-save-active nnml-group-alist nnml-active-file)
397            (and last (nnml-save-nov))))
398       (and
399        (nnmail-activate 'nnml)
400        (if (and (not (setq result (nnmail-article-group 'nnml-active-number)))
401                 (yes-or-no-p "Moved to `junk' group; delete article? "))
402            (setq result 'junk)
403          (setq result (car (nnml-save-mail result))))
404        (when last
405          (nnmail-save-active nnml-group-alist nnml-active-file)
406          (when nnmail-cache-accepted-message-ids
407            (nnmail-cache-close))
408          (nnml-save-nov))))
409     result))
410
411 (deffoo nnml-request-post (&optional server)
412   (nnmail-do-request-post 'nnml-request-accept-article server))
413
414 (deffoo nnml-request-replace-article (article group buffer)
415   (nnml-possibly-change-directory group)
416   (save-excursion
417     (set-buffer buffer)
418     (nnml-possibly-create-directory group)
419     (let ((chars (nnmail-insert-lines))
420           (art (concat (int-to-string article) "\t"))
421           headers)
422       (when (ignore-errors
423               (nnmail-write-region
424                (point-min) (point-max)
425                (or (nnml-article-to-file article)
426                    (expand-file-name (int-to-string article)
427                                      nnml-current-directory))
428                nil (if (nnheader-be-verbose 5) nil 'nomesg))
429               t)
430         (setq headers (nnml-parse-head chars article))
431         ;; Replace the NOV line in the NOV file.
432         (save-excursion
433           (set-buffer (nnml-open-nov group))
434           (goto-char (point-min))
435           (if (or (looking-at art)
436                   (search-forward (concat "\n" art) nil t))
437               ;; Delete the old NOV line.
438               (gnus-delete-line)
439             ;; The line isn't here, so we have to find out where
440             ;; we should insert it.  (This situation should never
441             ;; occur, but one likes to make sure...)
442             (while (and (looking-at "[0-9]+\t")
443                         (< (string-to-number
444                             (buffer-substring
445                              (match-beginning 0) (match-end 0)))
446                            article)
447                         (zerop (forward-line 1)))))
448           (beginning-of-line)
449           (nnheader-insert-nov headers)
450           (nnml-save-nov)
451           t)))))
452
453 (deffoo nnml-request-delete-group (group &optional force server)
454   (nnml-possibly-change-directory group server)
455   (when force
456     ;; Delete all articles in GROUP.
457     (let ((articles
458            (directory-files
459             nnml-current-directory t
460             (concat nnheader-numerical-short-files
461                     "\\|" (regexp-quote nnml-nov-file-name) "$"
462                     "\\|" (regexp-quote nnml-marks-file-name) "$"))))
463       (dolist (article articles)
464         (when (file-writable-p article)
465           (nnheader-message 5 "Deleting article %s in %s..." article group)
466           (funcall nnmail-delete-file-function article))))
467     ;; Try to delete the directory itself.
468     (ignore-errors (delete-directory nnml-current-directory)))
469   ;; Remove the group from all structures.
470   (setq nnml-group-alist
471         (delq (assoc group nnml-group-alist) nnml-group-alist)
472         nnml-current-group nil
473         nnml-current-directory nil)
474   ;; Save the active file.
475   (nnmail-save-active nnml-group-alist nnml-active-file)
476   t)
477
478 (deffoo nnml-request-rename-group (group new-name &optional server)
479   (nnml-possibly-change-directory group server)
480   (let ((new-dir (nnmail-group-pathname new-name nnml-directory))
481         (old-dir (nnmail-group-pathname group nnml-directory)))
482     (when (ignore-errors
483             (make-directory new-dir t)
484             t)
485       ;; We move the articles file by file instead of renaming
486       ;; the directory -- there may be subgroups in this group.
487       ;; One might be more clever, I guess.
488       (dolist (file (nnheader-article-to-file-alist old-dir))
489         (rename-file
490          (concat old-dir (cdr file))
491          (concat new-dir (cdr file))))
492       ;; Move .overview file.
493       (let ((overview (concat old-dir nnml-nov-file-name)))
494         (when (file-exists-p overview)
495           (rename-file overview (concat new-dir nnml-nov-file-name))))
496       ;; Move .marks file.
497       (let ((marks (concat old-dir nnml-marks-file-name)))
498         (when (file-exists-p marks)
499           (rename-file marks (concat new-dir nnml-marks-file-name))))
500       (when (<= (length (directory-files old-dir)) 2)
501         (ignore-errors (delete-directory old-dir)))
502       ;; That went ok, so we change the internal structures.
503       (let ((entry (assoc group nnml-group-alist)))
504         (when entry
505           (setcar entry new-name))
506         (setq nnml-current-directory nil
507               nnml-current-group nil)
508         ;; Save the new group alist.
509         (nnmail-save-active nnml-group-alist nnml-active-file)
510         t))))
511
512 (deffoo nnml-set-status (article name value &optional group server)
513   (nnml-possibly-change-directory group server)
514   (let ((file (nnml-article-to-file article)))
515     (cond
516      ((not (file-exists-p file))
517       (nnheader-report 'nnml "File %s does not exist" file))
518      (t
519       (with-temp-file file
520         (nnheader-insert-file-contents file)
521         (nnmail-replace-status name value))
522       t))))
523
524 \f
525 ;;; Internal functions.
526
527 (defun nnml-article-to-file (article)
528   (nnml-update-file-alist)
529   (let (file)
530     (if (setq file
531               (if nnml-use-compressed-files
532                   (cdr (assq article nnml-article-file-alist))
533                 (number-to-string article)))
534         (expand-file-name file nnml-current-directory)
535       (when (not nnheader-directory-files-is-safe)
536         ;; Just to make sure nothing went wrong when reading over NFS --
537         ;; check once more.
538         (when (file-exists-p
539                (setq file (expand-file-name (number-to-string article)
540                                             nnml-current-directory)))
541           (nnml-update-file-alist t)
542           file)))))
543
544 (defun nnml-deletable-article-p (group article)
545   "Say whether ARTICLE in GROUP can be deleted."
546   (let (path)
547     (when (setq path (nnml-article-to-file article))
548       (when (file-writable-p path)
549         (or (not nnmail-keep-last-article)
550             (not (eq (cdr (nth 1 (assoc group nnml-group-alist)))
551                      article)))))))
552
553 ;; Find an article number in the current group given the Message-ID.
554 (defun nnml-find-group-number (id)
555   (save-excursion
556     (set-buffer (get-buffer-create " *nnml id*"))
557     (let ((alist nnml-group-alist)
558           number)
559       ;; We want to look through all .overview files, but we want to
560       ;; start with the one in the current directory.  It seems most
561       ;; likely that the article we are looking for is in that group.
562       (if (setq number (nnml-find-id nnml-current-group id))
563           (cons nnml-current-group number)
564       ;; It wasn't there, so we look through the other groups as well.
565         (while (and (not number)
566                     alist)
567           (or (string= (caar alist) nnml-current-group)
568               (setq number (nnml-find-id (caar alist) id)))
569           (or number
570               (setq alist (cdr alist))))
571         (and number
572              (cons (caar alist) number))))))
573
574 (defun nnml-find-id (group id)
575   (erase-buffer)
576   (let ((nov (expand-file-name nnml-nov-file-name
577                                (nnmail-group-pathname group nnml-directory)))
578         number found)
579     (when (file-exists-p nov)
580       (nnheader-insert-file-contents nov)
581       (while (and (not found)
582                   (search-forward id nil t)) ; We find the ID.
583         ;; And the id is in the fourth field.
584         (if (not (and (search-backward "\t" nil t 4)
585                       (not (search-backward "\t" (point-at-bol) t))))
586             (forward-line 1)
587           (beginning-of-line)
588           (setq found t)
589           ;; We return the article number.
590           (setq number
591                 (ignore-errors (read (current-buffer))))))
592       number)))
593
594 (defun nnml-retrieve-headers-with-nov (articles &optional fetch-old)
595   (if (or gnus-nov-is-evil nnml-nov-is-evil)
596       nil
597     (let ((nov (expand-file-name nnml-nov-file-name nnml-current-directory)))
598       (when (file-exists-p nov)
599         (save-excursion
600           (set-buffer nntp-server-buffer)
601           (erase-buffer)
602           (nnheader-insert-file-contents nov)
603           (if (and fetch-old
604                    (not (numberp fetch-old)))
605               t                         ; Don't remove anything.
606             (nnheader-nov-delete-outside-range
607              (if fetch-old (max 1 (- (car articles) fetch-old))
608                (car articles))
609              (car (last articles)))
610             t))))))
611
612 (defun nnml-possibly-change-directory (group &optional server)
613   (when (and server
614              (not (nnml-server-opened server)))
615     (nnml-open-server server))
616   (if (not group)
617       t
618     (let ((pathname (nnmail-group-pathname group nnml-directory))
619           (file-name-coding-system nnmail-pathname-coding-system))
620       (when (not (equal pathname nnml-current-directory))
621         (setq nnml-current-directory pathname
622               nnml-current-group group
623               nnml-article-file-alist nil))
624       (file-exists-p nnml-current-directory))))
625
626 (defun nnml-possibly-create-directory (group)
627   (let ((dir (nnmail-group-pathname group nnml-directory)))
628     (unless (file-exists-p dir)
629       (make-directory (directory-file-name dir) t)
630       (nnheader-message 5 "Creating mail directory %s" dir))))
631
632 (defun nnml-save-mail (group-art)
633   "Called narrowed to an article."
634   (let (chars headers extension)
635     (setq chars (nnmail-insert-lines))
636     (setq extension
637          (and nnml-use-compressed-files
638               (> chars nnml-compressed-files-size-threshold)
639               (if (stringp nnml-use-compressed-files)
640                   nnml-use-compressed-files
641                 ".gz")))
642     (nnmail-insert-xref group-art)
643     (run-hooks 'nnmail-prepare-save-mail-hook)
644     (run-hooks 'nnml-prepare-save-mail-hook)
645     (goto-char (point-min))
646     (while (looking-at "From ")
647       (replace-match "X-From-Line: ")
648       (forward-line 1))
649     ;; We save the article in all the groups it belongs in.
650     (let ((ga group-art)
651           first)
652       (while ga
653         (nnml-possibly-create-directory (caar ga))
654         (let ((file (concat (nnmail-group-pathname
655                              (caar ga) nnml-directory)
656                             (int-to-string (cdar ga))
657                             extension)))
658           (if first
659               ;; It was already saved, so we just make a hard link.
660               (funcall nnmail-crosspost-link-function first file t)
661             ;; Save the article.
662             (nnmail-write-region (point-min) (point-max) file nil
663                                  (if (nnheader-be-verbose 5) nil 'nomesg))
664             (setq first file)))
665         (setq ga (cdr ga))))
666     ;; Generate a nov line for this article.  We generate the nov
667     ;; line after saving, because nov generation destroys the
668     ;; header.
669     (setq headers (nnml-parse-head chars))
670     ;; Output the nov line to all nov databases that should have it.
671     (let ((ga group-art))
672       (while ga
673         (nnml-add-nov (caar ga) (cdar ga) headers)
674         (setq ga (cdr ga))))
675     group-art))
676
677 (defun nnml-active-number (group)
678   "Compute the next article number in GROUP."
679   (let ((active (cadr (assoc group nnml-group-alist))))
680     ;; The group wasn't known to nnml, so we just create an active
681     ;; entry for it.
682     (unless active
683       ;; Perhaps the active file was corrupt?  See whether
684       ;; there are any articles in this group.
685       (nnml-possibly-create-directory group)
686       (nnml-possibly-change-directory group)
687       (unless nnml-article-file-alist
688         (setq nnml-article-file-alist
689               (sort
690                (nnml-current-group-article-to-file-alist)
691                'car-less-than-car)))
692       (setq active
693             (if nnml-article-file-alist
694                 (cons (caar nnml-article-file-alist)
695                       (caar (last nnml-article-file-alist)))
696               (cons 1 0)))
697       (push (list group active) nnml-group-alist))
698     (setcdr active (1+ (cdr active)))
699     (while (file-exists-p
700             (expand-file-name (int-to-string (cdr active))
701                               (nnmail-group-pathname group nnml-directory)))
702       (setcdr active (1+ (cdr active))))
703     (cdr active)))
704
705 (defun nnml-add-nov (group article headers)
706   "Add a nov line for the GROUP base."
707   (save-excursion
708     (set-buffer (nnml-open-nov group))
709     (goto-char (point-max))
710     (mail-header-set-number headers article)
711     (nnheader-insert-nov headers)))
712
713 (defsubst nnml-header-value ()
714   (buffer-substring (match-end 0) (point-at-eol)))
715
716 (defun nnml-parse-head (chars &optional number)
717   "Parse the head of the current buffer."
718   (save-excursion
719     (save-restriction
720       (unless (zerop (buffer-size))
721         (narrow-to-region
722          (goto-char (point-min))
723          (if (re-search-forward "\n\r?\n" nil t)
724              (1- (point))
725            (point-max))))
726       (let ((headers (nnheader-parse-naked-head)))
727         (mail-header-set-chars headers chars)
728         (mail-header-set-number headers number)
729         headers))))
730
731 (defun nnml-get-nov-buffer (group)
732   (let ((buffer (get-buffer-create (format " *nnml overview %s*" group))))
733     (save-excursion
734       (set-buffer buffer)
735       (set (make-local-variable 'nnml-nov-buffer-file-name)
736            (expand-file-name
737             nnml-nov-file-name
738             (nnmail-group-pathname group nnml-directory)))
739       (erase-buffer)
740       (when (file-exists-p nnml-nov-buffer-file-name)
741         (nnheader-insert-file-contents nnml-nov-buffer-file-name)))
742     buffer))
743
744 (defun nnml-open-nov (group)
745   (or (cdr (assoc group nnml-nov-buffer-alist))
746       (let ((buffer (nnml-get-nov-buffer group)))
747         (push (cons group buffer) nnml-nov-buffer-alist)
748         buffer)))
749
750 (defun nnml-save-nov ()
751   (save-excursion
752     (while nnml-nov-buffer-alist
753       (when (buffer-name (cdar nnml-nov-buffer-alist))
754         (set-buffer (cdar nnml-nov-buffer-alist))
755         (when (buffer-modified-p)
756           (nnmail-write-region (point-min) (point-max)
757                                nnml-nov-buffer-file-name nil 'nomesg))
758         (set-buffer-modified-p nil)
759         (kill-buffer (current-buffer)))
760       (setq nnml-nov-buffer-alist (cdr nnml-nov-buffer-alist)))))
761
762 ;;;###autoload
763 (defun nnml-generate-nov-databases (&optional server)
764   "Generate NOV databases in all nnml directories."
765   (interactive (list (or (nnoo-current-server 'nnml) "")))
766   ;; Read the active file to make sure we don't re-use articles
767   ;; numbers in empty groups.
768   (nnmail-activate 'nnml)
769   (unless (nnml-server-opened server)
770     (nnml-open-server server))
771   (setq nnml-directory (expand-file-name nnml-directory))
772   ;; Recurse down the directories.
773   (nnml-generate-nov-databases-directory nnml-directory nil t)
774   ;; Save the active file.
775   (nnmail-save-active nnml-group-alist nnml-active-file))
776
777 (defun nnml-generate-nov-databases-directory (dir &optional seen no-active)
778   "Regenerate the NOV database in DIR.
779
780 Unless no-active is non-nil, update the active file too."
781   (interactive "DRegenerate NOV in: ")
782   (setq dir (file-name-as-directory dir))
783   ;; Only scan this sub-tree if we haven't been here yet.
784   (unless (member (file-truename dir) seen)
785     (push (file-truename dir) seen)
786     ;; We descend recursively
787     (dolist (dir (directory-files dir t nil t))
788       (when (and (not (string-match "^\\." (file-name-nondirectory dir)))
789                  (file-directory-p dir))
790         (nnml-generate-nov-databases-directory dir seen)))
791     ;; Do this directory.
792     (let ((files (sort (nnheader-article-to-file-alist dir)
793                        'car-less-than-car)))
794       (if (not files)
795           (let* ((group (nnheader-file-to-group
796                          (directory-file-name dir) nnml-directory))
797                  (info (cadr (assoc group nnml-group-alist))))
798             (when info
799               (setcar info (1+ (cdr info)))))
800         (funcall nnml-generate-active-function dir)
801         ;; Generate the nov file.
802         (nnml-generate-nov-file dir files)
803         (unless no-active
804           (nnmail-save-active nnml-group-alist nnml-active-file))))))
805
806 (eval-when-compile (defvar files))
807 (defun nnml-generate-active-info (dir)
808   ;; Update the active info for this group.
809   (let* ((group (nnheader-file-to-group
810                  (directory-file-name dir) nnml-directory))
811          (entry (assoc group nnml-group-alist))
812          (last (or (caadr entry) 0)))
813     (setq nnml-group-alist (delq entry nnml-group-alist))
814     (push (list group
815                 (cons (or (caar files) (1+ last))
816                       (max last
817                            (or (caar (last files))
818                                0))))
819           nnml-group-alist)))
820
821 (defun nnml-generate-nov-file (dir files)
822   (let* ((dir (file-name-as-directory dir))
823          (nov (concat dir nnml-nov-file-name))
824          (nov-buffer (get-buffer-create " *nov*"))
825          chars file headers)
826     (save-excursion
827       ;; Init the nov buffer.
828       (set-buffer nov-buffer)
829       (buffer-disable-undo)
830       (erase-buffer)
831       (set-buffer nntp-server-buffer)
832       ;; Delete the old NOV file.
833       (when (file-exists-p nov)
834         (funcall nnmail-delete-file-function nov))
835       (while files
836         (unless (file-directory-p (setq file (concat dir (cdar files))))
837           (erase-buffer)
838           (nnheader-insert-file-contents file)
839           (narrow-to-region
840            (goto-char (point-min))
841            (progn
842              (re-search-forward "\n\r?\n" nil t)
843              (setq chars (- (point-max) (point)))
844              (max (point-min) (1- (point)))))
845           (unless (zerop (buffer-size))
846             (goto-char (point-min))
847             (setq headers (nnml-parse-head chars (caar files)))
848             (save-excursion
849               (set-buffer nov-buffer)
850               (goto-char (point-max))
851               (nnheader-insert-nov headers)))
852           (widen))
853         (setq files (cdr files)))
854       (save-excursion
855         (set-buffer nov-buffer)
856         (nnmail-write-region (point-min) (point-max) nov nil 'nomesg)
857         (kill-buffer (current-buffer))))))
858
859 (defun nnml-nov-delete-article (group article)
860   (save-excursion
861     (set-buffer (nnml-open-nov group))
862     (when (nnheader-find-nov-line article)
863       (delete-region (point) (progn (forward-line 1) (point)))
864       (when (bobp)
865         (let ((active (cadr (assoc group nnml-group-alist)))
866               num)
867           (when active
868             (if (eobp)
869                 (setf (car active) (1+ (cdr active)))
870               (when (and (setq num (ignore-errors (read (current-buffer))))
871                          (numberp num))
872                 (setf (car active) num)))))))
873     t))
874
875 (defun nnml-update-file-alist (&optional force)
876   (when nnml-use-compressed-files
877     (when (or (not nnml-article-file-alist)
878               force)
879       (setq nnml-article-file-alist
880             (nnml-current-group-article-to-file-alist)))))
881
882 (defun nnml-directory-articles (dir)
883   "Return a list of all article files in a directory.
884 Use the nov database for that directory if available."
885   (if (or gnus-nov-is-evil nnml-nov-is-evil
886           (not (file-exists-p
887                 (expand-file-name nnml-nov-file-name dir))))
888       (nnheader-directory-articles dir)
889     ;; build list from .overview if available
890     ;; We would use nnml-open-nov, except that nnml-nov-buffer-alist is
891     ;; defvoo'd, and we might get called when it hasn't been swapped in.
892     (save-excursion
893       (let ((list nil)
894             art
895             (buffer (nnml-get-nov-buffer nnml-current-group)))
896         (set-buffer buffer)
897         (goto-char (point-min))
898         (while (not (eobp))
899           (setq art (read (current-buffer)))
900           (push art list)
901           (forward-line 1))
902         list))))
903
904 (defun nnml-current-group-article-to-file-alist ()
905   "Return an alist of article/file pairs in the current group.
906 Use the nov database for the current group if available."
907   (if (or nnml-use-compressed-files
908           gnus-nov-is-evil
909           nnml-nov-is-evil
910           (not (file-exists-p
911                 (expand-file-name nnml-nov-file-name
912                                   nnml-current-directory))))
913       (nnheader-article-to-file-alist nnml-current-directory)
914     ;; build list from .overview if available
915     (save-excursion
916       (let ((alist nil)
917             (buffer (nnml-get-nov-buffer nnml-current-group))
918             art)
919         (set-buffer buffer)
920         (goto-char (point-min))
921         (while (not (eobp))
922           (setq art (read (current-buffer)))
923           ;; assume file name is unadorned (ie. not compressed etc)
924           (push (cons art (int-to-string art)) alist)
925           (forward-line 1))
926         alist))))
927
928 (deffoo nnml-request-set-mark (group actions &optional server)
929   (nnml-possibly-change-directory group server)
930   (unless nnml-marks-is-evil
931     (nnml-open-marks group server)
932     (dolist (action actions)
933       (let ((range (nth 0 action))
934             (what  (nth 1 action))
935             (marks (nth 2 action)))
936         (assert (or (eq what 'add) (eq what 'del)) nil
937                 "Unknown request-set-mark action: %s" what)
938         (dolist (mark marks)
939           (setq nnml-marks (gnus-update-alist-soft
940                             mark
941                             (funcall (if (eq what 'add) 'gnus-range-add
942                                        'gnus-remove-from-range)
943                                      (cdr (assoc mark nnml-marks)) range)
944                             nnml-marks)))))
945     (nnml-save-marks group server))
946   nil)
947
948 (deffoo nnml-request-update-info (group info &optional server)
949   (nnml-possibly-change-directory group server)
950   (when (and (not nnml-marks-is-evil) (nnml-marks-changed-p group))
951     (nnheader-message 8 "Updating marks for %s..." group)
952     (nnml-open-marks group server)
953     ;; Update info using `nnml-marks'.
954     (mapc (lambda (pred)
955             (unless (memq (cdr pred) gnus-article-unpropagated-mark-lists)
956               (gnus-info-set-marks
957                info
958                (gnus-update-alist-soft
959                 (cdr pred)
960                 (cdr (assq (cdr pred) nnml-marks))
961                 (gnus-info-marks info))
962                t)))
963           gnus-article-mark-lists)
964     (let ((seen (cdr (assq 'read nnml-marks))))
965       (gnus-info-set-read info
966                           (if (and (integerp (car seen))
967                                    (null (cdr seen)))
968                               (list (cons (car seen) (car seen)))
969                             seen)))
970     (nnheader-message 8 "Updating marks for %s...done" group))
971   info)
972
973 (defun nnml-marks-changed-p (group)
974   (let ((file (expand-file-name nnml-marks-file-name
975                                 (nnmail-group-pathname group nnml-directory))))
976     (if (null (gnus-gethash file nnml-marks-modtime))
977         t ;; never looked at marks file, assume it has changed
978       (not (equal (gnus-gethash file nnml-marks-modtime)
979                   (nth 5 (file-attributes file)))))))
980
981 (defun nnml-save-marks (group server)
982   (let ((file-name-coding-system nnmail-pathname-coding-system)
983         (file (expand-file-name nnml-marks-file-name
984                                 (nnmail-group-pathname group nnml-directory))))
985     (condition-case err
986         (progn
987           (nnml-possibly-create-directory group)
988           (with-temp-file file
989             (erase-buffer)
990             (gnus-prin1 nnml-marks)
991             (insert "\n"))
992           (gnus-sethash file
993                         (nth 5 (file-attributes file))
994                         nnml-marks-modtime))
995       (error (or (gnus-yes-or-no-p
996                   (format "Could not write to %s (%s).  Continue? " file err))
997                  (error "Cannot write to %s (%s)" file err))))))
998
999 (defun nnml-open-marks (group server)
1000   (let ((file (expand-file-name
1001                nnml-marks-file-name
1002                (nnmail-group-pathname group nnml-directory))))
1003     (if (file-exists-p file)
1004         (condition-case err
1005             (with-temp-buffer
1006               (gnus-sethash file (nth 5 (file-attributes file))
1007                             nnml-marks-modtime)
1008               (nnheader-insert-file-contents file)
1009               (setq nnml-marks (read (current-buffer)))
1010               (dolist (el gnus-article-unpropagated-mark-lists)
1011                 (setq nnml-marks (gnus-remassoc el nnml-marks))))
1012           (error (or (gnus-yes-or-no-p
1013                       (format "Error reading nnml marks file %s (%s).  Continuing will use marks from .newsrc.eld.  Continue? " file err))
1014                      (error "Cannot read nnml marks file %s (%s)" file err))))
1015       ;; User didn't have a .marks file.  Probably first time
1016       ;; user of the .marks stuff.  Bootstrap it from .newsrc.eld.
1017       (let ((info (gnus-get-info
1018                    (gnus-group-prefixed-name
1019                     group
1020                     (gnus-server-to-method (format "nnml:%s" server))))))
1021         (nnheader-message 7 "Bootstrapping marks for %s..." group)
1022         (setq nnml-marks (gnus-info-marks info))
1023         (push (cons 'read (gnus-info-read info)) nnml-marks)
1024         (dolist (el gnus-article-unpropagated-mark-lists)
1025           (setq nnml-marks (gnus-remassoc el nnml-marks)))
1026         (nnml-save-marks group server)
1027         (nnheader-message 7 "Bootstrapping marks for %s...done" group)))))
1028
1029
1030 ;;;
1031 ;;; Group and server compaction. -- dvl
1032 ;;;
1033
1034 ;; #### FIXME: this function handles self Xref: entry correctly, but I don't
1035 ;; #### know how to handle external cross-references. I actually don't know if
1036 ;; #### this is handled correctly elsewhere. For instance, what happens if you
1037 ;; #### move all articles to a new group (that's what people do for manual
1038 ;; #### compaction) ?
1039
1040 ;; #### NOTE: the function below handles the article backlog. This is
1041 ;; #### conceptually the wrong place to do it because the backend is at a
1042 ;; #### lower level. However, this is the only place where we have the needed
1043 ;; #### information to do the job. Ideally, this function should not handle
1044 ;; #### the backlog by itself, but return a list of moved groups / articles to
1045 ;; #### the caller. This will become important to avoid code duplication when
1046 ;; #### other backends get a compaction feature. Also, note that invalidating
1047 ;; #### the "original article buffer" is already done at an upper level.
1048
1049 ;; Shouldn't `nnml-request-compact-group' be interactive? --rsteib
1050
1051 (defun nnml-request-compact-group (group &optional server save)
1052   (nnml-possibly-change-directory group server)
1053   (unless nnml-article-file-alist
1054     (setq nnml-article-file-alist
1055           (sort (nnml-current-group-article-to-file-alist)
1056                 'car-less-than-car)))
1057   (if (not nnml-article-file-alist)
1058       ;; The group is empty: do nothing but return t
1059       t
1060     ;; The group is not empty:
1061     (let* ((group-full-name
1062             (gnus-group-prefixed-name
1063              group
1064              (gnus-server-to-method (format "nnml:%s" server))))
1065            (info (gnus-get-info group-full-name))
1066            (new-number 1)
1067            compacted)
1068       (let ((articles nnml-article-file-alist)
1069             article)
1070         (while (setq article (pop articles))
1071           (let ((old-number (car article)))
1072             (when (> old-number new-number)
1073               ;; There is a gap here:
1074               (let ((old-number-string (int-to-string old-number))
1075                     (new-number-string (int-to-string new-number)))
1076                 (setq compacted t)
1077                 ;; #### NOTE: `nnml-article-to-file' calls
1078                 ;; #### `nnml-update-file-alist'  (which in turn calls
1079                 ;; #### `nnml-current-group-article-to-file-alist', which
1080                 ;; #### might use the NOV database). This might turn out to be
1081                 ;; #### inefficient. In that case, we will do the work
1082                 ;; #### manually.
1083                 ;; 1/ Move the article to a new file:
1084                 (let* ((oldfile (nnml-article-to-file old-number))
1085                        (newfile
1086                         (gnus-replace-in-string
1087                          oldfile (concat "\\("
1088                                          old-number-string
1089                                          "\\)\\(\\(\\.gz\\)?\\)$")
1090                          (concat new-number-string "\\2"))))
1091                   (with-current-buffer nntp-server-buffer
1092                     (nnmail-find-file oldfile)
1093                     ;; Update the Xref header in the article itself:
1094                     (when (and (re-search-forward "^Xref: [^ ]+ " nil t)
1095                                (re-search-forward
1096                                 (concat "\\<"
1097                                         (regexp-quote
1098                                          (concat group ":" old-number-string))
1099                                         "\\>")
1100                                 (point-at-eol) t))
1101                       (replace-match
1102                        (concat group ":" new-number-string)))
1103                     ;; Save to the new file:
1104                     (nnmail-write-region (point-min) (point-max) newfile))
1105                   (funcall nnmail-delete-file-function oldfile))
1106                 ;; 2/ Update all marks for this article:
1107                 ;; #### NOTE: it is possible that the new article number
1108                 ;; #### already belongs to a range, whereas the corresponding
1109                 ;; #### article doesn't exist (for example, if you delete an
1110                 ;; #### article). For that reason, it is important to update
1111                 ;; #### the ranges (meaning remove inexistant articles) before
1112                 ;; #### doing anything on them.
1113                 ;; 2 a/ read articles:
1114                 (let ((read (gnus-info-read info)))
1115                   (setq read (gnus-remove-from-range read (list new-number)))
1116                   (when (gnus-member-of-range old-number read)
1117                     (setq read (gnus-remove-from-range read (list old-number)))
1118                     (setq read (gnus-add-to-range read (list new-number))))
1119                   (gnus-info-set-read info read))
1120                 ;; 2 b/ marked articles:
1121                 (let ((oldmarks (gnus-info-marks info))
1122                       mark newmarks)
1123                   (while (setq mark (pop oldmarks))
1124                     (setcdr mark (gnus-remove-from-range (cdr mark)
1125                                                          (list new-number)))
1126                     (when (gnus-member-of-range old-number (cdr mark))
1127                       (setcdr mark (gnus-remove-from-range (cdr mark)
1128                                                            (list old-number)))
1129                       (setcdr mark (gnus-add-to-range (cdr mark)
1130                                                       (list new-number))))
1131                     (push mark newmarks))
1132                   (gnus-info-set-marks info newmarks))
1133                 ;; 3/ Update the NOV entry for this article:
1134                 (unless nnml-nov-is-evil
1135                   (save-excursion
1136                     (set-buffer (nnml-open-nov group))
1137                     (when (nnheader-find-nov-line old-number)
1138                       ;; Replace the article number:
1139                       (looking-at old-number-string)
1140                       (replace-match new-number-string nil t)
1141                       ;; Update the Xref header:
1142                       (when (re-search-forward
1143                              (concat "\\(Xref:[^\t\n]* \\)\\<"
1144                                      (regexp-quote
1145                                       (concat group ":" old-number-string))
1146                                      "\\>")
1147                              (point-at-eol) t)
1148                         (replace-match
1149                          (concat "\\1" group ":" new-number-string))))))
1150                 ;; 4/ Possibly remove the article from the backlog:
1151                 (when gnus-keep-backlog
1152                   ;; #### NOTE: instead of removing the article, we could
1153                   ;; #### modify the backlog to reflect the numbering change,
1154                   ;; #### but I don't think it's worth it.
1155                   (gnus-backlog-remove-article group-full-name old-number)
1156                   (gnus-backlog-remove-article group-full-name new-number))))
1157             (setq new-number (1+ new-number)))))
1158       (if (not compacted)
1159           ;; No compaction had to be done:
1160           t
1161         ;; Some articles have actually been renamed:
1162         ;; 1/ Rebuild active information:
1163         (let ((entry (assoc group nnml-group-alist))
1164               (active (cons 1 (1- new-number))))
1165           (setq nnml-group-alist (delq entry nnml-group-alist))
1166           (push (list group active) nnml-group-alist)
1167           ;; Update the active hashtable to let the *Group* buffer display
1168           ;; up-to-date lines. I don't think that either gnus-newsrc-hashtb or
1169           ;; gnus-newwrc-alist are out of date, since all we did is to modify
1170           ;; the info of the group internally.
1171           (gnus-set-active group-full-name active))
1172         ;; 1 bis/
1173         ;; #### NOTE: normally, we should save the overview (NOV) file
1174         ;; #### here, just like we save the marks file. However, there is no
1175         ;; #### such function as nnml-save-nov for a single group. Only for
1176         ;; #### all groups. Gnus inconsistency is getting worse every day...
1177         ;; 2/ Rebuild marks file:
1178         (unless nnml-marks-is-evil
1179           ;; #### NOTE: this constant use of global variables everywhere is
1180           ;; #### truly disgusting. Gnus really needs a *major* cleanup.
1181           (setq nnml-marks (gnus-info-marks info))
1182           (push (cons 'read (gnus-info-read info)) nnml-marks)
1183           (dolist (el gnus-article-unpropagated-mark-lists)
1184             (setq nnml-marks (gnus-remassoc el nnml-marks)))
1185           (nnml-save-marks group server))
1186         ;; 3/ Save everything if this was not part of a bigger operation:
1187         (if (not save)
1188             ;; Nothing to save (yet):
1189             t
1190           ;; Something to save:
1191           ;; a/ Save the NOV databases:
1192           ;; #### NOTE: this should be done directory per directory in 1bis
1193           ;; #### above. See comment there.
1194           (nnml-save-nov)
1195           ;; b/ Save the active file:
1196           (nnmail-save-active nnml-group-alist nnml-active-file)
1197           t)))))
1198
1199 (defun nnml-request-compact (&optional server)
1200   "Request compaction of all SERVER nnml groups."
1201   (interactive (list (or (nnoo-current-server 'nnml) "")))
1202   (nnmail-activate 'nnml)
1203   (unless (nnml-server-opened server)
1204     (nnml-open-server server))
1205   (setq nnml-directory (expand-file-name nnml-directory))
1206   (let* ((groups (gnus-groups-from-server
1207                   (gnus-server-to-method (format "nnml:%s" server))))
1208          (first (pop groups))
1209          group)
1210     (when first
1211       (while (setq group (pop groups))
1212         (nnml-request-compact-group (gnus-group-real-name group) server))
1213       (nnml-request-compact-group (gnus-group-real-name first) server t))))
1214
1215
1216 (provide 'nnml)
1217
1218 ;;; arch-tag: 52c97dc3-9735-45de-b439-9e4d23b52004
1219 ;;; nnml.el ends here