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