* mu-maildir: preserve custom (non-standard) maildir file flags

This commit is contained in:
djcb 2012-06-13 09:10:22 +03:00
parent d497bfe804
commit 4dadca3a8d
3 changed files with 54 additions and 10 deletions

4
TODO
View File

@ -26,8 +26,6 @@
- show maildirs as a tree, not a list in speed bar
- mark message, decide what to do with them later
- make killing all windows (i.e.. 'fullscreen mode' optional)
- *BUG* don't remove unknown message flags when moving (see
https://github.com/djcb/mu/issues/20)
- improve fringe marks (see https://github.com/djcb/mu/issues/21)
** Done
@ -52,6 +50,8 @@
- *FIX* fix for strings where len (g_utf8_strdown (str)) > len (str)
- make sure marks correspond to the *current* message in message view (see
https://github.com/djcb/mu/issues/26)
- *FIX* don't remove unknown message flags when moving (see
https://github.com/djcb/mu/issues/20)

View File

@ -711,7 +711,8 @@ mu_maildir_get_flags_from_path (const char *path)
*
*/
static gchar*
get_new_path (const char *mdir, const char *mfile, MuFlags flags)
get_new_path (const char *mdir, const char *mfile, MuFlags flags,
const char* custom_flags)
{
if (flags & MU_FLAG_NEW)
return g_strdup_printf ("%s%cnew%c%s",
@ -721,9 +722,10 @@ 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",
return g_strdup_printf ("%s%ccur%c%s:2,%s%s",
mdir, G_DIR_SEPARATOR, G_DIR_SEPARATOR,
mfile, flagstr);
mfile, flagstr,
custom_flags ? custom_flags : "");
}
}
@ -755,32 +757,35 @@ char*
mu_maildir_get_new_path (const char *oldpath, const char *new_mdir,
MuFlags newflags)
{
char *mfile, *mdir, *newpath, *cur;
char *mfile, *mdir, *custom_flags, *newpath, *cur;
g_return_val_if_fail (oldpath, NULL);
mfile = newpath = NULL;
mfile = newpath = custom_flags = NULL;
/* determine the maildir */
mdir = mu_maildir_get_maildir_from_path (oldpath);
if (!mdir)
return NULL;
/* determine the name of the mailfile, stripped of its flags */
/* determine the name of the mailfile, stripped of its flags, as well
* as any custom (non-standard) flags */
mfile = g_path_get_basename (oldpath);
for (cur = &mfile[strlen(mfile)-1]; cur > mfile; --cur) {
if ((*cur == ':' || *cur == '!') &&
(cur[1] == '2' && cur[2] == ',')) {
/* get the custom flags (if any) */
custom_flags = mu_flags_custom_from_str (cur + 3);
cur[0] = '\0'; /* strip the flags */
break;
}
}
newpath = get_new_path (new_mdir ? new_mdir : mdir,
mfile, newflags);
mfile, newflags, custom_flags);
g_free (mfile);
g_free (mdir);
g_free (custom_flags);
return newpath;
}

View File

@ -517,6 +517,43 @@ test_mu_maildir_get_new_path_02 (void)
}
static void
test_mu_maildir_get_new_path_custom (void)
{
int i;
struct {
const char *oldpath;
MuFlags flags;
const char *targetdir;
const char *newpath;
} paths[] = {
{
"/home/foo/Maildir/test/cur/123456:2,FR",
MU_FLAG_REPLIED, "/home/foo/Maildir/blabla",
"/home/foo/Maildir/blabla/cur/123456:2,R"
}, {
"/home/foo/Maildir/test/cur/123456:2,hFeRllo123",
MU_FLAG_FLAGGED, "/home/foo/Maildir/blabla",
"/home/foo/Maildir/blabla/cur/123456:2,Fhello123"
}, {
"/home/foo/Maildir/test/cur/123456:2,abc",
MU_FLAG_PASSED, "/home/foo/Maildir/blabla",
"/home/foo/Maildir/blabla/cur/123456:2,Pabc"
}
};
for (i = 0; i != G_N_ELEMENTS(paths); ++i) {
gchar *str;
str = mu_maildir_get_new_path(paths[i].oldpath,
paths[i].targetdir,
paths[i].flags);
g_assert_cmpstr(str, ==, paths[i].newpath);
g_free(str);
}
}
static void
test_mu_maildir_get_maildir_from_path (void)
@ -573,6 +610,8 @@ main (int argc, char *argv[])
test_mu_maildir_get_new_path_01);
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-02",
test_mu_maildir_get_new_path_02);
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-custom",
test_mu_maildir_get_new_path_custom);
g_test_add_func("/mu-maildir/mu-maildir-get-flags-from-path",
test_mu_maildir_get_flags_from_path);