*** empty log message ***
[gnus] / lisp / nnsoup.el
index cb98ace..fcf2c62 100644 (file)
 (require 'nnmail)
 (require 'gnus-soup)
 (require 'gnus-msg)
+(require 'nnoo)
 (eval-when-compile (require 'cl))
 
-(defvar nnsoup-directory "~/SOUP/"
+(nnoo-declare nnsoup)
+
+(defvoo nnsoup-directory "~/SOUP/"
   "*SOUP packet directory.")
 
-(defvar nnsoup-tmp-directory "/tmp/"
+(defvoo nnsoup-tmp-directory "/tmp/"
   "*Where nnsoup will store temporary files.")
 
-(defvar nnsoup-replies-directory (concat nnsoup-directory "replies/")
+(defvoo nnsoup-replies-directory (concat nnsoup-directory "replies/")
   "*Directory where outgoing packets will be composed.")
 
-(defvar nnsoup-replies-format-type ?n
+(defvoo nnsoup-replies-format-type ?n
   "*Format of the replies packages.")
 
-(defvar nnsoup-replies-index-type ?n
+(defvoo nnsoup-replies-index-type ?n
   "*Index type of the replies packages.")
 
-(defvar nnsoup-active-file (concat nnsoup-directory "active")
+(defvoo nnsoup-active-file (concat nnsoup-directory "active")
   "Active file.")
 
-(defvar nnsoup-packer "tar cf - %s | gzip > $HOME/Soupin%d.tgz"
+(defvoo nnsoup-packer "tar cf - %s | gzip > $HOME/Soupin%d.tgz"
   "Format string command for packing a SOUP packet.
 The SOUP files will be inserted where the %s is in the string.
-This string MUST contain both %s and %d. The file number will be
+This string MUST contain both %s and %d.  The file number will be
 inserted where %d appears.")
 
-(defvar nnsoup-unpacker "gunzip -c %s | tar xvf -"
+(defvoo nnsoup-unpacker "gunzip -c %s | tar xvf -"
   "*Format string command for unpacking a SOUP packet.
 The SOUP packet file name will be inserted at the %s.")
 
-(defvar nnsoup-packet-directory "~/"
+(defvoo nnsoup-packet-directory "~/"
   "*Where nnsoup will look for incoming packets.")
 
-(defvar nnsoup-packet-regexp "Soupout"
+(defvoo nnsoup-packet-regexp "Soupout"
   "*Regular expression matching SOUP packets in `nnsoup-packet-directory'.")
 
 \f
@@ -71,31 +74,21 @@ The SOUP packet file name will be inserted at the %s.")
 (defconst nnsoup-version "nnsoup 0.0"
   "nnsoup version.")
 
-(defvar nnsoup-status-string "")
-(defvar nnsoup-group-alist nil)
-(defvar nnsoup-current-prefix 0)
-(defvar nnsoup-replies-list nil)
-(defvar nnsoup-buffers nil)
-(defvar nnsoup-current-group nil)
-
-\f
-
-;; Server variables.
-
-(defvar nnsoup-current-server nil)
-(defvar nnsoup-server-alist nil)
-(defvar nnsoup-server-variables 
-  `((nnsoup-directory ,nnsoup-directory)
-    (nnsoup-active-file ,nnsoup-active-file)
-    (nnsoup-status-string "")
-    (nnsoup-current-prefix 0)
-    (nnsoup-group-alist nil)))
+(defvoo nnsoup-status-string "")
+(defvoo nnsoup-group-alist nil)
+(defvoo nnsoup-current-prefix 0)
+(defvoo nnsoup-replies-list nil)
+(defvoo nnsoup-buffers nil)
+(defvoo nnsoup-current-group nil)
+(defvoo nnsoup-group-alist-touched nil)
 
 \f
 
 ;;; Interface functions.
 
-(defun nnsoup-retrieve-headers (sequence &optional group server fetch-old)
+(nnoo-define-basics nnsoup)
+
+(deffoo nnsoup-retrieve-headers (sequence &optional group server fetch-old)
   (nnsoup-possibly-change-group group)
   (save-excursion
     (set-buffer nntp-server-buffer)
@@ -111,7 +104,7 @@ The SOUP packet file name will be inserted at the %s.")
        ;; articles in SEQUENCE come from.
        (while (and areas sequence)
          ;; Peel off areas that are below sequence.
-         (while (and areas (< (cdr (car (car areas))) (car sequence)))
+         (while (and areas (< (cdaar areas) (car sequence)))
            (setq areas (cdr areas)))
          (when areas
            ;; This is a useful area.
@@ -127,7 +120,7 @@ The SOUP packet file name will be inserted at the %s.")
              (setq use-nov nil))
            ;; We assign the portion of `sequence' that is relevant to
            ;; this MSG packet to this packet.
-           (while (and sequence (<= (car sequence) (cdr (car (car areas)))))
+           (while (and sequence (<= (car sequence) (cdaar areas)))
              (push (car sequence) this-area-seq)
              (setq sequence (cdr sequence)))
            (setcar useful-areas (cons (nreverse this-area-seq)
@@ -165,12 +158,12 @@ The SOUP packet file name will be inserted at the %s.")
              'nov)
          ;; We insert HEADs.
          (while useful-areas
-           (setq articles (car (car useful-areas))
+           (setq articles (caar useful-areas)
                  useful-areas (cdr useful-areas))
            (while articles
              (when (setq msg-buf
                          (nnsoup-narrow-to-article 
-                          (car articles) (cdr (car useful-areas)) 'head))
+                          (car articles) (cdar useful-areas) 'head))
                (goto-char (point-max))
                (insert (format "221 %d Article retrieved.\n" (car articles)))
                (insert-buffer-substring msg-buf)
@@ -181,8 +174,8 @@ The SOUP packet file name will be inserted at the %s.")
          (nnheader-fold-continuation-lines)
          'headers)))))
 
-(defun nnsoup-open-server (server &optional defs)
-  (nnheader-change-server 'nnsoup server defs)
+(deffoo nnsoup-open-server (server &optional defs)
+  (nnoo-change-server 'nnsoup server defs)
   (when (not (file-exists-p nnsoup-directory))
     (condition-case ()
        (make-directory nnsoup-directory t)
@@ -200,12 +193,7 @@ The SOUP packet file name will be inserted at the %s.")
                     server nnsoup-directory)
     t)))
 
-(defun nnsoup-close-server (&optional server)
-  (setq nnsoup-current-server nil
-       nnsoup-group-alist nil)
-  t)
-
-(defun nnsoup-request-close ()
+(deffoo nnsoup-request-close ()
   (nnsoup-write-active-file)
   (nnsoup-write-replies)
   (gnus-soup-save-areas)
@@ -217,33 +205,24 @@ The SOUP packet file name will be inserted at the %s.")
           (buffer-name buffer)
           (kill-buffer buffer))))
   (setq nnsoup-group-alist nil
+       nnsoup-group-alist-touched nil
        nnsoup-current-group nil
-       nnsoup-current-server nil
-       nnsoup-server-alist nil
        nnsoup-replies-list nil)
+  (nnoo-close-server 'nnoo)
   t)
 
-(defun nnsoup-server-opened (&optional server)
-  (and (equal server nnsoup-current-server)
-       nntp-server-buffer
-       (buffer-name nntp-server-buffer)))
-
-(defun nnsoup-status-message (&optional server)
-  nnsoup-status-string)
-
-(defun nnsoup-request-article (id &optional newsgroup server buffer)
+(deffoo nnsoup-request-article (id &optional newsgroup server buffer)
   (nnsoup-possibly-change-group newsgroup)
-  (let ((buffer (or buffer nntp-server-buffer)))
+  (let (buf)
     (save-excursion
-      (set-buffer buffer)
+      (set-buffer (or buffer nntp-server-buffer))
       (erase-buffer)
-      (if (stringp id)
-         ()
-       (insert-buffer-substring
-        (nnsoup-narrow-to-article id))
+      (when (and (not (stringp id))
+                (setq buf (nnsoup-narrow-to-article id)))
+       (insert-buffer-substring buf)
        t))))
 
-(defun nnsoup-request-group (group &optional server dont-check)
+(deffoo nnsoup-request-group (group &optional server dont-check)
   (nnsoup-possibly-change-group group)
   (if dont-check 
       t
@@ -255,7 +234,7 @@ The SOUP packet file name will be inserted at the %s.")
         (max (1+ (- (cdr active) (car active))) 0) 
         (car active) (cdr active) group)))))
 
-(defun nnsoup-request-type (group &optional article)
+(deffoo nnsoup-request-type (group &optional article)
   (nnsoup-possibly-change-group group)
   (if (not article)
       'unknown
@@ -267,7 +246,7 @@ The SOUP packet file name will be inserted at the %s.")
            ((= kind ?n) 'news)
            (t 'unknown)))))
 
-(defun nnsoup-close-group (group &optional server)
+(deffoo nnsoup-close-group (group &optional server)
   ;; Kill all nnsoup buffers.
   (let ((buffers nnsoup-buffers)
        elem)
@@ -278,35 +257,41 @@ The SOUP packet file name will be inserted at the %s.")
             (kill-buffer (cdr elem))))))
   t)
 
-(defun nnsoup-request-list (&optional server)
+(deffoo nnsoup-request-list (&optional server)
   (save-excursion
     (set-buffer nntp-server-buffer)
     (erase-buffer)
+    (unless nnsoup-group-alist
+      (nnsoup-read-active-file))
     (let ((alist nnsoup-group-alist)
+         (standard-output (current-buffer))
          entry)
       (while (setq entry (pop alist))
-       (insert (format "%s %d %d y\n" (car entry)
-                       (cdadr entry) (caadr entry))))
+       (insert (car entry) " ")
+       (princ (cdadr entry))
+       (insert " ")
+       (princ (caadr entry))
+       (insert " y\n"))
       t)))
 
-(defun nnsoup-request-scan (group &optional server)
+(deffoo nnsoup-request-scan (group &optional server)
   (nnsoup-unpack-packets))
 
-(defun nnsoup-request-newgroups (date &optional server)
+(deffoo nnsoup-request-newgroups (date &optional server)
   (nnsoup-request-list))
 
-(defun nnsoup-request-list-newsgroups (&optional server)
+(deffoo nnsoup-request-list-newsgroups (&optional server)
   nil)
 
-(defun nnsoup-request-post (&optional server)
+(deffoo nnsoup-request-post (&optional server)
   (nnsoup-store-reply "news")
   t)
 
-(defun nnsoup-request-mail ()
+(deffoo nnsoup-request-mail (&optional server)
   (nnsoup-store-reply "mail")
   t)
 
-(defun nnsoup-request-expire-articles (articles group &optional server force)
+(deffoo nnsoup-request-expire-articles (articles group &optional server force)
   (nnsoup-possibly-change-group group)
   (let* ((total-infolist (assoc group nnsoup-group-alist))
         (active (cadr total-infolist))
@@ -344,9 +329,9 @@ The SOUP packet file name will be inserted at the %s.")
       (when (not mod-time)
        (setcdr (cdr total-infolist) (delq info (cddr total-infolist)))))
     (if (cddr total-infolist)
-       (setcar active (car (car (car (cdr (cdr total-infolist))))))
+       (setcar active (caaadr (cdr total-infolist)))
       (setcar active (1+ (cdr active))))
-    (nnsoup-write-active-file)
+    (nnsoup-write-active-file t)
     ;; Return the articles that weren't expired.
     articles))
 
@@ -359,10 +344,10 @@ The SOUP packet file name will be inserted at the %s.")
     t))
 
 (defun nnsoup-read-active-file ()
-  (setq nnsoup-group-alist)
+  (setq nnsoup-group-alist nil)
   (when (file-exists-p nnsoup-active-file)
     (condition-case ()
-       (load nnsoup-active-file)
+       (load nnsoup-active-file t t t)
       (error nil))
     ;; Be backwards compatible.
     (when (and nnsoup-group-alist
@@ -374,21 +359,20 @@ The SOUP packet file name will be inserted at the %s.")
          (while (cdr e)
            (setq e (cdr e)))
          (setq max (cdaar e))
-         (setcdr entry (cons (cons min max) (cdr entry))))))
+         (setcdr entry (cons (cons min max) (cdr entry)))))
+      (setq nnsoup-group-alist-touched t))
     nnsoup-group-alist))
 
-(defun nnsoup-write-active-file ()
-  (when nnsoup-group-alist
-    (save-excursion
-      (set-buffer (get-buffer-create " *nnsoup work*"))
-      (buffer-disable-undo (current-buffer))
-      (erase-buffer)
-      (insert (format "(setq nnsoup-group-alist '%S)\n" nnsoup-group-alist))
-      (insert (format "(setq nnsoup-current-prefix %d)\n"
-                     nnsoup-current-prefix))
-      (write-region (point-min) (point-max) nnsoup-active-file
-                   nil 'silent)
-      (kill-buffer (current-buffer)))))
+(defun nnsoup-write-active-file (&optional force)
+  (when (and nnsoup-group-alist
+            (or force 
+                nnsoup-group-alist-touched))
+    (setq nnsoup-group-alist-touched nil)
+    (nnheader-temp-write nnsoup-active-file
+      (gnus-prin1 `(setq nnsoup-group-alist ',nnsoup-group-alist))
+      (insert "\n")
+      (gnus-prin1 `(setq nnsoup-current-prefix ,nnsoup-current-prefix))
+      (insert "\n"))))
 
 (defun nnsoup-next-prefix ()
   "Return the next free prefix."
@@ -436,7 +420,7 @@ The SOUP packet file name will be inserted at the %s.")
                                           (+ lnum number))
                                     area)))
            (setcdr (cadr entry) (+ lnum number))))))
-    (nnsoup-write-active-file)
+    (nnsoup-write-active-file t)
     (delete-file (concat nnsoup-tmp-directory "AREAS"))))
 
 (defun nnsoup-number-of-articles (area)
@@ -464,9 +448,9 @@ The SOUP packet file name will be inserted at the %s.")
 (defun nnsoup-index-buffer (prefix &optional message)
   (let* ((file (concat prefix (if message ".MSG" ".IDX")))
         (buffer-name (concat " *nnsoup " file "*")))
-    (or (get-buffer buffer-name)       ; File aready loaded.
+    (or (get-buffer buffer-name)       ; File already loaded.
        (when (file-exists-p (concat nnsoup-directory file))
-         (save-excursion                       ; Load the file.
+         (save-excursion               ; Load the file.
            (set-buffer (get-buffer-create buffer-name))
            (buffer-disable-undo (current-buffer))
            (push (cons nnsoup-current-group (current-buffer)) nnsoup-buffers)
@@ -496,68 +480,69 @@ The SOUP packet file name will be inserted at the %s.")
 
 (defun nnsoup-narrow-to-article (article &optional area head)
   (let* ((area (or area (nnsoup-article-to-area article nnsoup-current-group)))
-        (prefix (gnus-soup-area-prefix (nth 1 area)))
-        (msg-buf (nnsoup-index-buffer prefix 'msg))
+        (prefix (and area (gnus-soup-area-prefix (nth 1 area))))
+        (msg-buf (and prefix (nnsoup-index-buffer prefix 'msg)))
         beg end)
-    (save-excursion
-      (cond
-       ;; There is no MSG file.
-       ((null msg-buf)
-       nil)
+    (when area
+      (save-excursion
+       (cond
+        ;; There is no MSG file.
+        ((null msg-buf)
+         nil)
        
-       ;; We use the index file to find out where the article begins and ends. 
-       ((and (= (gnus-soup-encoding-index 
-                (gnus-soup-area-encoding (nth 1 area)))
-               ?c)
-            (file-exists-p (nnsoup-file prefix)))
-       (set-buffer (nnsoup-index-buffer prefix))
-       (widen)
+        ;; We use the index file to find out where the article begins and ends. 
+        ((and (= (gnus-soup-encoding-index 
+                  (gnus-soup-area-encoding (nth 1 area)))
+                 ?c)
+              (file-exists-p (nnsoup-file prefix)))
+         (set-buffer (nnsoup-index-buffer prefix))
+         (widen)
+         (goto-char (point-min))
+         (forward-line (- article (caar area)))
+         (setq beg (read (current-buffer)))
+         (forward-line 1)
+         (if (looking-at "[0-9]+")
+             (progn
+               (setq end (read (current-buffer)))
+               (set-buffer msg-buf)
+               (widen)
+               (let ((format (gnus-soup-encoding-format
+                              (gnus-soup-area-encoding (nth 1 area)))))
+                 (goto-char end)
+                 (if (or (= format ?n) (= format ?m))
+                     (setq end (progn (forward-line -1) (point))))))
+           (set-buffer msg-buf))
+         (widen)
+         (narrow-to-region beg (or end (point-max))))
+        (t
+         (set-buffer msg-buf)
+         (widen)
+         (goto-char (point-min))
+         (let ((header (nnsoup-header 
+                        (gnus-soup-encoding-format 
+                         (gnus-soup-area-encoding (nth 1 area))))))
+           (re-search-forward header nil t (- article (caar area)))
+           (narrow-to-region
+            (match-beginning 0)
+            (if (re-search-forward header nil t)
+                (match-beginning 0)
+              (point-max))))))
        (goto-char (point-min))
-       (forward-line (- article (car (car area))))
-       (setq beg (read (current-buffer)))
-       (forward-line 1)
-       (if (looking-at "[0-9]+")
-           (progn
-             (setq end (read (current-buffer)))
-             (set-buffer msg-buf)
-             (widen)
-             (let ((format (gnus-soup-encoding-format
-                            (gnus-soup-area-encoding (nth 1 area)))))
-               (goto-char end)
-               (if (or (= format ?n) (= format ?m))
-                   (setq end (progn (forward-line -1) (point))))))
-         (set-buffer msg-buf))
-       (widen)
-       (narrow-to-region beg (or end (point-max))))
-       (t
-       (set-buffer msg-buf)
-       (widen)
-       (goto-char (point-min))
-       (let ((header (nnsoup-header 
-                      (gnus-soup-encoding-format 
-                       (gnus-soup-area-encoding (nth 1 area))))))
-         (re-search-forward header nil t (- article (car (car area))))
+       (if (not head)
+           ()
          (narrow-to-region
-          (match-beginning 0)
-          (if (re-search-forward header nil t)
-              (match-beginning 0)
-            (point-max))))))
-      (goto-char (point-min))
-      (if (not head)
-         ()
-       (narrow-to-region
-        (point-min)
-        (if (search-forward "\n\n" nil t)
-            (1- (point))
-          (point-max))))
-      msg-buf)))
+          (point-min)
+          (if (search-forward "\n\n" nil t)
+              (1- (point))
+            (point-max))))
+       msg-buf))))
 
 (defun nnsoup-header (format)
   (cond 
    ((= format ?n)
     "^#! *rnews +[0-9]+ *$")
    ((= format ?m)
-    (concat "^" rmail-unix-mail-delimiter))
+    (concat "^" message-unix-mail-delimiter))
    ((= format ?M)
     "^\^A\^A\^A\^A\n")
    (t
@@ -585,90 +570,81 @@ The SOUP packet file name will be inserted at the %s.")
 (defun nnsoup-article-to-area (article group)
   "Return the area that ARTICLE in GROUP is located in."
   (let ((areas (cddr (assoc group nnsoup-group-alist))))
-    (while (and areas (< (cdr (car (car areas))) article))
+    (while (and areas (< (cdaar areas) article))
       (setq areas (cdr areas)))
     (and areas (car areas))))
 
 (defvar nnsoup-old-functions
-  (list gnus-inews-article-function send-mail-function))
+  (list message-send-mail-function message-send-news-function))
 
 ;;;###autoload
 (defun nnsoup-set-variables ()
   "Use the SOUP methods for posting news and mailing mail."
   (interactive)
-  (setq gnus-inews-article-function 'nnsoup-request-post)
-  (setq send-mail-function 'nnsoup-request-mail))
+  (setq message-send-news-function 'nnsoup-request-post)
+  (setq message-send-mail-function 'nnsoup-request-mail))
 
 ;;;###autoload
 (defun nnsoup-revert-variables ()
   "Revert posting and mailing methods to the standard Emacs methods."
   (interactive)
-  (setq gnus-inews-article-function (car nnsoup-old-functions))
-  (setq send-mail-function (cadr nnsoup-old-functions)))
+  (setq message-send-mail-function (car nnsoup-old-functions))
+  (setq message-send-news-function (cadr nnsoup-old-functions)))
 
 (defun nnsoup-store-reply (kind)
-  ;; Mostly stolen from `sendmail.el'.
-  (let ((tembuf (generate-new-buffer " sendmail temp"))
+  ;; Mostly stolen from `message.el'.
+  (require 'mail-utils)
+  (let ((tembuf (generate-new-buffer " message temp"))
        (case-fold-search nil)
-       (mailbuf (current-buffer))
-       delimline)
-    (save-excursion
-      (set-buffer tembuf)
-      (erase-buffer)
-      (insert-buffer-substring mailbuf)
-      (goto-char (point-max))
-      ;; require one newline at the end.
-      (or (= (preceding-char) ?\n)
-         (insert ?\n))
-      ;; Change header-delimiter to be what sendmail expects.
-      (goto-char (point-min))
-      (if (re-search-forward
-          (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
-         (replace-match "\n")
-       (search-forward "\n\n" nil t))
-      (backward-char 1)
-      (setq delimline (point-marker))
-      (if mail-aliases (expand-mail-aliases (point-min) delimline))
-      (goto-char (point-min))
-      ;; ignore any blank lines in the header
-      (while (and (re-search-forward "\n\n\n*" delimline t)
-                 (< (point) delimline))
-       (replace-match "\n"))
-      (let ((case-fold-search t))
-       (goto-char (point-min))
-       ;; Find and handle any FCC fields.
-       (goto-char (point-min))
-       (if (re-search-forward "^FCC:" delimline t)
-           (mail-do-fcc delimline))
-       (goto-char (point-min))
-       ;; "S:" is an abbreviation for "Subject:".
-       (goto-char (point-min))
-       (if (re-search-forward "^S:" delimline t)
-           (replace-match "Subject:"))
-       ;; Don't send out a blank subject line
-       (goto-char (point-min))
-       (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
-           (replace-match ""))
-       ;; Insert an extra newline if we need it to work around
-       ;; Sun's bug that swallows newlines.
-       (goto-char (1+ delimline))
-       (if (eval mail-mailer-swallows-blank-line)
-           (newline)))
-      (let ((msg-buf
-            (gnus-soup-store 
-             nnsoup-replies-directory 
-             (nnsoup-kind-to-prefix kind) nil nnsoup-replies-format-type
-             nnsoup-replies-index-type))
-           (num 0))
-       (when (and msg-buf (bufferp msg-buf))
-         (save-excursion
-           (set-buffer msg-buf)
+       delimline
+       (mailbuf (current-buffer)))
+    (unwind-protect
+       (save-excursion
+         (save-restriction
+           (message-narrow-to-headers)
+           (if (equal kind "mail")
+               (message-generate-headers message-required-mail-headers)
+             (message-generate-headers message-required-news-headers)))
+         (set-buffer tembuf)
+         (erase-buffer)
+         (insert-buffer-substring mailbuf)
+         ;; Remove some headers.
+         (save-restriction
+           (message-narrow-to-headers)
+           ;; Remove some headers.
+           (message-remove-header message-ignored-mail-headers t))
+         (goto-char (point-max))
+         ;; require one newline at the end.
+         (or (= (preceding-char) ?\n)
+             (insert ?\n))
+         (let ((case-fold-search t))
+           ;; Change header-delimiter to be what sendmail expects.
            (goto-char (point-min))
-           (while (re-search-forward "^#! *rnews" nil t)
-             (incf num)))
-         (message "Stored %d messages" num)))
-      (nnsoup-write-replies)
-      (kill-buffer tembuf))))
+           (re-search-forward
+            (concat "^" (regexp-quote mail-header-separator) "\n"))
+           (replace-match "\n")
+           (backward-char 1)
+           (setq delimline (point-marker))
+           ;; Insert an extra newline if we need it to work around
+           ;; Sun's bug that swallows newlines.
+           (goto-char (1+ delimline))
+           (when (eval message-mailer-swallows-blank-line)
+             (newline))
+           (let ((msg-buf
+                  (gnus-soup-store 
+                   nnsoup-replies-directory 
+                   (nnsoup-kind-to-prefix kind) nil nnsoup-replies-format-type
+                   nnsoup-replies-index-type))
+                 (num 0))
+             (when (and msg-buf (bufferp msg-buf))
+               (save-excursion
+                 (set-buffer msg-buf)
+                 (goto-char (point-min))
+                 (while (re-search-forward "^#! *rnews" nil t)
+                   (incf num)))
+               (message "Stored %d messages" num)))
+           (nnsoup-write-replies)
+           (kill-buffer tembuf))))))
 
 (defun nnsoup-kind-to-prefix (kind)
   (unless nnsoup-replies-list
@@ -709,9 +685,9 @@ The SOUP packet file name will be inserted at the %s.")
       (erase-buffer)
       (insert-file-contents (car files))
       (goto-char (point-min))
-      (end-of-line)
-      (re-search-backward "[ \t]\\([^ ]+\\):[0-9]")
-      (setq group (buffer-substring (match-beginning 1) (match-end 1)))
+      (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))
+         (setq group "unknown")
+       (setq group (match-string 2)))
       (setq lines (count-lines (point-min) (point-max)))
       (setq ident (progn (string-match
                          "/\\([0-9]+\\)\\." (car files))
@@ -725,18 +701,14 @@ The SOUP packet file name will be inserted at the %s.")
                active)
        (nconc elem
               (list
-               (list (cons (setq min (1+ (cdr (car (car
-                                                    (cdr elem))))))
+               (list (cons (1+ (setq min (cdadr elem)))
                            (+ min lines))
                      (vector ident group "ncm" "" lines))))
        (setcdr (cadr elem) (+ min lines)))
       (setq files (cdr files)))
     (message "")
     (setq nnsoup-group-alist active)
-    (while active
-      (setcdr (car active) (nreverse (cdr (car active))))
-      (setq active (cdr active)))
-    (nnsoup-write-active-file)))
+    (nnsoup-write-active-file t)))
 
 (defun nnsoup-delete-unreferenced-message-files ()
   "Delete any *.MSG and *.IDX files that aren't known by nnsoup."