[evolution/email-factory-3-4: 28/53] Update e-mail-utils from em-utils.



commit e491c91c3589fd7e87565183283102d6e3f37cab
Author: Srinivasa Ragavan <sragavan gnome org>
Date:   Fri Dec 16 13:27:19 2011 +0530

    Update e-mail-utils from em-utils.

 libemail-engine/e-mail-utils.c |   39 ++-
 mail/em-utils.c                |  822 ----------------------------------------
 mail/em-utils.h                |    5 -
 3 files changed, 25 insertions(+), 841 deletions(-)
---
diff --git a/libemail-engine/e-mail-utils.c b/libemail-engine/e-mail-utils.c
index 647cdfa..5e935ec 100644
--- a/libemail-engine/e-mail-utils.c
+++ b/libemail-engine/e-mail-utils.c
@@ -79,17 +79,18 @@ em_utils_folder_is_templates (CamelFolder *folder)
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
 
+	store = camel_folder_get_parent_store (folder);
+	session = camel_service_get_session (CAMEL_SERVICE (store));
+
 	local_templates_folder =
-		e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_TEMPLATES);
+		e_mail_session_get_local_folder (
+		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_TEMPLATES);
 
 	if (folder == local_templates_folder)
 		return TRUE;
 
 	folder_uri = e_mail_folder_uri_from_folder (folder);
 
-	store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (store));
-
 	account_list = e_get_account_list ();
 	iterator = e_list_get_iterator (E_LIST (account_list));
 
@@ -134,17 +135,18 @@ em_utils_folder_is_drafts (CamelFolder *folder)
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
 
+	store = camel_folder_get_parent_store (folder);
+	session = camel_service_get_session (CAMEL_SERVICE (store));
+
 	local_drafts_folder =
-		e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_DRAFTS);
+		e_mail_session_get_local_folder (
+		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_DRAFTS);
 
 	if (folder == local_drafts_folder)
 		return TRUE;
 
 	folder_uri = e_mail_folder_uri_from_folder (folder);
 
-	store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (store));
-
 	account_list = e_get_account_list ();
 	iterator = e_list_get_iterator (E_LIST (account_list));
 
@@ -189,17 +191,18 @@ em_utils_folder_is_sent (CamelFolder *folder)
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
 
+	store = camel_folder_get_parent_store (folder);
+	session = camel_service_get_session (CAMEL_SERVICE (store));
+
 	local_sent_folder =
-		e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_SENT);
+		e_mail_session_get_local_folder (
+		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_SENT);
 
 	if (folder == local_sent_folder)
 		return TRUE;
 
 	folder_uri = e_mail_folder_uri_from_folder (folder);
 
-	store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (store));
-
 	account_list = e_get_account_list ();
 	iterator = e_list_get_iterator (E_LIST (account_list));
 
@@ -234,19 +237,25 @@ em_utils_folder_is_sent (CamelFolder *folder)
 gboolean
 em_utils_folder_is_outbox (CamelFolder *folder)
 {
+	CamelStore *store;
+	CamelSession *session;
 	CamelFolder *local_outbox_folder;
 
 	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
 
+	store = camel_folder_get_parent_store (folder);
+	session = camel_service_get_session (CAMEL_SERVICE (store));
+
 	local_outbox_folder =
-		e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_OUTBOX);
+		e_mail_session_get_local_folder (
+		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_OUTBOX);
 
 	return (folder == local_outbox_folder);
 }
 
-
 /* ********************************************************************** */
 
+
 /* runs sync, in main thread */
 static gpointer
 emu_addr_setup (gpointer user_data)
@@ -360,6 +369,7 @@ try_open_book_client (EBookClient *book_client,
 	return data.result && (!error || !*error);
 }
 
+
 #define NOT_FOUND_BOOK (GINT_TO_POINTER (1))
 
 G_LOCK_DEFINE_STATIC (contact_cache);
@@ -766,6 +776,7 @@ emu_remove_from_mail_cache (const GSList *addresses)
 	g_object_unref (cia);
 }
 
+
 void
 emu_remove_from_mail_cache_1 (const gchar *address)
 {
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 95ad743..5b30d0b 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1108,202 +1108,6 @@ em_utils_selection_get_urilist (GtkSelectionData *selection_data,
 	g_strfreev (uris);
 }
 
-/**
- * em_utils_folder_is_templates:
- * @folder: a #CamelFolder
- *
- * Decides if @folder is a Templates folder.
- *
- * Returns %TRUE if this is a Templates folder or %FALSE otherwise.
- **/
-
-gboolean
-em_utils_folder_is_templates (CamelFolder *folder)
-{
-	CamelFolder *local_templates_folder;
-	CamelSession *session;
-	CamelStore *store;
-	EAccountList *account_list;
-	EIterator *iterator;
-	gchar *folder_uri;
-	gboolean is_templates = FALSE;
-
-	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
-
-	store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (store));
-
-	local_templates_folder =
-		e_mail_session_get_local_folder (
-		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_TEMPLATES);
-
-	if (folder == local_templates_folder)
-		return TRUE;
-
-	folder_uri = e_mail_folder_uri_from_folder (folder);
-
-	account_list = e_get_account_list ();
-	iterator = e_list_get_iterator (E_LIST (account_list));
-
-	while (!is_templates && e_iterator_is_valid (iterator)) {
-		EAccount *account;
-
-		/* XXX EIterator misuses const. */
-		account = (EAccount *) e_iterator_get (iterator);
-
-		if (account->templates_folder_uri != NULL)
-			is_templates = e_mail_folder_uri_equal (
-				session, folder_uri,
-				account->templates_folder_uri);
-
-		e_iterator_next (iterator);
-	}
-
-	g_object_unref (iterator);
-	g_free (folder_uri);
-
-	return is_templates;
-}
-
-/**
- * em_utils_folder_is_drafts:
- * @folder: a #CamelFolder
- *
- * Decides if @folder is a Drafts folder.
- *
- * Returns %TRUE if this is a Drafts folder or %FALSE otherwise.
- **/
-gboolean
-em_utils_folder_is_drafts (CamelFolder *folder)
-{
-	CamelFolder *local_drafts_folder;
-	CamelSession *session;
-	CamelStore *store;
-	EAccountList *account_list;
-	EIterator *iterator;
-	gchar *folder_uri;
-	gboolean is_drafts = FALSE;
-
-	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
-
-	store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (store));
-
-	local_drafts_folder =
-		e_mail_session_get_local_folder (
-		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_DRAFTS);
-
-	if (folder == local_drafts_folder)
-		return TRUE;
-
-	folder_uri = e_mail_folder_uri_from_folder (folder);
-
-	account_list = e_get_account_list ();
-	iterator = e_list_get_iterator (E_LIST (account_list));
-
-	while (!is_drafts && e_iterator_is_valid (iterator)) {
-		EAccount *account;
-
-		/* XXX EIterator misuses const. */
-		account = (EAccount *) e_iterator_get (iterator);
-
-		if (account->drafts_folder_uri != NULL)
-			is_drafts = e_mail_folder_uri_equal (
-				session, folder_uri,
-				account->drafts_folder_uri);
-
-		e_iterator_next (iterator);
-	}
-
-	g_object_unref (iterator);
-	g_free (folder_uri);
-
-	return is_drafts;
-}
-
-/**
- * em_utils_folder_is_sent:
- * @folder: a #CamelFolder
- *
- * Decides if @folder is a Sent folder.
- *
- * Returns %TRUE if this is a Sent folder or %FALSE otherwise.
- **/
-gboolean
-em_utils_folder_is_sent (CamelFolder *folder)
-{
-	CamelFolder *local_sent_folder;
-	CamelSession *session;
-	CamelStore *store;
-	EAccountList *account_list;
-	EIterator *iterator;
-	gchar *folder_uri;
-	gboolean is_sent = FALSE;
-
-	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
-
-	store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (store));
-
-	local_sent_folder =
-		e_mail_session_get_local_folder (
-		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_SENT);
-
-	if (folder == local_sent_folder)
-		return TRUE;
-
-	folder_uri = e_mail_folder_uri_from_folder (folder);
-
-	account_list = e_get_account_list ();
-	iterator = e_list_get_iterator (E_LIST (account_list));
-
-	while (!is_sent && e_iterator_is_valid (iterator)) {
-		EAccount *account;
-
-		/* XXX EIterator misuses const. */
-		account = (EAccount *) e_iterator_get (iterator);
-
-		if (account->sent_folder_uri != NULL)
-			is_sent = e_mail_folder_uri_equal (
-				session, folder_uri,
-				account->sent_folder_uri);
-
-		e_iterator_next (iterator);
-	}
-
-	g_object_unref (iterator);
-	g_free (folder_uri);
-
-	return is_sent;
-}
-
-/**
- * em_utils_folder_is_outbox:
- * @folder: a #CamelFolder
- *
- * Decides if @folder is an Outbox folder.
- *
- * Returns %TRUE if this is an Outbox folder or %FALSE otherwise.
- **/
-gboolean
-em_utils_folder_is_outbox (CamelFolder *folder)
-{
-	CamelStore *store;
-	CamelSession *session;
-	CamelFolder *local_outbox_folder;
-
-	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
-
-	store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (store));
-
-	local_outbox_folder =
-		e_mail_session_get_local_folder (
-		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_OUTBOX);
-
-	return (folder == local_outbox_folder);
-}
-
 /* ********************************************************************** */
 static EProxy *emu_proxy = NULL;
 static GStaticMutex emu_proxy_lock = G_STATIC_MUTEX_INIT;
