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))))
375 (setq max (cdar (car e)))
376 (setcdr entry (cons (cons min max) (cdr entry)))))
377 (setq nnsoup-group-alist-touched t))
380 (defun nnsoup-write-active-file (&optional force)
381 (when (and nnsoup-group-alist
383 nnsoup-group-alist-touched))
384 (setq nnsoup-group-alist-touched nil)
385 (with-temp-file nnsoup-active-file
386 (gnus-prin1 `(setq nnsoup-group-alist ',nnsoup-group-alist))
388 (gnus-prin1 `(setq nnsoup-current-prefix ,nnsoup-current-prefix))
391 (defun nnsoup-next-prefix ()
392 "Return the next free prefix."
394 (while (or (file-exists-p
395 (nnsoup-file (setq prefix (int-to-string
396 nnsoup-current-prefix))))
397 (file-exists-p (nnsoup-file prefix t)))
398 (incf nnsoup-current-prefix))
399 (incf nnsoup-current-prefix)
402 (defun nnsoup-file-name (dir file)
403 "Return the full name of FILE (in any case) in DIR."
404 (let* ((case-fold-search t)
405 (files (directory-files dir t))
406 (regexp (concat (regexp-quote file) "$")))
410 (if (string-match regexp file)
415 (defun nnsoup-read-areas ()
416 (let ((areas-file (nnsoup-file-name nnsoup-tmp-directory "areas")))
419 (set-buffer nntp-server-buffer)
420 (let ((areas (gnus-soup-parse-areas areas-file))
421 entry number area lnum cur-prefix file)
422 ;; Go through all areas in the new AREAS file.
423 (while (setq area (pop areas))
424 ;; Change the name to the permanent name and move the files.
425 (setq cur-prefix (nnsoup-next-prefix))
426 (nnheader-message 5 "Incorporating file %s..." cur-prefix)
430 (concat (gnus-soup-area-prefix area) ".IDX")
431 nnsoup-tmp-directory)))
432 (rename-file file (nnsoup-file cur-prefix)))
434 (setq file (expand-file-name
435 (concat (gnus-soup-area-prefix area) ".MSG")
436 nnsoup-tmp-directory)))
437 (rename-file file (nnsoup-file cur-prefix t))
438 (gnus-soup-set-area-prefix area cur-prefix)
439 ;; Find the number of new articles in this area.
440 (setq number (nnsoup-number-of-articles area))
441 (if (not (setq entry (assoc (gnus-soup-area-name area)
442 nnsoup-group-alist)))
443 ;; If this is a new area (group), we just add this info to
445 (push (list (gnus-soup-area-name area)
447 (list (cons 1 number) area))
449 ;; There are already articles in this group, so we add this
450 ;; info to the end of the entry.
451 (nconc entry (list (list (cons (1+ (setq lnum (cdadr entry)))
454 (setcdr (cadr entry) (+ lnum number))))))
455 (nnsoup-write-active-file t)
456 (delete-file areas-file)))))
458 (defun nnsoup-number-of-articles (area)
461 ;; If the number is in the area info, we just return it.
462 ((gnus-soup-area-number area)
463 (gnus-soup-area-number area))
464 ;; If there is an index file, we just count the lines.
465 ((/= (gnus-soup-encoding-index (gnus-soup-area-encoding area)) ?n)
466 (set-buffer (nnsoup-index-buffer (gnus-soup-area-prefix area)))
467 (count-lines (point-min) (point-max)))
468 ;; We do it the hard way - re-searching through the message
471 (set-buffer (nnsoup-message-buffer (gnus-soup-area-prefix area)))
472 (unless (assoc (gnus-soup-area-prefix area) nnsoup-article-alist)
473 (nnsoup-dissect-buffer area))
474 (length (cdr (assoc (gnus-soup-area-prefix area)
475 nnsoup-article-alist)))))))
477 (defun nnsoup-dissect-buffer (area)
478 (let ((mbox-delim (concat "^" message-unix-mail-delimiter))
479 (format (gnus-soup-encoding-format (gnus-soup-area-encoding area)))
482 (goto-char (point-min))
484 ;; rnews batch format
486 (= format ?n)) ;; Gnus back compatibility.
487 (while (looking-at "^#! *rnews \\(+[0-9]+\\) *$")
492 (forward-char (string-to-number (match-string 1)))
497 (while (looking-at mbox-delim)
502 (if (re-search-forward mbox-delim nil t)
504 (goto-char (point-max)))
509 (while (looking-at "\^A\^A\^A\^A\n")
514 (if (search-forward "\n\^A\^A\^A\^A\n" nil t)
516 (goto-char (point-max)))
520 ((or (= format ?B) (= format ?b))
522 (setq len (+ (* (char-after (point)) (expt 2.0 24))
523 (* (char-after (+ (point) 1)) (expt 2 16))
524 (* (char-after (+ (point) 2)) (expt 2 8))
525 (char-after (+ (point) 3))))
527 (incf i) (+ (point) 4)
529 (forward-char (floor (+ len 4)))
533 (error "Unknown format: %c" format)))
534 (push (cons (gnus-soup-area-prefix area) alist) nnsoup-article-alist)))
536 (defun nnsoup-index-buffer (prefix &optional message)
537 (let* ((file (concat prefix (if message ".MSG" ".IDX")))
538 (buffer-name (concat " *nnsoup " file "*")))
539 (or (get-buffer buffer-name) ; File already loaded.
540 (when (file-exists-p (expand-file-name file nnsoup-directory))
541 (save-excursion ; Load the file.
542 (set-buffer (get-buffer-create buffer-name))
543 (buffer-disable-undo)
544 (push (cons nnsoup-current-group (current-buffer)) nnsoup-buffers)
545 (nnheader-insert-file-contents
546 (expand-file-name file nnsoup-directory))
547 (current-buffer))))))
549 (defun nnsoup-file (prefix &optional message)
551 (concat prefix (if message ".MSG" ".IDX"))
554 (defun nnsoup-message-buffer (prefix)
555 (nnsoup-index-buffer prefix 'msg))
557 (defun nnsoup-unpack-packets ()
558 "Unpack all packets in `nnsoup-packet-directory'."
559 (let ((packets (directory-files
560 nnsoup-packet-directory t nnsoup-packet-regexp))
562 (while (setq packet (pop packets))
563 (nnheader-message 5 "nnsoup: unpacking %s..." packet)
564 (if (not (gnus-soup-unpack-packet
565 nnsoup-tmp-directory nnsoup-unpacker packet))
566 (nnheader-message 5 "Couldn't unpack %s" packet)
569 (nnheader-message 5 "Unpacking...done")))))
571 (defun nnsoup-narrow-to-article (article &optional area head)
572 (let* ((area (or area (nnsoup-article-to-area article nnsoup-current-group)))
573 (prefix (and area (gnus-soup-area-prefix (nth 1 area))))
574 (msg-buf (and prefix (nnsoup-index-buffer prefix 'msg)))
579 ;; There is no MSG file.
582 ;; We use the index file to find out where the article
584 ((and (= (gnus-soup-encoding-index
585 (gnus-soup-area-encoding (nth 1 area)))
587 (file-exists-p (nnsoup-file prefix)))
588 (set-buffer (nnsoup-index-buffer prefix))
590 (goto-char (point-min))
591 (forward-line (- article (caar area)))
592 (setq beg (read (current-buffer)))
594 (if (looking-at "[0-9]+")
596 (setq end (read (current-buffer)))
599 (let ((format (gnus-soup-encoding-format
600 (gnus-soup-area-encoding (nth 1 area)))))
602 (when (or (= format ?u) (= format ?n) (= format ?m))
603 (setq end (progn (forward-line -1) (point))))))
604 (set-buffer msg-buf))
606 (narrow-to-region beg (or end (point-max))))
610 (unless (assoc (gnus-soup-area-prefix (nth 1 area))
611 nnsoup-article-alist)
612 (nnsoup-dissect-buffer (nth 1 area)))
613 (let ((entry (assq article (cdr (assoc (gnus-soup-area-prefix
615 nnsoup-article-alist)))))
617 (narrow-to-region (cadr entry) (caddr entry))))))
618 (goto-char (point-min))
623 (if (search-forward "\n\n" nil t)
629 (defun nnsoup-pack-replies ()
630 "Make an outbound package of SOUP replies."
632 (unless (file-exists-p nnsoup-replies-directory)
633 (nnheader-message 5 "No such directory: %s" nnsoup-replies-directory))
634 ;; Write all data buffers.
635 (gnus-soup-save-areas)
636 ;; Write the active file.
637 (nnsoup-write-active-file)
638 ;; Write the REPLIES file.
639 (nnsoup-write-replies)
640 ;; Check whether there is anything here.
641 (when (null (directory-files nnsoup-replies-directory nil "\\.MSG$"))
642 (error "No files to pack"))
643 ;; Pack all these files into a SOUP packet.
644 (gnus-soup-pack nnsoup-replies-directory nnsoup-packer))
646 (defun nnsoup-write-replies ()
647 "Write the REPLIES file."
648 (when nnsoup-replies-list
649 (gnus-soup-write-replies nnsoup-replies-directory nnsoup-replies-list)
650 (setq nnsoup-replies-list nil)))
652 (defun nnsoup-article-to-area (article group)
653 "Return the area that ARTICLE in GROUP is located in."
654 (let ((areas (cddr (assoc group nnsoup-group-alist))))
655 (while (and areas (< (cdar (car areas)) article))
656 (setq areas (cdr areas)))
657 (and areas (car areas))))
659 (defvar nnsoup-old-functions
660 (list message-send-mail-real-function message-send-news-function))
663 (defun nnsoup-set-variables ()
664 "Use the SOUP methods for posting news and mailing mail."
666 (setq message-send-news-function 'nnsoup-request-post)
667 (setq message-send-mail-real-function 'nnsoup-request-mail))
670 (defun nnsoup-revert-variables ()
671 "Revert posting and mailing methods to the standard Emacs methods."
673 (setq message-send-mail-real-function (car nnsoup-old-functions))
674 (setq message-send-news-function (cadr nnsoup-old-functions)))
676 (defun nnsoup-store-reply (kind)
677 ;; Mostly stolen from `message.el'.
678 (require 'mail-utils)
679 (let ((tembuf (generate-new-buffer " message temp"))
680 (case-fold-search nil)
682 (mailbuf (current-buffer)))
686 (message-narrow-to-headers)
687 (if (equal kind "mail")
688 (message-generate-headers message-required-mail-headers)
689 (message-generate-headers message-required-news-headers)))
692 (insert-buffer-substring mailbuf)
693 ;; Remove some headers.
695 (message-narrow-to-headers)
696 ;; Remove some headers.
697 (message-remove-header message-ignored-mail-headers t))
698 (goto-char (point-max))
699 ;; require one newline at the end.
700 (or (= (preceding-char) ?\n)
702 (let ((case-fold-search t))
703 ;; Change header-delimiter to be what sendmail expects.
704 (goto-char (point-min))
706 (concat "^" (regexp-quote mail-header-separator) "\n"))
709 (setq delimline (point-marker))
710 (goto-char (1+ delimline))
713 nnsoup-replies-directory
714 (nnsoup-kind-to-prefix kind) nil nnsoup-replies-format-type
715 nnsoup-replies-index-type))
717 (when (and msg-buf (bufferp msg-buf))
720 (goto-char (point-min))
721 (while (re-search-forward "^#! *rnews" nil t)
723 (when nnsoup-always-save
725 (nnheader-message 5 "Stored %d messages" num)))
726 (nnsoup-write-replies)
727 (kill-buffer tembuf))))))
729 (defun nnsoup-kind-to-prefix (kind)
730 (unless nnsoup-replies-list
731 (setq nnsoup-replies-list
732 (gnus-soup-parse-replies
733 (expand-file-name "REPLIES" nnsoup-replies-directory))))
734 (let ((replies nnsoup-replies-list))
736 (not (string= kind (gnus-soup-reply-kind (car replies)))))
737 (setq replies (cdr replies)))
739 (gnus-soup-reply-prefix (car replies))
740 (push (vector (gnus-soup-unique-prefix nnsoup-replies-directory)
743 nnsoup-replies-format-type
744 nnsoup-replies-index-type
745 (if (string= kind "news")
748 (gnus-soup-reply-prefix (car nnsoup-replies-list)))))
750 (defun nnsoup-make-active ()
751 "(Re-)create the SOUP active file."
753 (let ((files (sort (directory-files nnsoup-directory t "IDX$")
755 (< (progn (string-match "/\\([0-9]+\\)\\." f1)
756 (string-to-int (match-string 1 f1)))
757 (progn (string-match "/\\([0-9]+\\)\\." f2)
758 (string-to-int (match-string 1 f2)))))))
759 active group lines ident elem min)
760 (set-buffer (get-buffer-create " *nnsoup work*"))
762 (nnheader-message 5 "Doing %s..." (car files))
764 (nnheader-insert-file-contents (car files))
765 (goto-char (point-min))
766 (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))
767 (setq group "unknown")
768 (setq group (match-string 2)))
769 (setq lines (count-lines (point-min) (point-max)))
770 (setq ident (progn (string-match
771 "/\\([0-9]+\\)\\." (car files))
773 (car files) (match-beginning 1)
775 (if (not (setq elem (assoc group active)))
776 (push (list group (cons 1 lines)
778 (vector ident group "ucm" "" lines)))
782 (list (cons (1+ (setq min (cdadr elem)))
784 (vector ident group "ucm" "" lines))))
785 (setcdr (cadr elem) (+ min lines)))
786 (setq files (cdr files)))
787 (nnheader-message 5 "")
788 (setq nnsoup-group-alist active)
789 (nnsoup-write-active-file t)))
791 (defun nnsoup-delete-unreferenced-message-files ()
792 "Delete any *.MSG and *.IDX files that aren't known by nnsoup."
794 (let* ((known (apply 'nconc (mapcar
798 (gnus-soup-area-prefix (cadr area)))
800 nnsoup-group-alist)))
801 (regexp "\\.MSG$\\|\\.IDX$")
802 (files (directory-files nnsoup-directory nil regexp))
804 ;; Find all files that aren't known by nnsoup.
805 (while (setq file (pop files))
806 (string-match regexp file)
807 (unless (member (substring file 0 (match-beginning 0)) known)
808 (push file non-files)))
809 ;; Sort and delete the files.
810 (setq non-files (sort non-files 'string<))
811 (map-y-or-n-p "Delete file %s? "
812 (lambda (file) (delete-file
813 (expand-file-name file nnsoup-directory)))
818 ;;; nnsoup.el ends here