Patch: implement "allow external images" flag



	Hi,

	This patch implements a way to flag messages in local storage / cache
as allowed to fetch external images. This way, if user accepts that a
message can fetch them, mail client, does not need to ask again for it.

	The implementation is similar to the "ispartial" flag. I save a file
for each message tracking this.

The changelog would be:

* libtinymail/tny-msg.[ch]:
        * New virtual methods get/set allow external images, to store
          user acceptation to allow mail client to fetch external images
          referenced in a message.
* libtinymail-camel/tny-camel-msg.[ch]:
        * Implement new public methods get/set allow external images
          available in TnyMsg interface. It uses TnyCamelFolder for
          implementation of storage of the flag.
* libtinymail-camel/tny-camel-folder.c,
  libtinymail-camel/tny-camel-folder-priv.h:
        * In camel we delegate on folder for storing the "get external
          images" flag. Then we expose a private method for this, that
          will be called in TnyMsg public implementation.
* libtinymail-camel/camel-lite/camel/camel-folder.[ch]:
        * Add new virtual methods (not implemented here) for getting
          and setting "get external images" flag for each message.
* libtinymail-camel/camel-lite/camel/camel-data-cache.[ch]:
        * Implementation of storage of "get external images" flag in
          data cache. It stores a file with extension getimages in the
          same folder the message contents are retrieved.
* libtinymail-camel/camel-lite/camel/providers/nntp/camel-nntp-folder.c:
        * Implement get/set allow external images methods. It stores
          it in the camel data cache using the methods the cache
          exposes for this.
* libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.c:
        * Implement get/set allow external images methods. It also uses
          the data cache as nntp provider.
* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c:
        * Implement get/set allow external images methods. It relies on
          proper implementation in imap messages cache.
* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.[ch]:
        * Add storage of allow external images flag. It saves an empty
          file with extension getimages per allowed file (similar to
          is partial flag approach).
* libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-folder.c:
        * Implement get/set allow external images methods. It stores
          an empty file for each message in the folder maildir metadata
          directory (the one on top of cur, new and tmp).

