Gnus development mailing list
 help / color / mirror / Atom feed
* mml-attach-file: Argument TYPE is not optional
@ 2005-07-26 14:22 Reiner Steib
  2005-07-27  1:37 ` Katsumi Yamaoka
  0 siblings, 1 reply; 2+ messages in thread
From: Reiner Steib @ 2005-07-26 14:22 UTC (permalink / raw)


Hi,

the doc string of `mml-attach-file' says that TYPE is optional:

,----[ C-h f mml-attach-file RET ]
| mml-attach-file is an interactive Lisp function in `mml.el'.
| It is bound to <menu-bar> <Attachments> <Attach File...>, C-c RET f, C-c C-a.
| (mml-attach-file FILE &optional TYPE DESCRIPTION DISPOSITION)
| 
| Attach a file to the outgoing MIME message.
| The file is not inserted or encoded until you send the message with
| `C-c C-c' or `C-c C-s'.
| 
| FILE is the name of the file to attach.  TYPE is its content-type, a
| string of the form "type/subtype".  DESCRIPTION is a one-line
| description of the attachment.
`----

After evaluating (mml-attach-file "/tmp/ste/gnus/test-file-1.txt") in
a message buffer, I get:

| <# part filename="/tmp/ste/gnus/test-file-1.txt" disposition=attachment>
| <# /part>

Note: type="text/plain" is not specified.

When sending the message, I get the backtrace listed below[1].

I'm not sure about the best way to fix this problem:

(1) Make TYPE in `mml-attach-file' mandatory.

