[PATCH] Fix <get-attachment> to use $tmpdraftdir.
"Kevin J. McCarthy" <[email protected]>
| Newsgroups | gmane.mail.mutt.devel |
|---|---|
| Message-ID | <[email protected]> |
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.
Add a parameter to select the $tmpdraftdir and modify
mutt_get_tmp_attachment() to set the parameter when calling.
---
attach.c | 11 ++++++-----
handler.c | 2 +-
rfc1524.c | 8 ++++++--
rfc1524.h | 2 +-
4 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/attach.c b/attach.c
index 74cc99e7..95597e5f 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> should save the file inside $tmpdraftdir */
+ mutt_rfc1524_expand_filename(entry->nametemplate, a->filename, tempfile, 1);
rfc1524_free_entry(&entry);
@@ -113,7 +114,7 @@ int mutt_compose_attachment(BODY *a)
mutt_buffer_strcpy(command, entry->composecommand);
mutt_rfc1524_expand_filename(entry->nametemplate,
- a->filename, newfile);
+ a->filename, newfile, 0);
muttdbg(1, "oldfile: %s\t newfile: %s", a->filename, mutt_b2s(newfile));
if (safe_symlink(a->filename, mutt_b2s(newfile)) == -1)
@@ -245,7 +246,7 @@ int mutt_edit_attachment(BODY *a)
mutt_buffer_strcpy(command, entry->editcommand);
mutt_rfc1524_expand_filename(entry->nametemplate,
- a->filename, newfile);
+ a->filename, newfile, 0);
muttdbg(1, "oldfile: %s\t newfile: %s", a->filename, mutt_b2s(newfile));
if (safe_symlink(a->filename, mutt_b2s(newfile)) == -1)
@@ -404,7 +405,7 @@ int mutt_view_attachment(FILE *fp, BODY *a, int flag, HEADER *hdr,
(fp ? 0 : MUTT_SANITIZE_ALLOW_SLASH) |
MUTT_SANITIZE_ALLOW_8BIT);
mutt_rfc1524_expand_filename(entry->nametemplate, fname,
- tempfile);
+ tempfile, 0);
FREE(&fname);
if (mutt_save_attachment(fp, a, mutt_b2s(tempfile), 0, NULL, 0) == -1)
@@ -979,7 +980,7 @@ int mutt_print_attachment(FILE *fp, BODY *a)
(fp ? 0 : MUTT_SANITIZE_ALLOW_SLASH) |
MUTT_SANITIZE_ALLOW_8BIT);
mutt_rfc1524_expand_filename(entry->nametemplate, sanitized_fname,
- newfile);
+ newfile, 0);
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..1eedaceb 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_filename(entry->nametemplate, fname, tempfile, 0);
FREE(&fname);
if (entry->command)
diff --git a/rfc1524.c b/rfc1524.c
index f1b13fc9..2fefc0e4 100644
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -496,7 +496,8 @@ int rfc1524_mailcap_lookup(BODY *a, char *type, size_t typelen, rfc1524_entry *e
*/
void mutt_rfc1524_expand_filename(const char *nametemplate,
const char *oldfile,
- BUFFER *newfile)
+ BUFFER *newfile,
+ int use_tmpdraftdir)
{
int i, j, k, ps;
const char *s;
@@ -601,7 +602,10 @@ void mutt_rfc1524_expand_filename(const char *nametemplate,
}
}
- mutt_adv_mktemp(newfile);
+ if (use_tmpdraftdir)
+ mutt_adv_mktemp_draft(newfile);
+ else
+ mutt_adv_mktemp(newfile);
}
/* If rfc1524_expand_command() is used on a recv'd message, then
diff --git a/rfc1524.h b/rfc1524.h
index e74feb37..7d0f2426 100644
--- a/rfc1524.h
+++ b/rfc1524.h
@@ -37,7 +37,7 @@ 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_filename(const char *, const char *, BUFFER *, int);
int rfc1524_mailcap_lookup(BODY *, char *, size_t, rfc1524_entry *, int);
int mutt_rename_file(const char *, const char *);
--
2.55.0