[evolution-mapi/gnome-2-32] Bug #608388 - Copying a mail from another account loses headers



commit f33af9039e6fec3ea91d15952e90229cca3dd1d5
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 18 15:54:10 2010 +0200

    Bug #608388 - Copying a mail from another account loses headers

 src/camel/camel-mapi-folder.c                  |    2 +-
 src/camel/camel-mapi-transport.c               |    4 +-
 src/camel/camel-mapi-utils.c                   |   87 +++++++++++++++++++++---
 src/camel/camel-mapi-utils.h                   |    2 +-
 src/libexchangemapi/exchange-mapi-mail-utils.c |    9 +--
 5 files changed, 87 insertions(+), 17 deletions(-)
---
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index 1f33fb8..526bdd6 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -1642,7 +1642,7 @@ mapi_append_message (CamelFolder *folder, CamelMimeMessage *message,
 	/* Convert MIME to Item */
 	from = (CamelAddress *) camel_mime_message_get_from (message);
 
-	item = camel_mapi_utils_mime_to_item (message, from, error);
+	item = camel_mapi_utils_mime_to_item (message, info ? camel_message_info_flags (info) : 0, from, error);
 	if (item == NULL)
 		return FALSE;
 
diff --git a/src/camel/camel-mapi-transport.c b/src/camel/camel-mapi-transport.c
index 1467a1e..adb794d 100644
--- a/src/camel/camel-mapi-transport.c
+++ b/src/camel/camel-mapi-transport.c
@@ -63,6 +63,8 @@ mapi_message_item_send (ExchangeMapiConnection *conn, MailItem *item, GError **p
 	guint64 fid = 0;
 	mapi_id_t mid = 0;
 
+	item->header.flags = MSGFLAG_UNSENT;
+
 	mid = exchange_mapi_connection_create_item (conn, olFolderSentMail, fid,
 					 camel_mapi_utils_create_item_build_props, item,
 					 item->recipients, item->attachments, item->generic_streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE, perror);
@@ -101,7 +103,7 @@ mapi_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	}
 
 	/* Convert MIME to MailItem, attacment lists and recipient list.*/
-	item = camel_mapi_utils_mime_to_item (message, from, NULL);
+	item = camel_mapi_utils_mime_to_item (message, 0, from, NULL);
 
 	/* send */
 	st = mapi_message_item_send (conn, item, error);
diff --git a/src/camel/camel-mapi-utils.c b/src/camel/camel-mapi-utils.c
index 863f01e..9c6eb4f 100644
--- a/src/camel/camel-mapi-utils.c
+++ b/src/camel/camel-mapi-utils.c
@@ -98,12 +98,15 @@ mail_item_add_recipient (const gchar *recipients, OlMailRecipientType type, GSLi
 }
 
 static void
-mail_item_set_from(MailItem *item, const gchar *from)
+mail_item_set_from(MailItem *item, const gchar *from_name, const gchar *from_email)
 {
 	if (item->header.from)
 		g_free (item->header.from);
+	if (item->header.from_email)
+		g_free (item->header.from_email);
 
-	item->header.from = g_strdup (from);
+	item->header.from = g_strdup (from_name);
+	item->header.from_email = g_strdup (from_email);
 }
 
 static void
@@ -310,8 +313,21 @@ mapi_do_multipart (CamelMultipart *mp, MailItem *item, gboolean *is_first)
 	return TRUE;
 }
 
+static void
+mail_item_set_time (time_t *item_time, time_t camel_time, gint camel_offset)
+{
+	if (camel_time == CAMEL_MESSAGE_DATE_CURRENT) {
+		*item_time = 0;
+	} else {
+		/* Convert to UTC */
+		/*camel_time -= (camel_offset / 100) * 60 * 60;
+		camel_time -= (camel_offset % 100) * 60;*/
+		*item_time = camel_time;
+	}
+}
+
 MailItem *
