From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/64337 Path: news.gmane.org!not-for-mail From: Katsumi Yamaoka Newsgroups: gmane.emacs.gnus.general Subject: Re: default mime for attaching files Date: Mon, 19 Feb 2007 21:22:00 +0900 Organization: Emacsen advocacy group Message-ID: References: <87zm7op2y1.fsf@patagonia.sebmags.homelinux.org> <87lkj7q506.fsf@patagonia.sebmags.homelinux.org> <878xewfiue.fsf@patagonia.sebmags.homelinux.org> <877iug6szc.fsf@catnip.gol.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1171887816 28634 80.91.229.12 (19 Feb 2007 12:23:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 19 Feb 2007 12:23:36 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M12861@lists.math.uh.edu Mon Feb 19 13:23:30 2007 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1HJ7YG-0004IT-O9 for ding-account@gmane.org; Mon, 19 Feb 2007 13:23:29 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1HJ7X8-0004Qk-0e; Mon, 19 Feb 2007 06:22:18 -0600 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1HJ7X6-0004QS-8K for ding@lists.math.uh.edu; Mon, 19 Feb 2007 06:22:16 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtp (Exim 4.63) (envelope-from ) id 1HJ7Wz-0000S9-Gk for ding@lists.math.uh.edu; Mon, 19 Feb 2007 06:22:16 -0600 Original-Received: from orlando.hostforweb.net ([216.246.45.90]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1HJ7Wy-0004tK-00 for ; Mon, 19 Feb 2007 13:22:08 +0100 Original-Received: from [66.225.201.151] (port=42609 helo=mail.jpl.org) by orlando.hostforweb.net with esmtpa (Exim 4.63) (envelope-from ) id 1HJ7Ww-0005aY-9c for ding@gnus.org; Mon, 19 Feb 2007 06:22:06 -0600 X-Hashcash: 1:20:070219:ding@gnus.org::BAp2/pFIZN4zW/4f:00001dOH X-Face: #kKnN,xUnmKia.'[pp`;Omh}odZK)?7wQSl"4o04=EixTF+V[""w~iNbM9ZL+.b*_CxUmFk B#Fu[*?MZZH@IkN:!"\w%I_zt>[$nm7nQosZ<3eu;B:$Q_:p!',P.c0-_Cy[dz4oIpw0ESA^D*1Lw= L&i*6&( User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.93 (gnu/linux) Cancel-Lock: sha1:UL6feH69RAR8Z/mXMkuOcaLm6ww= X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - orlando.hostforweb.net X-AntiAbuse: Original Domain - gnus.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - jpl.org X-Source: X-Source-Args: X-Source-Dir: X-Spam-Score: -2.5 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:64337 Archived-At: --=-=-= >>>>> In <877iug6szc.fsf@catnip.gol.com> Miles Bader wrote: > Katsumi Yamaoka writes: >> By default, Gnus uses the "inline" disposition for an attachment of >> which the MIME type is text/* except text/rtf[1]. So, the reason >> seems to be that the text/* MIME type is specified in your system >> for *.csv files. You know how to customize it already. ;-) > Actually I've always thought that this behavior of Gnus was sort of dumb > -- I don't think it really makes sense to inline random text/ sub-types. > Glancing through the list of text/ sub-types in /etc/mime.types, most > look like the sort of thing I wouldn't want inline; in practice I also > find that I usually have to override the default (the one which annoys > most often is text/x-diff). > Instead I think Gnus should default to "attach", and have a list of > text/ sub-types which _should_ be inlined (bonus for making it a real > configurable list, not hardwired in the code...). I made such one for a trial. Is this worth implementing in Gnus? --8<---------------cut here---------------start------------->8--- mml-content-disposition-alist is a variable defined in `mml.el'. Its value is ((text (rtf . "attachment") (t . "inline")) (t . "attachment")) Documentation: Alist of MIME types or regexps matching file names and default dispositions. Each element should be one of the following three forms: (REGEXP . DISPOSITION) (TYPE (SUBTYPE . DISPOSITION) (SUBTYPE . DISPOSITION)...) (TYPE . DISPOSITION) Where REGEXP is a string which matches the file name (if any) of an attachment, TYPE is a MIME type and SUBTYPE is a MIME subtype of an attachment, and DISPOSITION should be either "attachment" or "inline". The value t for TYPE or SUBTYPE matches any MIME types or MIME subtypes. The first match found will be used. --8<---------------cut here---------------end--------------->8--- I did set the default value so as not to change the present behavior of Gnus. For instance, Sebastian may want to use the following: --8<---------------cut here---------------start------------->8--- (add-to-list 'mml-content-disposition-alist '("\\.csv\\'" . "attachment")) --8<---------------cut here---------------end--------------->8--- Here's a patch to the Gnus CVS trunk: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment --- mml.el~ 2007-01-24 07:13:23 +0000 +++ mml.el 2007-02-19 12:19:12 +0000 @@ -70,6 +70,51 @@ :type '(repeat (symbol :tag "Parameter")) :group 'message) +(defcustom mml-content-disposition-alist + '((text (rtf . "attachment") (t . "inline")) + (t . "attachment")) + "Alist of MIME types or regexps matching file names and default dispositions. +Each element should be one of the following three forms: + + (REGEXP . DISPOSITION) + (TYPE (SUBTYPE . DISPOSITION) (SUBTYPE . DISPOSITION)...) + (TYPE . DISPOSITION) + +Where REGEXP is a string which matches the file name (if any) of an +attachment, TYPE is a MIME type and SUBTYPE is a MIME subtype of an +attachment, and DISPOSITION should be either \"attachment\" or \"inline\". +The value t for TYPE or SUBTYPE matches any MIME types or MIME +subtypes. The first match found will be used." + :version "23.0" ;; No Gnus + :type (let ((dispositions '(radio :format "DISPOSITION: %v" + :value "attachment" + (const :format "\"%v\" " "attachment") + (const :format "\"%v\" " "inline") + (const :format "\"\"\n" "")))) + `(repeat + :offset 0 + (choice :format "%[Value Menu%]%v" + (cons :tag "(REGEXP . DISPOSITION)" + :extra-offset 4 + (regexp :tag "REGEXP" :value ".*") + ,dispositions) + (cons :tag "(TYPE (SUBTYPE . DISPOSITION)...)" + :indent 0 + (symbol :tag " TYPE" :value text) + (repeat :format "%v%i\n" + :extra-offset 4 + :offset 0 + (cons :format "%v" + :extra-offset 5 + (symbol :tag "SUBTYPE" + :value t) + ,dispositions))) + (cons :tag "(TYPE . DISPOSITION)" + :extra-offset 4 + (symbol :tag "TYPE" :value t) + ,dispositions)))) + :group 'message) + (defcustom mml-insert-mime-headers-always nil "If non-nil, always put Content-Type: text/plain at top of empty parts. It is necessary to work against a bug in certain clients." @@ -667,6 +712,30 @@ "") mml-base-boundary)) +(defun mml-content-disposition (type &optional filename) + "Return a default disposition name suitable to TYPE or FILENAME." + (let ((defs mml-content-disposition-alist) + disposition def types) + (while (and (not disposition) defs) + (setq def (pop defs)) + (cond ((stringp (car def)) + (when (and filename + (string-match (car def) filename)) + (setq disposition (cdr def)))) + ((consp (cdr def)) + (when (string= (car (setq types (split-string type "/"))) + (car def)) + (setq type (cadr types) + types (cdr def)) + (while (and (not disposition) types) + (setq def (pop types)) + (when (or (eq (car def) t) (string= type (car def))) + (setq disposition (cdr def)))))) + (t + (when (or (eq (car def) t) (string= type (car def))) + (setq disposition (cdr def)))))) + disposition)) + (defun mml-insert-mime-headers (cont type charset encoding flowed) (let (parameters id disposition description) (setq parameters @@ -697,7 +766,9 @@ cont mml-content-disposition-parameters)) (when (or (setq disposition (cdr (assq 'disposition cont))) parameters) - (insert "Content-Disposition: " (or disposition "inline")) + (insert "Content-Disposition: " + (or disposition + (mml-content-disposition type (cdr (assq 'filename cont))))) (when parameters (mml-insert-parameter-string cont mml-content-disposition-parameters)) @@ -1056,16 +1127,13 @@ (setq description nil)) description)) -(defun mml-minibuffer-read-disposition (type &optional default) - (unless default (setq default - (if (and (string-match "\\`text/" type) - (not (string-match "\\`text/rtf\\'" type))) - "inline" - "attachment"))) +(defun mml-minibuffer-read-disposition (type &optional default filename) + (unless default + (setq default (mml-content-disposition type filename))) (let ((disposition (completing-read - (format "Disposition (default %s): " default) - '(("attachment") ("inline") ("")) - nil t nil nil default))) + (format "Disposition (default %s): " default) + '(("attachment") ("inline") ("")) + nil t nil nil default))) (if (not (equal disposition "")) disposition default))) @@ -1157,7 +1225,7 @@ (let* ((file (mml-minibuffer-read-file "Attach file: ")) (type (mml-minibuffer-read-type file)) (description (mml-minibuffer-read-description)) - (disposition (mml-minibuffer-read-disposition type))) + (disposition (mml-minibuffer-read-disposition type nil file))) (list file type description disposition))) (save-excursion (unless (message-in-body-p) (goto-char (point-max))) @@ -1188,7 +1256,7 @@ (when (memq 'description mml-dnd-attach-options) (setq description (mml-minibuffer-read-description))) (when (memq 'disposition mml-dnd-attach-options) - (setq disposition (mml-minibuffer-read-disposition type))) + (setq disposition (mml-minibuffer-read-disposition type nil file))) (mml-attach-file file type description disposition))))) (defun mml-attach-buffer (buffer &optional type description) --=-=-=--