Index: evolution-data-server/servers/google/libgdata-google/gdata-google-service.c
===================================================================
--- evolution-data-server/servers/google/libgdata-google/gdata-google-service.c	(Revision 8969)
+++ evolution-data-server/servers/google/libgdata-google/gdata-google-service.c	(Arbeitskopie)
@@ -75,6 +75,30 @@
 	return error ? error : (error = g_quark_from_static_string ("gdata_google_error_quark"));
 }
 
+static void
+handle_google_redirection (SoupSession *soup_session, SoupMessage *msg)
+{
+	SoupURI *new_uri;
+	const char *new_loc;
+
+	new_loc = soup_message_headers_get (msg->response_headers, "Location");
+	g_return_if_fail (new_loc != NULL);
+
+	new_uri = soup_uri_new_with_base (soup_message_get_uri (msg), new_loc);
+	if (!new_uri) {
+		soup_message_set_status_full (msg,
+					      SOUP_STATUS_MALFORMED,
+					      "Invalid Redirect URL");
+
+		return;
+	}
+
+	soup_message_set_uri (msg, new_uri);
+	soup_uri_free (new_uri);
+
+	soup_session_send_message (soup_session, msg);
+}
+
 void
 gdata_google_service_set_credentials (GDataService *service, const gchar *username, const gchar *password)
 {
@@ -115,7 +139,6 @@
 	GHashTable *request_form;
 	gchar *request_body;
 	gchar *token = NULL;
-	int  http_status;
 
 	priv = GDATA_GOOGLE_SERVICE_GET_PRIVATE(service);
 	auth = (GDataGoogleServiceAuth *)priv->auth;
@@ -135,11 +158,11 @@
 				  SOUP_MEMORY_TAKE,
 				  request_body, strlen(request_body));
 
-	http_status = soup_session_send_message (priv->soup_session, msg);
+	soup_session_send_message (priv->soup_session, msg);
 
-    	if (http_status != 200) {
+    	if (msg->status_code != 200) {
 		g_set_error (error, SOUP_HTTP_ERROR,
-					 http_status, soup_status_get_phrase (http_status));
+					 msg->status_code, msg->reason_phrase);
 		g_object_unref(msg);
 		return (NULL != token);
 	}
@@ -188,7 +211,6 @@
 	GDataGoogleServiceAuth *auth;
 	SoupSession *soup_session;
 	SoupMessage *msg;
-	int http_status;
 
 	g_return_val_if_fail(service != NULL, NULL);
 	g_return_val_if_fail(GDATA_IS_GOOGLE_SERVICE(service),NULL);
@@ -207,10 +229,10 @@
 	soup_message_headers_append(msg->request_headers,
 			"Authorization", (gchar *)g_strdup_printf("GoogleLogin auth=%s", auth->token));
 
-	http_status = soup_session_send_message(soup_session, msg);
-	if (http_status != 200) {
+	soup_session_send_message(soup_session, msg);
+	if (msg->status_code != 200) {
 		g_set_error (error, SOUP_HTTP_ERROR,
-					 http_status, soup_status_get_phrase (http_status));
+					 msg->status_code, msg->reason_phrase);
 		g_object_unref (msg);
 		return NULL;
 	}
@@ -249,7 +271,6 @@
 	SoupSession *soup_session;
 	SoupMessage *msg;
 	gchar *entry_xml;
-	int http_status;
 
 	g_return_val_if_fail(service != NULL, NULL);
 	g_return_val_if_fail(GDATA_IS_GOOGLE_SERVICE(service), NULL);
@@ -278,10 +299,19 @@
 				entry_xml,
 				strlen(entry_xml));
 
-	http_status = soup_session_send_message(soup_session, msg);
-    	if (http_status != 201) {
+	/* Handle redirects ourself, since soup does not behave like google-api expects */
+	soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+
+	soup_session_send_message (soup_session, msg);
+	if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
+		handle_google_redirection (soup_session, msg);
+	}
+    	
+	soup_message_set_flags (msg, 0);
+
+	if (msg->status_code != 201) {
 		g_set_error (error, SOUP_HTTP_ERROR,
-					 http_status, soup_status_get_phrase (http_status));
+					 msg->status_code, msg->reason_phrase);
 		g_object_unref (msg);
 		return NULL;
 	}
@@ -317,7 +347,6 @@
 	SoupSession *soup_session;
 	SoupMessage *msg;
 	const gchar *entry_edit_url;
-	int http_status;
 	gboolean retval = FALSE;
 
 	g_return_val_if_fail (service !=NULL, FALSE);
@@ -338,11 +367,20 @@
 				     "Authorization",
 				     (gchar *)g_strdup_printf ("GoogleLogin auth=%s",
 				     auth->token));
-	http_status = soup_session_send_message (soup_session, msg);
 
-    	if (http_status != 200) {
+	/* Handle redirects ourself */
+	soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+
+	soup_session_send_message (soup_session, msg);
+	if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
+		handle_google_redirection (soup_session, msg);
+	}
+    	
+	soup_message_set_flags (msg, 0);
+
+    	if (msg->status_code != 200) {
 		g_set_error (error, SOUP_HTTP_ERROR,
-					 http_status, soup_status_get_phrase (http_status));
+					 msg->status_code, msg->reason_phrase);
 	} else {
 		retval = TRUE;
 	}
@@ -392,7 +430,6 @@
 	SoupSession *soup_session;
 	SoupMessage *msg;
 	gchar *entry_xml;
-	int http_status;
 	GDataEntry *updated_entry = NULL;
 
 	g_return_val_if_fail (service !=NULL, FALSE);
@@ -422,11 +459,19 @@
 				entry_xml,
 				strlen(entry_xml));
 
-	http_status = soup_session_send_message (soup_session, msg);
+	/* Handle redirects ourself */
+	soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
 
-    	if (http_status != 200) {
+	soup_session_send_message (soup_session, msg);
+	if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
+		handle_google_redirection (soup_session, msg);
+	}
+    	
+	soup_message_set_flags (msg, 0);
+
+    	if (msg->status_code != 200) {
 		g_set_error (error, SOUP_HTTP_ERROR,
-					 http_status, soup_status_get_phrase (http_status));
+					 msg->status_code, msg->reason_phrase);
 		g_object_unref (msg);
 		return updated_entry;
 	}
