mirror of https://github.com/djcb/mu.git
* lib: make renaming messages upon moving them optional
This commit is contained in:
parent
6e9390d5c2
commit
7cb3bb9e36
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue