Re: [evolution-patches] Re: patch for junk-api implementation (eds/servers/groupwise)



Including one more API implementation
(e_gw_connection_get_junk_settings) in the same patch, so that this also
gets in along with the previous one.
Here is the patch which includes all of them.


Thanks,
Vivek Jain
On Sun, 2005-06-26 at 12:54 +0000, Vivek Jain  wrote:
> Hi,
> 
> Considering the scope of this implementation of api's being used beyond
> evolution, I have included more options in some of the new api's.
> I have added one more api which removes the junkentry.
> I had to define a structure in the e-gw-connection.h since I didn't find
> any other suitable place. The functions which build messages etc. are
> corrently e-gw-connection.c but can be moved anywhere else without any
> change.
> Here is the fresh patch.
> 
> Thanks,
> Vivek Jain
> 
> 
> 
> On Fri, 2005-06-24 at 10:12 +0000, Vivek Jain  wrote:
> > Here is the patch with more generic implementation of api's.
> > 
> > Thanks,
> > Vivek Jain
> > On Tue, 2005-06-21 at 06:49 +0000, Vivek Jain(Jain Vivek) wrote:
> > > Hi,
> > > 
> > > This patch adds some methods to e-gw-connection.c that implement the
> > > junk handling APIs for groupwise. 
> > > 
> > > Thanks,
> > > Vivek Jain
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/groupwise/ChangeLog,v
retrieving revision 1.141
diff -u -p -r1.141 ChangeLog
--- ChangeLog	8 Jun 2005 05:42:43 -0000	1.141
+++ ChangeLog	28 Jun 2005 10:02:38 -0000
@@ -1,3 +1,21 @@
+2005-06-27  Vivek Jain <jvivek novell com>
+	
+	* e-gw-connection.h:
+	Added EGwJunkEntry structure
+	* e-gw-connection.[ch]: added functions
+	(e_gw_connection_modify_junk_mail_settings):to set/modify junk mail
+	settings
+	(e_gw_connection_create_junk_entry): to create a junk entry 
+	(e_gw_connection_get_junk_entries) : to get junk entries stored at
+	server
+	uses to new helper functions
+	(get_junklist_from_soap_response)
+	(e_gw_junkentry_new_from_soap_parameter).
+	(e_gw_connection_remove_junk_entry): to remove a junk entry
+	(e_gw_connection_get_junk_settings): to get the junk settings
+	(parse_junk_settings): actually parses response and assigns values
+	
+
 2005-06-08  Srinivasa Ragavan <sragavan novell com>
 
 	* e-gw-connection.[ch] :Added function to retrive deltainfo and delta
Index: e-gw-connection.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/groupwise/e-gw-connection.h,v
retrieving revision 1.59
diff -u -p -r1.59 e-gw-connection.h
--- e-gw-connection.h	8 Jun 2005 05:42:43 -0000	1.59
+++ e-gw-connection.h	28 Jun 2005 10:02:38 -0000
@@ -52,6 +52,15 @@ struct _EGwConnectionClass {
 	GObjectClass parent_class;
 };
 
+typedef struct {
+	char *id ;
+	char *match ;
+	char *matchType ;
+	char *lastUsed ;
+	int version;
+	char *modified;
+} EGwJunkEntry;
+
 GType          e_gw_connection_get_type (void);
 EGwConnection *e_gw_connection_new (const char *uri, const char *username, const char *password);
 
@@ -147,6 +156,11 @@ EGwConnectionStatus e_gw_connection_purg
 EGwConnectionStatus e_gw_connection_mark_read(EGwConnection *cnc, GList *item_ids) ;
 EGwConnectionStatus e_gw_connection_mark_unread(EGwConnection *cnc, GList *item_ids) ;
 EGwConnectionStatus e_gw_connection_reply_item (EGwConnection *cnc, const char *id, const char *view, EGwItem **item) ;
