1 ;;; nnsoup.el --- SOUP access for Gnus
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Keywords: news, mail
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
34 (eval-when-compile (require 'cl
))
38 (defvoo nnsoup-directory
"~/SOUP/"
39 "*SOUP packet directory.")
41 (defvoo nnsoup-tmp-directory temporary-file-directory
42 "*Where nnsoup will store temporary files.")
44 (defvoo nnsoup-replies-directory
(concat nnsoup-directory
"replies/")
45 "*Directory where outgoing packets will be composed.")
47 (defvoo nnsoup-replies-format-type ?n
48 "*Format of the replies packages.")
50 (defvoo nnsoup-replies-index-type ?n
51 "*Index type of the replies packages.")
53 (defvoo nnsoup-active-file
(concat nnsoup-directory
"active")
56 (defvoo nnsoup-packer
"tar cf - %s | gzip > $HOME/Soupin%d.tgz"
57 "Format string command for packing a SOUP packet.
58 The SOUP files will be inserted where the %s is in the string.
59 This string MUST contain both %s and %d. The file number will be
60 inserted where %d appears.")
62 (defvoo nnsoup-unpacker
"gunzip -c %s | tar xvf -"
63 "*Format string command for unpacking a SOUP packet.
64 The SOUP packet file name will be inserted at the %s.")
66 (defvoo nnsoup-packet-directory
"~/"
67 "*Where nnsoup will look for incoming packets.")
69 (defvoo nnsoup-packet-regexp
"Soupout"
70 "*Regular expression matching SOUP packets in `nnsoup-packet-directory'.")
72 (defvoo nnsoup-always-save t
73 "If non nil commit the reply buffer on each message send.
74 This is necessary if using message mode outside Gnus with nnsoup as a
75 backend for the messages.")
79 (defconst nnsoup-version
"nnsoup 0.0"
82 (defvoo nnsoup-status-string
"")
83 (defvoo nnsoup-group-alist nil
)
84 (defvoo nnsoup-current-prefix
0)
85 (defvoo nnsoup-replies-list nil
)
86 (defvoo nnsoup-buffers nil
)
87 (defvoo nnsoup-current-group nil
)
88 (defvoo nnsoup-group-alist-touched nil
)
89 (defvoo nnsoup-article-alist nil
)
92 ;;; Interface functions.
94 (nnoo-define-basics nnsoup
)
96 (deffoo nnsoup-retrieve-headers
(sequence &optional group server fetch-old
)
97 (nnsoup-possibly-change-group group
)
99 (set-buffer nntp-server-buffer
)
101 (let ((areas (cddr (assoc nnsoup-current-group nnsoup-group-alist
)))
104 useful-areas this-area-seq msg-buf
)
105 (if (stringp (car sequence
))
106 ;; We don't support fetching by Message-ID.
108 ;; We go through all the areas and find which files the
109 ;; articles in SEQUENCE come from.
110 (while (and areas sequence
)
111 ;; Peel off areas that are below sequence.
112 (while (and areas
(< (cdaar areas
) (car sequence
)))
113 (setq areas
(cdr areas
)))
115 ;; This is a useful area.
116 (push (car areas
) useful-areas
)
117 (setq this-area-seq nil
)
118 ;; We take note whether this MSG has a corresponding IDX
120 (when (or (= (gnus-soup-encoding-index
121 (gnus-soup-area-encoding (nth 1 (car areas
)))) ?n
)
124 (gnus-soup-area-prefix (nth 1 (car areas
)))))))
126 ;; We assign the portion of `sequence' that is relevant to
127 ;; this MSG packet to this packet.
128 (while (and sequence
(<= (car sequence
) (cdaar areas
)))
129 (push (car sequence
) this-area-seq
)
130 (setq sequence
(cdr sequence
)))
131 (setcar useful-areas
(cons (nreverse this-area-seq
)
132 (car useful-areas
)))))
134 ;; We now have a list of article numbers and corresponding
136 (setq useful-areas
(nreverse useful-areas
))
138 ;; Two different approaches depending on whether all the MSG
139 ;; files have corresponding IDX files. If they all do, we
140 ;; simply return the relevant IDX files and let Gnus sort out
141 ;; what lines are relevant. If some of the IDX files are
142 ;; missing, we must return HEADs for all the articles.
144 ;; We have IDX files for all areas.
147 (goto-char (point-max))
149 (number (car (nth 1 (car useful-areas
))))
150 (index-buffer (nnsoup-index-buffer
151 (gnus-soup-area-prefix
152 (nth 2 (car useful-areas
))))))
154 (insert-buffer-substring index-buffer
)
156 ;; We have to remove the index number entires and
157 ;; insert article numbers instead.
158 (while (looking-at "[0-9]+")
159 (replace-match (int-to-string number
) t t
)
162 (setq useful-areas
(cdr useful-areas
)))
166 (setq articles
(caar useful-areas
)
167 useful-areas
(cdr useful-areas
))
170 (nnsoup-narrow-to-article
171 (car articles
) (cdar useful-areas
) 'head
))
172 (goto-char (point-max))
173 (insert (format "221 %d Article retrieved.\n" (car articles
)))
174 (insert-buffer-substring msg-buf
)
175 (goto-char (point-max))
177 (setq articles
(cdr articles
))))
179 (nnheader-fold-continuation-lines)
182 (deffoo nnsoup-open-server
(server &optional defs
)
183 (nnoo-change-server 'nnsoup server defs
)
184 (when (not (file-exists-p nnsoup-directory
))
186 (make-directory nnsoup-directory t
)
189 ((not (file-exists-p nnsoup-directory
))
190 (nnsoup-close-server)
191 (nnheader-report 'nnsoup
"Couldn't create directory: %s" nnsoup-directory
))
192 ((not (file-directory-p (file-truename nnsoup-directory
)))
193 (nnsoup-close-server)
194 (nnheader-report 'nnsoup
"Not a directory: %s" nnsoup-directory
))
196 (nnsoup-read-active-file)
197 (nnheader-report 'nnsoup
"Opened server %s using directory %s"
198 server nnsoup-directory
)
201 (deffoo nnsoup-request-close
()
202 (nnsoup-write-active-file)
203 (nnsoup-write-replies)
204 (gnus-soup-save-areas)
205 ;; Kill all nnsoup buffers.
207 (while nnsoup-buffers
208 (setq buffer
(cdr (pop nnsoup-buffers
)))
211 (kill-buffer buffer
))))
212 (setq nnsoup-group-alist nil
213 nnsoup-group-alist-touched nil
214 nnsoup-current-group nil
215 nnsoup-replies-list nil
)
216 (nnoo-close-server 'nnoo
)
219 (deffoo nnsoup-request-article
(id &optional newsgroup server buffer
)
220 (nnsoup-possibly-change-group newsgroup
)
223 (set-buffer (or buffer nntp-server-buffer
))
225 (when (and (not (stringp id
))
226 (setq buf
(nnsoup-narrow-to-article id
)))
227 (insert-buffer-substring buf
)
230 (deffoo nnsoup-request-group
(group &optional server dont-check
)
231 (nnsoup-possibly-change-group group
)
234 (let ((active (cadr (assoc group nnsoup-group-alist
))))
236 (nnheader-report 'nnsoup
"No such group: %s" group
)
239 (max (1+ (- (cdr active
) (car active
))) 0)
240 (car active
) (cdr active
) group
)))))
242 (deffoo nnsoup-request-type
(group &optional article
)
243 (nnsoup-possibly-change-group group
)
244 ;; Try to guess the type based on the first article in the group.
247 (cdaar (cddr (assoc group nnsoup-group-alist
)))))
250 (let ((kind (gnus-soup-encoding-kind
251 (gnus-soup-area-encoding
252 (nth 1 (nnsoup-article-to-area
253 article nnsoup-current-group
))))))
254 (cond ((= kind ?m
) 'mail
)
258 (deffoo nnsoup-close-group
(group &optional server
)
259 ;; Kill all nnsoup buffers.
260 (let ((buffers nnsoup-buffers
)
263 (when (equal (car (setq elem
(pop buffers
))) group
)
264 (setq nnsoup-buffers
(delq elem nnsoup-buffers
))
265 (and (cdr elem
) (buffer-name (cdr elem
))
266 (kill-buffer (cdr elem
))))))
269 (deffoo nnsoup-request-list
(&optional server
)
271 (set-buffer nntp-server-buffer
)
273 (unless nnsoup-group-alist
274 (nnsoup-read-active-file))
275 (let ((alist nnsoup-group-alist
)
276 (standard-output (current-buffer))
278 (while (setq entry
(pop alist
))
279 (insert (car entry
) " ")
280 (princ (cdadr entry
))
282 (princ (caadr entry
))
286 (deffoo nnsoup-request-scan
(group &optional server
)
287 (nnsoup-unpack-packets))
289 (deffoo nnsoup-request-newgroups
(date &optional server
)
290 (nnsoup-request-list))
292 (deffoo nnsoup-request-list-newsgroups
(&optional server
)
295 (deffoo nnsoup-request-post
(&optional server
)
296 (nnsoup-store-reply "news")
299 (deffoo nnsoup-request-mail
(&optional server
)
300 (nnsoup-store-reply "mail")
303 (deffoo nnsoup-request-expire-articles
(articles group
&optional server force
)
304 (nnsoup-possibly-change-group group
)
305 (let* ((total-infolist (assoc group nnsoup-group-alist
))
306 (active (cadr total-infolist
))
307 (infolist (cddr total-infolist
))
308 info range-list mod-time prefix
)
310 (setq info
(pop infolist
)
311 range-list
(gnus-uncompress-range (car info
))
312 prefix
(gnus-soup-area-prefix (nth 1 info
)))
313 (when ;; All the articles in this file are marked for expiry.
314 (and (or (setq mod-time
(nth 5 (file-attributes
315 (nnsoup-file prefix
))))
316 (setq mod-time
(nth 5 (file-attributes
317 (nnsoup-file prefix t
)))))
318 (gnus-sublist-p articles range-list
)
319 ;; This file is old enough.
320 (nnmail-expired-article-p group mod-time force
))
321 ;; Ok, we delete this file.
324 5 "Deleting %s in group %s..." (nnsoup-file prefix
)
326 (when (file-exists-p (nnsoup-file prefix
))
327 (delete-file (nnsoup-file prefix
)))
329 5 "Deleting %s in group %s..." (nnsoup-file prefix t
)
331 (when (file-exists-p (nnsoup-file prefix t
))
332 (delete-file (nnsoup-file prefix t
)))
334 (setcdr (cdr total-infolist
) (delq info
(cddr total-infolist
)))
335 (setq articles
(gnus-sorted-complement articles range-list
))))
337 (setcdr (cdr total-infolist
) (delq info
(cddr total-infolist
)))))
338 (if (cddr total-infolist
)
339 (setcar active
(caaadr (cdr total-infolist
)))
340 (setcar active
(1+ (cdr active
))))
341 (nnsoup-write-active-file t
)
342 ;; Return the articles that weren't expired.
346 ;;; Internal functions
348 (defun nnsoup-possibly-change-group (group &optional force
)
350 (not (equal nnsoup-current-group group
)))
351 (setq nnsoup-article-alist nil
)
352 (setq nnsoup-current-group group
))
355 (defun nnsoup-read-active-file ()
356 (setq nnsoup-group-alist nil
)
357 (when (file-exists-p nnsoup-active-file
)
359 (load nnsoup-active-file t t t
))
360 ;; Be backwards compatible.
361 (when (and nnsoup-group-alist
362 (not (atom (caadar nnsoup-group-alist
))))
363 (let ((alist nnsoup-group-alist
)
365 (while (setq e
(cdr (setq entry
(pop alist
))))
370 (setcdr entry
(cons (cons min max
) (cdr entry
)))))
371 (setq nnsoup-group-alist-touched t
))
374 (defun nnsoup-write-active-file (&optional force
)
375 (when (and nnsoup-group-alist
377 nnsoup-group-alist-touched
))
378 (setq nnsoup-group-alist-touched nil
)
379 (nnheader-temp-write nnsoup-active-file
380 (gnus-prin1 `(setq nnsoup-group-alist
',nnsoup-group-alist
))
382 (gnus-prin1 `(setq nnsoup-current-prefix
,nnsoup-current-prefix
))
385 (defun nnsoup-next-prefix ()
386 "Return the next free prefix."
388 (while (or (file-exists-p
389 (nnsoup-file (setq prefix
(int-to-string
390 nnsoup-current-prefix
))))
391 (file-exists-p (nnsoup-file prefix t
)))
392 (incf nnsoup-current-prefix
))
393 (incf nnsoup-current-prefix
)
396 (defun nnsoup-file-name (dir file
)
397 "Return the full path of FILE (in any case) in DIR."
398 (let* ((case-fold-search t
)
399 (files (directory-files dir t
))
400 (regexp (concat (regexp-quote file
) "$")))
404 (if (string-match regexp file
)
409 (defun nnsoup-read-areas ()
410 (let ((areas-file (nnsoup-file-name nnsoup-tmp-directory
"areas")))
413 (set-buffer nntp-server-buffer
)
414 (let ((areas (gnus-soup-parse-areas areas-file
))
415 entry number area lnum cur-prefix file
)
416 ;; Go through all areas in the new AREAS file.
417 (while (setq area
(pop areas
))
418 ;; Change the name to the permanent name and move the files.
419 (setq cur-prefix
(nnsoup-next-prefix))
420 (nnheader-message 5 "Incorporating file %s..." cur-prefix
)
422 (setq file
(concat nnsoup-tmp-directory
423 (gnus-soup-area-prefix area
) ".IDX")))
424 (rename-file file
(nnsoup-file cur-prefix
)))
426 (setq file
(concat nnsoup-tmp-directory
427 (gnus-soup-area-prefix area
) ".MSG")))
428 (rename-file file
(nnsoup-file cur-prefix t
))
429 (gnus-soup-set-area-prefix area cur-prefix
)
430 ;; Find the number of new articles in this area.
431 (setq number
(nnsoup-number-of-articles area
))
432 (if (not (setq entry
(assoc (gnus-soup-area-name area
)
433 nnsoup-group-alist
)))
434 ;; If this is a new area (group), we just add this info to
436 (push (list (gnus-soup-area-name area
)
438 (list (cons 1 number
) area
))
440 ;; There are already articles in this group, so we add this
441 ;; info to the end of the entry.
442 (nconc entry
(list (list (cons (1+ (setq lnum
(cdadr entry
)))
445 (setcdr (cadr entry
) (+ lnum number
))))))
446 (nnsoup-write-active-file t
)
447 (delete-file areas-file
)))))
449 (defun nnsoup-number-of-articles (area)
452 ;; If the number is in the area info, we just return it.
453 ((gnus-soup-area-number area
)
454 (gnus-soup-area-number area
))
455 ;; If there is an index file, we just count the lines.
456 ((/= (gnus-soup-encoding-index (gnus-soup-area-encoding area
)) ?n
)
457 (set-buffer (nnsoup-index-buffer (gnus-soup-area-prefix area
)))
458 (count-lines (point-min) (point-max)))
459 ;; We do it the hard way - re-searching through the message
462 (set-buffer (nnsoup-message-buffer (gnus-soup-area-prefix area
)))
463 (unless (assoc (gnus-soup-area-prefix area
) nnsoup-article-alist
)
464 (nnsoup-dissect-buffer area
))
465 (length (cdr (assoc (gnus-soup-area-prefix area
)
466 nnsoup-article-alist
)))))))
468 (defun nnsoup-dissect-buffer (area)
469 (let ((mbox-delim (concat "^" message-unix-mail-delimiter
))
470 (format (gnus-soup-encoding-format (gnus-soup-area-encoding area
)))
473 (goto-char (point-min))
475 ;; rnews batch format
477 (while (looking-at "^#! *rnews \\(+[0-9]+\\) *$")
482 (forward-char (string-to-number (match-string 1)))
487 (while (looking-at mbox-delim
)
492 (if (re-search-forward mbox-delim nil t
)
494 (goto-char (point-max)))
499 (while (looking-at "\^A\^A\^A\^A\n")
504 (if (search-forward "\n\^A\^A\^A\^A\n" nil t
)
506 (goto-char (point-max)))
510 ((or (= format ?B
) (= format ?b
))
512 (setq len
(+ (* (char-after (point)) (expt 2.0 24))
513 (* (char-after (+ (point) 1)) (expt 2 16))
514 (* (char-after (+ (point) 2)) (expt 2 8))
515 (char-after (+ (point) 3))))
517 (incf i
) (+ (point) 4)
519 (forward-char (floor (+ len
4)))
523 (error "Unknown format: %c" format
)))
524 (push (cons (gnus-soup-area-prefix area
) alist
) nnsoup-article-alist
)))
526 (defun nnsoup-index-buffer (prefix &optional message
)
527 (let* ((file (concat prefix
(if message
".MSG" ".IDX")))
528 (buffer-name (concat " *nnsoup " file
"*")))
529 (or (get-buffer buffer-name
) ; File already loaded.
530 (when (file-exists-p (concat nnsoup-directory file
))
531 (save-excursion ; Load the file.
532 (set-buffer (get-buffer-create buffer-name
))
533 (buffer-disable-undo (current-buffer))
534 (push (cons nnsoup-current-group
(current-buffer)) nnsoup-buffers
)
535 (nnheader-insert-file-contents (concat nnsoup-directory file
))
536 (current-buffer))))))
538 (defun nnsoup-file (prefix &optional message
)
540 (concat nnsoup-directory prefix
(if message
".MSG" ".IDX"))))
542 (defun nnsoup-message-buffer (prefix)
543 (nnsoup-index-buffer prefix
'msg
))
545 (defun nnsoup-unpack-packets ()
546 "Unpack all packets in `nnsoup-packet-directory'."
547 (let ((packets (directory-files
548 nnsoup-packet-directory t nnsoup-packet-regexp
))
550 (while (setq packet
(pop packets
))
551 (nnheader-message 5 "nnsoup: unpacking %s..." packet
)
552 (if (not (gnus-soup-unpack-packet
553 nnsoup-tmp-directory nnsoup-unpacker packet
))
554 (nnheader-message 5 "Couldn't unpack %s" packet
)
557 (nnheader-message 5 "Unpacking...done")))))
559 (defun nnsoup-narrow-to-article (article &optional area head
)
560 (let* ((area (or area
(nnsoup-article-to-area article nnsoup-current-group
)))
561 (prefix (and area
(gnus-soup-area-prefix (nth 1 area
))))
562 (msg-buf (and prefix
(nnsoup-index-buffer prefix
'msg
)))
567 ;; There is no MSG file.
570 ;; We use the index file to find out where the article
572 ((and (= (gnus-soup-encoding-index
573 (gnus-soup-area-encoding (nth 1 area
)))
575 (file-exists-p (nnsoup-file prefix
)))
576 (set-buffer (nnsoup-index-buffer prefix
))
578 (goto-char (point-min))
579 (forward-line (- article
(caar area
)))
580 (setq beg
(read (current-buffer)))
582 (if (looking-at "[0-9]+")
584 (setq end
(read (current-buffer)))
587 (let ((format (gnus-soup-encoding-format
588 (gnus-soup-area-encoding (nth 1 area
)))))
590 (when (or (= format ?n
) (= format ?m
))
591 (setq end
(progn (forward-line -
1) (point))))))
592 (set-buffer msg-buf
))
594 (narrow-to-region beg
(or end
(point-max))))
598 (unless (assoc (gnus-soup-area-prefix (nth 1 area
))
599 nnsoup-article-alist
)
600 (nnsoup-dissect-buffer (nth 1 area
)))
601 (let ((entry (assq article
(cdr (assoc (gnus-soup-area-prefix
603 nnsoup-article-alist
)))))
605 (narrow-to-region (cadr entry
) (caddr entry
))))))
606 (goto-char (point-min))
611 (if (search-forward "\n\n" nil t
)
617 (defun nnsoup-pack-replies ()
618 "Make an outbound package of SOUP replies."
620 (unless (file-exists-p nnsoup-replies-directory
)
621 (nnheader-message 5 "No such directory: %s" nnsoup-replies-directory
))
622 ;; Write all data buffers.
623 (gnus-soup-save-areas)
624 ;; Write the active file.
625 (nnsoup-write-active-file)
626 ;; Write the REPLIES file.
627 (nnsoup-write-replies)
628 ;; Check whether there is anything here.
629 (when (null (directory-files nnsoup-replies-directory nil
"\\.MSG$"))
630 (error "No files to pack"))
631 ;; Pack all these files into a SOUP packet.
632 (gnus-soup-pack nnsoup-replies-directory nnsoup-packer
))
634 (defun nnsoup-write-replies ()
635 "Write the REPLIES file."
636 (when nnsoup-replies-list
637 (gnus-soup-write-replies nnsoup-replies-directory nnsoup-replies-list
)
638 (setq nnsoup-replies-list nil
)))
640 (defun nnsoup-article-to-area (article group
)
641 "Return the area that ARTICLE in GROUP is located in."
642 (let ((areas (cddr (assoc group nnsoup-group-alist
))))
643 (while (and areas
(< (cdaar areas
) article
))
644 (setq areas
(cdr areas
)))
645 (and areas
(car areas
))))
647 (defvar nnsoup-old-functions
648 (list message-send-mail-function message-send-news-function
))
651 (defun nnsoup-set-variables ()
652 "Use the SOUP methods for posting news and mailing mail."
654 (setq message-send-news-function
'nnsoup-request-post
)
655 (setq message-send-mail-function
'nnsoup-request-mail
))
658 (defun nnsoup-revert-variables ()
659 "Revert posting and mailing methods to the standard Emacs methods."
661 (setq message-send-mail-function
(car nnsoup-old-functions
))
662 (setq message-send-news-function
(cadr nnsoup-old-functions
)))
664 (defun nnsoup-store-reply (kind)
665 ;; Mostly stolen from `message.el'.
666 (require 'mail-utils
)
667 (let ((tembuf (generate-new-buffer " message temp"))
668 (case-fold-search nil
)
669 (real-header-separator mail-header-separator
)
670 (mail-header-separator "")
672 (mailbuf (current-buffer)))
676 (message-narrow-to-headers)
677 (if (equal kind
"mail")
678 (message-generate-headers message-required-mail-headers
)
679 (message-generate-headers message-required-news-headers
)))
682 (insert-buffer-substring mailbuf
)
683 ;; Remove some headers.
685 (message-narrow-to-headers)
686 ;; Remove some headers.
687 (message-remove-header message-ignored-mail-headers t
))
688 (goto-char (point-max))
689 ;; require one newline at the end.
690 (or (= (preceding-char) ?
\n)
692 (let ((case-fold-search t
))
693 ;; Change header-delimiter to be what sendmail expects.
694 (goto-char (point-min))
696 (concat "^" (regexp-quote real-header-separator
) "\n"))
699 (setq delimline
(point-marker))
700 ;; Insert an extra newline if we need it to work around
701 ;; Sun's bug that swallows newlines.
702 (goto-char (1+ delimline
))
703 (when (eval message-mailer-swallows-blank-line
)
707 nnsoup-replies-directory
708 (nnsoup-kind-to-prefix kind
) nil nnsoup-replies-format-type
709 nnsoup-replies-index-type
))
711 (when (and msg-buf
(bufferp msg-buf
))
714 (goto-char (point-min))
715 (while (re-search-forward "^#! *rnews" nil t
)
717 (when nnsoup-always-save
719 (nnheader-message 5 "Stored %d messages" num
)))
720 (nnsoup-write-replies)
721 (kill-buffer tembuf
))))))
723 (defun nnsoup-kind-to-prefix (kind)
724 (unless nnsoup-replies-list
725 (setq nnsoup-replies-list
726 (gnus-soup-parse-replies
727 (concat nnsoup-replies-directory
"REPLIES"))))
728 (let ((replies nnsoup-replies-list
))
730 (not (string= kind
(gnus-soup-reply-kind (car replies
)))))
731 (setq replies
(cdr replies
)))
733 (gnus-soup-reply-prefix (car replies
))
734 (push (vector (gnus-soup-unique-prefix nnsoup-replies-directory
)
737 nnsoup-replies-format-type
738 nnsoup-replies-index-type
739 (if (string= kind
"news")
742 (gnus-soup-reply-prefix (car nnsoup-replies-list
)))))
744 (defun nnsoup-make-active ()
745 "(Re-)create the SOUP active file."
747 (let ((files (sort (directory-files nnsoup-directory t
"IDX$")
749 (< (progn (string-match "/\\([0-9]+\\)\\." f1
)
750 (string-to-int (match-string 1 f1
)))
751 (progn (string-match "/\\([0-9]+\\)\\." f2
)
752 (string-to-int (match-string 1 f2
)))))))
753 active group lines ident elem min
)
754 (set-buffer (get-buffer-create " *nnsoup work*"))
755 (buffer-disable-undo (current-buffer))
757 (nnheader-message 5 "Doing %s..." (car files
))
759 (nnheader-insert-file-contents (car files
))
760 (goto-char (point-min))
761 (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
))
762 (setq group
"unknown")
763 (setq group
(match-string 2)))
764 (setq lines
(count-lines (point-min) (point-max)))
765 (setq ident
(progn (string-match
766 "/\\([0-9]+\\)\\." (car files
))
768 (car files
) (match-beginning 1)
770 (if (not (setq elem
(assoc group active
)))
771 (push (list group
(cons 1 lines
)
773 (vector ident group
"ncm" "" lines
)))
777 (list (cons (1+ (setq min
(cdadr elem
)))
779 (vector ident group
"ncm" "" lines
))))
780 (setcdr (cadr elem
) (+ min lines
)))
781 (setq files
(cdr files
)))
782 (nnheader-message 5 "")
783 (setq nnsoup-group-alist active
)
784 (nnsoup-write-active-file t
)))
786 (defun nnsoup-delete-unreferenced-message-files ()
787 "Delete any *.MSG and *.IDX files that aren't known by nnsoup."
789 (let* ((known (apply 'nconc
(mapcar
793 (gnus-soup-area-prefix (cadr area
)))
795 nnsoup-group-alist
)))
796 (regexp "\\.MSG$\\|\\.IDX$")
797 (files (directory-files nnsoup-directory nil regexp
))
799 ;; Find all files that aren't known by nnsoup.
800 (while (setq file
(pop files
))
801 (string-match regexp file
)
802 (unless (member (substring file
0 (match-beginning 0)) known
)
803 (push file non-files
)))
804 ;; Sort and delete the files.
805 (setq non-files
(sort non-files
'string
<))
806 (map-y-or-n-p "Delete file %s? "
807 (lambda (file) (delete-file (concat nnsoup-directory file
)))
812 ;;; nnsoup.el ends here