diff options
author | Not Zed <NotZed@Ximian.com> | 2004-03-31 18:09:04 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-03-31 18:09:04 +0800 |
commit | 9e126a8d01dd36a19ab34a9d3edf016897b12d7e (patch) | |
tree | 9a57659490abf68cb1abd341a0d939f30fc1074e /mail/em-utils.c | |
parent | d239a18ce4bff4bd07c17118ca429f5020fc1731 (diff) | |
download | gsoc2013-evolution-9e126a8d01dd36a19ab34a9d3edf016897b12d7e.tar.gz gsoc2013-evolution-9e126a8d01dd36a19ab34a9d3edf016897b12d7e.tar.zst gsoc2013-evolution-9e126a8d01dd36a19ab34a9d3edf016897b12d7e.zip |
Cleaned up header inclusions and added plenty of forward declarations.
2004-03-31 Not Zed <NotZed@Ximian.com>
* *.[ch]: Cleaned up header inclusions and added plenty of forward
declarations. Sped up complete re-compilation by upto 20%.
** See bug #55950.
* em-utils.c (em_utils_in_addressbook): utility for checking if an
email address is in the addressbook. I can't tell if it works
'cause it crashes eds.
* em-format-html.c (emfh_gethttp): handle addressbook checking.
2004-03-30 Not Zed <NotZed@Ximian.com>
* mail-config.h: clean up the headers and use some forward decl's
instead.
* em-format-html.c (em_format_html_set_load_http): change state to
an int 'style' instead.
* em-folder-view.c (emfv_setting_notify): set the format load http
option to the config value directly.
** See bug #56147.
* message-list.c (clear_info): set the node data to NULL when we
unref its data.
(ml_get_save_id): use a different test for the root node, and
return NULL if we don't have any data on the node (because we're
cleaing it).
** See bug #54962.
* em-folder-tree.c (emft_popup_new_folder_response): put back the
old hack to open the vfolder editor if you try to create a folder
under vfolders.
** See bug #55940.
* mail-autofilter.c (mail_filter_rename_uri): map the uri to an
email uri before passing to filter code.
(mail_filter_delete_uri): same here.
svn path=/trunk/; revision=25261
Diffstat (limited to 'mail/em-utils.c')
-rw-r--r-- | mail/em-utils.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/mail/em-utils.c b/mail/em-utils.c index 0453c50ef7..7a553ad68c 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -47,6 +47,9 @@ #include <e-util/e-mktemp.h> #include <e-util/e-dialog-utils.h> +#include <e-util/e-account-list.h> + +#include <gal/util/e-util.h> #include "em-utils.h" #include "em-composer-utils.h" @@ -2666,3 +2669,125 @@ char *em_uri_to_camel(const char *euri) return curi; } + +/* ********************************************************************** */ +#include <libebook/e-book.h> + +struct _addr_node { + char *addr; + time_t stamp; + int found; +}; + +#define EMU_ADDR_CACHE_TIME (60*30) /* in seconds */ + +static GSList *emu_addr_sources; +static GHashTable *emu_addr_cache; + +static void +emu_addr_sources_refresh(void) +{ + GError *err = NULL; + ESourceList *list; + GSList *g, *s, *groups, *sources; + + g_slist_foreach(emu_addr_sources, (GFunc)g_object_unref, NULL); + g_slist_free(emu_addr_sources); + emu_addr_sources = NULL; + + if (!e_book_get_addressbooks(&list, &err)) { + g_error_free(err); + return; + } + + groups = e_source_list_peek_groups(list); + for (g=groups;g;g=g_slist_next(g)) { + sources = e_source_group_peek_sources((ESourceGroup *)g->data); + for (s=sources;s;s=g_slist_next(s)) { + emu_addr_sources = g_slist_prepend(emu_addr_sources, g_object_ref(s->data)); + } + } + + g_object_unref(list); +} + +gboolean +em_utils_in_addressbook(CamelInternetAddress *iaddr) +{ + GError *err = NULL; + GSList *s; + int found = FALSE; + EBookQuery *query; + const char *addr; + struct _addr_node *node; + time_t now; + + /* TODO: check all addresses? */ + if (!camel_internet_address_get(iaddr, 0, NULL, &addr)) + return FALSE; + + if (emu_addr_cache == NULL) { + emu_addr_cache = g_hash_table_new(g_str_hash, g_str_equal); + emu_addr_sources_refresh(); + } + + now = time(0); + + printf("Checking '%s' is in addressbook", addr); + + node = g_hash_table_lookup(emu_addr_cache, addr); + if (node) { + printf(" -> cached, found %s\n", node->found?"yes":"no"); + if (node->stamp + EMU_ADDR_CACHE_TIME > now) + return node->found; + printf(" but expired!\n"); + } else { + printf(" -> not found in cache\n"); + node = g_malloc0(sizeof(*node)); + node->addr = g_strdup(addr); + } + + query = e_book_query_field_test(E_CONTACT_EMAIL, E_BOOK_QUERY_IS, addr); + + for (s = emu_addr_sources;!found && s;s=g_slist_next(s)) { + ESource *source = s->data; + GList *contacts; + EBook *book; + + book = e_book_new(); + + printf(" checking '%s'\n", e_source_get_uri(source)); + + if (!e_book_load_source(book, source, TRUE, &err)) { + printf("couldn't load source?\n"); + g_clear_error(&err); + g_object_unref(book); + continue; + } + + if (!e_book_get_contacts(book, query, &contacts, &err)) { + printf("Can't get contacts?\n"); + g_clear_error(&err); + g_object_unref(book); + continue; + } + + found = contacts != NULL; + + printf(" %s\n", found?"found":"not found"); + + g_list_foreach(contacts, (GFunc)g_object_unref, NULL); + g_list_free(contacts); + + g_object_unref(book); + } + + e_book_query_unref(query); + + node->found = found; + node->stamp = now; + + g_hash_table_insert(emu_addr_cache, node->addr, node); + + return found; +} |