]> granicus.if.org Git - mutt/commitdiff
Convert mutt_compose_attachment to use BUFFER.
authorKevin McCarthy <kevin@8t8.us>
Sun, 14 Oct 2018 23:18:53 +0000 (16:18 -0700)
committerKevin McCarthy <kevin@8t8.us>
Mon, 15 Oct 2018 20:57:50 +0000 (13:57 -0700)
attach.c
rfc1524.c
rfc1524.h

index 89574f5009ae6c570383c4ab0246d0908fd0243b..904ec7867beb5181d31defeabcb88cf0b268fbbf 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -95,28 +95,29 @@ int mutt_get_tmp_attachment (BODY *a)
 int mutt_compose_attachment (BODY *a)
 {
   char type[STRING];
-  char command[STRING];
-  char newfile[_POSIX_PATH_MAX] = "";
+  BUFFER *command = mutt_buffer_pool_get ();
+  BUFFER *newfile = mutt_buffer_pool_get ();
+  BUFFER *tempfile = mutt_buffer_pool_get ();
   rfc1524_entry *entry = rfc1524_new_entry ();
   short unlink_newfile = 0;
   int rc = 0;
-  
+
   snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
   if (rfc1524_mailcap_lookup (a, type, entry, MUTT_COMPOSE))
   {
     if (entry->composecommand || entry->composetypecommand)
     {
-
       if (entry->composetypecommand)
-       strfcpy (command, entry->composetypecommand, sizeof (command));
+       mutt_buffer_strcpy (command, entry->composetypecommand);
       else 
-       strfcpy (command, entry->composecommand, sizeof (command));
-      if (rfc1524_expand_filename (entry->nametemplate,
-                                     a->filename, newfile, sizeof (newfile)))
+       mutt_buffer_strcpy (command, entry->composecommand);
+
+      if (mutt_buffer_rfc1524_expand_filename (entry->nametemplate,
+                                               a->filename, newfile))
       {
        dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n",
-                                 a->filename, newfile));
-       if (safe_symlink (a->filename, newfile) == -1)
+                   a->filename, mutt_b2s (newfile)));
+       if (safe_symlink (a->filename, mutt_b2s (newfile)) == -1)
        {
          if (mutt_yesorno (_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES)
            goto bailout;
@@ -125,10 +126,10 @@ int mutt_compose_attachment (BODY *a)
          unlink_newfile = 1;
       }
       else
-       strfcpy(newfile, a->filename, sizeof(newfile));
+       mutt_buffer_strcpy (newfile, a->filename);
       
-      if (rfc1524_expand_command (a, newfile, type,
-                                     command, sizeof (command)))
+      if (mutt_buffer_rfc1524_expand_command (a, mutt_b2s (newfile), type,
+                                              command))
       {
        /* For now, editing requires a file, no piping */
        mutt_error _("Mailcap compose entry requires %%s");
@@ -138,14 +139,13 @@ int mutt_compose_attachment (BODY *a)
        int r;
 
        mutt_endwin (NULL);
-       if ((r = mutt_system (command)) == -1)
-         mutt_error (_("Error running \"%s\"!"), command);
+       if ((r = mutt_system (mutt_b2s (command))) == -1)
+         mutt_error (_("Error running \"%s\"!"), mutt_b2s (command));
        
        if (r != -1 && entry->composetypecommand)
        {
          BODY *b;
          FILE *fp, *tfp;
-         char tempfile[_POSIX_PATH_MAX];
 
          if ((fp = safe_fopen (a->filename, "r")) == NULL)
          {
@@ -177,8 +177,8 @@ int mutt_compose_attachment (BODY *a)
            /* Remove headers by copying out data to another file, then 
             * copying the file back */
            fseeko (fp, b->offset, 0);
-           mutt_mktemp (tempfile, sizeof (tempfile));
-           if ((tfp = safe_fopen (tempfile, "w")) == NULL)
+           mutt_buffer_mktemp (tempfile);
+           if ((tfp = safe_fopen (mutt_b2s (tempfile), "w")) == NULL)
            {
              mutt_perror _("Failure to open file to strip headers.");
              goto bailout;
@@ -187,7 +187,7 @@ int mutt_compose_attachment (BODY *a)
            safe_fclose (&fp);
            safe_fclose (&tfp);
            mutt_unlink (a->filename);  
-           if (mutt_rename_file (tempfile, a->filename) != 0) 
+           if (mutt_rename_file (mutt_b2s (tempfile), a->filename) != 0) 
            {
              mutt_perror _("Failure to rename file.");
              goto bailout;
@@ -201,18 +201,22 @@ int mutt_compose_attachment (BODY *a)
   }
   else
   {
-    rfc1524_free_entry (&entry);
     mutt_message (_("No mailcap compose entry for %s, creating empty file."),
                   type);
-    return 1;
+    rc = 1;
+    goto bailout;
   }
 
   rc = 1;
-  
-  bailout:
-  
+
+bailout:
+
   if(unlink_newfile)
-    unlink(newfile);
+    unlink(mutt_b2s (newfile));
+
+  mutt_buffer_pool_release (&command);
+  mutt_buffer_pool_release (&newfile);
+  mutt_buffer_pool_release (&tempfile);
 
   rfc1524_free_entry (&entry);
   return rc;
index 87678bbfefacc7cf6c5960bf527bb1f52ef1f5f6..311d5e054fe35fc3b1f7bca65b79c97d9047e289 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -595,7 +595,7 @@ int rfc1524_expand_filename (const char *nametemplate,
  * safe_fopen().
  */
 
-int mutt_rename_file (char *oldfile, char *newfile)
+int mutt_rename_file (const char *oldfile, const char *newfile)
 {
   FILE *ofp, *nfp;
 
index a3f3a828f3cf6a75e166a765d2b20a5027609c1b..5c1bd6ed9d9aa33e833174bdce29d23a429eb3af 100644 (file)
--- a/rfc1524.h
+++ b/rfc1524.h
@@ -39,7 +39,7 @@ void rfc1524_free_entry (rfc1524_entry **);
 int rfc1524_expand_command (BODY *, const char *, const char *, char *, int);
 int rfc1524_expand_filename (const char *, const char *, char *, size_t);
 int rfc1524_mailcap_lookup (BODY *, char *, rfc1524_entry *, int);
-int mutt_rename_file (char *, char *);
+int mutt_rename_file (const char *, const char *);
 
 
 /* Temporary BUFFER transition functions */