Mercurial > emacs
comparison lisp/gnus/nnsoup.el @ 31716:9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Tue, 19 Sep 2000 13:37:09 +0000 |
parents | 6df76c3ff5c2 |
children | be3ff3e3e5b0 |
comparison
equal
deleted
inserted
replaced
31715:7c896543d225 | 31716:9968f55ad26e |
---|---|
1 ;;; nnsoup.el --- SOUP access for Gnus | 1 ;;; nnsoup.el --- SOUP access for Gnus |
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc. | 2 |
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 | |
4 ;; Free Software Foundation, Inc. | |
3 | 5 |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | 6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> | 7 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> |
6 ;; Keywords: news, mail | 8 ;; Keywords: news, mail |
7 | 9 |
36 (nnoo-declare nnsoup) | 38 (nnoo-declare nnsoup) |
37 | 39 |
38 (defvoo nnsoup-directory "~/SOUP/" | 40 (defvoo nnsoup-directory "~/SOUP/" |
39 "*SOUP packet directory.") | 41 "*SOUP packet directory.") |
40 | 42 |
41 (defvoo nnsoup-tmp-directory temporary-file-directory | 43 (defvoo nnsoup-tmp-directory |
44 (cond ((fboundp 'temp-directory) (temp-directory)) | |
45 ((boundp 'temporary-file-directory) temporary-file-directory) | |
46 ("/tmp/")) | |
42 "*Where nnsoup will store temporary files.") | 47 "*Where nnsoup will store temporary files.") |
43 | 48 |
44 (defvoo nnsoup-replies-directory (concat nnsoup-directory "replies/") | 49 (defvoo nnsoup-replies-directory (expand-file-name "replies/" nnsoup-directory) |
45 "*Directory where outgoing packets will be composed.") | 50 "*Directory where outgoing packets will be composed.") |
46 | 51 |
47 (defvoo nnsoup-replies-format-type ?n | 52 (defvoo nnsoup-replies-format-type ?u ;; u is USENET news format. |
48 "*Format of the replies packages.") | 53 "*Format of the replies packages.") |
49 | 54 |
50 (defvoo nnsoup-replies-index-type ?n | 55 (defvoo nnsoup-replies-index-type ?n |
51 "*Index type of the replies packages.") | 56 "*Index type of the replies packages.") |
52 | 57 |
53 (defvoo nnsoup-active-file (concat nnsoup-directory "active") | 58 (defvoo nnsoup-active-file (expand-file-name "active" nnsoup-directory) |
54 "Active file.") | 59 "Active file.") |
55 | 60 |
56 (defvoo nnsoup-packer "tar cf - %s | gzip > $HOME/Soupin%d.tgz" | 61 (defvoo nnsoup-packer "tar cf - %s | gzip > $HOME/Soupin%d.tgz" |
57 "Format string command for packing a SOUP packet. | 62 "Format string command for packing a SOUP packet. |
58 The SOUP files will be inserted where the %s is in the string. | 63 The SOUP files will be inserted where the %s is in the string. |
68 | 73 |
69 (defvoo nnsoup-packet-regexp "Soupout" | 74 (defvoo nnsoup-packet-regexp "Soupout" |
70 "*Regular expression matching SOUP packets in `nnsoup-packet-directory'.") | 75 "*Regular expression matching SOUP packets in `nnsoup-packet-directory'.") |
71 | 76 |
72 (defvoo nnsoup-always-save t | 77 (defvoo nnsoup-always-save t |
73 "If non nil commit the reply buffer on each message send. | 78 "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 | 79 This is necessary if using message mode outside Gnus with nnsoup as a |
75 backend for the messages.") | 80 backend for the messages.") |
76 | 81 |
77 | 82 |
78 | 83 |
79 (defconst nnsoup-version "nnsoup 0.0" | 84 (defconst nnsoup-version "nnsoup 0.0" |
250 (let ((kind (gnus-soup-encoding-kind | 255 (let ((kind (gnus-soup-encoding-kind |
251 (gnus-soup-area-encoding | 256 (gnus-soup-area-encoding |
252 (nth 1 (nnsoup-article-to-area | 257 (nth 1 (nnsoup-article-to-area |
253 article nnsoup-current-group)))))) | 258 article nnsoup-current-group)))))) |
254 (cond ((= kind ?m) 'mail) | 259 (cond ((= kind ?m) 'mail) |
255 ((= kind ?n) 'news) | 260 ((= kind ?n) 'news) |
256 (t 'unknown))))) | 261 (t 'unknown))))) |
257 | 262 |
258 (deffoo nnsoup-close-group (group &optional server) | 263 (deffoo nnsoup-close-group (group &optional server) |
259 ;; Kill all nnsoup buffers. | 264 ;; Kill all nnsoup buffers. |
260 (let ((buffers nnsoup-buffers) | 265 (let ((buffers nnsoup-buffers) |
308 info range-list mod-time prefix) | 313 info range-list mod-time prefix) |
309 (while infolist | 314 (while infolist |
310 (setq info (pop infolist) | 315 (setq info (pop infolist) |
311 range-list (gnus-uncompress-range (car info)) | 316 range-list (gnus-uncompress-range (car info)) |
312 prefix (gnus-soup-area-prefix (nth 1 info))) | 317 prefix (gnus-soup-area-prefix (nth 1 info))) |
313 (when ;; All the articles in this file are marked for expiry. | 318 (when;; All the articles in this file are marked for expiry. |
314 (and (or (setq mod-time (nth 5 (file-attributes | 319 (and (or (setq mod-time (nth 5 (file-attributes |
315 (nnsoup-file prefix)))) | 320 (nnsoup-file prefix)))) |
316 (setq mod-time (nth 5 (file-attributes | 321 (setq mod-time (nth 5 (file-attributes |
317 (nnsoup-file prefix t))))) | 322 (nnsoup-file prefix t))))) |
318 (gnus-sublist-p articles range-list) | 323 (gnus-sublist-p articles range-list) |
374 (defun nnsoup-write-active-file (&optional force) | 379 (defun nnsoup-write-active-file (&optional force) |
375 (when (and nnsoup-group-alist | 380 (when (and nnsoup-group-alist |
376 (or force | 381 (or force |
377 nnsoup-group-alist-touched)) | 382 nnsoup-group-alist-touched)) |
378 (setq nnsoup-group-alist-touched nil) | 383 (setq nnsoup-group-alist-touched nil) |
379 (nnheader-temp-write nnsoup-active-file | 384 (with-temp-file nnsoup-active-file |
380 (gnus-prin1 `(setq nnsoup-group-alist ',nnsoup-group-alist)) | 385 (gnus-prin1 `(setq nnsoup-group-alist ',nnsoup-group-alist)) |
381 (insert "\n") | 386 (insert "\n") |
382 (gnus-prin1 `(setq nnsoup-current-prefix ,nnsoup-current-prefix)) | 387 (gnus-prin1 `(setq nnsoup-current-prefix ,nnsoup-current-prefix)) |
383 (insert "\n")))) | 388 (insert "\n")))) |
384 | 389 |
417 (while (setq area (pop areas)) | 422 (while (setq area (pop areas)) |
418 ;; Change the name to the permanent name and move the files. | 423 ;; Change the name to the permanent name and move the files. |
419 (setq cur-prefix (nnsoup-next-prefix)) | 424 (setq cur-prefix (nnsoup-next-prefix)) |
420 (nnheader-message 5 "Incorporating file %s..." cur-prefix) | 425 (nnheader-message 5 "Incorporating file %s..." cur-prefix) |
421 (when (file-exists-p | 426 (when (file-exists-p |
422 (setq file (concat nnsoup-tmp-directory | 427 (setq file |
423 (gnus-soup-area-prefix area) ".IDX"))) | 428 (expand-file-name |
429 (concat (gnus-soup-area-prefix area) ".IDX") | |
430 nnsoup-tmp-directory))) | |
424 (rename-file file (nnsoup-file cur-prefix))) | 431 (rename-file file (nnsoup-file cur-prefix))) |
425 (when (file-exists-p | 432 (when (file-exists-p |
426 (setq file (concat nnsoup-tmp-directory | 433 (setq file (expand-file-name |
427 (gnus-soup-area-prefix area) ".MSG"))) | 434 (concat (gnus-soup-area-prefix area) ".MSG") |
435 nnsoup-tmp-directory))) | |
428 (rename-file file (nnsoup-file cur-prefix t)) | 436 (rename-file file (nnsoup-file cur-prefix t)) |
429 (gnus-soup-set-area-prefix area cur-prefix) | 437 (gnus-soup-set-area-prefix area cur-prefix) |
430 ;; Find the number of new articles in this area. | 438 ;; Find the number of new articles in this area. |
431 (setq number (nnsoup-number-of-articles area)) | 439 (setq number (nnsoup-number-of-articles area)) |
432 (if (not (setq entry (assoc (gnus-soup-area-name area) | 440 (if (not (setq entry (assoc (gnus-soup-area-name area) |
471 (i 0) | 479 (i 0) |
472 alist len) | 480 alist len) |
473 (goto-char (point-min)) | 481 (goto-char (point-min)) |
474 (cond | 482 (cond |
475 ;; rnews batch format | 483 ;; rnews batch format |
476 ((= format ?n) | 484 ((or (= format ?u) |
485 (= format ?n)) ;; Gnus back compatibility. | |
477 (while (looking-at "^#! *rnews \\(+[0-9]+\\) *$") | 486 (while (looking-at "^#! *rnews \\(+[0-9]+\\) *$") |
478 (forward-line 1) | 487 (forward-line 1) |
479 (push (list | 488 (push (list |
480 (incf i) (point) | 489 (incf i) (point) |
481 (progn | 490 (progn |
525 | 534 |
526 (defun nnsoup-index-buffer (prefix &optional message) | 535 (defun nnsoup-index-buffer (prefix &optional message) |
527 (let* ((file (concat prefix (if message ".MSG" ".IDX"))) | 536 (let* ((file (concat prefix (if message ".MSG" ".IDX"))) |
528 (buffer-name (concat " *nnsoup " file "*"))) | 537 (buffer-name (concat " *nnsoup " file "*"))) |
529 (or (get-buffer buffer-name) ; File already loaded. | 538 (or (get-buffer buffer-name) ; File already loaded. |
530 (when (file-exists-p (concat nnsoup-directory file)) | 539 (when (file-exists-p (expand-file-name file nnsoup-directory)) |
531 (save-excursion ; Load the file. | 540 (save-excursion ; Load the file. |
532 (set-buffer (get-buffer-create buffer-name)) | 541 (set-buffer (get-buffer-create buffer-name)) |
533 (buffer-disable-undo (current-buffer)) | 542 (buffer-disable-undo) |
534 (push (cons nnsoup-current-group (current-buffer)) nnsoup-buffers) | 543 (push (cons nnsoup-current-group (current-buffer)) nnsoup-buffers) |
535 (nnheader-insert-file-contents (concat nnsoup-directory file)) | 544 (nnheader-insert-file-contents |
545 (expand-file-name file nnsoup-directory)) | |
536 (current-buffer)))))) | 546 (current-buffer)))))) |
537 | 547 |
538 (defun nnsoup-file (prefix &optional message) | 548 (defun nnsoup-file (prefix &optional message) |
539 (expand-file-name | 549 (expand-file-name |
540 (concat nnsoup-directory prefix (if message ".MSG" ".IDX")))) | 550 (concat prefix (if message ".MSG" ".IDX")) |
551 nnsoup-directory)) | |
541 | 552 |
542 (defun nnsoup-message-buffer (prefix) | 553 (defun nnsoup-message-buffer (prefix) |
543 (nnsoup-index-buffer prefix 'msg)) | 554 (nnsoup-index-buffer prefix 'msg)) |
544 | 555 |
545 (defun nnsoup-unpack-packets () | 556 (defun nnsoup-unpack-packets () |
585 (set-buffer msg-buf) | 596 (set-buffer msg-buf) |
586 (widen) | 597 (widen) |
587 (let ((format (gnus-soup-encoding-format | 598 (let ((format (gnus-soup-encoding-format |
588 (gnus-soup-area-encoding (nth 1 area))))) | 599 (gnus-soup-area-encoding (nth 1 area))))) |
589 (goto-char end) | 600 (goto-char end) |
590 (when (or (= format ?n) (= format ?m)) | 601 (when (or (= format ?u) (= format ?n) (= format ?m)) |
591 (setq end (progn (forward-line -1) (point)))))) | 602 (setq end (progn (forward-line -1) (point)))))) |
592 (set-buffer msg-buf)) | 603 (set-buffer msg-buf)) |
593 (widen) | 604 (widen) |
594 (narrow-to-region beg (or end (point-max)))) | 605 (narrow-to-region beg (or end (point-max)))) |
595 (t | 606 (t |
664 (defun nnsoup-store-reply (kind) | 675 (defun nnsoup-store-reply (kind) |
665 ;; Mostly stolen from `message.el'. | 676 ;; Mostly stolen from `message.el'. |
666 (require 'mail-utils) | 677 (require 'mail-utils) |
667 (let ((tembuf (generate-new-buffer " message temp")) | 678 (let ((tembuf (generate-new-buffer " message temp")) |
668 (case-fold-search nil) | 679 (case-fold-search nil) |
669 (real-header-separator mail-header-separator) | |
670 (mail-header-separator "") | |
671 delimline | 680 delimline |
672 (mailbuf (current-buffer))) | 681 (mailbuf (current-buffer))) |
673 (unwind-protect | 682 (unwind-protect |
674 (save-excursion | 683 (save-excursion |
675 (save-restriction | 684 (save-restriction |
691 (insert ?\n)) | 700 (insert ?\n)) |
692 (let ((case-fold-search t)) | 701 (let ((case-fold-search t)) |
693 ;; Change header-delimiter to be what sendmail expects. | 702 ;; Change header-delimiter to be what sendmail expects. |
694 (goto-char (point-min)) | 703 (goto-char (point-min)) |
695 (re-search-forward | 704 (re-search-forward |
696 (concat "^" (regexp-quote real-header-separator) "\n")) | 705 (concat "^" (regexp-quote mail-header-separator) "\n")) |
697 (replace-match "\n") | 706 (replace-match "\n") |
698 (backward-char 1) | 707 (backward-char 1) |
699 (setq delimline (point-marker)) | 708 (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)) | 709 (goto-char (1+ delimline)) |
703 (when (eval message-mailer-swallows-blank-line) | |
704 (newline)) | |
705 (let ((msg-buf | 710 (let ((msg-buf |
706 (gnus-soup-store | 711 (gnus-soup-store |
707 nnsoup-replies-directory | 712 nnsoup-replies-directory |
708 (nnsoup-kind-to-prefix kind) nil nnsoup-replies-format-type | 713 (nnsoup-kind-to-prefix kind) nil nnsoup-replies-format-type |
709 nnsoup-replies-index-type)) | 714 nnsoup-replies-index-type)) |
722 | 727 |
723 (defun nnsoup-kind-to-prefix (kind) | 728 (defun nnsoup-kind-to-prefix (kind) |
724 (unless nnsoup-replies-list | 729 (unless nnsoup-replies-list |
725 (setq nnsoup-replies-list | 730 (setq nnsoup-replies-list |
726 (gnus-soup-parse-replies | 731 (gnus-soup-parse-replies |
727 (concat nnsoup-replies-directory "REPLIES")))) | 732 (expand-file-name "REPLIES" nnsoup-replies-directory)))) |
728 (let ((replies nnsoup-replies-list)) | 733 (let ((replies nnsoup-replies-list)) |
729 (while (and replies | 734 (while (and replies |
730 (not (string= kind (gnus-soup-reply-kind (car replies))))) | 735 (not (string= kind (gnus-soup-reply-kind (car replies))))) |
731 (setq replies (cdr replies))) | 736 (setq replies (cdr replies))) |
732 (if replies | 737 (if replies |
750 (string-to-int (match-string 1 f1))) | 755 (string-to-int (match-string 1 f1))) |
751 (progn (string-match "/\\([0-9]+\\)\\." f2) | 756 (progn (string-match "/\\([0-9]+\\)\\." f2) |
752 (string-to-int (match-string 1 f2))))))) | 757 (string-to-int (match-string 1 f2))))))) |
753 active group lines ident elem min) | 758 active group lines ident elem min) |
754 (set-buffer (get-buffer-create " *nnsoup work*")) | 759 (set-buffer (get-buffer-create " *nnsoup work*")) |
755 (buffer-disable-undo (current-buffer)) | |
756 (while files | 760 (while files |
757 (nnheader-message 5 "Doing %s..." (car files)) | 761 (nnheader-message 5 "Doing %s..." (car files)) |
758 (erase-buffer) | 762 (erase-buffer) |
759 (nnheader-insert-file-contents (car files)) | 763 (nnheader-insert-file-contents (car files)) |
760 (goto-char (point-min)) | 764 (goto-char (point-min)) |
768 (car files) (match-beginning 1) | 772 (car files) (match-beginning 1) |
769 (match-end 1)))) | 773 (match-end 1)))) |
770 (if (not (setq elem (assoc group active))) | 774 (if (not (setq elem (assoc group active))) |
771 (push (list group (cons 1 lines) | 775 (push (list group (cons 1 lines) |
772 (list (cons 1 lines) | 776 (list (cons 1 lines) |
773 (vector ident group "ncm" "" lines))) | 777 (vector ident group "ucm" "" lines))) |
774 active) | 778 active) |
775 (nconc elem | 779 (nconc elem |
776 (list | 780 (list |
777 (list (cons (1+ (setq min (cdadr elem))) | 781 (list (cons (1+ (setq min (cdadr elem))) |
778 (+ min lines)) | 782 (+ min lines)) |
779 (vector ident group "ncm" "" lines)))) | 783 (vector ident group "ucm" "" lines)))) |
780 (setcdr (cadr elem) (+ min lines))) | 784 (setcdr (cadr elem) (+ min lines))) |
781 (setq files (cdr files))) | 785 (setq files (cdr files))) |
782 (nnheader-message 5 "") | 786 (nnheader-message 5 "") |
783 (setq nnsoup-group-alist active) | 787 (setq nnsoup-group-alist active) |
784 (nnsoup-write-active-file t))) | 788 (nnsoup-write-active-file t))) |
802 (unless (member (substring file 0 (match-beginning 0)) known) | 806 (unless (member (substring file 0 (match-beginning 0)) known) |
803 (push file non-files))) | 807 (push file non-files))) |
804 ;; Sort and delete the files. | 808 ;; Sort and delete the files. |
805 (setq non-files (sort non-files 'string<)) | 809 (setq non-files (sort non-files 'string<)) |
806 (map-y-or-n-p "Delete file %s? " | 810 (map-y-or-n-p "Delete file %s? " |
807 (lambda (file) (delete-file (concat nnsoup-directory file))) | 811 (lambda (file) (delete-file |
812 (expand-file-name file nnsoup-directory))) | |
808 non-files))) | 813 non-files))) |
809 | 814 |
810 (provide 'nnsoup) | 815 (provide 'nnsoup) |
811 | 816 |
812 ;;; nnsoup.el ends here | 817 ;;; nnsoup.el ends here |