From a350e2047dd32a5877adae6845a5bca52206c48d Mon Sep 17 00:00:00 2001 From: djcb Date: Fri, 2 Oct 2015 17:43:38 +0300 Subject: [PATCH] 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. --- lib/mu-maildir.c | 22 ++++++++++++---------- lib/tests/test-mu-maildir.c | 5 ++++- mu4e/mu4e-draft.el | 7 ++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/mu-maildir.c b/lib/mu-maildir.c index 51c028bc..2bedb8b9 100644 --- a/lib/mu-maildir.c +++ b/lib/mu-maildir.c @@ -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); } diff --git a/lib/tests/test-mu-maildir.c b/lib/tests/test-mu-maildir.c index 358ad9c6..3b634ebb 100644 --- a/lib/tests/test-mu-maildir.c +++ b/lib/tests/test-mu-maildir.c @@ -481,7 +481,10 @@ test_mu_maildir_get_new_path_new (void) str = mu_maildir_get_new_path (paths[i].oldpath, NULL, paths[i].flags, TRUE); newbase = g_path_get_basename (str); - assert_matches_regexp (newbase, "\\d{8}-[[:xdigit:]]{8}-[[:alpha:]]+(:2,.*)?"); + assert_matches_regexp (newbase, + "\\d+\\." + "[[:xdigit:]]{16}\\." + "[[:alpha:]]+(:2,.*)?"); g_free (newbase); g_free(str); } diff --git a/mu4e/mu4e-draft.el b/mu4e/mu4e-draft.el index 3308d38d..a017b7f1 100644 --- a/mu4e/mu4e-draft.el +++ b/mu4e/mu4e-draft.el @@ -309,9 +309,10 @@ You can append flags." (save-match-data (substring system-name (string-match "^[^.]+" system-name) (match-end 0)))))) - (format "%s-%02x%04x-%s:2,%s" - (format-time-string "%Y%m%d" (current-time)) - (random 255) (random 65535) hostname (or flagstr "")))) + (format "%s.%04x%04x%04x%04x.%s:2,%s" + (format-time-string "%s" (current-time)) + (random 65535) (random 65535) (random 65535) (random 65535) + hostname (or flagstr "")))) (defun mu4e~draft-common-construct () "Construct the common headers for each message."