annotate lisp/w3/url-news.el @ 181:bfd6434d15b3 r20-3b17

Import from CVS: tag r20-3b17
author cvs
date Mon, 13 Aug 2007 09:53:19 +0200
parents 8eaf7971accc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; url-news.el --- News Uniform Resource Locator retrieval code
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2 ;; Author: wmperry
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
3 ;; Created: 1997/07/05 22:54:24
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
4 ;; Version: 1.8
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Keywords: comm, data, processes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1993-1996 by William M. Perry (wmperry@cs.indiana.edu)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
10 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ;;; any later version.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28 (require 'url-vars)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
29 (require 'url-parse)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
30
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
31 (defgroup url-news nil
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
32 "News related options"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
33 :group 'url)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
34
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
35 (defcustom url-news-use-article-mode nil
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
36 "*Whether to use Gnus' article mode for displaying news articles."
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
37 :type 'boolean
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
38 :group 'url-news)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
39
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 (defun url-format-news ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 (url-clear-tmp-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 (insert "HTTP/1.0 200 Retrieval OK\r\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 (set-buffer nntp-server-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45 (buffer-string)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46 (url-parse-mime-headers)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
47 (let* ((from (cdr (assoc "from" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
48 (qfrom (if from (url-insert-entities-in-string from) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
49 (subj (cdr (assoc "subject" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
50 (qsubj (if subj (url-insert-entities-in-string subj) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
51 (org (cdr (assoc "organization" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
52 (qorg (if org (url-insert-entities-in-string org) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
53 (typ (or (cdr (assoc "content-type" url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
54 "text/plain"))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
55 (inhibit-read-only t)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
56 (qgrps (mapcar 'car
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
57 (url-split
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
58 (url-insert-entities-in-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
59 (or (cdr (assoc "newsgroups"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
60 url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
61 ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
62 "[ \t\n,]+")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 (qrefs (delete ""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
64 (mapcar
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
65 'url-insert-entities-in-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
66 (mapcar 'car
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
67 (url-split
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
68 (or (cdr (assoc "references"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
70 "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
71 "[ \t,\n<>]+")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
72 (date (cdr (assoc "date" url-current-mime-headers))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
73 (if (or (not (string-match "text/" typ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
74 (string-match "text/html" typ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75 nil ; Let natural content-type take over
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
76 (if (and (fboundp 'gnus-article-mode)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
77 url-news-use-article-mode)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
78 (progn
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
79 (kill-buffer (current-buffer))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
80 (set-buffer (get-buffer-create "Emacs/W3 News"))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
81 (erase-buffer)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
82 (insert
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
83 (save-excursion
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
84 (set-buffer nntp-server-buffer)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
85 (save-restriction
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
86 (widen)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
87 (buffer-string))))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
88 (gnus-article-mode)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
89 (article-hide-headers 1)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
90 (goto-char (point-min))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
91 (display-buffer (current-buffer)))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
92 (insert "<html>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
93 " <head>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
94 " <title>" qsubj "</title>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
95 " <link rev=\"made\" href=\"mailto:" qfrom "\">\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
96 " </head>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
97 " <body>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
98 " <div>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
99 " <h1 align=center>" qsubj "</h1>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
100 " <p role=\"headers\">\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
101 " <b>From</b>: " qfrom "<br>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
102 " <b>Newsgroups</b>: "
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
103 (mapconcat
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
104 (function
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
105 (lambda (grp)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
106 (concat "<a href=\"" grp "\">" grp "</a>"))) qgrps ", ")
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
107 "<br>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
108 (if org
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
109 (concat
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
110 " <b>Organization</b>: <i> " qorg "</i> <br>\n")
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
111 "")
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
112 " <b>Date</b>: <date> " date "</date> <br>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
113 " </p> <hr>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
114 (if (null qrefs)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
115 ""
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
116 (concat
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
117 " <p>References\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
118 " <ol>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
119 (mapconcat
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
120 (function
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
121 (lambda (ref)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
122 (concat " <li> <a href=\"" ref "\"> "
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
123 ref "</a></li>\n")))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
124 qrefs "")
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
125 " </ol>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
126 " </p>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
127 " <hr>\n"))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
128 " <ul plain>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
129 " <li><a href=\"newspost:disfunctional\"> "
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
130 "Post to this group </a></li>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
131 " <li><a href=\"mailto:" qfrom "\"> Reply to " qfrom
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
132 "</a></li>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
133 " </ul>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
134 " <hr>"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
135 " <pre>\n")
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
136 (let ((s (buffer-substring (point) (point-max))))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
137 (delete-region (point) (point-max))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
138 (insert (url-insert-entities-in-string s)))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
139 (goto-char (point-max))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
140 (setq url-current-mime-type "text/html"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
141 url-current-mime-viewer (mm-mime-info url-current-mime-type nil 5))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
142 (let ((x (assoc "content-type" url-current-mime-headers)))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
143 (if x
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
144 (setcdr x "text/html")
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
145 (setq url-current-mime-headers (cons (cons "content-type"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
146 "text/html")
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
147 url-current-mime-headers))))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
148 (insert "\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
149 " </pre>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
150 " </div>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
151 " </body>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
152 "</html>\n"
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
153 "<!-- Automatically generated by URL/" url-version
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 26
diff changeset
154 "-->")))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 (defun url-check-gnus-version ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 (require 'nntp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
158 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
159 (require 'gnus)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
160 (error (setq gnus-version "GNUS not found")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
161 (if (or (not (boundp 'gnus-version))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
162 (string-match "v5.[.0-9]+$" gnus-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
163 (string-match "Red" gnus-version))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
164 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
165 (url-warn 'url (concat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
166 "The version of GNUS found on this system is too old and does\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
167 "not support the necessary functionality for the URL package.\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
168 "Please upgrade to version 5.x of GNUS. This is bundled by\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
169 "default with Emacs 19.30 and XEmacs 19.14 and later.\n\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
170 "This version of GNUS is: " gnus-version "\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
171 (fset 'url-news 'url-news-version-too-old))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
172 (fset 'url-check-gnus-version 'ignore))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
173
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
174 (defun url-news-version-too-old (article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
175 (set-buffer (get-buffer-create url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
176 (setq url-current-mime-headers '(("content-type" . "text/html"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
177 url-current-mime-type "text/html")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
178 (insert "<html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
179 " <head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
180 " <title>News Error</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
181 " </head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
182 " <body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
183 " <h1>News Error - too old</h1>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
184 " <p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
185 " The version of GNUS found on this system is too old and does\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
186 " not support the necessary functionality for the URL package.\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
187 " Please upgrade to version 5.x of GNUS. This is bundled by\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
188 " default with Emacs 19.30 and XEmacs 19.14 and later.\n\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
189 " This version of GNUS is: " gnus-version "\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
190 " </p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
191 " </body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
192 "</html>\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
193
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
194 (defun url-news-open-host (host port user pass)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
195 (if (fboundp 'nnheader-init-server-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
196 (nnheader-init-server-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
197 (nntp-open-server host (list (string-to-int port)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
198 (if (and user pass)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
199 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
200 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" user)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
201 (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" pass)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
202 (if (not (nntp-server-opened host))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
203 (url-warn 'url (format "NNTP authentication to `%s' as `%s' failed"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
204 host user))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
205
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
206 (defun url-news-fetch-article-number (newsgroup article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
207 (nntp-request-group newsgroup)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
208 (nntp-request-article article))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
209
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
210 (defun url-news-fetch-message-id (host port message-id)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
211 (if (eq ?> (aref message-id (1- (length message-id))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
212 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
213 (setq message-id (concat "<" message-id ">")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
214 (if (nntp-request-article message-id)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
215 (url-format-news)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
216 (set-buffer (get-buffer-create url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
217 (setq url-current-can-be-cached nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
218 (insert "<html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
219 " <head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
220 " <title>Error</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
221 " </head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
222 " <body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
223 " <div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
224 " <h1>Error requesting article...</h1>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
225 " <p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
226 " The status message returned by the NNTP server was:"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
227 "<br><hr>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
228 " <xmp>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
229 (nntp-status-message)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
230 " </xmp>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
231 " </p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
232 " <p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
233 " If you If you feel this is an error, <a href=\""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
234 "mailto:" url-bug-address "\">send me mail</a>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
235 " </p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
236 " </div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
237 " </body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
238 "</html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
239 "<!-- Automatically generated by URL v" url-version " -->\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
240 )))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
241
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
242 (defun url-news-fetch-newsgroup (newsgroup host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
243 (if (string-match "^/+" newsgroup)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
244 (setq newsgroup (substring newsgroup (match-end 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
245 (if (string-match "/+$" newsgroup)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
246 (setq newsgroup (substring newsgroup 0 (match-beginning 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
247
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
248 ;; This saves a bogus 'Untitled' buffer by Emacs-W3
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
249 (kill-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
250
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
251 ;; This saves us from checking new news if GNUS is already running
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
252 (if (or (not (get-buffer gnus-group-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
253 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
254 (set-buffer gnus-group-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
255 (not (eq major-mode 'gnus-group-mode))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
256 (gnus))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
257 (set-buffer gnus-group-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
258 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
259 (gnus-group-read-ephemeral-group newsgroup (list 'nntp host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
260 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
261 (cons (current-buffer) 'browse)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
262
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
263 (defun url-news (article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
264 ;; Find a news reference
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
265 (url-check-gnus-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
266 (let* ((urlobj (url-generic-parse-url article))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
267 (host (or (url-host urlobj) url-news-server))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
268 (port (or (url-port urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
269 (cdr-safe (assoc "news" url-default-ports))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
270 (article-brackets nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
271 (article (url-filename urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
272 (url-news-open-host host port (url-user urlobj) (url-password urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
273 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
274 ((string-match "@" article) ; Its a specific article
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
275 (url-news-fetch-message-id host port article))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
276 ((string= article "") ; List all newsgroups
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
277 (gnus)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
278 (kill-buffer url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
279 (t ; Whole newsgroup
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
280 (url-news-fetch-newsgroup article host)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
281
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
282 (defun url-nntp (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
283 ;; Find a news reference
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
284 (url-check-gnus-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
285 (let* ((urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
286 (host (or (url-host urlobj) url-news-server))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
287 (port (or (url-port urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
288 (cdr-safe (assoc "nntp" url-default-ports))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
289 (article-brackets nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
290 (article (url-filename urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
291 (url-news-open-host host port (url-user urlobj) (url-password urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
292 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
293 ((string-match "@" article) ; Its a specific article
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
294 (url-news-fetch-message-id host port article))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
295 ((string-match "/\\([0-9]+\\)$" article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
296 (url-news-fetch-article-number (substring article 0
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
297 (match-beginning 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
298 (match-string 1 article)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
299
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
300 ((string= article "") ; List all newsgroups
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
301 (gnus)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
302 (kill-buffer url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
303 (t ; Whole newsgroup
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
304 (url-news-fetch-newsgroup article)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
305
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
306 (provide 'url-news)