1 ;;; url-news.el --- News Uniform Resource Locator retrieval code
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Keywords: comm, data, processes
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)
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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
31 (autoload 'url-warn
"url")
32 (autoload 'gnus-group-read-ephemeral-group
"gnus-group")
35 (defvar nntp-open-tls-stream
)
36 (defvar nntp-open-ssl-stream
))
38 (defgroup url-news nil
39 "News related options."
42 (defun url-news-open-host (host port user pass
)
43 (if (fboundp 'nnheader-init-server-buffer
)
44 (nnheader-init-server-buffer))
45 (nntp-open-server host
(list port
))
48 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" user
)
49 (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" pass
)
50 (if (not (nntp-server-opened host
))
51 (url-warn 'url
(format "NNTP authentication to `%s' as `%s' failed"
54 (defun url-news-fetch-message-id (host message-id
)
55 (let ((buf (generate-new-buffer " *url-news*")))
56 (if (eq ?
> (aref message-id
(1- (length message-id
))))
58 (setq message-id
(concat "<" message-id
">")))
59 (if (cdr-safe (nntp-request-article message-id nil host buf
))
60 ;; Successfully retrieved the article
64 (insert "Content-type: text/html\n\n"
67 " <title>Error</title>\n"
71 " <h1>Error requesting article...</h1>\n"
73 " The status message returned by the NNTP server was:"
80 " If you If you feel this is an error, <a href=\""
81 "mailto:" url-bug-address
"\">send mail</a>\n"
86 "<!-- Automatically generated by URL v" url-version
" -->\n"
90 (defun url-news-fetch-newsgroup (newsgroup host
)
91 (declare (special gnus-group-buffer
))
92 (if (string-match "^/+" newsgroup
)
93 (setq newsgroup
(substring newsgroup
(match-end 0))))
94 (if (string-match "/+$" newsgroup
)
95 (setq newsgroup
(substring newsgroup
0 (match-beginning 0))))
97 ;; This saves us from checking new news if Gnus is already running
98 ;; FIXME - is it relatively safe to use gnus-alive-p here? FIXME
99 (if (or (not (get-buffer gnus-group-buffer
))
101 (set-buffer gnus-group-buffer
)
102 (not (eq major-mode
'gnus-group-mode
))))
104 (set-buffer gnus-group-buffer
)
105 (goto-char (point-min))
106 (gnus-group-read-ephemeral-group newsgroup
108 'nntp-open-connection-function
109 nntp-open-connection-function
)
111 (cons (current-buffer) 'browse
)))
114 (defun url-news (url)
115 ;; Find a news reference
116 (let* ((host (or (url-host url
) url-news-server
))
117 (port (url-port url
))
118 (article-brackets nil
)
120 (article (url-filename url
)))
121 (url-news-open-host host port
(url-user url
) (url-password url
))
122 (setq article
(url-unhex-string article
))
124 ((string-match "@" article
) ; Its a specific article
125 (setq buf
(url-news-fetch-message-id host article
)))
126 ((string= article
"") ; List all newsgroups
129 (url-news-fetch-newsgroup article host
)))
133 (defun url-snews (url)
134 (let ((nntp-open-connection-function (if (eq 'tls url-gateway-method
)
136 nntp-open-ssl-stream
)))
141 ;;; arch-tag: 8975be13-04e8-4d38-bfff-47918e3ad311
142 ;;; url-news.el ends here