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