<commit_before>/*
 * Filename: eas-mail.c
 */
 
#include <libedataserver/e-flag.h>
#include "eas-mail.h"
#include "eas-mail-stub.h"
#include "eas-folder.h"
#include "eas-sync-folder-hierarchy.h"


G_DEFINE_TYPE (EasMail, eas_mail, G_TYPE_OBJECT);

static void
eas_mail_init (EasMail *object)
{
	/* TODO: Add initialization code here */
}

static void
eas_mail_finalize (GObject *object)
{
	/* TODO: Add deinitalization code here */

	G_OBJECT_CLASS (eas_mail_parent_class)->finalize (object);
}

static void
eas_mail_class_init (EasMailClass *klass)
{
	GObjectClass* object_class = G_OBJECT_CLASS (klass);
	GObjectClass* parent_class = G_OBJECT_CLASS (klass);

	object_class->finalize = eas_mail_finalize;
	
	 /* Binding to GLib/D-Bus" */ 
    dbus_g_object_type_install_info(EAS_TYPE_MAIL,
                                            &dbus_glib_eas_mail_object_info);
}



gboolean eas_mail_start_sync(EasMail* easMailObj, gint valueIn, GError** error)
{
/*
guint64 account_uid = 12345;
const gchar* sync_key =NULL; 
gchar **ret_sync_key =NULL;
gchar **ret_created_folders_array =NULL;
gchar **ret_updated_folders_array =NULL;
gchar **ret_deleted_folders_array =NULL;


eas_connection_folder_sync(easMailObj->easConnection, 
                                            account_uid,
						sync_key, 
						ret_sync_key,  
						ret_created_folders_array,
						ret_updated_folders_array,
						ret_deleted_folders_array,
						error);
*/
  return TRUE;
}

void eas_mail_test_001(EasMail* obj, DBusGMethodInvocation* context)
{

 	g_print(">> eas_mail_test_001()\n");
        GError *error = NULL;
        gchar *ok_str = g_strdup ("OK");
         // ...

        if (error) {
		g_print(">> eas_mail_test_001 -error-\n");
                dbus_g_method_return_error (context, error);
                g_error_free (error);
        } else{
		g_print(">> eas_mail_test_001 -No error-\n");
                dbus_g_method_return (context, ok_str);
	}

        g_free (ok_str);
}

gboolean eas_mail_set_eas_connection(EasMail* easMailObj, EasConnection* easConnObj)
{
  gboolean ret= FALSE;

  if(easConnObj != NULL){
  	easMailObj->easConnection = easConnObj;
	ret= TRUE;
  }
  return ret;
}

