*** empty log message ***
[gnus] / lisp / nntp.el
1 ;;; nntp.el --- nntp access for Gnus
2 ;;; Copyright (C) 1987-90,92-97 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (require 'nnheader)
28 (require 'nnoo)
29 (require 'gnus-util)
30
31 (nnoo-declare nntp)
32
33 (eval-and-compile
34   (unless (fboundp 'open-network-stream)
35     (require 'tcp)))
36
37 (eval-when-compile (require 'cl))
38
39 (defvoo nntp-address nil
40   "Address of the physical nntp server.")
41
42 (defvoo nntp-port-number "nntp"
43   "Port number on the physical nntp server.")
44
45 (defvoo nntp-server-opened-hook '(nntp-send-mode-reader)
46   "*Hook used for sending commands to the server at startup.
47 The default value is `nntp-send-mode-reader', which makes an innd
48 server spawn an nnrpd server.")
49
50 (defvoo nntp-authinfo-function 'nntp-send-authinfo
51   "Function used to send AUTHINFO to the server.
52 It is called with no parameters.")
53
54 (defvoo nntp-server-action-alist
55   '(("nntpd 1\\.5\\.11t"
56      (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader))
57     ("NNRP server Netscape"
58      (setq nntp-server-list-active-group nil)))
59   "Alist of regexps to match on server types and actions to be taken.
60 For instance, if you want Gnus to beep every time you connect
61 to innd, you could say something like:
62
63 \(setq nntp-server-action-alist
64        '((\"innd\" (ding))))
65
66 You probably don't want to do that, though.")
67
68 (defvoo nntp-open-connection-function 'nntp-open-network-stream
69   "*Function used for connecting to a remote system.
70 It will be called with the buffer to output in.
71
72 Two pre-made functions are `nntp-open-network-stream', which is the
73 default, and simply connects to some port or other on the remote
74 system (see nntp-port-number).  The other are `nntp-open-rlogin',
75 which does an rlogin on the remote system, and then does a telnet to
76 the NNTP server available there (see nntp-rlogin-parameters) and
77 `nntp-open-telnet' which telnets to a remote system, logs in and does
78 the same.")
79
80 (defvoo nntp-rlogin-program "rsh"
81   "*Program used to log in on remote machines.
82 The default is \"rsh\", but \"ssh\" is a popular alternative.")
83
84 (defvoo nntp-rlogin-parameters '("telnet" "-8" "${NNTPSERVER:=news}" "nntp")
85   "*Parameters to `nntp-open-rlogin'.
86 That function may be used as `nntp-open-connection-function'.  In that
87 case, this list will be used as the parameter list given to rsh.")
88
89 (defvoo nntp-rlogin-user-name nil
90   "*User name on remote system when using the rlogin connect method.")
91
92 (defvoo nntp-telnet-parameters '("exec" "telnet" "-8" "${NNTPSERVER:=news}" "nntp")
93   "*Parameters to `nntp-open-telnet'.
94 That function may be used as `nntp-open-connection-function'.  In that
95 case, this list will be executed as a command after logging in
96 via telnet.")
97
98 (defvoo nntp-telnet-user-name nil
99   "User name to log in via telnet with.")
100
101 (defvoo nntp-telnet-passwd nil
102   "Password to use to log in via telnet with.")
103
104 (defvoo nntp-open-telnet-envuser nil
105   "*If non-nil, telnet session (client and server both) will support the ENVIRON option and not prompt for login name.")
106
107 (defvoo nntp-telnet-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
108   "*Regular expression to match the shell prompt on the remote machine.")
109
110 (defvoo nntp-telnet-command "telnet"
111   "Command used to start telnet.")
112
113 (defvoo nntp-telnet-switches '("-8")
114   "Switches given to the telnet command.")
115
116 (defvoo nntp-end-of-line "\r\n"
117   "String to use on the end of lines when talking to the NNTP server.
118 This is \"\\r\\n\" by default, but should be \"\\n\" when
119 using rlogin or telnet to communicate with the server.")
120
121 (defvoo nntp-large-newsgroup 50
122   "*The number of the articles which indicates a large newsgroup.
123 If the number of the articles is greater than the value, verbose
124 messages will be shown to indicate the current status.")
125
126 (defvoo nntp-maximum-request 400
127   "*The maximum number of the requests sent to the NNTP server at one time.
128 If Emacs hangs up while retrieving headers, set the variable to a
129 lower value.")
130
131 (defvoo nntp-nov-is-evil nil
132   "*If non-nil, nntp will never attempt to use XOVER when talking to the server.")
133
134 (defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
135   "*List of strings that are used as commands to fetch NOV lines from a server.
136 The strings are tried in turn until a positive response is gotten.  If
137 none of the commands are successful, nntp will just grab headers one
138 by one.")
139
140 (defvoo nntp-nov-gap 5
141   "*Maximum allowed gap between two articles.
142 If the gap between two consecutive articles is bigger than this
143 variable, split the XOVER request into two requests.")
144
145 (defvoo nntp-prepare-server-hook nil
146   "*Hook run before a server is opened.
147 If can be used to set up a server remotely, for instance.  Say you
148 have an account at the machine \"other.machine\".  This machine has
149 access to an NNTP server that you can't access locally.  You could
150 then use this hook to rsh to the remote machine and start a proxy NNTP
151 server there that you can connect to.  See also
152 `nntp-open-connection-function'")
153
154 (defvoo nntp-warn-about-losing-connection t
155   "*If non-nil, beep when a server closes connection.")
156
157 (defvoo nntp-coding-system-for-read 'binary
158   "*Coding system to read from NNTP.")
159
160 (defvoo nntp-coding-system-for-write 'binary
161   "*Coding system to write to NNTP.")
162
163 (defcustom nntp-authinfo-file "~/.authinfo"
164   ".netrc-like file that holds nntp authinfo passwords."
165   :type
166   '(choice file
167            (repeat :tag "Entries"
168                    :menu-tag "Inline"
169                    (list :format "%v"
170                          :value ("" ("login" . "") ("password" . ""))
171                          (string :tag "Host")
172                          (checklist :inline t
173                                     (cons :format "%v"
174                                           (const :format "" "login")
175                                           (string :format "Login: %v"))
176                                     (cons :format "%v"
177                                           (const :format "" "password")
178                                           (string :format "Password: %v")))))))
179
180 \f
181
182 ;;; Internal variables.
183
184 (defvar nntp-record-commands nil
185   "*If non-nil, nntp will record all commands in the \"*nntp-log*\" buffer.")
186
187 (defvar nntp-have-messaged nil)
188
189 (defvar nntp-process-wait-for nil)
190 (defvar nntp-process-to-buffer nil)
191 (defvar nntp-process-callback nil)
192 (defvar nntp-process-decode nil)
193 (defvar nntp-process-start-point nil)
194 (defvar nntp-inside-change-function nil)
195 (defvoo nntp-last-command-time nil)
196 (defvoo nntp-last-command nil)
197 (defvoo nntp-authinfo-password nil)
198 (defvoo nntp-authinfo-user nil)
199
200 (defvar nntp-connection-list nil)
201
202 (defvoo nntp-server-type nil)
203 (defvoo nntp-connection-alist nil)
204 (defvoo nntp-status-string "")
205 (defconst nntp-version "nntp 5.0")
206 (defvoo nntp-inhibit-erase nil)
207 (defvoo nntp-inhibit-output nil)
208
209 (defvoo nntp-server-xover 'try)
210 (defvoo nntp-server-list-active-group 'try)
211
212 (eval-and-compile
213   (autoload 'nnmail-read-passwd "nnmail")
214   (autoload 'open-ssl-stream "ssl"))
215
216 \f
217
218 ;;; Internal functions.
219
220 (defsubst nntp-send-string (process string)
221   "Send STRING to PROCESS."
222   ;; We need to store the time to provide timeouts, and
223   ;; to store the command so the we can replay the command
224   ;; if the server gives us an AUTHINFO challenge.
225   (setq nntp-last-command-time (current-time)
226         nntp-last-command string)
227   (when nntp-record-commands
228     (nntp-record-command string))
229   (process-send-string process (concat string nntp-end-of-line)))
230
231 (defun nntp-record-command (string)
232   "Record the command STRING."
233   (save-excursion
234     (set-buffer (get-buffer-create "*nntp-log*"))
235     (goto-char (point-max))
236     (let ((time (current-time)))
237       (insert (format-time-string "%Y%m%dT%H%M%S" time)
238               "." (format "%03d" (/ (nth 2 time) 1000))
239               " " nntp-address " " string "\n"))))
240
241 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard)
242   "Wait for WAIT-FOR to arrive from PROCESS."
243   (save-excursion
244     (set-buffer (process-buffer process))
245     (goto-char (point-min))
246     (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5)))
247                     (looking-at "480"))
248                 (memq (process-status process) '(open run)))
249       (when (looking-at "480")
250         (nntp-handle-authinfo process))
251       (nntp-accept-process-output process)
252       (goto-char (point-min)))
253     (prog1
254         (cond
255          ((looking-at "[45]")
256           (progn
257             (nntp-snarf-error-message)
258             nil))
259          ((not (memq (process-status process) '(open run)))
260           (nnheader-report 'nntp "Server closed connection"))
261          (t
262           (goto-char (point-max))
263           (let ((limit (point-min)))
264             (while (not (re-search-backward wait-for limit t))
265               (nntp-accept-process-output process)
266               ;; We assume that whatever we wait for is less than 1000
267               ;; characters long.
268               (setq limit (max (- (point-max) 1000) (point-min)))
269               (goto-char (point-max))))
270           (nntp-decode-text (not decode))
271           (unless discard
272             (save-excursion
273               (set-buffer buffer)
274               (goto-char (point-max))
275               (insert-buffer-substring (process-buffer process))
276               ;; Nix out "nntp reading...." message.
277               (when nntp-have-messaged
278                 (setq nntp-have-messaged nil)
279                 (nnheader-message 5 ""))
280               t))))
281       (unless discard
282         (erase-buffer)))))
283
284 (defsubst nntp-find-connection (buffer)
285   "Find the connection delivering to BUFFER."
286   (let ((alist nntp-connection-alist)
287         (buffer (if (stringp buffer) (get-buffer buffer) buffer))
288         process entry)
289     (while (setq entry (pop alist))
290       (when (eq buffer (cadr entry))
291         (setq process (car entry)
292               alist nil)))
293     (when process
294       (if (memq (process-status process) '(open run))
295           process
296         (when (buffer-name (process-buffer process))
297           (kill-buffer (process-buffer process)))
298         (setq nntp-connection-alist (delq entry nntp-connection-alist))
299         nil))))
300
301 (defsubst nntp-find-connection-entry (buffer)
302   "Return the entry for the connection to BUFFER."
303   (assq (nntp-find-connection buffer) nntp-connection-alist))
304
305 (defun nntp-find-connection-buffer (buffer)
306   "Return the process connection buffer tied to BUFFER."
307   (let ((process (nntp-find-connection buffer)))
308     (when process
309       (process-buffer process))))
310
311 (defsubst nntp-retrieve-data (command address port buffer
312                                       &optional wait-for callback decode)
313   "Use COMMAND to retrieve data into BUFFER from PORT on ADDRESS."
314   (let ((process (or (nntp-find-connection buffer)
315                      (nntp-open-connection buffer))))
316     (if (not process)
317         (nnheader-report 'nntp "Couldn't open connection to %s" address)
318       (unless (or nntp-inhibit-erase nnheader-callback-function)
319         (save-excursion
320           (set-buffer (process-buffer process))
321           (erase-buffer)))
322       (when command
323         (nntp-send-string process command))
324       (cond
325        ((eq callback 'ignore)
326         t)
327        ((and callback wait-for)
328         (save-excursion
329           (set-buffer (process-buffer process))
330           (unless nntp-inside-change-function
331             (erase-buffer))
332           (setq nntp-process-decode decode
333                 nntp-process-to-buffer buffer
334                 nntp-process-wait-for wait-for
335                 nntp-process-callback callback
336                 nntp-process-start-point (point-max)
337                 after-change-functions
338                 (list 'nntp-after-change-function-callback)))
339         t)
340        (wait-for
341         (nntp-wait-for process wait-for buffer decode))
342        (t t)))))
343
344 (defsubst nntp-send-command (wait-for &rest strings)
345   "Send STRINGS to server and wait until WAIT-FOR returns."
346   (when (and (not nnheader-callback-function)
347              (not nntp-inhibit-output))
348     (save-excursion
349       (set-buffer nntp-server-buffer)
350       (erase-buffer)))
351   (nntp-retrieve-data
352    (mapconcat 'identity strings " ")
353    nntp-address nntp-port-number nntp-server-buffer
354    wait-for nnheader-callback-function))
355
356 (defun nntp-send-command-nodelete (wait-for &rest strings)
357   "Send STRINGS to server and wait until WAIT-FOR returns."
358   (nntp-retrieve-data
359    (mapconcat 'identity strings " ")
360    nntp-address nntp-port-number nntp-server-buffer
361    wait-for nnheader-callback-function))
362
363 (defun nntp-send-command-and-decode (wait-for &rest strings)
364   "Send STRINGS to server and wait until WAIT-FOR returns."
365   (when (and (not nnheader-callback-function)
366              (not nntp-inhibit-output))
367     (save-excursion
368       (set-buffer nntp-server-buffer)
369       (erase-buffer)))
370   (nntp-retrieve-data
371    (mapconcat 'identity strings " ")
372    nntp-address nntp-port-number nntp-server-buffer
373    wait-for nnheader-callback-function t))
374
375 (defun nntp-send-buffer (wait-for)
376   "Send the current buffer to server and wait until WAIT-FOR returns."
377   (when (and (not nnheader-callback-function)
378              (not nntp-inhibit-output))
379     (save-excursion
380       (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
381       (erase-buffer)))
382   (nntp-encode-text)
383   (process-send-region (nntp-find-connection nntp-server-buffer)
384                        (point-min) (point-max))
385   (nntp-retrieve-data
386    nil nntp-address nntp-port-number nntp-server-buffer
387    wait-for nnheader-callback-function))
388
389 \f
390
391 ;;; Interface functions.
392
393 (nnoo-define-basics nntp)
394
395 (defsubst nntp-next-result-arrived-p ()
396   (cond
397    ;; A result that starts with a 2xx code is terminated by
398    ;; a line with only a "." on it.
399    ((eq (following-char) ?2)
400     (if (re-search-forward "\n\\.\r?\n" nil t)
401         t
402       nil))
403    ;; A result that startx with a 3xx or 4xx code is terminated
404    ;; by a newline.
405    ((looking-at "[34]")
406     (if (search-forward "\n" nil t)
407         t
408       nil))
409    ;; No result here.
410    (t
411     nil)))
412
413 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
414   "Retrieve the headers of ARTICLES."
415   (nntp-possibly-change-group group server)
416   (save-excursion
417     (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
418     (erase-buffer)
419     (if (and (not gnus-nov-is-evil)
420              (not nntp-nov-is-evil)
421              (nntp-retrieve-headers-with-xover articles fetch-old))
422         ;; We successfully retrieved the headers via XOVER.
423         'nov
424       ;; XOVER didn't work, so we do it the hard, slow and inefficient
425       ;; way.
426       (let ((number (length articles))
427             (count 0)
428             (received 0)
429             (last-point (point-min))
430             (buf (nntp-find-connection-buffer nntp-server-buffer))
431             (nntp-inhibit-erase t)
432             article)
433         ;; Send HEAD commands.
434       (while (setq article (pop articles))
435         (nntp-send-command
436          nil
437          "HEAD" (if (numberp article)
438                     (int-to-string article)
439                   ;; `articles' is either a list of article numbers
440                   ;; or a list of article IDs.
441                   article))
442         (incf count)
443         ;; Every 400 requests we have to read the stream in
444         ;; order to avoid deadlocks.
445         (when (or (null articles)       ;All requests have been sent.
446                   (zerop (% count nntp-maximum-request)))
447           (nntp-accept-response)
448           (while (progn
449                    (set-buffer buf)
450                    (goto-char last-point)
451                    ;; Count replies.
452                    (while (nntp-next-result-arrived-p)
453                      (setq last-point (point))
454                      (incf received))
455                    (< received count))
456             ;; If number of headers is greater than 100, give
457             ;;  informative messages.
458             (and (numberp nntp-large-newsgroup)
459                  (> number nntp-large-newsgroup)
460                  (zerop (% received 20))
461                  (nnheader-message 6 "NNTP: Receiving headers... %d%%"
462                                    (/ (* received 100) number)))
463             (nntp-accept-response))))
464         (and (numberp nntp-large-newsgroup)
465              (> number nntp-large-newsgroup)
466              (nnheader-message 6 "NNTP: Receiving headers...done"))
467
468         ;; Now all of replies are received.  Fold continuation lines.
469         (nnheader-fold-continuation-lines)
470         ;; Remove all "\r"'s.
471         (nnheader-strip-cr)
472         (copy-to-buffer nntp-server-buffer (point-min) (point-max))
473         'headers))))
474
475 (deffoo nntp-retrieve-groups (groups &optional server)
476   "Retrieve group info on GROUPS."
477   (nntp-possibly-change-group nil server)
478   (save-excursion
479     (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
480     ;; The first time this is run, this variable is `try'.  So we
481     ;; try.
482     (when (eq nntp-server-list-active-group 'try)
483       (nntp-try-list-active (car groups)))
484     (erase-buffer)
485     (let ((count 0)
486           (received 0)
487           (last-point (point-min))
488           (nntp-inhibit-erase t)
489           (command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP")))
490       (while groups
491         ;; Send the command to the server.
492         (nntp-send-command nil command (pop groups))
493         (incf count)
494         ;; Every 400 requests we have to read the stream in
495         ;; order to avoid deadlocks.
496         (when (or (null groups)         ;All requests have been sent.
497                   (zerop (% count nntp-maximum-request)))
498           (nntp-accept-response)
499           (while (progn
500                    (goto-char last-point)
501                    ;; Count replies.
502                    (while (re-search-forward "^[0-9]" nil t)
503                      (incf received))
504                    (setq last-point (point))
505                    (< received count))
506             (nntp-accept-response))))
507
508       ;; Wait for the reply from the final command.
509       (goto-char (point-max))
510       (re-search-backward "^[0-9]" nil t)
511       (when (looking-at "^[23]")
512         (while (progn
513                  (goto-char (point-max))
514                  (if (not nntp-server-list-active-group)
515                      (not (re-search-backward "\r?\n" (- (point) 3) t))
516                    (not (re-search-backward "^\\.\r?\n" (- (point) 4) t))))
517           (nntp-accept-response)))
518
519       ;; Now all replies are received.  We remove CRs.
520       (goto-char (point-min))
521       (while (search-forward "\r" nil t)
522         (replace-match "" t t))
523
524       (if (not nntp-server-list-active-group)
525           (progn
526             (copy-to-buffer nntp-server-buffer (point-min) (point-max))
527             'group)
528         ;; We have read active entries, so we just delete the
529         ;; superfluous gunk.
530         (goto-char (point-min))
531         (while (re-search-forward "^[.2-5]" nil t)
532           (delete-region (match-beginning 0)
533                          (progn (forward-line 1) (point))))
534         (copy-to-buffer nntp-server-buffer (point-min) (point-max))
535         'active))))
536
537 (deffoo nntp-retrieve-articles (articles &optional group server)
538   (nntp-possibly-change-group group server)
539   (save-excursion
540     (let ((number (length articles))
541           (count 0)
542           (received 0)
543           (last-point (point-min))
544           (buf (nntp-find-connection-buffer nntp-server-buffer))
545           (nntp-inhibit-erase t)
546           (map (apply 'vector articles))
547           (point 1)
548           article alist)
549       (set-buffer buf)
550       (erase-buffer)
551       ;; Send ARTICLE command.
552       (while (setq article (pop articles))
553         (nntp-send-command
554          nil
555          "ARTICLE" (if (numberp article)
556                        (int-to-string article)
557                      ;; `articles' is either a list of article numbers
558                      ;; or a list of article IDs.
559                      article))
560         (incf count)
561         ;; Every 400 requests we have to read the stream in
562         ;; order to avoid deadlocks.
563         (when (or (null articles)       ;All requests have been sent.
564                   (zerop (% count nntp-maximum-request)))
565           (nntp-accept-response)
566           (while (progn
567                    (set-buffer buf)
568                    (goto-char last-point)
569                    ;; Count replies.
570                    (while (nntp-next-result-arrived-p)
571                      (aset map received (cons (aref map received) (point)))
572                      (setq last-point (point))
573                      (incf received))
574                    (< received count))
575             ;; If number of headers is greater than 100, give
576             ;;  informative messages.
577             (and (numberp nntp-large-newsgroup)
578                  (> number nntp-large-newsgroup)
579                  (zerop (% received 20))
580                  (nnheader-message 6 "NNTP: Receiving articles... %d%%"
581                                    (/ (* received 100) number)))
582             (nntp-accept-response))))
583       (and (numberp nntp-large-newsgroup)
584            (> number nntp-large-newsgroup)
585            (nnheader-message 6 "NNTP: Receiving articles...done"))
586       
587       ;; Now we have all the responses.  We go through the results,
588       ;; washes it and copies it over to the server buffer.
589       (set-buffer nntp-server-buffer)
590       (erase-buffer)
591       (setq last-point (point-min))
592       (mapcar
593        (lambda (entry)
594          (narrow-to-region
595           (setq point (goto-char (point-max)))
596           (progn
597             (insert-buffer-substring buf last-point (cdr entry))
598             (point-max)))
599          (setq last-point (cdr entry))
600          (nntp-decode-text)
601          (widen)
602          (cons (car entry) point))
603        map))))
604
605 (defun nntp-try-list-active (group)
606   (nntp-list-active-group group)
607   (save-excursion
608     (set-buffer nntp-server-buffer)
609     (goto-char (point-min))
610     (cond ((or (eobp)
611                (looking-at "5[0-9]+"))
612            (setq nntp-server-list-active-group nil))
613           (t
614            (setq nntp-server-list-active-group t)))))
615
616 (deffoo nntp-list-active-group (group &optional server)
617   "Return the active info on GROUP (which can be a regexp."
618   (nntp-possibly-change-group nil server)
619   (nntp-send-command "^.*\r?\n" "LIST ACTIVE" group))
620
621 (deffoo nntp-request-article (article &optional group server buffer command)
622   (nntp-possibly-change-group group server)
623   (when (nntp-send-command-and-decode
624          "\r?\n\\.\r?\n" "ARTICLE"
625          (if (numberp article) (int-to-string article) article))
626     (if (and buffer
627              (not (equal buffer nntp-server-buffer)))
628         (save-excursion
629           (set-buffer nntp-server-buffer)
630           (copy-to-buffer buffer (point-min) (point-max))
631           (nntp-find-group-and-number))
632       (nntp-find-group-and-number))))
633
634 (deffoo nntp-request-head (article &optional group server)
635   (nntp-possibly-change-group group server)
636   (when (nntp-send-command
637          "\r?\n\\.\r?\n" "HEAD"
638          (if (numberp article) (int-to-string article) article))
639     (prog1
640         (nntp-find-group-and-number)
641       (nntp-decode-text))))
642
643 (deffoo nntp-request-body (article &optional group server)
644   (nntp-possibly-change-group group server)
645   (nntp-send-command-and-decode
646    "\r?\n\\.\r?\n" "BODY"
647    (if (numberp article) (int-to-string article) article)))
648
649 (deffoo nntp-request-group (group &optional server dont-check)
650   (nntp-possibly-change-group nil server)
651   (when (nntp-send-command "^21.*\n" "GROUP" group)
652     (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
653       (setcar (cddr entry) group))))
654
655 (deffoo nntp-close-group (group &optional server)
656   t)
657
658 (deffoo nntp-server-opened (&optional server)
659   "Say whether a connection to SERVER has been opened."
660   (and (nnoo-current-server-p 'nntp server)
661        nntp-server-buffer
662        (gnus-buffer-live-p nntp-server-buffer)
663        (nntp-find-connection nntp-server-buffer)))
664
665 (deffoo nntp-open-server (server &optional defs connectionless)
666   (nnheader-init-server-buffer)
667   (if (nntp-server-opened server)
668       t
669     (when (or (stringp (car defs))
670               (numberp (car defs)))
671       (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs))))
672     (unless (assq 'nntp-address defs)
673       (setq defs (append defs (list (list 'nntp-address server)))))
674     (nnoo-change-server 'nntp server defs)
675     (unless connectionless
676       (or (nntp-find-connection nntp-server-buffer)
677           (nntp-open-connection nntp-server-buffer)))))
678
679 (deffoo nntp-close-server (&optional server)
680   (nntp-possibly-change-group nil server t)
681   (let ((process (nntp-find-connection nntp-server-buffer)))
682     (while process
683       (when (memq (process-status process) '(open run))
684         (ignore-errors
685           (nntp-send-string process "QUIT")
686           (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
687             (sleep-for 1))))
688       (when (buffer-name (process-buffer process))
689         (kill-buffer (process-buffer process)))
690       (setq process (car (pop nntp-connection-alist))))
691     (nnoo-close-server 'nntp)))
692
693 (deffoo nntp-request-close ()
694   (let (process)
695     (while (setq process (pop nntp-connection-list))
696       (when (memq (process-status process) '(open run))
697         (ignore-errors
698           (nntp-send-string process "QUIT")
699           (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
700             ;; Ok, this is evil, but when using telnet and stuff
701             ;; as the connection method, it's important that the
702             ;; QUIT command actually is sent out before we kill
703             ;; the process.  
704             (sleep-for 1))))
705       (when (buffer-name (process-buffer process))
706         (kill-buffer (process-buffer process))))))
707
708 (deffoo nntp-request-list (&optional server)
709   (nntp-possibly-change-group nil server)
710   (nntp-send-command-and-decode "\r?\n\\.\r?\n" "LIST"))
711
712 (deffoo nntp-request-list-newsgroups (&optional server)
713   (nntp-possibly-change-group nil server)
714   (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS"))
715
716 (deffoo nntp-request-newgroups (date &optional server)
717   (nntp-possibly-change-group nil server)
718   (save-excursion
719     (set-buffer nntp-server-buffer)
720     (prog1
721         (nntp-send-command
722          "^\\.\r?\n" "NEWGROUPS"
723          (format-time-string "%y%m%d %H%M%S" (nnmail-date-to-time date)))
724       (nntp-decode-text))))
725
726 (deffoo nntp-request-post (&optional server)
727   (nntp-possibly-change-group nil server)
728   (when (nntp-send-command "^[23].*\r?\n" "POST")
729     (nntp-send-buffer "^[23].*\n")))
730
731 (deffoo nntp-request-type (group article)
732   'news)
733
734 (deffoo nntp-asynchronous-p ()
735   t)
736
737 ;;; Hooky functions.
738
739 (defun nntp-send-mode-reader ()
740   "Send the MODE READER command to the nntp server.
741 This function is supposed to be called from `nntp-server-opened-hook'.
742 It will make innd servers spawn an nnrpd process to allow actual article
743 reading."
744   (nntp-send-command "^.*\r?\n" "MODE READER"))
745
746 (defun nntp-send-authinfo (&optional send-if-force)
747   "Send the AUTHINFO to the nntp server.
748 It will look in the \"~/.authinfo\" file for matching entries.  If
749 nothing suitable is found there, it will prompt for a user name
750 and a password.
751
752 If SEND-IF-FORCE, only send authinfo to the server if the
753 .authinfo file has the FORCE token."
754   (let* ((list (gnus-parse-netrc nntp-authinfo-file))
755          (alist (gnus-netrc-machine list nntp-address))
756          (force (gnus-netrc-get alist "force"))
757          (user (gnus-netrc-get alist "login"))
758          (passwd (gnus-netrc-get alist "password")))
759     (when (or (not send-if-force)
760               force)
761       (nntp-send-command
762        "^3.*\r?\n" "AUTHINFO USER"
763        (or user
764            nntp-authinfo-user
765            (setq nntp-authinfo-user
766                  (read-string (format "NNTP (%s) user name: " nntp-address)))))
767       (nntp-send-command
768        "^2.*\r?\n" "AUTHINFO PASS"
769        (or passwd
770            nntp-authinfo-password
771            (setq nntp-authinfo-password
772                  (nnmail-read-passwd (format "NNTP (%s) password: "
773                                              nntp-address))))))))
774
775 (defun nntp-send-nosy-authinfo ()
776   "Send the AUTHINFO to the nntp server."
777   (nntp-send-command
778    "^3.*\r?\n" "AUTHINFO USER"
779    (read-string (format "NNTP (%s) user name: " nntp-address)))
780   (nntp-send-command
781    "^2.*\r?\n" "AUTHINFO PASS"
782    (nnmail-read-passwd "NNTP (%s) password: " nntp-address)))
783
784 (defun nntp-send-authinfo-from-file ()
785   "Send the AUTHINFO to the nntp server.
786
787 The authinfo login name is taken from the user's login name and the
788 password contained in '~/.nntp-authinfo'."
789   (when (file-exists-p "~/.nntp-authinfo")
790     (nnheader-temp-write nil
791       (insert-file-contents "~/.nntp-authinfo")
792       (goto-char (point-min))
793       (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" (user-login-name))
794       (nntp-send-command
795        "^2.*\r?\n" "AUTHINFO PASS"
796        (buffer-substring (point) (progn (end-of-line) (point)))))))
797
798 ;;; Internal functions.
799
800 (defun nntp-handle-authinfo (process)
801   "Take care of an authinfo response from the server."
802   (let ((last nntp-last-command))
803     (funcall nntp-authinfo-function)
804     ;; We have to re-send the function that was interrupted by
805     ;; the authinfo request.
806     (save-excursion
807       (set-buffer nntp-server-buffer)
808       (erase-buffer))
809     (nntp-send-string process last)))
810
811 (defun nntp-make-process-buffer (buffer)
812   "Create a new, fresh buffer usable for nntp process connections."
813   (save-excursion
814     (set-buffer
815      (generate-new-buffer
816       (format " *server %s %s %s*"
817               nntp-address nntp-port-number
818               (gnus-buffer-exists-p buffer))))
819     (buffer-disable-undo (current-buffer))
820     (set (make-local-variable 'after-change-functions) nil)
821     (set (make-local-variable 'nntp-process-wait-for) nil)
822     (set (make-local-variable 'nntp-process-callback) nil)
823     (set (make-local-variable 'nntp-process-to-buffer) nil)
824     (set (make-local-variable 'nntp-process-start-point) nil)
825     (set (make-local-variable 'nntp-process-decode) nil)
826     (current-buffer)))
827
828 (defun nntp-open-connection (buffer)
829   "Open a connection to PORT on ADDRESS delivering output to BUFFER."
830   (run-hooks 'nntp-prepare-server-hook)
831   (let* ((pbuffer (nntp-make-process-buffer buffer))
832          (process
833           (condition-case ()
834               (let ((coding-system-for-read nntp-coding-system-for-read))
835                 (funcall nntp-open-connection-function pbuffer))
836             (error nil)
837             (quit nil))))
838     (when process
839       (process-kill-without-query process)
840       (nntp-wait-for process "^.*\n" buffer nil t)
841       (if (memq (process-status process) '(open run))
842           (prog1
843               (caar (push (list process buffer nil) nntp-connection-alist))
844             (push process nntp-connection-list)
845             (save-excursion
846               (set-buffer pbuffer)
847               (nntp-read-server-type)
848               (erase-buffer)
849               (set-buffer nntp-server-buffer)
850               (let ((nnheader-callback-function nil))
851                 (run-hooks 'nntp-server-opened-hook)
852                 (nntp-send-authinfo t))))
853         (when (buffer-name (process-buffer process))
854           (kill-buffer (process-buffer process)))
855         nil))))
856
857 (defun nntp-open-network-stream (buffer)
858   (open-network-stream "nntpd" buffer nntp-address nntp-port-number))
859
860 (defun nntp-open-ssl-stream (buffer)
861   (let* ((ssl-program-arguments '("-connect" (concat host ":" service)))
862          (proc (open-ssl-stream "nntpd" buffer nntp-address nntp-port-number)))
863     (save-excursion
864       (set-buffer buffer)
865       (nntp-wait-for-string "^\r*20[01]")
866       (beginning-of-line)
867       (delete-region (point-min) (point))
868       proc)))
869
870 (defun nntp-read-server-type ()
871   "Find out what the name of the server we have connected to is."
872   ;; Wait for the status string to arrive.
873   (setq nntp-server-type (buffer-string))
874   (let ((alist nntp-server-action-alist)
875         (case-fold-search t)
876         entry)
877     ;; Run server-specific commands.
878     (while alist
879       (setq entry (pop alist))
880       (when (string-match (car entry) nntp-server-type)
881         (if (and (listp (cadr entry))
882                  (not (eq 'lambda (caadr entry))))
883             (eval (cadr entry))
884           (funcall (cadr entry)))))))
885
886 (defun nntp-after-change-function-callback (beg end len)
887   (when nntp-process-callback
888     (save-match-data
889       (if (and (= beg (point-min))
890                (memq (char-after beg) '(?4 ?5)))
891           ;; Report back error messages.
892           (save-excursion
893             (goto-char beg)
894             (if (looking-at "480")
895                 (nntp-handle-authinfo nntp-process-to-buffer)
896               (nntp-snarf-error-message)
897               (funcall nntp-process-callback nil)))
898         (goto-char end)
899         (when (and (> (point) nntp-process-start-point)
900                    (re-search-backward nntp-process-wait-for
901                                        nntp-process-start-point t))
902           (when (gnus-buffer-exists-p nntp-process-to-buffer)
903             (let ((cur (current-buffer))
904                   (start nntp-process-start-point))
905               (save-excursion
906                 (set-buffer nntp-process-to-buffer)
907                 (goto-char (point-max))
908                 (let ((b (point)))
909                   (insert-buffer-substring cur start)
910                   (narrow-to-region b (point-max))
911                   (nntp-decode-text)
912                   (widen)))))
913           (goto-char end)
914           (let ((callback nntp-process-callback)
915                 (nntp-inside-change-function t))
916             (setq nntp-process-callback nil)
917             (save-excursion
918               (funcall callback (buffer-name
919                                  (get-buffer nntp-process-to-buffer))))))))))
920
921 (defun nntp-snarf-error-message ()
922   "Save the error message in the current buffer."
923   (let ((message (buffer-string)))
924     (while (string-match "[\r\n]+" message)
925       (setq message (replace-match " " t t message)))
926     (nnheader-report 'nntp message)
927     message))
928
929 (defun nntp-accept-process-output (process)
930   "Wait for output from PROCESS and message some dots."
931   (save-excursion
932     (set-buffer (or (nntp-find-connection-buffer nntp-server-buffer)
933                     nntp-server-buffer))
934     (let ((len (/ (point-max) 1024))
935           message-log-max)
936       (unless (< len 10)
937         (setq nntp-have-messaged t)
938         (nnheader-message 7 "nntp read: %dk" len)))
939     (accept-process-output process 1)))
940
941 (defun nntp-accept-response ()
942   "Wait for output from the process that outputs to BUFFER."
943   (nntp-accept-process-output (nntp-find-connection nntp-server-buffer)))
944
945 (defun nntp-possibly-change-group (group server &optional connectionless)
946   (let ((nnheader-callback-function nil))
947     (when server
948       (or (nntp-server-opened server)
949           (nntp-open-server server nil connectionless)))
950
951     (unless connectionless
952       (or (nntp-find-connection nntp-server-buffer)
953           (nntp-open-connection nntp-server-buffer))))
954
955   (when group
956     (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
957       (when (not (equal group (caddr entry)))
958         (save-excursion
959           (set-buffer (process-buffer (car entry)))
960           (erase-buffer)
961           (nntp-send-string (car entry) (concat "GROUP " group))
962           (nntp-wait-for-string "^2.*\n")
963           (setcar (cddr entry) group)
964           (erase-buffer))))))
965
966 (defun nntp-decode-text (&optional cr-only)
967   "Decode the text in the current buffer."
968   (goto-char (point-min))
969   (while (search-forward "\r" nil t)
970     (delete-char -1))
971   (unless cr-only
972     ;; Remove trailing ".\n" end-of-transfer marker.
973     (goto-char (point-max))
974     (forward-line -1)
975     (when (looking-at ".\n")
976       (delete-char 2))
977     ;; Delete status line.
978     (goto-char (point-min))
979     (delete-region (point) (progn (forward-line 1) (point)))
980     ;; Remove "." -> ".." encoding.
981     (while (search-forward "\n.." nil t)
982       (delete-char -1))))
983
984 (defun nntp-encode-text ()
985   "Encode the text in the current buffer."
986   (save-excursion
987     ;; Replace "." at beginning of line with "..".
988     (goto-char (point-min))
989     (while (re-search-forward "^\\." nil t)
990       (insert "."))
991     (goto-char (point-max))
992     ;; Insert newline at the end of the buffer.
993     (unless (bolp)
994       (insert "\n"))
995     ;; Insert `.' at end of buffer (end of text mark).
996     (goto-char (point-max))
997     (insert ".\n")
998     (goto-char (point-min))
999     (while (not (eobp))
1000       (end-of-line)
1001       (delete-char 1)
1002       (insert nntp-end-of-line))
1003     (forward-char -1)
1004     (unless (eq (char-after (1- (point))) ?\r)
1005       (insert "\r"))))
1006
1007 (defun nntp-retrieve-headers-with-xover (articles &optional fetch-old)
1008   (set-buffer nntp-server-buffer)
1009   (erase-buffer)
1010   (cond
1011
1012    ;; This server does not talk NOV.
1013    ((not nntp-server-xover)
1014     nil)
1015
1016    ;; We don't care about gaps.
1017    ((or (not nntp-nov-gap)
1018         fetch-old)
1019     (nntp-send-xover-command
1020      (if fetch-old
1021          (if (numberp fetch-old)
1022              (max 1 (- (car articles) fetch-old))
1023            1)
1024        (car articles))
1025      (car (last articles)) 'wait)
1026
1027     (goto-char (point-min))
1028     (when (looking-at "[1-5][0-9][0-9] ")
1029       (delete-region (point) (progn (forward-line 1) (point))))
1030     (while (search-forward "\r" nil t)
1031       (replace-match "" t t))
1032     (goto-char (point-max))
1033     (forward-line -1)
1034     (when (looking-at "\\.")
1035       (delete-region (point) (progn (forward-line 1) (point)))))
1036
1037    ;; We do it the hard way.  For each gap, an XOVER command is sent
1038    ;; to the server.  We do not wait for a reply from the server, we
1039    ;; just send them off as fast as we can.  That means that we have
1040    ;; to count the number of responses we get back to find out when we
1041    ;; have gotten all we asked for.
1042    ((numberp nntp-nov-gap)
1043     (let ((count 0)
1044           (received 0)
1045           (last-point (point-min))
1046           (buf nntp-server-buffer)
1047           ;;(process-buffer (nntp-find-connection (current-buffer))))
1048           first)
1049       ;; We have to check `nntp-server-xover'.  If it gets set to nil,
1050       ;; that means that the server does not understand XOVER, but we
1051       ;; won't know that until we try.
1052       (while (and nntp-server-xover articles)
1053         (setq first (car articles))
1054         ;; Search forward until we find a gap, or until we run out of
1055         ;; articles.
1056         (while (and (cdr articles)
1057                     (< (- (nth 1 articles) (car articles)) nntp-nov-gap))
1058           (setq articles (cdr articles)))
1059
1060         (when (nntp-send-xover-command first (car articles))
1061           (setq articles (cdr articles)
1062                 count (1+ count))
1063
1064           ;; Every 400 requests we have to read the stream in
1065           ;; order to avoid deadlocks.
1066           (when (or (null articles)     ;All requests have been sent.
1067                     (zerop (% count nntp-maximum-request)))
1068             (accept-process-output)
1069             ;; On some Emacs versions the preceding function has
1070             ;; a tendency to change the buffer.  Perhaps.  It's
1071             ;; quite difficult to reproduce, because it only
1072             ;; seems to happen once in a blue moon.
1073             (set-buffer buf)
1074             (while (progn
1075                      (goto-char last-point)
1076                      ;; Count replies.
1077                      (while (re-search-forward "^[0-9][0-9][0-9] " nil t)
1078                        (setq received (1+ received)))
1079                      (setq last-point (point))
1080                      (< received count))
1081               (accept-process-output)
1082               (set-buffer buf)))))
1083
1084       (when nntp-server-xover
1085         ;; Wait for the reply from the final command.
1086         (goto-char (point-max))
1087         (re-search-backward "^[0-9][0-9][0-9] " nil t)
1088         (when (looking-at "^[23]")
1089           (while (progn
1090                    (goto-char (point-max))
1091                    (forward-line -1)
1092                    (not (looking-at "^\\.\r?\n")))
1093             (nntp-accept-response)))
1094
1095         ;; We remove any "." lines and status lines.
1096         (goto-char (point-min))
1097         (while (search-forward "\r" nil t)
1098           (delete-char -1))
1099         (goto-char (point-min))
1100         (delete-matching-lines "^\\.$\\|^[1-5][0-9][0-9] ")
1101         ;;(copy-to-buffer nntp-server-buffer (point-min) (point-max))
1102         t))))
1103
1104   nntp-server-xover)
1105
1106 (defun nntp-send-xover-command (beg end &optional wait-for-reply)
1107   "Send the XOVER command to the server."
1108   (let ((range (format "%d-%d" beg end))
1109         (nntp-inhibit-erase t))
1110     (if (stringp nntp-server-xover)
1111         ;; If `nntp-server-xover' is a string, then we just send this
1112         ;; command.
1113         (if wait-for-reply
1114             (nntp-send-command-nodelete
1115              "\r?\n\\.\r?\n" nntp-server-xover range)
1116           ;; We do not wait for the reply.
1117           (nntp-send-command-nodelete "\r?\n\\.\r?\n" nntp-server-xover range))
1118       (let ((commands nntp-xover-commands))
1119         ;; `nntp-xover-commands' is a list of possible XOVER commands.
1120         ;; We try them all until we get at positive response.
1121         (while (and commands (eq nntp-server-xover 'try))
1122           (nntp-send-command-nodelete "\r?\n\\.\r?\n" (car commands) range)
1123           (save-excursion
1124             (set-buffer nntp-server-buffer)
1125             (goto-char (point-min))
1126             (and (looking-at "[23]")    ; No error message.
1127                  ;; We also have to look at the lines.  Some buggy
1128                  ;; servers give back simple lines with just the
1129                  ;; article number.  How... helpful.
1130                  (progn
1131                    (forward-line 1)
1132                    (looking-at "[0-9]+\t...")) ; More text after number.
1133                  (setq nntp-server-xover (car commands))))
1134           (setq commands (cdr commands)))
1135         ;; If none of the commands worked, we disable XOVER.
1136         (when (eq nntp-server-xover 'try)
1137           (save-excursion
1138             (set-buffer nntp-server-buffer)
1139             (erase-buffer)
1140             (setq nntp-server-xover nil)))
1141         nntp-server-xover))))
1142
1143 ;;; Alternative connection methods.
1144
1145 (defun nntp-wait-for-string (regexp)
1146   "Wait until string arrives in the buffer."
1147   (let ((buf (current-buffer)))
1148     (goto-char (point-min))
1149     (while (not (re-search-forward regexp nil t))
1150       (accept-process-output (nntp-find-connection nntp-server-buffer))
1151       (set-buffer buf)
1152       (goto-char (point-min)))))
1153
1154 (defun nntp-open-telnet (buffer)
1155   (save-excursion
1156     (set-buffer buffer)
1157     (erase-buffer)
1158     (let ((proc (apply
1159                  'start-process
1160                  "nntpd" buffer nntp-telnet-command nntp-telnet-switches))
1161           (case-fold-search t))
1162       (when (memq (process-status proc) '(open run))
1163         (process-send-string proc "set escape \^X\n")
1164         (cond
1165          ((and nntp-open-telnet-envuser nntp-telnet-user-name)
1166           (process-send-string proc (concat "open " "-l" nntp-telnet-user-name
1167                                             nntp-address "\n")))
1168          (t
1169           (process-send-string proc (concat "open " nntp-address "\n"))))
1170         (cond
1171          ((not nntp-open-telnet-envuser)
1172           (nntp-wait-for-string "^\r*.?login:")
1173           (process-send-string
1174            proc (concat
1175                  (or nntp-telnet-user-name
1176                      (setq nntp-telnet-user-name (read-string "login: ")))
1177                  "\n"))))
1178         (nntp-wait-for-string "^\r*.?password:")
1179         (process-send-string
1180          proc (concat
1181                (or nntp-telnet-passwd
1182                    (setq nntp-telnet-passwd
1183                          (nnmail-read-passwd "Password: ")))
1184                "\n"))
1185         (erase-buffer)
1186         (nntp-wait-for-string nntp-telnet-shell-prompt)
1187         (process-send-string
1188          proc (concat (mapconcat 'identity nntp-telnet-parameters " ") "\n"))
1189         (nntp-wait-for-string "^\r*20[01]")
1190         (beginning-of-line)
1191         (delete-region (point-min) (point))
1192         (process-send-string proc "\^]")
1193         (nntp-wait-for-string "^telnet")
1194         (process-send-string proc "mode character\n")
1195         (accept-process-output proc 1)
1196         (sit-for 1)
1197         (goto-char (point-min))
1198         (forward-line 1)
1199         (delete-region (point) (point-max)))
1200       proc)))
1201
1202 (defun nntp-open-rlogin (buffer)
1203   "Open a connection to SERVER using rsh."
1204   (let ((proc (if nntp-rlogin-user-name
1205                   (apply 'start-process
1206                          "nntpd" buffer nntp-rlogin-program
1207                          nntp-address "-l" nntp-rlogin-user-name
1208                          nntp-rlogin-parameters)
1209                 (apply 'start-process
1210                        "nntpd" buffer nntp-rlogin-program nntp-address
1211                        nntp-rlogin-parameters))))
1212     (save-excursion
1213       (set-buffer buffer)
1214       (nntp-wait-for-string "^\r*20[01]")
1215       (beginning-of-line)
1216       (delete-region (point-min) (point))
1217       proc)))
1218
1219 (defun nntp-find-group-and-number ()
1220   (save-excursion
1221     (save-restriction
1222       (set-buffer nntp-server-buffer)
1223       (narrow-to-region (goto-char (point-min))
1224                         (or (search-forward "\n\n" nil t) (point-max)))
1225       (goto-char (point-min))
1226       ;; We first find the number by looking at the status line.
1227       (let ((number (and (looking-at "2[0-9][0-9] +\\([0-9]+\\) ")
1228                          (string-to-int
1229                           (buffer-substring (match-beginning 1)
1230                                             (match-end 1)))))
1231             group newsgroups xref)
1232         (and number (zerop number) (setq number nil))
1233         ;; Then we find the group name.
1234         (setq group
1235               (cond
1236                ;; If there is only one group in the Newsgroups header,
1237                ;; then it seems quite likely that this article comes
1238                ;; from that group, I'd say.
1239                ((and (setq newsgroups (mail-fetch-field "newsgroups"))
1240                      (not (string-match "," newsgroups)))
1241                 newsgroups)
1242                ;; If there is more than one group in the Newsgroups
1243                ;; header, then the Xref header should be filled out.
1244                ;; We hazard a guess that the group that has this
1245                ;; article number in the Xref header is the one we are
1246                ;; looking for.  This might very well be wrong if this
1247                ;; article happens to have the same number in several
1248                ;; groups, but that's life.
1249                ((and (setq xref (mail-fetch-field "xref"))
1250                      number
1251                      (string-match (format "\\([^ :]+\\):%d" number) xref))
1252                 (substring xref (match-beginning 1) (match-end 1)))
1253                (t "")))
1254         (when (string-match "\r" group)
1255           (setq group (substring group 0 (match-beginning 0))))
1256         (cons group number)))))
1257
1258 (provide 'nntp)
1259
1260 ;;; nntp.el ends here