54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; url-news.el --- News Uniform Resource Locator retrieval code
|
57612
|
2
|
|
3 ;; Copyright (c) 1996 - 1999, 2004 Free Software Foundation, Inc.
|
|
4
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Keywords: comm, data, processes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6
|
57612
|
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 the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Code:
|
|
25
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 (require 'url-vars)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 (require 'url-util)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 (require 'url-parse)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 (require 'nntp)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 (autoload 'url-warn "url")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 (autoload 'gnus-group-read-ephemeral-group "gnus-group")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 (eval-when-compile (require 'cl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 (defgroup url-news nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 "News related options"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 :group 'url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 (defun url-news-open-host (host port user pass)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 (if (fboundp 'nnheader-init-server-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 (nnheader-init-server-buffer))
|
57886
|
41 (nntp-open-server host (list port))
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 (if (and user pass)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" user)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" pass)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 (if (not (nntp-server-opened host))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 (url-warn 'url (format "NNTP authentication to `%s' as `%s' failed"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 host user))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 (defun url-news-fetch-message-id (host message-id)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 (let ((buf (generate-new-buffer " *url-news*")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 (if (eq ?> (aref message-id (1- (length message-id))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 (setq message-id (concat "<" message-id ">")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 (if (cdr-safe (nntp-request-article message-id nil host buf))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 ;; Successfully retrieved the article
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (set-buffer buf)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (insert "Content-type: text/html\n\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 "<html>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 " <head>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 " <title>Error</title>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 " </head>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 " <body>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 " <div>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 " <h1>Error requesting article...</h1>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 " <p>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 " The status message returned by the NNTP server was:"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 "<br><hr>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 " <xmp>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 (nntp-status-message)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 " </xmp>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 " </p>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 " <p>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 " If you If you feel this is an error, <a href=\""
|
54801
|
77 "mailto:" url-bug-address "\">send mail</a>\n"
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 " </p>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 " </div>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 " </body>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 "</html>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 "<!-- Automatically generated by URL v" url-version " -->\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 buf))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 (defun url-news-fetch-newsgroup (newsgroup host)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 (declare (special gnus-group-buffer))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88 (if (string-match "^/+" newsgroup)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 (setq newsgroup (substring newsgroup (match-end 0))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 (if (string-match "/+$" newsgroup)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 (setq newsgroup (substring newsgroup 0 (match-beginning 0))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92
|
54801
|
93 ;; This saves us from checking new news if Gnus is already running
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 ;; FIXME - is it relatively safe to use gnus-alive-p here? FIXME
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 (if (or (not (get-buffer gnus-group-buffer))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (set-buffer gnus-group-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 (not (eq major-mode 'gnus-group-mode))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 (gnus))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 (set-buffer gnus-group-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 (gnus-group-read-ephemeral-group newsgroup
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 (list 'nntp host
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 'nntp-open-connection-function
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 nntp-open-connection-function)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 (cons (current-buffer) 'browse)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 (defun url-news (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 ;; Find a news reference
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 (let* ((host (or (url-host url) url-news-server))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 (port (url-port url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 (article-brackets nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 (buf nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116 (article (url-filename url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 (url-news-open-host host port (url-user url) (url-password url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 (setq article (url-unhex-string article))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
120 ((string-match "@" article) ; Its a specific article
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 (setq buf (url-news-fetch-message-id host article)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 ((string= article "") ; List all newsgroups
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 (gnus))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 (t ; Whole newsgroup
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 (url-news-fetch-newsgroup article host)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 buf))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 (defun url-snews (url)
|
57449
|
130 (let ((nntp-open-connection-function (if (eq 'tls url-gateway-method)
|
|
131 nntp-open-tls-stream
|
|
132 nntp-open-ssl-stream)))
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
133 (url-news url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
135 (provide 'url-news)
|
54699
|
136
|
|
137 ;;; arch-tag: 8975be13-04e8-4d38-bfff-47918e3ad311
|
57612
|
138 ;;; url-news.el ends here
|