if (opts && opts->format_out != nsMimeOutput::nsMimeMessageFilterSniffer)
if (opts && opts->format_out != nsMimeOutput::nsMimeMessageFilterSniffer && opts->format_out != nsMimeOutput::nsMimeMessageDecrypt)
mime_find_class (const char *content_type, MimeHeaders *hdrs,				 MimeDisplayOptions *opts, PRBool exact_match_p){  MimeObjectClass *clazz = 0;  MimeObjectClass *tempClass = 0;  contentTypeHandlerInitStruct  ctHandlerInfo;  // Read some prefs  nsIPref *pref = GetPrefServiceManager(opts);   PRInt32 html_as = 0;  // def. see below  PRInt32 types_of_classes_to_disallow = 0;  /* Let only a few libmime classes       process incoming data. This protects from bugs (e.g. buffer overflows)       and from security loopholes (e.g. allowing unchecked HTML in some       obscure classes, although the user has html_as > 0).       This option is mainly for the UI of html_as.       0 = allow all available classes       1 = Use hardcoded blacklist to avoid rendering (incoming) HTML       2 = ... and images       3 = ... and some other uncommon content types       100 = Use hardcoded whitelist to avoid even more bugs(buffer overflows).           This mode will limit the features available (e.g. uncommon           attachment types and inline images) and is for paranoid users.       */  if (opts && opts->format_out != nsMimeOutput::nsMimeMessageFilterSniffer)    if (pref)    {      pref->GetIntPref("mailnews.display.html_as", &html_as);      pref->GetIntPref("mailnews.display.disallow_mime_handlers",                       &types_of_classes_to_disallow);      if (types_of_classes_to_disallow > 0 && html_as == 0)           // We have non-sensical prefs. Do some fixup.        html_as = 1;    }  /*  * What we do first is check for an external content handler plugin.   * This will actually extend the mime handling by calling a routine   * which will allow us to load an external content type handler  * for specific content types. If one is not found, we will drop back  * to the default handler.  */  if ((tempClass = mime_locate_external_content_handler(content_type, &ctHandlerInfo)) != NULL)  {    if (types_of_classes_to_disallow > 0        && (!nsCRT::strncasecmp(content_type, "text/x-vcard", 12) ||            !nsCRT::strncasecmp(content_type, "text/calendar", 13))       )      /* Use a little hack to prevent some dangerous plugins, which ship         with Mozilla, to run.         For the truely user-installed plugins, we rely on the judgement         of the user. */    {      if (!exact_match_p)        clazz = (MimeObjectClass *)&mimeExternalObjectClass; // As attachment    }    else      clazz = (MimeObjectClass *)tempClass;  }  else  {    if (!content_type || !*content_type ||        !nsCRT::strcasecmp(content_type, "text"))  /* with no / in the type */      clazz = (MimeObjectClass *)&mimeUntypedTextClass;        /* Subtypes of text...    */    else if (!nsCRT::strncasecmp(content_type,			"text/", 5))    {      if      (!nsCRT::strcasecmp(content_type+5,		"html"))      {        if (opts            && opts->format_out == nsMimeOutput::nsMimeMessageSaveAs)          // SaveAs in new modes doesn't work yet.        {          clazz = (MimeObjectClass *)&mimeInlineTextHTMLClass;          types_of_classes_to_disallow = 0;        }        else if (html_as == 0) // Render sender's HTML          clazz = (MimeObjectClass *)&mimeInlineTextHTMLClass;        else if (html_as == 1) // convert HTML to plaintext          // Do a HTML->TXT->HTML conversion, see mimethpl.h.          clazz = (MimeObjectClass *)&mimeInlineTextHTMLAsPlaintextClass;        else if (html_as == 2) // display HTML source          /* This is for the freaks. Treat HTML as plaintext,             which will cause the HTML source to be displayed.             Not very user-friendly, but some seem to want this. */          clazz = (MimeObjectClass *)&mimeInlineTextPlainClass;        else if (html_as == 3) // Sanitize          // Strip all but allowed HTML          clazz = (MimeObjectClass *)&mimeInlineTextHTMLSanitizedClass;        else // Goofy pref          /* User has an unknown pref value. Maybe he used a newer Mozilla             with a new alternative to avoid HTML. Defaulting to option 1,             which is less dangerous than defaulting to the raw HTML. */          clazz = (MimeObjectClass *)&mimeInlineTextHTMLAsPlaintextClass;      }      else if (!nsCRT::strcasecmp(content_type+5,		"enriched"))        clazz = (MimeObjectClass *)&mimeInlineTextEnrichedClass;      else if (!nsCRT::strcasecmp(content_type+5,		"richtext"))        clazz = (MimeObjectClass *)&mimeInlineTextRichtextClass;      else if (!nsCRT::strcasecmp(content_type+5,		"rtf"))        clazz = (MimeObjectClass *)&mimeExternalObjectClass;      else if (!nsCRT::strcasecmp(content_type+5,		"plain"))      {        // Preliminary use the normal plain text        clazz = (MimeObjectClass *)&mimeInlineTextPlainClass;                if (opts && opts->format_out != nsMimeOutput::nsMimeMessageFilterSniffer)        {          PRBool disable_format_flowed = PR_FALSE;          if (pref)            pref->GetBoolPref("mailnews.display.disable_format_flowed_support",                              &disable_format_flowed);          if(!disable_format_flowed)          {            // Check for format=flowed, damn, it is already stripped away from            // the contenttype!            // Look in headers instead even though it's expensive and clumsy            // First find Content-Type:            char *content_type_row =              (hdrs               ? MimeHeaders_get(hdrs, HEADER_CONTENT_TYPE,                                 PR_FALSE, PR_FALSE)               : 0);            // Then the format parameter if there is one.            // I would rather use a PARAM_FORMAT but I can't find the right            // place to put the define. The others seems to be in net.h            // but is that really really the right place? There is also            // a nsMimeTypes.h but that one isn't included. Bug?            char *content_type_format =              (content_type_row               ? MimeHeaders_get_parameter(content_type_row, "format", NULL,NULL)               : 0);            if (content_type_format && !nsCRT::strcasecmp(content_type_format,                                                          "flowed"))              clazz = (MimeObjectClass *)&mimeInlineTextPlainFlowedClass;            PR_FREEIF(content_type_format);            PR_FREEIF(content_type_row);          }        }      }      else if (!exact_match_p)        clazz = (MimeObjectClass *)&mimeInlineTextPlainClass;    }        /* Subtypes of multipart...    */    else if (!nsCRT::strncasecmp(content_type,			"multipart/", 10))    {      if      (!nsCRT::strcasecmp(content_type+10,	"alternative"))        clazz = (MimeObjectClass *)&mimeMultipartAlternativeClass;      else if (!nsCRT::strcasecmp(content_type+10,	"related"))        clazz = (MimeObjectClass *)&mimeMultipartRelatedClass;      else if (!nsCRT::strcasecmp(content_type+10,	"digest"))        clazz = (MimeObjectClass *)&mimeMultipartDigestClass;      else if (!nsCRT::strcasecmp(content_type+10,	"appledouble") ||               !nsCRT::strcasecmp(content_type+10,	"header-set"))        clazz = (MimeObjectClass *)&mimeMultipartAppleDoubleClass;      else if (!nsCRT::strcasecmp(content_type+10,	"parallel"))        clazz = (MimeObjectClass *)&mimeMultipartParallelClass;      else if (!nsCRT::strcasecmp(content_type+10,	"mixed"))        clazz = (MimeObjectClass *)&mimeMultipartMixedClass;#ifdef ENABLE_SMIME            else if (!nsCRT::strcasecmp(content_type+10,	"signed"))      {      /* Check that the "protocol" and "micalg" parameters are ones we        know about. */        char *ct = (hdrs          ? MimeHeaders_get(hdrs, HEADER_CONTENT_TYPE,                            PR_FALSE, PR_FALSE)                    : 0);        char *proto = (ct          ? MimeHeaders_get_parameter(ct, PARAM_PROTOCOL, NULL, NULL)          : 0);        char *micalg = (ct          ? MimeHeaders_get_parameter(ct, PARAM_MICALG, NULL, NULL)          : 0);          if (proto              && (                  (/* is a signature */                   !nsCRT::strcasecmp(proto, APPLICATION_XPKCS7_SIGNATURE)                   ||                   !nsCRT::strcasecmp(proto, APPLICATION_PKCS7_SIGNATURE))                  && micalg                  && (!nsCRT::strcasecmp(micalg, PARAM_MICALG_MD5) ||                      !nsCRT::strcasecmp(micalg, PARAM_MICALG_MD5_2) ||                      !nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1) ||                      !nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1_2) ||                      !nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1_3) ||                      !nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1_4) ||                      !nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1_5) ||                      !nsCRT::strcasecmp(micalg, PARAM_MICALG_MD2))))            clazz = (MimeObjectClass *)&mimeMultipartSignedCMSClass;          else            clazz = 0;                  PR_FREEIF(proto);        PR_FREEIF(micalg);        PR_FREEIF(ct);      } #endif            if (!clazz && !exact_match_p)        /* Treat all unknown multipart subtypes as "multipart/mixed" */        clazz = (MimeObjectClass *)&mimeMultipartMixedClass;      /* If we are sniffing a message, let's threat alternative parts as mixed */      if (opts && opts->format_out == nsMimeOutput::nsMimeMessageFilterSniffer)        if (clazz == (MimeObjectClass *)&mimeMultipartAlternativeClass)          clazz = (MimeObjectClass *)&mimeMultipartMixedClass;    }        /* Subtypes of message...    */    else if (!nsCRT::strncasecmp(content_type,			"message/", 8))    {      if      (!nsCRT::strcasecmp(content_type+8,		"rfc822") ||        !nsCRT::strcasecmp(content_type+8,		"news"))        clazz = (MimeObjectClass *)&mimeMessageClass;      else if (!nsCRT::strcasecmp(content_type+8,		"external-body"))        clazz = (MimeObjectClass *)&mimeExternalBodyClass;      else if (!nsCRT::strcasecmp(content_type+8,		"partial"))        /* I guess these are most useful as externals, for now... */        clazz = (MimeObjectClass *)&mimeExternalObjectClass;      else if (!exact_match_p)        /* Treat all unknown message subtypes as "text/plain" */        clazz = (MimeObjectClass *)&mimeInlineTextPlainClass;    }        /* The magic image types which we are able to display internally...    */    else if (!nsCRT::strncasecmp(content_type,		"image/", 6)) {        nsCOMPtr<imgILoader> loader(do_GetService("@mozilla.org/image/loader;1"));        PRBool isReg = PR_FALSE;        loader->SupportImageWithMimeType(content_type, &isReg);        if (isReg)          clazz = (MimeObjectClass *)&mimeInlineImageClass;        else          clazz = (MimeObjectClass *)&mimeExternalObjectClass;    }    #ifdef ENABLE_SMIME    else if (!nsCRT::strcasecmp(content_type, APPLICATION_XPKCS7_MIME)             || !nsCRT::strcasecmp(content_type, APPLICATION_PKCS7_MIME))	        clazz = (MimeObjectClass *)&mimeEncryptedCMSClass;#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 (!nsCRT::strcasecmp(content_type,			APPLICATION_PGP) ||             !nsCRT::strcasecmp(content_type,			APPLICATION_PGP2))      clazz = (MimeObjectClass *)&mimeInlineTextPlainClass;    else if (!nsCRT::strcasecmp(content_type,			SUN_ATTACHMENT))      clazz = (MimeObjectClass *)&mimeSunAttachmentClass;        /* Everything else gets represented as a clickable link.    */    else if (!exact_match_p)      clazz = (MimeObjectClass *)&mimeExternalObjectClass;    if (!mime_is_allowed_class(clazz, types_of_classes_to_disallow))    {      /* Do that check here (not after the if block), because we want to allow         user-installed plugins. */      if(!exact_match_p)        clazz = (MimeObjectClass *)&mimeExternalObjectClass;      else        clazz = 0;    }  }  if (!exact_match_p)    NS_ASSERTION(clazz, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");  if (!clazz) return 0;  NS_ASSERTION(clazz, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");  if (clazz && !clazz->class_initialized)	{	  int status = mime_classinit(clazz);	  if (status < 0) return 0;	}  return clazz;}