properly detect pkcs-7 mime subtypes in libmime, r/sr=bienvenu 456250
authormozbugzilla@velox.ch
Tue, 23 Sep 2008 16:17:16 -0700
changeset 414 bf5ecaf124165107fc4a961663fe38222d05f513
parent 413 01caea2439c84f3808455a61b7d7b3d502c8859f
child 415 0873795c1cc4502a4b90b9354c9a9d6e27fb7e63
push idunknown
push userunknown
push dateunknown
bugs456250
properly detect pkcs-7 mime subtypes in libmime, r/sr=bienvenu 456250
mailnews/mime/src/mimei.cpp
--- a/mailnews/mime/src/mimei.cpp
+++ b/mailnews/mime/src/mimei.cpp
@@ -731,18 +731,48 @@ mime_find_class (const char *content_typ
         if (isReg)
           clazz = (MimeObjectClass *)&mimeInlineImageClass;
         else
           clazz = (MimeObjectClass *)&mimeExternalObjectClass;
     }
 
 #ifdef ENABLE_SMIME
     else if (!PL_strcasecmp(content_type, APPLICATION_XPKCS7_MIME)
-             || !PL_strcasecmp(content_type, APPLICATION_PKCS7_MIME))
-          clazz = (MimeObjectClass *)&mimeEncryptedCMSClass;
+             || !PL_strcasecmp(content_type, APPLICATION_PKCS7_MIME)) {
+        char *ct = (hdrs ? MimeHeaders_get(hdrs, HEADER_CONTENT_TYPE,
+                                           PR_FALSE, PR_FALSE)
+                           : nsnull);
+        char *st = (ct ? MimeHeaders_get_parameter(ct, "smime-type", NULL, NULL)
+                         : nsnull);
+
+        /* by default, assume that it is an encrypted message */
+        clazz = (MimeObjectClass *)&mimeEncryptedCMSClass;
+
+        /* if the smime-type parameter says that it's a certs-only or
+           compressed file, then show it as an attachment, however
+           (MimeEncryptedCMS doesn't handle these correctly) */
+        if (st &&
+            (!PL_strcasecmp(st, "certs-only") ||
+             !PL_strcasecmp(st, "compressed-data")))
+          clazz = (MimeObjectClass *)&mimeExternalObjectClass;
+        else {
+          /* look at the file extension... less reliable, but still covered
+             by the S/MIME specification (RFC 3851, section 3.2.1)  */
+          char *name = (hdrs ? MimeHeaders_get_name(hdrs, opts) : nsnull);
+          if (name) {
+            char *suf = PL_strrchr(name, '.');
+            if (suf &&
+                (!PL_strcasecmp(suf, ".p7c") || !PL_strcasecmp(suf, ".p7z")))
+              clazz = (MimeObjectClass *)&mimeExternalObjectClass;
+          }
+          PR_Free(name);
+        }
+        PR_Free(st);
+        PR_Free(ct);
+    }
 #endif
     /* A few types which occur in the real world and which we would otherwise
     treat as non-text types (which would be bad) without this special-case...
     */
     else if (!PL_strcasecmp(content_type,      APPLICATION_PGP) ||
              !PL_strcasecmp(content_type,      APPLICATION_PGP2))
       clazz = (MimeObjectClass *)&mimeInlineTextPlainClass;