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