| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 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 |
|---|
| 36 |
"News related options." |
|---|
| 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)) |
|---|
| 42 |
(nntp-open-server host (list port)) |
|---|
| 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 |
|
|---|
| 58 |
nil |
|---|
| 59 |
(with-current-buffer buf |
|---|
| 60 |
(insert "Content-type: text/html\n\n" |
|---|
| 61 |
"<html>\n" |
|---|
| 62 |
" <head>\n" |
|---|
| 63 |
" <title>Error</title>\n" |
|---|
| 64 |
" </head>\n" |
|---|
| 65 |
" <body>\n" |
|---|
| 66 |
" <div>\n" |
|---|
| 67 |
" <h1>Error requesting article...</h1>\n" |
|---|
| 68 |
" <p>\n" |
|---|
| 69 |
" The status message returned by the NNTP server was:" |
|---|
| 70 |
"<br><hr>\n" |
|---|
| 71 |
" <xmp>\n" |
|---|
| 72 |
(nntp-status-message) |
|---|
| 73 |
" </xmp>\n" |
|---|
| 74 |
" </p>\n" |
|---|
| 75 |
" <p>\n" |
|---|
| 76 |
" If you If you feel this is an error, <a href=\"" |
|---|
| 77 |
"mailto:" url-bug-address "\">send mail</a>\n" |
|---|
| 78 |
" </p>\n" |
|---|
| 79 |
" </div>\n" |
|---|
| 80 |
" </body>\n" |
|---|
| 81 |
"</html>\n" |
|---|
| 82 |
"<!-- Automatically generated by URL v" url-version " -->\n" |
|---|
| 83 |
))) |
|---|
| 84 |
buf)) |
|---|
| 85 |
|
|---|
| 86 |
(defun url-news-fetch-newsgroup (newsgroup host) |
|---|
| 87 |
(declare (special gnus-group-buffer)) |
|---|
| 88 |
(if (string-match "^/+" newsgroup) |
|---|
| 89 |
(setq newsgroup (substring newsgroup (match-end 0)))) |
|---|
| 90 |
(if (string-match "/+$" newsgroup) |
|---|
| 91 |
(setq newsgroup (substring newsgroup 0 (match-beginning 0)))) |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
(if (or (not (get-buffer gnus-group-buffer)) |
|---|
| 96 |
(with-current-buffer gnus-group-buffer |
|---|
| 97 |
(not (eq major-mode 'gnus-group-mode)))) |
|---|
| 98 |
(gnus)) |
|---|
| 99 |
(set-buffer gnus-group-buffer) |
|---|
| 100 |
(goto-char (point-min)) |
|---|
| 101 |
(gnus-group-read-ephemeral-group newsgroup |
|---|
| 102 |
(list 'nntp host |
|---|
| 103 |
(list 'nntp-open-connection-function |
|---|
| 104 |
nntp-open-connection-function)) |
|---|
| 105 |
nil |
|---|
| 106 |
(cons (current-buffer) 'browse))) |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
(defun url-news (url) |
|---|
| 110 |
|
|---|
| 111 |
(let* ((host (or (url-host url) url-news-server)) |
|---|
| 112 |
(port (url-port url)) |
|---|
| 113 |
(article-brackets nil) |
|---|
| 114 |
(buf nil) |
|---|
| 115 |
(article (url-unhex-string (url-filename url)))) |
|---|
| 116 |
(url-news-open-host host port (url-user url) (url-password url)) |
|---|
| 117 |
(cond |
|---|
| 118 |
((string-match "@" article) |
|---|
| 119 |
(setq buf (url-news-fetch-message-id host article))) |
|---|
| 120 |
((string= article "") |
|---|
| 121 |
(gnus)) |
|---|
| 122 |
(t |
|---|
| 123 |
(url-news-fetch-newsgroup article host))) |
|---|
| 124 |
buf)) |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
(defun url-snews (url) |
|---|
| 128 |
(let ((nntp-open-connection-function (if (eq 'ssl url-gateway-method) |
|---|
| 129 |
'nntp-open-ssl-stream |
|---|
| 130 |
'nntp-open-tls-stream))) |
|---|
| 131 |
(url-news url))) |
|---|
| 132 |
|
|---|
| 133 |
(provide 'url-news) |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|