1 ;;; url-news.el --- News Uniform Resource Locator retrieval code
2 ;; Keywords: comm, data, processes
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 ;;; Copyright (c) 1993 - 1996 by William M. Perry <wmperry@cs.indiana.edu>
6 ;;; Copyright (c) 1996 - 1999 Free Software Foundation, Inc.
8 ;;; This file is part of GNU Emacs.
10 ;;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2, or (at your option)
13 ;;; any later version.
15 ;;; GNU Emacs is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;;; Boston, MA 02111-1307, USA.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 (autoload 'url-warn
"url")
30 (autoload 'gnus-group-read-ephemeral-group
"gnus-group")
31 (eval-when-compile (require 'cl
))
33 (defgroup url-news nil
34 "News related options"
37 (defun url-news-open-host (host port user pass
)
38 (if (fboundp 'nnheader-init-server-buffer
)
39 (nnheader-init-server-buffer))
40 (nntp-open-server host
(list (string-to-int port
)))
43 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" user
)
44 (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" pass
)
45 (if (not (nntp-server-opened host
))
46 (url-warn 'url
(format "NNTP authentication to `%s' as `%s' failed"
49 (defun url-news-fetch-message-id (host message-id
)
50 (let ((buf (generate-new-buffer " *url-news*")))
51 (if (eq ?
> (aref message-id
(1- (length message-id
))))
53 (setq message-id
(concat "<" message-id
">")))
54 (if (cdr-safe (nntp-request-article message-id nil host buf
))
55 ;; Successfully retrieved the article
59 (insert "Content-type: text/html\n\n"
62 " <title>Error</title>\n"
66 " <h1>Error requesting article...</h1>\n"
68 " The status message returned by the NNTP server was:"
75 " If you If you feel this is an error, <a href=\""
76 "mailto:" url-bug-address
"\">send mail</a>\n"
81 "<!-- Automatically generated by URL v" url-version
" -->\n"
85 (defun url-news-fetch-newsgroup (newsgroup host
)
86 (declare (special gnus-group-buffer
))
87 (if (string-match "^/+" newsgroup
)
88 (setq newsgroup
(substring newsgroup
(match-end 0))))
89 (if (string-match "/+$" newsgroup
)
90 (setq newsgroup
(substring newsgroup
0 (match-beginning 0))))
92 ;; This saves us from checking new news if Gnus is already running
93 ;; FIXME - is it relatively safe to use gnus-alive-p here? FIXME
94 (if (or (not (get-buffer gnus-group-buffer
))
96 (set-buffer gnus-group-buffer
)
97 (not (eq major-mode
'gnus-group-mode
))))
99 (set-buffer gnus-group-buffer
)
100 (goto-char (point-min))
101 (gnus-group-read-ephemeral-group newsgroup
103 'nntp-open-connection-function
104 nntp-open-connection-function
)
106 (cons (current-buffer) 'browse
)))
109 (defun url-news (url)
110 ;; Find a news reference
111 (let* ((host (or (url-host url
) url-news-server
))
112 (port (url-port url
))
113 (article-brackets nil
)
115 (article (url-filename url
)))
116 (url-news-open-host host port
(url-user url
) (url-password url
))
117 (setq article
(url-unhex-string article
))
119 ((string-match "@" article
) ; Its a specific article
120 (setq buf
(url-news-fetch-message-id host article
)))
121 ((string= article
"") ; List all newsgroups
124 (url-news-fetch-newsgroup article host
)))
128 (defun url-snews (url)
129 (let ((nntp-open-connection-function 'nntp-open-ssl-stream
))
134 ;;; arch-tag: 8975be13-04e8-4d38-bfff-47918e3ad311