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