@@ -1455,562 +1259,6 @@ em_utils_empty_trash (GtkWidget *parent,
 
 /* ********************************************************************** */
 
-/* runs sync, in main thread */
-static gpointer
-emu_addr_setup (gpointer user_data)
-{
-	GError *err = NULL;
-	ESourceList **psource_list = user_data;
-
-	if (!e_book_client_get_sources (psource_list, &err))
-		g_error_free (err);
-
-	return NULL;
-}
-
-static void
-emu_addr_cancel_stop (gpointer data)
-{
-	gboolean *stop = data;
-
-	g_return_if_fail (stop != NULL);
-
-	*stop = TRUE;
-}
-
-static void
-emu_addr_cancel_cancellable (gpointer data)
-{
-	GCancellable *cancellable = data;
-
-	g_return_if_fail (cancellable != NULL);
-
-	g_cancellable_cancel (cancellable);
-}
-
-struct TryOpenEBookStruct {
-	GError **error;
-	EFlag *flag;
-	gboolean result;
-};
-
-static void
-try_open_book_client_cb (GObject *source_object,
-                         GAsyncResult *result,
-                         gpointer closure)
-{
-	EBookClient *book_client = E_BOOK_CLIENT (source_object);
-	struct TryOpenEBookStruct *data = (struct TryOpenEBookStruct *) closure;
-	GError *error = NULL;
-
-	if (!data)
-		return;
-
-	e_client_open_finish (E_CLIENT (book_client), result, &error);
-
-	data->result = error == NULL;
-
-	if (!data->result) {
-		g_clear_error (data->error);
-		g_propagate_error (data->error, error);
-	}
-
-	e_flag_set (data->flag);
-}
-
-/*
- * try_open_book_client:
- * Tries to open address book asynchronously, but acts as synchronous.
- * The advantage is it checks periodically whether the camel_operation
- * has been canceled or not, and if so, then stops immediately, with
- * result FALSE. Otherwise returns same as e_client_open()
- */
-static gboolean
-try_open_book_client (EBookClient *book_client,
-                      gboolean only_if_exists,
-                      GCancellable *cancellable,
-                      GError **error)
-{
-	struct TryOpenEBookStruct data;
-	gboolean canceled = FALSE;
-	EFlag *flag = e_flag_new ();
-
-	data.error = error;
-	data.flag = flag;
-	data.result = FALSE;
-
-	e_client_open (
-		E_CLIENT (book_client), only_if_exists,
-		cancellable, try_open_book_client_cb, &data);
-
-	while (canceled = g_cancellable_is_cancelled (cancellable),
-			!canceled && !e_flag_is_set (flag)) {
-		GTimeVal wait;
-
-		g_get_current_time (&wait);
-		g_time_val_add (&wait, 250000); /* waits 250ms */
-
-		e_flag_timed_wait (flag, &wait);
-	}
-
-	if (canceled) {
-		g_cancellable_cancel (cancellable);
-
-		g_clear_error (error);
-		g_propagate_error (
-			error, e_client_error_create (
-			E_CLIENT_ERROR_CANCELLED, NULL));
-	}
-
-	e_flag_wait (flag);
-	e_flag_free (flag);
-
-	return data.result && (!error || !*error);
-}
-
-#define NOT_FOUND_BOOK (GINT_TO_POINTER (1))
-
-G_LOCK_DEFINE_STATIC (contact_cache);
-
-/* key is lowercased contact email; value is EBook pointer
- * (just for comparison) where it comes from */
-static GHashTable *contact_cache = NULL;
-
-/* key is source ID; value is pointer to EBook */
-static GHashTable *emu_books_hash = NULL;
-
-/* key is source ID; value is same pointer as key; this is hash of
- * broken books, which failed to open for some reason */
-static GHashTable *emu_broken_books_hash = NULL;
-
-static ESourceList *emu_books_source_list = NULL;
-
-static gboolean
-search_address_in_addressbooks (const gchar *address,
-                                gboolean local_only,
-                                gboolean (*check_contact) (EContact *contact,
-                                                           gpointer user_data),
-                                gpointer user_data)
-{
-	gboolean found = FALSE, stop = FALSE, found_any = FALSE;
-	gchar *lowercase_addr;
-	gpointer ptr;
-	EBookQuery *book_query;
-	gchar *query;
-	GSList *s, *g, *addr_sources = NULL;
-	GHook *hook_cancellable;
-	GCancellable *cancellable;
-
-	if (!address || !*address)
-		return FALSE;
-
-	G_LOCK (contact_cache);
-
-	if (!emu_books_source_list) {
-		mail_call_main (
-			MAIL_CALL_p_p, (MailMainFunc)
-			emu_addr_setup, &emu_books_source_list);
-		emu_books_hash = g_hash_table_new_full (
-			g_str_hash, g_str_equal, g_free, g_object_unref);
-		emu_broken_books_hash = g_hash_table_new_full (
-			g_str_hash, g_str_equal, g_free, NULL);
-		contact_cache = g_hash_table_new_full (
-			g_str_hash, g_str_equal, g_free, NULL);
-	}
-
-	if (!emu_books_source_list) {
-		G_UNLOCK (contact_cache);
-		return FALSE;
-	}
-
-	lowercase_addr = g_utf8_strdown (address, -1);
-	ptr = g_hash_table_lookup (contact_cache, lowercase_addr);
-	if (ptr != NULL && (check_contact == NULL || ptr == NOT_FOUND_BOOK)) {
-		g_free (lowercase_addr);
-		G_UNLOCK (contact_cache);
-		return ptr != NOT_FOUND_BOOK;
-	}
-
-	book_query = e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_IS, address);
-	query = e_book_query_to_string (book_query);
-	e_book_query_unref (book_query);
-
-	for (g = e_source_list_peek_groups (emu_books_source_list);
-			g; g = g_slist_next (g)) {
-		ESourceGroup *group = g->data;
-
-		if (!group)
-			continue;
-
-		if (local_only && !(e_source_group_peek_base_uri (group) &&
-			g_str_has_prefix (
-			e_source_group_peek_base_uri (group), "local:")))
-			continue;
-
-		for (s = e_source_group_peek_sources (group); s; s = g_slist_next (s)) {
-			ESource *source = s->data;
-			const gchar *completion = e_source_get_property (source, "completion");
-
-			if (completion && g_ascii_strcasecmp (completion, "true") == 0) {
-				addr_sources = g_slist_prepend (addr_sources, g_object_ref (source));
-			}
-		}
-	}
-
-	cancellable = g_cancellable_new ();
-	hook_cancellable = mail_cancel_hook_add (emu_addr_cancel_cancellable, cancellable);
-
-	for (s = addr_sources; !stop && !found && s; s = g_slist_next (s)) {
-		ESource *source = s->data;
-		GSList *contacts;
-		EBookClient *book_client = NULL;
-		GHook *hook_stop;
-		gboolean cached_book = FALSE;
-		const gchar *display_name;
-		const gchar *uid;
-		GError *err = NULL;
-
-		uid = e_source_peek_uid (source);
-		display_name = e_source_peek_name (source);
-
-		/* failed to load this book last time, skip it now */
-		if (g_hash_table_lookup (emu_broken_books_hash, uid) != NULL) {
-			d(printf ("%s: skipping broken book '%s'\n",
-				G_STRFUNC, display_name));
-			continue;
-		}
-
-		d(printf(" checking '%s'\n", e_source_get_uri(source)));
-
-		hook_stop = mail_cancel_hook_add (emu_addr_cancel_stop, &stop);
-
-		book_client = g_hash_table_lookup (emu_books_hash, uid);
-		if (!book_client) {
-			book_client = e_book_client_new (source, &err);
-
-			if (book_client == NULL) {
-				if (err && (g_error_matches (err, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
-				    g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))) {
-					stop = TRUE;
-				} else if (err) {
-					gchar *source_uid;
-
-					source_uid = g_strdup (uid);
-
-					g_hash_table_insert (
-						emu_broken_books_hash,
-						source_uid, source_uid);
-
-					g_warning (
-						"%s: Unable to create addressbook '%s': %s",
-						G_STRFUNC,
-						display_name,
-						err->message);
-				}
-				g_clear_error (&err);
-			} else if (!stop && !try_open_book_client (book_client, TRUE, cancellable, &err)) {
-				g_object_unref (book_client);
-				book_client = NULL;
-
-				if (err && (g_error_matches (err, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
-				    g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))) {
-					stop = TRUE;
-				} else if (err) {
-					gchar *source_uid;
-
-					source_uid = g_strdup (uid);
-
-					g_hash_table_insert (
-						emu_broken_books_hash,
-						source_uid, source_uid);
-
-					g_warning (
-						"%s: Unable to open addressbook '%s': %s",
-						G_STRFUNC,
-						display_name,
-						err->message);
-				}
-				g_clear_error (&err);
-			}
-		} else {
-			cached_book = TRUE;
-		}
-
-		if (book_client && !stop && e_book_client_get_contacts_sync (book_client, query, &contacts, cancellable, &err)) {
-			if (contacts != NULL) {
-				if (!found_any) {
-					g_hash_table_insert (contact_cache, g_strdup (lowercase_addr), book_client);
-				}
-				found_any = TRUE;
-
-				if (check_contact) {
-					GSList *l;
-
-					for (l = contacts; l && !found; l = l->next) {
-						EContact *contact = l->data;
-
-						found = check_contact (contact, user_data);
-					}
-				} else {
-					found = TRUE;
-				}
-
-				g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
-				g_slist_free (contacts);
-			}
-		} else if (book_client) {
-			stop = stop || (err &&
-			    (g_error_matches (err, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
-			     g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)));
-			if (err && !stop) {
-				gchar *source_uid = g_strdup (uid);
-
-				g_hash_table_insert (emu_broken_books_hash, source_uid, source_uid);
-
-				g_warning (
-					"%s: Can't get contacts from '%s': %s",
-					G_STRFUNC,
-					display_name,
-					err->message);
-			}
-			g_clear_error (&err);
-		}
-
-		mail_cancel_hook_remove (hook_stop);
-
-		if (stop && !cached_book && book_client) {
-			g_object_unref (book_client);
-		} else if (!stop && book_client && !cached_book) {
-			g_hash_table_insert (
-				emu_books_hash, g_strdup (uid), book_client);
-		}
-	}
-
-	mail_cancel_hook_remove (hook_cancellable);
-	g_object_unref (cancellable);
-
-	g_slist_free_full (addr_sources, (GDestroyNotify) g_object_unref);
-
-	g_free (query);
-
-	if (!found_any) {
-		g_hash_table_insert (contact_cache, lowercase_addr, NOT_FOUND_BOOK);
-		lowercase_addr = NULL;
-	}
-
-	G_UNLOCK (contact_cache);
-
-	g_free (lowercase_addr);
-
-	return found_any;
-}
-
-gboolean
-em_utils_in_addressbook (CamelInternetAddress *iaddr,
-                         gboolean local_only)
-{
-	const gchar *addr;
-
-	/* TODO: check all addresses? */
-	if (iaddr == NULL || !camel_internet_address_get (iaddr, 0, NULL, &addr))
-		return FALSE;
-
-	return search_address_in_addressbooks (addr, local_only, NULL, NULL);
-}
-
-static gboolean
-extract_photo_data (EContact *contact,
-                    gpointer user_data)
-{
-	EContactPhoto **photo = user_data;
-
-	g_return_val_if_fail (contact != NULL, FALSE);
-	g_return_val_if_fail (user_data != NULL, FALSE);
-
-	*photo = e_contact_get (contact, E_CONTACT_PHOTO);
-	if (!*photo)
-		*photo = e_contact_get (contact, E_CONTACT_LOGO);
-
-	return *photo != NULL;
-}
-
-typedef struct _PhotoInfo {
-	gchar *address;
-	EContactPhoto *photo;
-} PhotoInfo;
-
-static void
-emu_free_photo_info (PhotoInfo *pi)
-{
-	if (!pi)
-		return;
-
-	if (pi->address)
-		g_free (pi->address);
-	if (pi->photo)
-		e_contact_photo_free (pi->photo);
-	g_free (pi);
-}
-
-G_LOCK_DEFINE_STATIC (photos_cache);
-static GSList *photos_cache = NULL; /* list of PhotoInfo-s */
-
-CamelMimePart *
-em_utils_contact_photo (CamelInternetAddress *cia,
-                        gboolean local_only)
-{
-	const gchar *addr = NULL;
-	CamelMimePart *part = NULL;
-	EContactPhoto *photo = NULL;
-	GSList *p, *first_not_null = NULL;
-	gint count_not_null = 0;
-
-	if (cia == NULL || !camel_internet_address_get (cia, 0, NULL, &addr) || !addr) {
-		return NULL;
-	}
-
-	G_LOCK (photos_cache);
-
-	/* search a cache first */
-	for (p = photos_cache; p; p = p->next) {
-		PhotoInfo *pi = p->data;
-
-		if (!pi)
-			continue;
-
-		if (pi->photo) {
-			if (!first_not_null)
-				first_not_null = p;
-			count_not_null++;
-		}
-
-		if (g_ascii_strcasecmp (addr, pi->address) == 0) {
-			photo = pi->photo;
-			break;
-		}
-	}
-
-	/* !p means the address had not been found in the cache */
-	if (!p && search_address_in_addressbooks (
-			addr, local_only, extract_photo_data, &photo)) {
-		PhotoInfo *pi;
-
-		if (photo && photo->type != E_CONTACT_PHOTO_TYPE_INLINED) {
-			e_contact_photo_free (photo);
-			photo = NULL;
-		}
-
-		/* keep only up to 10 photos in memory */
-		if (photo && count_not_null >= 10 && first_not_null) {
-			pi = first_not_null->data;
-
-			photos_cache = g_slist_remove (photos_cache, pi);
-
-			emu_free_photo_info (pi);
-		}
-
-		pi = g_new0 (PhotoInfo, 1);
-		pi->address = g_strdup (addr);
-		pi->photo = photo;
-
-		photos_cache = g_slist_append (photos_cache, pi);
-	}
-
-	/* some photo found, use it */
-	if (photo) {
-		/* Form a mime part out of the photo */
-		part = camel_mime_part_new ();
-		camel_mime_part_set_content (part,
-				    (const gchar *) photo->data.inlined.data,
-				    photo->data.inlined.length, "image/jpeg");
-	}
-
-	G_UNLOCK (photos_cache);
-
-	return part;
-}
-
-/* list of email addresses (strings) to remove from local cache of photos and
- * contacts, but only if the photo doesn't exist or is an not-found contact */
-void
-emu_remove_from_mail_cache (const GSList *addresses)
-{
-	const GSList *a;
-	GSList *p;
-	CamelInternetAddress *cia;
-
-	cia = camel_internet_address_new ();
-
-	for (a = addresses; a; a = a->next) {
-		const gchar *addr = NULL;
-
-		if (!a->data)
-			continue;
-
-		if (camel_address_decode ((CamelAddress *) cia, a->data) != -1 &&
-		    camel_internet_address_get (cia, 0, NULL, &addr) && addr) {
-			gchar *lowercase_addr = g_utf8_strdown (addr, -1);
-
-			G_LOCK (contact_cache);
-			if (g_hash_table_lookup (contact_cache, lowercase_addr) == NOT_FOUND_BOOK)
-				g_hash_table_remove (contact_cache, lowercase_addr);
-			G_UNLOCK (contact_cache);
-
-			g_free (lowercase_addr);
-
-			G_LOCK (photos_cache);
-			for (p = photos_cache; p; p = p->next) {
-				PhotoInfo *pi = p->data;
-
-				if (pi && !pi->photo && g_ascii_strcasecmp (pi->address, addr) == 0) {
-					photos_cache = g_slist_remove (photos_cache, pi);
-					emu_free_photo_info (pi);
-					break;
-				}
-			}
-			G_UNLOCK (photos_cache);
-		}
-	}
-
-	g_object_unref (cia);
-}
-
-void
-emu_free_mail_account_sort_order_cache (void)
-{
-	G_LOCK (contact_cache);
-
-	if (emu_books_hash) {
-		g_hash_table_destroy (emu_books_hash);
-		emu_books_hash = NULL;
-	}
-
-	if (emu_broken_books_hash) {
-		g_hash_table_destroy (emu_broken_books_hash);
-		emu_broken_books_hash = NULL;
-	}
-
-	if (emu_books_source_list) {
-		g_object_unref (emu_books_source_list);
-		emu_books_source_list = NULL;
-	}
-
-	if (contact_cache) {
-		g_hash_table_destroy (contact_cache);
-		contact_cache = NULL;
-	}
-
-	G_UNLOCK (contact_cache);
-
-	G_LOCK (photos_cache);
-
-	g_slist_foreach (photos_cache, (GFunc) emu_free_photo_info, NULL);
-	g_slist_free (photos_cache);
-	photos_cache = NULL;
-
-	G_UNLOCK (photos_cache);
-	free_account_sort_order_cache ();
-}
 
 void
 em_utils_clear_get_password_canceled_accounts_flag (void)
