[evolution/email-factory-3-4: 19/23] Merge some missing bits
- From: Srinivasa Ragavan <sragavan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/email-factory-3-4: 19/23] Merge some missing bits
- Date: Wed, 23 Nov 2011 10:23:54 +0000 (UTC)
commit 7579448313d20224057873e5b40c50df3e4c6757
Author: Srinivasa Ragavan <sragavan gnome org>
Date: Thu Nov 17 15:42:55 2011 +0530
Merge some missing bits
libemail-engine/e-mail-session.c | 35 ++--
mail/em-utils.c | 524 --------------------------------------
2 files changed, 17 insertions(+), 542 deletions(-)
---
diff --git a/libemail-engine/e-mail-session.c b/libemail-engine/e-mail-session.c
index 0ee6989..410c7b5 100644
--- a/libemail-engine/e-mail-session.c
+++ b/libemail-engine/e-mail-session.c
@@ -123,10 +123,10 @@ struct _user_message_msg {
CamelSessionAlertType type;
gchar *prompt;
+ GSList *button_captions;
EFlag *done;
- guint allow_cancel : 1;
- guint result : 1;
+ gint result;
guint ismain : 1;
};
@@ -154,7 +154,7 @@ static void
user_message_response (struct _user_message_msg *m)
{
/* if !allow_cancel, then we've already replied */
- if (m->allow_cancel) {
+ if (m->button_captions) {
m->result = TRUE; //If Accepted
e_flag_set (m->done);
}
@@ -176,19 +176,13 @@ user_message_exec (struct _user_message_msg *m,
switch (m->type) {
case CAMEL_SESSION_ALERT_INFO:
- error_type = m->allow_cancel ?
- "mail:session-message-info-cancel" :
- "mail:session-message-info";
+ error_type = "mail:session-message-info";
break;
case CAMEL_SESSION_ALERT_WARNING:
- error_type = m->allow_cancel ?
- "mail:session-message-warning-cancel" :
- "mail:session-message-warning";
+ error_type = "mail:session-message-warning";
break;
case CAMEL_SESSION_ALERT_ERROR:
- error_type = m->allow_cancel ?
- "mail:session-message-error-cancel" :
- "mail:session-message-error";
+ error_type = "mail:session-message-error";
break;
default:
error_type = NULL;
@@ -208,6 +202,7 @@ static void
user_message_free (struct _user_message_msg *m)
{
g_free (m->prompt);
+ g_slist_free_full (m->button_captions, g_free);
e_flag_free (m->done);
}
@@ -788,24 +783,28 @@ mail_session_forget_password (CamelSession *session,
return TRUE;
}
-static gboolean
+static int
mail_session_alert_user (CamelSession *session,
CamelSessionAlertType type,
const gchar *prompt,
- gboolean cancel)
+ GSList *button_captions)
{
struct _user_message_msg *m;
GCancellable *cancellable;
- gboolean result = TRUE;
+ gint result = -1;
+ GSList *iter;
m = mail_msg_new (&user_message_info);
m->ismain = mail_in_main_thread ();
m->type = type;
m->prompt = g_strdup (prompt);
m->done = e_flag_new ();
- m->allow_cancel = cancel;
+ m->button_captions = g_slist_copy (button_captions);
+
+ for (iter = m->button_captions; iter; iter = iter->next)
+ iter->data = g_strdup (iter->data);
- if (cancel)
+ if (g_slist_length (button_captions) > 1)
mail_msg_ref (m);
cancellable = m->base.cancellable;
@@ -815,7 +814,7 @@ mail_session_alert_user (CamelSession *session,
else
mail_msg_main_loop_push (m);
- if (cancel) {
+ if (g_slist_length (button_captions) > 1) {
e_flag_wait (m->done);
result = m->result;
mail_msg_unref (m);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 7447b08..022697c 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1156,530 +1156,6 @@ em_utils_empty_trash (GtkWidget *parent,
g_list_free (list);
}
-<<<<<<< HEAD
-/* ********************************************************************** */
-
-/* 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;
- GError *err = NULL;
-
- /* failed to load this book last time, skip it now */
- if (g_hash_table_lookup (emu_broken_books_hash,
- e_source_peek_uid (source)) != NULL) {
- d(printf ("%s: skipping broken book '%s'\n",
- G_STRFUNC, e_source_peek_name (source)));
- 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, e_source_peek_uid (source));
- 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 (
- e_source_peek_uid (source));
-
- g_hash_table_insert (
- emu_broken_books_hash,
- source_uid, source_uid);
-
- g_warning (
- "%s: Unable to create addressbook '%s': %s",
- G_STRFUNC,
- e_source_peek_name (source),
- 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 (
- e_source_peek_uid (source));
-
- g_hash_table_insert (
- emu_broken_books_hash,
- source_uid, source_uid);
-
- g_warning (
- "%s: Unable to open addressbook '%s': %s",
- G_STRFUNC,
- e_source_peek_name (source),
- 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 (e_source_peek_uid (source));
-
- g_hash_table_insert (emu_broken_books_hash, source_uid, source_uid);
-
- g_warning (
- "%s: Can't get contacts from '%s': %s",
- G_STRFUNC, e_source_peek_name (source),
- 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 (
- e_source_peek_uid (source)), book_client);
- }
- }
-
- mail_cancel_hook_remove (hook_cancellable);
- g_object_unref (cancellable);
-
- g_slist_foreach (addr_sources, (GFunc) g_object_unref, NULL);
- g_slist_free (addr_sources);
-
- 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);
-}
-
-=======
->>>>>>> Port Evolution to EDS's new mail library.
void
emu_free_mail_account_sort_order_cache (void)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]