Subject: Re: bug#62815: Gnus: MIME types of attachments contain regexp quotation

From: Andrew Cohen <[email-masked]>
Date: Sun, 23 Apr 2023 10:43:27 +0800

>>>>> "EZ" == Eli Zaretskii <[email-masked]> writes:

    EZ> Andrew, perhaps you could look into this some time soon?  It
    EZ> sounds like a recent regression, so I'd like to fix this in
    EZ> Emacs 29.

(I've added Arash Esbati who filed the original bug that this commit was
intended to fix, and Andreas since I think he understands mime handling
in gnus and can probably comment.)

I have taken a quick look and think I understand what is going on, but
I'm not positive. The mailcap-mime-data can include a regexp for the
subtype; it appears that the only circumstance in which it is used as a
regexp is matching the possible viewer to be used for this subtype.

The patch in commit 3faa508eba84a1983732099cbd3cc1eaad404158 also treats
mailcap-mime-extensions as regexps, which I think is a mistake: these
should be associations between mime types and file extensions.

If all this is right, the simple fix is to revert the part of
3faa508eba84a1983732099cbd3cc1eaad404158 that treated the extension data
as regexps.  I have attached a diff below that does this. If Torsten
and Arash can check if this continues to provide a fix for bug#52038 and
bug#62815 that would be great!

There is one more place I think needs fixing (and maybe others I haven't
spotted yet):  the function mailcap-mime-types returns a list of mime
types, and excludes any type that contains a wildcard:
(unless (string-search "*" type) (push type res))
which suggests that this should be a list of actual types and not
include regexps. Hence we should remove any regexp quoting from the
entries. I have included a line that removes the "\\" in the diff.

diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el
index 10c5a7744c1..b8990266069 100644
--- a/lisp/net/mailcap.el
+++ b/lisp/net/mailcap.el
@@ -979,7 +979,7 @@ mailcap-mime-extensions
     (".vox"   . "audio/basic")
     (".vrml"  . "x-world/x-vrml")
     (".wav"   . "audio/x-wav")
-    (".xls"   . "application/vnd\\.ms-excel")
+    (".xls"   . "application/vnd.ms-excel")
     (".wrl"   . "x-world/x-vrml")
     (".xbm"   . "image/xbm")
     (".xpm"   . "image/xpm")
@@ -1051,8 +1051,7 @@ mailcap-parse-mimetype-file
 	(setq save-pos (point))
 	(skip-chars-forward "^ \t\n")
 	(downcase-region save-pos (point))
-	(setq type (mailcap--regexp-quote-type
-                    (buffer-substring save-pos (point))))
+	(setq type (buffer-substring save-pos (point)))
 	(while (not (eolp))
 	  (skip-chars-forward " \t")
 	  (setq save-pos (point))
@@ -1107,7 +1106,7 @@ mailcap-mime-types
         (dolist (info (cdr data))
           (setq type (cdr (assq 'type (cdr info))))
           (unless (string-search "*" type)
-            (push type res))))
+            (push (string-replace "\\" "" type) res))))
       (nreverse res)))))
 
 ;;;

-- 
Andrew Cohen