Default it to /var/tmp, so that files will survive an unfortunately
timed computer reboot.
Create two new functions for generating temp filenames in $tmpdraftdir:
- mutt_adv_mktemp_draft() for template-style naming
- mutt_buffer_mktemp_draft() for random naming with a "mutt" prefix.
---
globals.h | 1 +
init.h | 10 +++++++++-
muttlib.c | 13 +++++++------
protos.h | 13 +++++++++----
4 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/globals.h b/globals.h
index 0675348f..03e43c02 100644
--- a/globals.h
+++ b/globals.h
@@ -171,6 +171,7 @@ WHERE char *SslVerifyHostOverride;
WHERE mbchar_table *StChars;
WHERE char *Status;
WHERE char *Tempdir;
+WHERE char *TempDraftDir;
WHERE mbchar_table *Tochars;
WHERE char *TrashPath;
WHERE char *TSStatusFormat;
diff --git a/init.h b/init.h
index 29d54b34..c50164e7 100644
--- a/init.h
+++ b/init.h
@@ -4696,10 +4696,18 @@ struct option_t MuttVars[] = {
/*
** .pp
** This variable allows you to specify where Mutt will place its
- ** temporary files needed for displaying and composing messages. If
+ ** temporary files needed for displaying messages. If
** this variable is not set, the environment variable \fC$$$TMPDIR\fP is
** used. If \fC$$$TMPDIR\fP is not set then ``\fC/tmp\fP'' is used.
*/
+ { "tmpdraftdir", DT_PATH, R_NONE, {.p=&TempDraftDir},
{.p="/var/tmp"} },
+ /*
+ ** .pp
+ ** This variable allows you to specify where Mutt will place its
+ ** temporary files when composing messages. It defaults to
+ ** ``\fC/var/tmp\fP'' so that the files will survive a reboot in the
+ ** event of a crash or other unplanned computer shutdown.
+ */
{ "to_chars", DT_MBCHARTBL, R_BOTH, {.p=&Tochars}, {.p=" +TCFL"} },
/*
** .pp
diff --git a/muttlib.c b/muttlib.c
index 2022ee61..494c27d0 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -64,7 +64,7 @@ BODY *mutt_new_body (void)
* Renamed to mutt_adv_mktemp so I only have to change where it's
* called, and not all possible cases.
*/
-void mutt_adv_mktemp (BUFFER *buf)
+void _mutt_adv_mktemp (BUFFER *buf, const char *tempdir)
{
BUFFER *prefix = NULL;
char *suffix;
@@ -72,14 +72,14 @@ void mutt_adv_mktemp (BUFFER *buf)
if (!(buf->data && buf->data[0]))
{
- mutt_buffer_mktemp (buf);
+ _mutt_buffer_mktemp_pfx_sfx (buf, tempdir, "mutt", NULL);
}
else
{
prefix = mutt_buffer_pool_get ();
mutt_buffer_strcpy (prefix, buf->data);
mutt_sanitize_filename (prefix->data, MUTT_SANITIZE_ALLOW_8BIT);
- mutt_buffer_printf (buf, "%s/%s", NONULL (Tempdir), mutt_b2s (prefix));
+ mutt_buffer_printf (buf, "%s/%s", NONULL (tempdir), mutt_b2s (prefix));
if (lstat (mutt_b2s (buf), &sb) == -1 && errno == ENOENT)
goto out;
@@ -88,21 +88,22 @@ void mutt_adv_mktemp (BUFFER *buf)
*suffix = 0;
++suffix;
}
- _mutt_buffer_mktemp_pfx_sfx (buf, mutt_b2s (prefix), suffix);
+ _mutt_buffer_mktemp_pfx_sfx (buf, tempdir, mutt_b2s (prefix), suffix);
out:
mutt_buffer_pool_release (&prefix);
}
}
-void _mutt_buffer_mktemp (BUFFER *buf, const char *prefix, const char *suffix,
+void _mutt_buffer_mktemp (BUFFER *buf, const char *tempdir,
+ const char *prefix, const char *suffix,
const char *src, int line)
{
RANDOM64 random64;
mutt_random_bytes(random64.char_array, sizeof(random64));
mutt_buffer_printf (buf, "%s/%s-%s-%d-%d-%"PRIu64"%s%s",
- NONULL (Tempdir), NONULL (prefix), NONULL (Hostname),
+ NONULL (tempdir), NONULL (prefix), NONULL (Hostname),
(int) getuid (), (int) getpid (), random64.int_64,
suffix ? "." : "", NONULL (suffix));
muttdbg(3, "%s:%d: mutt_mktemp returns \"%s\".", src, line, mutt_b2s (buf));
diff --git a/protos.h b/protos.h
index 2c6b1aef..90a28b67 100644
--- a/protos.h
+++ b/protos.h
@@ -172,10 +172,15 @@ group_t *mutt_pattern_group (const char *);
REGEXP *mutt_compile_regexp (const char *, int);
-void mutt_adv_mktemp (BUFFER *);
-#define mutt_buffer_mktemp(a) _mutt_buffer_mktemp_pfx_sfx (a, "mutt", NULL)
-#define _mutt_buffer_mktemp_pfx_sfx(a,b,c) _mutt_buffer_mktemp (a, b, c,
__FILE__, __LINE__)
-void _mutt_buffer_mktemp (BUFFER *, const char *, const char *, const char *,
int);
+#define mutt_adv_mktemp(a) _mutt_adv_mktemp (a, Tempdir)
+#define mutt_adv_mktemp_draft(a) _mutt_adv_mktemp (a, TempDraftDir)
+void _mutt_adv_mktemp (BUFFER *, const char *);
+
+#define mutt_buffer_mktemp(a) _mutt_buffer_mktemp_pfx_sfx (a, Tempdir, "mutt",
NULL)
+#define mutt_buffer_mktemp_draft(a) _mutt_buffer_mktemp_pfx_sfx (a,
TempDraftDir, "mutt", NULL)
+
+#define _mutt_buffer_mktemp_pfx_sfx(a,b,c,d) _mutt_buffer_mktemp (a, b, c, d,
__FILE__, __LINE__)
+void _mutt_buffer_mktemp (BUFFER *, const char *, const char *, const char *,
const char *, int);
void mutt_account_hook (const char* url);
void mutt_alias_menu (char *, size_t, ALIAS *);
--
2.53.0