*ppar = mutt_new_parameter (); (*ppar)->attribute = safe_strdup (par->attribute); (*ppar)->value = safe_strdup (par->value);
b = mutt_new_body (); memcpy (b, hdr->content, sizeof (BODY)); hdr->content->parts = NULL;   b->xtype = safe_strdup (b->xtype); b->subtype = safe_strdup (b->subtype); b->form_name = safe_strdup (b->form_name); b->filename = safe_strdup (b->filename); b->d_filename = safe_strdup (b->d_filename);   for (par = b->parameter, ppar = &b->parameter; par; ppar = &(*ppar)->next, par = par->next) { *ppar = mutt_new_parameter (); (*ppar)->attribute = safe_strdup (par->attribute); (*ppar)->value = safe_strdup (par->value); }  bfp = msg->fp;
int mutt_prepare_template (CONTEXT *ctx, HEADER *newhdr, HEADER *hdr,			       short weed){  PARAMETER *par, **ppar;  MESSAGE *msg;  char file[_POSIX_PATH_MAX];  BODY *b;  LIST *p, **q;  if ((msg = mx_open_message (ctx, hdr->msgno)) == NULL)    return (-1);  /* parse the message header */  fseek (msg->fp, hdr->offset, 0);  newhdr->env = mutt_read_rfc822_header (msg->fp, newhdr, 1, weed);  /* weed user-agent, x-mailer - we don't want them here */  p = newhdr->env->userhdrs;   q = &newhdr->env->userhdrs;    while (p)  {    if (!strncasecmp (p->data, "x-mailer:", 9) || !strncasecmp (p->data, "user-agent:", 11))    {      *q = p->next;      p->next = NULL;      mutt_free_list (&p);    }    else      q = &p->next;    p = *q;  }  safe_free ((void **) &newhdr->env->message_id);  /* make sure we parse the message */  mutt_parse_part (msg->fp, hdr->content);  /* copy the MIME structure */  b = mutt_new_body ();  memcpy (b, hdr->content, sizeof (BODY));  hdr->content->parts = NULL;  /* detach the temporary MIME structure from the message. */  b->xtype = safe_strdup (b->xtype);  b->subtype = safe_strdup (b->subtype);  b->form_name = safe_strdup (b->form_name);  b->filename = safe_strdup (b->filename);  b->d_filename = safe_strdup (b->d_filename);  forget_header_pointers (b);  /* copy parameters */  for (par = b->parameter, ppar = &b->parameter; par; ppar = &(*ppar)->next, par = par->next)  {    *ppar = mutt_new_parameter ();    (*ppar)->attribute = safe_strdup (par->attribute);    (*ppar)->value = safe_strdup (par->value);  }#ifdef _PGPPATH    /*    * remove a potential multipart/signed layer - useful when   * resending messages    */    if (mutt_is_multipart_signed (b))  {    newhdr->pgp |= PGPSIGN;        /* destroy the signature */    mutt_free_body (&b->parts->next);    b = mutt_remove_multipart (b);  }#endif    /*    * We don't need no primary multipart.   * Note: We _do_ preserve messages!   *    * XXX - we don't handle multipart/alternative in any    * smart way when sending messages.   *    */    if (b->type == TYPEMULTIPART)    b = mutt_remove_multipart (b);    newhdr->content = b;    /* create temporary files for all attachments */  for (; b; b = b->next)  {    file[0] = '\0';    if (b->filename)      strfcpy (file, b->filename, sizeof (file));    else      /* avoid Content-Disposition: header with temporary filename */      b->use_disp = 0;    mutt_adv_mktemp (file, sizeof(file));    if (mutt_save_attachment (msg->fp, b, file, 0, NULL) == -1)    {      mutt_free_envelope (&newhdr->env);      /* XXX hack around problem with mutt_free_body */       newhdr->content = mutt_make_multipart (newhdr->content);       mutt_free_body (&newhdr->content);      mx_close_message (&msg);      return -1;    }        safe_free ((void *) &b->filename);    b->filename = safe_strdup (file);    b->unlink = 1;    if (mutt_is_text_type (b->type, b->subtype))      b->noconv = 1;          mutt_stamp_attachment (b);    mutt_free_body (&b->parts);  }  /* that's it. */  mx_close_message (&msg);  return 0;}