Fix my last change.
[gnus] / lisp / nnsoup.el
index 7088c64..c6b1925 100644 (file)
@@ -1,7 +1,7 @@
 ;;; nnsoup.el --- SOUP access for Gnus
-;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
+;; Copyright (C) 1995,96,97,98,99 Free Software Foundation, Inc.
 
-;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;;     Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
 ;; Keywords: news, mail
 
 (defvoo nnsoup-directory "~/SOUP/"
   "*SOUP packet directory.")
 
-(defvoo nnsoup-tmp-directory "/tmp/"
+(defvoo nnsoup-tmp-directory
+    (cond ((fboundp 'temp-directory) (temp-directory))
+         ((boundp 'temporary-file-directory) temporary-file-directory)
+         ("/tmp/"))
   "*Where nnsoup will store temporary files.")
 
-(defvoo nnsoup-replies-directory (concat nnsoup-directory "replies/")
+(defvoo nnsoup-replies-directory (expand-file-name "replies/" nnsoup-directory)
   "*Directory where outgoing packets will be composed.")
 
-(defvoo nnsoup-replies-format-type ?n
+(defvoo nnsoup-replies-format-type ?u  ;; u is USENET news format.
   "*Format of the replies packages.")
 
 (defvoo nnsoup-replies-index-type ?n
   "*Index type of the replies packages.")
 
-(defvoo nnsoup-active-file (concat nnsoup-directory "active")
+(defvoo nnsoup-active-file (expand-file-name "active" nnsoup-directory)
   "Active file.")
 
 (defvoo nnsoup-packer "tar cf - %s | gzip > $HOME/Soupin%d.tgz"
@@ -69,6 +72,11 @@ The SOUP packet file name will be inserted at the %s.")
 (defvoo nnsoup-packet-regexp "Soupout"
   "*Regular expression matching SOUP packets in `nnsoup-packet-directory'.")
 
+(defvoo nnsoup-always-save t
+  "If non nil commit the reply buffer on each message send.
+This is necessary if using message mode outside Gnus with nnsoup as a
+backend for the messages.")
+
 \f
 
 (defconst nnsoup-version "nnsoup 0.0"
@@ -82,7 +90,6 @@ The SOUP packet file name will be inserted at the %s.")
 (defvoo nnsoup-current-group nil)
 (defvoo nnsoup-group-alist-touched nil)
 (defvoo nnsoup-article-alist nil)
-
 \f
 
 ;;; Interface functions.
@@ -237,7 +244,7 @@ The SOUP packet file name will be inserted at the %s.")
 
 (deffoo nnsoup-request-type (group &optional article)
   (nnsoup-possibly-change-group group)
-  ;; Try to guess the type based on the first articl ein the group.
+  ;; Try to guess the type based on the first articlin the group.
   (when (not article)
     (setq article
          (cdaar (cddr (assoc group nnsoup-group-alist)))))
@@ -248,7 +255,7 @@ The SOUP packet file name will be inserted at the %s.")
                  (nth 1 (nnsoup-article-to-area
                          article nnsoup-current-group))))))
       (cond ((= kind ?m) 'mail)
-           ((= kind ?n) 'news)
+           ((= kind ?n) 'news) 
            (t 'unknown)))))
 
 (deffoo nnsoup-close-group (group &optional server)
@@ -306,7 +313,7 @@ The SOUP packet file name will be inserted at the %s.")
       (setq info (pop infolist)
            range-list (gnus-uncompress-range (car info))
            prefix (gnus-soup-area-prefix (nth 1 info)))
-      (when ;; All the articles in this file are marked for expiry.
+      (when;; All the articles in this file are marked for expiry.
          (and (or (setq mod-time (nth 5 (file-attributes
                                          (nnsoup-file prefix))))
                   (setq mod-time (nth 5 (file-attributes
@@ -372,7 +379,7 @@ The SOUP packet file name will be inserted at the %s.")
             (or force
                 nnsoup-group-alist-touched))
     (setq nnsoup-group-alist-touched nil)
-    (nnheader-temp-write nnsoup-active-file
+    (with-temp-file nnsoup-active-file
       (gnus-prin1 `(setq nnsoup-group-alist ',nnsoup-group-alist))
       (insert "\n")
       (gnus-prin1 `(setq nnsoup-current-prefix ,nnsoup-current-prefix))
@@ -413,14 +420,17 @@ The SOUP packet file name will be inserted at the %s.")
          (while (setq area (pop areas))
            ;; Change the name to the permanent name and move the files.
            (setq cur-prefix (nnsoup-next-prefix))
-           (message "Incorporating file %s..." cur-prefix)
+           (nnheader-message 5 "Incorporating file %s..." cur-prefix)
            (when (file-exists-p
-                  (setq file (concat nnsoup-tmp-directory
-                                     (gnus-soup-area-prefix area) ".IDX")))
+                  (setq file
+                        (expand-file-name
+                         (concat (gnus-soup-area-prefix area) ".IDX")
+                         nnsoup-tmp-directory)))
              (rename-file file (nnsoup-file cur-prefix)))
            (when (file-exists-p
-                  (setq file (concat nnsoup-tmp-directory
-                                     (gnus-soup-area-prefix area) ".MSG")))
+                  (setq file (expand-file-name
+                              (concat (gnus-soup-area-prefix area) ".MSG")
+                              nnsoup-tmp-directory)))
              (rename-file file (nnsoup-file cur-prefix t))
              (gnus-soup-set-area-prefix area cur-prefix)
              ;; Find the number of new articles in this area.
@@ -469,7 +479,8 @@ The SOUP packet file name will be inserted at the %s.")
     (goto-char (point-min))
     (cond
      ;; rnews batch format
-     ((= format ?n)
+     ((or (= format ?u)
+         (= format ?n)) ;; Gnus back compatibility.
       (while (looking-at "^#! *rnews \\(+[0-9]+\\) *$")
        (forward-line 1)
        (push (list
@@ -523,17 +534,19 @@ The SOUP packet file name will be inserted at the %s.")
   (let* ((file (concat prefix (if message ".MSG" ".IDX")))
         (buffer-name (concat " *nnsoup " file "*")))
     (or (get-buffer buffer-name)       ; File already loaded.
-       (when (file-exists-p (concat nnsoup-directory file))
+       (when (file-exists-p (expand-file-name file nnsoup-directory))
          (save-excursion               ; Load the file.
            (set-buffer (get-buffer-create buffer-name))
-           (buffer-disable-undo (current-buffer))
+           (buffer-disable-undo)
            (push (cons nnsoup-current-group (current-buffer)) nnsoup-buffers)
-           (nnheader-insert-file-contents (concat nnsoup-directory file))
+           (nnheader-insert-file-contents
+            (expand-file-name file nnsoup-directory))
            (current-buffer))))))
 
 (defun nnsoup-file (prefix &optional message)
   (expand-file-name
-   (concat nnsoup-directory prefix (if message ".MSG" ".IDX"))))
+   (concat prefix (if message ".MSG" ".IDX"))
+   nnsoup-directory))
 
 (defun nnsoup-message-buffer (prefix)
   (nnsoup-index-buffer prefix 'msg))
@@ -544,13 +557,13 @@ The SOUP packet file name will be inserted at the %s.")
                  nnsoup-packet-directory t nnsoup-packet-regexp))
        packet)
     (while (setq packet (pop packets))
-      (message "nnsoup: unpacking %s..." packet)
+      (nnheader-message 5 "nnsoup: unpacking %s..." packet)
       (if (not (gnus-soup-unpack-packet
                nnsoup-tmp-directory nnsoup-unpacker packet))
-         (message "Couldn't unpack %s" packet)
+         (nnheader-message 5 "Couldn't unpack %s" packet)
        (delete-file packet)
        (nnsoup-read-areas)
-       (message "Unpacking...done")))))
+       (nnheader-message 5 "Unpacking...done")))))
 
 (defun nnsoup-narrow-to-article (article &optional area head)
   (let* ((area (or area (nnsoup-article-to-area article nnsoup-current-group)))
@@ -583,7 +596,7 @@ The SOUP packet file name will be inserted at the %s.")
                (let ((format (gnus-soup-encoding-format
                               (gnus-soup-area-encoding (nth 1 area)))))
                  (goto-char end)
-                 (when (or (= format ?n) (= format ?m))
+                 (when (or (= format ?u) (= format ?n) (= format ?m))
                    (setq end (progn (forward-line -1) (point))))))
            (set-buffer msg-buf))
          (widen)
@@ -614,7 +627,7 @@ The SOUP packet file name will be inserted at the %s.")
   "Make an outbound package of SOUP replies."
   (interactive)
   (unless (file-exists-p nnsoup-replies-directory)
-    (message "No such directory: %s" nnsoup-replies-directory))
+    (nnheader-message 5 "No such directory: %s" nnsoup-replies-directory))
   ;; Write all data buffers.
   (gnus-soup-save-areas)
   ;; Write the active file.
@@ -623,7 +636,7 @@ The SOUP packet file name will be inserted at the %s.")
   (nnsoup-write-replies)
   ;; Check whether there is anything here.
   (when (null (directory-files nnsoup-replies-directory nil "\\.MSG$"))
-    (error "No files to pack."))
+    (error "No files to pack"))
   ;; Pack all these files into a SOUP packet.
   (gnus-soup-pack nnsoup-replies-directory nnsoup-packer))
 
@@ -691,11 +704,7 @@ The SOUP packet file name will be inserted at the %s.")
            (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
@@ -707,8 +716,10 @@ The SOUP packet file name will be inserted at the %s.")
                  (set-buffer msg-buf)
                  (goto-char (point-min))
                  (while (re-search-forward "^#! *rnews" nil t)
-                   (incf num)))
-               (message "Stored %d messages" num)))
+                   (incf num))
+                 (when nnsoup-always-save
+                   (save-buffer)))
+               (nnheader-message 5 "Stored %d messages" num)))
            (nnsoup-write-replies)
            (kill-buffer tembuf))))))
 
@@ -716,7 +727,7 @@ The SOUP packet file name will be inserted at the %s.")
   (unless nnsoup-replies-list
     (setq nnsoup-replies-list
          (gnus-soup-parse-replies
-          (concat nnsoup-replies-directory "REPLIES"))))
+          (expand-file-name "REPLIES" nnsoup-replies-directory))))
   (let ((replies nnsoup-replies-list))
     (while (and replies
                (not (string= kind (gnus-soup-reply-kind (car replies)))))
@@ -744,9 +755,8 @@ The SOUP packet file name will be inserted at the %s.")
                                 (string-to-int (match-string 1 f2)))))))
        active group lines ident elem min)
     (set-buffer (get-buffer-create " *nnsoup work*"))
