I missed converting it before because it was hidden inside a shared
function, mutt_rfc1524_expand_filename().  Most of those callers use
the file for an actual $tmpdir file, but <get-attachment> should put
it in the compose $tmpdraftdir like other attachments.

Create two separate functions, mutt_rfc1524_expand_tmpdir_filename()
and mutt_rfc1524_expand_tmpdraftdir_filename().  Change
mutt_get_tmp_attachment() to call the latter.
---
 attach.c  | 18 +++++++++---------
 handler.c |  2 +-
 rfc1524.c | 26 +++++++++++++++++++++++---
 rfc1524.h |  3 ++-
 4 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/attach.c b/attach.c
index 74cc99e7..59fe1a26 100644
--- a/attach.c
+++ b/attach.c
@@ -59,7 +59,8 @@ int mutt_get_tmp_attachment(BODY *a)
 
   snprintf(type, sizeof(type), "%s/%s", TYPE(a), a->subtype);
   rfc1524_mailcap_lookup(a, type, sizeof(type), entry, 0);
-  mutt_rfc1524_expand_filename(entry->nametemplate, a->filename, tempfile);
+  /* <get-attachment> in the compose menu should save the file inside 
$tmpdraftdir */
+  mutt_rfc1524_expand_tmpdraftdir_filename(entry->nametemplate, a->filename, 
tempfile);
 
   rfc1524_free_entry(&entry);
 
@@ -112,8 +113,8 @@ int mutt_compose_attachment(BODY *a)
       else
         mutt_buffer_strcpy(command, entry->composecommand);
 
-      mutt_rfc1524_expand_filename(entry->nametemplate,
-                                   a->filename, newfile);
+      mutt_rfc1524_expand_tmpdir_filename(entry->nametemplate, a->filename,
+                                          newfile);
       muttdbg(1, "oldfile: %s\t newfile: %s", a->filename, mutt_b2s(newfile));
 
       if (safe_symlink(a->filename, mutt_b2s(newfile)) == -1)
@@ -244,8 +245,8 @@ int mutt_edit_attachment(BODY *a)
     {
 
       mutt_buffer_strcpy(command, entry->editcommand);
-      mutt_rfc1524_expand_filename(entry->nametemplate,
-                                   a->filename, newfile);
+      mutt_rfc1524_expand_tmpdir_filename(entry->nametemplate, a->filename,
+                                          newfile);
       muttdbg(1, "oldfile: %s\t newfile: %s", a->filename, mutt_b2s(newfile));
 
       if (safe_symlink(a->filename, mutt_b2s(newfile)) == -1)
@@ -403,8 +404,7 @@ int mutt_view_attachment(FILE *fp, BODY *a, int flag, 
HEADER *hdr,
     mutt_sanitize_filename(fname,
                            (fp ? 0 : MUTT_SANITIZE_ALLOW_SLASH) |
                            MUTT_SANITIZE_ALLOW_8BIT);
-    mutt_rfc1524_expand_filename(entry->nametemplate, fname,
-                                 tempfile);
+    mutt_rfc1524_expand_tmpdir_filename(entry->nametemplate, fname, tempfile);
     FREE(&fname);
 
     if (mutt_save_attachment(fp, a, mutt_b2s(tempfile), 0, NULL, 0) == -1)
@@ -978,8 +978,8 @@ int mutt_print_attachment(FILE *fp, BODY *a)
     mutt_sanitize_filename(sanitized_fname,
                            (fp ? 0 : MUTT_SANITIZE_ALLOW_SLASH) |
                            MUTT_SANITIZE_ALLOW_8BIT);
-    mutt_rfc1524_expand_filename(entry->nametemplate, sanitized_fname,
-                                 newfile);
+    mutt_rfc1524_expand_tmpdir_filename(entry->nametemplate, sanitized_fname,
+                                        newfile);
     FREE(&sanitized_fname);
 
     if (mutt_save_attachment(fp, a, mutt_b2s(newfile), 0, NULL, 0) == -1)
diff --git a/handler.c b/handler.c
index 8a7bbbb7..ddba01f2 100644
--- a/handler.c
+++ b/handler.c
@@ -1329,7 +1329,7 @@ static int autoview_handler(BODY *a, STATE *s)
 
   fname = safe_strdup(a->filename);
   mutt_sanitize_filename(fname, MUTT_SANITIZE_ALLOW_8BIT);
-  mutt_rfc1524_expand_filename(entry->nametemplate, fname, tempfile);
+  mutt_rfc1524_expand_tmpdir_filename(entry->nametemplate, fname, tempfile);
   FREE(&fname);
 
   if (entry->command)
diff --git a/rfc1524.c b/rfc1524.c
index f1b13fc9..b14436c1 100644
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -494,9 +494,9 @@ int rfc1524_mailcap_lookup(BODY *a, char *type, size_t 
typelen, rfc1524_entry *e
  * template and/or the old file name will be used for the
  * comparison and the temporary file name.
  */
-void mutt_rfc1524_expand_filename(const char *nametemplate,
-                                  const char *oldfile,
-                                  BUFFER *newfile)
+static void _rfc1524_expand_filename(const char *nametemplate,
+                                     const char *oldfile,
+                                     BUFFER *newfile)
 {
   int i, j, k, ps;
   const char *s;
@@ -600,10 +600,30 @@ void mutt_rfc1524_expand_filename(const char 
*nametemplate,
       mutt_buffer_strcpy(newfile, nametemplate);
     }
   }
+}
 
+/* This routine will create a _temporary_ filename, matching the
+ * name template if given, in $tmpdir.
+ */
+void mutt_rfc1524_expand_tmpdir_filename(const char *nametemplate,
+                                         const char *oldfile,
+                                         BUFFER *newfile)
+{
+  _rfc1524_expand_filename(nametemplate, oldfile, newfile);
   mutt_adv_mktemp(newfile);
 }
 
+/* This routine will create a _temporary_ filename, matching the
+ * name template if given, in $tmpdraftdir.
+ */
+void mutt_rfc1524_expand_tmpdraftdir_filename(const char *nametemplate,
+                                              const char *oldfile,
+                                              BUFFER *newfile)
+{
+  _rfc1524_expand_filename(nametemplate, oldfile, newfile);
+  mutt_adv_mktemp_draft(newfile);
+}
+
 /* If rfc1524_expand_command() is used on a recv'd message, then
  * the filename doesn't exist yet, but if its used while sending a message,
  * then we need to rename the existing file.
diff --git a/rfc1524.h b/rfc1524.h
index e74feb37..4d7b14e5 100644
--- a/rfc1524.h
+++ b/rfc1524.h
@@ -37,7 +37,8 @@ typedef struct rfc1524_mailcap_entry {
 rfc1524_entry *rfc1524_new_entry(void);
 void rfc1524_free_entry(rfc1524_entry **);
 int mutt_rfc1524_expand_command(BODY *, const char *, const char *, BUFFER *);
-void mutt_rfc1524_expand_filename(const char *, const char *, BUFFER *);
+void mutt_rfc1524_expand_tmpdir_filename(const char *, const char *, BUFFER *);
+void mutt_rfc1524_expand_tmpdraftdir_filename(const char *, const char *, 
BUFFER *);
 int rfc1524_mailcap_lookup(BODY *, char *, size_t, rfc1524_entry *, int);
 int mutt_rename_file(const char *, const char *);
 
-- 
2.55.0

Reply via email to