[evolution-ews] evolution-ews: fix draft flag on sent items



commit d2db63a9515ac9d8eb4433059e083eaaed4e1bdd
Author: James Bottomley <JBottomley Parallels com>
Date:   Wed Jul 13 09:39:58 2011 -0500

    evolution-ews: fix draft flag on sent items
    
    What's happening currently is that the outlook web server shows all my
    sent messages with a yellow banner wrongly saying "This Message has
    not been Sent".
    
    The design of EWS is that you should append to folders with
    MessageDisposition "SaveOnly" and send with "SendAndSaveCopy".  The
    former always sets the IsDraft flag and the latter always clears it.
    Unfortunately, the design of evolution precludes us from using
    SendAndSaveCopy since evolution wants to send and then separately save
    the sent email.  Thus we need to modify SaveOnly to respect the
    CAMEL_MESSAGE_DRAFT flag by setting the MAPI message flags.
    
    I also removed the FIXME: comment about the From: field.  This is
    irrelevant to us, since EWS respects all the properties in the MIME
    body (which include the From: field and the Importance: field).
    
    Signed-off-by: James Bottomley <JBottomley Parallels com>

 src/utils/ews-camel-common.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/src/utils/ews-camel-common.c b/src/utils/ews-camel-common.c
index 98e2b77..2f478b1 100644
--- a/src/utils/ews-camel-common.c
+++ b/src/utils/ews-camel-common.c
@@ -27,6 +27,7 @@
 
 #include "ews-camel-common.h"
 #include "e-ews-compat.h"
+#include "e-ews-message.h"
 
 struct _create_mime_msg_data {
 	CamelMimeMessage *message;
@@ -34,6 +35,10 @@ struct _create_mime_msg_data {
 	CamelAddress *from;
 };
 
+/* MAPI flags gleaned from windows header files */
+#define MAPI_MSGFLAG_READ	0x01
+#define MAPI_MSGFLAG_UNSENT	0x08
+
 static void
 create_mime_message_cb (ESoapMessage *msg, gpointer user_data)
 {
@@ -42,6 +47,7 @@ create_mime_message_cb (ESoapMessage *msg, gpointer user_data)
 	CamelMimeFilter *filter;
 	GByteArray *bytes;
 	gchar *base64;
+	int msgflag;
 
 	e_soap_message_start_element (msg, "Message", NULL, NULL);
 	e_soap_message_start_element (msg, "MimeContent", NULL, NULL);
@@ -78,8 +84,24 @@ create_mime_message_cb (ESoapMessage *msg, gpointer user_data)
 
 	e_soap_message_end_element (msg); /* MimeContent */
 
-	/* FIXME: Handle From address and message_camel_flags */
+	/* more MAPI crap.  You can't just set the IsDraft property
+	 * here you have to use the MAPI MSGFLAG_UNSENT extended
+	 * property Further crap is that Exchange 2007 assumes when it
+	 * sees this property that you're setting the value to 0
+	 * ... it never checks */
+	msgflag  = MAPI_MSGFLAG_READ; /* draft or sent is always read */
+	if (create_data->message_camel_flags & CAMEL_MESSAGE_DRAFT)
+		msgflag |= MAPI_MSGFLAG_UNSENT;
+
+	e_soap_message_start_element (msg, "ExtendedProperty", NULL, NULL);
+	e_soap_message_start_element (msg, "ExtendedFieldURI", NULL, NULL);
+	e_soap_message_add_attribute (msg, "PropertyTag", "0x0E07", NULL, NULL);
+	e_soap_message_add_attribute (msg, "PropertyType", "Integer", NULL, NULL);
+	e_soap_message_end_element (msg); /* ExtendedFieldURI */
+
+	e_ews_message_write_int_parameter (msg, "Value", NULL, msgflag);
 
+	e_soap_message_end_element (msg); /* ExtendedProperty */
 	e_soap_message_end_element (msg); /* Message */
 
 	g_free (create_data);



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