Parse malformed multipart parts as application/octet-stream, not by
authorTaylor R. Campbell <net/mumble/campbell>
Tue, 3 Feb 2009 01:42:10 +0000 (01:42 +0000)
committerTaylor R. Campbell <net/mumble/campbell>
Tue, 3 Feb 2009 01:42:10 +0000 (01:42 +0000)
exploding.

v7/src/imail/imail-mime.scm

index cf8934221ae180176703f917c9692bcf68e16d67..8429e3d0218172b6ea9a785c9174074fa8955280 100644 (file)
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: imail-mime.scm,v 1.13 2009/02/03 01:16:52 riastradh Exp $
+$Id: imail-mime.scm,v 1.14 2009/02/03 01:42:10 riastradh Exp $
 
 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
@@ -520,34 +520,37 @@ USA.
 
 (define-mime-media-parser 'MULTIPART #f
   (lambda (header-fields string start end type subtype parameters)
-    type                                ;ignore
-    (mime:parse-multipart header-fields string start end subtype parameters)))
+    (mime:parse-multipart header-fields string start end
+                          type subtype parameters)))
 
 (define-mime-media-parser 'MULTIPART 'DIGEST
   (lambda (header-fields string start end type subtype parameters)
-    type                                ;ignore
     (fluid-let ((mime:default-content-type '(MESSAGE RFC822)))
       (mime:parse-multipart header-fields string start end
-                            subtype parameters))))
+                            type subtype parameters))))
 
 (define (mime:parse-multipart header-fields string start end
-                              subtype parameters)
-  (let ((boundary (mime:get-boundary parameters)))
-    (and boundary
-         (let ((parts
-                (mime:parse-multipart-parts header-fields string start end
-                                            boundary)))
-           (and parts
-                (let* ((enclosure
-                        (make-mime-body-multipart-substring
-                         header-fields string start end
-                        subtype parameters parts
-                         (mime:get-content-disposition header-fields)
-                         (mime:get-content-language header-fields))))
-                  (for-each (lambda (part)
-                              (set-mime-body-enclosure! part enclosure))
-                            parts)
-                  enclosure))))))
+                              type subtype parameters)
+  (or (let ((boundary (mime:get-boundary parameters)))
+        (and boundary
+             (let ((parts
+                    (mime:parse-multipart-parts header-fields string start end
+                                                boundary)))
+               (and parts
+                    (let* ((enclosure
+                            (make-mime-body-multipart-substring
+                             header-fields string start end
+                             subtype parameters parts
+                             (mime:get-content-disposition header-fields)
+                             (mime:get-content-language header-fields))))
+                      (for-each (lambda (part)
+                                  (set-mime-body-enclosure! part enclosure))
+                                parts)
+                      enclosure)))))
+      ;++ This is not quite right, but at least it will preserve the
+      ;++ octets in the malformed part and not crash IMAIL.
+      (mime:basic-media-parser header-fields string start end
+                               type subtype parameters)))
 
 (define (mime:parse-multipart-parts header-fields string start end boundary)
   (let ((encoding