diff --git a/lib/mu-maildir.c b/lib/mu-maildir.c index dc8837fa..cb756b5b 100644 --- a/lib/mu-maildir.c +++ b/lib/mu-maildir.c @@ -766,9 +766,9 @@ get_new_basename (void) char* mu_maildir_get_new_path (const char *oldpath, const char *new_mdir, - MuFlags newflags) + MuFlags newflags, gboolean new_name) { - char *mfile, *mdir, *custom_flags, *newpath;/**cur;q*/ + char *mfile, *mdir, *custom_flags, *newpath; g_return_val_if_fail (oldpath, NULL); @@ -779,21 +779,23 @@ mu_maildir_get_new_path (const char *oldpath, const char *new_mdir, if (!mdir) return NULL; - /* 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; */ - /* } */ - /* } */ - - mfile = get_new_basename (); + if (new_name) + mfile = get_new_basename (); + else { + /* determine the name of the mailfile, stripped of its flags, as well + * as any custom (non-standard) flags */ + char *cur; + 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, custom_flags); @@ -859,7 +861,7 @@ msg_move (const char* src, const char *dst, GError **err) gchar* mu_maildir_move_message (const char* oldpath, const char* targetmdir, - MuFlags newflags, gboolean ignore_dups, + MuFlags newflags, gboolean ignore_dups, gboolean new_name, GError **err) { char *newfullpath; @@ -869,7 +871,7 @@ mu_maildir_move_message (const char* oldpath, const char* targetmdir, g_return_val_if_fail (oldpath, FALSE); newfullpath = mu_maildir_get_new_path (oldpath, targetmdir, - newflags); + newflags, new_name); if (!newfullpath) { mu_util_g_set_error (err, MU_ERROR_FILE, "failed to determine targetpath"); diff --git a/lib/mu-maildir.h b/lib/mu-maildir.h index 03910714..93d6324b 100644 --- a/lib/mu-maildir.h +++ b/lib/mu-maildir.h @@ -160,12 +160,14 @@ MuFlags mu_maildir_get_flags_from_path (const char* pathname); * it in the current one. The maildir is the absolute file system * path, without the 'cur' or 'new' * @param new_flags the new flags for this message + * @param new_name whether to create a new unique name, or keep the + * old one * * @return a new path name; use g_free when done with. NULL in case of * error. */ char* mu_maildir_get_new_path (const char *oldpath, const char *new_mdir, - MuFlags new_flags); + MuFlags new_flags, gboolean new_name); /** * get the maildir for a certain message path, ie, the path *before* @@ -192,16 +194,16 @@ char* mu_maildir_get_maildir_from_path (const char* path); * moved to another directory (say, from new/ to cur/) * @param flags to set for the target (influences the filename, path) * @param ignore_dups whether to silent ignore the src=target case (and return TRUE) - * @param err (may be NULL) may contain error information; note if the - * function return FALSE, err is not set for all error condition - * (ie. not for parameter errors) + * @param new_name whether to create a new unique name, or keep the + * old one + * @param err receives error information * * @return return the full path name of the target file (g_free) if * the move succeeded, NULL otherwise */ gchar* mu_maildir_move_message (const char* oldpath, const char* targetmdir, MuFlags newflags, gboolean ignore_dups, - GError **err); + gboolean new_name, GError **err); G_END_DECLS diff --git a/lib/mu-msg.c b/lib/mu-msg.c index 4e6b5dbe..8ce5b4af 100644 --- a/lib/mu-msg.c +++ b/lib/mu-msg.c @@ -855,7 +855,8 @@ get_target_mdir (MuMsg *msg, const char *target_maildir, GError **err) */ gboolean mu_msg_move_to_maildir (MuMsg *self, const char *maildir, - MuFlags flags, gboolean ignore_dups, GError **err) + MuFlags flags, gboolean ignore_dups, gboolean new_name, + GError **err) { char *newfullpath; char *targetmdir; @@ -871,7 +872,7 @@ mu_msg_move_to_maildir (MuMsg *self, const char *maildir, newfullpath = mu_maildir_move_message (mu_msg_get_path (self), targetmdir, flags, - ignore_dups, err); + ignore_dups, new_name, err); /* update the message path and the flags; they may have * changed */ if (!newfullpath) { diff --git a/lib/mu-msg.h b/lib/mu-msg.h index 9f2bf452..86bf9909 100644 --- a/lib/mu-msg.h +++ b/lib/mu-msg.h @@ -475,6 +475,8 @@ char* mu_msg_to_sexp (MuMsg *msg, unsigned docid, * rootmaildir. e.g. "/archive" * @param flags to set for the target (influences the filename, path) * @param silently ignore the src=target case (return TRUE) + * @param new_name whether to create a new unique name, or keep the + * old one * @param err (may be NULL) may contain error information; note if the * function return FALSE, err is not set for all error condition * (ie. not for parameter error @@ -483,6 +485,7 @@ char* mu_msg_to_sexp (MuMsg *msg, unsigned docid, */ gboolean mu_msg_move_to_maildir (MuMsg *msg, const char *maildir, MuFlags flags, gboolean ignore_dups, + gboolean new_name, GError **err);