[PATCH 04/10] Added a global filter to bs msg receive strategy, to set up the number of bodies the strategy will autofetch.



---
 libtinymail-camel/tny-camel-bs-mime-part.c         |    2 +-
 .../tny-camel-bs-msg-receive-strategy.c            |   42 +++++++++++++++++++-
 .../tny-camel-bs-msg-receive-strategy.h            |    7 +++
 3 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/libtinymail-camel/tny-camel-bs-mime-part.c b/libtinymail-camel/tny-camel-bs-mime-part.c
index 77cb490..58ee384 100644
--- a/libtinymail-camel/tny-camel-bs-mime-part.c
+++ b/libtinymail-camel/tny-camel-bs-mime-part.c
@@ -1084,7 +1084,7 @@ _tny_camel_bs_mime_part_set_strat (TnyCamelBsMimePart *self, TnyCamelBsMsgReceiv
 gboolean
 tny_camel_bs_mime_part_is_fetched (TnyCamelBsMimePart *part)
 {
-	TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (self);
+	TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (part);
 	CamelFolderPartState state;
 	CamelFolder *cfolder = _tny_camel_folder_get_camel_folder (TNY_CAMEL_FOLDER (priv->folder));
 	gchar *pos_filename = camel_folder_get_cache_filename (cfolder, 
diff --git a/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c b/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c
index e70b133..b45c343 100644
--- a/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c
+++ b/libtinymail-camel/tny-camel-bs-msg-receive-strategy.c
@@ -50,6 +50,8 @@
 #include <tny-camel-bs-mime-part.h>
 
 #include <tny-fs-stream.h>
+#include <tny-simple-list.h>
+#include <tny-camel-stream.h>
 
 #include "tny-camel-account-priv.h"
 #include "tny-camel-folder-priv.h"
@@ -57,6 +59,8 @@
 #include "tny-camel-bs-msg-priv.h"
 #include "tny-camel-bs-mime-part-priv.h"
 
+static TnyCamelBsMsgReceiveStrategyBodiesFilter _bodies_filter = NULL;
+
 static GObjectClass *parent_class = NULL;
 
 static TnyMsg *
@@ -149,6 +153,36 @@ tny_camel_bs_msg_receive_strategy_perform_get_msg_default (TnyMsgReceiveStrategy
 		_tny_camel_bs_mime_part_set_strat (TNY_CAMEL_BS_MIME_PART (message), 
 			TNY_CAMEL_BS_MSG_RECEIVE_STRATEGY (self));
 
+		/* If there are bodies to fetch, fetch them */
+		if (_bodies_filter) {
+			TnyList *bodies;
+			TnyIterator *iterator;
+
+			bodies = TNY_LIST (tny_simple_list_new ());
+			_bodies_filter (message, bodies);
+			for (iterator = tny_list_create_iterator (bodies);
+			     !tny_iterator_is_done (iterator) && (err && !*err);
+			     tny_iterator_next (iterator)) {
+				TnyMimePart *body;
+				CamelStream *null_stream;
+				TnyStream *tny_null_stream;
+
+				body = TNY_MIME_PART (tny_iterator_get_current (iterator));
+				null_stream = camel_stream_null_new ();
+				tny_null_stream = tny_camel_stream_new (null_stream);
+				tny_mime_part_write_to_stream (body, tny_null_stream, err);
+				g_object_unref (tny_null_stream);
+				
+				g_object_unref (body);
+			}
+			g_object_unref (iterator);
+			g_object_unref (bodies);
+
+			if (err && *err != NULL) {
+				g_object_unref (message);
+				return NULL;
+			}
+		}
 	} else
 		message = NULL;
 
@@ -185,7 +219,6 @@ tny_camel_bs_msg_receive_strategy_new (void)
 	return TNY_MSG_RECEIVE_STRATEGY (self);
 }
 
-
 static void
 tny_camel_bs_msg_receive_strategy_class_init (TnyCamelBsMsgReceiveStrategyClass *klass)
 {
@@ -197,6 +230,7 @@ tny_camel_bs_msg_receive_strategy_class_init (TnyCamelBsMsgReceiveStrategyClass
 	klass->perform_get_msg= tny_camel_bs_msg_receive_strategy_perform_get_msg_default;
 
 	object_class->finalize = tny_camel_bs_msg_receive_strategy_finalize;
+
 }
 
 static void 
@@ -249,3 +283,9 @@ tny_camel_bs_msg_receive_strategy_get_type (void)
 	g_once (&once, tny_camel_bs_msg_receive_strategy_register_type, NULL);
 	return GPOINTER_TO_UINT (once.retval);
 }
+
+void
+tny_camel_bs_msg_receive_strategy_set_global_bodies_filter (TnyCamelBsMsgReceiveStrategyBodiesFilter filter)
+{
+	_bodies_filter = filter;
+}
diff --git a/libtinymail-camel/tny-camel-bs-msg-receive-strategy.h b/libtinymail-camel/tny-camel-bs-msg-receive-strategy.h
index 0d717ac..b0c1665 100644
--- a/libtinymail-camel/tny-camel-bs-msg-receive-strategy.h
+++ b/libtinymail-camel/tny-camel-bs-msg-receive-strategy.h
@@ -24,6 +24,8 @@
 
 #include <tny-msg-receive-strategy.h>
 #include <tny-camel-bs-mime-part.h>
+#include <tny-msg.h>
+#include <tny-list.h>
 
 G_BEGIN_DECLS
 
@@ -34,6 +36,8 @@ G_BEGIN_DECLS
 #define TNY_IS_CAMEL_BS_MSG_RECEIVE_STRATEGY_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), TNY_TYPE_CAMEL_BS_MSG_RECEIVE_STRATEGY))
 #define TNY_CAMEL_BS_MSG_RECEIVE_STRATEGY_GET_CLASS(inst)  (G_TYPE_INSTANCE_GET_CLASS ((inst), TNY_TYPE_CAMEL_BS_MSG_RECEIVE_STRATEGY, TnyCamelBsMsgReceiveStrategyClass))
 
+typedef void (*TnyCamelBsMsgReceiveStrategyBodiesFilter) (TnyMsg *msg, TnyList *list);
+
 typedef struct _TnyCamelBsMsgReceiveStrategy TnyCamelBsMsgReceiveStrategy;
 typedef struct _TnyCamelBsMsgReceiveStrategyClass TnyCamelBsMsgReceiveStrategyClass;
 
@@ -54,6 +58,9 @@ struct _TnyCamelBsMsgReceiveStrategyClass
 GType tny_camel_bs_msg_receive_strategy_get_type (void);
 TnyMsgReceiveStrategy* tny_camel_bs_msg_receive_strategy_new (void);
 
+void tny_camel_bs_msg_receive_strategy_set_global_bodies_filter (TnyCamelBsMsgReceiveStrategyBodiesFilter filter);
+						     
+
 TnyStream * tny_camel_bs_msg_receive_strategy_start_receiving_part (TnyCamelBsMsgReceiveStrategy *self, TnyFolder *folder, TnyCamelBsMimePart *part, gboolean *binary, GError **err);
 
 G_END_DECLS
-- 
1.6.3.3


--=-gnkDh763C8UIUYIzLd8x
Content-Disposition: attachment; filename="0005-Properly-reload-imap-message-cache.patch"
Content-Type: text/x-patch; name="0005-Properly-reload-imap-message-cache.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit



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