comparison lisp/gnus/nntp.el @ 92778:054fe9aaf3e3

Use with-current-buffer. (nntp-send-buffer): Just set the buffer to unibyte rather than use the dubious mm-with-unibyte-current-buffer. (nntp-with-open-group-function): New function extracted from nntp-with-open-group macro. (nntp-with-open-group): Use the function, so it's easier to debug. Add indentation and debugging info. (nntp-open-telnet-stream, nntp-open-via-rlogin-and-telnet): Recommend the use of the netcat alternatives.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 12 Mar 2008 19:56:09 +0000
parents 107ccd98fa12
children a789a1138b08
comparison
equal deleted inserted replaced
92777:1186239f19c8 92778:054fe9aaf3e3
333 (or (memq (process-status process) '(open run)) 333 (or (memq (process-status process) '(open run))
334 (nntp-report "Server closed connection"))) 334 (nntp-report "Server closed connection")))
335 335
336 (defun nntp-record-command (string) 336 (defun nntp-record-command (string)
337 "Record the command STRING." 337 "Record the command STRING."
338 (save-excursion 338 (with-current-buffer (get-buffer-create "*nntp-log*")
339 (set-buffer (get-buffer-create "*nntp-log*"))
340 (goto-char (point-max)) 339 (goto-char (point-max))
341 (let ((time (current-time))) 340 (let ((time (current-time)))
342 (insert (format-time-string "%Y%m%dT%H%M%S" time) 341 (insert (format-time-string "%Y%m%dT%H%M%S" time)
343 "." (format "%03d" (/ (nth 2 time) 1000)) 342 "." (format "%03d" (/ (nth 2 time) 1000))
344 " " nntp-address " " string "\n")))) 343 " " nntp-address " " string "\n"))))
391 nil)))) 390 nil))))
392 391
393 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard) 392 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard)
394 "Wait for WAIT-FOR to arrive from PROCESS." 393 "Wait for WAIT-FOR to arrive from PROCESS."
395 394
396 (save-excursion 395 (with-current-buffer (process-buffer process)
397 (set-buffer (process-buffer process))
398 (goto-char (point-min)) 396 (goto-char (point-min))
399 397
400 (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5))) 398 (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5)))
401 (looking-at "48[02]")) 399 (looking-at "48[02]"))
402 (memq (process-status process) '(open run))) 400 (memq (process-status process) '(open run)))
430 (setq response (match-string 0)) 428 (setq response (match-string 0))
431 (with-current-buffer nntp-server-buffer 429 (with-current-buffer nntp-server-buffer
432 (setq nntp-process-response response))) 430 (setq nntp-process-response response)))
433 (nntp-decode-text (not decode)) 431 (nntp-decode-text (not decode))
434 (unless discard 432 (unless discard
435 (save-excursion 433 (with-current-buffer buffer
436 (set-buffer buffer)
437 (goto-char (point-max)) 434 (goto-char (point-max))
438 (nntp-insert-buffer-substring (process-buffer process)) 435 (nntp-insert-buffer-substring (process-buffer process))
439 ;; Nix out "nntp reading...." message. 436 ;; Nix out "nntp reading...." message.
440 (when nntp-have-messaged 437 (when nntp-have-messaged
441 (setq nntp-have-messaged nil) 438 (setq nntp-have-messaged nil)
537 nntp-never-echoes-commands 534 nntp-never-echoes-commands
538 (memq 535 (memq
539 nntp-open-connection-function 536 nntp-open-connection-function
540 nntp-open-connection-functions-never-echo-commands)) 537 nntp-open-connection-functions-never-echo-commands))
541 (nntp-accept-response) 538 (nntp-accept-response)
542 (save-excursion 539 (with-current-buffer buffer
543 (set-buffer buffer)
544 (goto-char pos) 540 (goto-char pos)
545 (if (looking-at (regexp-quote command)) 541 (if (looking-at (regexp-quote command))
546 (delete-region pos (progn (forward-line 1) 542 (delete-region pos (progn (forward-line 1)
547 (point-at-bol))))))) 543 (point-at-bol)))))))
548 (nnheader-report 'nntp "Couldn't open connection to %s." 544 (nnheader-report 'nntp "Couldn't open connection to %s."
561 nntp-server-buffer 557 nntp-server-buffer
562 wait-for nnheader-callback-function) 558 wait-for nnheader-callback-function)
563 ;; If nothing to wait for, still remove possibly echo'ed commands 559 ;; If nothing to wait for, still remove possibly echo'ed commands
564 (unless wait-for 560 (unless wait-for
565 (nntp-accept-response) 561 (nntp-accept-response)
566 (save-excursion 562 (with-current-buffer buffer
567 (set-buffer buffer)
568 (goto-char pos) 563 (goto-char pos)
569 (if (looking-at (regexp-quote command)) 564 (if (looking-at (regexp-quote command))
570 (delete-region pos (progn (forward-line 1) 565 (delete-region pos (progn (forward-line 1)
571 (point-at-bol))))))) 566 (point-at-bol)))))))
572 (nnheader-report 'nntp "Couldn't open connection to %s." 567 (nnheader-report 'nntp "Couldn't open connection to %s."
588 nntp-server-buffer 583 nntp-server-buffer
589 wait-for nnheader-callback-function t) 584 wait-for nnheader-callback-function t)
590 ;; If nothing to wait for, still remove possibly echo'ed commands 585 ;; If nothing to wait for, still remove possibly echo'ed commands
591 (unless wait-for 586 (unless wait-for
592 (nntp-accept-response) 587 (nntp-accept-response)
593 (save-excursion 588 (with-current-buffer buffer
594 (set-buffer buffer)
595 (goto-char pos) 589 (goto-char pos)
596 (if (looking-at (regexp-quote command)) 590 (if (looking-at (regexp-quote command))
597 (delete-region pos (progn (forward-line 1) (point-at-bol)))) 591 (delete-region pos (progn (forward-line 1) (point-at-bol))))
598 ))) 592 )))
599 (nnheader-report 'nntp "Couldn't open connection to %s." 593 (nnheader-report 'nntp "Couldn't open connection to %s."
605 (when (and (not nnheader-callback-function) 599 (when (and (not nnheader-callback-function)
606 (not nntp-inhibit-output)) 600 (not nntp-inhibit-output))
607 (nntp-erase-buffer 601 (nntp-erase-buffer
608 (nntp-find-connection-buffer nntp-server-buffer))) 602 (nntp-find-connection-buffer nntp-server-buffer)))
609 (nntp-encode-text) 603 (nntp-encode-text)
610 (mm-with-unibyte-current-buffer 604 ;; Make sure we did not forget to encode some of the content.
611 ;; Some encoded unicode text contains character 0x80-0x9f e.g. Euro. 605 (assert (save-excursion (goto-char (point-min))
612 (process-send-region (nntp-find-connection nntp-server-buffer) 606 (not (re-search-forward "[^\000-\377]" nil t))))
613 (point-min) (point-max))) 607 (mm-disable-multibyte)
608 (process-send-region (nntp-find-connection nntp-server-buffer)
609 (point-min) (point-max))
614 (nntp-retrieve-data 610 (nntp-retrieve-data
615 nil nntp-address nntp-port-number nntp-server-buffer 611 nil nntp-address nntp-port-number nntp-server-buffer
616 wait-for nnheader-callback-function)) 612 wait-for nnheader-callback-function))
617 613
618 614
646 642
647 (eval-when-compile 643 (eval-when-compile
648 (defvar nntp-with-open-group-internal nil) 644 (defvar nntp-with-open-group-internal nil)
649 (defvar nntp-report-n nil)) 645 (defvar nntp-report-n nil))
650 646
647 (defun nntp-with-open-group-function (-group -server -connectionless -bodyfun)
648 "Protect against servers that don't like clients that keep idle connections opens.
649 The problem being that these servers may either close a connection or
650 simply ignore any further requests on a connection. Closed
651 connections are not detected until `accept-process-output' has updated
652 the `process-status'. Dropped connections are not detected until the
653 connection timeouts (which may be several minutes) or
654 `nntp-connection-timeout' has expired. When these occur
655 `nntp-with-open-group', opens a new connection then re-issues the NNTP
656 command whose response triggered the error."
657 (letf ((nntp-report-n (symbol-function 'nntp-report))
658 ((symbol-function 'nntp-report) (symbol-function 'nntp-report-1))
659 (nntp-with-open-group-internal nil))
660 (while (catch 'nntp-with-open-group-error
661 ;; Open the connection to the server
662 ;; NOTE: Existing connections are NOT tested.
663 (nntp-possibly-change-group -group -server -connectionless)
664
665 (let ((-timer
666 (and nntp-connection-timeout
667 (run-at-time
668 nntp-connection-timeout nil
669 (lambda ()
670 (let* ((-process (nntp-find-connection
671 nntp-server-buffer))
672 (-buffer (and -process
673 (process-buffer -process))))
674 ;; When I an able to identify the
675 ;; connection to the server AND I've
676 ;; received NO reponse for
677 ;; nntp-connection-timeout seconds.
678 (when (and -buffer (eq 0 (buffer-size -buffer)))
679 ;; Close the connection. Take no
680 ;; other action as the accept input
681 ;; code will handle the closed
682 ;; connection.
683 (nntp-kill-buffer -buffer))))))))
684 (unwind-protect
685 (setq nntp-with-open-group-internal
686 (condition-case nil
687 (funcall -bodyfun)
688 (quit
689 (unless debug-on-quit
690 (nntp-close-server))
691 (signal 'quit nil))))
692 (when -timer
693 (nnheader-cancel-timer -timer)))
694 nil))
695 (setf (symbol-function 'nntp-report) nntp-report-n))
696 nntp-with-open-group-internal))
697
651 (defmacro nntp-with-open-group (group server &optional connectionless &rest forms) 698 (defmacro nntp-with-open-group (group server &optional connectionless &rest forms)
652 "Protect against servers that don't like clients that keep idle connections opens. 699 "Protect against servers that don't like clients that keep idle connections opens.
653 The problem being that these servers may either close a connection or 700 The problem being that these servers may either close a connection or
654 simply ignore any further requests on a connection. Closed 701 simply ignore any further requests on a connection. Closed
655 connections are not detected until accept-process-output has updated 702 connections are not detected until `accept-process-output' has updated
656 the process-status. Dropped connections are not detected until the 703 the `process-status'. Dropped connections are not detected until the
657 connection timeouts (which may be several minutes) or 704 connection timeouts (which may be several minutes) or
658 nntp-connection-timeout has expired. When these occur 705 `nntp-connection-timeout' has expired. When these occur
659 nntp-with-open-group, opens a new connection then re-issues the NNTP 706 `nntp-with-open-group', opens a new connection then re-issues the NNTP
660 command whose response triggered the error." 707 command whose response triggered the error."
708 (declare (indent 2) (debug (form form [&optional symbolp] def-body)))
661 (when (and (listp connectionless) 709 (when (and (listp connectionless)
662 (not (eq connectionless nil))) 710 (not (eq connectionless nil)))
663 (setq forms (cons connectionless forms) 711 (setq forms (cons connectionless forms)
664 connectionless nil)) 712 connectionless nil))
665 `(letf ((nntp-report-n (symbol-function 'nntp-report)) 713 `(nntp-with-open-group-function ,group ,server ,connectionless (lambda () ,@forms)))
666 ((symbol-function 'nntp-report) (symbol-function 'nntp-report-1))
667 (nntp-with-open-group-internal nil))
668 (while (catch 'nntp-with-open-group-error
669 ;; Open the connection to the server
670 ;; NOTE: Existing connections are NOT tested.
671 (nntp-possibly-change-group ,group ,server ,connectionless)
672
673 (let ((timer
674 (and nntp-connection-timeout
675 (run-at-time
676 nntp-connection-timeout nil
677 '(lambda ()
678 (let ((process (nntp-find-connection
679 nntp-server-buffer))
680 (buffer (and process
681 (process-buffer process))))
682 ;; When I am able to identify the
683 ;; connection to the server AND I've
684 ;; received NO reponse for
685 ;; nntp-connection-timeout seconds.
686 (when (and buffer (eq 0 (buffer-size buffer)))
687 ;; Close the connection. Take no
688 ;; other action as the accept input
689 ;; code will handle the closed
690 ;; connection.
691 (nntp-kill-buffer buffer))))))))
692 (unwind-protect
693 (setq nntp-with-open-group-internal
694 (condition-case nil
695 (progn ,@forms)
696 (quit
697 (unless debug-on-quit
698 (nntp-close-server))
699 (signal 'quit nil))))
700 (when timer
701 (nnheader-cancel-timer timer)))
702 nil))
703 (setf (symbol-function 'nntp-report) nntp-report-n))
704 nntp-with-open-group-internal))
705 714
706 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old) 715 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
707 "Retrieve the headers of ARTICLES." 716 "Retrieve the headers of ARTICLES."
708 (nntp-with-open-group 717 (nntp-with-open-group
709 group server 718 group server
710 (save-excursion 719 (with-current-buffer (nntp-find-connection-buffer nntp-server-buffer)
711 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
712 (erase-buffer) 720 (erase-buffer)
713 (if (and (not gnus-nov-is-evil) 721 (if (and (not gnus-nov-is-evil)
714 (not nntp-nov-is-evil) 722 (not nntp-nov-is-evil)
715 (nntp-retrieve-headers-with-xover articles fetch-old)) 723 (nntp-retrieve-headers-with-xover articles fetch-old))
716 ;; We successfully retrieved the headers via XOVER. 724 ;; We successfully retrieved the headers via XOVER.
928 (cons (car entry) point)) 936 (cons (car entry) point))
929 map))))) 937 map)))))
930 938
931 (defun nntp-try-list-active (group) 939 (defun nntp-try-list-active (group)
932 (nntp-list-active-group group) 940 (nntp-list-active-group group)
933 (save-excursion 941 (with-current-buffer nntp-server-buffer
934 (set-buffer nntp-server-buffer)
935 (goto-char (point-min)) 942 (goto-char (point-min))
936 (cond ((or (eobp) 943 (cond ((or (eobp)
937 (looking-at "5[0-9]+")) 944 (looking-at "5[0-9]+"))
938 (setq nntp-server-list-active-group nil)) 945 (setq nntp-server-list-active-group nil))
939 (t 946 (t
957 (when (nntp-send-command-and-decode 964 (when (nntp-send-command-and-decode
958 "\r?\n\\.\r?\n" "ARTICLE" 965 "\r?\n\\.\r?\n" "ARTICLE"
959 (if (numberp article) (int-to-string article) article)) 966 (if (numberp article) (int-to-string article) article))
960 (if (and buffer 967 (if (and buffer
961 (not (equal buffer nntp-server-buffer))) 968 (not (equal buffer nntp-server-buffer)))
962 (save-excursion 969 (with-current-buffer nntp-server-buffer
963 (set-buffer nntp-server-buffer)
964 (copy-to-buffer buffer (point-min) (point-max)) 970 (copy-to-buffer buffer (point-min) (point-max))
965 (nntp-find-group-and-number group)) 971 (nntp-find-group-and-number group))
966 (nntp-find-group-and-number group))))) 972 (nntp-find-group-and-number group)))))
967 973
968 (deffoo nntp-request-head (article &optional group server) 974 (deffoo nntp-request-head (article &optional group server)
1055 (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS"))) 1061 (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS")))
1056 1062
1057 (deffoo nntp-request-newgroups (date &optional server) 1063 (deffoo nntp-request-newgroups (date &optional server)
1058 (nntp-with-open-group 1064 (nntp-with-open-group
1059 nil server 1065 nil server
1060 (save-excursion 1066 (with-current-buffer nntp-server-buffer
1061 (set-buffer nntp-server-buffer)
1062 (let* ((time (date-to-time date)) 1067 (let* ((time (date-to-time date))
1063 (ls (- (cadr time) (nth 8 (decode-time time))))) 1068 (ls (- (cadr time) (nth 8 (decode-time time)))))
1064 (cond ((< ls 0) 1069 (cond ((< ls 0)
1065 (setcar time (1- (car time))) 1070 (setcar time (1- (car time)))
1066 (setcar (cdr time) (+ ls 65536))) 1071 (setcar (cdr time) (+ ls 65536)))
1225 (nntp-erase-buffer nntp-server-buffer) 1230 (nntp-erase-buffer nntp-server-buffer)
1226 (nntp-send-string process last))) 1231 (nntp-send-string process last)))
1227 1232
1228 (defun nntp-make-process-buffer (buffer) 1233 (defun nntp-make-process-buffer (buffer)
1229 "Create a new, fresh buffer usable for nntp process connections." 1234 "Create a new, fresh buffer usable for nntp process connections."
1230 (save-excursion 1235 (with-current-buffer
1231 (set-buffer 1236 (generate-new-buffer
1232 (generate-new-buffer 1237 (format " *server %s %s %s*"
1233 (format " *server %s %s %s*" 1238 nntp-address nntp-port-number
1234 nntp-address nntp-port-number 1239 (gnus-buffer-exists-p buffer)))
1235 (gnus-buffer-exists-p buffer))))
1236 (mm-disable-multibyte) 1240 (mm-disable-multibyte)
1237 (set (make-local-variable 'after-change-functions) nil) 1241 (set (make-local-variable 'after-change-functions) nil)
1238 (set (make-local-variable 'nntp-process-wait-for) nil) 1242 (set (make-local-variable 'nntp-process-wait-for) nil)
1239 (set (make-local-variable 'nntp-process-callback) nil) 1243 (set (make-local-variable 'nntp-process-callback) nil)
1240 (set (make-local-variable 'nntp-process-to-buffer) nil) 1244 (set (make-local-variable 'nntp-process-to-buffer) nil)
1273 (if (and (nntp-wait-for process "^2.*\n" buffer nil t) 1277 (if (and (nntp-wait-for process "^2.*\n" buffer nil t)
1274 (memq (process-status process) '(open run))) 1278 (memq (process-status process) '(open run)))
1275 (prog1 1279 (prog1
1276 (caar (push (list process buffer nil) nntp-connection-alist)) 1280 (caar (push (list process buffer nil) nntp-connection-alist))
1277 (push process nntp-connection-list) 1281 (push process nntp-connection-list)
1278 (save-excursion 1282 (with-current-buffer pbuffer
1279 (set-buffer pbuffer)
1280 (nntp-read-server-type) 1283 (nntp-read-server-type)
1281 (erase-buffer) 1284 (erase-buffer)
1282 (set-buffer nntp-server-buffer) 1285 (set-buffer nntp-server-buffer)
1283 (let ((nnheader-callback-function nil)) 1286 (let ((nnheader-callback-function nil))
1284 (run-hooks 'nntp-server-opened-hook) 1287 (run-hooks 'nntp-server-opened-hook)
1302 (format-spec nntp-ssl-program 1305 (format-spec nntp-ssl-program
1303 (format-spec-make 1306 (format-spec-make
1304 ?s nntp-address 1307 ?s nntp-address
1305 ?p nntp-port-number))))) 1308 ?p nntp-port-number)))))
1306 (gnus-set-process-query-on-exit-flag proc nil) 1309 (gnus-set-process-query-on-exit-flag proc nil)
1307 (save-excursion 1310 (with-current-buffer buffer
1308 (set-buffer buffer)
1309 (let ((nntp-connection-alist (list proc buffer nil))) 1311 (let ((nntp-connection-alist (list proc buffer nil)))
1310 (nntp-wait-for-string "^\r*20[01]")) 1312 (nntp-wait-for-string "^\r*20[01]"))
1311 (beginning-of-line) 1313 (beginning-of-line)
1312 (delete-region (point-min) (point)) 1314 (delete-region (point-min) (point))
1313 proc))) 1315 proc)))
1314 1316
1315 (defun nntp-open-tls-stream (buffer) 1317 (defun nntp-open-tls-stream (buffer)
1316 (let ((proc (open-tls-stream "nntpd" buffer nntp-address nntp-port-number))) 1318 (let ((proc (open-tls-stream "nntpd" buffer nntp-address nntp-port-number)))
1317 (gnus-set-process-query-on-exit-flag proc nil) 1319 (gnus-set-process-query-on-exit-flag proc nil)
1318 (save-excursion 1320 (with-current-buffer buffer
1319 (set-buffer buffer)
1320 (let ((nntp-connection-alist (list proc buffer nil))) 1321 (let ((nntp-connection-alist (list proc buffer nil)))
1321 (nntp-wait-for-string "^\r*20[01]")) 1322 (nntp-wait-for-string "^\r*20[01]"))
1322 (beginning-of-line) 1323 (beginning-of-line)
1323 (delete-region (point-min) (point)) 1324 (delete-region (point-min) (point))
1324 proc))) 1325 proc)))
1335 (not (eq 'lambda (caadr entry)))) 1336 (not (eq 'lambda (caadr entry))))
1336 (eval (cadr entry)) 1337 (eval (cadr entry))
1337 (funcall (cadr entry))))))) 1338 (funcall (cadr entry)))))))
1338 1339
1339 (defun nntp-async-wait (process wait-for buffer decode callback) 1340 (defun nntp-async-wait (process wait-for buffer decode callback)
1340 (save-excursion 1341 (with-current-buffer (process-buffer process)
1341 (set-buffer (process-buffer process))
1342 (unless nntp-inside-change-function 1342 (unless nntp-inside-change-function
1343 (erase-buffer)) 1343 (erase-buffer))
1344 (setq nntp-process-wait-for wait-for 1344 (setq nntp-process-wait-for wait-for
1345 nntp-process-to-buffer buffer 1345 nntp-process-to-buffer buffer
1346 nntp-process-decode decode 1346 nntp-process-decode decode
1384 ;; set to nil. so we reset it here, if necessary. 1384 ;; set to nil. so we reset it here, if necessary.
1385 (when quit-flag 1385 (when quit-flag
1386 (setq after-change-functions '(nntp-after-change-function))))) 1386 (setq after-change-functions '(nntp-after-change-function)))))
1387 1387
1388 (defun nntp-async-trigger (process) 1388 (defun nntp-async-trigger (process)
1389 (save-excursion 1389 (with-current-buffer (process-buffer process)
1390 (set-buffer (process-buffer process))
1391 (when nntp-process-callback 1390 (when nntp-process-callback
1392 ;; do we have an error message? 1391 ;; do we have an error message?
1393 (goto-char nntp-process-start-point) 1392 (goto-char nntp-process-start-point)
1394 (if (memq (following-char) '(?4 ?5)) 1393 (if (memq (following-char) '(?4 ?5))
1395 ;; wants credentials? 1394 ;; wants credentials?
1410 ;; convert it. 1409 ;; convert it.
1411 (when (gnus-buffer-exists-p nntp-process-to-buffer) 1410 (when (gnus-buffer-exists-p nntp-process-to-buffer)
1412 (let ((buf (current-buffer)) 1411 (let ((buf (current-buffer))
1413 (start nntp-process-start-point) 1412 (start nntp-process-start-point)
1414 (decode nntp-process-decode)) 1413 (decode nntp-process-decode))
1415 (save-excursion 1414 (with-current-buffer nntp-process-to-buffer
1416 (set-buffer nntp-process-to-buffer)
1417 (goto-char (point-max)) 1415 (goto-char (point-max))
1418 (save-restriction 1416 (save-restriction
1419 (narrow-to-region (point) (point)) 1417 (narrow-to-region (point) (point))
1420 (nntp-insert-buffer-substring buf start) 1418 (nntp-insert-buffer-substring buf start)
1421 (when decode 1419 (when decode
1475 (when group 1473 (when group
1476 (let ((entry (nntp-find-connection-entry nntp-server-buffer))) 1474 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
1477 (cond ((not entry) 1475 (cond ((not entry)
1478 (nntp-report "Server closed connection")) 1476 (nntp-report "Server closed connection"))
1479 ((not (equal group (caddr entry))) 1477 ((not (equal group (caddr entry)))
1480 (save-excursion 1478 (with-current-buffer (process-buffer (car entry))
1481 (set-buffer (process-buffer (car entry)))
1482 (erase-buffer) 1479 (erase-buffer)
1483 (nntp-send-command "^[245].*\n" "GROUP" group) 1480 (nntp-send-command "^[245].*\n" "GROUP" group)
1484 (setcar (cddr entry) group) 1481 (setcar (cddr entry) group)
1485 (erase-buffer) 1482 (erase-buffer)
1486 (nntp-erase-buffer nntp-server-buffer))))))) 1483 (nntp-erase-buffer nntp-server-buffer)))))))
1676 (let ((commands nntp-xover-commands)) 1673 (let ((commands nntp-xover-commands))
1677 ;; `nntp-xover-commands' is a list of possible XOVER commands. 1674 ;; `nntp-xover-commands' is a list of possible XOVER commands.
1678 ;; We try them all until we get at positive response. 1675 ;; We try them all until we get at positive response.
1679 (while (and commands (eq nntp-server-xover 'try)) 1676 (while (and commands (eq nntp-server-xover 'try))
1680 (nntp-send-command-nodelete "\r?\n\\.\r?\n" (car commands) range) 1677 (nntp-send-command-nodelete "\r?\n\\.\r?\n" (car commands) range)
1681 (save-excursion 1678 (with-current-buffer nntp-server-buffer
1682 (set-buffer nntp-server-buffer)
1683 (goto-char (point-min)) 1679 (goto-char (point-min))
1684 (and (looking-at "[23]") ; No error message. 1680 (and (looking-at "[23]") ; No error message.
1685 ;; We also have to look at the lines. Some buggy 1681 ;; We also have to look at the lines. Some buggy
1686 ;; servers give back simple lines with just the 1682 ;; servers give back simple lines with just the
1687 ;; article number. How... helpful. 1683 ;; article number. How... helpful.
1698 nntp-server-xover)))) 1694 nntp-server-xover))))
1699 1695
1700 (defun nntp-find-group-and-number (&optional group) 1696 (defun nntp-find-group-and-number (&optional group)
1701 (save-excursion 1697 (save-excursion
1702 (save-restriction 1698 (save-restriction
1699 ;; FIXME: This is REALLY FISHY: set-buffer after save-restriction?!?
1703 (set-buffer nntp-server-buffer) 1700 (set-buffer nntp-server-buffer)
1704 (narrow-to-region (goto-char (point-min)) 1701 (narrow-to-region (goto-char (point-min))
1705 (or (search-forward "\n\n" nil t) (point-max))) 1702 (or (search-forward "\n\n" nil t) (point-max)))
1706 (goto-char (point-min)) 1703 (goto-char (point-min))
1707 ;; We first find the number by looking at the status line. 1704 ;; We first find the number by looking at the status line.
1874 ;; Replacements for the nntp-open-* functions -- drv 1871 ;; Replacements for the nntp-open-* functions -- drv
1875 ;; ========================================================================== 1872 ;; ==========================================================================
1876 1873
1877 (defun nntp-open-telnet-stream (buffer) 1874 (defun nntp-open-telnet-stream (buffer)
1878 "Open a nntp connection by telnet'ing the news server. 1875 "Open a nntp connection by telnet'ing the news server.
1876 `nntp-open-via-netcat' is recommended in place of this function
1877 because it is more reliable.
1879 1878
1880 Please refer to the following variables to customize the connection: 1879 Please refer to the following variables to customize the connection:
1881 - `nntp-pre-command', 1880 - `nntp-pre-command',
1882 - `nntp-telnet-command', 1881 - `nntp-telnet-command',
1883 - `nntp-telnet-switches', 1882 - `nntp-telnet-switches',
1889 ,nntp-address ,nntp-port-number)) 1888 ,nntp-address ,nntp-port-number))
1890 proc) 1889 proc)
1891 (and nntp-pre-command 1890 (and nntp-pre-command
1892 (push nntp-pre-command command)) 1891 (push nntp-pre-command command))
1893 (setq proc (apply 'start-process "nntpd" buffer command)) 1892 (setq proc (apply 'start-process "nntpd" buffer command))
1894 (save-excursion 1893 (with-current-buffer buffer
1895 (set-buffer buffer)
1896 (nntp-wait-for-string "^\r*20[01]") 1894 (nntp-wait-for-string "^\r*20[01]")
1897 (beginning-of-line) 1895 (beginning-of-line)
1898 (delete-region (point-min) (point)) 1896 (delete-region (point-min) (point))
1899 proc))) 1897 proc)))
1900 1898
1901 (defun nntp-open-via-rlogin-and-telnet (buffer) 1899 (defun nntp-open-via-rlogin-and-telnet (buffer)
1902 "Open a connection to an nntp server through an intermediate host. 1900 "Open a connection to an nntp server through an intermediate host.
1903 First rlogin to the remote host, and then telnet the real news server 1901 First rlogin to the remote host, and then telnet the real news server
1904 from there. 1902 from there.
1903 `nntp-open-via-rlogin-and-netcat' is recommended in place of this function
1904 because it is more reliable.
1905 1905
1906 Please refer to the following variables to customize the connection: 1906 Please refer to the following variables to customize the connection:
1907 - `nntp-pre-command', 1907 - `nntp-pre-command',
1908 - `nntp-via-rlogin-command', 1908 - `nntp-via-rlogin-command',
1909 - `nntp-via-rlogin-command-switches', 1909 - `nntp-via-rlogin-command-switches',
1924 (setq command (append nntp-via-rlogin-command-switches command))) 1924 (setq command (append nntp-via-rlogin-command-switches command)))
1925 (push nntp-via-rlogin-command command) 1925 (push nntp-via-rlogin-command command)
1926 (and nntp-pre-command 1926 (and nntp-pre-command
1927 (push nntp-pre-command command)) 1927 (push nntp-pre-command command))
1928 (setq proc (apply 'start-process "nntpd" buffer command)) 1928 (setq proc (apply 'start-process "nntpd" buffer command))
1929 (save-excursion 1929 (with-current-buffer buffer
1930 (set-buffer buffer)
1931 (nntp-wait-for-string "^r?telnet") 1930 (nntp-wait-for-string "^r?telnet")
1932 (process-send-string proc (concat "open " nntp-address 1931 (process-send-string proc (concat "open " nntp-address
1933 " " nntp-port-number "\n")) 1932 " " nntp-port-number "\n"))
1934 (nntp-wait-for-string "^\r*20[01]") 1933 (nntp-wait-for-string "^\r*20[01]")
1935 (beginning-of-line) 1934 (beginning-of-line)
1991 - `nntp-telnet-command', 1990 - `nntp-telnet-command',
1992 - `nntp-telnet-switches', 1991 - `nntp-telnet-switches',
1993 - `nntp-address', 1992 - `nntp-address',
1994 - `nntp-port-number', 1993 - `nntp-port-number',
1995 - `nntp-end-of-line'." 1994 - `nntp-end-of-line'."
1996 (save-excursion 1995 (with-current-buffer buffer
1997 (set-buffer buffer)
1998 (erase-buffer) 1996 (erase-buffer)
1999 (let ((command `(,nntp-via-telnet-command ,@nntp-via-telnet-switches)) 1997 (let ((command `(,nntp-via-telnet-command ,@nntp-via-telnet-switches))
2000 (case-fold-search t) 1998 (case-fold-search t)
2001 proc) 1999 proc)
2002 (and nntp-pre-command (push nntp-pre-command command)) 2000 (and nntp-pre-command (push nntp-pre-command command))
2139 (nnheader-message 7 "Bootstrapping marks for %s...done" 2137 (nnheader-message 7 "Bootstrapping marks for %s...done"
2140 decoded-name))))) 2138 decoded-name)))))
2141 2139
2142 (provide 'nntp) 2140 (provide 'nntp)
2143 2141
2144 ;;; arch-tag: 8655466a-b1b5-4929-9c45-7b1b2e767271 2142 ;; arch-tag: 8655466a-b1b5-4929-9c45-7b1b2e767271
2145 ;;; nntp.el ends here 2143 ;;; nntp.el ends here