-- 
José Dapena Paz <jdapena igalia com>
Igalia
Index: libtinymail/tny-msg.c
===================================================================
--- libtinymail/tny-msg.c	(revision 3685)
+++ libtinymail/tny-msg.c	(working copy)
@@ -91,6 +91,66 @@
 }
 
 /**
+ * tny_msg_set_allow_external_images:
+ * @self: a #TnyMsg
+ * @allow: a #gboolean
+ * 
+ * API WARNING: This API might change
+ * 
+ * Set if views should fetch external images referenced
+ * in this message or not.
+ *
+ * since: 1.0
+ * audience: application-developer
+ **/
+void
+tny_msg_set_allow_external_images (TnyMsg *self, gboolean allow)
+{
+#ifdef DBC /* require */
+	g_assert (TNY_IS_MSG (self));
+	g_assert (TNY_MSG_GET_IFACE (self)->get_allow_external_images != NULL);
+#endif
+
+	TNY_MSG_GET_IFACE (self)->set_allow_external_images (self, allow);
+
+#ifdef DBC /* ensure */
+#endif
+
+	return;
+}
+
+
+/**
+ * tny_msg_get_allow_external_images:
+ * @self: a #TnyMsg
+ * 
+ * API WARNING: This API might change
+ * 
+ * Get if views should fetch external images into message.
+ *
+ * Returns: a #gboolean
+ *
+ * since: 1.0
+ * audience: application-developer
+ **/
+gboolean
+tny_msg_get_allow_external_images (TnyMsg *self)
+{
+	gboolean retval;
+#ifdef DBC /* require */
+	g_assert (TNY_IS_MSG (self));
+	g_assert (TNY_MSG_GET_IFACE (self)->get_allow_external_images != NULL);
+#endif
+
+	retval = TNY_MSG_GET_IFACE (self)->get_allow_external_images (self);
+
+#ifdef DBC /* ensure */
+#endif
+
+	return retval;
+}
+
+/**
  * tny_msg_get_url_string:
  * @self: a #TnyMsg
  * 
Index: libtinymail/tny-msg.h
===================================================================
--- libtinymail/tny-msg.h	(revision 3685)
+++ libtinymail/tny-msg.h	(working copy)
@@ -47,6 +47,8 @@
 	gchar* (*get_url_string) (TnyMsg *self);
 	void (*uncache_attachments) (TnyMsg *self);
 	void (*rewrite_cache) (TnyMsg *self);
+	gboolean (*get_allow_external_images) (TnyMsg *self);
+	void (*set_allow_external_images) (TnyMsg *self, gboolean allow);
 
 };
 
@@ -57,6 +59,8 @@
 gchar* tny_msg_get_url_string (TnyMsg *self);
 void tny_msg_uncache_attachments (TnyMsg *self);
 void tny_msg_rewrite_cache (TnyMsg *self);
+gboolean tny_msg_get_allow_external_images (TnyMsg *self);
+void tny_msg_set_allow_external_images (TnyMsg *self, gboolean allow);
 
 G_END_DECLS
 
Index: libtinymail-camel/tny-camel-msg.c
===================================================================
--- libtinymail-camel/tny-camel-msg.c	(revision 3685)
+++ libtinymail-camel/tny-camel-msg.c	(working copy)
@@ -228,6 +228,50 @@
 	return;
 }
 
+static gboolean
+tny_camel_msg_get_allow_external_images_default (TnyMsg *self)
+{
+	TnyCamelMsgPriv *priv = TNY_CAMEL_MSG_GET_PRIVATE (self);
+	gboolean allow = FALSE;
+	
+	if (priv->folder && priv->header) {
+		gchar *uid;
+		uid = tny_header_dup_uid (priv->header);
+		allow = _tny_camel_folder_get_allow_external_images (TNY_CAMEL_FOLDER(priv->folder),
+								     uid);
+		g_free (uid);
+	}
+	return allow;
+}
+
+static gboolean
+tny_camel_msg_get_allow_external_images (TnyMsg *self)
+{
+	return TNY_CAMEL_MSG_GET_CLASS (self)->get_allow_external_images (self);
+}
+
+static void
+tny_camel_msg_set_allow_external_images_default (TnyMsg *self, gboolean allow)
+{
+	TnyCamelMsgPriv *priv = TNY_CAMEL_MSG_GET_PRIVATE (self);
+
+	if (priv->folder && priv->header) {
+		gchar *uid;
+		uid = tny_header_dup_uid (priv->header);
+		_tny_camel_folder_set_allow_external_images (TNY_CAMEL_FOLDER(priv->folder),
+							     uid, allow);
+		g_free (uid);
+	}
+	return;
+}
+
+static void
+tny_camel_msg_set_allow_external_images (TnyMsg *self, gboolean allow)
+{
+	TNY_CAMEL_MSG_GET_CLASS (self)->set_allow_external_images (self, allow);
+	return;
+}
+
 static TnyHeader*
 tny_camel_msg_get_header_default (TnyMsg *self)
 {
@@ -359,6 +403,8 @@
 	klass->get_url_string= tny_camel_msg_get_url_string;
 	klass->uncache_attachments= tny_camel_msg_uncache_attachments;
 	klass->rewrite_cache= tny_camel_msg_rewrite_cache;
+	klass->get_allow_external_images = tny_camel_msg_get_allow_external_images;
+	klass->set_allow_external_images = tny_camel_msg_set_allow_external_images;
 
 	return;
 }
@@ -376,6 +422,8 @@
 	class->get_url_string= tny_camel_msg_get_url_string_default;
 	class->uncache_attachments= tny_camel_msg_uncache_attachments_default;
 	class->rewrite_cache= tny_camel_msg_rewrite_cache_default;
+	class->get_allow_external_images = tny_camel_msg_get_allow_external_images_default;
+	class->set_allow_external_images = tny_camel_msg_set_allow_external_images_default;
 	
 	object_class->finalize = tny_camel_msg_finalize;
 	
Index: libtinymail-camel/tny-camel-msg.h
===================================================================
--- libtinymail-camel/tny-camel-msg.h	(revision 3685)
+++ libtinymail-camel/tny-camel-msg.h	(working copy)
@@ -56,6 +56,8 @@
 	gchar* (*get_url_string) (TnyMsg *self);
 	void (*uncache_attachments) (TnyMsg *self);
 	void (*rewrite_cache) (TnyMsg *self);
+	gboolean (*get_allow_external_images) (TnyMsg *self);
+	void (*set_allow_external_images) (TnyMsg *self, gboolean allow);
 };
 
 GType tny_camel_msg_get_type (void);
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c	(revision 3685)
+++ libtinymail-camel/tny-camel-folder.c	(working copy)
@@ -666,8 +666,47 @@
 	g_static_rec_mutex_unlock (priv->folder_lock);
 }
 
+gboolean
+_tny_camel_folder_get_allow_external_images (TnyCamelFolder *self, const gchar *uid)
+{
+	TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+	gboolean retval;
 
+	g_static_rec_mutex_lock (priv->folder_lock);
 
+	if (!priv->folder || !priv->loaded || !CAMEL_IS_FOLDER (priv->folder))
+		if (!load_folder_no_lock (priv))
+		{
+			g_static_rec_mutex_unlock (priv->folder_lock);
+			return FALSE;
+		}
+
+	retval = camel_folder_get_allow_external_images (priv->folder, uid);
+
+	g_static_rec_mutex_unlock (priv->folder_lock);
+	return retval;
+}
+
+void
+_tny_camel_folder_set_allow_external_images (TnyCamelFolder *self, const gchar *uid, gboolean allow)
+{
+	TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+	gboolean retval;
+
+	g_static_rec_mutex_lock (priv->folder_lock);
+
+	if (!priv->folder || !priv->loaded || !CAMEL_IS_FOLDER (priv->folder))
+		if (!load_folder_no_lock (priv))
+		{
+			g_static_rec_mutex_unlock (priv->folder_lock);
+			return;
+		}
+
+	camel_folder_set_allow_external_images (priv->folder, uid, allow);
+
+	g_static_rec_mutex_unlock (priv->folder_lock);
+}
+
 static gboolean
 tny_camel_folder_add_msg_shared (TnyFolder *self, TnyMsg *msg, TnyFolderChange *change, GError **err)
 {
Index: libtinymail-camel/tny-camel-folder-priv.h
===================================================================
--- libtinymail-camel/tny-camel-folder-priv.h	(revision 3685)
+++ libtinymail-camel/tny-camel-folder-priv.h	(working copy)
@@ -78,6 +78,9 @@
 void _tny_camel_folder_uncache_attachments (TnyCamelFolder *self, const gchar *uid);
 void _tny_camel_folder_rewrite_cache (TnyCamelFolder *self, const gchar *uid, CamelMimeMessage *msg);
 
+gboolean _tny_camel_folder_get_allow_external_images (TnyCamelFolder *self, const gchar *uid);
+void _tny_camel_folder_set_allow_external_images (TnyCamelFolder *self, const gchar *uid, gboolean allow);
+
 void _tny_camel_folder_remove_folder_actual (TnyFolderStore *self, TnyFolder *folder, TnyFolderStoreChange *change, GError **err);
 
 void _tny_camel_folder_freeup_observers (TnyCamelFolder *self, TnyCamelFolderPriv *priv);
Index: libtinymail-camel/camel-lite/camel/camel-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-folder.c	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/camel-folder.c	(working copy)
@@ -183,7 +183,18 @@
 {
 }
 
+static gboolean
+get_allow_external_images (CamelFolder *folder, const char *uid)
+{
+	return FALSE;
+}
+
 static void
+set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow)
+{
+}
+
+static void
 folder_set_push_email (CamelFolder *folder, gboolean setting)
 {
 	return;
@@ -246,6 +257,8 @@
 	camel_folder_class->is_frozen = is_frozen;
 	camel_folder_class->delete_attachments = delete_attachments;
 	camel_folder_class->rewrite_cache = rewrite_cache;
+	camel_folder_class->get_allow_external_images = get_allow_external_images;
+	camel_folder_class->set_allow_external_images = set_allow_external_images;
 
 	/* virtual method overload */
 	camel_object_class->getv = folder_getv;