@@ -2238,76 +1486,6 @@ emu_restore_folder_tree_state (EMFolderTree *folder_tree)
 	g_key_file_free (key_file);
 }
 
-/* Returns TRUE if CamelURL points to a local mbox file. */
-gboolean
-em_utils_is_local_delivery_mbox_file (CamelURL *url)
-{
-	g_return_val_if_fail (url != NULL, FALSE);
-
-	return g_str_equal (url->protocol, "mbox") &&
-		(url->path != NULL) &&
-		g_file_test (url->path, G_FILE_TEST_EXISTS) &&
-		!g_file_test (url->path, G_FILE_TEST_IS_DIR);
-}
-
-static void
-cancel_service_connect_cb (GCancellable *cancellable,
-                           CamelService *service)
-{
-	g_return_if_fail (CAMEL_IS_SERVICE (service));
-
-	camel_service_cancel_connect (service);
-}
-
-gboolean
-em_utils_connect_service_sync (CamelService *service,
-                               GCancellable *cancellable,
-                               GError **error)
-{
-	gboolean res;
-	gulong handler_id = 0;
-
-	g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE);
-
-	if (cancellable != NULL)
-		handler_id = g_cancellable_connect (
-			cancellable,
-			G_CALLBACK (cancel_service_connect_cb),
-			service, NULL);
-
-	res = camel_service_connect_sync (service, error);
-
-	if (handler_id)
-		g_cancellable_disconnect (cancellable, handler_id);
-
-	return res;
-}
-
-gboolean
-em_utils_disconnect_service_sync (CamelService *service,
-                                  gboolean clean,
-                                  GCancellable *cancellable,
-                                  GError **error)
-{
-	gboolean res;
-	gulong handler_id = 0;
-
-	g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE);
-
-	if (cancellable != NULL)
-		handler_id = g_cancellable_connect (
-			cancellable,
-			G_CALLBACK (cancel_service_connect_cb),
-			service, NULL);
-
-	res = camel_service_disconnect_sync (service, clean, error);
-
-	if (handler_id)
-		g_cancellable_disconnect (cancellable, handler_id);
-
-	return res;
-}
-
 static gboolean
 check_prefix (const gchar *subject,
 	      const gchar *prefix,
diff --git a/mail/em-utils.h b/mail/em-utils.h
index 296a623..8b62bcf 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -91,11 +91,6 @@ void emu_free_mail_account_sort_order_cache (void);
 
 void emu_restore_folder_tree_state (EMFolderTree *folder_tree);
 
-gboolean em_utils_is_local_delivery_mbox_file (CamelURL *url);
-
-gboolean em_utils_connect_service_sync (CamelService *service, GCancellable *cancellable, GError **error);
-gboolean em_utils_disconnect_service_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error);
-
 gboolean em_utils_is_re_in_subject (struct _EShell *shell,
 				    const gchar *subject,
 				    gint *skip_len);



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