[Commits] [SCM] claws branch, master, updated. 3.10.1-57-g42e1120

Colin colin at claws-mail.org
Sun Jun 15 14:55:40 CEST 2014


The branch master of project "claws" (Claws Mail) has been updated
       via  42e1120c430aa5da7d3e332200a5f1060a61aafc (commit)
       via  42eac1e8f7624533bfff86e14ae5ac007ebbe57d (commit)
       via  15784c7a971595c53c0088c80ecde92d126b23eb (commit)
      from  eaf1e7a4176909b64ccea6dd43360eb3db73ce44 (commit)

Summary of changes:
 src/common/utils.c |   22 +++++++++++++-
 src/imap.c         |   85 ++++++++++++++++++++++++++++++++++++++++++----------
 src/mh.c           |   44 ++++++++++++++++++++++++++-
 3 files changed, 134 insertions(+), 17 deletions(-)


- Log -----------------------------------------------------------------
commit 42e1120c430aa5da7d3e332200a5f1060a61aafc
Author: Colin Leroy <colin at colino.net>
Date:   Sun Jun 15 14:53:31 2014 +0200

    Cache files with a dot in front when a directory with the same number exists. Fixes bug #3212, "When msgnum matches a sub-folder name, fetch fails"

diff --git a/src/common/utils.c b/src/common/utils.c
index b37a568..8382176 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -2355,6 +2355,12 @@ gint remove_numbered_files(const gchar *dir, guint first, guint last)
 	if (first == last) {
 		/* Skip all the dir reading part. */
 		gchar *filename = g_strdup_printf("%s%s%u", dir, G_DIR_SEPARATOR_S, first);
+		if (is_dir_exist(filename)) {
+			/* a numbered directory with this name exists,
+			 * remove the dot-file instead */
+			g_free(filename);
+			filename = g_strdup_printf("%s%s.%u", dir, G_DIR_SEPARATOR_S, first);
+		}
 		if (claws_unlink(filename) < 0) {
 			FILE_OP_ERROR(filename, "unlink");
 			g_free(filename);
@@ -2381,8 +2387,14 @@ gint remove_numbered_files(const gchar *dir, guint first, guint last)
 	while ((dir_name = g_dir_read_name(dp)) != NULL) {
 		file_no = to_number(dir_name);
 		if (file_no > 0 && first <= file_no && file_no <= last) {
-			if (is_dir_exist(dir_name))
+			if (is_dir_exist(dir_name)) {
+				gchar *dot_file = g_strdup_printf(".%s", dir_name);
+				if (is_file_exist(dot_file) && claws_unlink(dot_file) < 0) {
+					FILE_OP_ERROR(dot_file, "unlink");
+				}
+				g_free(dot_file);
 				continue;
+			}
 			if (claws_unlink(dir_name) < 0)
 				FILE_OP_ERROR(dir_name, "unlink");
 		}
@@ -2439,6 +2451,14 @@ gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist)
 			continue;
 		if (file_no > 0 && g_hash_table_lookup(wanted_files, GINT_TO_POINTER(file_no)) == NULL) {
 			debug_print("removing unwanted file %d from %s\n", file_no, dir);
+			if (is_dir_exist(dir_name)) {
+				gchar *dot_file = g_strdup_printf(".%s", dir_name);
+				if (is_file_exist(dot_file) && claws_unlink(dot_file) < 0) {
+					FILE_OP_ERROR(dot_file, "unlink");
+				}
+				g_free(dot_file);
+				continue;
+			}
 			if (claws_unlink(dir_name) < 0)
 				FILE_OP_ERROR(dir_name, "unlink");
 		}
diff --git a/src/imap.c b/src/imap.c
index 9086635..fc3c50d 100644
--- a/src/imap.c
+++ b/src/imap.c
@@ -1330,20 +1330,38 @@ static guint get_file_size_with_crs(const gchar *filename)
 	return cnt;
 }
 
-static void imap_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
+static gchar *imap_get_cached_filename(FolderItem *item, guint msgnum)
 {
 	gchar *path, *filename;
 
+	cm_return_val_if_fail(item != NULL, NULL);
+
 	path = folder_item_get_path(item);
 
 	if (!is_dir_exist(path)) {
 		g_free(path);
-		return;
+		return NULL;
 	}
 
-	filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
+	filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msgnum), NULL);
+
+	if (is_dir_exist(filename)) {
+		g_free(filename);
+		filename = g_strconcat(path, G_DIR_SEPARATOR_S, ".", itos(msgnum), NULL);
+	}
 	g_free(path);
 