(2) Set Content-Type in `mml-generate-mime-1' appropriately if no
    type=".../..." is specified.

Patch for solution (2):

--8<---------------cut here---------------start------------->8---
--- mml.el	22 Jul 2005 18:49:24 +0200	6.88.2.10
+++ mml.el	26 Jul 2005 15:50:11 +0200	
@@ -518,7 +518,11 @@
 	    (mml-insert-parameter-string
 	     cont '(expiration size permission))))
 	(insert "\n\n")
-	(insert "Content-Type: " (cdr (assq 'type cont)) "\n")
+	(insert "Content-Type: "
+		(or (cdr (assq 'type cont))
+		    (and name (mm-default-file-encoding name))
+		    "application/octet-stream")
+		"\n")
 	(insert "Content-ID: " (message-make-message-id) "\n")
 	(insert "Content-Transfer-Encoding: "
 		(or (cdr (assq 'encoding cont)) "binary"))
--8<---------------cut here---------------end--------------->8---

Opinions?  Unless there are other suggestion, I'll install (2).

Bye, Reiner.

[1] Backtrace (probably you need to specify a Gcc group and set
    gnus-gcc-externalize-attachments to 'all to reproduce the problem):

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument char-or-string-p nil)
  insert("Content-Type: " nil "\n")
  (cond ((or ... ...) (let ... ... ...)) ((eq ... ...) (insert "Content-Type: message/external-body") (let ... ... ... ...) (insert "\n\n") (insert "Content-Type: " ... "\n") (insert "Content-ID: " ... "\n") (insert "Content-Transfer-Encoding: " ...) (insert "\n\n") (insert ...) (insert "\n")) ((eq ... ...) (let* ... ...)) (t (error "Invalid element: %S" cont)))
  (save-restriction (narrow-to-region (point) (point)) (mml-tweak-part cont) (cond (... ...) (... ... ... ... ... ... ... ... ... ...) (... ...) (t ...)) (let (... ... sender recipients) (when ... ... ... ...)))
  (let ((mm-use-ultra-safe-encoding ...)) (save-restriction (narrow-to-region ... ...) (mml-tweak-part cont) (cond ... ... ... ...) (let ... ...)))
  mml-generate-mime-1((external (name . "/tmp/ste/gnus/test-file-1.txt") (disposition . "attachment") (tag-location . 639) (contents . "")))
  (progn (insert "\n--" mml-boundary "\n") (mml-generate-mime-1 part))
  (if (and (consp part) (consp ...)) (progn (insert "\n--" mml-boundary "\n") (mml-generate-mime-1 part)))
  (when (and (consp part) (consp ...)) (insert "\n--" mml-boundary "\n") (mml-generate-mime-1 part))
  (while (setq part (pop cont)) (when (and ... ...) (insert "\n--" mml-boundary "\n") (mml-generate-mime-1 part)))
  (let ((cont cont) part) (while (setq part ...) (when ... ... ...)))
  (let ((mml-boundary ...)) (insert (format "Content-Type: multipart/%s; boundary=\"%s\"" type mml-boundary) (if ... ... "\n")) (let (... part) (while ... ...)) (insert "\n--" mml-boundary "--\n"))
  (if handler (funcall (cdr handler) cont) (let (...) (insert ... ...) (let ... ...) (insert "\n--" mml-boundary "--\n")))
  (let* ((type ...) (mml-generate-default-type ...) (handler ...)) (if handler (funcall ... cont) (let ... ... ... ...)))
  (cond ((or ... ...) (let ... ... ...)) ((eq ... ...) (insert "Content-Type: message/external-body") (let ... ... ... ...) (insert "\n\n") (insert "Content-Type: " ... "\n") (insert "Content-ID: " ... "\n") (insert "Content-Transfer-Encoding: " ...) (insert "\n\n") (insert ...) (insert "\n")) ((eq ... ...) (let* ... ...)) (t (error "Invalid element: %S" cont)))
  (save-restriction (narrow-to-region (point) (point)) (mml-tweak-part cont) (cond (... ...) (... ... ... ... ... ... ... ... ... ...) (... ...) (t ...)) (let (... ... sender recipients) (when ... ... ... ...)))
  (let ((mm-use-ultra-safe-encoding ...)) (save-restriction (narrow-to-region ... ...) (mml-tweak-part cont) (cond ... ... ... ...) (let ... ...)))
  mml-generate-mime-1((multipart (type . "mixed") (part (type . "text/plain") (contents . "(mml-attach-file \"/tmp/ste/gnus/test-file-1.txt\")\n\n| < #part filename=\"/tmp/ste/gnus/test-file-1.txt\" disposition=attachment>\n| < #/part>\n\n")) (external (name . "/tmp/ste/gnus/test-file-1.txt") (disposition . "attachment") (tag-location . 639) (contents . ""))))
  (if (and (consp ...) (= ... 1)) (mml-generate-mime-1 (car cont)) (mml-generate-mime-1 (nconc ... cont)))
  (save-current-buffer (set-buffer temp-buffer) (if (and ... ...) (mml-generate-mime-1 ...) (mml-generate-mime-1 ...)) (buffer-string))
  (with-current-buffer temp-buffer (if (and ... ...) (mml-generate-mime-1 ...) (mml-generate-mime-1 ...)) (buffer-string))
  (unwind-protect (with-current-buffer temp-buffer (if ... ... ...) (buffer-string)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
  (let ((temp-buffer ...)) (unwind-protect (with-current-buffer temp-buffer ... ...) (and ... ...)))
  (with-temp-buffer (if (and ... ...) (mml-generate-mime-1 ...) (mml-generate-mime-1 ...)) (buffer-string))
  (if (not cont) nil (with-temp-buffer (if ... ... ...) (buffer-string)))
  (let ((cont ...) (mml-multipart-number mml-multipart-number)) (if (not cont) nil (with-temp-buffer ... ...)))
  mml-generate-mime()
  message-encode-message-body()
  gnus-inews-do-gcc()
  run-hooks(message-sent-hook)
  message-send(nil)
  message-send-and-exit(nil)
  call-interactively(message-send-and-exit)
--8<---------------cut here---------------end--------------->8---




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mml-attach-file: Argument TYPE is not optional
  2005-07-26 14:22 mml-attach-file: Argument TYPE is not optional Reiner Steib
@ 2005-07-27  1:37 ` Katsumi Yamaoka
  0 siblings, 0 replies; 2+ messages in thread
From: Katsumi Yamaoka @ 2005-07-27  1:37 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1370 bytes --]

>>>>> In <v9ack9lkaa.fsf@marauder.physik.uni-ulm.de> Reiner Steib wrote:

> the doc string of `mml-attach-file' says that TYPE is optional:

And also for `mml-attach-external'.

[...]

> After evaluating (mml-attach-file "/tmp/ste/gnus/test-file-1.txt") in
> a message buffer, I get:

