From: Lars Ingebrigtsen Date: Sun, 2 Oct 2022 12:58:25 +0000 (+0200) Subject: Fix coding system problems in gnus-read-ephemeral-bug-group X-Git-Tag: emacs-29.0.90~1856^2~80 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4efb2ef57237147111de90781755f666b3cb9bdd;p=emacs.git Fix coding system problems in gnus-read-ephemeral-bug-group * lisp/gnus/gnus-group.el (gnus-read-ephemeral-bug-group): Don't bind coding system variables, because that leads to loading other files (like cookie files) using that coding system (bug#58227). * lisp/url/url-handlers.el (url-insert-file-literally): New function. (url-insert): Allow forcing no-decode. --- diff --git a/lisp/gnus/gnus-group.el b/lisp/gnus/gnus-group.el index d1098be6fd3..35103e9c4f4 100644 --- a/lisp/gnus/gnus-group.el +++ b/lisp/gnus/gnus-group.el @@ -2421,44 +2421,37 @@ the ephemeral group." (regexp-quote address) "\\(?:\\'\\|[ ,>]\\)")) (delim (concat "^" message-unix-mail-delimiter))) - (let ((coding-system-for-write 'binary) - (coding-system-for-read 'binary)) - (with-temp-file tmpfile - (mm-disable-multibyte) - (dolist (id ids) - (let ((file (expand-file-name id (locate-user-emacs-file - "debbugs-cache")))) - (if (and (not gnus-plugged) - (file-exists-p file)) - (insert-file-contents file) - ;; Pass non-nil VISIT to avoid errors with non-nil - ;; `url-automatic-caching' (bug#26063, bug#29008) - ;; and immediately unvisit. - ;; FIXME: This masks real errors! - (url-insert-file-contents (format mbox-url id) t) - (setq buffer-file-name nil)))) - (goto-char (point-min)) - ;; Throw an informative error early instead of passing nonsense - ;; to `gnus-group-read-ephemeral-group' (bug#36433). - (unless (save-excursion (re-search-forward delim nil t)) - (error "Invalid mbox format for bug IDs: %s" - (string-join ids ", "))) - (while (re-search-forward delim nil t) - (narrow-to-region (point) - (if (search-forward "\n\n" nil t) - (1- (point)) - (point-max))) - (unless (string-match-p address-re - (concat (message-fetch-field "to") " " - (message-fetch-field "cc"))) - (goto-char (point-min)) - (if (not (re-search-forward "^To:" nil t)) - (insert "To: " address "\n") - (message-next-header) - (skip-chars-backward "\t\n ") - (insert ", " address))) - (goto-char (point-max)) - (widen)))) + (with-temp-file tmpfile + (mm-disable-multibyte) + (dolist (id ids) + (let ((file (expand-file-name id (locate-user-emacs-file + "debbugs-cache")))) + (if (and (not gnus-plugged) + (file-exists-p file)) + (insert-file-contents-literally file) + (url-insert-file-contents-literally (format mbox-url id))))) + (goto-char (point-min)) + ;; Throw an informative error early instead of passing nonsense + ;; to `gnus-group-read-ephemeral-group' (bug#36433). + (unless (save-excursion (re-search-forward delim nil t)) + (error "Invalid mbox format for bug IDs: %s" + (string-join ids ", "))) + (while (re-search-forward delim nil t) + (narrow-to-region (point) + (if (search-forward "\n\n" nil t) + (1- (point)) + (point-max))) + (unless (string-match-p address-re + (concat (message-fetch-field "to") " " + (message-fetch-field "cc"))) + (goto-char (point-min)) + (if (not (re-search-forward "^To:" nil t)) + (insert "To: " address "\n") + (message-next-header) + (skip-chars-backward "\t\n ") + (insert ", " address))) + (goto-char (point-max)) + (widen))) (gnus-group-read-ephemeral-group (concat "nndoc+ephemeral:bug#" (string-join ids ",")) `(nndoc ,tmpfile diff --git a/lisp/url/url-handlers.el b/lisp/url/url-handlers.el index 74f77cd2383..b66c187c547 100644 --- a/lisp/url/url-handlers.el +++ b/lisp/url/url-handlers.el @@ -302,11 +302,13 @@ accessible." filename)) (put 'file-local-copy 'url-file-handlers #'url-file-local-copy) -(defun url-insert (buffer &optional beg end) +(defun url-insert (buffer &optional beg end inhibit-decode) "Insert the body of a URL object. BUFFER should be a complete URL buffer as returned by `url-retrieve'. If the headers specify a coding-system (and current buffer is multibyte), -it is applied to the body before it is inserted. +it is applied to the body before it is inserted. If INHIBIT-DECODE is +non-nil, don't do any coding system decoding even in multibyte buffers. + Returns a list of the form (SIZE CHARSET), where SIZE is the size in bytes of the inserted text and CHARSET is the charset that was specified in the header, or nil if none was found. @@ -318,7 +320,8 @@ They count bytes from the beginning of the body." (buffer-substring (+ (point-min) beg) (if end (+ (point-min) end) (point-max))) (buffer-string)))) - (charset (if enable-multibyte-characters + (charset (if (and enable-multibyte-characters + (not inhibit-decode)) (mail-content-type-get (mm-handle-type handle) 'charset)))) (mm-destroy-parts handle) @@ -362,6 +365,14 @@ if it had been inserted from a file named URL." (url-insert-buffer-contents buffer url visit beg end replace))) (put 'insert-file-contents 'url-file-handlers #'url-insert-file-contents) +;;;###autoload +(defun url-insert-file-contents-literally (url) + "Insert the data retrieved from URL literally in the current buffer." + (let ((buffer (url-retrieve-synchronously url))) + (unless buffer + (signal 'file-error (list url "No Data"))) + (url-insert buffer nil nil t))) + (defun url-file-name-completion (url _directory &optional _predicate) ;; Even if it's not implemented, it's not an error to ask for completion, ;; in case it's available (bug#14806).