[evolution-mapi] Bug #644796 - Lookup for display name for recipients in "Sent Items"



commit 8c2867e1d118b3c22dc07f8891652313e38da3ca
Author: Milan Crha <mcrha redhat com>
Date:   Tue Mar 15 15:16:26 2011 +0100

    Bug #644796 - Lookup for display name for recipients in "Sent Items"

 src/camel/camel-mapi-folder.c                  |    2 +-
 src/libexchangemapi/exchange-mapi-cal-utils.c  |    8 ++--
 src/libexchangemapi/exchange-mapi-connection.c |    9 ++++--
 src/libexchangemapi/exchange-mapi-connection.h |    2 +-
 src/libexchangemapi/exchange-mapi-mail-utils.c |   39 +++++++++++++++++++----
 5 files changed, 44 insertions(+), 16 deletions(-)
---
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index 76d3956..b8498fb 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -456,7 +456,7 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
 				gchar *from_email;
 
 				camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-				from_email = exchange_mapi_connection_ex_to_smtp (camel_mapi_store_get_exchange_connection (mapi_store), item->header.from_email, NULL);
+				from_email = exchange_mapi_connection_ex_to_smtp (camel_mapi_store_get_exchange_connection (mapi_store), item->header.from_email, NULL, NULL);
 				camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 				g_free (item->header.from_email);