>| <# part filename="/tmp/ste/gnus/test-file-1.txt" disposition=attachment>
>| <# /part>

> Note: type="text/plain" is not specified.

It is the same in the case where `mml-attach-external' is used.

> When sending the message, I get the backtrace listed below[1].

Aren't you talking about `mml-attach-external'?  Though I couldn't
reproduce the error because the type defaults to text/plain for the <#
part ...>s internally in `mml-generate-mime-1', I think it isn't good
that Gnus doesn't add the Content-Type MIME header to the part anyway,
and the default type should be application/octet-stream if it cannot
be guessed.

> I'm not sure about the best way to fix this problem:

> (1) Make TYPE in `mml-attach-file' mandatory.

> (2) Set Content-Type in `mml-generate-mime-1' appropriately if no
>     type=".../..." is specified.

> Patch for solution (2):

[...]

> Opinions?  Unless there are other suggestion, I'll install (2).

I vote to (2).  Here're patches for the v5-10 branch and for the
trunk, which enable to add the Content-Type header for the <#
part ...>s as well.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v5-10.patch --]
[-- Type: text/x-patch, Size: 3055 bytes --]

--- mml.el~	2005-07-24 21:54:30 +0000
+++ mml.el	2005-07-27 01:34:21 +0000
@@ -400,9 +400,12 @@
       (mml-tweak-part cont)
       (cond
        ((or (eq (car cont) 'part) (eq (car cont) 'mml))
-	(let ((raw (cdr (assq 'raw cont)))
-	      coded encoding charset filename type flowed)
-	  (setq type (or (cdr (assq 'type cont)) "text/plain"))
+	(let* ((raw (cdr (assq 'raw cont)))
+	       (filename (cdr (assq 'filename cont)))
+	       (type (or (cdr (assq 'type cont))
+			 (and filename (mm-default-file-encoding filename))
+			 "application/octet-stream"))
+	       coded encoding charset flowed)
 	  (if (and (not raw)
 		   (member (car (split-string type "/")) '("text" "message")))
 	      (progn
@@ -414,7 +417,7 @@
 		  (cond
 		   ((cdr (assq 'buffer cont))
 		    (insert-buffer-substring (cdr (assq 'buffer cont))))
-		   ((and (setq filename (cdr (assq 'filename cont)))
+		   ((and filename
 			 (not (equal (cdr (assq 'nofile cont)) "yes")))
 		    (let ((coding-system-for-read charset))
 		      (mm-insert-file-contents filename)))
@@ -475,7 +478,7 @@
 		(insert (with-current-buffer (cdr (assq 'buffer cont))
 			  (mm-with-unibyte-current-buffer
 			    (buffer-string)))))
-	       ((and (setq filename (cdr (assq 'filename cont)))
+	       ((and filename
 		     (not (equal (cdr (assq 'nofile cont)) "yes")))
 		(let ((coding-system-for-read mm-binary-coding-system))
 		  (mm-insert-file-contents filename nil nil nil nil t)))
@@ -516,15 +519,19 @@
 	     "access-type=url"))
 	  (when parameters
 	    (mml-insert-parameter-string
-	     cont '(expiration size permission))))
-	(insert "\n\n")
-	(insert "Content-Type: " (cdr (assq 'type cont)) "\n")
-	(insert "Content-ID: " (message-make-message-id) "\n")
-	(insert "Content-Transfer-Encoding: "
-		(or (cdr (assq 'encoding cont)) "binary"))
-	(insert "\n\n")
-	(insert (or (cdr (assq 'contents cont))))
-	(insert "\n"))
+	     cont '(expiration size permission)))
+	  (insert "\n\n")
+	  (insert "Content-Type: "
+		  (or (cdr (assq 'type cont))
+		      (and name (mm-default-file-encoding name))
+		      "application/octet-stream")
+		  "\n")
+	  (insert "Content-ID: " (message-make-message-id) "\n")
+	  (insert "Content-Transfer-Encoding: "
+		  (or (cdr (assq 'encoding cont)) "binary"))
+	  (insert "\n\n")
+	  (insert (or (cdr (assq 'contents cont))))
+	  (insert "\n")))
        ((eq (car cont) 'multipart)
 	(let* ((type (or (cdr (assq 'type cont)) "mixed"))
 	       (mml-generate-default-type (if (equal type "digest")
@@ -560,7 +567,8 @@
 	    (message-options-set 'message-sender sender))
 	  (if (setq recipients (cdr (assq 'recipients cont)))
 	      (message-options-set 'message-recipients recipients))
-	  (let ((style (mml-signencrypt-style (first (or sign-item encrypt-item)))))
+	  (let ((style (mml-signencrypt-style
+			(first (or sign-item encrypt-item)))))
 	    ;; check if: we're both signing & encrypting, both methods
 	    ;; are the same (why would they be different?!), and that
 	    ;; the signencrypt style allows for combined operation.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: trunk.patch --]
[-- Type: text/x-patch, Size: 2669 bytes --]

--- mml.el~	2005-07-24 21:50:41 +0000
+++ mml.el	2005-07-27 01:34:21 +0000
@@ -404,11 +404,14 @@
       (mml-tweak-part cont)
       (cond
        ((or (eq (car cont) 'part) (eq (car cont) 'mml))
-	(let ((raw (cdr (assq 'raw cont)))
-	      type charset coding filename encoding flowed coded)
-	  (setq type (or (cdr (assq 'type cont)) "text/plain")
-		charset (cdr (assq 'charset cont))
-		coding (mm-charset-to-coding-system charset))
+	(let* ((raw (cdr (assq 'raw cont)))
+	       (filename (cdr (assq 'filename cont)))
+	       (type (or (cdr (assq 'type cont))
+			 (and filename (mm-default-file-encoding filename))
+			 "application/octet-stream"))
+	       (charset (cdr (assq 'charset cont)))
+	       (coding (mm-charset-to-coding-system charset))
+	       encoding flowed coded)
 	  (cond ((eq coding 'ascii)
 		 (setq charset nil
 		       coding nil))
@@ -421,7 +424,7 @@
 		  (cond
 		   ((cdr (assq 'buffer cont))
 		    (insert-buffer-substring (cdr (assq 'buffer cont))))
-		   ((and (setq filename (cdr (assq 'filename cont)))
+		   ((and filename
 			 (not (equal (cdr (assq 'nofile cont)) "yes")))
 		    (let ((coding-system-for-read coding))
 		      (mm-insert-file-contents filename)))
@@ -482,7 +485,7 @@
 		(insert (with-current-buffer (cdr (assq 'buffer cont))
 			  (mm-with-unibyte-current-buffer
 			    (buffer-string)))))
-	       ((and (setq filename (cdr (assq 'filename cont)))
+	       ((and filename
 		     (not (equal (cdr (assq 'nofile cont)) "yes")))
 		(let ((coding-system-for-read mm-binary-coding-system))
 		  (mm-insert-file-contents filename nil nil nil nil t))
@@ -527,15 +530,19 @@
 	     "access-type=url"))
 	  (when parameters
 	    (mml-insert-parameter-string
-	     cont '(expiration size permission))))
-	(insert "\n\n")
-	(insert "Content-Type: " (cdr (assq 'type cont)) "\n")
-	(insert "Content-ID: " (message-make-message-id) "\n")
-	(insert "Content-Transfer-Encoding: "
-		(or (cdr (assq 'encoding cont)) "binary"))
-	(insert "\n\n")
-	(insert (or (cdr (assq 'contents cont))))
-	(insert "\n"))
+	     cont '(expiration size permission)))
+	  (insert "\n\n")
+	  (insert "Content-Type: "
+		  (or (cdr (assq 'type cont))
+		      (and name (mm-default-file-encoding name))
+		      "application/octet-stream")
+		  "\n")
+	  (insert "Content-ID: " (message-make-message-id) "\n")
+	  (insert "Content-Transfer-Encoding: "
+		  (or (cdr (assq 'encoding cont)) "binary"))
+	  (insert "\n\n")
+	  (insert (or (cdr (assq 'contents cont))))
+	  (insert "\n")))
        ((eq (car cont) 'multipart)
 	(let* ((type (or (cdr (assq 'type cont)) "mixed"))
 	       (mml-generate-default-type (if (equal type "digest")

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-07-27  1:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-26 14:22 mml-attach-file: Argument TYPE is not optional Reiner Steib
2005-07-27  1:37 ` Katsumi Yamaoka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).