1 ;;; nndigest.el --- digest access for Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
30 (autoload 'mail-send-and-exit "sendmail"))
34 (defconst nndigest-version "nndigest 0.0"
37 (defvar nndigest-current-buffer nil
38 "Current digest "group" buffer.")
40 (defvar nndigest-status-string "")
42 (defvar nndigest-group-alist nil)
44 (defvar nndigest-separator
45 "^------------------------------[\n \t]*\n[^ ]+: ")
47 (defvar nndigest-first-article-separator
48 "^------------------------------*[\n \t]*\n[^ ]+: ")
52 ;;; Interface functions.
54 (defun nndigest-retrieve-headers (sequence &optional newsgroup server)
56 (set-buffer nntp-server-buffer)
59 (number (length sequence))
63 (nndigest-possibly-change-buffer newsgroup)
65 (setq article (car sequence))
66 (if (setq range (nndigest-narrow-to-article article))
68 (insert (format "221 %d Article retrieved.\n" article))
70 (insert-buffer-substring nndigest-current-buffer
71 (car range) (cdr range))
73 (if (search-forward "\n\n" nil t)
75 (goto-char (point-max))
77 (insert (format "Lines: %d\n" (count-lines (point) (point-max))))
79 (delete-region (point) (point-max))))
80 (setq sequence (cdr sequence)))
82 ;; Fold continuation lines.
83 (goto-char (point-min))
84 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
85 (replace-match " " t t))
88 (defun nndigest-open-server (host &optional service)
89 (setq nndigest-status-string "")
90 (nnheader-init-server-buffer))
92 (defun nndigest-close-server (&optional server)
95 (defun nndigest-server-opened (&optional server)
96 (and nntp-server-buffer
97 (get-buffer nntp-server-buffer)))
99 (defun nndigest-status-message ()
100 nndigest-status-string)
102 (defun nndigest-request-article (id &optional newsgroup server buffer)
103 (nndigest-possibly-change-buffer newsgroup)
104 (let ((range (nndigest-narrow-to-article id)))
107 (set-buffer (or buffer nntp-server-buffer))
109 (insert-buffer-substring
110 nndigest-current-buffer (car range) (cdr range))
113 (defun nndigest-request-group (group &optional server dont-check)
114 (let ((entry (assoc group nndigest-group-alist)))
115 (and entry (setq nndigest-group-alist (delq entry nndigest-group-alist))))
116 (let ((buffer (get-buffer-create (concat " *nndigest " group "*"))))
117 (setq nndigest-group-alist
118 (cons (cons group buffer) nndigest-group-alist))
122 (insert-buffer-substring server)))
123 (nndigest-possibly-change-buffer group)
126 (set-buffer nndigest-current-buffer)
128 (goto-char (point-min))
129 (if (re-search-forward nndigest-first-article-separator nil t)
131 (while (re-search-forward nndigest-separator nil t)
133 (set-buffer nntp-server-buffer)
135 (insert (format "211 %d %d %d %s\n" num 1 num group))
138 (defun nndigest-close-group (group &optional server)
139 (nndigest-possibly-change-buffer group)
140 (kill-buffer nndigest-current-buffer)
141 (setq nndigest-group-alist (delq (assoc group nndigest-group-alist)
142 nndigest-group-alist))
143 (setq nndigest-current-buffer nil)
146 (defun nndigest-request-list (&optional server)
148 (set-buffer nntp-server-buffer)
152 (defun nndigest-request-newgroups (date &optional server)
154 (set-buffer nntp-server-buffer)
158 (defun nndigest-request-list-newsgroups (&optional server)
160 (set-buffer nntp-server-buffer)
164 (defun nndigest-request-post (&optional server)
165 (mail-send-and-exit nil))
167 (fset 'nndigest-request-post-buffer 'nnmail-request-post-buffer)
171 ;;; Internal functions
173 (defun nndigest-possibly-change-buffer (group)
175 (not (equal (cdr (assoc group nndigest-group-alist))
176 nndigest-current-buffer))
177 (setq nndigest-current-buffer
178 (cdr (assoc group nndigest-group-alist)))))
180 (defun nndigest-narrow-to-article (article)
182 (set-buffer nndigest-current-buffer)
184 (goto-char (point-min))
185 (re-search-forward nndigest-first-article-separator nil t)
186 (while (and (not (zerop (setq article (1- article))))
187 (re-search-forward nndigest-separator nil t)))
190 (goto-char (match-end 0))
194 (or (and (re-search-forward nndigest-separator nil t)
197 (cons (point-min) (point-max)))
203 ;;; nndigest.el ends here