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