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