[evolution-ews] Bug #664749 - Cannot send message "Service not connected"



commit 546b2d73fb72a75d54cd035bda3567247f78a67a
Author: Milan Crha <mcrha redhat com>
Date:   Thu Feb 9 14:12:44 2012 +0100

    Bug #664749 - Cannot send message "Service not connected"

 src/camel/camel-ews-transport.c |   34 ++++++++++++++++++++++++++++++++++
 src/utils/ews-camel-common.c    |   26 ++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/src/camel/camel-ews-transport.c b/src/camel/camel-ews-transport.c
index 74cddeb..3637a50 100644
--- a/src/camel/camel-ews-transport.c
+++ b/src/camel/camel-ews-transport.c
@@ -79,6 +79,7 @@ ews_send_to_sync (CamelTransport *transport,
 {
 	CamelNetworkSettings *network_settings;
 	CamelEwsSettings *ews_settings;
+	CamelInternetAddress *used_from;
 	CamelSettings *settings;
 	CamelService *service;
 	EEwsConnection *cnc;
@@ -95,6 +96,38 @@ ews_send_to_sync (CamelTransport *transport,
 	network_settings = CAMEL_NETWORK_SETTINGS (settings);
 	user = camel_network_settings_get_user (network_settings);
 
+	used_from = camel_mime_message_get_from (message);
+
+	if (!used_from && CAMEL_IS_INTERNET_ADDRESS (from))
+		used_from = CAMEL_INTERNET_ADDRESS (from);
+
+	if (!used_from || camel_address_length (CAMEL_ADDRESS (used_from)) == 0) {
+		g_set_error_literal (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+			_("Cannot send message with no From address"));
+		return FALSE;
+	} else if (camel_address_length (CAMEL_ADDRESS (used_from)) > 1) {
+		g_set_error_literal (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+			_("Exchange server cannot send message with multiple From addresses"));
+		return FALSE;
+	} else {
+		const gchar *ews_email = NULL, *used_email = NULL;
+
+		ews_email = camel_ews_settings_get_email (ews_settings);
+		if (!camel_internet_address_get (used_from, 0, NULL, &used_email)) {
+			g_set_error_literal (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Failed to read From address"));
+			return FALSE;
+		}
+
+		if (!ews_email || !used_email || g_ascii_strcasecmp (ews_email, used_email) != 0) {
+			g_set_error (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Exchange server cannot send message as '%s', when the account was configured for address '%s'"),
+				used_email ? used_email : "NULL",
+				ews_email ? ews_email : "NULL");
+			return FALSE;
+		}
+	}
+
 	cnc = e_ews_connection_find (host_url, user);
 	if (!cnc) {
 		g_set_error (error, CAMEL_SERVICE_ERROR,
@@ -118,6 +151,7 @@ camel_ews_transport_class_init (CamelEwsTransportClass *class)
 	CamelTransportClass *transport_class;
 
 	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->settings_type = CAMEL_TYPE_EWS_SETTINGS;
 	service_class->connect_sync = ews_transport_connect_sync;
 	service_class->get_name = ews_transport_get_name;
 
diff --git a/src/utils/ews-camel-common.c b/src/utils/ews-camel-common.c
index 121b2e8..58c210e 100644
--- a/src/utils/ews-camel-common.c
+++ b/src/utils/ews-camel-common.c
@@ -117,6 +117,7 @@ camel_ews_utils_create_mime_message (EEwsConnection *cnc, const gchar *dispositi
 	GSList *ids;
 	EEwsItem *item;
 	const EwsId *ewsid;
+	gchar *restore_from = NULL;
 	gboolean res;
 
 	create_data = g_new0 (struct _create_mime_msg_data, 1);
@@ -125,10 +126,35 @@ camel_ews_utils_create_mime_message (EEwsConnection *cnc, const gchar *dispositi
 	create_data->message_camel_flags = message_camel_flags;
 	create_data->from = from;
 
+	if (g_strcmp0 (disposition, "SendOnly") == 0) {
+		struct _camel_header_raw *header;
+
+		for (header = CAMEL_MIME_PART (message)->headers; header; header = header->next) {
+			if (header->name && g_ascii_strcasecmp (header->name, "From") == 0) {
+				restore_from = header->value;
+				header->value = g_strdup ("");
+				break;
+			}
+		}
+	}
+
 	res = e_ews_connection_create_items (cnc, EWS_PRIORITY_MEDIUM,
 					     disposition, NULL, save_folder,
 					     create_mime_message_cb, create_data,
 					     &ids, cancellable, error);
+
+	if (restore_from) {
+		struct _camel_header_raw *header;
+
+		for (header = CAMEL_MIME_PART (message)->headers; header; header = header->next) {
+			if (header->name && g_ascii_strcasecmp (header->name, "From") == 0) {
+				g_free (header->value);
+				header->value = restore_from;
+				break;
+			}
+		}
+	}
+
 	if (!res || (!itemid && !changekey))
 		return res;
 



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