Change format for filenames

It seems some tools try to interpret the filename of message files,
even though they shouldn't:
   "Do not try to extract information from unique names."

In particular, they seem to interpret the first part of the name (before
the first dot) as the # of seconds since the Unix epoch (ie.,
time(NULL)). That's not what mu/mu4e put there.

So, let's conform a bit more to the expected filename (as per the
maildir spec), so we're not confusing those tools.
This commit is contained in:
djcb
2015-10-02 17:43:38 +03:00
parent 4774429ad6
commit a350e2047d
3 changed files with 20 additions and 14 deletions

View File

@ -750,19 +750,21 @@ mu_maildir_get_maildir_from_path (const char* path)
static char*
get_new_basename (void)
{
char date[9]; /* YYYYMMDD */
char hostname[32]; /* should be enough...*/
long int rnd;
time_t now;
time_t now;
char hostname[64];
if (gethostname (hostname, sizeof(hostname)) == -1)
memcpy (hostname, "localhost", sizeof(hostname));
else
hostname[sizeof(hostname)-1] = '\0';
now = time(NULL);
strftime (date, sizeof(date), "%Y%m%d", localtime(&now));
if (gethostname (hostname, sizeof(hostname)) != 0)
memcpy (hostname, "hostname", strlen("hostname"));
rnd = random ();
return g_strdup_printf ("%s-%08x-%s", date,
(unsigned)rnd, hostname);
return g_strdup_printf ("%u.%8x%8x.%s",
(guint)now,
g_random_int(),
(gint32)g_get_monotonic_time (),
hostname);
}