-camel_mapi_utils_mime_to_item (CamelMimeMessage *message, CamelAddress *from, GError **error)
+camel_mapi_utils_mime_to_item (CamelMimeMessage *message, gint32 message_camel_flags, CamelAddress *from, GError **error)
 {
 	CamelDataWrapper *dw = NULL;
 	CamelContentType *type;
@@ -319,9 +335,12 @@ camel_mapi_utils_mime_to_item (CamelMimeMessage *message, CamelAddress *from, GE
 	CamelMultipart *multipart;
 	CamelInternetAddress *to, *cc, *bcc;
 	MailItem *item = g_new0 (MailItem, 1);
-	const gchar *namep;
-	const gchar *addressp;
+	const gchar *namep = NULL;
+	const gchar *addressp = NULL;
 	const gchar *content_type;
+	time_t msg_time = 0;
+	gint msg_time_offset = 0;
+	GArray *headers;
 
 	gssize	content_size;
 	GSList *recipient_list = NULL;
@@ -340,7 +359,18 @@ camel_mapi_utils_mime_to_item (CamelMimeMessage *message, CamelAddress *from, GE
 		namep = NULL;
 	}
 
-	mail_item_set_from (item, namep);
+	item->header.flags = 0;
+	if (message_camel_flags & CAMEL_MESSAGE_SEEN)
+		item->header.flags |= MSGFLAG_READ;
+	if (message_camel_flags & CAMEL_MESSAGE_ATTACHMENTS)
+		item->header.flags |= MSGFLAG_HASATTACH;
+
+	mail_item_set_from (item, namep, addressp);
+
+	msg_time = camel_mime_message_get_date (message, &msg_time_offset);
+	if (msg_time == CAMEL_MESSAGE_DATE_CURRENT)
+		msg_time = camel_mime_message_get_date_received (message, &msg_time_offset);
+	mail_item_set_time (&item->header.recieved_time, msg_time, msg_time_offset);
 
 	to = camel_mime_message_get_recipients(message, CAMEL_RECIPIENT_TYPE_TO);
 	for (i = 0; to && camel_internet_address_get (to, i, &namep, &addressp); i++) {
@@ -361,6 +391,25 @@ camel_mapi_utils_mime_to_item (CamelMimeMessage *message, CamelAddress *from, GE
 		mail_item_set_subject(item, camel_mime_message_get_subject(message));
 	}
 
+	headers = camel_medium_get_headers (CAMEL_MEDIUM (message));
+	if (headers) {
+		GString *hstr = g_string_new ("");
+		gint i;
+
+		for (i = 0; i < headers->len; i++) {
+			CamelMediumHeader *h = &g_array_index (headers, CamelMediumHeader, i);
+
+			if (!h->name || !*h->name || g_ascii_strncasecmp (h->name, "X-Evolution", 11) == 0)
+				continue;
+
+			g_string_append_printf (hstr, "%s: %s\n", h->name, h->value ? h->value : "");
+		}
+
+		camel_medium_free_headers (CAMEL_MEDIUM (message), headers);
+
+		item->header.transport_headers = g_string_free (hstr, hstr->len == 0);
+	}
+
 	/*Add message threading properties */
 	item->header.references = g_strdup (camel_medium_get_header ((CamelMedium *) message, "References"));
 	item->header.in_reply_to = g_strdup (camel_medium_get_header ((CamelMedium *) message, "In-Reply-To"));
@@ -398,7 +447,6 @@ camel_mapi_utils_create_item_build_props (ExchangeMapiConnection *conn, mapi_id_
 	MailItem *item = (MailItem *) data;
 	GSList *l;
 	bool send_rich_info;
-	uint32_t msgflag;
 	uint32_t cpid;
 
 	#define set_value(hex, val) G_STMT_START { \
@@ -415,8 +463,29 @@ camel_mapi_utils_create_item_build_props (ExchangeMapiConnection *conn, mapi_id_
 	send_rich_info = false;
 	set_value (PR_SEND_RICH_INFO, &send_rich_info);
 
-	msgflag = MSGFLAG_UNSENT;
-	set_value (PR_MESSAGE_FLAGS, &msgflag);
+	set_value (PR_MESSAGE_FLAGS, &item->header.flags);
+
+	if (item->header.from && *item->header.from)
+		set_value (PR_SENT_REPRESENTING_NAME_UNICODE, item->header.from);
+
+	if (item->header.from_email && *item->header.from_email) {
+		set_value (PR_SENT_REPRESENTING_ADDRTYPE_UNICODE, "SMTP");
+		set_value (PR_SENT_REPRESENTING_EMAIL_ADDRESS_UNICODE, item->header.from_email);
+	}
+
+	if (item->header.recieved_time != 0) {
+		struct FILETIME msg_date = { 0 };
+		NTTIME nttime = 0;
+		unix_to_nt_time (&nttime, item->header.recieved_time);
+
+		msg_date.dwHighDateTime = nttime >> 32;
+		msg_date.dwLowDateTime = nttime & 0xFFFFFFFF;
+
+		set_value (PR_MESSAGE_DELIVERY_TIME, &msg_date);
+	}
+
+	if (item->header.transport_headers && *item->header.transport_headers)
+		set_value (PR_TRANSPORT_MESSAGE_HEADERS_UNICODE, item->header.transport_headers);
 
 	/* Message threading information */
 	if (item->header.references)
diff --git a/src/camel/camel-mapi-utils.h b/src/camel/camel-mapi-utils.h
index 6205b72..f3c28e4 100644
--- a/src/camel/camel-mapi-utils.h
+++ b/src/camel/camel-mapi-utils.h
@@ -31,7 +31,7 @@ G_BEGIN_DECLS
 #include <camel/camel.h>
 
 MailItem *
-camel_mapi_utils_mime_to_item (CamelMimeMessage *message, CamelAddress *from, GError **error);
+camel_mapi_utils_mime_to_item (CamelMimeMessage *message, gint32 message_camel_flags, CamelAddress *from, GError **error);
 
 gboolean
 camel_mapi_utils_create_item_build_props (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values, uint32_t *n_values, gpointer data);
diff --git a/src/libexchangemapi/exchange-mapi-mail-utils.c b/src/libexchangemapi/exchange-mapi-mail-utils.c
index d42fde7..b339863 100644
--- a/src/libexchangemapi/exchange-mapi-mail-utils.c
+++ b/src/libexchangemapi/exchange-mapi-mail-utils.c
@@ -407,6 +407,10 @@ mapi_mime_set_msg_headers (ExchangeMapiConnection *conn, CamelMimeMessage *msg,
 
 		g_object_unref (parser);
 		g_object_unref (part);
+	} else {
+		recieved_time = item->header.recieved_time;
+		actual_time = camel_header_decode_date (ctime(&recieved_time), &offset);
+		camel_mime_message_set_date (msg, actual_time, offset);
 	}
 
 	/* Overwrite headers if we have specific properties available*/
@@ -414,11 +418,6 @@ mapi_mime_set_msg_headers (ExchangeMapiConnection *conn, CamelMimeMessage *msg,
 	if (temp_str)
 		camel_mime_message_set_subject (msg, temp_str);
 
-	recieved_time = item->header.recieved_time;
-
-	actual_time = camel_header_decode_date (ctime(&recieved_time), &offset);
-	/* camel_mime_message_set_date (msg, actual_time, offset); */
-
 	if (item->header.from) {
 		if ((item->header.from_type != NULL) && !g_utf8_collate (item->header.from_type, "EX")) {
 			gchar *from_email;



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