1 ;;; nnsoup.el --- SOUP access for Gnus
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
8 ;; Keywords: news, mail
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 (eval-when-compile (require 'cl))
41 (defvoo nnsoup-directory "~/SOUP/"
42 "*SOUP packet directory.")
44 (defvoo nnsoup-tmp-directory
45 (cond ((fboundp 'temp-directory) (temp-directory))
46 ((boundp 'temporary-file-directory) temporary-file-directory)
48 "*Where nnsoup will store temporary files.")
50 (defvoo nnsoup-replies-directory (expand-file-name "replies/" nnsoup-directory)
51 "*Directory where outgoing packets will be composed.")
53 (defvoo nnsoup-replies-format-type ?u ;; u is USENET news format.
54 "*Format of the replies packages.")
56 (defvoo nnsoup-replies-index-type ?n
57 "*Index type of the replies packages.")
59 (defvoo nnsoup-active-file (expand-file-name "active" nnsoup-directory)
62 (defvoo nnsoup-packer "tar cf - %s | gzip > $HOME/Soupin%d.tgz"
63 "Format string command for packing a SOUP packet.
64 The SOUP files will be inserted where the %s is in the string.
65 This string MUST contain both %s and %d. The file number will be
66 inserted where %d appears.")
68 (defvoo nnsoup-unpacker "gunzip -c %s | tar xvf -"
69 "*Format string command for unpacking a SOUP packet.
70 The SOUP packet file name will be inserted at the %s.")
72 (defvoo nnsoup-packet-directory "~/"
73 "*Where nnsoup will look for incoming packets.")
75 (defvoo nnsoup-packet-regexp "Soupout"
76 "*Regular expression matching SOUP packets in `nnsoup-packet-directory'.")
78 (defvoo nnsoup-always-save t
79 "If non nil commit the reply buffer on each message send.
80 This is necessary if using message mode outside Gnus with nnsoup as a
81 backend for the messages.")
85 (defconst nnsoup-version "nnsoup 0.0"
88 (defvoo nnsoup-status-string "")
89 (defvoo nnsoup-group-alist nil)
90 (defvoo nnsoup-current-prefix 0)
91 (defvoo nnsoup-replies-list nil)
92 (defvoo nnsoup-buffers nil)
93 (defvoo nnsoup-current-group nil)
94 (defvoo nnsoup-group-alist-touched nil)
95 (defvoo nnsoup-article-alist nil)
98 ;;; Interface functions.
100 (nnoo-define-basics nnsoup)
102 (deffoo nnsoup-retrieve-headers (sequence &optional group server fetch-old)
103 (nnsoup-possibly-change-group group)
105 (set-buffer nntp-server-buffer)
107 (let ((areas (cddr (assoc nnsoup-current-group nnsoup-group-alist)))
110 useful-areas this-area-seq msg-buf)
111 (if (stringp (car sequence))
112 ;; We don't support fetching by Message-ID.
114 ;; We go through all the areas and find which files the
115 ;; articles in SEQUENCE come from.
116 (while (and areas sequence)
117 ;; Peel off areas that are below sequence.
118 (while (and areas (< (cdar (car areas)) (car sequence)))
119 (setq areas (cdr areas)))
121 ;; This is a useful area.
122 (push (car areas) useful-areas)
123 (setq this-area-seq nil)
124 ;; We take note whether this MSG has a corresponding IDX
126 (when (or (= (gnus-soup-encoding-index
127 (gnus-soup-area-encoding (nth 1 (car areas)))) ?n)
130 (gnus-soup-area-prefix (nth 1 (car areas)))))))
132 ;; We assign the portion of `sequence' that is relevant to
133 ;; this MSG packet to this packet.
134 (while (and sequence (<= (car sequence) (cdar (car areas))))
135 (push (car sequence) this-area-seq)
136 (setq sequence (cdr sequence)))
137 (setcar useful-areas (cons (nreverse this-area-seq)
138 (car useful-areas)))))
140 ;; We now have a list of article numbers and corresponding
142 (setq useful-areas (nreverse useful-areas))
144 ;; Two different approaches depending on whether all the MSG
145 ;; files have corresponding IDX files. If they all do, we
146 ;; simply return the relevant IDX files and let Gnus sort out
147 ;; what lines are relevant. If some of the IDX files are
148 ;; missing, we must return HEADs for all the articles.
150 ;; We have IDX files for all areas.
153 (goto-char (point-max))
155 (number (car (nth 1 (car useful-areas))))
156 (index-buffer (nnsoup-index-buffer
157 (gnus-soup-area-prefix
158 (nth 2 (car useful-areas))))))
160 (insert-buffer-substring index-buffer)
162 ;; We have to remove the index number entries and
163 ;; insert article numbers instead.
164 (while (looking-at "[0-9]+")
165 (replace-match (int-to-string number) t t)
168 (setq useful-areas (cdr useful-areas)))
172 (setq articles (caar useful-areas)
173 useful-areas (cdr useful-areas))
176 (nnsoup-narrow-to-article
177 (car articles) (cdar useful-areas) 'head))
178 (goto-char (point-max))
179 (insert (format "221 %d Article retrieved.\n" (car articles)))
180 (insert-buffer-substring msg-buf)
181 (goto-char (point-max))
183 (setq articles (cdr articles))))
185 (nnheader-fold-continuation-lines)
188 (deffoo nnsoup-open-server (server &optional defs)
189 (nnoo-change-server 'nnsoup server defs)
190 (when (not (file-exists-p nnsoup-directory))
192 (make-directory nnsoup-directory t)
195 ((not (file-exists-p nnsoup-directory))
196 (nnsoup-close-server)
197 (nnheader-report 'nnsoup "Couldn't create directory: %s" nnsoup-directory))
198 ((not (file-directory-p (file-truename nnsoup-directory)))
199 (nnsoup-close-server)
200 (nnheader-report 'nnsoup "Not a directory: %s" nnsoup-directory))
202 (nnsoup-read-active-file)
203 (nnheader-report 'nnsoup "Opened server %s using directory %s"
204 server nnsoup-directory)
207 (deffoo nnsoup-request-close ()
208 (nnsoup-write-active-file)
209 (nnsoup-write-replies)
210 (gnus-soup-save-areas)
211 ;; Kill all nnsoup buffers.
213 (while nnsoup-buffers
214 (setq buffer (cdr (pop nnsoup-buffers)))
217 (kill-buffer buffer))))
218 (setq nnsoup-group-alist nil
219 nnsoup-group-alist-touched nil
220 nnsoup-current-group nil
221 nnsoup-replies-list nil)
222 (nnoo-close-server 'nnoo)
225 (deffoo nnsoup-request-article (id &optional newsgroup server buffer)
226 (nnsoup-possibly-change-group newsgroup)
229 (set-buffer (or buffer nntp-server-buffer))
231 (when (and (not (stringp id))
232 (setq buf (nnsoup-narrow-to-article id)))
233 (insert-buffer-substring buf)
236 (deffoo nnsoup-request-group (group &optional server dont-check)
237 (nnsoup-possibly-change-group group)
240 (let ((active (cadr (assoc group nnsoup-group-alist))))
242 (nnheader-report 'nnsoup "No such group: %s" group)
245 (max (1+ (- (cdr active) (car active))) 0)
246 (car active) (cdr active) group)))))
248 (deffoo nnsoup-request-type (group &optional article)
249 (nnsoup-possibly-change-group group)
250 ;; Try to guess the type based on the first article in the group.
253 (cdar (car (cddr (assoc group nnsoup-group-alist))))))
256 (let ((kind (gnus-soup-encoding-kind
257 (gnus-soup-area-encoding
258 (nth 1 (nnsoup-article-to-area
259 article nnsoup-current-group))))))
260 (cond ((= kind ?m) 'mail)
264 (deffoo nnsoup-close-group (group &optional server)
265 ;; Kill all nnsoup buffers.
266 (let ((buffers nnsoup-buffers)
269 (when (equal (car (setq elem (pop buffers))) group)
270 (setq nnsoup-buffers (delq elem nnsoup-buffers))
271 (and (cdr elem) (buffer-name (cdr elem))
272 (kill-buffer (cdr elem))))))
275 (deffoo nnsoup-request-list (&optional server)
277 (set-buffer nntp-server-buffer)
279 (unless nnsoup-group-alist
280 (nnsoup-read-active-file))
281 (let ((alist nnsoup-group-alist)
282 (standard-output (current-buffer))
284 (while (setq entry (pop alist))
285 (insert (car entry) " ")
286 (princ (cdadr entry))
288 (princ (caadr entry))
292 (deffoo nnsoup-request-scan (group &optional server)
293 (nnsoup-unpack-packets))
295 (deffoo nnsoup-request-newgroups (date &optional server)
296 (nnsoup-request-list))
298 (deffoo nnsoup-request-list-newsgroups (&optional server)
301 (deffoo nnsoup-request-post (&optional server)
302 (nnsoup-store-reply "news")
305 (deffoo nnsoup-request-mail (&optional server)
306 (nnsoup-store-reply "mail")
309 (deffoo nnsoup-request-expire-articles (articles group &optional server force)
310 (nnsoup-possibly-change-group group)
311 (let* ((total-infolist (assoc group nnsoup-group-alist))
312 (active (cadr total-infolist))
313 (infolist (cddr total-infolist))
314 info range-list mod-time prefix)
316 (setq info (pop infolist)
317 range-list (gnus-uncompress-range (car info))
318 prefix (gnus-soup-area-prefix (nth 1 info)))
319 (when;; All the articles in this file are marked for expiry.
320 (and (or (setq mod-time (nth 5 (file-attributes
321 (nnsoup-file prefix))))
322 (setq mod-time (nth 5 (file-attributes
323 (nnsoup-file prefix t)))))
324 (gnus-sublist-p articles range-list)
325 ;; This file is old enough.
326 (nnmail-expired-article-p group mod-time force))
327 ;; Ok, we delete this file.
330 5 "Deleting %s in group %s..." (nnsoup-file prefix)
332 (when (file-exists-p (nnsoup-file prefix))
333 (delete-file (nnsoup-file prefix)))
335 5 "Deleting %s in group %s..." (nnsoup-file prefix t)
337 (when (file-exists-p (nnsoup-file prefix t))
338 (delete-file (nnsoup-file prefix t)))
340 (setcdr (cdr total-infolist) (delq info (cddr total-infolist)))
341 (setq articles (gnus-sorted-difference articles range-list))))
343 (setcdr (cdr total-infolist) (delq info (cddr total-infolist)))))
344 (if (cddr total-infolist)
345 (setcar active (caaadr (cdr total-infolist)))
346 (setcar active (1+ (cdr active))))
347 (nnsoup-write-active-file t)
348 ;; Return the articles that weren't expired.
352 ;;; Internal functions
354 (defun nnsoup-possibly-change-group (group &optional force)
356 (not (equal nnsoup-current-group group)))
357 (setq nnsoup-article-alist nil)
358 (setq nnsoup-current-group group))
361 (defun nnsoup-read-active-file ()
362 (setq nnsoup-group-alist nil)
363 (when (file-exists-p nnsoup-active-file)
365 (load nnsoup-active-file t t t))
366 ;; Be backwards compatible.
367 (when (and nnsoup-group-alist
368 (not (atom (caadar nnsoup-group-alist))))
369 (let ((alist nnsoup-group-alist)
371 (while (setq e (cdr (setq entry (pop alist))))
373 (setq max (cdar (car (last e))))
374 (setcdr entry (cons (cons min max) (cdr entry)))))
375 (setq nnsoup-group-alist-touched t))
378 (defun nnsoup-write-active-file (&optional force)
379 (when (and nnsoup-group-alist
381 nnsoup-group-alist-touched))
382 (setq nnsoup-group-alist-touched nil)
383 (with-temp-file nnsoup-active-file
384 (gnus-prin1 `(setq nnsoup-group-alist ',nnsoup-group-alist))
386 (gnus-prin1 `(setq nnsoup-current-prefix ,nnsoup-current-prefix))
389 (defun nnsoup-next-prefix ()
390 "Return the next free prefix."
392 (while (or (file-exists-p
393 (nnsoup-file (setq prefix (int-to-string
394 nnsoup-current-prefix))))
395 (file-exists-p (nnsoup-file prefix t)))
396 (incf nnsoup-current-prefix))
397 (incf nnsoup-current-prefix)
400 (defun nnsoup-file-name (dir file)
401 "Return the full name of FILE (in any case) in DIR."
402 (let* ((case-fold-search t)
403 (files (directory-files dir t))
404 (regexp (concat (regexp-quote file) "$")))
408 (if (string-match regexp file)
413 (defun nnsoup-read-areas ()
414 (let ((areas-file (nnsoup-file-name nnsoup-tmp-directory "areas")))
417 (set-buffer nntp-server-buffer)
418 (let ((areas (gnus-soup-parse-areas areas-file))
419 entry number area lnum cur-prefix file)
420 ;; Go through all areas in the new AREAS file.
421 (while (setq area (pop areas))
422 ;; Change the name to the permanent name and move the files.
423 (setq cur-prefix (nnsoup-next-prefix))
424 (nnheader-message 5 "Incorporating file %s..." cur-prefix)
428 (concat (gnus-soup-area-prefix area) ".IDX")
429 nnsoup-tmp-directory)))
430 (rename-file file (nnsoup-file cur-prefix)))
432 (setq file (expand-file-name
433 (concat (gnus-soup-area-prefix area) ".MSG")
434 nnsoup-tmp-directory)))
435 (rename-file file (nnsoup-file cur-prefix t))
436 (gnus-soup-set-area-prefix area cur-prefix)
437 ;; Find the number of new articles in this area.
438 (setq number (nnsoup-number-of-articles area))
439 (if (not (setq entry (assoc (gnus-soup-area-name area)
440 nnsoup-group-alist)))
441 ;; If this is a new area (group), we just add this info to
443 (push (list (gnus-soup-area-name area)
445 (list (cons 1 number) area))
447 ;; There are already articles in this group, so we add this
448 ;; info to the end of the entry.
449 (nconc entry (list (list (cons (1+ (setq lnum (cdadr entry)))
452 (setcdr (cadr entry) (+ lnum number))))))
453 (nnsoup-write-active-file t)
454 (delete-file areas-file)))))
456 (defun nnsoup-number-of-articles (area)
459 ;; If the number is in the area info, we just return it.
460 ((gnus-soup-area-number area)
461 (gnus-soup-area-number area))
462 ;; If there is an index file, we just count the lines.
463 ((/= (gnus-soup-encoding-index (gnus-soup-area-encoding area)) ?n)
464 (set-buffer (nnsoup-index-buffer (gnus-soup-area-prefix area)))
465 (count-lines (point-min) (point-max)))
466 ;; We do it the hard way - re-searching through the message
469 (set-buffer (nnsoup-message-buffer (gnus-soup-area-prefix area)))
470 (unless (assoc (gnus-soup-area-prefix area) nnsoup-article-alist)
471 (nnsoup-dissect-buffer area))
472 (length (cdr (assoc (gnus-soup-area-prefix area)
473 nnsoup-article-alist)))))))
475 (defun nnsoup-dissect-buffer (area)
476 (let ((mbox-delim (concat "^" message-unix-mail-delimiter))
477 (format (gnus-soup-encoding-format (gnus-soup-area-encoding area)))
480 (goto-char (point-min))
482 ;; rnews batch format
484 (= format ?n)) ;; Gnus back compatibility.
485 (while (looking-at "^#! *rnews \\(+[0-9]+\\) *$")
490 (forward-char (string-to-number (match-string 1)))
495 (while (looking-at mbox-delim)
500 (if (re-search-forward mbox-delim nil t)
502 (goto-char (point-max)))
507 (while (looking-at "\^A\^A\^A\^A\n")
512 (if (search-forward "\n\^A\^A\^A\^A\n" nil t)
514 (goto-char (point-max)))
518 ((or (= format ?B) (= format ?b))
520 (setq len (+ (* (char-after (point)) (expt 2.0 24))
521 (* (char-after (+ (point) 1)) (expt 2 16))
522 (* (char-after (+ (point) 2)) (expt 2 8))
523 (char-after (+ (point) 3))))
525 (incf i) (+ (point) 4)
527 (forward-char (floor (+ len 4)))
531 (error "Unknown format: %c" format)))
532 (push (cons (gnus-soup-area-prefix area) alist) nnsoup-article-alist)))
534 (defun nnsoup-index-buffer (prefix &optional message)
535 (let* ((file (concat prefix (if message ".MSG" ".IDX")))
536 (buffer-name (concat " *nnsoup " file "*")))
537 (or (get-buffer buffer-name) ; File already loaded.
538 (when (file-exists-p (expand-file-name file nnsoup-directory))
539 (save-excursion ; Load the file.
540 (set-buffer (get-buffer-create buffer-name))
541 (buffer-disable-undo)
542 (push (cons nnsoup-current-group (current-buffer)) nnsoup-buffers)
543 (nnheader-insert-file-contents
544 (expand-file-name file nnsoup-directory))
545 (current-buffer))))))
547 (defun nnsoup-file (prefix &optional message)
549 (concat prefix (if message ".MSG" ".IDX"))
552 (defun nnsoup-message-buffer (prefix)
553 (nnsoup-index-buffer prefix 'msg))
555 (defun nnsoup-unpack-packets ()
556 "Unpack all packets in `nnsoup-packet-directory'."
557 (let ((packets (directory-files
558 nnsoup-packet-directory t nnsoup-packet-regexp)))
559 (dolist (packet packets)
560 (nnheader-message 5 "nnsoup: unpacking %s..." packet)
561 (if (not (gnus-soup-unpack-packet
562 nnsoup-tmp-directory nnsoup-unpacker packet))
563 (nnheader-message 5 "Couldn't unpack %s" packet)
566 (nnheader-message 5 "Unpacking...done")))))
568 (defun nnsoup-narrow-to-article (article &optional area head)
569 (let* ((area (or area (nnsoup-article-to-area article nnsoup-current-group)))
570 (prefix (and area (gnus-soup-area-prefix (nth 1 area))))
571 (msg-buf (and prefix (nnsoup-index-buffer prefix 'msg)))
576 ;; There is no MSG file.
579 ;; We use the index file to find out where the article
581 ((and (= (gnus-soup-encoding-index
582 (gnus-soup-area-encoding (nth 1 area)))
584 (file-exists-p (nnsoup-file prefix)))
585 (set-buffer (nnsoup-index-buffer prefix))
587 (goto-char (point-min))
588 (forward-line (- article (caar area)))
589 (setq beg (read (current-buffer)))
591 (if (looking-at "[0-9]+")
593 (setq end (read (current-buffer)))
596 (let ((format (gnus-soup-encoding-format
597 (gnus-soup-area-encoding (nth 1 area)))))
599 (when (or (= format ?u) (= format ?n) (= format ?m))
600 (setq end (progn (forward-line -1) (point))))))
601 (set-buffer msg-buf))
603 (narrow-to-region beg (or end (point-max))))
607 (unless (assoc (gnus-soup-area-prefix (nth 1 area))
608 nnsoup-article-alist)
609 (nnsoup-dissect-buffer (nth 1 area)))
610 (let ((entry (assq article (cdr (assoc (gnus-soup-area-prefix
612 nnsoup-article-alist)))))
614 (narrow-to-region (cadr entry) (caddr entry))))))
615 (goto-char (point-min))
620 (if (search-forward "\n\n" nil t)
626 (defun nnsoup-pack-replies ()
627 "Make an outbound package of SOUP replies."
629 (unless (file-exists-p nnsoup-replies-directory)
630 (nnheader-message 5 "No such directory: %s" nnsoup-replies-directory))
631 ;; Write all data buffers.
632 (gnus-soup-save-areas)
633 ;; Write the active file.
634 (nnsoup-write-active-file)
635 ;; Write the REPLIES file.
636 (nnsoup-write-replies)
637 ;; Check whether there is anything here.
638 (when (null (directory-files nnsoup-replies-directory nil "\\.MSG$"))
639 (error "No files to pack"))
640 ;; Pack all these files into a SOUP packet.
641 (gnus-soup-pack nnsoup-replies-directory nnsoup-packer))
643 (defun nnsoup-write-replies ()
644 "Write the REPLIES file."
645 (when nnsoup-replies-list
646 (gnus-soup-write-replies nnsoup-replies-directory nnsoup-replies-list)
647 (setq nnsoup-replies-list nil)))
649 (defun nnsoup-article-to-area (article group)
650 "Return the area that ARTICLE in GROUP is located in."
651 (let ((areas (cddr (assoc group nnsoup-group-alist))))
652 (while (and areas (< (cdar (car areas)) article))
653 (setq areas (cdr areas)))
654 (and areas (car areas))))
656 (defvar nnsoup-old-functions
657 (list message-send-mail-real-function message-send-news-function))
660 (defun nnsoup-set-variables ()
661 "Use the SOUP methods for posting news and mailing mail."
663 (setq message-send-news-function 'nnsoup-request-post)
664 (setq message-send-mail-real-function 'nnsoup-request-mail))
667 (defun nnsoup-revert-variables ()
668 "Revert posting and mailing methods to the standard Emacs methods."
670 (setq message-send-mail-real-function (car nnsoup-old-functions))
671 (setq message-send-news-function (cadr nnsoup-old-functions)))
673 (defun nnsoup-store-reply (kind)
674 ;; Mostly stolen from `message.el'.
675 (require 'mail-utils)
676 (let ((tembuf (generate-new-buffer " message temp"))
677 (case-fold-search nil)
679 (mailbuf (current-buffer)))
683 (message-narrow-to-headers)
684 (if (equal kind "mail")
685 (message-generate-headers message-required-mail-headers)
686 (message-generate-headers message-required-news-headers)))
689 (insert-buffer-substring mailbuf)
690 ;; Remove some headers.
692 (message-narrow-to-headers)
693 ;; Remove some headers.
694 (message-remove-header message-ignored-mail-headers t))
695 (goto-char (point-max))
696 ;; require one newline at the end.
697 (or (= (preceding-char) ?\n)
699 (let ((case-fold-search t))
700 ;; Change header-delimiter to be what sendmail expects.
701 (goto-char (point-min))
703 (concat "^" (regexp-quote mail-header-separator) "\n"))
706 (setq delimline (point-marker))
707 (goto-char (1+ delimline))
710 nnsoup-replies-directory
711 (nnsoup-kind-to-prefix kind) nil nnsoup-replies-format-type
712 nnsoup-replies-index-type))
714 (when (and msg-buf (bufferp msg-buf))
717 (goto-char (point-min))
718 (while (re-search-forward "^#! *rnews" nil t)
720 (when nnsoup-always-save
722 (nnheader-message 5 "Stored %d messages" num)))
723 (nnsoup-write-replies)
724 (kill-buffer tembuf))))))
726 (defun nnsoup-kind-to-prefix (kind)
727 (unless nnsoup-replies-list
728 (setq nnsoup-replies-list
729 (gnus-soup-parse-replies
730 (expand-file-name "REPLIES" nnsoup-replies-directory))))
731 (let ((replies nnsoup-replies-list))
733 (not (string= kind (gnus-soup-reply-kind (car replies)))))
734 (setq replies (cdr replies)))
736 (gnus-soup-reply-prefix (car replies))
737 (push (vector (gnus-soup-unique-prefix nnsoup-replies-directory)
740 nnsoup-replies-format-type
741 nnsoup-replies-index-type
742 (if (string= kind "news")
745 (gnus-soup-reply-prefix (car nnsoup-replies-list)))))
747 (defun nnsoup-make-active ()
748 "(Re-)create the SOUP active file."
750 (let ((files (sort (directory-files nnsoup-directory t "IDX$")
752 (< (progn (string-match "/\\([0-9]+\\)\\." f1)
753 (string-to-int (match-string 1 f1)))
754 (progn (string-match "/\\([0-9]+\\)\\." f2)
755 (string-to-int (match-string 1 f2)))))))
756 active group lines ident elem min)
757 (set-buffer (get-buffer-create " *nnsoup work*"))
759 (nnheader-message 5 "Doing %s..." file)
761 (nnheader-insert-file-contents file)
762 (goto-char (point-min))
763 (if (not (re-search-forward "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t *\\(Xref: \\)? *[^ ]* \\([^ ]+\\):[0-9]" nil t))
764 (setq group "unknown")
765 (setq group (match-string 2)))
766 (setq lines (count-lines (point-min) (point-max)))
767 (setq ident (progn (string-match
768 "/\\([0-9]+\\)\\." file)
769 (match-string 1 file)))
770 (if (not (setq elem (assoc group active)))
771 (push (list group (cons 1 lines)
773 (vector ident group "ucm" "" lines)))
777 (list (cons (1+ (setq min (cdadr elem)))
779 (vector ident group "ucm" "" lines))))
780 (setcdr (cadr elem) (+ min lines))))
781 (nnheader-message 5 "")
782 (setq nnsoup-group-alist active)
783 (nnsoup-write-active-file t)))
785 (defun nnsoup-delete-unreferenced-message-files ()
786 "Delete any *.MSG and *.IDX files that aren't known by nnsoup."
788 (let* ((known (apply 'nconc (mapcar
792 (gnus-soup-area-prefix (cadr area)))
794 nnsoup-group-alist)))
795 (regexp "\\.MSG$\\|\\.IDX$")
796 (files (directory-files nnsoup-directory nil regexp))
798 ;; Find all files that aren't known by nnsoup.
800 (string-match regexp file)
801 (unless (member (substring file 0 (match-beginning 0)) known)
802 (push file non-files)))
803 ;; Sort and delete the files.
804 (setq non-files (sort non-files 'string<))
805 (map-y-or-n-p "Delete file %s? "
806 (lambda (file) (delete-file
807 (expand-file-name file nnsoup-directory)))
812 ;;; nnsoup.el ends here