(defvar nnspool-current-server nil)
(defvar nnspool-server-alist nil)
(defvar nnspool-server-variables
- (list
- (list 'nnspool-inews-program nnspool-inews-program)
- (list 'nnspool-inews-switches nnspool-inews-switches)
- (list 'nnspool-spool-directory nnspool-spool-directory)
- (list 'nnspool-nov-directory nnspool-nov-directory)
- (list 'nnspool-lib-dir nnspool-lib-dir)
- (list 'nnspool-active-file nnspool-active-file)
- (list 'nnspool-newsgroups-file nnspool-newsgroups-file)
- (list 'nnspool-distributions-file nnspool-distributions-file)
- (list 'nnspool-history-file nnspool-history-file)
- (list 'nnspool-active-times-file nnspool-active-times-file)
- (list 'nnspool-large-newsgroup nnspool-large-newsgroup)
- (list 'nnspool-nov-is-evil nnspool-nov-is-evil)
- (list 'nnspool-sift-nov-with-sed nnspool-sift-nov-with-sed)
- '(nnspool-current-directory nil)
- '(nnspool-current-group nil)
- '(nnspool-status-string "")))
+ `((nnspool-inews-program ,nnspool-inews-program)
+ (nnspool-inews-switches ,nnspool-inews-switches)
+ (nnspool-spool-directory ,nnspool-spool-directory)
+ (nnspool-nov-directory ,nnspool-nov-directory)
+ (nnspool-lib-dir ,nnspool-lib-dir)
+ (nnspool-active-file ,nnspool-active-file)
+ (nnspool-newsgroups-file ,nnspool-newsgroups-file)
+ (nnspool-distributions-file ,nnspool-distributions-file)
+ (nnspool-rejected-article-hook nil)
+ (nnspool-history-file ,nnspool-history-file)
+ (nnspool-active-times-file ,nnspool-active-times-file)
+ (nnspool-large-newsgroup ,nnspool-large-newsgroup)
+ (nnspool-nov-is-evil ,nnspool-nov-is-evil)
+ (nnspool-sift-nov-with-sed ,nnspool-sift-nov-with-sed)
+ (nnspool-current-directory nil)
+ (nnspool-current-group nil)
+ (nnspool-status-string "")))
\f
;;; Interface functions.
(when (nnspool-possibly-change-directory group)
(let* ((number (length articles))
(count 0)
+ (default-directory nnspool-current-directory)
(do-message (and (numberp nnspool-large-newsgroup)
(> number nnspool-large-newsgroup)))
file beg article ag)
;; We successfully retrieved the NOV headers.
'nov
;; No NOV headers here, so we do it the hard way.
- (while articles
- (setq article (pop articles))
+ (while (setq article (pop articles))
(if (stringp article)
;; This is a Message-ID.
(setq ag (nnspool-find-id article)
(car ag) (cdr ag)))
article (cdr ag))
;; This is an article in the current group.
- (setq file (nnspool-article-pathname
- nnspool-current-group article)))
+ (setq file (int-to-string article)))
;; Insert the head of the article.
(when (and file
(file-exists-p file))
- (insert (format "221 %d Article retrieved.\n" article))
+ (insert "221 ")
+ (princ article (current-buffer))
+ (insert " Article retrieved.\n")
(setq beg (point))
- (nnheader-insert-head file)
+ (inline (nnheader-insert-head file))
(goto-char beg)
(search-forward "\n\n" nil t)
(forward-char -1)
'headers)))))
(defun nnspool-open-server (server &optional defs)
- (nnheader-init-server-buffer)
- (if (equal server nnspool-current-server)
- t
- (if nnspool-current-server
- (setq nnspool-server-alist
- (cons (list nnspool-current-server
- (nnheader-save-variables nnspool-server-variables))
- nnspool-server-alist)))
- (let ((state (assoc server nnspool-server-alist)))
- (if state
- (progn
- (nnheader-restore-variables (nth 1 state))
- (setq nnspool-server-alist (delq state nnspool-server-alist)))
- (nnheader-set-init-variables nnspool-server-variables defs)))
- (setq nnspool-current-server server)))
+ (nnheader-change-server 'nnspool server defs)
+ (cond
+ ((not (file-exists-p nnspool-spool-directory))
+ (nnspool-close-server)
+ (nnheader-report 'nnspool "Spool directory doesn't exist: %s"
+ nnspool-spool-directory))
+ ((not (file-directory-p (file-truename nnspool-spool-directory)))
+ (nnspool-close-server)
+ (nnheader-report 'nnspool "Not a directory: %s" nnspool-spool-directory))
+ (t
+ (nnheader-report 'nnspool "Opened server %s using directory %s"
+ server nnspool-spool-directory)
+ t)))
(defun nnspool-close-server (&optional server)
(setq nnspool-current-server nil)
(defun nnspool-request-body (id &optional group server)
"Select article body by message ID (or number)."
(nnspool-possibly-change-directory group)
- (if (nnspool-request-article id)
+ (let ((res (nnspool-request-article id)))
+ (when res
(save-excursion
(set-buffer nntp-server-buffer)
(goto-char (point-min))
- (if (search-forward "\n\n" nil t)
- (delete-region (point-min) (point)))
- t)))
+ (when (search-forward "\n\n" nil t)
+ (delete-region (point-min) (point)))
+ res))))
(defun nnspool-request-head (id &optional group server)
"Select article head by message ID (or number)."
(progn
(nnheader-report 'nnspool "Selected group %s" group)
t)
- ;; Yes, completely empty spool directories *are* possible
+ ;; Yes, completely empty spool directories *are* possible.
;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
(when (setq dir (directory-files pathname nil "^[0-9]+$" t))
(setq dir
(sort (mapcar (lambda (name) (string-to-int name)) dir) '<)))
- (save-excursion
- (set-buffer nntp-server-buffer)
- (erase-buffer)
- (if dir
- (progn
- (insert
- (format "211 %d %d %d %s\n" (length dir) (car dir)
- (progn (while (cdr dir) (setq dir (cdr dir)))
- (car dir))
- group))
- t)
- (insert (format "211 0 0 0 %s\n" group))
- (nnheader-report 'nnspool "Empty group %s" group)
- t))))))
+ (if dir
+ (nnheader-insert
+ "211 %d %d %d %s\n" (length dir) (car dir)
+ (progn (while (cdr dir) (setq dir (cdr dir))) (car dir))
+ group)
+ (nnheader-report 'nnspool "Empty group %s" group)
+ (nnheader-insert "211 0 0 0 %s\n" group))))))
(defun nnspool-request-type (group &optional article)
'news)
(apply 'start-process "*nnspool inews*" inews-buffer
nnspool-inews-program nnspool-inews-switches)
(error
- (setq nnspool-status-string (format "inews error: %S" err))
- nil))))
+ (nnheader-report 'nnspool "inews error: %S" err)))))
(if (not proc)
;; The inews program failed.
()
- (setq nnspool-status-string "")
+ (nnheader-report 'nnspool "")
(set-process-sentinel proc 'nnspool-inews-sentinel)
(process-send-region proc (point-min) (point-max))
;; We slap a condition-case around this, because the process may
;; Make status message by folding lines.
(while (re-search-forward "[ \t\n]+" nil t)
(replace-match " " t t))
- (setq nnspool-status-string (buffer-string))
+ (nnheader-report 'nnspool "%s" (buffer-string))
(message "nnspool: %s" nnspool-status-string)
(ding)
(run-hooks 'nnspool-rejected-article-hook))))
((< num article)
(setq min (point)))
(t
- (setq found t)))))
- (when (not (eq num article))
+ (setq found 'yes)))))
+ ;; Now we may have found the article we're looking for, or we
+ ;; may be somewhere near it.
+ (when (and (not (eq found 'yes))
+ (not (eq num article)))
(setq found (point))
- (forward-line 1)
- (or (eobp)
- (= (setq num (read cur)) article)
- (goto-char found)))
+ (while (and (< (point) max)
+ (or (not (numberp num))
+ (< num article)))
+ (forward-line 1)
+ (setq found (point))
+ (or (eobp)
+ (= (setq num (read cur)) article)))
+ (unless (eq num article)
+ (goto-char found)))
(beginning-of-line)
(eq num article)))
-
(defun nnspool-sift-nov-with-sed (articles file)
(let ((first (car articles))
(last (progn (while (cdr articles) (setq articles (cdr articles)))
(file-error nil)))
(defun nnspool-possibly-change-directory (group)
- (if group
- (let ((pathname (nnspool-article-pathname group)))
- (if (file-directory-p pathname)
- (progn
- (setq nnspool-current-directory pathname)
- (setq nnspool-current-group group))
- (setq nnspool-status-string
- (format "No such newsgroup: %s" group))
- nil))
- t))
+ (if (not group)
+ t
+ (let ((pathname (nnspool-article-pathname group)))
+ (if (file-directory-p pathname)
+ (setq nnspool-current-directory pathname
+ nnspool-current-group group)
+ (nnheader-report 'nnspool "No such newsgroup: %s" group)))))
(defun nnspool-article-pathname (group &optional article)
"Find the path for GROUP."
(nth 2 tdate) (nth 1 tdate) (nth 0 tdate)
(nth 4 tdate))))
(+ (* (car unix) 65536.0)
- (car (cdr unix)))))
+ (cadr unix))))
(provide 'nnspool)