@@ -416,6 +429,24 @@
 	return;
 }
 
+gboolean
+camel_folder_get_allow_external_images (CamelFolder *folder, const char *uid)
+{
+	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+     
+	return CF_CLASS (folder)->get_allow_external_images (folder, uid);
+}
+
+void
+camel_folder_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow)
+{
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+     
+	CF_CLASS (folder)->set_allow_external_images (folder, uid, allow);
+
+	return;
+}
+
 static int
 folder_getv(CamelObject *object, CamelException *ex, CamelArgGetV *args)
 {
Index: libtinymail-camel/camel-lite/camel/camel-folder.h
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-folder.h	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/camel-folder.h	(working copy)
@@ -216,6 +216,9 @@
 	void (*delete_attachments) (CamelFolder *folder, const char *uid);
 	void (*rewrite_cache) (CamelFolder *folder, const char *uid, CamelMimeMessage *msg);
 
+	gboolean (*get_allow_external_images) (CamelFolder *folder, const char *uid);
+	void (*set_allow_external_images) (CamelFolder *folder, const char *uid, gboolean allow);
+
 	char* (*get_cache_filename) (CamelFolder *folder, const char *uid, const char *spec, CamelFolderPartState *state);
 	char* (*fetch) (CamelFolder *folder, const char *uid, const char *spec, gboolean *binary, CamelException *ex);
 	char* (*fetch_structure) (CamelFolder *folder, const char *uid, CamelException *ex);
@@ -380,6 +383,9 @@
 void camel_folder_delete_attachments (CamelFolder *folder, const char *uid);
 void camel_folder_rewrite_cache (CamelFolder *folder, const char *uid, CamelMimeMessage *msg);
 
+gboolean camel_folder_get_allow_external_images (CamelFolder *folder, const char *uid);
+void camel_folder_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow);
+
 char* camel_folder_fetch (CamelFolder *folder, const char *uid, const char *spec, gboolean *binary, CamelException *ex);
 char* camel_folder_fetch_structure (CamelFolder *folder, const char *uid, CamelException *ex);
 char* camel_folder_get_cache_filename (CamelFolder *folder, const char *uid, const char *spec, CamelFolderPartState *state);
