- command, sizeof (command)))
- {
- /* For now, editing requires a file, no piping */
- mutt_error _("Mailcap compose entry requires %%s");
- }
- else
- {
- int r;
-
- mutt_endwin (NULL);
- if ((r = mutt_system (command)) == -1)
- mutt_error (_("Error running \"%s\"!"), command);
-
- if (r != -1 && entry->composetypecommand)
- {
- BODY *b;
- FILE *fp, *tfp;
- char tempfile[_POSIX_PATH_MAX];
-
- if ((fp = safe_fopen (a->filename, "r")) == NULL)
- {
- mutt_perror _("Failure to open file to parse headers.");
- goto bailout;
- }
-
- b = mutt_read_mime_header (fp, 0);
- if (b)
- {
- if (b->parameter)
- {
- mutt_free_parameter (&a->parameter);
- a->parameter = b->parameter;
- b->parameter = NULL;
- }
- if (b->description) {
- FREE (&a->description);
- a->description = b->description;
- b->description = NULL;
- }
- if (b->form_name)
- {
- FREE (&a->form_name);
- a->form_name = b->form_name;
- b->form_name = NULL;
- }
-
- /* Remove headers by copying out data to another file, then
- * copying the file back */
- fseek (fp, b->offset, 0);
- mutt_mktemp (tempfile);
- if ((tfp = safe_fopen (tempfile, "w")) == NULL)
- {
- mutt_perror _("Failure to open file to strip headers.");
- goto bailout;
- }
- mutt_copy_stream (fp, tfp);
- fclose (fp);
- fclose (tfp);
- mutt_unlink (a->filename);
- mutt_rename_file (tempfile, a->filename);
-
- mutt_free_body (&b);
- }
- }
+ command, sizeof (command))) {
+ /* For now, editing requires a file, no piping */
+ mutt_error _("Mailcap compose entry requires %%s");
+ } else {
+ int r;
+
+ mutt_endwin (NULL);
+ if ((r = mutt_system (command)) == -1)
+ mutt_error (_("Error running \"%s\"!"), command);
+
+ if (r != -1 && entry->composetypecommand) {
+ BODY *b;
+ FILE *fp, *tfp;
+
+ if ((fp = safe_fopen (a->filename, "r")) == NULL) {
+ mutt_perror (_("Failure to open file to parse headers."));
+
+ goto bailout;
+ }
+
+ b = mutt_read_mime_header (fp, 0);
+ if (b) {
+ char tempfile[_POSIX_PATH_MAX];
+
+ if (b->parameter) {
+ parameter_list_wipe(&a->parameter);
+ a->parameter = b->parameter;
+ b->parameter = NULL;
+ }
+ if (b->description) {
+ p_delete(&a->description);
+ a->description = b->description;
+ b->description = NULL;
+ }
+ if (b->form_name) {
+ p_delete(&a->form_name);
+ a->form_name = b->form_name;
+ b->form_name = NULL;
+ }
+
+ /* Remove headers by copying out data to another file, then
+ * copying the file back */
+ fseeko (fp, b->offset, 0);
+ tfp = m_tempfile(tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL);
+ if (!tfp) {
+ mutt_perror (_("Failure to open file to strip headers."));
+ goto bailout;
+ }
+ mutt_copy_stream (fp, tfp);
+ m_fclose(&fp);
+ m_fclose(&tfp);
+ mutt_unlink (a->filename);
+ if (mutt_rename_file (tempfile, a->filename) != 0) {
+ mutt_perror (_("Failure to rename file."));
+
+ goto bailout;
+ }
+
+ body_list_wipe(&b);
+ }
+ }