+EGwConnectionStatus e_gw_connection_create_junk_entry (EGwConnection *cnc, const char *value, const char *match_type , const char *list_type);
+EGwConnectionStatus e_gw_connection_get_junk_settings (EGwConnection *cnc, int *use_junk, int *use_block, int *use_pab,  int *persistence);
+EGwConnectionStatus e_gw_connection_modify_junk_settings (EGwConnection *cnc, int use_junk, int use_block, int use_pab , int persistence);
+EGwConnectionStatus e_gw_connection_get_junk_entries (EGwConnection *cnc, GList **entries);
+EGwConnectionStatus  e_gw_connection_remove_junk_entry (EGwConnection *cnc, const char *id);
 G_END_DECLS
 
 #endif
Index: e-gw-connection.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/groupwise/e-gw-connection.c,v
retrieving revision 1.118
diff -u -p -r1.118 e-gw-connection.c
--- e-gw-connection.c	8 Jun 2005 05:42:43 -0000	1.118
+++ e-gw-connection.c	28 Jun 2005 10:02:39 -0000
@@ -2901,3 +2901,408 @@ e_gw_connection_reply_item (EGwConnectio
 
         return E_GW_CONNECTION_STATUS_OK;
 }
+
+/* e_gw_connection_create_junk_entry :creates a junk entry in the list
+ * @cnc
+ * @value : to be added in the list 
+ * @match_type : "email"/"domain" default: email
+ * @list_type : "junk"/"trust"/"block" default: junk
+ * */
+
+EGwConnectionStatus
+e_gw_connection_create_junk_entry (EGwConnection *cnc, const char *value, const char *match_type, const char *list_type) 
+{
+	SoupSoapMessage *msg;
+        SoupSoapResponse *response;
+        EGwConnectionStatus status;
+        
+	g_return_val_if_fail (E_IS_GW_CONNECTION (cnc), E_GW_CONNECTION_STATUS_INVALID_OBJECT);
+	g_return_val_if_fail (value != NULL, E_GW_CONNECTION_STATUS_INVALID_OBJECT);
+	
+	/* build the SOAP message */
+        msg = e_gw_message_new_with_header (cnc->priv->uri, cnc->priv->session_id, "createJunkEntryRequest");
+        if (!msg) {
+                g_warning (G_STRLOC ": Could not build SOAP message");
+                return E_GW_CONNECTION_STATUS_UNKNOWN;
+        }
+	soup_soap_message_start_element (msg, "entry", NULL, NULL);
+	e_gw_message_write_string_parameter (msg, "match", NULL, value);
+	e_gw_message_write_string_parameter (msg, "matchType", NULL, match_type);
+	e_gw_message_write_string_parameter (msg, "listType", NULL, list_type);
+	soup_soap_message_end_element (msg);
+	e_gw_message_write_footer (msg);
+	response =  e_gw_connection_send_message (cnc, msg);
+	
+	if (!response) {
+		g_object_unref (msg);
+		return E_GW_CONNECTION_STATUS_NO_RESPONSE;
+	}
+
+	status = e_gw_connection_parse_response_status (response);
+	if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
+		reauthenticate (cnc);
+	/* free memory */
+	g_object_unref (response);
+	g_object_unref (msg);
+
+	return status;
+}
+
+static void
+parse_junk_settings (SoupSoapParameter *param, int *use_junk, int *use_block, int *use_pab, int *persistence)
+{
+	SoupSoapParameter *subparam, *field_param, *val_param;
+	
+	int val;
+	
+	if (param == NULL)
+		return ;
+	else	{
+		/* parse these parameters into junk junk settings*/
+		for (subparam = soup_soap_parameter_get_first_child_by_name (param, "setting");
+				subparam != NULL;
+				subparam = soup_soap_parameter_get_next_child_by_name (subparam, "setting")) {
+			char *field = NULL;
+
+			field_param = soup_soap_parameter_get_first_child_by_name (subparam, "field");
+			val_param = soup_soap_parameter_get_first_child_by_name (subparam, "value");
+
+			if (field_param) {
+				field = soup_soap_parameter_get_string_value (field_param);
+				if (!field)
+					continue;
+			} else
+				continue;
+
+			if (!g_ascii_strcasecmp (field, "useJunkList")) {
+				if (val_param)
+					val = soup_soap_parameter_get_int_value (val_param);
+				*use_junk = val;
+			}
+			if (!g_ascii_strcasecmp (field, "useBlockList")) {
+				if (val_param)
+					val = soup_soap_parameter_get_int_value (val_param);
+				*use_block = val;
+			}
+
+			if (!g_ascii_strcasecmp (field, "usePAB")) {
+				if (val_param)
+					val = soup_soap_parameter_get_int_value (val_param);
+				*use_pab = val;
+			}
+			if (!g_ascii_strcasecmp (field, "persistence")) { 
+				if (val_param)
+					val = soup_soap_parameter_get_int_value (val_param);
+				*persistence = val;
+			}
+		}
+	}
+}
+
+/*
+ * e_gw_connection_get_junk_settings: gets the junk settings
+ * use_junk : returned value, whether junk list is being used
+ * use_block: use block list
+ * use_pab: returned value, whether personal addresbook is used
+ * persistence: 
+ * */
+EGwConnectionStatus
+e_gw_connection_get_junk_settings (EGwConnection *cnc, int *use_junk, int *use_block, int *use_pab, int *persistence)
+{
+	SoupSoapMessage *msg;
+        SoupSoapResponse *response;
+	SoupSoapParameter *param;
+        EGwConnectionStatus status;
+        
+	g_return_val_if_fail (E_IS_GW_CONNECTION (cnc), E_GW_CONNECTION_STATUS_INVALID_OBJECT);
+	
+	/* build the SOAP message */
+        msg = e_gw_message_new_with_header (cnc->priv->uri, cnc->priv->session_id, "getJunkMailSettingsRequest");
+
+	if (!msg) {
+                g_warning (G_STRLOC ": Could not build SOAP message");
+                return E_GW_CONNECTION_STATUS_UNKNOWN;
+        }
+	e_gw_message_write_footer (msg);
+	response =  e_gw_connection_send_message (cnc, msg);
+	
+	if (!response) {
+		g_object_unref (msg);
+		return E_GW_CONNECTION_STATUS_NO_RESPONSE;
+	}
+
+	status = e_gw_connection_parse_response_status (response);
+	if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
+		reauthenticate (cnc);
+
+	/* if status is OK - parse result. return the list */
+	param = soup_soap_response_get_first_parameter_by_name (response, "settings");
+	parse_junk_settings (param, use_junk, use_block, use_pab, persistence);
+
+
+	/* free memory */
+	g_object_unref (response);
+	g_object_unref (msg);
+
+	return status;
+
+}
+
+
+/* e_gw_connection_modify_junk_settings: creates/removes junk mail settings
+ * @cnc
+ * @use_junk 0 : disable spam learning from junk list 1: enable
+ * @use_block: same for block list
+ * use_pab 1: put messages except from personal add book in junk, 0 disable
+ * @persistence :delete after
+ * */
+ 
+EGwConnectionStatus
+e_gw_connection_modify_junk_settings (EGwConnection *cnc, int use_junk, int use_pab, int use_block, int persistence)
+{
+	SoupSoapMessage *msg;
+        SoupSoapResponse *response;
+        EGwConnectionStatus status;
+        
+	g_return_val_if_fail (E_IS_GW_CONNECTION (cnc), E_GW_CONNECTION_STATUS_INVALID_OBJECT);
+	
+	/* build the SOAP message */
+        msg = e_gw_message_new_with_header (cnc->priv->uri, cnc->priv->session_id, "modifyJunkMailSettingsRequest");
+        if (!msg) {
+                g_warning (G_STRLOC ": Could not build SOAP message");
+                return E_GW_CONNECTION_STATUS_UNKNOWN;
+        }
+	soup_soap_message_start_element (msg, "settings", NULL, NULL);
+
+	if (use_junk) {
+		soup_soap_message_start_element (msg, "setting", NULL, NULL);
+		e_gw_message_write_string_parameter (msg, "field", NULL, "useJunkList");
+		e_gw_message_write_int_parameter (msg, "value", NULL, use_junk);
+		soup_soap_message_end_element (msg);
+	}
+
+	if (use_pab) {
+		soup_soap_message_start_element (msg, "setting", NULL, NULL);
+		e_gw_message_write_string_parameter (msg, "field", NULL, "usePAB");
+		e_gw_message_write_int_parameter (msg, "value", NULL, use_pab);
+		soup_soap_message_end_element (msg);
+	}
+
+	if (use_pab) {
+		soup_soap_message_start_element (msg, "setting", NULL, NULL);
+		e_gw_message_write_string_parameter (msg, "field", NULL, "useBlockList");
+		e_gw_message_write_int_parameter (msg, "value", NULL, use_pab);
+		soup_soap_message_end_element (msg);
+	}
+
+	soup_soap_message_start_element (msg, "setting", NULL, NULL);
+	e_gw_message_write_string_parameter (msg, "field", NULL, "persistence");
+	e_gw_message_write_int_parameter (msg, "value", NULL, persistence);
+	soup_soap_message_end_element (msg);
+	soup_soap_message_end_element (msg);
+	e_gw_message_write_footer (msg);
+	response =  e_gw_connection_send_message (cnc, msg);
+	
+	if (!response) {
+		g_object_unref (msg);
+		return E_GW_CONNECTION_STATUS_NO_RESPONSE;
+	}
+
+	status = e_gw_connection_parse_response_status (response);
+	if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
+		reauthenticate (cnc);
+	/* free memory */
+	g_object_unref (response);
+	g_object_unref (msg);
+
+	return status;
+}
+
+
+/*TODO:Move this code to some other file and make this function public*/
+
+static EGwJunkEntry *
+e_gw_junkentry_new_from_soap_parameter (SoupSoapParameter *param)
+{
+	EGwJunkEntry *junk_entry;
+	SoupSoapParameter *subparam;
+	int int_value;
+	char *value;
+
+	g_return_val_if_fail (param != NULL, NULL);
+
+	junk_entry = g_new0(EGwJunkEntry, 1);
+
+	subparam = soup_soap_parameter_get_first_child_by_name (param, "id");
+	if (!subparam) {
+		g_warning (G_STRLOC ": found junk entry with no name");
+		return NULL;
+	}
+
+	value = soup_soap_parameter_get_string_value (subparam);
+	junk_entry->id = g_strdup (value); 
+	g_free (value);
+
+	subparam = soup_soap_parameter_get_first_child_by_name (param, "match");
+	if (!subparam) {
+		g_warning (G_STRLOC ": found junk entry with no Match");
+		return NULL;
+	}
+		
+		value = soup_soap_parameter_get_string_value (subparam);
+		junk_entry->match = g_strdup (value);
+		g_free (value);
+	
+
+	subparam = soup_soap_parameter_get_first_child_by_name (param, "matchType");
+	if (!subparam) {
+		g_warning (G_STRLOC ": found junk entry with no MatchType");
+		return NULL;
+	}
+		value = soup_soap_parameter_get_string_value (subparam);
+		junk_entry->matchType = g_strdup (value);
+		g_free (value);
+	
+	subparam = soup_soap_parameter_get_first_child_by_name (param, "lastUsed");
+	if (subparam) {
+		value = soup_soap_parameter_get_string_value (subparam);
+		junk_entry->lastUsed = g_strdup (value);
+		g_free (value);
+	}
+	
+	subparam = soup_soap_parameter_get_first_child_by_name (param, "version");
+	if (subparam) {
+		int_value = soup_soap_parameter_get_int_value (subparam);
+		junk_entry->version = int_value;
+	}
+	
+	subparam = soup_soap_parameter_get_first_child_by_name (param, "modified");
+	if (subparam) {
+		value = soup_soap_parameter_get_string_value (subparam);
+		junk_entry->modified = g_strdup (value);
+		g_free (value);
+	}
+
+	return junk_entry;
+
+}
+
+/*TODO:Move this code to some other file and make this function public*/
+
+static void
+get_junk_list_from_soap_response (SoupSoapResponse *response, GList **entries)
+{
+	SoupSoapParameter *param, *subparam;
+
+	param = soup_soap_response_get_first_parameter_by_name (response, "junk");
+	if (param) {
+		/* parse these parameters into junk entries*/
+		for (subparam = soup_soap_parameter_get_first_child_by_name (param, "entry");
+				subparam != NULL;
+				subparam = soup_soap_parameter_get_next_child_by_name (subparam, "entry")) {
+			EGwJunkEntry *junk_entry;
+
+			junk_entry = e_gw_junkentry_new_from_soap_parameter (subparam);
+			if (junk_entry)
+				*entries = g_list_append (*entries, junk_entry);
+		}
+	}	
+	param = soup_soap_response_get_first_parameter_by_name (response, "block");
+	if (param) {
+		for (subparam = soup_soap_parameter_get_first_child_by_name (param, "entry");
+				subparam != NULL;
+				subparam = soup_soap_parameter_get_next_child_by_name (subparam, "entry")) {
+			EGwJunkEntry *junk_entry;
+			junk_entry = e_gw_junkentry_new_from_soap_parameter (subparam);
+			if (junk_entry)
+				*entries = g_list_append (*entries, junk_entry);
+		}
+	}
+	param = soup_soap_response_get_first_parameter_by_name (response, "trust");
+	if (param) {
+		for (subparam = soup_soap_parameter_get_first_child_by_name (param, "entry");
+				subparam != NULL;
+				subparam = soup_soap_parameter_get_next_child_by_name (subparam, "entry")) {
+			EGwJunkEntry *junk_entry;
+			junk_entry = e_gw_junkentry_new_from_soap_parameter (subparam);
+			if (junk_entry)
+				*entries = g_list_append (*entries, junk_entry);
+		}
+	}
+ }
+
+	
+/* Caller must free the entries*/
+
+EGwConnectionStatus
+e_gw_connection_get_junk_entries (EGwConnection *cnc, GList **entries)
+{
+	SoupSoapMessage *msg;
+        SoupSoapResponse *response;
+        EGwConnectionStatus status;
+        
+	g_return_val_if_fail (E_IS_GW_CONNECTION (cnc), E_GW_CONNECTION_STATUS_INVALID_OBJECT);
+	
+	/* build the SOAP message */
+        msg = e_gw_message_new_with_header (cnc->priv->uri, cnc->priv->session_id, "getJunkEntriesRequest");
+        msg = e_gw_message_new_with_header (cnc->priv->uri, cnc->priv->session_id, "getJunkMailSettingsRequest");
+
+	if (!msg) {
+                g_warning (G_STRLOC ": Could not build SOAP message");
+                return E_GW_CONNECTION_STATUS_UNKNOWN;
+        }
+	e_gw_message_write_footer (msg);
+	response =  e_gw_connection_send_message (cnc, msg);
+	
+	if (!response) {
+		g_object_unref (msg);
+		return E_GW_CONNECTION_STATUS_NO_RESPONSE;
+	}
+
+	status = e_gw_connection_parse_response_status (response);
+	if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
+		reauthenticate (cnc);
+
+	/* if status is OK - parse result. return the list */
+	get_junk_list_from_soap_response (response, entries);
+	
+	/* free memory */
+	g_object_unref (response);
+	g_object_unref (msg);
+
+	return status;
+}
+
+EGwConnectionStatus
+e_gw_connection_remove_junk_entry (EGwConnection *cnc, const char *id)
+{
+	SoupSoapMessage *msg;
+	SoupSoapResponse *response;
+	EGwConnectionStatus status;
+
+	g_return_val_if_fail (E_IS_GW_CONNECTION (cnc), E_GW_CONNECTION_STATUS_INVALID_CONNECTION);
+	g_return_val_if_fail (id != NULL, E_GW_CONNECTION_STATUS_INVALID_OBJECT);
+
+	/* build the SOAP message */
+	msg = e_gw_message_new_with_header (cnc->priv->uri, cnc->priv->session_id, "removeJunkEntryRequest");
+
+	e_gw_message_write_string_parameter (msg, "id", NULL, id);
+	e_gw_message_write_footer (msg);
+
+	/* send message to server */
+	response = e_gw_connection_send_message (cnc, msg);
+	if (!response) {
+		g_object_unref (msg);
+		return E_GW_CONNECTION_STATUS_NO_RESPONSE;
+	}
+
+	status = e_gw_connection_parse_response_status (response);
+	if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
+		reauthenticate (cnc);
+	/* free memory */
+	g_object_unref (response);
+	g_object_unref (msg);
+
+	return status;
+
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]