// allocates an array of ptrs to strings and the strings it points to and populates each string with serialised folder details
// null terminates the array
static gboolean 
build_serialised_folder_array(gchar ***serialised_folder_array, const GSList *folder_list, GError **error)
{ 
	gboolean ret = TRUE;
	g_assert(*serialised_folder_array == NULL);
	//g_assert(folder_list != NULL);

	guint array_len = g_slist_length((GSList*)folder_list) + 1;	//cast away const to avoid warning. +1 to allow terminating null 
	*serialised_folder_array = g_malloc0(array_len * sizeof(gchar*));
	GSList *l = (GSList*)folder_list;
	guint i = 0;
	for(i = 0; i < array_len - 1; i++)
	{
		g_assert(l != NULL);
		gchar *serialised;
		EasFolder *folder;
		folder = l->data;
		if(!eas_folder_serialise(folder, &serialised))
		{
			ret = FALSE;
			goto cleanup;
		}
		*serialised_folder_array[i] = serialised;		
		l = g_slist_next (l);		
	}
	*serialised_folder_array[i] = NULL;
	
cleanup:<commit_msg>fix folder serialise (shouldn't have trailing separator)clear<commit_after>/*
 * Filename: eas-mail.c
 */
 
#include <libedataserver/e-flag.h>
#include "eas-mail.h"
#include "eas-mail-stub.h"
#include "eas-folder.h"
#include "eas-sync-folder-hierarchy.h"


G_DEFINE_TYPE (EasMail, eas_mail, G_TYPE_OBJECT);

static void
eas_mail_init (EasMail *object)
{
	/* TODO: Add initialization code here */
}

static void
eas_mail_finalize (GObject *object)
{
	/* TODO: Add deinitalization code here */

	G_OBJECT_CLASS (eas_mail_parent_class)->finalize (object);
}

static void
eas_mail_class_init (EasMailClass *klass)
{
	GObjectClass* object_class = G_OBJECT_CLASS (klass);
	GObjectClass* parent_class = G_OBJECT_CLASS (klass);

	object_class->finalize = eas_mail_finalize;
	
	 /* Binding to GLib/D-Bus" */ 
    dbus_g_object_type_install_info(EAS_TYPE_MAIL,
                                            &dbus_glib_eas_mail_object_info);
}



gboolean eas_mail_start_sync(EasMail* easMailObj, gint valueIn, GError** error)
{
/*
guint64 account_uid = 12345;
const gchar* sync_key =NULL; 
gchar **ret_sync_key =NULL;
gchar **ret_created_folders_array =NULL;
gchar **ret_updated_folders_array =NULL;
gchar **ret_deleted_folders_array =NULL;


eas_connection_folder_sync(easMailObj->easConnection, 
                                            account_uid,
						sync_key, 
						ret_sync_key,  
						ret_created_folders_array,
						ret_updated_folders_array,
						ret_deleted_folders_array,
						error);
*/
  return TRUE;
}

void eas_mail_test_001(EasMail* obj, DBusGMethodInvocation* context)
{

 	g_print(">> eas_mail_test_001()\n");
        GError *error = NULL;
        gchar *ok_str = g_strdup ("OK");
         // ...

        if (error) {
		g_print(">> eas_mail_test_001 -error-\n");
                dbus_g_method_return_error (context, error);
                g_error_free (error);
        } else{
		g_print(">> eas_mail_test_001 -No error-\n");
                dbus_g_method_return (context, ok_str);
	}

        g_free (ok_str);
}

gboolean eas_mail_set_eas_connection(EasMail* easMailObj, EasConnection* easConnObj)
{
  gboolean ret= FALSE;

  if(easConnObj != NULL){
  	easMailObj->easConnection = easConnObj;
	ret= TRUE;
  }
  return ret;
}

// allocates an array of ptrs to strings and the strings it points to and populates each string with serialised folder details
// null terminates the array
static gboolean 
build_serialised_folder_array(gchar ***serialised_folder_array, const GSList *folder_list, GError **error)
{ 
	gboolean ret = TRUE;
	g_assert(*serialised_folder_array == NULL);
	//g_assert(folder_list != NULL);

	guint array_len = g_slist_length((GSList*)folder_list) + 1;	//cast away const to avoid warning. +1 to allow terminating null 
	*serialised_folder_array = g_malloc0(array_len * sizeof(gchar*));
	GSList *l = (GSList*)folder_list;
	guint i = 0;
	g_print("array_len = %d\n", array_len -1);
	for(i = 0; i < array_len - 1; i++)
	{
		g_assert(l != NULL);
		gchar *serialised;
		EasFolder *folder;
		folder = l->data;
		if(!eas_folder_serialise(folder, &serialised))
		{
			g_print("failed!");
			ret = FALSE;
			goto cleanup;
		}
		*serialised_folder_array[i] = serialised;		
		l = g_slist_next (l);		
	}
	*serialised_folder_array[i] = NULL;
	
cleanup:
{'fraction_non_alphanumeric': 0.11294081093677179, 'fraction_numerical': 0.007922945471492932, 'mean_word_length': 3.6416726748377792, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '87176', 'n_tokens_mistral': 2512, 'n_tokens_neox': 2311, 'n_words': 488}