From 2087abde4c7c6190edfaa561d0002b312251663d Mon Sep 17 00:00:00 2001
From: Martyn Russell <martyn@lanedo.com>
Date: Fri, 17 Feb 2012 15:38:21 +0000
Subject: [PATCH] tracker-miner-evolution: Doesn't build with Evolution 3.3.5

This is based on the patch from Milan Crha <mcrha@redhat.com>

Fixes GB#669646.
---
 configure.ac                                     |   86 ++++++++++------
 src/plugins/evolution/tracker-evolution-plugin.c |  123 ++++++++++++---------
 2 files changed, 125 insertions(+), 84 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2006f50..0abfcb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -332,51 +332,76 @@ PKG_CHECK_MODULES(TRACKER_MINER_FS, [$TRACKER_MINER_FS_REQUIRED])
 TRACKER_MINER_FS_LIBS="$TRACKER_MINER_FS_LIBS -lz -lm"
 
 # Check requirements for tracker-miner-evolution
-TRACKER_MINER_EVOLUTION_REQUIRED="glib-2.0                  >= $GLIB_REQUIRED
-                                  evolution-shell-3.0       >= 3.1
-                                  evolution-plugin-3.0
-                                  evolution-data-server-1.2 >= $EDS_REQUIRED
-                                  camel-1.2                 >= $CAMEL_REQUIRED"
+evolution_plugin_name=""
+
+# First test for 3_3_5
+TRACKER_MINER_EVOLUTION_3_3_5_REQUIRED="glib-2.0                  >= $GLIB_REQUIRED
+                                        evolution-shell-3.0       >= 3.1
+                                        evolution-plugin-3.0
+                                        libemail-utils
+                                        libemail-engine
+                                        evolution-data-server-1.2 >= $EDS_REQUIRED
+                                        camel-1.2                 >= $CAMEL_REQUIRED"
 
