-(defun nntp-send-strings-to-server (&rest strings)
- "Send list of STRINGS to news server as command and its arguments."
- (let ((cmd (concat (mapconcat 'identity strings " ") "\r\n")))
- ;; We open the nntp server if it is down.
- (or (nntp-server-opened nntp-current-server)
- (nntp-open-server nntp-current-server)
- (error (nntp-status-message)))
- ;; Send the strings.
- (process-send-string nntp-server-process cmd)))
-
-(defun nntp-send-region-to-server (begin end)
- "Send current buffer region (from BEGIN to END) to news server."
- (save-excursion
- ;; We have to work in the buffer associated with NNTP server
- ;; process because of NEmacs hack.
- (copy-to-buffer nntp-server-buffer begin end)
- (set-buffer nntp-server-buffer)
- (setq begin (point-min))
- (setq end (point-max))
- ;; `process-send-region' does not work if text to be sent is very
- ;; large. I don't know maximum size of text sent correctly.
- (let ((last nil)
- (size 100)) ;Size of text sent at once.
- (save-restriction
- (narrow-to-region begin end)
- (goto-char begin)
- (while (not (eobp))
- ;;(setq last (min end (+ (point) size)))
- ;; NEmacs gets confused if character at `last' is Kanji.
- (setq last (save-excursion
- (goto-char (min end (+ (point) size)))
- (or (eobp) (forward-char 1)) ;Adjust point
- (point)))
- (process-send-region nntp-server-process (point) last)
- ;; I don't know whether the next codes solve the known
- ;; problem of communication error of GNU Emacs.
- (accept-process-output)
- ;;(sit-for 0)
- (goto-char last))))
- ;; We cannot erase buffer, because reply may be received.
- (delete-region begin end)))
-
-(defun nntp-open-server-semi-internal (server &optional service)
- "Open SERVER.
-If SERVER is nil, use value of environment variable `NNTPSERVER'.
-If SERVICE, this this as the port number."
- (let ((server (or server (getenv "NNTPSERVER")))
- (status nil)
- (timer
- (and nntp-connection-timeout
- (cond
- ((fboundp 'run-at-time)
- (run-at-time nntp-connection-timeout
- nil 'nntp-kill-connection server))
- ((fboundp 'start-itimer)
- ;; Not sure if this will work or not, only one way to
- ;; find out
- (eval '(start-itimer "nntp-timeout"
- (lambda ()
- (nntp-kill-connection server))
- nntp-connection-timeout nil)))))))
- (setq nntp-status-string "")
- (message "nntp: Connecting to server on %s..." server)
- (cond ((and server (nntp-open-server-internal server service))
- (setq nntp-address server)
- (setq status
- (condition-case nil
- (nntp-wait-for-response "^[23].*\r?\n" 'slow)
- (error nil)
- (quit nil)))
- (or status (nntp-close-server-internal server))
- (and nntp-server-process
- (progn
- (set-process-sentinel
- nntp-server-process 'nntp-default-sentinel)
- ;; You can send commands at startup like AUTHINFO here.
- ;; Added by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>
- (run-hooks 'nntp-server-opened-hook))))
- ((null server)
- (setq nntp-status-string "NNTP server is not specified."))
- (t ; We couldn't open the server.
- (setq nntp-timeout-servers (cons server nntp-timeout-servers))))
- (and timer (cancel-timer timer))
- (message "")
- (or status
- (setq nntp-current-server nil
- nntp-async-number nil))
- status))
-
-(defun nntp-open-server-internal (server &optional service)
- "Open connection to news server on SERVER by SERVICE (default is nntp)."
- (let (proc)
- (save-excursion
- ;; Use TCP/IP stream emulation package if needed.
- (or (fboundp 'open-network-stream)
- (require 'tcp))
- ;; Initialize communication buffer.
- (nnheader-init-server-buffer)
- (set-buffer nntp-server-buffer)
- (if (setq proc
- (condition-case nil
- (funcall nntp-open-server-function server)
- (error nil)))
- (progn
- (setq nntp-server-process proc)
- ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
- (process-kill-without-query proc)
- (setq nntp-address server)
- ;; It is possible to change kanji-fileio-code in this hook.
- (run-hooks 'nntp-server-hook)
- nntp-server-process)))))
-
-(defvar nntp-dum-num 5)
-
-(defun nntp-open-network-stream (server)
- (open-network-stream
- "nntpd" nntp-server-buffer server nntp-port-number))
-
-(defun nntp-open-rlogin (server)
- (let ((proc (start-process "nntpd" nntp-server-buffer "rsh" server)))
- (process-send-string proc (mapconcat 'identity nntp-rlogin-parameters
- " "))
- (process-send-string proc "\n")))
-
-(defun nntp-telnet-to-machine ()
- (let (b)
- (telnet "localhost")
- (goto-char (point-min))
- (while (not (re-search-forward "^login: *" nil t))
- (sit-for 1)
- (goto-char (point-min)))
- (goto-char (point-max))
- (insert "larsi")
- (telnet-send-input)
- (setq b (point))
- (while (not (re-search-forward ">" nil t))
- (sit-for 1)
- (goto-char b))
- (goto-char (point-max))
- (insert "ls")
- (telnet-send-input)))
-
-(defun nntp-close-server-internal (&optional server)
- "Close connection to news server."
- (nntp-possibly-change-server nil server)
- (if nntp-server-process
- (delete-process nntp-server-process))
- (setq nntp-server-process nil)
- (setq nntp-address ""))
-
-(defun nntp-accept-response ()
- "Read response of server.
-It is well-known that the communication speed will be much improved by
-defining this function as macro."
- ;; To deal with server process exiting before
- ;; accept-process-output is called.
- ;; Suggested by Jason Venner <jason@violet.berkeley.edu>.
- ;; This is a copy of `nntp-default-sentinel'.
- (if (or (not nntp-server-process)
- (not (memq (process-status nntp-server-process) '(open run))))
- (error "nntp: Process connection closed; %s" (nntp-status-message))
- (if nntp-buggy-select
- (progn
- ;; We cannot use `accept-process-output'.
- ;; Fujitsu UTS requires messages during sleep-for. I don't know why.
- (message "NNTP: Reading...")
- (sleep-for 1)
- (message ""))
- (condition-case errorcode
- (accept-process-output nntp-server-process)
- (error
- (cond ((string-equal "select error: Invalid argument"
- (nth 1 errorcode))
- ;; Ignore select error.
- nil)
- (t
- (signal (car errorcode) (cdr errorcode)))))))))
-
-(defun nntp-last-element (list)
- "Return last element of LIST."
- (while (cdr list)
- (setq list (cdr list)))
- (car list))
-
-(defun nntp-possibly-change-server (newsgroup server)
- (let ((result t))
- ;; We see whether it is necessary to change newsgroup.
- (and newsgroup
- (or (not (string= newsgroup nntp-current-group)))
- (progn
- (setq result (nntp-request-group newsgroup server))
- (setq nntp-current-group newsgroup)))
- result))