From f8fcb55f91334195a80bfcde5fc788c88cbf47cf Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 23 May 2020 09:21:57 +0800 Subject: [PATCH] Allow ';' as a Maildir flags seperator Isync uses this by default on Windows where ':' is an invalid character in file names. Also try to preserve the existing separator character when generating a new file name. --- lib/mu-maildir.c | 22 +++++++++++++--------- lib/mu-msg-part.c | 2 +- man/mu-index.1 | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/mu-maildir.c b/lib/mu-maildir.c index c8c74f41..50e10e0e 100644 --- a/lib/mu-maildir.c +++ b/lib/mu-maildir.c @@ -663,12 +663,13 @@ mu_maildir_get_flags_from_path (const char *path) g_return_val_if_fail (path, MU_FLAG_INVALID); /* try to find the info part */ - /* note that we can use either the ':' or '!' as separator; + /* note that we can use either the ':', ';', or '!' as separator; * the former is the official, but as it does not work on e.g. VFAT * file systems, some Maildir implementations use the latter instead * (or both). For example, Tinymail/modest does this. The python * documentation at http://docs.python.org/lib/mailbox-maildir.html - * mentions the '!' as well as a 'popular choice' + * mentions the '!' as well as a 'popular choice'. Isync uses ';' by + * default on Windows. */ /* we check the dir -- */ @@ -702,7 +703,7 @@ mu_maildir_get_flags_from_path (const char *path) info = strrchr (path, '2'); if (!info || info == path || - (info[-1] != ':' && info[-1] != '!') || + (info[-1] != ':' && info[-1] != '!' && info[-1] != ';') || (info[1] != ',')) return MU_FLAG_NONE; else @@ -729,7 +730,7 @@ mu_maildir_get_flags_from_path (const char *path) */ static gchar* get_new_path (const char *mdir, const char *mfile, MuFlags flags, - const char* custom_flags) + const char* custom_flags, char flags_sep) { if (flags & MU_FLAG_NEW) return g_strdup_printf ("%s%cnew%c%s", @@ -739,9 +740,9 @@ get_new_path (const char *mdir, const char *mfile, MuFlags flags, const char *flagstr; flagstr = mu_flags_to_str_s (flags, MU_FLAG_TYPE_MAILFILE); - return g_strdup_printf ("%s%ccur%c%s:2,%s%s", + return g_strdup_printf ("%s%ccur%c%s%c2,%s%s", mdir, G_DIR_SEPARATOR, G_DIR_SEPARATOR, - mfile, flagstr, + mfile, flags_sep, flagstr, custom_flags ? custom_flags : ""); } } @@ -784,7 +785,7 @@ char* mu_maildir_get_new_path (const char *oldpath, const char *new_mdir, MuFlags newflags, gboolean new_name) { - char *mfile, *mdir, *custom_flags, *newpath; + char *mfile, *mdir, *custom_flags, *newpath, flags_sep = ':'; g_return_val_if_fail (oldpath, NULL); @@ -803,11 +804,14 @@ mu_maildir_get_new_path (const char *oldpath, const char *new_mdir, char *cur; mfile = g_path_get_basename (oldpath); for (cur = &mfile[strlen(mfile)-1]; cur > mfile; --cur) { - if ((*cur == ':' || *cur == '!') && + if ((*cur == ':' || *cur == '!' || *cur == ';') && (cur[1] == '2' && cur[2] == ',')) { /* get the custom flags (if any) */ custom_flags = mu_flags_custom_from_str (cur + 3); + /* preserve the existing flags separator + * in the new file name */ + flags_sep = *cur; cur[0] = '\0'; /* strip the flags */ break; } @@ -815,7 +819,7 @@ mu_maildir_get_new_path (const char *oldpath, const char *new_mdir, } newpath = get_new_path (new_mdir ? new_mdir : mdir, - mfile, newflags, custom_flags); + mfile, newflags, custom_flags, flags_sep); g_free (mfile); g_free (mdir); g_free (custom_flags); diff --git a/lib/mu-msg-part.c b/lib/mu-msg-part.c index 099274d2..3d33c98f 100644 --- a/lib/mu-msg-part.c +++ b/lib/mu-msg-part.c @@ -263,7 +263,7 @@ cleanup_filename (char *fname) /* replace control characters, slashes, and colons by '-' */ for (cur = fname; cur && *cur; cur = g_utf8_next_char (cur)) { uc = g_utf8_get_char (cur); - if (g_unichar_iscntrl (uc) || uc == '/' || uc == ':') + if (g_unichar_iscntrl (uc) || uc == '/' || uc == ':' || uc == ';') g_string_append_unichar (gstr, '-'); else g_string_append_unichar (gstr, uc); diff --git a/man/mu-index.1 b/man/mu-index.1 index c5b6008c..ff20e765 100644 --- a/man/mu-index.1 +++ b/man/mu-index.1 @@ -21,7 +21,7 @@ init\fR to initialize the database. \fBindex\fR understands Maildirs as defined by Daniel Bernstein for \fBqmail\fR(7). In addition, it understands recursive Maildirs (Maildirs within Maildirs), Maildir++. It can also deal with VFAT-based Maildirs -which use '!' as the separators instead of ':'. +which use '!' or ';' as the separators instead of ':'. E-mail messages which are not stored in something resembling a maildir leaf-directory (\fIcur\fR and \fInew\fR) are ignored, as are the cache