-PKG_CHECK_MODULES(TRACKER_MINER_EVOLUTION, [$TRACKER_MINER_EVOLUTION_REQUIRED],
+PKG_CHECK_MODULES(TRACKER_MINER_EVOLUTION, [$TRACKER_MINER_EVOLUTION_3_3_5_REQUIRED],
                   [have_tracker_miner_evolution=yes],
                   [have_tracker_miner_evolution=no])
 
-if test "x$have_tracker_miner_evolution" = "xyes"; then
+if test -z "$evolution_plugin_name" && test "x$have_tracker_miner_evolution" = "xyes"; then
    evolution_plugin_name="evolution-plugin-3.0"
 
+   AC_DEFINE(EVOLUTION_SHELL_3_3_5, 1, [Use new evolution-shell API])
    AC_DEFINE(EVOLUTION_SHELL_3_2, 1, [Use new evolution-shell API])
    AC_DEFINE(EVOLUTION_SHELL_2_91, 1, [Use new evolution-shell API])
-else
-   TRACKER_MINER_EVOLUTION_REQUIRED="glib-2.0                  >= $GLIB_REQUIRED
-                                     evolution-shell-3.0
-                                     evolution-plugin-3.0
-                                     evolution-data-server-1.2 >= $EDS_REQUIRED
-                                     camel-1.2                 >= $CAMEL_REQUIRED"
+fi
 
-   PKG_CHECK_MODULES(TRACKER_MINER_EVOLUTION, [$TRACKER_MINER_EVOLUTION_REQUIRED],
-                     [have_tracker_miner_evolution=yes],
-                     [have_tracker_miner_evolution=no])
+# Second test for 3_2
+TRACKER_MINER_EVOLUTION_3_2_REQUIRED="glib-2.0                  >= $GLIB_REQUIRED
+                                      evolution-shell-3.0       >= 3.1
+                                      evolution-plugin-3.0
+                                      evolution-data-server-1.2 >= $EDS_REQUIRED
+                                      camel-1.2                 >= $CAMEL_REQUIRED"
 
-   if test "x$have_tracker_miner_evolution" = "xyes"; then
-      evolution_plugin_name="evolution-plugin-3.0"
+PKG_CHECK_MODULES(TRACKER_MINER_EVOLUTION, [$TRACKER_MINER_EVOLUTION_3_2_REQUIRED],
+                  [have_tracker_miner_evolution=yes],
+                  [have_tracker_miner_evolution=no])
 
-      AC_DEFINE(EVOLUTION_SHELL_2_91, 1, [Use new evolution-shell API])
-   else
-      evolution_plugin_name="evolution-plugin"
+if test -z "$evolution_plugin_name" && test "x$have_tracker_miner_evolution" = "xyes"; then
+   evolution_plugin_name="evolution-plugin-3.0"
 
+   AC_DEFINE(EVOLUTION_SHELL_3_2, 1, [Use new evolution-shell API])
+   AC_DEFINE(EVOLUTION_SHELL_2_91, 1, [Use new evolution-shell API])
+fi
 
-      TRACKER_MINER_EVOLUTION_REQUIRED="glib-2.0                  >= $GLIB_REQUIRED
-                                        evolution-shell           >= $EVO_SHELL_REQUIRED
-                                        evolution-plugin          >= $EVO_REQUIRED
-                                        evolution-data-server-1.2 >= $EDS_REQUIRED
-                                        camel-1.2                 >= $CAMEL_REQUIRED"
+# Third test for 2_91
+TRACKER_MINER_EVOLUTION_2_91_REQUIRED="glib-2.0                  >= $GLIB_REQUIRED
+                                       evolution-shell-3.0
+                                       evolution-plugin-3.0
+                                       evolution-data-server-1.2 >= $EDS_REQUIRED
+                                       camel-1.2                 >= $CAMEL_REQUIRED"
 
-      PKG_CHECK_MODULES(TRACKER_MINER_EVOLUTION, [$TRACKER_MINER_EVOLUTION_REQUIRED],
-                        [have_tracker_miner_evolution=yes],
-                        [have_tracker_miner_evolution=no])
+PKG_CHECK_MODULES(TRACKER_MINER_EVOLUTION, [$TRACKER_MINER_EVOLUTION_2_91_REQUIRED],
+                  [have_tracker_miner_evolution=yes],
+                  [have_tracker_miner_evolution=no])
 
-   fi
+if test -z "$evolution_plugin_name" && test "x$have_tracker_miner_evolution" = "xyes"; then
+   evolution_plugin_name="evolution-plugin-3.0"
+   AC_DEFINE(EVOLUTION_SHELL_2_91, 1, [Use new evolution-shell API])
+fi
+
+# Fourth test others (do we really want support for anything < 3.2)?
+TRACKER_MINER_EVOLUTION_LAST_REQUIRED="glib-2.0                  >= $GLIB_REQUIRED
+                                       evolution-shell           >= $EVO_SHELL_REQUIRED
+                                       evolution-plugin          >= $EVO_REQUIRED
+                                       evolution-data-server-1.2 >= $EDS_REQUIRED
+                                       camel-1.2                 >= $CAMEL_REQUIRED"
+
+PKG_CHECK_MODULES(TRACKER_MINER_EVOLUTION, [$TRACKER_MINER_EVOLUTION_LAST_REQUIRED],
+                  [have_tracker_miner_evolution=yes],
+                  [have_tracker_miner_evolution=no])
+
+if test -z "$evolution_plugin_name" && test "x$have_tracker_miner_evolution" = "xyes"; then
+   evolution_plugin_name="evolution-plugin"
 fi
 
 # Check requirements for tracker-miner-thunderbird
@@ -1155,7 +1180,6 @@ else
 fi
 
 if test "x$have_tracker_miner_evolution" = "xyes"; then
-
    AC_ARG_WITH([evolution_plugin_dir],
                AS_HELP_STRING([--with-evolution-plugin-dir],
                               [path to Evolution plugin directory]))
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index fc9923a..9b11222 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -18,6 +18,7 @@
  *
  * Authors:
  *  Philip Van Hoof <philip@codeminded.be>
+ *  Martyn Russell <martyn@lanedo.com>
  */
 
 #include "config.h"
@@ -40,27 +41,39 @@
 
 #include <sqlite3.h>
 
+#include <libedataserver/eds-version.h>
+
 #include <camel/camel.h>
 
-#include <mail/mail-config.h>
 #include <mail/em-utils.h>
-#include <mail/mail-ops.h>
 
 #ifdef EVOLUTION_SHELL_3_2
+#include <mail/em-utils.h>
 #include <mail/e-mail.h>
-#endif
-
+#endif  /* EVOLUTION_SHELL_3_2 */
+
+#ifdef EVOLUTION_SHELL_3_3_5
+#include <libemail-engine/e-mail-folder-utils.h>
+#include <libemail-engine/e-mail-session.h>
+#include <libemail-engine/mail-config.h>
+#include <libemail-engine/mail-ops.h>
+#include <libemail-utils/e-account-utils.h>
+#else  /* EVOLUTION_SHELL_3_3_5 */
+#include <mail/e-mail-folder-utils.h>
+#include <mail/mail-config.h>
+#include <mail/mail-ops.h>
+#include <e-util/e-account-utils.h>
 #ifdef EVOLUTION_SHELL_2_91
 #include <mail/e-mail-session.h>
-#else
+#else  /* EVOLUTION_SHELL_2_91 */
 #include <mail/mail-session.h>
-#endif
+#endif /* EVOLUTION_SHELL_2_91 */
+#endif /* EVOLUTION_SHELL_3_3_5 */
 
 #include <mail/e-mail-backend.h>
 #include <shell/e-shell.h>
 
 #include <e-util/e-config.h>
-#include <e-util/e-account-utils.h>
 
 #include <libedataserver/e-account.h>
 #include <libedataserver/e-account-list.h>
@@ -572,7 +585,7 @@ message_uri_build (CamelFolder *folder,
 	g_free (folder_uri);
 
 	return uri;
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	CamelURL *a_url, *url;
 	const gchar *path;
 	gchar *uri, *qry, *ppath;
@@ -605,7 +618,7 @@ message_uri_build (CamelFolder *folder,
 	camel_url_free (url);
 
 	return uri;
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 }
 
 /* When new messages arrive to- or got deleted from the summary, called in
@@ -671,7 +684,11 @@ on_folder_summary_changed (CamelFolder           *folder,
 		const CamelFlag *cflags;
 		gchar *full_sparql;
 
+#if EDS_CHECK_VERSION(3,3,1)
+		linfo = camel_folder_summary_get (summary, merged->pdata[i]);
+#else
 		linfo = camel_folder_summary_uid (summary, merged->pdata[i]);
+#endif
 
 		if (linfo) {
 			uid = (gchar *) camel_message_info_uid (linfo);
@@ -777,9 +794,9 @@ on_folder_summary_changed (CamelFolder           *folder,
 
 #ifdef EVOLUTION_SHELL_3_2
 			folder_name = camel_folder_get_display_name (folder);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 			folder_name = camel_folder_get_name (folder);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 
 			if (folder_name && *folder_name) {
 				str = g_strdup_printf ("Updating E-mails for %s",
@@ -909,9 +926,9 @@ introduce_walk_folders_in_folder (TrackerMinerEvolution *self,
 
 #ifdef EVOLUTION_SHELL_3_2
 		status = g_strdup_printf ("Processing folder %s", iter->display_name);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 		status = g_strdup_printf ("Processing folder %s", iter->name);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 		g_object_set (self,  "progress", 0.01, "status", status, NULL);
 
 		ret = sqlite3_prepare_v2 (cdb_r->db, query, -1, &stmt, NULL);
@@ -1299,11 +1316,11 @@ get_last_deleted_time (TrackerMinerEvolution *self)
 			if (!(store = (CamelStore *) camel_session_get_service (CAMEL_SESSION (session),
 #ifdef EVOLUTION_SHELL_3_2
 			                                                        account->uid))) {
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 			                                                        uri,
 			                                                        CAMEL_PROVIDER_STORE,
 			                                                        NULL))) {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 				continue;
 			}
 
@@ -1344,13 +1361,13 @@ register_on_get_folder (GObject      *source_object,
                         gpointer      user_data)
 {
 	CamelFolder *folder = camel_store_get_folder_finish (CAMEL_STORE (source_object), res, NULL);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 static void
 register_on_get_folder (gchar       *uri,
                         CamelFolder *folder,
                         gpointer     user_data)
 {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 	GetFolderInfo *info = user_data;
 	gchar *account_uri = info->account_uri;
 	CamelFolderInfo *iter = info->iter;
@@ -1433,17 +1450,17 @@ register_walk_folders_in_folder (TrackerMinerEvolution *self,
 		                        NULL,
 		                        register_on_get_folder,
 		                        info);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 		mail_get_folder (
 #ifdef EVOLUTION_SHELL_2_91
 		                 session,
-#endif
+#endif /* EVOLUTION_SHELL_2_91 */
 		                 iter->uri,
 		                 0,
 		                 register_on_get_folder,
 		                 info,
 		                 mail_msg_unordered_push);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 
 		if (iter->child) {
 			register_walk_folders_in_folder (self, iter->child,
@@ -1462,13 +1479,13 @@ unregister_on_get_folder (GObject      *source_object,
                           gpointer      user_data)
 {
 	CamelFolder *folder = camel_store_get_folder_finish (CAMEL_STORE (source_object), res, NULL);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 static void
 unregister_on_get_folder (gchar       *uri,
                           CamelFolder *folder,
                           gpointer     user_data)
 {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 	GetFolderInfo *info = user_data;
 	CamelFolderInfo *titer = info->iter;
 	TrackerMinerEvolution *self = info->self;
@@ -1532,17 +1549,17 @@ unregister_walk_folders_in_folder (TrackerMinerEvolution *self,
 		                        NULL,
 		                        unregister_on_get_folder,
 		                        info);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 		mail_get_folder (
 #ifdef EVOLUTION_SHELL_2_91
 		                 session,
-#endif
+#endif /* EVOLUTION_SHELL_2_91 */
 		                 titer->uri,
 		                 0,
 		                 unregister_on_get_folder,
 		                 info,
 		                 mail_msg_unordered_push);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 
 		if (titer->child) {
 			unregister_walk_folders_in_folder (self, titer->child,
@@ -1642,13 +1659,13 @@ on_got_folderinfo_introduce (GObject      *source_object,
 {
 	CamelStore *store = CAMEL_STORE (source_object);
 	CamelFolderInfo *iter = camel_store_get_folder_info_finish (store, res, NULL);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 static gboolean
 on_got_folderinfo_introduce (CamelStore      *store,
                              CamelFolderInfo *iter,
                              void            *data)
 {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 	TryAgainInfo *info = g_new0 (TryAgainInfo, 1);
 
 	/* Ownership of these is transfered in try_again */
@@ -1687,9 +1704,9 @@ on_got_folderinfo_introduce (CamelStore      *store,
 
 #ifdef EVOLUTION_SHELL_3_2
 	camel_store_free_folder_info (store, iter);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	return TRUE;
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 }
 
 static void
@@ -1715,11 +1732,11 @@ introduce_account_to (TrackerMinerEvolution *self,
 	if (!(store = (CamelStore *) camel_session_get_service (CAMEL_SESSION (session),
 #ifdef EVOLUTION_SHELL_3_2
 	                                                        account->uid))) {
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	                                                        uri,
 	                                                        CAMEL_PROVIDER_STORE,
 	                                                        NULL))) {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 		return;
 	}
 
@@ -1748,13 +1765,13 @@ introduce_account_to (TrackerMinerEvolution *self,
 	                             NULL,
 	                             on_got_folderinfo_introduce,
 	                             intro_info);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	mail_get_folderinfo (store, NULL, on_got_folderinfo_introduce, intro_info);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 
 #ifndef EVOLUTION_SHELL_3_2
 	g_object_unref (store);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 
 }
 
@@ -1961,13 +1978,13 @@ on_got_folderinfo_register (GObject      *source_object,
 {
 	CamelStore *store = CAMEL_STORE (source_object);
 	CamelFolderInfo *iter = camel_store_get_folder_info_finish (store, res, NULL);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 static gboolean
 on_got_folderinfo_register (CamelStore      *store,
                             CamelFolderInfo *iter,
                             void            *data)
 {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 	RegisterInfo *reg_info = data;
 	TrackerMinerEvolution *self = reg_info->self;
 	TrackerMinerEvolutionPrivate *priv;
@@ -2026,9 +2043,9 @@ on_got_folderinfo_register (CamelStore      *store,
 
 #ifdef EVOLUTION_SHELL_3_2
 	camel_store_free_folder_info (store, iter);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	return TRUE;
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 }
 
 static void
@@ -2055,11 +2072,11 @@ register_account (TrackerMinerEvolution *self,
 	if (!(store = (CamelStore *) camel_session_get_service (CAMEL_SESSION (session),
 #ifdef EVOLUTION_SHELL_3_2
 	                                                        account->uid))) {
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	                                                        uri,
 	                                                        CAMEL_PROVIDER_STORE,
 	                                                        NULL))) {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 		return;
 	}
 
@@ -2082,13 +2099,13 @@ register_account (TrackerMinerEvolution *self,
 	                             NULL,
 	                             on_got_folderinfo_register,
 	                             reg_info);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	mail_get_folderinfo (store, NULL, on_got_folderinfo_register, reg_info);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 
 #ifndef EVOLUTION_SHELL_3_2
 	g_object_unref (store);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 }
 
 #ifdef EVOLUTION_SHELL_3_2
@@ -2099,13 +2116,13 @@ on_got_folderinfo_unregister (GObject      *source_object,
 {
 	CamelStore *store = CAMEL_STORE (source_object);
 	CamelFolderInfo *titer = camel_store_get_folder_info_finish (store, res, NULL);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 static gboolean
 on_got_folderinfo_unregister (CamelStore      *store,
                               CamelFolderInfo *titer,
                               void            *data)
 {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 	RegisterInfo *reg_info = data;
 	TrackerMinerEvolution *self = reg_info->self;
 	TrackerMinerEvolutionPrivate *priv;
@@ -2131,9 +2148,9 @@ on_got_folderinfo_unregister (CamelStore      *store,
 
 #ifdef EVOLUTION_SHELL_3_2
 	camel_store_free_folder_info (store, titer);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	return TRUE;
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 }
 
 static void
@@ -2155,11 +2172,11 @@ unregister_account (TrackerMinerEvolution *self,
 	if (!(store = (CamelStore *) camel_session_get_service (CAMEL_SESSION (session),
 #ifdef EVOLUTION_SHELL_3_2
 	                                                        account->uid))) {
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	                                                        uri,
 	                                                        CAMEL_PROVIDER_STORE,
 	                                                        NULL))) {
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 		return;
 	}
 
@@ -2180,13 +2197,13 @@ unregister_account (TrackerMinerEvolution *self,
 	                             NULL,
 	                             on_got_folderinfo_unregister,
 	                             reg_info);
-#else
+#else  /* EVOLUTION_SHELL_3_2 */
 	mail_get_folderinfo (store, NULL, on_got_folderinfo_unregister, reg_info);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 
 #ifndef EVOLUTION_SHELL_3_2
 	g_object_unref (store);
-#endif
+#endif /* EVOLUTION_SHELL_3_2 */
 }
 
 static void
@@ -2425,7 +2442,7 @@ tracker_miner_evolution_init (TrackerMinerEvolution *plugin)
 		shell_backend = e_shell_get_backend_by_name (shell, "mail");
 		session = e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend));
 	}
-#endif
+#endif /* EVOLUTION_SHELL_2_91 */
 
 	priv->sparql_cancel = g_cancellable_new ();
 
-- 
1.7.7.6
