1 ;;; nntp.el --- nntp access for Gnus
2 ;; Copyright (C) 1987, 1988, 1989, 1990, 1992, 1993, 1994, 1995, 1996,
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
30 (eval-when-compile (require 'cl))
31 (eval-when-compile (require 'gnus-clfns))
39 (defvoo nntp-address nil
40 "Address of the physical nntp server.")
42 (defvoo nntp-port-number "nntp"
43 "Port number on the physical nntp server.")
45 (defvoo nntp-list-options nil
46 "List of newsgroup name used for a option of the LIST command to
47 restrict the listing output to only the specified newsgroups.
48 Each newsgroup name can be a shell-style wildcard, for instance,
49 \"fj.*\", \"japan.*\", etc. Fortunately, if the server can accept
50 such a option, it will probably make gnus run faster. You may
51 use it as a server variable as follows:
53 \(setq gnus-select-method
54 '(nntp \"news.somewhere.edu\"
55 (nntp-list-options (\"fj.*\" \"japan.*\"))))")
57 (defvoo nntp-options-subscribe nil
58 "Regexp matching the newsgroup names which will be subscribed
59 unconditionally. It may be effective as well as `nntp-list-options'
60 even though the server could not accept a shell-style wildcard as a
61 option of the LIST command. You may use it as a server variable as
64 \(setq gnus-select-method
65 '(nntp \"news.somewhere.edu\"
66 (nntp-options-subscribe \"^fj\\\\.\\\\|^japan\\\\.\")))")
68 (defvoo nntp-options-not-subscribe nil
69 "Regexp matching the newsgroup names which will not be subscribed
70 unconditionally. It may be effective as well as `nntp-list-options'
71 even though the server could not accept a shell-style wildcard as a
72 option of the LIST command. You may use it as a server variable as
75 \(setq gnus-select-method
76 '(nntp \"news.somewhere.edu\"
77 (nntp-options-not-subscribe \"\\\\.binaries\\\\.\")))")
79 (defvoo nntp-server-opened-hook '(nntp-send-mode-reader)
80 "*Hook used for sending commands to the server at startup.
81 The default value is `nntp-send-mode-reader', which makes an innd
82 server spawn an nnrpd server.")
84 (defvoo nntp-authinfo-function 'nntp-send-authinfo
85 "Function used to send AUTHINFO to the server.
86 It is called with no parameters.")
88 (defvoo nntp-server-action-alist
89 '(("nntpd 1\\.5\\.11t"
90 (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader))
91 ("NNRP server Netscape"
92 (setq nntp-server-list-active-group nil)))
93 "Alist of regexps to match on server types and actions to be taken.
94 For instance, if you want Gnus to beep every time you connect
95 to innd, you could say something like:
97 \(setq nntp-server-action-alist
100 You probably don't want to do that, though.")
102 (defvoo nntp-open-connection-function 'nntp-open-network-stream
103 "*Function used for connecting to a remote system.
104 It will be called with the buffer to output in.
106 Two pre-made functions are `nntp-open-network-stream', which is the
107 default, and simply connects to some port or other on the remote
108 system (see nntp-port-number). The other are `nntp-open-rlogin',
109 which does an rlogin on the remote system, and then does a telnet to
110 the NNTP server available there (see nntp-rlogin-parameters) and
111 `nntp-open-telnet' which telnets to a remote system, logs in and does
114 (defvoo nntp-rlogin-program "rsh"
115 "*Program used to log in on remote machines.
116 The default is \"rsh\", but \"ssh\" is a popular alternative.")
118 (defvoo nntp-rlogin-parameters '("telnet" "-8" "${NNTPSERVER:=news}" "nntp")
119 "*Parameters to `nntp-open-rlogin'.
120 That function may be used as `nntp-open-connection-function'. In that
121 case, this list will be used as the parameter list given to rsh.")
123 (defvoo nntp-rlogin-user-name nil
124 "*User name on remote system when using the rlogin connect method.")
126 (defvoo nntp-telnet-parameters
127 '("exec" "telnet" "-8" "${NNTPSERVER:=news}" "nntp")
128 "*Parameters to `nntp-open-telnet'.
129 That function may be used as `nntp-open-connection-function'. In that
130 case, this list will be executed as a command after logging in
133 (defvoo nntp-telnet-user-name nil
134 "User name to log in via telnet with.")
136 (defvoo nntp-telnet-passwd nil
137 "Password to use to log in via telnet with.")
139 (defvoo nntp-open-telnet-envuser nil
140 "*If non-nil, telnet session (client and server both) will support the ENVIRON option and not prompt for login name.")
142 (defvoo nntp-telnet-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
143 "*Regular expression to match the shell prompt on the remote machine.")
145 (defvoo nntp-telnet-command "telnet"
146 "Command used to start telnet.")
148 (defvoo nntp-telnet-switches '("-8")
149 "Switches given to the telnet command.")
151 (defvoo nntp-end-of-line "\r\n"
152 "String to use on the end of lines when talking to the NNTP server.
153 This is \"\\r\\n\" by default, but should be \"\\n\" when
154 using rlogin or telnet to communicate with the server.")
156 (defvoo nntp-large-newsgroup 50
157 "*The number of the articles which indicates a large newsgroup.
158 If the number of the articles is greater than the value, verbose
159 messages will be shown to indicate the current status.")
161 (defvoo nntp-maximum-request 400
162 "*The maximum number of the requests sent to the NNTP server at one time.
163 If Emacs hangs up while retrieving headers, set the variable to a
166 (defvoo nntp-nov-is-evil nil
167 "*If non-nil, nntp will never attempt to use XOVER when talking to the server.")
169 (defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
170 "*List of strings that are used as commands to fetch NOV lines from a server.
171 The strings are tried in turn until a positive response is gotten. If
172 none of the commands are successful, nntp will just grab headers one
175 (defvoo nntp-nov-gap 5
176 "*Maximum allowed gap between two articles.
177 If the gap between two consecutive articles is bigger than this
178 variable, split the XOVER request into two requests.")
180 (defvoo nntp-prepare-server-hook nil
181 "*Hook run before a server is opened.
182 If can be used to set up a server remotely, for instance. Say you
183 have an account at the machine \"other.machine\". This machine has
184 access to an NNTP server that you can't access locally. You could
185 then use this hook to rsh to the remote machine and start a proxy NNTP
186 server there that you can connect to. See also
187 `nntp-open-connection-function'")
189 (defvoo nntp-warn-about-losing-connection t
190 "*If non-nil, beep when a server closes connection.")
192 (defcustom nntp-authinfo-file "~/.authinfo"
193 ".netrc-like file that holds nntp authinfo passwords."
196 (repeat :tag "Entries"
199 :value ("" ("login" . "") ("password" . ""))
203 (const :format "" "login")
204 (string :format "Login: %v"))
206 (const :format "" "password")
207 (string :format "Password: %v")))))))
211 (defvoo nntp-connection-timeout nil
212 "*Number of seconds to wait before an nntp connection times out.
213 If this variable is nil, which is the default, no timers are set.
214 NOTE: This variable is never seen to work in Emacs 20 and XEmacs 21.")
216 (defvoo nntp-prepare-post-hook nil
217 "*Hook run just before posting an article. It is supposed to be used for
218 inserting Cancel-Lock headers, signing with Gpg, etc.")
220 ;;; Internal variables.
222 (defvar nntp-record-commands nil
223 "*If non-nil, nntp will record all commands in the \"*nntp-log*\" buffer.")
225 (defvar nntp-have-messaged nil)
227 (defvar nntp-process-wait-for nil)
228 (defvar nntp-process-to-buffer nil)
229 (defvar nntp-process-callback nil)
230 (defvar nntp-process-decode nil)
231 (defvar nntp-process-start-point nil)
232 (defvar nntp-inside-change-function nil)
233 (defvoo nntp-last-command-time nil)
234 (defvoo nntp-last-command nil)
235 (defvoo nntp-authinfo-password nil)
236 (defvoo nntp-authinfo-user nil)
238 (defvar nntp-connection-list nil)
240 (defvoo nntp-server-type nil)
241 (defvoo nntp-connection-alist nil)
242 (defvoo nntp-status-string "")
243 (defconst nntp-version "nntp 5.0")
244 (defvoo nntp-inhibit-erase nil)
245 (defvoo nntp-inhibit-output nil)
247 (defvoo nntp-server-xover 'try)
248 (defvoo nntp-server-list-active-group 'try)
250 (defvar nntp-async-needs-kluge
251 (string-match "^GNU Emacs 20\\.3\\." (emacs-version))
252 "*When non-nil, nntp will poll asynchronous connections
253 once a second. By default, this is turned on only for Emacs
254 20.3, which has a bug that breaks nntp's normal method of
255 noticing asynchronous data.")
257 (defvar nntp-async-timer nil)
258 (defvar nntp-async-process-list nil)
261 (autoload 'mail-source-read-passwd "mail-source")
262 (autoload 'open-ssl-stream "ssl"))
266 ;;; Internal functions.
268 (defsubst nntp-send-string (process string)
269 "Send STRING to PROCESS."
270 ;; We need to store the time to provide timeouts, and
271 ;; to store the command so the we can replay the command
272 ;; if the server gives us an AUTHINFO challenge.
273 (setq nntp-last-command-time (current-time)
274 nntp-last-command string)
275 (when nntp-record-commands
276 (nntp-record-command string))
277 (process-send-string process (concat string nntp-end-of-line)))
279 (defun nntp-record-command (string)
280 "Record the command STRING."
282 (set-buffer (get-buffer-create "*nntp-log*"))
283 (goto-char (point-max))
284 (let ((time (current-time)))
285 (insert (format-time-string "%Y%m%dT%H%M%S" time)
286 "." (format "%03d" (/ (nth 2 time) 1000))
287 " " nntp-address " " string "\n"))))
289 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard)
290 "Wait for WAIT-FOR to arrive from PROCESS."
292 (set-buffer (process-buffer process))
293 (goto-char (point-min))
294 (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5)))
296 (memq (process-status process) '(open run)))
297 (when (looking-at "480")
298 (nntp-handle-authinfo process))
299 (nntp-accept-process-output process)
300 (goto-char (point-min)))
305 (nntp-snarf-error-message)
307 ((not (memq (process-status process) '(open run)))
308 (nnheader-report 'nntp "Server closed connection"))
310 (goto-char (point-max))
311 (let ((limit (point-min))
313 (while (not (re-search-backward wait-for limit t))
314 (nntp-accept-process-output process)
315 ;; We assume that whatever we wait for is less than 1000
317 (setq limit (max (- (point-max) 1000) (point-min)))
318 (goto-char (point-max)))
319 (setq response (match-string 0))
321 (set-buffer nntp-server-buffer)
322 (setq nntp-process-response response)))
323 (nntp-decode-text (not decode))
327 (goto-char (point-max))
328 (insert-buffer-substring (process-buffer process))
329 ;; Nix out "nntp reading...." message.
330 (when nntp-have-messaged
331 (setq nntp-have-messaged nil)
332 (nnheader-message 5 ""))
337 (defun nntp-kill-buffer (buffer)
338 (when (buffer-name buffer)
340 (nnheader-init-server-buffer)))
342 (defsubst nntp-find-connection (buffer)
343 "Find the connection delivering to BUFFER."
344 (let ((alist nntp-connection-alist)
345 (buffer (if (stringp buffer) (get-buffer buffer) buffer))
347 (while (and alist (setq entry (pop alist)))
348 (when (eq buffer (cadr entry))
349 (setq process (car entry)
352 (if (memq (process-status process) '(open run))
354 (nntp-kill-buffer (process-buffer process))
355 (setq nntp-connection-alist (delq entry nntp-connection-alist))
358 (defsubst nntp-find-connection-entry (buffer)
359 "Return the entry for the connection to BUFFER."
360 (assq (nntp-find-connection buffer) nntp-connection-alist))
362 (defun nntp-find-connection-buffer (buffer)
363 "Return the process connection buffer tied to BUFFER."
364 (let ((process (nntp-find-connection buffer)))
366 (process-buffer process))))
368 (defsubst nntp-retrieve-data (command address port buffer
369 &optional wait-for callback decode)
370 "Use COMMAND to retrieve data into BUFFER from PORT on ADDRESS."
371 (let ((process (or (nntp-find-connection buffer)
372 (nntp-open-connection buffer))))
374 (nnheader-report 'nntp "Couldn't open connection to %s" address)
375 (unless (or nntp-inhibit-erase nnheader-callback-function)
377 (set-buffer (process-buffer process))
382 (nntp-send-string process command))
384 ((eq callback 'ignore)
386 ((and callback wait-for)
387 (nntp-async-wait process wait-for buffer decode callback)
390 (nntp-wait-for process wait-for buffer decode))
393 (nnheader-report 'nntp "Couldn't open connection to %s: %s"
396 (message "Quit retrieving data from nntp")
400 (defsubst nntp-send-command (wait-for &rest strings)
401 "Send STRINGS to server and wait until WAIT-FOR returns."
402 (when (and (not nnheader-callback-function)
403 (not nntp-inhibit-output))
405 (set-buffer nntp-server-buffer)
408 (mapconcat 'identity strings " ")
409 nntp-address nntp-port-number nntp-server-buffer
410 wait-for nnheader-callback-function))
412 (defun nntp-send-command-nodelete (wait-for &rest strings)
413 "Send STRINGS to server and wait until WAIT-FOR returns."
415 (mapconcat 'identity strings " ")
416 nntp-address nntp-port-number nntp-server-buffer
417 wait-for nnheader-callback-function))
419 (defun nntp-send-command-and-decode (wait-for &rest strings)
420 "Send STRINGS to server and wait until WAIT-FOR returns."
421 (when (and (not nnheader-callback-function)
422 (not nntp-inhibit-output))
424 (set-buffer nntp-server-buffer)
427 (mapconcat 'identity strings " ")
428 nntp-address nntp-port-number nntp-server-buffer
429 wait-for nnheader-callback-function t))
431 (defun nntp-send-buffer (wait-for)
432 "Send the current buffer to server and wait until WAIT-FOR returns."
433 (when (and (not nnheader-callback-function)
434 (not nntp-inhibit-output))
436 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
439 (process-send-region (nntp-find-connection nntp-server-buffer)
440 (point-min) (point-max))
442 nil nntp-address nntp-port-number nntp-server-buffer
443 wait-for nnheader-callback-function))
447 ;;; Interface functions.
449 (nnoo-define-basics nntp)
451 (defsubst nntp-next-result-arrived-p ()
453 ;; A result that starts with a 2xx code is terminated by
454 ;; a line with only a "." on it.
455 ((eq (char-after) ?2)
456 (if (re-search-forward "\n\\.\r?\n" nil t)
459 ;; A result that starts with a 3xx or 4xx code is terminated
462 (if (search-forward "\n" nil t)
469 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
470 "Retrieve the headers of ARTICLES."
471 (nntp-possibly-change-group group server)
473 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
475 (if (and (not gnus-nov-is-evil)
476 (not nntp-nov-is-evil)
477 (nntp-retrieve-headers-with-xover articles fetch-old))
478 ;; We successfully retrieved the headers via XOVER.
480 ;; XOVER didn't work, so we do it the hard, slow and inefficient
482 (let ((number (length articles))
485 (last-point (point-min))
486 (buf (nntp-find-connection-buffer nntp-server-buffer))
487 (nntp-inhibit-erase t)
489 ;; Send HEAD commands.
490 (while (setq article (pop articles))
493 "HEAD" (if (numberp article)
494 (int-to-string article)
495 ;; `articles' is either a list of article numbers
496 ;; or a list of article IDs.
499 ;; Every 400 requests we have to read the stream in
500 ;; order to avoid deadlocks.
501 (when (or (null articles) ;All requests have been sent.
502 (zerop (% count nntp-maximum-request)))
503 (nntp-accept-response)
506 (goto-char last-point)
508 (while (nntp-next-result-arrived-p)
509 (setq last-point (point))
512 ;; If number of headers is greater than 100, give
513 ;; informative messages.
514 (and (numberp nntp-large-newsgroup)
515 (> number nntp-large-newsgroup)
516 (zerop (% received 20))
517 (nnheader-message 6 "NNTP: Receiving headers... %d%%"
518 (/ (* received 100) number)))
519 (nntp-accept-response))))
520 (and (numberp nntp-large-newsgroup)
521 (> number nntp-large-newsgroup)
522 (nnheader-message 6 "NNTP: Receiving headers...done"))
524 ;; Now all of replies are received. Fold continuation lines.
525 (nnheader-fold-continuation-lines)
526 ;; Remove all "\r"'s.
528 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
531 (deffoo nntp-retrieve-groups (groups &optional server)
532 "Retrieve group info on GROUPS."
533 (nntp-possibly-change-group nil server)
534 (when (nntp-find-connection-buffer nntp-server-buffer)
536 ;; Erase nntp-server-buffer before nntp-inhibit-erase.
537 (set-buffer nntp-server-buffer)
539 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
540 ;; The first time this is run, this variable is `try'. So we
542 (when (eq nntp-server-list-active-group 'try)
543 (nntp-try-list-active (car groups)))
547 (last-point (point-min))
548 (nntp-inhibit-erase t)
549 (buf (nntp-find-connection-buffer nntp-server-buffer))
550 (command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP")))
552 ;; Send the command to the server.
553 (nntp-send-command nil command (pop groups))
555 ;; Every 400 requests we have to read the stream in
556 ;; order to avoid deadlocks.
557 (when (or (null groups) ;All requests have been sent.
558 (zerop (% count nntp-maximum-request)))
559 (nntp-accept-response)
560 (while (and (gnus-buffer-live-p buf)
562 ;; Search `blue moon' in this file for the
563 ;; reason why set-buffer here.
565 (goto-char last-point)
567 (while (re-search-forward "^[0-9]" nil t)
569 (setq last-point (point))
571 (nntp-accept-response))))
573 ;; Wait for the reply from the final command.
574 (unless (gnus-buffer-live-p buf)
576 (nnheader-report 'nntp "Connection to %s is closed." server)))
578 (goto-char (point-max))
579 (re-search-backward "^[0-9]" nil t)
580 (when (looking-at "^[23]")
581 (while (and (gnus-buffer-live-p buf)
584 (goto-char (point-max))
585 (if (not nntp-server-list-active-group)
586 (not (re-search-backward "\r?\n" (- (point) 3) t))
587 (not (re-search-backward "^\\.\r?\n"
589 (nntp-accept-response)))
591 ;; Now all replies are received. We remove CRs.
592 (unless (gnus-buffer-live-p buf)
594 (nnheader-report 'nntp "Connection to %s is closed." server)))
596 (goto-char (point-min))
597 (while (search-forward "\r" nil t)
598 (replace-match "" t t))
600 (if (not nntp-server-list-active-group)
602 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
604 ;; We have read active entries, so we just delete the
606 (goto-char (point-min))
607 (while (re-search-forward "^[.2-5]" nil t)
608 (delete-region (match-beginning 0)
609 (progn (forward-line 1) (point))))
610 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
613 (deffoo nntp-retrieve-articles (articles &optional group server)
614 (nntp-possibly-change-group group server)
616 (let ((number (length articles))
619 (last-point (point-min))
620 (buf (nntp-find-connection-buffer nntp-server-buffer))
621 (nntp-inhibit-erase t)
622 (map (apply 'vector articles))
627 ;; Send ARTICLE command.
628 (while (setq article (pop articles))
631 "ARTICLE" (if (numberp article)
632 (int-to-string article)
633 ;; `articles' is either a list of article numbers
634 ;; or a list of article IDs.
637 ;; Every 400 requests we have to read the stream in
638 ;; order to avoid deadlocks.
639 (when (or (null articles) ;All requests have been sent.
640 (zerop (% count nntp-maximum-request)))
641 (nntp-accept-response)
644 (goto-char last-point)
646 (while (nntp-next-result-arrived-p)
647 (aset map received (cons (aref map received) (point)))
648 (setq last-point (point))
651 ;; If number of headers is greater than 100, give
652 ;; informative messages.
653 (and (numberp nntp-large-newsgroup)
654 (> number nntp-large-newsgroup)
655 (zerop (% received 20))
656 (nnheader-message 6 "NNTP: Receiving articles... %d%%"
657 (/ (* received 100) number)))
658 (nntp-accept-response))))
659 (and (numberp nntp-large-newsgroup)
660 (> number nntp-large-newsgroup)
661 (nnheader-message 6 "NNTP: Receiving articles...done"))
663 ;; Now we have all the responses. We go through the results,
664 ;; wash it and copy it over to the server buffer.
665 (set-buffer nntp-server-buffer)
667 (setq last-point (point-min))
671 (setq point (goto-char (point-max)))
673 (insert-buffer-substring buf last-point (cdr entry))
675 (setq last-point (cdr entry))
678 (cons (car entry) point))
681 (defun nntp-try-list-active (group)
682 (nntp-list-active-group group)
684 (set-buffer nntp-server-buffer)
685 (goto-char (point-min))
687 (looking-at "5[0-9]+"))
688 (setq nntp-server-list-active-group nil))
690 (setq nntp-server-list-active-group t)))))
692 (deffoo nntp-list-active-group (group &optional server)
693 "Return the active info on GROUP (which can be a regexp)."
694 (nntp-possibly-change-group nil server)
695 (nntp-send-command "^\\.*\r?\n" "LIST ACTIVE" group))
697 (deffoo nntp-request-group-articles (group &optional server)
698 "Return the list of existing articles in GROUP."
699 (nntp-possibly-change-group nil server)
700 (nntp-send-command "^\\.*\r?\n" "LISTGROUP" group))
702 (deffoo nntp-request-article (article &optional group server buffer command)
703 (nntp-possibly-change-group group server)
704 (when (nntp-send-command-and-decode
705 "\r?\n\\.\r?\n" "ARTICLE"
706 (if (numberp article) (int-to-string article) article))
708 (not (equal buffer nntp-server-buffer)))
710 (set-buffer nntp-server-buffer)
711 (copy-to-buffer buffer (point-min) (point-max))
712 (nntp-find-group-and-number))
713 (nntp-find-group-and-number))))
715 (deffoo nntp-request-head (article &optional group server)
716 (nntp-possibly-change-group group server)
717 (when (nntp-send-command
718 "\r?\n\\.\r?\n" "HEAD"
719 (if (numberp article) (int-to-string article) article))
721 (nntp-find-group-and-number)
722 (nntp-decode-text))))
724 (deffoo nntp-request-body (article &optional group server)
725 (nntp-possibly-change-group group server)
726 (nntp-send-command-and-decode
727 "\r?\n\\.\r?\n" "BODY"
728 (if (numberp article) (int-to-string article) article)))
730 (deffoo nntp-request-group (group &optional server dont-check)
731 (nntp-possibly-change-group nil server)
732 (when (nntp-send-command "^[245].*\n" "GROUP" group)
733 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
734 (setcar (cddr entry) group))))
736 (deffoo nntp-close-group (group &optional server)
739 (deffoo nntp-server-opened (&optional server)
740 "Say whether a connection to SERVER has been opened."
741 (and (nnoo-current-server-p 'nntp server)
743 (gnus-buffer-live-p nntp-server-buffer)
744 (nntp-find-connection nntp-server-buffer)))
746 (deffoo nntp-open-server (server &optional defs connectionless)
747 (nnheader-init-server-buffer)
748 (if (nntp-server-opened server)
750 (when (or (stringp (car defs))
751 (numberp (car defs)))
752 (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs))))
753 (unless (assq 'nntp-address defs)
754 (setq defs (append defs (list (list 'nntp-address server)))))
755 (nnoo-change-server 'nntp server defs)
756 (unless connectionless
757 (or (nntp-find-connection nntp-server-buffer)
758 (nntp-open-connection nntp-server-buffer)))))
760 (deffoo nntp-close-server (&optional server)
761 (nntp-possibly-change-group nil server t)
762 (let ((process (nntp-find-connection nntp-server-buffer)))
764 (when (memq (process-status process) '(open run))
766 (nntp-send-string process "QUIT")
767 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
768 ;; Ok, this is evil, but when using telnet and stuff
769 ;; as the connection method, it's important that the
770 ;; QUIT command actually is sent out before we kill
773 (nntp-kill-buffer (process-buffer process))
774 (setq process (car (pop nntp-connection-alist))))
775 (nnoo-close-server 'nntp)))
777 (deffoo nntp-request-close ()
779 (while (setq process (pop nntp-connection-list))
780 (when (memq (process-status process) '(open run))
782 (nntp-send-string process "QUIT")
783 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
784 ;; Ok, this is evil, but when using telnet and stuff
785 ;; as the connection method, it's important that the
786 ;; QUIT command actually is sent out before we kill
789 (nntp-kill-buffer (process-buffer process)))))
791 (deffoo nntp-request-list (&optional server)
792 "List active groups. If `nntp-list-options' is non-nil, the listing
793 output from the server will be restricted to the specified newsgroups.
794 If `nntp-options-subscribe' is non-nil, remove newsgroups that do not
795 match the regexp. If `nntp-options-not-subscribe' is non-nil, remove
796 newsgroups that match the regexp."
797 (nntp-possibly-change-group nil server)
798 (with-current-buffer nntp-server-buffer
800 (if (not nntp-list-options)
801 (nntp-send-command-and-decode "\r?\n\\.\r?\n" "LIST")
802 (let ((options (if (consp nntp-list-options)
804 (list nntp-list-options)))
808 (goto-char (point-max))
809 (narrow-to-region (point) (point))
811 (nntp-send-command-nodelete
813 (format "LIST ACTIVE %s" (car options))))
814 options (cdr options))
818 (when (and (stringp nntp-options-subscribe)
819 (not (string-equal "" nntp-options-subscribe)))
820 (goto-char (point-min))
821 (keep-lines nntp-options-subscribe))
822 (when (and (stringp nntp-options-not-subscribe)
823 (not (string-equal "" nntp-options-not-subscribe)))
824 (goto-char (point-min))
825 (flush-lines nntp-options-subscribe)))))
827 (deffoo nntp-request-list-newsgroups (&optional server)
828 (nntp-possibly-change-group nil server)
829 (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS"))
831 (deffoo nntp-request-newgroups (date &optional server)
832 (nntp-possibly-change-group nil server)
834 (set-buffer nntp-server-buffer)
837 "^\\.\r?\n" "NEWGROUPS"
838 (format-time-string "%y%m%d %H%M%S" (date-to-time date)))
839 (nntp-decode-text))))
841 (deffoo nntp-request-post (&optional server)
842 (nntp-possibly-change-group nil server)
843 (when (nntp-send-command "^[23].*\r?\n" "POST")
844 (let ((response (save-current-buffer
845 (set-buffer nntp-server-buffer)
846 nntp-process-response))
849 (string-match "^[23].*\\(<[^\t\n @<>]+@[^\t\n @<>]+>\\)"
851 (setq server-id (match-string 1 response))
852 (narrow-to-region (goto-char (point-min))
853 (if (search-forward "\n\n" nil t)
856 (unless (mail-fetch-field "Message-ID")
857 (goto-char (point-min))
858 (insert "Message-ID: " server-id "\n"))
860 (run-hooks 'nntp-prepare-post-hook)
861 (nntp-send-buffer "^[23].*\n"))))
863 (deffoo nntp-request-type (group article)
866 (deffoo nntp-asynchronous-p ()
871 (defun nntp-send-mode-reader ()
872 "Send the MODE READER command to the nntp server.
873 This function is supposed to be called from `nntp-server-opened-hook'.
874 It will make innd servers spawn an nnrpd process to allow actual article
876 (nntp-send-command "^.*\n" "MODE READER"))
878 (defun nntp-send-authinfo (&optional send-if-force)
879 "Send the AUTHINFO to the nntp server.
880 It will look in the \"~/.authinfo\" file for matching entries. If
881 nothing suitable is found there, it will prompt for a user name
884 If SEND-IF-FORCE, only send authinfo to the server if the
885 .authinfo file has the FORCE token."
886 (let* ((list (gnus-parse-netrc nntp-authinfo-file))
887 (alist (gnus-netrc-machine list nntp-address "nntp"))
888 (force (gnus-netrc-get alist "force"))
889 (user (or (gnus-netrc-get alist "login") nntp-authinfo-user))
890 (passwd (gnus-netrc-get alist "password")))
891 (when (or (not send-if-force)
894 (setq user (read-string (format "NNTP (%s) user name: " nntp-address))
895 nntp-authinfo-user user))
896 (unless (member user '(nil ""))
897 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
898 (when t ;???Should check if AUTHINFO succeeded
900 "^2.*\r?\n" "AUTHINFO PASS"
902 nntp-authinfo-password
903 (setq nntp-authinfo-password
904 (mail-source-read-passwd
905 (format "NNTP (%s@%s) password: "
906 user nntp-address))))))))))
908 (defun nntp-send-nosy-authinfo ()
909 "Send the AUTHINFO to the nntp server."
910 (let ((user (read-string (format "NNTP (%s) user name: " nntp-address))))
911 (unless (member user '(nil ""))
912 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
913 (when t ;???Should check if AUTHINFO succeeded
914 (nntp-send-command "^2.*\r?\n" "AUTHINFO PASS"
915 (mail-source-read-passwd "NNTP (%s@%s) password: "
916 user nntp-address))))))
918 (defun nntp-send-authinfo-from-file ()
919 "Send the AUTHINFO to the nntp server.
921 The authinfo login name is taken from the user's login name and the
922 password contained in '~/.nntp-authinfo'."
923 (when (file-exists-p "~/.nntp-authinfo")
925 (insert-file-contents "~/.nntp-authinfo")
926 (goto-char (point-min))
927 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" (user-login-name))
929 "^2.*\r?\n" "AUTHINFO PASS"
930 (buffer-substring (point) (progn (end-of-line) (point)))))))
932 ;;; Internal functions.
934 (defun nntp-handle-authinfo (process)
935 "Take care of an authinfo response from the server."
936 (let ((last nntp-last-command))
937 (funcall nntp-authinfo-function)
938 ;; We have to re-send the function that was interrupted by
939 ;; the authinfo request.
941 (set-buffer nntp-server-buffer)
943 (nntp-send-string process last)))
945 (defun nntp-make-process-buffer (buffer)
946 "Create a new, fresh buffer usable for nntp process connections."
950 (format " *server %s %s %s*"
951 nntp-address nntp-port-number
952 (gnus-buffer-exists-p buffer))))
953 (set (make-local-variable 'after-change-functions) nil)
954 (set (make-local-variable 'nntp-process-wait-for) nil)
955 (set (make-local-variable 'nntp-process-callback) nil)
956 (set (make-local-variable 'nntp-process-to-buffer) nil)
957 (set (make-local-variable 'nntp-process-start-point) nil)
958 (set (make-local-variable 'nntp-process-decode) nil)
961 (defun nntp-open-connection (buffer)
962 "Open a connection to PORT on ADDRESS delivering output to BUFFER."
963 (run-hooks 'nntp-prepare-server-hook)
964 (let* ((pbuffer (nntp-make-process-buffer buffer))
966 (and nntp-connection-timeout
967 (nnheader-run-at-time
968 nntp-connection-timeout nil
970 (nntp-kill-buffer ,pbuffer)))))
973 (funcall nntp-open-connection-function pbuffer)
976 (message "Quit opening connection")
977 (nntp-kill-buffer pbuffer)
981 (nnheader-cancel-timer timer))
983 (nntp-kill-buffer pbuffer))
984 (when (and (buffer-name pbuffer)
986 (process-kill-without-query process)
987 (nntp-wait-for process "^.*\n" buffer nil t)
988 (if (memq (process-status process) '(open run))
990 (caar (push (list process buffer nil) nntp-connection-alist))
991 (push process nntp-connection-list)
994 (nntp-read-server-type)
996 (set-buffer nntp-server-buffer)
997 (let ((nnheader-callback-function nil))
998 (run-hooks 'nntp-server-opened-hook)
999 (nntp-send-authinfo t))))
1000 (nntp-kill-buffer (process-buffer process))
1003 (defun nntp-open-network-stream (buffer)
1004 (open-network-stream-as-binary
1005 "nntpd" buffer nntp-address nntp-port-number))
1007 (defun nntp-open-ssl-stream (buffer)
1008 (let* ((ssl-program-arguments '("-connect" (concat host ":" service)))
1009 (proc (open-ssl-stream "nntpd" buffer nntp-address nntp-port-number)))
1012 (nntp-wait-for-string "^\r*20[01]")
1014 (delete-region (point-min) (point))
1017 (defun nntp-read-server-type ()
1018 "Find out what the name of the server we have connected to is."
1019 ;; Wait for the status string to arrive.
1020 (setq nntp-server-type (buffer-string))
1021 (let ((alist nntp-server-action-alist)
1022 (case-fold-search t)
1024 ;; Run server-specific commands.
1026 (setq entry (pop alist))
1027 (when (string-match (car entry) nntp-server-type)
1028 (if (and (listp (cadr entry))
1029 (not (eq 'lambda (caadr entry))))
1031 (funcall (cadr entry)))))))
1033 (defun nntp-async-wait (process wait-for buffer decode callback)
1035 (set-buffer (process-buffer process))
1036 (unless nntp-inside-change-function
1038 (setq nntp-process-wait-for wait-for
1039 nntp-process-to-buffer buffer
1040 nntp-process-decode decode
1041 nntp-process-callback callback
1042 nntp-process-start-point (point-max))
1043 (setq after-change-functions '(nntp-after-change-function))
1044 (if nntp-async-needs-kluge
1045 (nntp-async-kluge process))))
1047 (defun nntp-async-kluge (process)
1048 ;; emacs 20.3 bug: process output with encoding 'binary
1049 ;; doesn't trigger after-change-functions.
1050 (unless nntp-async-timer
1051 (setq nntp-async-timer
1052 (nnheader-run-at-time 1 1 'nntp-async-timer-handler)))
1053 (add-to-list 'nntp-async-process-list process))
1055 (defun nntp-async-timer-handler ()
1058 (if (memq (process-status proc) '(open run))
1059 (nntp-async-trigger proc)
1060 (nntp-async-stop proc)))
1061 nntp-async-process-list))
1063 (defun nntp-async-stop (proc)
1064 (setq nntp-async-process-list (delq proc nntp-async-process-list))
1065 (when (and nntp-async-timer (not nntp-async-process-list))
1066 (nnheader-cancel-timer nntp-async-timer)
1067 (setq nntp-async-timer nil)))
1069 (defun nntp-after-change-function (beg end len)
1071 ;; we only care about insertions at eob
1072 (when (and (eq 0 len) (eq (point-max) end))
1074 (let ((proc (get-buffer-process (current-buffer))))
1076 (nntp-async-trigger proc)))))
1077 ;; any throw from after-change-functions will leave it
1078 ;; set to nil. so we reset it here, if necessary.
1080 (setq after-change-functions '(nntp-after-change-function)))))
1082 (defun nntp-async-trigger (process)
1084 (set-buffer (process-buffer process))
1085 (when nntp-process-callback
1086 ;; do we have an error message?
1087 (goto-char nntp-process-start-point)
1088 (if (memq (following-char) '(?4 ?5))
1089 ;; wants credentials?
1090 (if (looking-at "480")
1091 (nntp-handle-authinfo process)
1092 ;; report error message.
1093 (nntp-snarf-error-message)
1094 (nntp-do-callback nil))
1096 ;; got what we expect?
1097 (goto-char (point-max))
1098 (when (re-search-backward
1099 nntp-process-wait-for nntp-process-start-point t)
1100 (let ((response (match-string 0)))
1101 (save-current-buffer
1102 (set-buffer nntp-server-buffer)
1103 (setq nntp-process-response response)))
1104 (nntp-async-stop process)
1106 (when (gnus-buffer-exists-p nntp-process-to-buffer)
1107 (let ((buf (current-buffer))
1108 (start nntp-process-start-point)
1109 (decode nntp-process-decode))
1111 (set-buffer nntp-process-to-buffer)
1112 (goto-char (point-max))
1114 (narrow-to-region (point) (point))
1115 (insert-buffer-substring buf start)
1117 (nntp-decode-text))))))
1119 (goto-char (point-max))
1121 (buffer-name (get-buffer nntp-process-to-buffer))))))))
1123 (defun nntp-do-callback (arg)
1124 (let ((callback nntp-process-callback)
1125 (nntp-inside-change-function t))
1126 (setq nntp-process-callback nil)
1127 (funcall callback arg)))
1129 (defun nntp-snarf-error-message ()
1130 "Save the error message in the current buffer."
1131 (let ((message (buffer-string)))
1132 (while (string-match "[\r\n]+" message)
1133 (setq message (replace-match " " t t message)))
1134 (nnheader-report 'nntp message)
1137 (defun nntp-accept-process-output (process &optional timeout)
1138 "Wait for output from PROCESS and message some dots."
1140 (set-buffer (or (nntp-find-connection-buffer nntp-server-buffer)
1141 nntp-server-buffer))
1142 (let ((len (/ (point-max) 1024))
1145 (setq nntp-have-messaged t)
1146 (nnheader-message 7 "nntp read: %dk" len)))
1147 (accept-process-output process (or timeout 1))))
1149 (defun nntp-accept-response ()
1150 "Wait for output from the process that outputs to BUFFER."
1151 (nntp-accept-process-output (nntp-find-connection nntp-server-buffer)))
1153 (defun nntp-possibly-change-group (group server &optional connectionless)
1154 (let ((nnheader-callback-function nil))
1156 (or (nntp-server-opened server)
1157 (nntp-open-server server nil connectionless)))
1159 (unless connectionless
1160 (or (nntp-find-connection nntp-server-buffer)
1161 (nntp-open-connection nntp-server-buffer))))
1164 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
1165 (when (not (equal group (caddr entry)))
1167 (set-buffer (process-buffer (car entry)))
1169 (nntp-send-command "^[245].*\n" "GROUP" group)
1170 (setcar (cddr entry) group)
1173 (defun nntp-decode-text (&optional cr-only)
1174 "Decode the text in the current buffer."
1175 (goto-char (point-min))
1176 (while (search-forward "\r" nil t)
1179 ;; Remove trailing ".\n" end-of-transfer marker.
1180 (goto-char (point-max))
1182 (when (looking-at ".\n")
1184 ;; Delete status line.
1185 (goto-char (point-min))
1186 (while (looking-at "[1-5][0-9][0-9] .*\n")
1187 ;; For some unknown reason, there is more than one status line.
1188 (delete-region (point) (progn (forward-line 1) (point))))
1189 ;; Remove "." -> ".." encoding.
1190 (while (search-forward "\n.." nil t)
1193 (defun nntp-encode-text ()
1194 "Encode the text in the current buffer."
1196 ;; Replace "." at beginning of line with "..".
1197 (goto-char (point-min))
1198 (while (re-search-forward "^\\." nil t)
1200 (goto-char (point-max))
1201 ;; Insert newline at the end of the buffer.
1204 ;; Insert `.' at end of buffer (end of text mark).
1205 (goto-char (point-max))
1207 (goto-char (point-min))
1211 (insert nntp-end-of-line))))
1213 (defun nntp-retrieve-headers-with-xover (articles &optional fetch-old)
1214 (set-buffer nntp-server-buffer)
1218 ;; This server does not talk NOV.
1219 ((not nntp-server-xover)
1222 ;; We don't care about gaps.
1223 ((or (not nntp-nov-gap)
1225 (nntp-send-xover-command
1227 (if (numberp fetch-old)
1228 (max 1 (- (car articles) fetch-old))
1231 (car (last articles)) 'wait)
1233 (goto-char (point-min))
1234 (when (looking-at "[1-5][0-9][0-9] .*\n")
1235 (delete-region (point) (progn (forward-line 1) (point))))
1236 (while (search-forward "\r" nil t)
1237 (replace-match "" t t))
1238 (goto-char (point-max))
1240 (when (looking-at "\\.")
1241 (delete-region (point) (progn (forward-line 1) (point)))))
1243 ;; We do it the hard way. For each gap, an XOVER command is sent
1244 ;; to the server. We do not wait for a reply from the server, we
1245 ;; just send them off as fast as we can. That means that we have
1246 ;; to count the number of responses we get back to find out when we
1247 ;; have gotten all we asked for.
1248 ((numberp nntp-nov-gap)
1253 (buf nntp-server-buffer)
1254 (process-buffer (nntp-find-connection-buffer nntp-server-buffer))
1256 ;; We have to check `nntp-server-xover'. If it gets set to nil,
1257 ;; that means that the server does not understand XOVER, but we
1258 ;; won't know that until we try.
1259 (while (and nntp-server-xover articles)
1260 (setq first (car articles))
1261 ;; Search forward until we find a gap, or until we run out of
1263 (while (and (cdr articles)
1264 (< (- (nth 1 articles) (car articles)) nntp-nov-gap))
1265 (setq articles (cdr articles)))
1267 (setq in-process-buffer-p (stringp nntp-server-xover))
1268 (nntp-send-xover-command first (car articles))
1269 (setq articles (cdr articles))
1271 (when (and nntp-server-xover in-process-buffer-p)
1272 ;; Don't count tried request.
1273 (setq count (1+ count))
1275 ;; Every 400 requests we have to read the stream in
1276 ;; order to avoid deadlocks.
1277 (when (or (null articles) ;All requests have been sent.
1278 (zerop (% count nntp-maximum-request)))
1280 (nntp-accept-response)
1281 ;; On some Emacs versions the preceding function has a
1282 ;; tendency to change the buffer. Perhaps. It's quite
1283 ;; difficult to reproduce, because it only seems to happen
1284 ;; once in a blue moon.
1285 (set-buffer process-buffer)
1287 (goto-char (or last-point (point-min)))
1289 (while (re-search-forward "^[0-9][0-9][0-9] .*\n" nil t)
1291 (setq last-point (point))
1293 (nntp-accept-response)
1294 (set-buffer process-buffer))
1297 (when nntp-server-xover
1298 (when in-process-buffer-p
1299 (set-buffer process-buffer)
1300 ;; Wait for the reply from the final command.
1301 (goto-char (point-max))
1302 (while (not (re-search-backward "^[0-9][0-9][0-9] " nil t))
1303 (nntp-accept-response)
1304 (set-buffer process-buffer)
1305 (goto-char (point-max)))
1306 (when (looking-at "^[23]")
1308 (goto-char (point-max))
1310 (not (looking-at "^\\.\r?\n")))
1311 (nntp-accept-response)
1312 (set-buffer process-buffer)))
1314 (goto-char (point-max))
1315 (insert-buffer-substring process-buffer)
1316 (set-buffer process-buffer)
1320 ;; We remove any "." lines and status lines.
1321 (goto-char (point-min))
1322 (while (search-forward "\r" nil t)
1324 (goto-char (point-min))
1325 (delete-matching-lines "^\\.$\\|^[1-5][0-9][0-9] ")
1330 (defun nntp-send-xover-command (beg end &optional wait-for-reply)
1331 "Send the XOVER command to the server."
1332 (let ((range (format "%d-%d" beg end))
1333 (nntp-inhibit-erase t))
1334 (if (stringp nntp-server-xover)
1335 ;; If `nntp-server-xover' is a string, then we just send this
1338 (nntp-send-command-nodelete
1339 "\r?\n\\.\r?\n" nntp-server-xover range)
1340 ;; We do not wait for the reply.
1341 (nntp-send-command-nodelete nil nntp-server-xover range))
1342 (let ((commands nntp-xover-commands))
1343 ;; `nntp-xover-commands' is a list of possible XOVER commands.
1344 ;; We try them all until we get at positive response.
1345 (while (and commands (eq nntp-server-xover 'try))
1346 (nntp-send-command-nodelete "\r?\n\\.\r?\n" (car commands) range)
1348 (set-buffer nntp-server-buffer)
1349 (goto-char (point-min))
1350 (and (looking-at "[23]") ; No error message.
1351 ;; We also have to look at the lines. Some buggy
1352 ;; servers give back simple lines with just the
1353 ;; article number. How... helpful.
1356 (looking-at "[0-9]+\t...")) ; More text after number.
1357 (setq nntp-server-xover (car commands))))
1358 (setq commands (cdr commands)))
1359 ;; If none of the commands worked, we disable XOVER.
1360 (when (eq nntp-server-xover 'try)
1362 (set-buffer nntp-server-buffer)
1364 (setq nntp-server-xover nil)))
1365 nntp-server-xover))))
1367 ;;; Alternative connection methods.
1369 (defun nntp-wait-for-string (regexp)
1370 "Wait until string arrives in the buffer."
1371 (let ((buf (current-buffer)))
1372 (goto-char (point-min))
1373 (while (not (re-search-forward regexp nil t))
1374 (accept-process-output (nntp-find-connection nntp-server-buffer))
1376 (goto-char (point-min)))))
1378 (defun nntp-open-telnet (buffer)
1382 (let ((proc (as-binary-process
1385 "nntpd" buffer nntp-telnet-command nntp-telnet-switches)))
1386 (case-fold-search t))
1387 (when (memq (process-status proc) '(open run))
1388 (nntp-wait-for-string "^r?telnet")
1389 (process-send-string proc "set escape \^X\n")
1391 ((and nntp-open-telnet-envuser nntp-telnet-user-name)
1392 (process-send-string proc (concat "open " "-l" nntp-telnet-user-name
1393 nntp-address "\n")))
1395 (process-send-string proc (concat "open " nntp-address "\n"))))
1397 ((not nntp-open-telnet-envuser)
1398 (nntp-wait-for-string "^\r*.?login:")
1399 (process-send-string
1401 (or nntp-telnet-user-name
1402 (setq nntp-telnet-user-name (read-string "login: ")))
1404 (nntp-wait-for-string "^\r*.?password:")
1405 (process-send-string
1407 (or nntp-telnet-passwd
1408 (setq nntp-telnet-passwd
1409 (mail-source-read-passwd "Password: ")))
1411 (nntp-wait-for-string nntp-telnet-shell-prompt)
1412 (process-send-string
1413 proc (concat (mapconcat 'identity nntp-telnet-parameters " ") "\n"))
1414 (nntp-wait-for-string "^\r*20[01]")
1416 (delete-region (point-min) (point))
1417 (process-send-string proc "\^]")
1418 (nntp-wait-for-string "^r?telnet")
1419 (process-send-string proc "mode character\n")
1420 (accept-process-output proc 1)
1422 (goto-char (point-min))
1424 (delete-region (point) (point-max)))
1427 (defun nntp-open-rlogin (buffer)
1428 "Open a connection to SERVER using rsh."
1429 (let ((proc (if nntp-rlogin-user-name
1431 (apply 'start-process
1432 "nntpd" buffer nntp-rlogin-program
1433 nntp-address "-l" nntp-rlogin-user-name
1434 nntp-rlogin-parameters))
1436 (apply 'start-process
1437 "nntpd" buffer nntp-rlogin-program nntp-address
1438 nntp-rlogin-parameters)))))
1441 (nntp-wait-for-string "^\r*20[01]")
1443 (delete-region (point-min) (point))
1446 (defun nntp-find-group-and-number ()
1449 (set-buffer nntp-server-buffer)
1450 (narrow-to-region (goto-char (point-min))
1451 (or (search-forward "\n\n" nil t) (point-max)))
1452 (goto-char (point-min))
1453 ;; We first find the number by looking at the status line.
1454 (let ((number (and (looking-at "2[0-9][0-9] +\\([0-9]+\\) ")
1456 (buffer-substring (match-beginning 1)
1458 group newsgroups xref)
1459 (and number (zerop number) (setq number nil))
1460 ;; Then we find the group name.
1463 ;; If there is only one group in the Newsgroups header,
1464 ;; then it seems quite likely that this article comes
1465 ;; from that group, I'd say.
1466 ((and (setq newsgroups (mail-fetch-field "newsgroups"))
1467 (not (string-match "," newsgroups)))
1469 ;; If there is more than one group in the Newsgroups
1470 ;; header, then the Xref header should be filled out.
1471 ;; We hazard a guess that the group that has this
1472 ;; article number in the Xref header is the one we are
1473 ;; looking for. This might very well be wrong if this
1474 ;; article happens to have the same number in several
1475 ;; groups, but that's life.
1476 ((and (setq xref (mail-fetch-field "xref"))
1478 (string-match (format "\\([^ :]+\\):%d" number) xref))
1479 (substring xref (match-beginning 1) (match-end 1)))
1481 (when (string-match "\r" group)
1482 (setq group (substring group 0 (match-beginning 0))))
1483 (cons group number)))))
1487 ;;; nntp.el ends here