nsXPIDLCString fileExtension;  if ( (NS_SUCCEEDED(mimeInfo->GetPrimaryExtension(getter_Copies(fileExtension)))) && fileExtension) { newAttachName.Append("."); newAttachName.Append(fileExtension); extensionAdded = PR_TRUE; } }
newAttachName.Append("."); newAttachName.Append(fileExtension); extensionAdded = PR_TRUE; }
mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers ){  struct mime_draft_data *mdd = (struct mime_draft_data *) stream_closure;  nsMsgAttachedFile *attachments = 0, *newAttachment = 0;  int nAttachments = 0;  //char *hdr_value = NULL;  char *parm_value = NULL;  PRBool needURL = PR_FALSE;  PRBool creatingMsgBody = PR_TRUE;  PRBool bodyPart = PR_FALSE;    NS_ASSERTION (mdd && headers, "null mime draft data and/or headers");  if (!mdd || !headers)     return -1;  if (mdd->options->decompose_init_count)   {    mdd->options->decompose_init_count++;    NS_ASSERTION(mdd->curAttachment, "missing attachment in mime_decompose_file_init_fn");    if (mdd->curAttachment) {      char *ct = MimeHeaders_get(headers, HEADER_CONTENT_TYPE, PR_TRUE, PR_FALSE);      if (ct)        NS_MsgSACopy(&(mdd->curAttachment->type), ct);      PR_FREEIF(ct);    }    return 0;  }  else    mdd->options->decompose_init_count++;  nAttachments = mdd->attachments_count;  if (!nAttachments && !mdd->messageBody)   {    // if we've been told to use an override charset then do so....otherwise use the charset    // inside the message header...    if (mdd->options && mdd->options->override_charset)        mdd->mailcharset = nsCRT::strdup(mdd->options->default_charset);    else    {      char *contentType = NULL;      contentType = MimeHeaders_get(headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);      if (contentType)       {        mdd->mailcharset = MimeHeaders_get_parameter(contentType, "charset", NULL, NULL);        PR_FREEIF(contentType);      }    }        mdd->messageBody = PR_NEWZAP (nsMsgAttachedFile);    NS_ASSERTION (mdd->messageBody, "missing messageBody in mime_decompose_file_init_fn");    if (!mdd->messageBody)       return MIME_OUT_OF_MEMORY;    newAttachment = mdd->messageBody;    creatingMsgBody = PR_TRUE;    bodyPart = PR_TRUE;  }  else   {    /* always allocate one more extra; don't ask me why */    needURL = PR_TRUE;    if ( nAttachments )     {      NS_ASSERTION (mdd->attachments, "no attachments");            attachments = (nsMsgAttachedFile *)PR_REALLOC(mdd->attachments,                                                     sizeof (nsMsgAttachedFile) *                                                     (nAttachments + 2));    if (!attachments)        return MIME_OUT_OF_MEMORY;      mdd->attachments = attachments;      mdd->attachments_count++;    }    else {      NS_ASSERTION (!mdd->attachments, "have attachments but count is 0");            attachments = (nsMsgAttachedFile *) PR_MALLOC ( sizeof (nsMsgAttachedFile) * 2);      if (!attachments)         return MIME_OUT_OF_MEMORY;      mdd->attachments_count++;      mdd->attachments = attachments;    }        newAttachment = attachments + nAttachments;    memset ( newAttachment, 0, sizeof (nsMsgAttachedFile) * 2 );  }  char *workURLSpec = nsnull;  char *contLoc = nsnull;  newAttachment->real_name = MimeHeaders_get_name ( headers, mdd->options );  contLoc = MimeHeaders_get( headers, HEADER_CONTENT_LOCATION, PR_FALSE, PR_FALSE );  if (!contLoc)      contLoc = MimeHeaders_get( headers, HEADER_CONTENT_BASE, PR_FALSE, PR_FALSE );  if ( (!contLoc) && (newAttachment->real_name) )    workURLSpec = nsCRT::strdup(newAttachment->real_name);  if ( (contLoc) && (!workURLSpec) )    workURLSpec = nsCRT::strdup(contLoc);  PR_FREEIF(contLoc);  mdd->curAttachment = newAttachment;    newAttachment->type =  MimeHeaders_get ( headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE );  if (PL_strstr(newAttachment->type, MESSAGE_RFC822))  {    char *newName = PR_smprintf("%s.eml", newAttachment->real_name);    if (newName)    {      PR_Free(newAttachment->real_name);      newAttachment->real_name = newName;    }  }          //  // This is to handle the degenerated Apple Double attachment.  //  parm_value = MimeHeaders_get( headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE );  if (parm_value)   {    char *boundary = NULL;    char *tmp_value = NULL;    boundary = MimeHeaders_get_parameter(parm_value, "boundary", NULL, NULL);    if (boundary)      tmp_value = PR_smprintf("; boundary=\"%s\"", boundary);    if (tmp_value)      NS_MsgSACat(&(newAttachment->type), tmp_value);    newAttachment->x_mac_type = MimeHeaders_get_parameter(parm_value, "x-mac-type", NULL, NULL);    newAttachment->x_mac_creator = MimeHeaders_get_parameter(parm_value, "x-mac-creator", NULL, NULL);    PR_FREEIF(parm_value);    PR_FREEIF(boundary);    PR_FREEIF(tmp_value);  }  newAttachment->encoding = MimeHeaders_get ( headers, HEADER_CONTENT_TRANSFER_ENCODING,                                              PR_FALSE, PR_FALSE );  newAttachment->description = MimeHeaders_get( headers, HEADER_CONTENT_DESCRIPTION,                                                PR_FALSE, PR_FALSE );  //   // If we came up empty for description or the orig URL, we should do something about it.  //  if  ( ( (!newAttachment->description) || (!*newAttachment->description) ) && (workURLSpec) )    newAttachment->description = nsCRT::strdup(workURLSpec);  nsFileSpec *tmpSpec = nsnull;  {    // Let's build a temp file with an extension based on the content-type: nsmail.<extension>    nsCAutoString  newAttachName ("nsmail");    PRBool extensionAdded = PR_FALSE;    // the content type may contain a charset. i.e. text/html; ISO-2022-JP...we want to strip off the charset    // before we ask the mime service for a mime info for this content type.    nsCAutoString contentType (newAttachment->type);    PRInt32 pos = contentType.FindChar(';');    if (pos > 0)      contentType.Truncate(pos);    nsresult  rv = NS_OK;    nsCOMPtr<nsIMIMEService> mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));    if (NS_SUCCEEDED(rv) && mimeFinder)     {      nsCOMPtr<nsIMIMEInfo> mimeInfo = nsnull;      rv = mimeFinder->GetFromTypeAndExtension(contentType.get(), nsnull, getter_AddRefs(mimeInfo));      if (NS_SUCCEEDED(rv) && mimeInfo)       {        nsXPIDLCString fileExtension;        if ( (NS_SUCCEEDED(mimeInfo->GetPrimaryExtension(getter_Copies(fileExtension)))) && fileExtension)        {          newAttachName.Append(".");          newAttachName.Append(fileExtension);          extensionAdded = PR_TRUE;        }      }            }    if (!extensionAdded)    {      newAttachName.Append(".tmp");    }    tmpSpec = nsMsgCreateTempFileSpec(NS_CONST_CAST(char*, newAttachName.get()));  }  // This needs to be done so the attachment structure has a handle   // on the temp file for this attachment...  // if ( (tmpSpec) && (!bodyPart) )  if (tmpSpec)  {      nsFileURL fileURL(*tmpSpec);      const char * tempSpecStr = fileURL.GetURLString();      nsMimeNewURI(getter_AddRefs(newAttachment->orig_url), tempSpecStr, nsnull);  }  PR_FREEIF(workURLSpec);  if (!tmpSpec)    return MIME_OUT_OF_MEMORY;  NS_NewFileSpecWithSpec(*tmpSpec, &mdd->tmpFileSpec);  if (!mdd->tmpFileSpec)    return MIME_OUT_OF_MEMORY;    newAttachment->file_spec = tmpSpec;  mdd->tmpFileStream = new nsOutputFileStream(*tmpSpec, PR_WRONLY | PR_CREATE_FILE, 00600);  if (!mdd->tmpFileStream)    return MIME_UNABLE_TO_OPEN_TMP_FILE;      // For now, we are always going to decode all of the attachments   // for the message. This way, we have native data   if (creatingMsgBody)   {    MimeDecoderData *(*fn) (nsresult (*) (const char*, PRInt32, void*), void*) = 0;        //    // Initialize a decoder if necessary.    //    if (!newAttachment->encoding)      ;    else if (!nsCRT::strcasecmp(newAttachment->encoding, ENCODING_BASE64))      fn = &MimeB64DecoderInit;    else if (!nsCRT::strcasecmp(newAttachment->encoding, ENCODING_QUOTED_PRINTABLE))      fn = &MimeQPDecoderInit;    else if (!nsCRT::strcasecmp(newAttachment->encoding, ENCODING_UUENCODE) ||             !nsCRT::strcasecmp(newAttachment->encoding, ENCODING_UUENCODE2) ||             !nsCRT::strcasecmp(newAttachment->encoding, ENCODING_UUENCODE3) ||             !nsCRT::strcasecmp(newAttachment->encoding, ENCODING_UUENCODE4))      fn = &MimeUUDecoderInit;    else if (!nsCRT::strcasecmp(newAttachment->encoding, ENCODING_YENCODE))      fn = &MimeYDecoderInit;        if (fn)     {      mdd->decoder_data = fn (/* The (nsresult (*) ...) cast is to turn the `void' argument into `MimeObject'. */                              ((nsresult (*) (const char *, PRInt32, void *))                              dummy_file_write), mdd->tmpFileStream);      if (!mdd->decoder_data)        return MIME_OUT_OF_MEMORY;    }  }  return 0;}