const char *aMessageURL)
const char *aMessageURL, PRBool addExternalBodiesOnly)
BuildAttachmentList(MimeObject *aChild, nsMsgAttachmentData *aAttachData,                    const char *aMessageURL){  char                  *disp;  PRInt32               i;  PRInt32               j;  MimeContainer         *cobj = (MimeContainer *) aChild;  nsMsgAttachmentData   *tmp = nsnull;  PRBool                isAlternativeOrRelated;  PRBool                isIMAPPart = PR_FALSE;  char                  *charset = nsnull;  if ( (!aChild) || (!cobj->children) ||        (mime_typep(aChild, (MimeObjectClass *)&mimeExternalBodyClass)))    return NS_OK;  if (MimeObjectChildIsMessageBody(aChild, &isAlternativeOrRelated))    i = 1;  else    i = 0;  for (; i<cobj->nchildren ; i++)   {    MimeObject    *child = cobj->children[i];    char          *part = mime_part_address(child);    char          *imappart = NULL;    /*      if we are processing an inline RFC822 message, we should skip its childern    */    PRBool isAnInlineMessage = mime_typep(child, (MimeObjectClass *) &mimeMessageClass);        /*      AppleDouble part need special care: we need to fetch the part as well it's two      children for the needed info as they could be anywhere, eventually, they won't contain      a name or file name. In any case we need to build only one attachment data    */    PRBool isAnAppleDoublePart = mime_typep(child, (MimeObjectClass *) &mimeMultipartAppleDoubleClass) &&                                 ((MimeContainer *)child)->nchildren == 2;        if (!isAnAppleDoublePart && !isAnInlineMessage)      if ( NS_FAILED(BuildAttachmentList((MimeObject *)child, aAttachData, aMessageURL)) )        return NS_OK;    if (!part)       return NS_ERROR_OUT_OF_MEMORY;    if (aChild->options->missing_parts)      imappart = mime_imap_part_address(child);    char *urlSpec = nsnull;    if (imappart)    {      isIMAPPart = PR_TRUE;      urlSpec = mime_set_url_imap_part(aMessageURL, imappart, part);    }    else      urlSpec = mime_set_url_part(aMessageURL, part, PR_TRUE);  	  PR_FREEIF(part);  	PR_FREEIF(imappart);    if (!urlSpec)      return NS_ERROR_OUT_OF_MEMORY;    tmp = &(aAttachData[attIndex++]);    nsresult rv = nsMimeNewURI(&(tmp->url), urlSpec, nsnull);	  PR_FREEIF(urlSpec);    if ( (NS_FAILED(rv)) || (!tmp->url) )      return NS_ERROR_OUT_OF_MEMORY;    tmp->real_type = child->content_type ? nsCRT::strdup(child->content_type) : NULL;    tmp->real_encoding = child->encoding ? nsCRT::strdup(child->encoding) : NULL;    disp = MimeHeaders_get(child->headers, HEADER_CONTENT_DISPOSITION, PR_FALSE, PR_FALSE);    if (disp)     {      tmp->real_name = MimeHeaders_get_parameter(disp, "filename", &charset, NULL);      if (isAnAppleDoublePart)        for (j = 0; j < 2 && !tmp->real_name; j ++)        {          PR_FREEIF(disp);          PR_FREEIF(charset);          disp = MimeHeaders_get(((MimeContainer *)child)->children[j]->headers, HEADER_CONTENT_DISPOSITION, PR_FALSE, PR_FALSE);          tmp->real_name = MimeHeaders_get_parameter(disp, "filename", &charset, NULL);        }      if (tmp->real_name)      {        // check encoded type        //        // The parameter of Content-Disposition must use RFC 2231.        // But old Netscape 4.x and Outlook Express etc. use RFC2047.        // So we should parse both types.        char *fname = NULL;        fname = mime_decode_filename(tmp->real_name, charset, aChild->options);        PR_FREEIF(charset);        if (fname && fname != tmp->real_name)        {          PR_FREEIF(tmp->real_name);          tmp->real_name = fname;        }      }      PR_FREEIF(disp);    }    disp = MimeHeaders_get(child->headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);    if (disp)    {      tmp->x_mac_type   = MimeHeaders_get_parameter(disp, PARAM_X_MAC_TYPE, NULL, NULL);      tmp->x_mac_creator= MimeHeaders_get_parameter(disp, PARAM_X_MAC_CREATOR, NULL, NULL);            if (!tmp->real_name || *tmp->real_name == 0)      {        PR_FREEIF(tmp->real_name);        tmp->real_name = MimeHeaders_get_parameter(disp, "name", &charset, NULL);        if (isAnAppleDoublePart)          for (j = 0; j < 2 && !tmp->real_name; j ++)          {            PR_FREEIF(disp);            PR_FREEIF(charset);            disp = MimeHeaders_get(((MimeContainer *)child)->children[j]->headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);            tmp->real_name = MimeHeaders_get_parameter(disp, "name", &charset, NULL);          }                if (tmp->real_name)        {          // check encoded type          //          // The parameter of Content-Disposition must use RFC 2231.          // But old Netscape 4.x and Outlook Express etc. use RFC2047.          // So we should parse both types.          char *fname = NULL;          fname = mime_decode_filename(tmp->real_name, charset,                                        aChild->options);          PR_FREEIF(charset);          if (fname && fname != tmp->real_name)          {            PR_Free(tmp->real_name);            tmp->real_name = fname;          }        }      }      PR_FREEIF(disp);    }    tmp->description = MimeHeaders_get(child->headers, HEADER_CONTENT_DESCRIPTION,                                        PR_FALSE, PR_FALSE);    // Now, do the right thing with the name!    if (!tmp->real_name)    {      /* If this attachment doesn't have a name, just give it one... */      tmp->real_name = MimeGetStringByID(MIME_MSG_DEFAULT_ATTACHMENT_NAME);      if (tmp->real_name)      {        char *newName = PR_smprintf(tmp->real_name, mime_part_address(child));        if (newName)        {          PR_Free(tmp->real_name);          tmp->real_name = newName;        }      }      else        tmp->real_name = mime_part_address(child);    }    ValidateRealName(tmp, child->headers);    if (isIMAPPart)    {      // If we get here, we should mark this attachment as not being      // downloaded.       tmp->notDownloaded = PR_TRUE;    }  }  return NS_OK;}