msd->options->rfc1522_conversion_fn = mime_convert_rfc1522;
msd->options->rfc1522_conversion_p  = PR_TRUE;
mime_bridge_create_display_stream(                          nsIMimeEmitter      *newEmitter,                          nsStreamConverter   *newPluginObj2,                          nsIURI              *uri,                          nsMimeOutputType    format_out,                          PRUint32	          whattodo,                          nsIChannel          *aChannel){  int                       status = 0;  MimeObject                *obj;  struct mime_stream_data   *msd;  nsMIMESession             *stream = 0;    if (!uri)    return nsnull;  msd = PR_NEWZAP(struct mime_stream_data);  if (!msd)     return NULL;  // Assign the new mime emitter - will handle output operations  msd->output_emitter = newEmitter;  msd->firstCheck = PR_TRUE;  // Store the URL string for this decode operation  char *urlString;  nsresult rv;  // Keep a hold of the channel...  msd->channel = aChannel;  rv = uri->GetSpec(&urlString);  if (NS_SUCCEEDED(rv))  {    if ((urlString) && (*urlString))    {      msd->url_name = nsCRT::strdup(urlString);      if (!(msd->url_name))      {        PR_FREEIF(msd);        return NULL;      }      nsCOMPtr<nsIMsgMessageUrl> msgUrl = do_QueryInterface(uri);      if (msgUrl)          msgUrl->GetOriginalSpec(&msd->orig_url_name);      PR_FREEIF(urlString);    }  }    msd->format_out = format_out;       // output format  msd->pluginObj2 = newPluginObj2;    // the plugin object pointer     msd->options = new MimeDisplayOptions;  if (!msd->options)  {    PR_Free(msd);    return 0;  }//  memset(msd->options, 0, sizeof(*msd->options));  msd->options->format_out = format_out;     // output format  rv = nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**)&(msd->options->prefs));  if (! (msd->options->prefs && NS_SUCCEEDED(rv)))	{    PR_FREEIF(msd);    return nsnull;  }  // Need the text converter...  rv = nsComponentManager::CreateInstance(kTXTToHTMLConvCID,                                          NULL, NS_GET_IID(mozITXTToHTMLConv),                                          (void **)&(msd->options->conv));  if (NS_FAILED(rv))	{    nsServiceManager::ReleaseService(kPrefCID, msd->options->prefs);    PR_FREEIF(msd);    return nsnull;  }  //  // Set the defaults, based on the context, and the output-type.  //  MIME_HeaderType = MimeHeadersAll;  switch (format_out)   {		case nsMimeOutput::nsMimeMessageSplitDisplay:   // the wrapper HTML output to produce the split header/body display		case nsMimeOutput::nsMimeMessageHeaderDisplay:  // the split header/body display		case nsMimeOutput::nsMimeMessageBodyDisplay:    // the split header/body display    case nsMimeOutput::nsMimeMessageXULDisplay:      msd->options->fancy_headers_p = PR_TRUE;      msd->options->output_vcard_buttons_p = PR_TRUE;      msd->options->fancy_links_p = PR_TRUE;      break;	case nsMimeOutput::nsMimeMessageSaveAs:         // Save As operations	case nsMimeOutput::nsMimeMessageQuoting:        // all HTML quoted/printed output  case nsMimeOutput::nsMimeMessagePrintOutput:      msd->options->fancy_headers_p = PR_TRUE;      msd->options->fancy_links_p = PR_TRUE;      break;	case nsMimeOutput::nsMimeMessageBodyQuoting:        // only HTML body quoted output      MIME_HeaderType = MimeHeadersNone;      break;    case nsMimeOutput::nsMimeMessageRaw:              // the raw RFC822 data (view source) and attachments		case nsMimeOutput::nsMimeMessageDraftOrTemplate:  // Loading drafts & templates		case nsMimeOutput::nsMimeMessageEditorTemplate:   // Loading templates into editor      break;  }  ////////////////////////////////////////////////////////////  // Now, get the libmime prefs...  ////////////////////////////////////////////////////////////    /* This pref is written down in with the  opposite sense of what we like to use... */  MIME_WrapLongLines = PR_TRUE;  if (msd->options->prefs)    msd->options->prefs->GetBoolPref("mail.wrap_long_lines", &MIME_WrapLongLines);  MIME_VariableWidthPlaintext = PR_TRUE;  if (msd->options->prefs)    msd->options->prefs->GetBoolPref("mail.fixed_width_messages", &MIME_VariableWidthPlaintext);  MIME_VariableWidthPlaintext = !MIME_VariableWidthPlaintext;  msd->options->wrap_long_lines_p = MIME_WrapLongLines;  msd->options->headers = MIME_HeaderType;    // We need to have the URL to be able to support the various   // arguments  status = mime_parse_url_options(msd->url_name, msd->options);  if (status < 0)  {    PR_FREEIF(msd->options->part_to_load);    PR_Free(msd->options);    PR_Free(msd);    return 0;  }   if (msd->options->headers == MimeHeadersMicro &&     (msd->url_name == NULL || (nsCRT::strncmp(msd->url_name, "news:", 5) != 0 &&              nsCRT::strncmp(msd->url_name, "snews:", 6) != 0)) )    msd->options->headers = MimeHeadersMicroPlus;  msd->options->url = msd->url_name;  msd->options->write_html_p          = PR_TRUE;  msd->options->output_init_fn        = mime_output_init_fn;    msd->options->output_fn             = mime_output_fn;  msd->options->whattodo 	      = whattodo;  msd->options->charset_conversion_fn = mime_convert_charset;  msd->options->rfc1522_conversion_fn = mime_convert_rfc1522;  msd->options->file_type_fn          = mime_file_type;  msd->options->stream_closure        = msd;  msd->options->passwd_prompt_fn      = 0;    msd->options->image_begin           = mime_image_begin;  msd->options->image_end             = mime_image_end;  msd->options->make_image_html       = mime_image_make_image_html;  msd->options->image_write_buffer    = mime_image_write_buffer;    msd->options->variable_width_plaintext_p = MIME_VariableWidthPlaintext;  //   // Charset overrides takes place here  //  // We have a bool pref (mail.force_user_charset) to deal with attachments.  // 1) If true - libmime does NO conversion and just passes it through to raptor  // 2) If false, then we try to use the charset of the part and if not available,   //    the charset of the root message   //  msd->options->force_user_charset = PR_FALSE;  if (msd->options->prefs)    msd->options->prefs->GetBoolPref("mail.force_user_charset", &(msd->options->force_user_charset));  // If this is a part, then we should emit the HTML to render the data  // (i.e. embedded images)  if (msd->options->part_to_load)    msd->options->write_html_p = PR_FALSE;  obj = mime_new ((MimeObjectClass *)&mimeMessageClass, (MimeHeaders *) NULL, MESSAGE_RFC822);  if (!obj)  {    delete msd->options;    PR_Free(msd);    return 0;  }  obj->options = msd->options;  msd->obj = obj;    /* Both of these better not be true at the same time. */  PR_ASSERT(! (obj->options->dexlate_p && obj->options->write_html_p));    stream = PR_NEW(nsMIMESession);  if (!stream)  {    delete msd->options;    PR_Free(msd);    PR_Free(obj);    return 0;  }    nsCRT::memset (stream, 0, sizeof (*stream));    stream->name           = "MIME Conversion Stream";  stream->complete       = mime_display_stream_complete;  stream->abort          = mime_display_stream_abort;  stream->put_block      = mime_display_stream_write;  stream->data_object    = msd;    status = obj->clazz->initialize(obj);  if (status >= 0)    status = obj->clazz->parse_begin(obj);  if (status < 0)  {    PR_Free(stream);    delete msd->options;    PR_Free(msd);    PR_Free(obj);    return 0;  }    return stream;}