Index: libtinymail-camel/camel-lite/camel/camel-data-cache.c
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-data-cache.c	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/camel-data-cache.c	(working copy)
@@ -314,7 +314,60 @@
 
 }
 
+gboolean
+camel_data_cache_get_allow_external_images (CamelDataCache *cdc, const char *path,
+					    const char *uid)
+{
+	gboolean retval = FALSE;
+	gchar *mpath; char *dir;
+	guint32 hash;
+	hash = g_str_hash(uid);
+	hash = (hash>>5)&CAMEL_DATA_CACHE_MASK;
+	dir = alloca(strlen(cdc->path) + strlen(path) + 8);
+	sprintf(dir, "%s/%s/%02x", cdc->path, path, hash);
 
+	mpath = g_strdup_printf ("%s/%s.getimages", dir, uid);
+
+	retval = g_file_test (mpath, G_FILE_TEST_IS_REGULAR);
+
+	g_free (mpath);
+
+	return retval;
+}
+
+
+void
+camel_data_cache_set_allow_external_images (CamelDataCache *cdc, const char *path,
+					    const char *uid, gboolean allow)
+{
+	int fd; char *dir;
+	gchar *mpath;
+	guint32 hash;
+	hash = g_str_hash(uid);
+	hash = (hash>>5)&CAMEL_DATA_CACHE_MASK;
+	dir = alloca(strlen(cdc->path) + strlen(path) + 8);
+	sprintf(dir, "%s/%s/%02x", cdc->path, path, hash);
+
+	mpath = g_strdup_printf ("%s/%s.getimages", dir, uid);
+
+	if (!allow)
+	{
+		if (g_file_test (mpath, G_FILE_TEST_IS_REGULAR))
+			g_unlink (mpath);
+	} else {
+		if (!g_file_test (mpath, G_FILE_TEST_IS_REGULAR))
+		{
+		    fd = g_open (mpath, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0600);
+		    if (fd != -1)
+			close (fd);
+		}
+	}
+
+	g_free (mpath);
+
+}
+
+
 /* Since we have to stat the directory anyway, we use this opportunity to
    lazily expire old data.
    If it is this directories 'turn', and we haven't done it for CYCLE_TIME seconds,
Index: libtinymail-camel/camel-lite/camel/camel-data-cache.h
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-data-cache.h	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/camel-data-cache.h	(working copy)
@@ -95,6 +95,10 @@
 
 void         camel_data_cache_set_partial (CamelDataCache *cache, const char *path,
 					      const char *uid, gboolean partial);
+gboolean     camel_data_cache_get_allow_external_images (CamelDataCache *cache, const char *path,
+							 const char *uid);
+void         camel_data_cache_set_allow_external_images (CamelDataCache *cache, const char *path,
+							 const char *uid, gboolean allow);
 void         camel_data_cache_delete_attachments (CamelDataCache *cdc, const char *path,
 					      const char *key);
 
Index: libtinymail-camel/camel-lite/camel/providers/nntp/camel-nntp-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/nntp/camel-nntp-folder.c	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/providers/nntp/camel-nntp-folder.c	(working copy)
@@ -406,6 +406,29 @@
 	                      _("You cannot copy messages from a NNTP folder!"));
 }
 
+static gboolean
+nntp_folder_get_allow_external_images (CamelFolder *folder, const char *uid)
+{
+	gboolean retval;
+	CamelNNTPStore *nntp_store;
+
+	nntp_store = (CamelNNTPStore *) folder->parent_store;
+	retval = camel_data_cache_get_allow_external_images (nntp_store->cache, "cache", uid);
+	
+	return retval;
+}
+
+static gboolean
+nntp_folder_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow)
+{
+	CamelNNTPStore *nntp_store;
+
+	nntp_store = (CamelNNTPStore *) folder->parent_store;
+	camel_data_cache_set_allow_external_images (nntp_store->cache, "cache", uid, allow);
+	
+	return;
+}
+
 static void
 nntp_folder_init (CamelNNTPFolder *nntp_folder, CamelNNTPFolderClass *klass)
 {
@@ -460,6 +483,8 @@
 	camel_folder_class->search_by_expression = nntp_folder_search_by_expression;
 	camel_folder_class->search_by_uids = nntp_folder_search_by_uids;
 	camel_folder_class->search_free = nntp_folder_search_free;
+	camel_folder_class->get_allow_external_images = nntp_folder_get_allow_external_images;
+	camel_folder_class->set_allow_external_images = nntp_folder_set_allow_external_images;
 }
 
 CamelType
Index: libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.c	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.c	(working copy)
@@ -80,6 +80,8 @@
 static int pop3_get_local_size (CamelFolder *folder);
 
 static void pop3_delete_attachments (CamelFolder *folder, const char *uid);
+static gboolean pop3_get_allow_external_images (CamelFolder *folder, const char *uid);
+static void pop3_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow);
 
 static void
 check_dir (CamelPOP3Store *store, CamelFolder *folder)
@@ -1069,6 +1071,24 @@
 	return;
 }
 
+static gboolean
+pop3_get_allow_external_images (CamelFolder *folder, const char *uid)
+{
+	gboolean retval;
+	CamelPOP3Store *pop3_store = CAMEL_POP3_STORE (folder->parent_store);
+	retval = camel_data_cache_get_allow_external_images (pop3_store->cache, "cache", uid);
+	return retval;
+}
+
+static void
+pop3_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow)
+{
+	gboolean retval;
+	CamelPOP3Store *pop3_store = CAMEL_POP3_STORE (folder->parent_store);
+	camel_data_cache_set_allow_external_images (pop3_store->cache, "cache", uid, allow);
+	return;
+}
+
 static CamelMimeMessage *
 pop3_get_message (CamelFolder *folder, const char *uid, CamelFolderReceiveType type, gint param, CamelException *ex)
 {
@@ -1821,6 +1841,8 @@
 	camel_folder_class->get_message = pop3_get_message;
 	camel_folder_class->set_message_flags = pop3_set_message_flags;
 	camel_folder_class->delete_attachments = pop3_delete_attachments;
+	camel_folder_class->get_allow_external_images = pop3_get_allow_external_images;
+	camel_folder_class->set_allow_external_images = pop3_set_allow_external_images;
 
 	camel_disco_folder_class->refresh_info_online = pop3_refresh_info;
 	camel_disco_folder_class->sync_online = pop3_sync_online;
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c	(working copy)
@@ -176,6 +176,8 @@
 static void imap_delete_attachments (CamelFolder *folder, const char *uid);
 static void imap_rewrite_cache (CamelFolder *folder, const char *uid, CamelMimeMessage *msg);
 
+static gboolean imap_get_allow_external_images (CamelFolder *folder, const char *uid);
+static void imap_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow);
 
 static void stop_gmsgstore_from_idle (CamelImapFolder *imap_folder);
 
@@ -214,6 +216,8 @@
 	camel_folder_class->thaw = imap_thaw;
 	camel_folder_class->delete_attachments = imap_delete_attachments;
 	camel_folder_class->rewrite_cache = imap_rewrite_cache;
+	camel_folder_class->get_allow_external_images = imap_get_allow_external_images;
+	camel_folder_class->set_allow_external_images = imap_set_allow_external_images;
 
 	camel_disco_folder_class->refresh_info_online = imap_refresh_info;
 	camel_disco_folder_class->sync_online = imap_sync_online;
@@ -379,6 +383,24 @@
 	return;
 }
 
+static gboolean
+imap_get_allow_external_images (CamelFolder *folder, const char *uid)
+{
+	CamelImapMessageCache *cache = CAMEL_IMAP_FOLDER (folder)->cache;
+
+	return camel_imap_message_cache_get_allow_external_images (cache, uid);
+}
+
+static void
+imap_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow)
+{
+	CamelImapMessageCache *cache = CAMEL_IMAP_FOLDER (folder)->cache;
+
+	camel_imap_message_cache_set_allow_external_images (cache, uid, allow);
+
+	return;
+}
+
 static int
 imap_get_local_size (CamelFolder *folder)
 {
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.c	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.c	(working copy)
@@ -32,6 +32,7 @@
 #endif
 
 #include <string.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 
 #include <glib/gi18n-lib.h>
@@ -396,6 +397,41 @@
 	g_free (path);
 }
 
+gboolean
+camel_imap_message_cache_get_allow_external_images (CamelImapMessageCache *cache, const char *uid)
+{
+	gchar *path = g_strdup_printf ("%s/%s.getimages", cache->path, uid);
+	gboolean retval = FALSE;
+
+	retval = g_file_test (path, G_FILE_TEST_IS_REGULAR);
+
+	g_free (path);
+
+	return retval;
+}
+
+void
+camel_imap_message_cache_set_allow_external_images (CamelImapMessageCache *cache, const char *uid, gboolean allow)
+{
+	gchar *path = g_strdup_printf ("%s/%s.getimages", cache->path, uid);
+	int fd;
+
+	if (!allow)
+	{
+		if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
+			g_unlink (path);
+	} else {
+		if (!g_file_test (path, G_FILE_TEST_IS_REGULAR))
+		{
+		    fd = g_open (path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0600);
+		    if (fd != -1)
+			close (fd);
+		}
+	}
+
+	g_free (path);	
+}
+
 /**
  * camel_imap_message_cache_insert_stream:
  * @cache: the cache
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.h
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.h	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.h	(working copy)
@@ -110,6 +110,9 @@
 void camel_imap_message_cache_replace_cache (CamelImapMessageCache *cache, const char *uid, const char *part_spec,
 					     const char *dest_uid, const char *dest_part_spec);
 
+gboolean camel_imap_message_cache_get_allow_external_images (CamelImapMessageCache *cache, const char *uid);
+void camel_imap_message_cache_set_allow_external_images (CamelImapMessageCache *cache, const char *uid, gboolean allow);
+
 void
 camel_imap_message_cache_replace_with_wrapper (CamelImapMessageCache *cache,
 					       const char *uid,
Index: libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-folder.c	(revision 3685)
+++ libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-folder.c	(working copy)
@@ -33,11 +33,13 @@
 #include <sys/types.h>
 
 #include <glib/gi18n-lib.h>
+#include <glib/gstdio.h>
 
 #include "camel-data-wrapper.h"
 #include "camel-exception.h"
 #include "camel-mime-message.h"
 #include "camel-stream-fs.h"
+#include "camel-file-utils.h"
 
 #include "camel-maildir-folder.h"
 #include "camel-maildir-store.h"
@@ -60,7 +62,10 @@
 
 static void maildir_transfer_messages_to (CamelFolder *source, GPtrArray *uids, CamelFolder *dest, GPtrArray **transferred_uids, gboolean delete_originals, CamelException *ex);
 
+static gboolean maildir_get_allow_external_images (CamelFolder *folder, const char *uid);
+static void maildir_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow);
 
+
 static void maildir_finalize(CamelObject * object);
 
 static int
@@ -107,6 +112,8 @@
 	camel_folder_class->append_message = maildir_append_message;
 	camel_folder_class->get_message = maildir_get_message;
 	camel_folder_class->rewrite_cache = maildir_rewrite_cache;
+	camel_folder_class->get_allow_external_images = maildir_get_allow_external_images;
+	camel_folder_class->set_allow_external_images = maildir_set_allow_external_images;
 
 	//camel_folder_class->transfer_messages_to = maildir_transfer_messages_to;
 
@@ -407,3 +414,44 @@
 	g_free (name);
 	g_free (dest);
 }
+
+static gboolean
+maildir_get_allow_external_images (CamelFolder *folder, const char *uid)
+{
+	CamelLocalFolder *lf = (CamelLocalFolder *) folder;
+	char *name = NULL;
+	gboolean retval;
+
+	/* write it out to tmp, use the uid we got from the summary */
+	name = g_strdup_printf("%s/%s.getimages", lf->folder_path, uid);
+	retval = g_file_test (name, G_FILE_TEST_IS_REGULAR);
+	g_free (name);
+	return retval;
+}
+
+static void
+maildir_set_allow_external_images (CamelFolder *folder, const char *uid, gboolean allow)
+{
+	CamelLocalFolder *lf = (CamelLocalFolder *) folder;
+	char *name = NULL;
+	int fd;
+
+	/* write it out to tmp, use the uid we got from the summary */
+	name = g_strdup_printf("%s/%s.getimages", lf->folder_path, uid);
+
+	if (!allow)
+	{
+		if (g_file_test (name, G_FILE_TEST_IS_REGULAR))
+			g_unlink (name);
+	} else {
+		if (!g_file_test (name, G_FILE_TEST_IS_REGULAR))
+		{
+		    fd = g_open (name, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0600);
+		    if (fd != -1)
+			close (fd);
+		}
+	}
+
+	g_free (name);	
+}
+


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