-    (buffer-disable-undo (current-buffer))
     (while files
-      (message "Doing %s..." (car files))
+      (nnheader-message 5 "Doing %s..." (car files))
       (erase-buffer)
       (nnheader-insert-file-contents (car files))
       (goto-char (point-min))
@@ -762,16 +772,16 @@ The SOUP packet file name will be inserted at the %s.")
       (if (not (setq elem (assoc group active)))
          (push (list group (cons 1 lines)
                      (list (cons 1 lines)
-                           (vector ident group "ncm" "" lines)))
+                           (vector ident group "ucm" "" lines)))
                active)
        (nconc elem
               (list
                (list (cons (1+ (setq min (cdadr elem)))
                            (+ min lines))
-                     (vector ident group "ncm" "" lines))))
+                     (vector ident group "ucm" "" lines))))
        (setcdr (cadr elem) (+ min lines)))
       (setq files (cdr files)))
-    (message "")
+    (nnheader-message 5 "")
     (setq nnsoup-group-alist active)
     (nnsoup-write-active-file t)))
 
@@ -796,7 +806,8 @@ The SOUP packet file name will be inserted at the %s.")
     ;; Sort and delete the files.
     (setq non-files (sort non-files 'string<))
     (map-y-or-n-p "Delete file %s? "
-                 (lambda (file) (delete-file (concat nnsoup-directory file)))
+                 (lambda (file) (delete-file
+                                 (expand-file-name file nnsoup-directory)))
                  non-files)))
 
 (provide 'nnsoup)