[evolution-mapi/native-gal] First drop of blood drawn.Sign of success with GAL
- From: Bharath Acharya <abharath src gnome org>
- To: svn-commits-list gnome org
- Subject: [evolution-mapi/native-gal] First drop of blood drawn.Sign of success with GAL
- Date: Mon, 27 Jul 2009 11:12:05 +0000 (UTC)
commit 79872561644d967bdff6a7857c46666817542998
Author: Bharath Acharya <abharath novell com>
Date: Mon Jul 27 16:38:35 2009 +0530
First drop of blood drawn.Sign of success with GAL
Able to view GAL entries in Evolution. Now need to fetch them all
and dump it into the GAL factory.
.../exchange-mapi-account-listener.c | 13 +-
.../exchange-mapi-account-setup.c | 11 -
src/addressbook/e-book-backend-mapi-gal.c | 240 ++++++++++++++++++--
src/libexchangemapi/exchange-mapi-connection.c | 38 +++-
src/libexchangemapi/exchange-mapi-connection.h | 7 +-
5 files changed, 258 insertions(+), 51 deletions(-)
---
diff --git a/src/account-setup-eplugin/exchange-mapi-account-listener.c b/src/account-setup-eplugin/exchange-mapi-account-listener.c
index 4766884..15b8934 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-listener.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-listener.c
@@ -458,26 +458,15 @@ add_addressbook_sources (EAccount *account, GSList *folders)
//Add GAL
{
- char *uri, *tmp;
- mapi_id_t fid, pfid;
- const char *sfid;
+ char *uri;
uri = g_strdup_printf("mapigal://%s %s/;Global Address List", url->user, url->host);
source = e_source_new_with_absolute_uri ("Global Address List", uri);
// source = e_source_new ("Global Address List", g_strconcat (";","Global Address List" , NULL));
e_source_set_property (source, "auth", "plain/password");
e_source_set_property (source, "auth-domain", "MAPIGAL");
- fid = exchange_mapi_get_default_folder_id (olFolderContacts);
//FIXME: Offline handling
- sfid = e_source_get_property (source, "parent-fid");
- exchange_mapi_util_mapi_id_from_string (sfid, &pfid);
-
- fid = exchange_mapi_create_folder (olFolderContacts, pfid, e_source_peek_name (source));
- tmp = exchange_mapi_util_mapi_id_to_string (fid);
- e_source_set_property(source, "folder-id", tmp);
- g_free (tmp);
-
e_source_set_property(source, "user", url->user);
e_source_set_property(source, "host", camel_url_get_param (url, "ad_server"));
e_source_set_property(source, "view-limit", camel_url_get_param (url, "ad_limit"));
diff --git a/src/account-setup-eplugin/exchange-mapi-account-setup.c b/src/account-setup-eplugin/exchange-mapi-account-setup.c
index 393464c..6648624 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-setup.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-setup.c
@@ -326,7 +326,6 @@ add_folders (GSList *folders, GtkTreeStore *ts)
gtk_tree_store_set (ts, &iter, 0, node, -1);
while (tmp) {
ExchangeMAPIFolder *folder = tmp->data;
- g_print("%s\n", folder->folder_name);
add_to_store (ts, folder);
tmp = tmp->next;
}
@@ -444,8 +443,6 @@ exchange_mapi_book_commit (EPlugin *epl, EConfigTarget *target)
EABConfigTargetSource *t = (EABConfigTargetSource *) target;
ESource *source = t->source;
char *uri_text, *tmp;
- const char *sfid;
- mapi_id_t fid, pfid;
ESourceGroup *grp;
uri_text = e_source_get_uri (source);
@@ -453,11 +450,6 @@ exchange_mapi_book_commit (EPlugin *epl, EConfigTarget *target)
return;
//FIXME: Offline handling
- sfid = e_source_get_property (source, "parent-fid");
- exchange_mapi_util_mapi_id_from_string (sfid, &pfid);
-
- fid = exchange_mapi_create_folder (olFolderContacts, pfid, e_source_peek_name (source));
- g_print("Created %016" G_GINT64_MODIFIER "X\n", fid);
grp = e_source_peek_group (source);
e_source_set_property (source, "auth", "plain/password");
e_source_set_property (source, "auth-domain", EXCHANGE_MAPI_PASSWORD_COMPONENT);
@@ -467,9 +459,6 @@ exchange_mapi_book_commit (EPlugin *epl, EConfigTarget *target)
e_source_set_property(source, "domain", e_source_group_get_property (grp, "domain"));
e_source_set_relative_uri (source, g_strconcat (";",e_source_peek_name (source), NULL));
- tmp = exchange_mapi_util_mapi_id_to_string (fid);
- e_source_set_property(source, "folder-id", tmp);
- g_free (tmp);
e_source_set_property (source, "completion", "true");
// Update the folder list in the plugin and ExchangeMAPIFolder
diff --git a/src/addressbook/e-book-backend-mapi-gal.c b/src/addressbook/e-book-backend-mapi-gal.c
index f431d9a..eb87b58 100644
--- a/src/addressbook/e-book-backend-mapi-gal.c
+++ b/src/addressbook/e-book-backend-mapi-gal.c
@@ -126,7 +126,8 @@ build_cache (EBookBackendMAPIGAL *ebmapi)
{
EBookBackendMAPIGALPrivate *priv = ((EBookBackendMAPIGAL *) ebmapi)->priv;
char *tmp;
- GSList **gal_list = NULL;
+ EContact *contact = e_contact_new ();
+ gint i = 0;
//FIXME: What if book view is NULL? Can it be? Check that.
if (!priv->cache) {
@@ -142,17 +143,33 @@ build_cache (EBookBackendMAPIGAL *ebmapi)
e_file_cache_freeze_changes (E_FILE_CACHE (priv->cache));
-/* if (!exchange_mapi_connection_fetch_items (priv->fid, NULL, NULL,
- NULL, 0,
- NULL, NULL,
- cache_contact_cb, ebmapi,
- MAPI_OPTIONS_FETCH_ALL)) {
- printf("Error during caching addressbook\n");
- e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
- return NULL;
+ GPtrArray *contacts_array = g_ptr_array_new();
+
+ exchange_mapi_util_get_gal (contacts_array);
+
+ e_book_backend_cache_add_contact (priv->cache, contact);
+ e_book_backend_summary_add_contact (priv->summary, contact);
+ g_object_unref(contact);
+
+ for (i=0;i<contacts_array->len;i++) {
+ EContact *contact = e_contact_new ();
+ ExchangeMAPIGALEntry *gal_entry = contacts_array->pdata[i];
+ char *uid;
+ GPtrArray *contacts_array = g_ptr_array_new();
+
+ uid = g_strdup_printf ("%d", i);
+
+ e_contact_set (contact, E_CONTACT_UID, uid);
+ e_contact_set (contact, E_CONTACT_FULL_NAME, gal_entry->name);
+ e_contact_set (contact, E_CONTACT_EMAIL_1, gal_entry->email);
+
+ e_book_backend_cache_add_contact (priv->cache, contact);
+ e_book_backend_summary_add_contact (priv->summary, contact);
+ g_object_unref(contact);
+ g_free (uid);
}
-*/
- exchange_mapi_util_get_gal (&gal_list);
+
+ g_ptr_array_free(contacts_array, TRUE);
tmp = g_strdup_printf("%d", (int)time (NULL));
e_book_backend_cache_set_time (priv->cache, tmp);
@@ -162,7 +179,7 @@ build_cache (EBookBackendMAPIGAL *ebmapi)
e_book_backend_summary_save (priv->summary);
priv->is_cache_ready = TRUE;
priv->is_summary_ready = TRUE;
- return NULL;
+ return NULL;
}
@@ -454,6 +471,142 @@ create_gal_contact_cb (FetchItemsCallbackData *item_data, gpointer data)
}
static void
+get_contacts_from_cache (EBookBackendMAPIGAL *ebmapi,
+ const char *query,
+ GPtrArray *ids,
+ EDataBookView *book_view,
+ BESearchClosure *closure)
+{
+ int i;
+
+ for (i = 0; i < ids->len; i ++) {
+ char *uid;
+ EContact *contact;
+
+ if (!e_flag_is_set (closure->running))
+ break;
+
+ uid = g_ptr_array_index (ids, i);
+ contact = e_book_backend_cache_get_contact (ebmapi->priv->cache, uid);
+ if (contact) {
+ e_data_book_view_notify_update (book_view, contact);
+ g_object_unref (contact);
+ }
+ }
+ if (e_flag_is_set (closure->running))
+ e_data_book_view_notify_complete (book_view,
+ GNOME_Evolution_Addressbook_Success);
+}
+
+static gboolean
+build_restriction_emails_contains (struct mapi_SRestriction *res,
+ const char *query)
+{
+ char *email=NULL, *tmp, *tmp1;
+
+ /* This currently supports "email foo bar soo" */
+ tmp = strdup (query);
+
+ tmp = strstr (tmp, "email");
+ if (tmp ) {
+ tmp = strchr (tmp, '\"');
+ if (tmp && ++tmp) {
+ tmp = strchr (tmp, '\"');
+ if (tmp && ++tmp) {
+ tmp1 = tmp;
+ tmp1 = strchr (tmp1, '\"');
+ if (tmp1) {
+ *tmp1 = 0;
+ email = tmp;
+ }
+ }
+ }
+ }
+
+
+ if (email==NULL || !strchr (email, '@'))
+ return FALSE;
+
+ res->rt = RES_PROPERTY;
+ res->res.resProperty.relop = RES_PROPERTY;
+ res->res.resProperty.ulPropTag = 0x801f001e; /* EMAIL */
+ res->res.resProperty.lpProp.ulPropTag = 0x801f001e; /* EMAIL*/
+ res->res.resProperty.lpProp.value.lpszA = email;
+
+ return TRUE;
+}
+
+static gboolean
+build_multiple_restriction_emails_contains (struct mapi_SRestriction *res,
+ struct mapi_SRestriction_or *or_res,
+ const char *query)
+{
+ char *email=NULL, *tmp, *tmp1;
+ //Number of restriction to apply
+ unsigned int res_count = 6;
+
+ /* This currently supports "email foo bar soo" */
+ tmp = strdup (query);
+
+ tmp = strstr (tmp, "email");
+ if (tmp ) {
+ tmp = strchr (tmp, '\"');
+ if (tmp && ++tmp) {
+ tmp = strchr (tmp, '\"');
+ if (tmp && ++tmp) {
+ tmp1 = tmp;
+ tmp1 = strchr (tmp1, '\"');
+ if (tmp1) {
+ *tmp1 = 0;
+ email = tmp;
+ }
+ }
+ }
+ }
+
+ if (email==NULL || !strchr (email, '@'))
+ return FALSE;
+
+ or_res[0].rt = RES_CONTENT;
+ or_res[0].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
+ or_res[0].res.resContent.ulPropTag = PR_EMS_AB_MANAGER_T;
+ or_res[0].res.resContent.lpProp.value.lpszA = email;
+
+ or_res[1].rt = RES_CONTENT;
+ or_res[1].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
+ or_res[1].res.resContent.ulPropTag = PR_DISPLAY_NAME;
+ or_res[1].res.resContent.lpProp.value.lpszA = email;
+
+ or_res[2].rt = RES_CONTENT;
+ or_res[2].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
+ or_res[2].res.resContent.ulPropTag = PR_GIVEN_NAME;
+ or_res[2].res.resContent.lpProp.value.lpszA = email;
+
+ or_res[3].rt = RES_CONTENT;
+ or_res[3].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
+ or_res[3].res.resContent.ulPropTag = 0x8084001e;
+ or_res[3].res.resContent.lpProp.value.lpszA = email;
+
+ or_res[4].rt = RES_CONTENT;
+ or_res[4].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
+ or_res[4].res.resContent.ulPropTag = 0x8094001e;
+ or_res[4].res.resContent.lpProp.value.lpszA = email;
+
+ or_res[5].rt = RES_CONTENT;
+ or_res[5].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
+ or_res[5].res.resContent.ulPropTag = 0x80a4001e;
+ or_res[5].res.resContent.lpProp.value.lpszA = email;
+
+ res = g_new0 (struct mapi_SRestriction, 1);
+
+ res->rt = RES_OR;
+ res->res.resOr.cRes = res_count;
+ res->res.resOr.res = or_res;
+
+ return TRUE;
+}
+
+static void
book_view_thread (gpointer data)
{
struct mapi_SRestriction res;
@@ -468,6 +621,7 @@ book_view_thread (gpointer data)
//Number of multiple restriction to apply
unsigned int res_count = 6;
GSList **gal_list, *l = NULL;
+ GPtrArray *contacts_array = g_ptr_array_new();
if (enable_debug)
printf("mapi: book view\n");
@@ -480,26 +634,70 @@ book_view_thread (gpointer data)
switch (priv->mode) {
case GNOME_Evolution_Addressbook_MODE_REMOTE:
- exchange_mapi_util_get_gal (&gal_list);
- break;
-/* if (!exchange_mapi_connection_fetch_items (priv->fid, NULL, NULL,
- NULL, 0,
- NULL, NULL,
- create_gal_contact_cb, book_view,
- MAPI_OPTIONS_FETCH_GAL)) {
+ exchange_mapi_util_get_gal (contacts_array);
+ if (!exchange_mapi_connection_exists ()) {
+ e_book_backend_notify_auth_required (E_BOOK_BACKEND (backend));
+ e_data_book_view_notify_complete (book_view,
+ GNOME_Evolution_Addressbook_AuthenticationRequired);
+ bonobo_object_unref (book_view);
+ return;
+ }
+
+
+ if (priv->marked_for_offline && priv->cache && priv->is_cache_ready) {
+ if (priv->is_summary_ready &&
+ e_book_backend_summary_is_summary_query (priv->summary, query)) {
+ if (enable_debug)
+ printf ("reading the contacts from summary \n");
+ ids = e_book_backend_summary_search (priv->summary, query);
+ if (ids && ids->len > 0) {
+ get_contacts_from_cache (backend, query, ids, book_view, closure);
+ g_ptr_array_free (ids, TRUE);
+ }
+ bonobo_object_unref (book_view);
+ return;
+ }
+
+ printf("Summary seems to be not there or not a summary query, lets fetch from cache directly\n");
+
+ /* We are already cached. Lets return from there. */
+ contacts = e_book_backend_cache_get_contacts (priv->cache,
+ query);
+ temp_list = contacts;
+ for (; contacts != NULL; contacts = g_list_next(contacts)) {
+ if (!e_flag_is_set (closure->running)) {
+ for (;contacts != NULL; contacts = g_list_next (contacts))
+ g_object_unref (contacts->data);
+ break;
+ }
+ e_data_book_view_notify_update (book_view,
+ E_CONTACT(contacts->data));
+ g_object_unref (contacts->data);
+ }
if (e_flag_is_set (closure->running))
e_data_book_view_notify_complete (book_view,
- GNOME_Evolution_Addressbook_OtherError);
+ GNOME_Evolution_Addressbook_Success);
+ if (temp_list)
+ g_list_free (temp_list);
bonobo_object_unref (book_view);
return;
}
+ if (e_book_backend_summary_is_summary_query (priv->summary, query)) {
+ or_res = g_new (struct mapi_SRestriction_or, res_count);
+
+ if (!build_multiple_restriction_emails_contains (&res, or_res, query)) {
+ e_data_book_view_notify_complete (book_view,
+ GNOME_Evolution_Addressbook_OtherError);
+ return ;
+ }
+
if (e_flag_is_set (closure->running))
e_data_book_view_notify_complete (book_view,
GNOME_Evolution_Addressbook_Success);
bonobo_object_unref (book_view);
break;
-*/
+ }
}
}
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index f894833..ddcb397 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -708,8 +708,33 @@ cleanup:
return status;
}
+
+
+static ExchangeMAPIGALEntry *
+mapidump_PAB_gal_entry (struct SRow *aRow)
+{
+ const char *addrtype;
+ const char *name;
+ const char *email;
+ const char *account;
+
+ addrtype = (const char *)find_SPropValue_data(aRow, PR_ADDRTYPE_UNICODE);
+ name = (const char *)find_SPropValue_data(aRow, PR_DISPLAY_NAME_UNICODE);
+ email = (const char *)find_SPropValue_data(aRow, PR_EMAIL_ADDRESS_UNICODE);
+ account = (const char *)find_SPropValue_data(aRow, PR_ACCOUNT_UNICODE);
+
+ printf("[%s] %s:\n\tName: %-25s\n\tEmail: %-25s\n",
+ addrtype, account, name, email);
+
+ ExchangeMAPIGALEntry *gal_entry = g_new0 (ExchangeMAPIGALEntry, 1);
+ gal_entry->name = g_strdup (name);
+ gal_entry->email = g_strdup (email);
+
+ return gal_entry;
+}
+
gboolean
-exchange_mapi_util_get_gal (GSList **gal_list)
+exchange_mapi_util_get_gal (GPtrArray *contacts_array)
{
struct SPropTagArray *SPropTagArray;
struct SRowSet *SRowSet;
@@ -717,8 +742,8 @@ exchange_mapi_util_get_gal (GSList **gal_list)
uint32_t i;
uint32_t count;
uint8_t ulFlags;
- TALLOC_CTX *mem_ctx;
-
+ TALLOC_CTX *mem_ctx;
+
mem_ctx = talloc_init ("ExchangeMAPI_GetGAL");
SPropTagArray = set_SPropTagArray(mem_ctx, 0xc,
@@ -745,7 +770,9 @@ exchange_mapi_util_get_gal (GSList **gal_list)
}
if (SRowSet->cRows) {
for (i = 0; i < SRowSet->cRows; i++) {
- mapidump_PAB_entry(&SRowSet->aRow[i]);
+ ExchangeMAPIGALEntry *gal_entry = g_new0 (ExchangeMAPIGALEntry, 1);
+ gal_entry = mapidump_PAB_gal_entry(&SRowSet->aRow[i]);
+ g_ptr_array_add(contacts_array, gal_entry);
}
}
ulFlags = TABLE_CUR;
@@ -1210,8 +1237,7 @@ exchange_mapi_connection_fetch_items (mapi_id_t fid,
if (options & MAPI_OPTIONS_FETCH_RECIPIENTS)
exchange_mapi_util_get_recipients (&obj_message, &recip_list);
-// if (options & MAPI_OPTIONS_FETCH_GAL)
-// exchange_mapi_util_get_gal (&gal_list);
+// exchange_mapi_util_get_gal (contacts_array);
/* get the main body stream no matter what */
if (options & MAPI_OPTIONS_FETCH_BODY_STREAM)
diff --git a/src/libexchangemapi/exchange-mapi-connection.h b/src/libexchangemapi/exchange-mapi-connection.h
index ec225d0..86dcbb4 100644
--- a/src/libexchangemapi/exchange-mapi-connection.h
+++ b/src/libexchangemapi/exchange-mapi-connection.h
@@ -85,6 +85,11 @@ typedef struct {
} ExchangeMAPIRecipient;
typedef struct {
+ const char *name;
+ const char *email;
+} ExchangeMAPIGALEntry;
+
+typedef struct {
uint32_t cValues;
struct SPropValue *lpProps;
GSList *streams;
@@ -135,7 +140,7 @@ exchange_mapi_connection_fetch_items (mapi_id_t fid,
guint32 options);
gboolean
-exchange_mapi_util_get_gal (GSList **gal_list);
+exchange_mapi_util_get_gal (GPtrArray *contacts_array);
mapi_id_t
exchange_mapi_create_folder (uint32_t olFolder, mapi_id_t pfid, const char *name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]