printf("RICHIE: Time to create the EDITOR with this template - HAS a body!!!!\n");
PRINTF("RICHIE: Time to create the EDITOR with this template - HAS a body!!!!\n");
mime_parse_stream_complete (nsMIMESession *stream){  struct mime_draft_data *mdd = (struct mime_draft_data *) stream->data_object;  nsIMsgCompFields *fields = NULL;  int htmlAction = 0;  int lineWidth = 0;    char *host = 0;  char *news_host = 0;  char *to_and_cc = 0;  char *re_subject = 0;  char *new_refs = 0;  char *from = 0;  char *repl = 0;  char *subj = 0;  char *id = 0;  char *refs = 0;  char *to = 0;  char *cc = 0;  char *bcc = 0;   char *fcc = 0;   char *org = 0;   char *grps = 0;  char *foll = 0;  char *priority = 0;  char *draftInfo = 0;    PRBool xlate_p = PR_FALSE;	/* #### how do we determine this? */  PRBool sign_p = PR_FALSE;		/* #### how do we determine this? */  PRBool forward_inline = PR_FALSE;    NS_ASSERTION (mdd, "null mime draft data");    if (!mdd) return;    if (mdd->obj)   {    int status;        status = mdd->obj->clazz->parse_eof ( mdd->obj, PR_FALSE );    mdd->obj->clazz->parse_end( mdd->obj, status < 0 ? PR_TRUE : PR_FALSE );        xlate_p = mdd->options->dexlate_p;    sign_p = mdd->options->signed_p;        // RICHIE    // We need to figure out how to pass the forwarded flag along with this    // operation.        //forward_inline = (mdd->format_out != FO_CMDLINE_ATTACHMENTS);        forward_inline = mdd->forwardInline;    if (forward_inline)    {#ifdef MOZ_SECURITY      HG88890#endif    }        NS_ASSERTION ( mdd->options == mdd->obj->options, "mime draft options not same as obj->options" );    mime_free (mdd->obj);    mdd->obj = 0;    if (mdd->options)     {      // mscott: aren't we leaking a bunch of trings here like the charset strings and such?      delete mdd->options;      mdd->options = 0;    }    if (mdd->stream)     {      mdd->stream->complete ((nsMIMESession *)mdd->stream->data_object);      PR_Free( mdd->stream );      mdd->stream = 0;    }  }    //  // Now, process the attachments that we have gathered from the message  // on disk  //  nsMsgAttachmentData     *newAttachData = nsnull;  if (mdd && (mdd->attachments_count > 0))    newAttachData = mime_draft_process_attachments(mdd);    //  // time to bring up the compose windows with all the info gathered   //  if ( mdd->headers )  {    subj = MimeHeaders_get(mdd->headers, HEADER_SUBJECT,  PR_FALSE, PR_FALSE);    if (forward_inline)    {      if (subj)      {        char *newSubj = PR_smprintf("[Fwd: %s]", subj);        if (newSubj)        {          PR_Free(subj);          subj = newSubj;        }      }    }	    else    {      repl = MimeHeaders_get(mdd->headers, HEADER_REPLY_TO, PR_FALSE, PR_FALSE);      to   = MimeHeaders_get(mdd->headers, HEADER_TO,       PR_FALSE, PR_TRUE);      cc   = MimeHeaders_get(mdd->headers, HEADER_CC,       PR_FALSE, PR_TRUE);      bcc   = MimeHeaders_get(mdd->headers, HEADER_BCC,       PR_FALSE, PR_TRUE);            /* These headers should not be RFC-1522-decoded. */      grps = MimeHeaders_get(mdd->headers, HEADER_NEWSGROUPS,  PR_FALSE, PR_TRUE);      foll = MimeHeaders_get(mdd->headers, HEADER_FOLLOWUP_TO, PR_FALSE, PR_TRUE);            host = MimeHeaders_get(mdd->headers, HEADER_X_MOZILLA_NEWSHOST, PR_FALSE, PR_FALSE);      if (!host)        host = MimeHeaders_get(mdd->headers, HEADER_NNTP_POSTING_HOST, PR_FALSE, PR_FALSE);            id   = MimeHeaders_get(mdd->headers, HEADER_MESSAGE_ID,  PR_FALSE, PR_FALSE);      refs = MimeHeaders_get(mdd->headers, HEADER_REFERENCES,  PR_FALSE, PR_TRUE);      priority = MimeHeaders_get(mdd->headers, HEADER_X_PRIORITY, PR_FALSE, PR_FALSE);            mime_intl_mimepart_2_str(&repl, mdd->mailcharset);      mime_intl_mimepart_2_str(&to, mdd->mailcharset);      mime_intl_mimepart_2_str(&cc, mdd->mailcharset);      mime_intl_mimepart_2_str(&bcc, mdd->mailcharset);      mime_intl_mimepart_2_str(&grps, mdd->mailcharset);      mime_intl_mimepart_2_str(&foll, mdd->mailcharset);      mime_intl_mimepart_2_str(&host, mdd->mailcharset);            if (host)       {        char *secure = NULL;                secure = PL_strcasestr(host, "secure");        if (secure)         {          *secure = 0;          news_host = PR_smprintf ("snews://%s", host);        }        else         {          news_host = PR_smprintf ("news://%s", host);        }      }    }        mime_intl_mimepart_2_str(&subj, mdd->mailcharset);        fields = CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll,      org, subj, refs, 0, priority, 0, news_host,      xlate_p, sign_p, mdd->mailcharset);        draftInfo = MimeHeaders_get(mdd->headers, HEADER_X_MOZILLA_DRAFT_INFO, PR_FALSE, PR_FALSE);    if (draftInfo && fields && !forward_inline)     {      char *parm = 0;      parm = MimeHeaders_get_parameter(draftInfo, "vcard", NULL, NULL);      if (parm && !nsCRT::strcmp(parm, "1"))        fields->SetBoolHeader(nsMsg_ATTACH_VCARD_BOOL_HEADER_MASK, PR_TRUE);      else        fields->SetBoolHeader(nsMsg_ATTACH_VCARD_BOOL_HEADER_MASK, PR_FALSE);            PR_FREEIF(parm);      parm = MimeHeaders_get_parameter(draftInfo, "receipt", NULL, NULL);      if (parm && !nsCRT::strcmp(parm, "0"))        fields->SetBoolHeader(nsMsg_RETURN_RECEIPT_BOOL_HEADER_MASK, PR_FALSE);       else      {        int receiptType = 0;        fields->SetBoolHeader(nsMsg_RETURN_RECEIPT_BOOL_HEADER_MASK, PR_TRUE);         sscanf(parm, "%d", &receiptType);        fields->SetReturnReceipt((PRInt32) receiptType);      }      PR_FREEIF(parm);      parm = MimeHeaders_get_parameter(draftInfo, "uuencode", NULL, NULL);      if (parm && !nsCRT::strcmp(parm, "1"))        fields->SetBoolHeader(nsMsg_UUENCODE_BINARY_BOOL_HEADER_MASK, PR_TRUE);      else        fields->SetBoolHeader(nsMsg_UUENCODE_BINARY_BOOL_HEADER_MASK, PR_FALSE);      PR_FREEIF(parm);      parm = MimeHeaders_get_parameter(draftInfo, "html", NULL, NULL);      if (parm)        sscanf(parm, "%d", &htmlAction);      PR_FREEIF(parm);      parm = MimeHeaders_get_parameter(draftInfo, "linewidth", NULL, NULL);      if (parm)        sscanf(parm, "%d", &lineWidth);      PR_FREEIF(parm);          }        if (mdd->messageBody)     {      char *body;      PRUint32 bodyLen = 0;      MSG_ComposeFormat composeFormat = nsIMsgCompFormat::Default;            bodyLen = mdd->messageBody->file_spec->GetFileSize();      body = (char *)PR_MALLOC (bodyLen + 1);      if (body)      {        nsCRT::memset (body, 0, bodyLen+1);                nsInputFileStream inputFile(*(mdd->messageBody->file_spec));        if (inputFile.is_open())          inputFile.read(body, bodyLen);                inputFile.close();                if (mdd->messageBody->type && *mdd->messageBody->type)        {          if( PL_strcasestr(mdd->messageBody->type, "text/html") != NULL )            composeFormat = nsIMsgCompFormat::HTML;          else if ( ( PL_strcasestr(mdd->messageBody->type, "text/plain") != NULL ) ||            ( PL_strcasecmp(mdd->messageBody->type, "text") == 0 ) )            composeFormat = nsIMsgCompFormat::PlainText;        }        else        {          composeFormat = nsIMsgCompFormat::PlainText;        }                // Since we have body text, then we should set the compose fields with        // this data.              //       if (composeFormat == nsIMsgCompFormat::PlainText)        //         fields->SetTheForcePlainText(PR_TRUE);                if (forward_inline)        {          if (mdd->identity)          {            PRBool bFormat;            mdd->identity->GetComposeHtml(&bFormat);            if (bFormat)            {              if (body && composeFormat == nsIMsgCompFormat::PlainText)              {                char* newbody = (char *)PR_MALLOC (bodyLen + 12); //+11 chars for <pre> & </pre> tags                if (newbody)                {                  *newbody = 0;                  PL_strcat(newbody, "<PRE>");                  PL_strcat(newbody, body);                  PL_strcat(newbody, "</PRE>");                  PR_Free(body);                  body = newbody;                }                composeFormat = nsIMsgCompFormat::HTML;              }            }          }                    mime_insert_forwarded_message_headers(&body, mdd->headers, composeFormat,            mdd->mailcharset);        }        // setting the charset while we are creating the composition fields        //fields->SetCharacterSet(NS_ConvertASCIItoUCS2(mdd->mailcharset));                // Ok, if we are here, then we should look at the charset and convert        // to UTF-8...        //        if (!forward_inline)        {          char *bodyCharset = MimeHeaders_get_parameter (mdd->messageBody->type, "charset", NULL, NULL);          if (bodyCharset)          {            // Now do conversion to UTF-8 for output            char  *convertedString = nsnull;            PRInt32 convertedStringLen;            PRInt32 res = MIME_ConvertCharset(PR_FALSE, bodyCharset, "UTF-8", body, nsCRT::strlen(body),                                               &convertedString, &convertedStringLen, NULL);            if (res == 0)            {              PR_FREEIF(body);              body = convertedString;            }              PR_FREEIF(bodyCharset);          }        }        // convert from UTF-8 to UCS2        nsString ucs2;        if (NS_SUCCEEDED(nsMsgI18NConvertToUnicode(nsCAutoString("UTF-8"), nsCAutoString(body), ucs2)))          fields->SetBody(ucs2.GetUnicode());        else          fields->SetBody(NS_ConvertASCIItoUCS2(body).GetUnicode());                PR_FREEIF(body);      } // end if (messageBody)            //      // At this point, we need to create a message compose window or editor      // window via XP-COM with the information that we have retrieved from       // the message store.      //      if (mdd->format_out == nsMimeOutput::nsMimeMessageEditorTemplate)      {#ifdef NS_DEBUG        printf("RICHIE: Time to create the EDITOR with this template - HAS a body!!!!\n");#endif        CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Template, composeFormat, mdd->identity);      }      else      {#ifdef NS_DEBUG        printf("Time to create the composition window WITH a body!!!!\n");#endif        if (mdd->forwardInline)          CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, composeFormat, mdd->identity);        else        {          nsString urlStr; urlStr.AssignWithConversion(mdd->url_name);          fields->SetDraftId(urlStr.GetUnicode());          CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, composeFormat, mdd->identity);        }      }            PR_FREEIF(body);      mime_free_attachments (mdd->messageBody, 1);    }    else    {      //      // At this point, we need to create a message compose window via      // XP-COM with the information that we have retrieved from the message store.      //      if (mdd->format_out == nsMimeOutput::nsMimeMessageEditorTemplate)      {#ifdef NS_DEBUG        printf("RICHIE: Time to create the EDITOR with this template - NO body!!!!\n");#endif        CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Template, nsIMsgCompFormat::Default, mdd->identity);      }      else      {#ifdef NS_DEBUG        printf("Time to create the composition window WITHOUT a body!!!!\n");#endif        if (mdd->forwardInline)          CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, nsIMsgCompFormat::Default, mdd->identity);        else        {          nsString urlStr; urlStr.AssignWithConversion(mdd->url_name);          fields->SetDraftId(urlStr.GetUnicode());          CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, nsIMsgCompFormat::Default, mdd->identity);        }      }    }      }  else  {    fields = CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll,      org, subj, refs, 0, priority, 0, news_host,      GetMailXlateionPreference(),       GetMailSigningPreference(),      mdd->mailcharset);    if (fields)      CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::New, nsIMsgCompFormat::Default, mdd->identity);  }    if ( mdd->headers )    MimeHeaders_free ( mdd->headers );    //   // Free the original attachment structure...  // Make sure we only cleanup the local copy of the memory and not kill   // files we need on disk  //  if (mdd->attachments)  {    int               i;    nsMsgAttachedFile *cur = mdd->attachments;        for ( i = 0; i < mdd->attachments_count; i++, cur++ )     {      if ( cur->file_spec )       {        delete ( cur->file_spec );        cur->file_spec = nsnull;      }    }        mime_free_attachments( mdd->attachments, mdd->attachments_count );  }    PR_FREEIF(mdd);  if (fields)    NS_RELEASE(fields);    // Release the prefs service  MimeObject *obj = (mdd ? mdd->obj : 0);    if ( (obj) && (obj->options) && (obj->options->prefs) )    nsServiceManager::ReleaseService(kPrefCID, obj->options->prefs);    PR_Free (mdd);    PR_FREEIF(host);  PR_FREEIF(to_and_cc);  PR_FREEIF(re_subject);  PR_FREEIF(new_refs);  PR_FREEIF(from);  PR_FREEIF(repl);  PR_FREEIF(subj);  PR_FREEIF(id);  PR_FREEIF(refs);  PR_FREEIF(to);  PR_FREEIF(cc);  PR_FREEIF(grps);  PR_FREEIF(foll);  PR_FREEIF(priority);  PR_FREEIF(draftInfo);  }