+	return filename;
+}
+
+static void imap_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
+{
+	gchar *filename;
+
+	filename = imap_get_cached_filename(item, msginfo->msgnum);
+
+	cm_return_if_fail(filename != NULL);
+
 	if (is_file_exist(filename)) {
 		claws_unlink(filename);
 	}
@@ -1481,9 +1499,11 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
 	path = folder_item_get_path(item);
 	if (!is_dir_exist(path))
 		make_dir_hier(path);
-	filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
 	g_free(path);
+
+	filename = imap_get_cached_filename(item, uid);
 	debug_print("trying to fetch cached %s\n", filename);
+
 	if (is_file_exist(filename)) {
 		/* see whether the local file represents the whole message
 		 * or not. As the IMAP server reports size with \r chars,
@@ -1581,7 +1601,7 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
 
 static gboolean imap_is_msg_fully_cached(Folder *folder, FolderItem *item, gint uid)
 {
-	gchar *path, *filename;
+	gchar *filename;
 	guint size = 0;
 	MsgInfo *cached = msgcache_get_msg(item->cache,uid);
 	
@@ -1592,14 +1612,9 @@ static gboolean imap_is_msg_fully_cached(Folder *folder, FolderItem *item, gint
 		procmsg_msginfo_free(cached);
 		return TRUE;
 	}
-	path = folder_item_get_path(item);
-	if (!is_dir_exist(path)) {
-		g_free(path);
-		return FALSE;
-	}
 
-	filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
-	g_free(path);
+	filename = imap_get_cached_filename(item, uid);
+
 	if (is_file_exist(filename)) {
 		if (cached && cached->total_size == cached->size) {
 			/* fast path */

commit 42eac1e8f7624533bfff86e14ae5ac007ebbe57d
Author: Colin Leroy <colin at colino.net>
Date:   Sun Jun 15 14:20:15 2014 +0200

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

diff --git a/src/imap.c b/src/imap.c
index 8870719..9086635 100644
--- a/src/imap.c
+++ b/src/imap.c
@@ -290,6 +290,12 @@ static FolderItem *imap_create_special_folder
 static gint imap_do_copy_msgs		(Folder		*folder,
 					 FolderItem	*dest,
 					 MsgInfoList	*msglist,
+					 GHashTable	*relation,
+					 gboolean	 same_dest_ok);
+
+static gint imap_do_remove_msgs		(Folder		*folder,
+					 FolderItem	*dest,
+					 MsgInfoList	*msglist,
 					 GHashTable	*relation);
 
 static void imap_delete_all_cached_messages	(FolderItem	*item);
@@ -1810,7 +1816,8 @@ static GSList *flatten_mailimap_set(struct mailimap_set * set)
 	return result;
 }
 static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest, 
-			      MsgInfoList *msglist, GHashTable *relation)
+			      MsgInfoList *msglist, GHashTable *relation,
+			      gboolean same_dest_ok)
 {
 	FolderItem *src;
 	gchar *destdir;
@@ -1834,7 +1841,7 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
 
 	msginfo = (MsgInfo *)msglist->data;
 	src = msginfo->folder;
-	if (src == dest) {
+	if (!same_dest_ok && src == dest) {
 		g_warning("the src folder is identical to the dest.\n");
 		return -1;
 	}
@@ -2018,10 +2025,32 @@ static gint imap_copy_msgs(Folder *folder, FolderItem *dest,
 	msginfo = (MsgInfo *)msglist->data;
 	g_return_val_if_fail(msginfo->folder != NULL, -1);
 
-	ret = imap_do_copy_msgs(folder, dest, msglist, relation);
+	ret = imap_do_copy_msgs(folder, dest, msglist, relation, FALSE);
 	return ret;
 }
 
+static gboolean imap_renumber_msg(MsgInfo *info)
+{
+	GSList msglist;
+	int ret;
+
+	g_return_val_if_fail(info != NULL, -1);
+
+	msglist.data = info;
+	msglist.next = NULL;
+
+	ret = imap_do_copy_msgs(info->folder->folder, info->folder, &msglist,
+				NULL, TRUE);
+	if (ret == 0)
+		ret = imap_do_remove_msgs(info->folder->folder, info->folder,
+					  &msglist, NULL);
+
+	if (ret == 0)
+		ret = folder_item_scan_full(info->folder, FALSE);
+
+	return ret == 0;
+}
+
 static gboolean imap_matcher_type_is_local(gint matchertype)
 {
 	switch (matchertype) {
@@ -3069,6 +3098,17 @@ static FolderItem *imap_create_folder(Folder *folder, FolderItem *parent,
 	g_return_val_if_fail(parent != NULL, NULL);
 	g_return_val_if_fail(name != NULL, NULL);
 
+	if (to_number(name) > 0) {
+		MsgInfo *info = folder_item_get_msginfo(parent, to_number(name));
+		if (info != NULL) {
+			gboolean ok = imap_renumber_msg(info);
+			procmsg_msginfo_free(info);
+			if (!ok) {
+				return NULL;
+			}
+		}
+	}
+
 	debug_print("getting session...\n");
 	session = imap_session_get(folder);
 	if (!session) {

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

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

diff --git a/src/mh.c b/src/mh.c
index e7b9888..b3fbc9c 100644
--- 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;

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list