talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 15784c7a971595c53c0088c80ecde92d126b23eb
parent eaf1e7a4176909b64ccea6dd43360eb3db73ce44
Author: Colin Leroy <colin@colino.net>
Date:   Sun, 15 Jun 2014 14:19:41 +0200

Fix creating a numeric directory when a message with the same number exists

Diffstat:
Msrc/mh.c | 44+++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/src/mh.c b/src/mh.c @@ -43,6 +43,7 @@ #include "statusbar.h" #include "gtkutils.h" #include "timing.h" +#include "msgcache.h" /* Define possible missing constants for Windows. */ #ifdef G_OS_WIN32 @@ -368,6 +369,11 @@ static gchar *mh_get_new_msg_filename(FolderItem *dest) destpath = folder_item_get_path(dest); cm_return_val_if_fail(destpath != NULL, NULL); + if (dest->last_num < 0) { + mh_get_last_num(dest->folder, dest); + if (dest->last_num < 0) return NULL; + } + if (!is_dir_exist(destpath)) make_dir_hier(destpath); @@ -867,6 +873,30 @@ static gchar *mh_item_get_path(Folder *folder, FolderItem *item) return real_path; } +static gboolean mh_renumber_msg(MsgInfo *info) +{ + gchar *src, *dest; + gboolean result = FALSE; + guint num; + cm_return_val_if_fail(info != NULL, FALSE); + + src = folder_item_fetch_msg(info->folder, info->msgnum); + dest = mh_get_new_msg_filename(info->folder); + num = info->folder->last_num + 1; + + if (move_file(src, dest, FALSE) == 0) { + msgcache_remove_msg(info->folder->cache, info->msgnum); + info->msgnum = num; + msgcache_add_msg(info->folder->cache, info); + result = TRUE; + } + + g_free(src); + g_free(dest); + + return result; +} + static FolderItem *mh_create_folder(Folder *folder, FolderItem *parent, const gchar *name) { @@ -884,12 +914,24 @@ static FolderItem *mh_create_folder(Folder *folder, FolderItem *parent, if (!is_dir_exist(path)) if (make_dir_hier(path) != 0) return NULL; - + real_name = mh_filename_from_utf8(name); fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, real_name, NULL); g_free(real_name); g_free(path); + if (to_number(name) > 0) { + MsgInfo *info = folder_item_get_msginfo(parent, to_number(name)); + if (info != NULL) { + gboolean ok = mh_renumber_msg(info); + procmsg_msginfo_free(info); + if (!ok) { + g_free(fullpath); + return NULL; + } + } + } + if (make_dir(fullpath) < 0) { g_free(fullpath); return NULL;