]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix coding system problems in gnus-read-ephemeral-bug-group
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 2 Oct 2022 12:58:25 +0000 (14:58 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 2 Oct 2022 13:50:02 +0000 (15:50 +0200)
* 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.

lisp/gnus/gnus-group.el
lisp/url/url-handlers.el

index d1098be6fd3a305dc332636cd3f740ced56b12af..35103e9c4f45148873ca9407199e77c2607550d2 100644 (file)
@@ -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
index 74f77cd2383c080c8bb63241b6557168c59ca9d7..b66c187c5472e737178ce9422b8ba05d8ca231a0 100644 (file)
@@ -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).