comparison lisp/gnus/nntp.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 0293115a14e9
comparison
equal deleted inserted replaced
1:c0c6a60d29db 2:ac2d302a0011
90 system (see nntp-port-number). The other is `nntp-open-rlogin', which 90 system (see nntp-port-number). The other is `nntp-open-rlogin', which
91 does an rlogin on the remote system, and then does a telnet to the 91 does an rlogin on the remote system, and then does a telnet to the
92 NNTP server available there (see nntp-rlogin-parameters).") 92 NNTP server available there (see nntp-rlogin-parameters).")
93 93
94 (defvoo nntp-rlogin-parameters '("telnet" "${NNTPSERVER:=localhost}" "nntp") 94 (defvoo nntp-rlogin-parameters '("telnet" "${NNTPSERVER:=localhost}" "nntp")
95 "*Parameters to `nntp-open-login'. 95 "*Parameters to `nntp-open-rlogin'.
96 That function may be used as `nntp-open-server-function'. In that 96 That function may be used as `nntp-open-server-function'. In that
97 case, this list will be used as the parameter list given to rsh.") 97 case, this list will be used as the parameter list given to rsh.")
98 98
99 (defvoo nntp-rlogin-user-name nil 99 (defvoo nntp-rlogin-user-name nil
100 "*User name on remote system when using the rlogin connect method.") 100 "*User name on remote system when using the rlogin connect method.")
101
102 (defvoo nntp-telnet-parameters '("exec" "telnet" "-8" "${NNTPSERVER:=localhost}" "nntp")
103 "*Parameters to `nntp-open-telnet'.
104 That function may be used as `nntp-open-server-function'. In that
105 case, this list will be executed as a command after logging in
106 via telnet.")
107
108 (defvoo nntp-telnet-user-name nil
109 "User name to log in via telnet with.")
110
111 (defvoo nntp-telnet-passwd nil
112 "Password to use to log in via telnet with.")
101 113
102 (defvoo nntp-address nil 114 (defvoo nntp-address nil
103 "*The name of the NNTP server.") 115 "*The name of the NNTP server.")
104 116
105 (defvoo nntp-port-number "nntp" 117 (defvoo nntp-port-number "nntp"
106 "*Port number to connect to.") 118 "*Port number to connect to.")
107 119
108 (defvoo nntp-end-of-line "\r\n" 120 (defvoo nntp-end-of-line "\r\n"
109 "String to use on the end of lines when talking to the NNTP server. 121 "String to use on the end of lines when talking to the NNTP server.
110 This is \"\\r\\n\" by default, but should be \"\\n\" when 122 This is \"\\r\\n\" by default, but should be \"\\n\" when
111 using rlogin to communicate with the server.") 123 using rlogin or telnet to communicate with the server.")
112 124
113 (defvoo nntp-large-newsgroup 50 125 (defvoo nntp-large-newsgroup 50
114 "*The number of the articles which indicates a large newsgroup. 126 "*The number of the articles which indicates a large newsgroup.
115 If the number of the articles is greater than the value, verbose 127 If the number of the articles is greater than the value, verbose
116 messages will be shown to indicate the current status.") 128 messages will be shown to indicate the current status.")
337 349
338 (deffoo nntp-open-server (server &optional defs connectionless) 350 (deffoo nntp-open-server (server &optional defs connectionless)
339 "Open the virtual server SERVER. 351 "Open the virtual server SERVER.
340 If CONNECTIONLESS is non-nil, don't attempt to connect to any physical 352 If CONNECTIONLESS is non-nil, don't attempt to connect to any physical
341 servers." 353 servers."
354 (nnheader-init-server-buffer)
342 ;; Called with just a port number as the defs. 355 ;; Called with just a port number as the defs.
343 (when (or (stringp (car defs)) 356 (when (or (stringp (car defs))
344 (numberp (car defs))) 357 (numberp (car defs)))
345 (setq defs `((nntp-port-number ,(car defs))))) 358 (setq defs `((nntp-port-number ,(car defs)))))
346 (unless (assq 'nntp-address defs) 359 (unless (assq 'nntp-address defs)
395 (while (setq entry (pop alist)) 408 (while (setq entry (pop alist))
396 (and (setq proc (cdr (assq 'nntp-async-buffer entry))) 409 (and (setq proc (cdr (assq 'nntp-async-buffer entry)))
397 (buffer-name proc) 410 (buffer-name proc)
398 (kill-buffer proc)))) 411 (kill-buffer proc))))
399 (nnoo-close-server 'nntp) 412 (nnoo-close-server 'nntp)
400 (setq nntp-async-group-alist nil))) 413 (setq nntp-async-group-alist nil
414 nntp-async-articles nil)))
401 415
402 (deffoo nntp-server-opened (&optional server) 416 (deffoo nntp-server-opened (&optional server)
403 "Say whether a connection to SERVER has been opened." 417 "Say whether a connection to SERVER has been opened."
404 (and (nnoo-current-server-p 'nntp server) 418 (and (nnoo-current-server-p 'nntp server)
405 nntp-server-buffer 419 nntp-server-buffer
718 1. Insert `.' at beginning of line. 732 1. Insert `.' at beginning of line.
719 2. Insert `.' at end of buffer (end of text mark)." 733 2. Insert `.' at end of buffer (end of text mark)."
720 (save-excursion 734 (save-excursion
721 ;; Replace `.' at beginning of line with `..'. 735 ;; Replace `.' at beginning of line with `..'.
722 (goto-char (point-min)) 736 (goto-char (point-min))
723 (while (search-forward "\n." nil t) 737 (while (re-search-forward "^\\." nil t)
724 (insert ".")) 738 (insert "."))
725 (goto-char (point-max)) 739 (goto-char (point-max))
726 ;; Insert newline at end of buffer. 740 ;; Insert newline at end of buffer.
727 (or (bolp) (insert "\n")) 741 (or (bolp) (insert "\n"))
742 ;(goto-char (point-min))
743 ;(while (not (eobp))
744 ; (end-of-line)
745 ; (insert "\r")
746 ; (forward-line 1))
728 ;; Insert `.' at end of buffer (end of text mark). 747 ;; Insert `.' at end of buffer (end of text mark).
748 (goto-char (point-max))
729 (insert "." nntp-end-of-line))) 749 (insert "." nntp-end-of-line)))
750
730 751
731 752
732 ;;; 753 ;;;
733 ;;; Synchronous Communication with NNTP servers. 754 ;;; Synchronous Communication with NNTP servers.
734 ;;; 755 ;;;
959 980
960 ;; Every 400 requests we have to read the stream in 981 ;; Every 400 requests we have to read the stream in
961 ;; order to avoid deadlocks. 982 ;; order to avoid deadlocks.
962 (when (or (null articles) ;All requests have been sent. 983 (when (or (null articles) ;All requests have been sent.
963 (zerop (% count nntp-maximum-request))) 984 (zerop (% count nntp-maximum-request)))
964 (accept-process-output) 985 (accept-process-output nntp-server-process 1)
965 ;; On some Emacs versions the preceding function has 986 ;; On some Emacs versions the preceding function has
966 ;; a tendency to change the buffer. Perhaps. It's 987 ;; a tendency to change the buffer. Perhaps. It's
967 ;; quite difficult to reproduce, because it only 988 ;; quite difficult to reproduce, because it only
968 ;; seems to happen once in a blue moon. 989 ;; seems to happen once in a blue moon.
969 (set-buffer buf) 990 (set-buffer buf)
972 ;; Count replies. 993 ;; Count replies.
973 (while (re-search-forward "^[0-9][0-9][0-9] " nil t) 994 (while (re-search-forward "^[0-9][0-9][0-9] " nil t)
974 (setq received (1+ received))) 995 (setq received (1+ received)))
975 (setq last-point (point)) 996 (setq last-point (point))
976 (< received count)) 997 (< received count))
977 (accept-process-output) 998 (accept-process-output nntp-server-process)
978 (set-buffer buf))))) 999 (set-buffer buf)))))
979 1000
980 (when nntp-server-xover 1001 (when nntp-server-xover
981 ;; Wait for the reply from the final command. 1002 ;; Wait for the reply from the final command.
982 (goto-char (point-max)) 1003 (goto-char (point-max))
1036 "Send STRINGS to the server." 1057 "Send STRINGS to the server."
1037 (let ((cmd (concat (mapconcat 'identity strings " ") nntp-end-of-line))) 1058 (let ((cmd (concat (mapconcat 'identity strings " ") nntp-end-of-line)))
1038 ;; We open the nntp server if it is down. 1059 ;; We open the nntp server if it is down.
1039 (or (nntp-server-opened (nnoo-current-server 'nntp)) 1060 (or (nntp-server-opened (nnoo-current-server 'nntp))
1040 (nntp-open-server (nnoo-current-server 'nntp)) 1061 (nntp-open-server (nnoo-current-server 'nntp))
1041 (error (nntp-status-message))) 1062 (error "Couldn't open server: " (nntp-status-message)))
1042 ;; Send the strings. 1063 ;; Send the strings.
1043 (process-send-string nntp-server-process cmd) 1064 (process-send-string nntp-server-process cmd)
1044 t)) 1065 t))
1045 1066
1046 (defun nntp-send-region-to-server (begin end) 1067 (defun nntp-send-region-to-server (begin end)
1067 (kill-buffer (current-buffer))))) 1088 (kill-buffer (current-buffer)))))
1068 1089
1069 (defun nntp-open-server-semi-internal (server &optional service) 1090 (defun nntp-open-server-semi-internal (server &optional service)
1070 "Open SERVER. 1091 "Open SERVER.
1071 If SERVER is nil, use value of environment variable `NNTPSERVER'. 1092 If SERVER is nil, use value of environment variable `NNTPSERVER'.
1072 If SERVICE, this this as the port number." 1093 If SERVICE, use this as the port number."
1073 (nnheader-insert "") 1094 (nnheader-insert "")
1074 (let ((server (or server (getenv "NNTPSERVER"))) 1095 (let ((server (or server (getenv "NNTPSERVER")))
1075 (status nil) 1096 (status nil)
1076 (timer 1097 (timer
1077 (and nntp-connection-timeout 1098 (and nntp-connection-timeout
1085 (setq nntp-address server) 1106 (setq nntp-address server)
1086 (setq status 1107 (setq status
1087 (condition-case nil 1108 (condition-case nil
1088 (nntp-wait-for-response "^[23].*\r?\n" 'slow) 1109 (nntp-wait-for-response "^[23].*\r?\n" 'slow)
1089 (error nil) 1110 (error nil)
1090 (quit nil))) 1111 ;(quit nil)
1112 ))
1091 (unless status 1113 (unless status
1092 (nntp-close-server-internal server) 1114 (nntp-close-server-internal server)
1093 (nnheader-report 1115 (nnheader-report
1094 'nntp "Couldn't open connection to %s" 1116 'nntp "Couldn't open connection to %s"
1095 (if (and nntp-address 1117 (if (and nntp-address
1102 ;; Added by Hallvard B Furuseth <h.b.furuseth@usit.uio.no> 1124 ;; Added by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>
1103 (run-hooks 'nntp-server-opened-hook))) 1125 (run-hooks 'nntp-server-opened-hook)))
1104 ((null server) 1126 ((null server)
1105 (nnheader-report 'nntp "NNTP server is not specified.")) 1127 (nnheader-report 'nntp "NNTP server is not specified."))
1106 (t ; We couldn't open the server. 1128 (t ; We couldn't open the server.
1107 (nnheader-report 1129 (nnheader-report 'nntp (buffer-string))))
1108 'nntp (buffer-substring (point-min) (point-max)))))
1109 (when timer 1130 (when timer
1110 (nnheader-cancel-timer timer)) 1131 (nnheader-cancel-timer timer))
1111 (message "") 1132 (message "")
1112 (unless status 1133 (unless status
1113 (nnoo-close-server 'nntp server) 1134 (nnoo-close-server 'nntp server)
1171 (defun nntp-open-network-stream (server) 1192 (defun nntp-open-network-stream (server)
1172 (open-network-stream 1193 (open-network-stream
1173 "nntpd" nntp-server-buffer server nntp-port-number)) 1194 "nntpd" nntp-server-buffer server nntp-port-number))
1174 1195
1175 (defun nntp-open-rlogin (server) 1196 (defun nntp-open-rlogin (server)
1197 "Open a connection to SERVER using rsh."
1176 (let ((proc (if nntp-rlogin-user-name 1198 (let ((proc (if nntp-rlogin-user-name
1177 (start-process 1199 (start-process
1178 "nntpd" nntp-server-buffer "rsh" 1200 "nntpd" nntp-server-buffer "rsh"
1179 "-l" nntp-rlogin-user-name server 1201 server "-l" nntp-rlogin-user-name
1180 (mapconcat 'identity 1202 (mapconcat 'identity
1181 nntp-rlogin-parameters " ")) 1203 nntp-rlogin-parameters " "))
1182 (start-process 1204 (start-process
1183 "nntpd" nntp-server-buffer "rsh" server 1205 "nntpd" nntp-server-buffer "rsh" server
1184 (mapconcat 'identity 1206 (mapconcat 'identity
1185 nntp-rlogin-parameters " "))))) 1207 nntp-rlogin-parameters " ")))))
1186 proc)) 1208 proc))
1187 1209
1188 (defun nntp-telnet-to-machine () 1210 (defun nntp-wait-for-string (regexp)
1189 (let (b) 1211 "Wait until string arrives in the buffer."
1190 (telnet "localhost") 1212 (let ((buf (current-buffer)))
1191 (goto-char (point-min)) 1213 (goto-char (point-min))
1192 (while (not (re-search-forward "^login: *" nil t)) 1214 (while (not (re-search-forward regexp nil t))
1193 (sit-for 1) 1215 (accept-process-output nntp-server-process)
1194 (goto-char (point-min))) 1216 (set-buffer buf)
1195 (goto-char (point-max)) 1217 (goto-char (point-min)))))
1196 (insert "larsi") 1218
1197 (telnet-send-input) 1219 (defun nntp-open-telnet (server)
1198 (setq b (point)) 1220 (save-excursion
1199 (while (not (re-search-forward ">" nil t)) 1221 (set-buffer nntp-server-buffer)
1200 (sit-for 1) 1222 (erase-buffer)
1201 (goto-char b)) 1223 (let ((proc (start-process
1202 (goto-char (point-max)) 1224 "nntpd" nntp-server-buffer "telnet" "-8"))
1203 (insert "ls") 1225 (case-fold-search t))
1204 (telnet-send-input))) 1226 (when (memq (process-status proc) '(open run))
1227 (process-send-string proc "set escape \^X\n")
1228 (process-send-string proc (concat "open " server "\n"))
1229 (nntp-wait-for-string "^\r*.?login:")
1230 (process-send-string
1231 proc (concat
1232 (or nntp-telnet-user-name
1233 (setq nntp-telnet-user-name (read-string "login: ")))
1234 "\n"))
1235 (nntp-wait-for-string "^\r*.?password:")
1236 (process-send-string
1237 proc (concat
1238 (or nntp-telnet-passwd
1239 (setq nntp-telnet-passwd
1240 (nnmail-read-passwd "Password: ")))
1241 "\n"))
1242 (erase-buffer)
1243 (nntp-wait-for-string "bash\\|\$ *\r?$\\|> *\r?")
1244 (process-send-string
1245 proc (concat (mapconcat 'identity nntp-telnet-parameters " ") "\n"))
1246 (nntp-wait-for-string "^\r*200")
1247 (beginning-of-line)
1248 (delete-region (point-min) (point))
1249 (process-send-string proc "\^]")
1250 (nntp-wait-for-string "^telnet")
1251 (process-send-string proc "mode character\n")
1252 (accept-process-output proc 1)
1253 (sit-for 1)
1254 (goto-char (point-min))
1255 (forward-line 1)
1256 (delete-region (point) (point-max)))
1257 proc)))
1205 1258
1206 (defun nntp-close-server-internal (&optional server) 1259 (defun nntp-close-server-internal (&optional server)
1207 "Close connection to news server." 1260 "Close connection to news server."
1208 (nntp-possibly-change-server nil server) 1261 (nntp-possibly-change-server nil server)
1209 (if nntp-server-process 1262 (if nntp-server-process
1210 (delete-process nntp-server-process)) 1263 (delete-process nntp-server-process))
1211 (setq nntp-server-process nil) 1264 (setq nntp-server-process nil)
1212 (setq nntp-address "")) 1265 ;(setq nntp-address "")
1266 )
1213 1267
1214 (defun nntp-accept-response () 1268 (defun nntp-accept-response ()
1215 "Read response of server. 1269 "Read response of server.
1216 It is well-known that the communication speed will be much improved by 1270 It is well-known that the communication speed will be much improved by
1217 defining this function as macro." 1271 defining this function as macro."