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