1 ;;; url-news.el --- News Uniform Resource Locator retrieval code
2 ;; Author: $Author: fx $
3 ;; Created: $Date: 2001/05/22 16:13:00 $
4 ;; Version: $Revision: 1.3 $
5 ;; Keywords: comm, data, processes
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; Copyright (c) 1993 - 1996 by William M. Perry <wmperry@cs.indiana.edu>
9 ;;; Copyright (c) 1996 - 1999 Free Software Foundation, Inc.
11 ;;; This file is part of GNU Emacs.
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;;; it under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 2, or (at your option)
16 ;;; any later version.
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;;; Boston, MA 02111-1307, USA.
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 (autoload 'url-warn
"url")
33 (autoload 'gnus-group-read-ephemeral-group
"gnus-group")
34 (eval-when-compile (require 'cl
))
36 (defgroup url-news nil
37 "News related options"
40 (defun url-news-open-host (host port user pass
)
41 (if (fboundp 'nnheader-init-server-buffer
)
42 (nnheader-init-server-buffer))
43 (nntp-open-server host
(list (string-to-int port
)))
46 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" user
)
47 (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" pass
)
48 (if (not (nntp-server-opened host
))
49 (url-warn 'url
(format "NNTP authentication to `%s' as `%s' failed"
52 (defun url-news-fetch-message-id (host message-id
)
53 (let ((buf (generate-new-buffer " *url-news*")))
54 (if (eq ?
> (aref message-id
(1- (length message-id
))))
56 (setq message-id
(concat "<" message-id
">")))
57 (if (cdr-safe (nntp-request-article message-id nil host buf
))
58 ;; Successfully retrieved the article
62 (insert "Content-type: text/html\n\n"
65 " <title>Error</title>\n"
69 " <h1>Error requesting article...</h1>\n"
71 " The status message returned by the NNTP server was:"
78 " If you If you feel this is an error, <a href=\""
79 "mailto:" url-bug-address
"\">send me mail</a>\n"
84 "<!-- Automatically generated by URL v" url-version
" -->\n"
88 (defun url-news-fetch-newsgroup (newsgroup host
)
89 (declare (special gnus-group-buffer
))
90 (if (string-match "^/+" newsgroup
)
91 (setq newsgroup
(substring newsgroup
(match-end 0))))
92 (if (string-match "/+$" newsgroup
)
93 (setq newsgroup
(substring newsgroup
0 (match-beginning 0))))
95 ;; This saves us from checking new news if GNUS is already running
96 ;; FIXME - is it relatively safe to use gnus-alive-p here? FIXME
97 (if (or (not (get-buffer gnus-group-buffer
))
99 (set-buffer gnus-group-buffer
)
100 (not (eq major-mode
'gnus-group-mode
))))
102 (set-buffer gnus-group-buffer
)
103 (goto-char (point-min))
104 (gnus-group-read-ephemeral-group newsgroup
106 'nntp-open-connection-function
107 nntp-open-connection-function
)
109 (cons (current-buffer) 'browse
)))
112 (defun url-news (url)
113 ;; Find a news reference
114 (let* ((host (or (url-host url
) url-news-server
))
115 (port (url-port url
))
116 (article-brackets nil
)
118 (article (url-filename url
)))
119 (url-news-open-host host port
(url-user url
) (url-password url
))
120 (setq article
(url-unhex-string article
))
122 ((string-match "@" article
) ; Its a specific article
123 (setq buf
(url-news-fetch-message-id host article
)))
124 ((string= article
"") ; List all newsgroups
127 (url-news-fetch-newsgroup article host
)))
131 (defun url-snews (url)
132 (let ((nntp-open-connection-function 'nntp-open-ssl-stream
))