1 ;;; nnsoup.el --- SOUP access for Gnus
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
36 (eval-when-compile (require 'cl
))
40 (defvoo nnsoup-directory
(nnheader-concat gnus-home-directory
"SOUP/")
41 "*SOUP packet directory.")
43 (defvoo nnsoup-tmp-directory
44 (cond ((fboundp 'temp-directory
) (temp-directory))
45 ((boundp 'temporary-file-directory
) temporary-file-directory
)
47 "*Where nnsoup will store temporary files.")
49 (defvoo nnsoup-replies-directory
(expand-file-name "replies/" nnsoup-directory
)
50 "*Directory where outgoing packets will be composed.")
52 (defvoo nnsoup-replies-format-type ?u
;; u is USENET news format.
53 "*Format of the replies packages.")
55 (defvoo nnsoup-replies-index-type ?n
56 "*Index type of the replies packages.")
58 (defvoo nnsoup-active-file
(expand-file-name "active" nnsoup-directory
)
61 (defvoo nnsoup-packer
(concat "tar cf - %s | gzip > "
62 (expand-file-name gnus-home-directory
)
64 "Format string command for packing a SOUP packet.
65 The SOUP files will be inserted where the %s is in the string.
66 This string MUST contain both %s and %d. The file number will be
67 inserted where %d appears.")
69 (defvoo nnsoup-unpacker
"gunzip -c %s | tar xvf -"
70 "*Format string command for unpacking a SOUP packet.
71 The SOUP packet file name will be inserted at the %s.")
73 (defvoo nnsoup-packet-directory gnus-home-directory
74 "*Where nnsoup will look for incoming packets.")
76 (defvoo nnsoup-packet-regexp
"Soupout"
77 "*Regular expression matching SOUP packets in `nnsoup-packet-directory'.")
79 (defvoo nnsoup-always-save t
80 "If non-nil commit the reply buffer on each message send.
81 This is necessary if using message mode outside Gnus with nnsoup as a
82 backend for the messages.")
86 (defconst nnsoup-version
"nnsoup 0.0"
89 (defvoo nnsoup-status-string
"")
90 (defvoo nnsoup-group-alist nil
)
91 (defvoo nnsoup-current-prefix
0)
92 (defvoo nnsoup-replies-list nil
)
93 (defvoo nnsoup-buffers nil
)
94 (defvoo nnsoup-current-group nil
)
95 (defvoo nnsoup-group-alist-touched nil
)
96 (defvoo nnsoup-article-alist nil
)
99 ;;; Interface functions.
101 (nnoo-define-basics nnsoup
)
103 (deffoo nnsoup-retrieve-headers
(sequence &optional group server fetch-old
)
104 (nnsoup-possibly-change-group group
)
106 (set-buffer nntp-server-buffer
)
108 (let ((areas (cddr (assoc nnsoup-current-group nnsoup-group-alist
)))
111 useful-areas this-area-seq msg-buf
)
112 (if (stringp (car sequence
))
113 ;; We don't support fetching by Message-ID.
115 ;; We go through all the areas and find which files the
116 ;; articles in SEQUENCE come from.
117 (while (and areas sequence
)
118 ;; Peel off areas that are below sequence.
119 (while (and areas
(< (cdar (car areas
)) (car sequence
)))
120 (setq areas
(cdr areas
)))
122 ;; This is a useful area.
123 (push (car areas
) useful-areas
)
124 (setq this-area-seq nil
)
125 ;; We take note whether this MSG has a corresponding IDX
127 (when (or (= (gnus-soup-encoding-index
128 (gnus-soup-area-encoding (nth 1 (car areas
)))) ?n
)
131 (gnus-soup-area-prefix (nth 1 (car areas
)))))))
133 ;; We assign the portion of `sequence' that is relevant to
134 ;; this MSG packet to this packet.
135 (while (and sequence
(<= (car sequence
) (cdar (car areas
))))
136 (push (car sequence
) this-area-seq
)
137 (setq sequence
(cdr sequence
)))
138 (setcar useful-areas
(cons (nreverse this-area-seq
)
139 (car useful-areas
)))))
141 ;; We now have a list of article numbers and corresponding
143 (setq useful-areas
(nreverse useful-areas
))
145 ;; Two different approaches depending on whether all the MSG
146 ;; files have corresponding IDX files. If they all do, we
147 ;; simply return the relevant IDX files and let Gnus sort out
148 ;; what lines are relevant. If some of the IDX files are
149 ;; missing, we must return HEADs for all the articles.
151 ;; We have IDX files for all areas.
154 (goto-char (point-max))
156 (number (car (nth 1 (car useful-areas
))))
157 (index-buffer (nnsoup-index-buffer
158 (gnus-soup-area-prefix
159 (nth 2 (car useful-areas
))))))
161 (insert-buffer-substring index-buffer
)
163 ;; We have to remove the index number entries and
164 ;; insert article numbers instead.
165 (while (looking-at "[0-9]+")
166 (replace-match (int-to-string number
) t t
)
169 (setq useful-areas
(cdr useful-areas
)))
173 (setq articles
(caar useful-areas
)
174 useful-areas
(cdr useful-areas
))
177 (nnsoup-narrow-to-article
178 (car articles
) (cdar useful-areas
) 'head
))
179 (goto-char (point-max))
180 (insert (format "221 %d Article retrieved.\n" (car articles
)))
181 (insert-buffer-substring msg-buf
)
182 (goto-char (point-max))
184 (setq articles
(cdr articles
))))
186 (nnheader-fold-continuation-lines)
189 (deffoo nnsoup-open-server
(server &optional defs
)
190 (nnoo-change-server 'nnsoup server defs
)
191 (when (not (file-exists-p nnsoup-directory
))
193 (make-directory nnsoup-directory t
)
196 ((not (file-exists-p nnsoup-directory
))
197 (nnsoup-close-server)
198 (nnheader-report 'nnsoup
"Couldn't create directory: %s" nnsoup-directory
))
199 ((not (file-directory-p (file-truename nnsoup-directory
)))
200 (nnsoup-close-server)
201 (nnheader-report 'nnsoup
"Not a directory: %s" nnsoup-directory
))
203 (nnsoup-read-active-file)
204 (nnheader-report 'nnsoup
"Opened server %s using directory %s"
205 server nnsoup-directory
)
208 (deffoo nnsoup-request-close
()
209 (nnsoup-write-active-file)
210 (nnsoup-write-replies)
211 (gnus-soup-save-areas)
212 ;; Kill all nnsoup buffers.
214 (while nnsoup-buffers
215 (setq buffer
(cdr (pop nnsoup-buffers
)))
218 (kill-buffer buffer
))))
219 (setq nnsoup-group-alist nil
220 nnsoup-group-alist-touched nil
221 nnsoup-current-group nil
222 nnsoup-replies-list nil
)
223 (nnoo-close-server 'nnoo
)
226 (deffoo nnsoup-request-article
(id &optional newsgroup server buffer
)
227 (nnsoup-possibly-change-group newsgroup
)
230 (set-buffer (or buffer nntp-server-buffer
))
232 (when (and (not (stringp id
))
233 (setq buf
(nnsoup-narrow-to-article id
)))
234 (insert-buffer-substring buf
)
237 (deffoo nnsoup-request-group
(group &optional server dont-check
)
238 (nnsoup-possibly-change-group group
)
241 (let ((active (cadr (assoc group nnsoup-group-alist
))))
243 (nnheader-report 'nnsoup
"No such group: %s" group
)
246 (max (1+ (- (cdr active
) (car active
))) 0)
247 (car active
) (cdr active
) group
)))))
249 (deffoo nnsoup-request-type
(group &optional article
)
250 (nnsoup-possibly-change-group group
)
251 ;; Try to guess the type based on the first article in the group.
254 (cdar (car (cddr (assoc group nnsoup-group-alist
))))))
257 (let ((kind (gnus-soup-encoding-kind
258 (gnus-soup-area-encoding
259 (nth 1 (nnsoup-article-to-area
260 article nnsoup-current-group
))))))
261 (cond ((= kind ?m
) 'mail
)
265 (deffoo nnsoup-close-group
(group &optional server
)
266 ;; Kill all nnsoup buffers.
267 (let ((buffers nnsoup-buffers
)
270 (when (equal (car (setq elem
(pop buffers
))) group
)
271 (setq nnsoup-buffers
(delq elem nnsoup-buffers
))
272 (and (cdr elem
) (buffer-name (cdr elem
))
273 (kill-buffer (cdr elem
))))))
276 (deffoo nnsoup-request-list
(&optional server
)
278 (set-buffer nntp-server-buffer
)
280 (unless nnsoup-group-alist
281 (nnsoup-read-active-file))
282 (let ((alist nnsoup-group-alist
)
283 (standard-output (current-buffer))
285 (while (setq entry
(pop alist
))
286 (insert (car entry
) " ")
287 (princ (cdadr entry
))
289 (princ (caadr entry
))
293 (deffoo nnsoup-request-scan
(group &optional server
)
294 (nnsoup-unpack-packets))
296 (deffoo nnsoup-request-newgroups
(date &optional server
)
297 (nnsoup-request-list))
299 (deffoo nnsoup-request-list-newsgroups
(&optional server
)
302 (deffoo nnsoup-request-post
(&optional server
)
303 (nnsoup-store-reply "news")
306 (deffoo nnsoup-request-mail
(&optional server
)
307 (nnsoup-store-reply "mail")
310 (deffoo nnsoup-request-expire-articles
(articles group
&optional server force
)
311 (nnsoup-possibly-change-group group
)
312 (let* ((total-infolist (assoc group nnsoup-group-alist
))
313 (active (cadr total-infolist
))
314 (infolist (cddr total-infolist
))
315 info range-list mod-time prefix
)
317 (setq info
(pop infolist
)
318 range-list
(gnus-uncompress-range (car info
))
319 prefix
(gnus-soup-area-prefix (nth 1 info
)))
320 (when;; All the articles in this file are marked for expiry.
321 (and (or (setq mod-time
(nth 5 (file-attributes
322 (nnsoup-file prefix
))))
323 (setq mod-time
(nth 5 (file-attributes
324 (nnsoup-file prefix t
)))))
325 (gnus-sublist-p articles range-list
)
326 ;; This file is old enough.
327 (nnmail-expired-article-p group mod-time force
))
328 ;; Ok, we delete this file.
331 5 "Deleting %s in group %s..." (nnsoup-file prefix
)
333 (when (file-exists-p (nnsoup-file prefix
))
334 (delete-file (nnsoup-file prefix
)))
336 5 "Deleting %s in group %s..." (nnsoup-file prefix t
)
338 (when (file-exists-p (nnsoup-file prefix t
))
339 (delete-file (nnsoup-file prefix t
)))
341 (setcdr (cdr total-infolist
) (delq info
(cddr total-infolist
)))
342 (setq articles
(gnus-sorted-difference articles range-list
))))
344 (setcdr (cdr total-infolist
) (delq info
(cddr total-infolist
)))))
345 (if (cddr total-infolist
)
346 (setcar active
(caaadr (cdr total-infolist
)))
347 (setcar active
(1+ (cdr active
))))
348 (nnsoup-write-active-file t
)
349 ;; Return the articles that weren't expired.
353 ;;; Internal functions
355 (defun nnsoup-possibly-change-group (group &optional force
)
357 (not (equal nnsoup-current-group group
)))
358 (setq nnsoup-article-alist nil
)
359 (setq nnsoup-current-group group
))
362 (defun nnsoup-read-active-file ()
363 (setq nnsoup-group-alist nil
)
364 (when (file-exists-p nnsoup-active-file
)
366 (load nnsoup-active-file t t t
))
367 ;; Be backwards compatible.
368 (when (and nnsoup-group-alist
369 (not (atom (caadar nnsoup-group-alist
))))
370 (let ((alist nnsoup-group-alist
)
372 (while (setq e
(cdr (setq entry
(pop alist
))))
376 (setq max
(cdar (car e
)))
377 (setcdr entry
(cons (cons min max
) (cdr entry
)))))
378 (setq nnsoup-group-alist-touched t
))
381 (defun nnsoup-write-active-file (&optional force
)
382 (when (and nnsoup-group-alist
384 nnsoup-group-alist-touched
))
385 (setq nnsoup-group-alist-touched nil
)
386 (with-temp-file nnsoup-active-file
387 (gnus-prin1 `(setq nnsoup-group-alist
',nnsoup-group-alist
))
389 (gnus-prin1 `(setq nnsoup-current-prefix
,nnsoup-current-prefix
))
392 (defun nnsoup-next-prefix ()
393 "Return the next free prefix."
395 (while (or (file-exists-p
396 (nnsoup-file (setq prefix
(int-to-string
397 nnsoup-current-prefix
))))
398 (file-exists-p (nnsoup-file prefix t
)))
399 (incf nnsoup-current-prefix
))
400 (incf nnsoup-current-prefix
)
403 (defun nnsoup-file-name (dir file
)
404 "Return the full name of FILE (in any case) in DIR."
405 (let* ((case-fold-search t
)
406 (files (directory-files dir t
))
407 (regexp (concat (regexp-quote file
) "$")))
411 (if (string-match regexp file
)
416 (defun nnsoup-read-areas ()
417 (let ((areas-file (nnsoup-file-name nnsoup-tmp-directory
"areas")))
420 (set-buffer nntp-server-buffer
)
421 (let ((areas (gnus-soup-parse-areas areas-file
))
422 entry number area lnum cur-prefix file
)
423 ;; Go through all areas in the new AREAS file.
424 (while (setq area
(pop areas
))
425 ;; Change the name to the permanent name and move the files.
426 (setq cur-prefix
(nnsoup-next-prefix))
427 (nnheader-message 5 "Incorporating file %s..." cur-prefix
)
431 (concat (gnus-soup-area-prefix area
) ".IDX")
432 nnsoup-tmp-directory
)))
433 (rename-file file
(nnsoup-file cur-prefix
)))
435 (setq file
(expand-file-name
436 (concat (gnus-soup-area-prefix area
) ".MSG")
437 nnsoup-tmp-directory
)))
438 (rename-file file
(nnsoup-file cur-prefix t
))
439 (gnus-soup-set-area-prefix area cur-prefix
)
440 ;; Find the number of new articles in this area.
441 (setq number
(nnsoup-number-of-articles area
))
442 (if (not (setq entry
(assoc (gnus-soup-area-name area
)
443 nnsoup-group-alist
)))
444 ;; If this is a new area (group), we just add this info to
446 (push (list (gnus-soup-area-name area
)
448 (list (cons 1 number
) area
))
450 ;; There are already articles in this group, so we add this
451 ;; info to the end of the entry.
452 (nconc entry
(list (list (cons (1+ (setq lnum
(cdadr entry
)))
455 (setcdr (cadr entry
) (+ lnum number
))))))
456 (nnsoup-write-active-file t
)
457 (delete-file areas-file
)))))
459 (defun nnsoup-number-of-articles (area)
462 ;; If the number is in the area info, we just return it.
463 ((gnus-soup-area-number area
)
464 (gnus-soup-area-number area
))
465 ;; If there is an index file, we just count the lines.
466 ((/= (gnus-soup-encoding-index (gnus-soup-area-encoding area
)) ?n
)
467 (set-buffer (nnsoup-index-buffer (gnus-soup-area-prefix area
)))
468 (count-lines (point-min) (point-max)))
469 ;; We do it the hard way - re-searching through the message
472 (set-buffer (nnsoup-message-buffer (gnus-soup-area-prefix area
)))
473 (unless (assoc (gnus-soup-area-prefix area
) nnsoup-article-alist
)
474 (nnsoup-dissect-buffer area
))
475 (length (cdr (assoc (gnus-soup-area-prefix area
)
476 nnsoup-article-alist
)))))))
478 (defun nnsoup-dissect-buffer (area)
479 (let ((mbox-delim (concat "^" message-unix-mail-delimiter
))
480 (format (gnus-soup-encoding-format (gnus-soup-area-encoding area
)))
483 (goto-char (point-min))
485 ;; rnews batch format
487 (= format ?n
)) ;; Gnus back compatibility.
488 (while (looking-at "^#! *rnews \\(+[0-9]+\\) *$")
493 (forward-char (string-to-number (match-string 1)))
498 (while (looking-at mbox-delim
)
503 (if (re-search-forward mbox-delim nil t
)
505 (goto-char (point-max)))
510 (while (looking-at "\^A\^A\^A\^A\n")
515 (if (search-forward "\n\^A\^A\^A\^A\n" nil t
)
517 (goto-char (point-max)))
521 ((or (= format ?B
) (= format ?b
))
523 (setq len
(+ (* (char-after (point)) (expt 2.0 24))
524 (* (char-after (+ (point) 1)) (expt 2 16))
525 (* (char-after (+ (point) 2)) (expt 2 8))
526 (char-after (+ (point) 3))))
528 (incf i
) (+ (point) 4)
530 (forward-char (floor (+ len
4)))
534 (error "Unknown format: %c" format
)))
535 (push (cons (gnus-soup-area-prefix area
) alist
) nnsoup-article-alist
)))
537 (defun nnsoup-index-buffer (prefix &optional message
)
538 (let* ((file (concat prefix
(if message
".MSG" ".IDX")))
539 (buffer-name (concat " *nnsoup " file
"*")))
540 (or (get-buffer buffer-name
) ; File already loaded.
541 (when (file-exists-p (expand-file-name file nnsoup-directory
))
542 (save-excursion ; Load the file.
543 (set-buffer (get-buffer-create buffer-name
))
544 (buffer-disable-undo)
545 (push (cons nnsoup-current-group
(current-buffer)) nnsoup-buffers
)
546 (nnheader-insert-file-contents
547 (expand-file-name file nnsoup-directory
))
548 (current-buffer))))))
550 (defun nnsoup-file (prefix &optional message
)
552 (concat prefix
(if message
".MSG" ".IDX"))
555 (defun nnsoup-message-buffer (prefix)
556 (nnsoup-index-buffer prefix
'msg
))
558 (defun nnsoup-unpack-packets ()
559 "Unpack all packets in `nnsoup-packet-directory'."
560 (let ((packets (directory-files
561 nnsoup-packet-directory t nnsoup-packet-regexp
))
563 (while (setq packet
(pop packets
))
564 (nnheader-message 5 "nnsoup: unpacking %s..." packet
)
565 (if (not (gnus-soup-unpack-packet
566 nnsoup-tmp-directory nnsoup-unpacker packet
))
567 (nnheader-message 5 "Couldn't unpack %s" packet
)
570 (nnheader-message 5 "Unpacking...done")))))
572 (defun nnsoup-narrow-to-article (article &optional area head
)
573 (let* ((area (or area
(nnsoup-article-to-area article nnsoup-current-group
)))
574 (prefix (and area
(gnus-soup-area-prefix (nth 1 area
))))
575 (msg-buf (and prefix
(nnsoup-index-buffer prefix
'msg
)))
580 ;; There is no MSG file.
583 ;; We use the index file to find out where the article
585 ((and (= (gnus-soup-encoding-index
586 (gnus-soup-area-encoding (nth 1 area
)))
588 (file-exists-p (nnsoup-file prefix
)))
589 (set-buffer (nnsoup-index-buffer prefix
))
591 (goto-char (point-min))
592 (forward-line (- article
(caar area
)))
593 (setq beg
(read (current-buffer)))
595 (if (looking-at "[0-9]+")
597 (setq end
(read (current-buffer)))
600 (let ((format (gnus-soup-encoding-format
601 (gnus-soup-area-encoding (nth 1 area
)))))
603 (when (or (= format ?u
) (= format ?n
) (= format ?m
))
604 (setq end
(progn (forward-line -
1) (point))))))
605 (set-buffer msg-buf
))
607 (narrow-to-region beg
(or end
(point-max))))
611 (unless (assoc (gnus-soup-area-prefix (nth 1 area
))
612 nnsoup-article-alist
)
613 (nnsoup-dissect-buffer (nth 1 area
)))
614 (let ((entry (assq article
(cdr (assoc (gnus-soup-area-prefix
616 nnsoup-article-alist
)))))
618 (narrow-to-region (cadr entry
) (caddr entry
))))))
619 (goto-char (point-min))
624 (if (search-forward "\n\n" nil t
)
630 (defun nnsoup-pack-replies ()
631 "Make an outbound package of SOUP replies."
633 (unless (file-exists-p nnsoup-replies-directory
)
634 (nnheader-message 5 "No such directory: %s" nnsoup-replies-directory
))
635 ;; Write all data buffers.
636 (gnus-soup-save-areas)
637 ;; Write the active file.
638 (nnsoup-write-active-file)
639 ;; Write the REPLIES file.
640 (nnsoup-write-replies)
641 ;; Check whether there is anything here.
642 (when (null (directory-files nnsoup-replies-directory nil
"\\.MSG$"))
643 (error "No files to pack"))
644 ;; Pack all these files into a SOUP packet.
645 (gnus-soup-pack nnsoup-replies-directory nnsoup-packer
))
647 (defun nnsoup-write-replies ()
648 "Write the REPLIES file."
649 (when nnsoup-replies-list
650 (gnus-soup-write-replies nnsoup-replies-directory nnsoup-replies-list
)
651 (setq nnsoup-replies-list nil
)))
653 (defun nnsoup-article-to-area (article group
)
654 "Return the area that ARTICLE in GROUP is located in."
655 (let ((areas (cddr (assoc group nnsoup-group-alist
))))
656 (while (and areas
(< (cdar (car areas
)) article
))
657 (setq areas
(cdr areas
)))
658 (and areas
(car areas
))))
660 (defvar nnsoup-old-functions
661 (list message-send-mail-real-function message-send-news-function
))
664 (defun nnsoup-set-variables ()
665 "Use the SOUP methods for posting news and mailing mail."
667 (setq message-send-news-function
'nnsoup-request-post
)
668 (setq message-send-mail-real-function
'nnsoup-request-mail
))
671 (defun nnsoup-revert-variables ()
672 "Revert posting and mailing methods to the standard Emacs methods."
674 (setq message-send-mail-real-function
(car nnsoup-old-functions
))
675 (setq message-send-news-function
(cadr nnsoup-old-functions
)))
677 (defun nnsoup-store-reply (kind)
678 ;; Mostly stolen from `message.el'.
679 (require 'mail-utils
)
680 (let ((tembuf (generate-new-buffer " message temp"))
681 (case-fold-search nil
)
683 (mailbuf (current-buffer)))
687 (message-narrow-to-headers)
688 (if (equal kind
"mail")
689 (message-generate-headers message-required-mail-headers
)
690 (message-generate-headers message-required-news-headers
)))
693 (insert-buffer-substring mailbuf
)
694 ;; Remove some headers.
696 (message-narrow-to-headers)
697 ;; Remove some headers.
698 (message-remove-header message-ignored-mail-headers t
))
699 (goto-char (point-max))
700 ;; require one newline at the end.
701 (or (= (preceding-char) ?
\n)
703 (let ((case-fold-search t
))
704 ;; Change header-delimiter to be what sendmail expects.
705 (goto-char (point-min))
707 (concat "^" (regexp-quote mail-header-separator
) "\n"))
710 (setq delimline
(point-marker))
711 (goto-char (1+ delimline
))
714 nnsoup-replies-directory
715 (nnsoup-kind-to-prefix kind
) nil nnsoup-replies-format-type
716 nnsoup-replies-index-type
))
718 (when (and msg-buf
(bufferp msg-buf
))
721 (goto-char (point-min))
722 (while (re-search-forward "^#! *rnews" nil t
)
724 (when nnsoup-always-save
726 (nnheader-message 5 "Stored %d messages" num
)))
727 (nnsoup-write-replies)
728 (kill-buffer tembuf
))))))
730 (defun nnsoup-kind-to-prefix (kind)
731 (unless nnsoup-replies-list
732 (setq nnsoup-replies-list
733 (gnus-soup-parse-replies
734 (expand-file-name "REPLIES" nnsoup-replies-directory
))))
735 (let ((replies nnsoup-replies-list
))
737 (not (string= kind
(gnus-soup-reply-kind (car replies
)))))
738 (setq replies
(cdr replies
)))
740 (gnus-soup-reply-prefix (car replies
))
741 (push (vector (gnus-soup-unique-prefix nnsoup-replies-directory
)
744 nnsoup-replies-format-type
745 nnsoup-replies-index-type
746 (if (string= kind
"news")
749 (gnus-soup-reply-prefix (car nnsoup-replies-list
)))))
751 (defun nnsoup-make-active ()
752 "(Re-)create the SOUP active file."
754 (let ((files (sort (directory-files nnsoup-directory t
"IDX$")
756 (< (progn (string-match "/\\([0-9]+\\)\\." f1
)
757 (string-to-number (match-string 1 f1
)))
758 (progn (string-match "/\\([0-9]+\\)\\." f2
)
759 (string-to-number (match-string 1 f2
)))))))
760 active group lines ident elem min
)
761 (set-buffer (get-buffer-create " *nnsoup work*"))
763 (nnheader-message 5 "Doing %s..." (car files
))
765 (nnheader-insert-file-contents (car files
))
766 (goto-char (point-min))
767 (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
))
768 (setq group
"unknown")
769 (setq group
(match-string 2)))
770 (setq lines
(count-lines (point-min) (point-max)))
771 (setq ident
(progn (string-match
772 "/\\([0-9]+\\)\\." (car files
))
774 (car files
) (match-beginning 1)
776 (if (not (setq elem
(assoc group active
)))
777 (push (list group
(cons 1 lines
)
779 (vector ident group
"ucm" "" lines
)))
783 (list (cons (1+ (setq min
(cdadr elem
)))
785 (vector ident group
"ucm" "" lines
))))
786 (setcdr (cadr elem
) (+ min lines
)))
787 (setq files
(cdr files
)))
788 (nnheader-message 5 "")
789 (setq nnsoup-group-alist active
)
790 (nnsoup-write-active-file t
)))
792 (defun nnsoup-delete-unreferenced-message-files ()
793 "Delete any *.MSG and *.IDX files that aren't known by nnsoup."
795 (let* ((known (apply 'nconc
(mapcar
799 (gnus-soup-area-prefix (cadr area
)))
801 nnsoup-group-alist
)))
802 (regexp "\\.MSG$\\|\\.IDX$")
803 (files (directory-files nnsoup-directory nil regexp
))
805 ;; Find all files that aren't known by nnsoup.
806 (while (setq file
(pop files
))
807 (string-match regexp file
)
808 (unless (member (substring file
0 (match-beginning 0)) known
)
809 (push file non-files
)))
810 ;; Sort and delete the files.
811 (setq non-files
(sort non-files
'string
<))
812 (map-y-or-n-p "Delete file %s? "
813 (lambda (file) (delete-file
814 (expand-file-name file nnsoup-directory
)))
819 ;;; arch-tag: b0451389-5703-4450-9425-f66f6b38c828
820 ;;; nnsoup.el ends here