[PATCH 3/3] Proper part spec for top member of a bodystruct hierarchy



	* libtinymail-camel/camel-lite/bs/bodystruct.c: set proper part_spec
	of root part (it's empty, not "1").

	* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c,
	libtinymail-camel/tny-camel-bs-msg-receive-strategy.c:
	properly handle stored parts with part_spec == "" (as root part spec)
---
 ChangeLog                                          |    7 ++
 libtinymail-camel/camel-lite/bs/bodystruct.c       |    6 +-
 .../camel/providers/imap/camel-imap-folder.c       |   60 ++++++++++++++++----
 .../tny-camel-bs-msg-receive-strategy.c            |    6 ++-
 4 files changed, 64 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index af58c5e..26504cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-12-22  Jose Dapena Paz  <jdapena igalia com>
 
+	* libtinymail-camel/camel-lite/bs/bodystruct.c: set proper part_spec
+	of root part (it's empty, not "1").
+
+	* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c,
+	libtinymail-camel/tny-camel-bs-msg-receive-strategy.c:
+	properly handle stored parts with part_spec == "" (as root part spec)
+
 	* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c:
 	detect properly also TEXT stored mime parts in bodystruct.
 
diff --git a/libtinymail-camel/camel-lite/bs/bodystruct.c b/libtinymail-camel/camel-lite/bs/bodystruct.c
index de4d1cf..e602c28 100644
--- a/libtinymail-camel/camel-lite/bs/bodystruct.c
+++ b/libtinymail-camel/camel-lite/bs/bodystruct.c
@@ -661,7 +661,7 @@ bodystruct_part_decode (unsigned char **in, unsigned char *inend, bodystruct_t *
 	part->parent = parent;
 
 	if (parent) {
-		if (parent->part_spec) {
+		if (parent->part_spec && *parent->part_spec) {
 			if (!strcasecmp (parent->content.type, "message") && !strcasecmp (parent->content.subtype, "rfc822")) {
 				part->part_spec = g_strdup (parent->part_spec);
 			} else {
@@ -670,6 +670,8 @@ bodystruct_part_decode (unsigned char **in, unsigned char *inend, bodystruct_t *
 		} else {
 			part->part_spec = g_strdup_printf ("%d", num);
 		}
+	} else {
+		part->part_spec = g_strdup ("");
 	}
 
 	if (*inptr == '(') {
@@ -1132,7 +1134,7 @@ bodystruct_parse (guchar *inbuf, guint inlen, GError **err)
 		r = bodystruct_part_decode (&start, (unsigned char *) ( start + (inlen - lendif) ), NULL, 1, err);
 	}
 	if (!r->part_spec)
-		r->part_spec = g_strdup ("1");
+		r->part_spec = g_strdup ("");
 	return r;
 }
 
diff --git a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
index 6a32172..347b4e3 100644
--- a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
+++ b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
@@ -4798,28 +4798,40 @@ imap_get_cache_filename (CamelFolder *folder, const char *uid, const char *spec,
 
 	*state = CAMEL_FOLDER_PART_STATE_NOT_CACHED;
 
-	check = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+	if (spec && *spec)
+		check = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+	else
+		check = g_strdup_printf ("%s/%s", imap_folder->cache->path, uid);
 	if (g_file_test (check, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
 		*state = CAMEL_FOLDER_PART_STATE_CACHED_BINARY;
 		return check;
 	}
 
 	g_free (check);
-	check = g_strdup_printf ("%s/%s_%s_ENCODED", imap_folder->cache->path, uid, spec);
+	if (spec && *spec)
+		check = g_strdup_printf ("%s/%s_%s_ENCODED", imap_folder->cache->path, uid, spec);
+	else
+		check = g_strdup_printf ("%s/%s_ENCODED", imap_folder->cache->path, uid);
 	if (g_file_test (check, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
 		*state = CAMEL_FOLDER_PART_STATE_CACHED_ENCODED;
 		return check;
 	}
 
 	g_free (check);
-	check = g_strdup_printf ("%s/%s_%s.TEXT_ENCODED", imap_folder->cache->path, uid, spec);
+	if (spec && *spec)
+		check = g_strdup_printf ("%s/%s_%s_TEXT_ENCODED", imap_folder->cache->path, uid, spec);
+	else
+		check = g_strdup_printf ("%s/%s_TEXT_ENCODED", imap_folder->cache->path, uid);
 	if (g_file_test (check, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
 		*state = CAMEL_FOLDER_PART_STATE_CACHED_ENCODED;
 		return check;
 	}
 
 	g_free (check);
-	check = g_strdup_printf ("%s/%s_%s_CONVERTED", imap_folder->cache->path, uid, spec);
+	if (spec && *spec)
+		check = g_strdup_printf ("%s/%s_%s_CONVERTED", imap_folder->cache->path, uid, spec);
+	else
+		check = g_strdup_printf ("%s/%s_CONVERTED", imap_folder->cache->path, uid);
 	if (g_file_test (check, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
 		*state = CAMEL_FOLDER_PART_STATE_CACHED_CONVERTED;
 		return check;
@@ -5088,33 +5100,48 @@ imap_fetch (CamelFolder *folder, const char *uid, const char *spec, gboolean *bi
 
   if (binary && *binary) {
 	g_free (path);
-	path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+	if (spec && *spec)
+		path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+	else
+		path = g_strdup_printf ("%s/%s", imap_folder->cache->path, uid);
 	found = g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
   }
 
   if (!found) {
 	g_free (path);
-	path = g_strdup_printf ("%s/%s_%s_ENCODED", imap_folder->cache->path, uid, spec);
+	if (spec  && *spec)
+		path = g_strdup_printf ("%s/%s_%s_ENCODED", imap_folder->cache->path, uid, spec);
+	else
+		path = g_strdup_printf ("%s/%s_ENCODED", imap_folder->cache->path, uid);
 	found = g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
 	if (found) {
 		if (binary)
 			*binary = FALSE;
 	} else if (binary && *binary) {
 		g_free (path);
-		path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+		if (spec && *spec)
+			path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+		else
+			path = g_strdup_printf ("%s/%s", imap_folder->cache->path, uid);
 	}
   }
 
   if (!found) {
 	g_free (path);
-	path = g_strdup_printf ("%s/%s_%s.TEXT_ENCODED", imap_folder->cache->path, uid, spec);
+	if (spec && *spec)
+		path = g_strdup_printf ("%s/%s_%s.TEXT_ENCODED", imap_folder->cache->path, uid, spec);
+	else
+		path = g_strdup_printf ("%s/%s.TEXT_ENCODED", imap_folder->cache->path, uid);
 	found = g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
 	if (found) {
 		if (binary)
 			*binary = FALSE;
 	} else if (binary && *binary) {
 		g_free (path);
-		path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+		if (spec && *spec)
+			path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+		else
+			path = g_strdup_printf ("%s/%s", imap_folder->cache->path, uid);
 	}
   }
 
@@ -5155,9 +5182,15 @@ imap_fetch (CamelFolder *folder, const char *uid, const char *spec, gboolean *bi
 
 			if (binary && *binary && store->capabilities & IMAP_CAPABILITY_BINARY)
 			{
-				path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+				if (spec && *spec)
+					path = g_strdup_printf ("%s/%s_%s", imap_folder->cache->path, uid, spec);
+				else
+					path = g_strdup_printf ("%s/%s", imap_folder->cache->path, uid);
 			} else {
-				path = g_strdup_printf ("%s/%s_%s_ENCODED", imap_folder->cache->path, uid, spec);
+				if (spec && *spec)
+					path = g_strdup_printf ("%s/%s_%s_ENCODED", imap_folder->cache->path, uid, spec);
+				else
+					path = g_strdup_printf ("%s/%s_ENCODED", imap_folder->cache->path, uid);
 			}
 			fil = fopen (path, "w");
 
@@ -5237,7 +5270,10 @@ imap_fetch (CamelFolder *folder, const char *uid, const char *spec, gboolean *bi
 						fil = NULL;
 						unlink (path);
 						g_free (path);
-						path = g_strdup_printf ("%s/%s_%s_ENCODED", imap_folder->cache->path, uid, spec);
+						if (spec && *spec)
+							path = g_strdup_printf ("%s/%s_%s_ENCODED", imap_folder->cache->path, uid, spec);
+						else
+							path = g_strdup_printf ("%s/%s_ENCODED", imap_folder->cache->path, uid);
 						camel_imap_store_connect_unlock_start_idle (store);
 						goto fetch_retry;
 					}
diff --git a/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c b/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c
index 39708ae..0cb2d04 100644
--- a/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c
+++ b/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c
@@ -87,7 +87,11 @@ tny_camel_bs_msg_receive_strategy_start_receiving_part (TnyCamelBsMsgReceiveStra
 		CamelFolder *cfolder = _tny_camel_folder_get_camel_folder (TNY_CAMEL_FOLDER (folder));
 
 		if (TNY_IS_CAMEL_BS_MSG (part)) {
-			text_part_spec = g_strconcat (part_spec, ".TEXT", NULL);
+			if (part_spec && *part_spec) {
+				text_part_spec = g_strconcat (part_spec, ".TEXT", NULL);
+			} else {
+				text_part_spec = g_strdup ("TEXT");
+			}
 		} else {
 			text_part_spec = g_strdup (part_spec);
 		}
-- 
1.6.3.3


--=-Iwo0I4zw/MZdOy8D2GEc--



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]