diff --git a/src/libexchangemapi/exchange-mapi-cal-utils.c b/src/libexchangemapi/exchange-mapi-cal-utils.c
index 28d9d26..be2554a 100644
--- a/src/libexchangemapi/exchange-mapi-cal-utils.c
+++ b/src/libexchangemapi/exchange-mapi-cal-utils.c
@@ -863,7 +863,7 @@ exchange_mapi_cal_util_mapi_props_to_comp (ExchangeMapiConnection *conn, icalcom
 						email = "";
 
 					if (g_str_equal (email_type, "EX")) {
-						to_free = exchange_mapi_connection_ex_to_smtp (conn, email, NULL);
+						to_free = exchange_mapi_connection_ex_to_smtp (conn, email, NULL, NULL);
 						email = to_free;
 					}
 
@@ -895,7 +895,7 @@ exchange_mapi_cal_util_mapi_props_to_comp (ExchangeMapiConnection *conn, icalcom
 						email = "";
 
 					if (g_str_equal (email_type, "EX")) {
-						to_free = exchange_mapi_connection_ex_to_smtp (conn, email, NULL);
+						to_free = exchange_mapi_connection_ex_to_smtp (conn, email, NULL, NULL);
 						email = to_free;
 					}
 
@@ -924,11 +924,11 @@ exchange_mapi_cal_util_mapi_props_to_comp (ExchangeMapiConnection *conn, icalcom
 				const gchar *sent_email = (const gchar *) exchange_mapi_util_find_array_propval (properties, PR_SENT_REPRESENTING_EMAIL_ADDRESS_UNICODE);
 
 				if (!g_utf8_collate (sender_email_type, "EX")) {
-					sender_free = exchange_mapi_connection_ex_to_smtp (conn, sender_email, NULL);
+					sender_free = exchange_mapi_connection_ex_to_smtp (conn, sender_email, NULL, NULL);
 					sender_email = sender_free;
 				}
 				if (!g_utf8_collate (sent_email_type, "EX")) {
-					sent_free = exchange_mapi_connection_ex_to_smtp (conn, sent_email, NULL);
+					sent_free = exchange_mapi_connection_ex_to_smtp (conn, sent_email, NULL, NULL);
 					sent_email = sent_free;
 				}
 
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index 794b535..8cb439c 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -3462,7 +3462,7 @@ exchange_mapi_connection_peek_folders_list (ExchangeMapiConnection *conn)
 
 /* free returned pointer with g_free() */
 gchar *
-exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *ex_address, GError **perror)
+exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *ex_address, gchar **display_name, GError **perror)
 {
 	enum MAPISTATUS	ms;
 	TALLOC_CTX		*mem_ctx;
@@ -3488,15 +3488,18 @@ exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *
 
 	LOCK ();
 
-	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1,
+	SPropTagArray = set_SPropTagArray (mem_ctx, 0x2,
+					  PR_DISPLAY_NAME_UNICODE,
 					  PR_SMTP_ADDRESS_UNICODE);
 
 	ms = ResolveNames (priv->session, (const gchar **)str_array, SPropTagArray, &SRowSet, &flaglist, MAPI_UNICODE);
 	if (ms != MAPI_E_SUCCESS)
 		ms = ResolveNames (priv->session, (const gchar **)str_array, SPropTagArray, &SRowSet, &flaglist, 0);
 
-	if (ms == MAPI_E_SUCCESS && SRowSet && SRowSet->cRows == 1) {
+	if (ms == MAPI_E_SUCCESS && SRowSet) {
 		smtp_addr = g_strdup (exchange_mapi_util_find_row_propval (SRowSet->aRow, PR_SMTP_ADDRESS_UNICODE));
+		if (display_name)
+			*display_name = g_strdup (exchange_mapi_util_find_row_propval (SRowSet->aRow, PR_DISPLAY_NAME_UNICODE));
 	}
 
 	talloc_free (mem_ctx);
diff --git a/src/libexchangemapi/exchange-mapi-connection.h b/src/libexchangemapi/exchange-mapi-connection.h
index 7531b7c..09e5ae7 100644
--- a/src/libexchangemapi/exchange-mapi-connection.h
+++ b/src/libexchangemapi/exchange-mapi-connection.h
@@ -215,7 +215,7 @@ GSList *		exchange_mapi_connection_peek_folders_list (ExchangeMapiConnection *co
 gboolean		exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi_id_t fid, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems, GError **perror);
 uint32_t		exchange_mapi_connection_resolve_named_prop (ExchangeMapiConnection *conn, mapi_id_t fid, uint32_t pidlid_propid, GError **perror);
 
-gchar *			exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *ex_address, GError **perror);
+gchar *			exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *ex_address, gchar **display_name, GError **perror);
 
 /* Push notifications APIs */
 typedef gboolean (*exchange_check_continue) (void);
diff --git a/src/libexchangemapi/exchange-mapi-mail-utils.c b/src/libexchangemapi/exchange-mapi-mail-utils.c
index 586e45e..9f0fd2c 100644
--- a/src/libexchangemapi/exchange-mapi-mail-utils.c
+++ b/src/libexchangemapi/exchange-mapi-mail-utils.c
@@ -317,8 +317,25 @@ mapi_mail_get_item_prop_list (ExchangeMapiConnection *conn, mapi_id_t fid, TALLO
 	return exchange_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
 }
 
+static gboolean
+name_is_email_user (const gchar *name, const gchar *email_id)
+{
+	gint name_len, email_len;
+
+	if (!name || !email_id)
+		return FALSE;
+
+	if (!*name || !*email_id || g_ascii_strcasecmp (email_id, name) == 0)
+		return TRUE;
+
+	name_len = strlen (name);
+	email_len = strlen (email_id);
+
+	return name_len < email_len && g_ascii_strncasecmp (email_id, name, name_len) == 0 && email_id[name_len] == '@';
+}
+
 static void
-mapi_mime_set_recipient_list (CamelMimeMessage *msg, MailItem *item)
+mapi_mime_set_recipient_list (ExchangeMapiConnection *conn, CamelMimeMessage *msg, MailItem *item)
 {
 	GSList *l = NULL;
 	CamelInternetAddress *to_addr, *cc_addr, *bcc_addr;
@@ -331,7 +348,7 @@ mapi_mime_set_recipient_list (CamelMimeMessage *msg, MailItem *item)
 	bcc_addr = camel_internet_address_new ();
 
 	for (l = item->recipients; l; l=l->next) {
-		gchar *display_name;
+		gchar *display_name = NULL;
 		const gchar *name = NULL;
 		uint32_t rcpt_type = MAPI_TO;
 		uint32_t *type = NULL;
@@ -348,12 +365,20 @@ mapi_mime_set_recipient_list (CamelMimeMessage *msg, MailItem *item)
 		/*Name is probably available in one of these props.*/
 		name = (const gchar *) exchange_mapi_util_find_row_propval (aRow, PR_DISPLAY_NAME_UNICODE);
 		name = name ? name : (const gchar *) exchange_mapi_util_find_row_propval (aRow, PR_RECIPIENT_DISPLAY_NAME_UNICODE);
-		name = name ? name : (const gchar *) exchange_mapi_util_find_row_propval (aRow, PR_7BIT_DISPLAY_NAME_UNICODE);
+		if (!name) {
+			name = (const gchar *) exchange_mapi_util_find_row_propval (aRow, PR_7BIT_DISPLAY_NAME_UNICODE);
+			if (name && !strchr (name, '@')) {
+				gchar *to_free;
+
+				to_free = exchange_mapi_connection_ex_to_smtp (conn, recip->email_id, &display_name, NULL);
+				g_free (to_free);
+			}
+		}
 
 		type = (uint32_t *) exchange_mapi_util_find_row_propval (aRow, PR_RECIPIENT_TYPE);
 
-		/*Fallbacks. Not good*/
-		display_name = name ? g_strdup (name) : g_strdup (recip->email_id);
+		if (!display_name && name && recip->email_id && !name_is_email_user (name, recip->email_id))
+			display_name = g_strdup (name);
 		rcpt_type = (type ? *type : MAPI_TO);
 
 		switch (rcpt_type) {
@@ -444,7 +469,7 @@ mapi_mime_set_msg_headers (ExchangeMapiConnection *conn, CamelMimeMessage *msg,
 		if ((item->header.from_type != NULL) && !g_utf8_collate (item->header.from_type, "EX")) {
 			gchar *from_email;
 
-			from_email = exchange_mapi_connection_ex_to_smtp (conn, item->header.from_email, NULL);
+			from_email = exchange_mapi_connection_ex_to_smtp (conn, item->header.from_email, NULL, NULL);
 			g_free (item->header.from_email);
 			item->header.from_email = from_email;
 		}
@@ -874,7 +899,7 @@ mapi_mail_item_to_mime_message (ExchangeMapiConnection *conn, MailItem *item)
 	attach_list = item->attachments;
 	msg = camel_mime_message_new ();
 
-	mapi_mime_set_recipient_list (msg, item);
+	mapi_mime_set_recipient_list (conn, msg, item);
 	mapi_mime_set_msg_headers (conn, msg, item);
 	mapi_mime_classify_attachments (conn, item->fid, item->msg_class, attach_list, &inline_attachs, &noninline_attachs);
 



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