annotate lisp/w3/url-news.el @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents 0293115a14e9
children 8eaf7971accc
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
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
3 ;; Created: 1997/02/18 23:35:11
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
4 ;; Version: 1.7
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
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
31 (defun url-format-news ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
32 (url-clear-tmp-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
33 (insert "HTTP/1.0 200 Retrieval OK\r\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
34 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
35 (set-buffer nntp-server-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
36 (buffer-string)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
37 (url-parse-mime-headers)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
38 (let* ((from (cdr (assoc "from" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
39 (qfrom (if from (url-insert-entities-in-string from) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 (subj (cdr (assoc "subject" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 (qsubj (if subj (url-insert-entities-in-string subj) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 (org (cdr (assoc "organization" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 (qorg (if org (url-insert-entities-in-string org) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 (typ (or (cdr (assoc "content-type" url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45 "text/plain"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46 (qgrps (mapcar 'car
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
47 (url-split
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
48 (url-insert-entities-in-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
49 (or (cdr (assoc "newsgroups"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
50 url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
51 ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
52 "[ \t\n,]+")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
53 (qrefs (delete ""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
54 (mapcar
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
55 'url-insert-entities-in-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
56 (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 (or (cdr (assoc "references"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
59 url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
60 "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
61 "[ \t,\n<>]+")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
62 (date (cdr (assoc "date" url-current-mime-headers))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 (if (or (not (string-match "text/" typ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
64 (string-match "text/html" typ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
65 nil ; Let natural content-type take over
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
66 (insert "<html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
67 " <head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
68 " <title>" qsubj "</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 " <link rev=\"made\" href=\"mailto:" qfrom "\">\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
70 " </head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
71 " <body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
72 " <div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
73 " <h1 align=center>" qsubj "</h1>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
74 " <p role=\"headers\">\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75 " <b>From</b>: " qfrom "<br>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
76 " <b>Newsgroups</b>: "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
77 (mapconcat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
78 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
79 (lambda (grp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
80 (concat "<a href=\"" grp "\">" grp "</a>"))) qgrps ", ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
81 "<br>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
82 (if org
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
83 (concat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
84 " <b>Organization</b>: <i> " qorg "</i> <br>\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
85 "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
86 " <b>Date</b>: <date> " date "</date> <br>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
87 " </p> <hr>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
88 (if (null qrefs)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
89 ""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
90 (concat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
91 " <p>References\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
92 " <ol>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
93 (mapconcat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
94 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
95 (lambda (ref)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
96 (concat " <li> <a href=\"" ref "\"> "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
97 ref "</a></li>\n")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
98 qrefs "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
99 " </ol>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
100 " </p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
101 " <hr>\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
102 " <ul plain>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
103 " <li><a href=\"newspost:disfunctional\"> "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
104 "Post to this group </a></li>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
105 " <li><a href=\"mailto:" qfrom "\"> Reply to " qfrom
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
106 "</a></li>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
107 " </ul>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
108 " <hr>"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
109 " <pre>\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
110 (let ((s (buffer-substring (point) (point-max))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
111 (delete-region (point) (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
112 (insert (url-insert-entities-in-string s)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
113 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
114 (setq url-current-mime-type "text/html"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
115 url-current-mime-viewer (mm-mime-info url-current-mime-type nil 5))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
116 (let ((x (assoc "content-type" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
117 (if x
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
118 (setcdr x "text/html")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
119 (setq url-current-mime-headers (cons (cons "content-type"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
120 "text/html")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
121 url-current-mime-headers))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
122 (insert "\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
123 " </pre>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
124 " </div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
125 " </body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
126 "</html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
127 "<!-- Automatically generated by URL/" url-version
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
128 "-->"))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
129
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
130 (defun url-check-gnus-version ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
131 (require 'nntp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
132 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
133 (require 'gnus)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
134 (error (setq gnus-version "GNUS not found")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
135 (if (or (not (boundp 'gnus-version))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
136 (string-match "v5.[.0-9]+$" gnus-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
137 (string-match "Red" gnus-version))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
138 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
139 (url-warn 'url (concat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
140 "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
141 "not support the necessary functionality for the URL package.\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
142 "Please upgrade to version 5.x of GNUS. This is bundled by\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
143 "default with Emacs 19.30 and XEmacs 19.14 and later.\n\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144 "This version of GNUS is: " gnus-version "\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 (fset 'url-news 'url-news-version-too-old))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 (fset 'url-check-gnus-version 'ignore))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148 (defun url-news-version-too-old (article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149 (set-buffer (get-buffer-create url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150 (setq url-current-mime-headers '(("content-type" . "text/html"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 url-current-mime-type "text/html")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 (insert "<html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 " <head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
154 " <title>News Error</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155 " </head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 " <body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 " <h1>News Error - too old</h1>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
158 " <p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
159 " 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
160 " not support the necessary functionality for the URL package.\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
161 " Please upgrade to version 5.x of GNUS. This is bundled by\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
162 " default with Emacs 19.30 and XEmacs 19.14 and later.\n\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
163 " This version of GNUS is: " gnus-version "\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
164 " </p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
165 " </body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
166 "</html>\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
167
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
168 (defun url-news-open-host (host port user pass)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
169 (if (fboundp 'nnheader-init-server-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
170 (nnheader-init-server-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
171 (nntp-open-server host (list (string-to-int port)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
172 (if (and user pass)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
173 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
174 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" user)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
175 (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" pass)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
176 (if (not (nntp-server-opened host))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
177 (url-warn 'url (format "NNTP authentication to `%s' as `%s' failed"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
178 host user))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
179
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
180 (defun url-news-fetch-article-number (newsgroup article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
181 (nntp-request-group newsgroup)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
182 (nntp-request-article article))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
183
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
184 (defun url-news-fetch-message-id (host port message-id)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
185 (if (eq ?> (aref message-id (1- (length message-id))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
186 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
187 (setq message-id (concat "<" message-id ">")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
188 (if (nntp-request-article message-id)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
189 (url-format-news)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
190 (set-buffer (get-buffer-create url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
191 (setq url-current-can-be-cached nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
192 (insert "<html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
193 " <head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
194 " <title>Error</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
195 " </head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
196 " <body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
197 " <div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
198 " <h1>Error requesting article...</h1>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
199 " <p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
200 " The status message returned by the NNTP server was:"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
201 "<br><hr>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
202 " <xmp>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
203 (nntp-status-message)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
204 " </xmp>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
205 " </p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
206 " <p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
207 " If you If you feel this is an error, <a href=\""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
208 "mailto:" url-bug-address "\">send me mail</a>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
209 " </p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
210 " </div>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
211 " </body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
212 "</html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
213 "<!-- Automatically generated by URL v" url-version " -->\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
214 )))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
215
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
216 (defun url-news-fetch-newsgroup (newsgroup host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
217 (if (string-match "^/+" newsgroup)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
218 (setq newsgroup (substring newsgroup (match-end 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
219 (if (string-match "/+$" newsgroup)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
220 (setq newsgroup (substring newsgroup 0 (match-beginning 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
221
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
222 ;; This saves a bogus 'Untitled' buffer by Emacs-W3
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
223 (kill-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
224
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
225 ;; This saves us from checking new news if GNUS is already running
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
226 (if (or (not (get-buffer gnus-group-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
227 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
228 (set-buffer gnus-group-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
229 (not (eq major-mode 'gnus-group-mode))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
230 (gnus))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
231 (set-buffer gnus-group-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
232 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
233 (gnus-group-read-ephemeral-group newsgroup (list 'nntp host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
234 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
235 (cons (current-buffer) 'browse)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
236
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
237 (defun url-news (article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
238 ;; Find a news reference
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
239 (url-check-gnus-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
240 (let* ((urlobj (url-generic-parse-url article))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
241 (host (or (url-host urlobj) url-news-server))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
242 (port (or (url-port urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
243 (cdr-safe (assoc "news" url-default-ports))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
244 (article-brackets nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
245 (article (url-filename urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
246 (url-news-open-host host port (url-user urlobj) (url-password urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
247 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
248 ((string-match "@" article) ; Its a specific article
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
249 (url-news-fetch-message-id host port article))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
250 ((string= article "") ; List all newsgroups
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
251 (gnus)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
252 (kill-buffer url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
253 (t ; Whole newsgroup
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
254 (url-news-fetch-newsgroup article host)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
255
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
256 (defun url-nntp (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
257 ;; Find a news reference
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
258 (url-check-gnus-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
259 (let* ((urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
260 (host (or (url-host urlobj) url-news-server))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
261 (port (or (url-port urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
262 (cdr-safe (assoc "nntp" url-default-ports))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
263 (article-brackets nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
264 (article (url-filename urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
265 (url-news-open-host host port (url-user urlobj) (url-password urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
266 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
267 ((string-match "@" article) ; Its a specific article
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
268 (url-news-fetch-message-id host port article))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
269 ((string-match "/\\([0-9]+\\)$" article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
270 (url-news-fetch-article-number (substring article 0
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
271 (match-beginning 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
272 (match-string 1 article)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
273
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
274 ((string= article "") ; List all newsgroups
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
275 (gnus)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
276 (kill-buffer url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
277 (t ; Whole newsgroup
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
278 (url-news-fetch-newsgroup article)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
279
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
280 (provide 'url-news)