* lib: make renaming messages upon moving them optional
This commit is contained in:
@ -766,9 +766,9 @@ get_new_basename (void)
|
|||||||
|
|
||||||
char*
|
char*
|
||||||
mu_maildir_get_new_path (const char *oldpath, const char *new_mdir,
|
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);
|
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)
|
if (!mdir)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* determine the name of the mailfile, stripped of its flags, as well
|
if (new_name)
|
||||||
* as any custom (non-standard) flags */
|
mfile = get_new_basename ();
|
||||||
/* /\* mfile = g_path_get_basename (oldpath); *\/ */
|
else {
|
||||||
|
/* determine the name of the mailfile, stripped of its flags, as well
|
||||||
/* for (cur = &mfile[strlen(mfile)-1]; cur > mfile; --cur) { */
|
* as any custom (non-standard) flags */
|
||||||
/* if ((*cur == ':' || *cur == '!') && */
|
char *cur;
|
||||||
/* (cur[1] == '2' && cur[2] == ',')) { */
|
mfile = g_path_get_basename (oldpath);
|
||||||
/* /\* get the custom flags (if any) *\/ */
|
for (cur = &mfile[strlen(mfile)-1]; cur > mfile; --cur) {
|
||||||
/* custom_flags = mu_flags_custom_from_str (cur + 3); */
|
if ((*cur == ':' || *cur == '!') &&
|
||||||
/* cur[0] = '\0'; /\* strip the flags *\/ */
|
(cur[1] == '2' && cur[2] == ',')) {
|
||||||
/* break; */
|
/* 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 ();
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newpath = get_new_path (new_mdir ? new_mdir : mdir,
|
newpath = get_new_path (new_mdir ? new_mdir : mdir,
|
||||||
mfile, newflags, custom_flags);
|
mfile, newflags, custom_flags);
|
||||||
@ -859,7 +861,7 @@ msg_move (const char* src, const char *dst, GError **err)
|
|||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
mu_maildir_move_message (const char* oldpath, const char* targetmdir,
|
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)
|
GError **err)
|
||||||
{
|
{
|
||||||
char *newfullpath;
|
char *newfullpath;
|
||||||
@ -869,7 +871,7 @@ mu_maildir_move_message (const char* oldpath, const char* targetmdir,
|
|||||||
g_return_val_if_fail (oldpath, FALSE);
|
g_return_val_if_fail (oldpath, FALSE);
|
||||||
|
|
||||||
newfullpath = mu_maildir_get_new_path (oldpath, targetmdir,
|
newfullpath = mu_maildir_get_new_path (oldpath, targetmdir,
|
||||||
newflags);
|
newflags, new_name);
|
||||||
if (!newfullpath) {
|
if (!newfullpath) {
|
||||||
mu_util_g_set_error (err, MU_ERROR_FILE,
|
mu_util_g_set_error (err, MU_ERROR_FILE,
|
||||||
"failed to determine targetpath");
|
"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
|
* it in the current one. The maildir is the absolute file system
|
||||||
* path, without the 'cur' or 'new'
|
* path, without the 'cur' or 'new'
|
||||||
* @param new_flags the new flags for this message
|
* @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
|
* @return a new path name; use g_free when done with. NULL in case of
|
||||||
* error.
|
* error.
|
||||||
*/
|
*/
|
||||||
char* mu_maildir_get_new_path (const char *oldpath, const char *new_mdir,
|
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*
|
* 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/)
|
* moved to another directory (say, from new/ to cur/)
|
||||||
* @param flags to set for the target (influences the filename, path)
|
* @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 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
|
* @param new_name whether to create a new unique name, or keep the
|
||||||
* function return FALSE, err is not set for all error condition
|
* old one
|
||||||
* (ie. not for parameter errors)
|
* @param err receives error information
|
||||||
*
|
*
|
||||||
* @return return the full path name of the target file (g_free) if
|
* @return return the full path name of the target file (g_free) if
|
||||||
* the move succeeded, NULL otherwise
|
* the move succeeded, NULL otherwise
|
||||||
*/
|
*/
|
||||||
gchar* mu_maildir_move_message (const char* oldpath, const char* targetmdir,
|
gchar* mu_maildir_move_message (const char* oldpath, const char* targetmdir,
|
||||||
MuFlags newflags, gboolean ignore_dups,
|
MuFlags newflags, gboolean ignore_dups,
|
||||||
GError **err);
|
gboolean new_name, GError **err);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|||||||
@ -855,7 +855,8 @@ get_target_mdir (MuMsg *msg, const char *target_maildir, GError **err)
|
|||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
mu_msg_move_to_maildir (MuMsg *self, const char *maildir,
|
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 *newfullpath;
|
||||||
char *targetmdir;
|
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),
|
newfullpath = mu_maildir_move_message (mu_msg_get_path (self),
|
||||||
targetmdir, flags,
|
targetmdir, flags,
|
||||||
ignore_dups, err);
|
ignore_dups, new_name, err);
|
||||||
/* update the message path and the flags; they may have
|
/* update the message path and the flags; they may have
|
||||||
* changed */
|
* changed */
|
||||||
if (!newfullpath) {
|
if (!newfullpath) {
|
||||||
|
|||||||
@ -475,6 +475,8 @@ char* mu_msg_to_sexp (MuMsg *msg, unsigned docid,
|
|||||||
* rootmaildir. e.g. "/archive"
|
* rootmaildir. e.g. "/archive"
|
||||||
* @param flags to set for the target (influences the filename, path)
|
* @param flags to set for the target (influences the filename, path)
|
||||||
* @param silently ignore the src=target case (return TRUE)
|
* @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
|
* @param err (may be NULL) may contain error information; note if the
|
||||||
* function return FALSE, err is not set for all error condition
|
* function return FALSE, err is not set for all error condition
|
||||||
* (ie. not for parameter error
|
* (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,
|
gboolean mu_msg_move_to_maildir (MuMsg *msg, const char *maildir,
|
||||||
MuFlags flags, gboolean ignore_dups,
|
MuFlags flags, gboolean ignore_dups,
|
||||||
|
gboolean new_name,
|
||||||
GError **err);
|
GError **err);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user