evolution-data-server r8455 - in branches/EXCHANGE_MAPI_BRANCH: camel/providers/mapi servers/mapi



Author: jjohnny
Date: Tue Feb  5 07:26:51 2008
New Revision: 8455
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8455&view=rev

Log:
Initial support for fetching mail attachments.


Modified:
   branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/ChangeLog
   branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-folder.c
   branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-folder.h
   branches/EXCHANGE_MAPI_BRANCH/servers/mapi/ChangeLog
   branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-connection.c
   branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-connection.h

Modified: branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-folder.c
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-folder.c	(original)
+++ branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-folder.c	Tue Feb  5 07:26:51 2008
@@ -34,7 +34,6 @@
 #include <string.h>
 #include <camel/camel-stream-buffer.h>
 #include <libmapi/libmapi.h>
-
 #include <pthread.h>
 
 #include "camel-mapi-private.h"
@@ -152,7 +151,7 @@
 			camel_store_summary_info_free ((CamelStoreSummary *)((CamelMapiStore *)folder->parent_store)->summary, si);
 		}
 		camel_folder_summary_save (folder->summary);
-		/* 		camel_store_summary_save ((CamelStoreSummary *)((CamelMapiStore *)folder->parent_store)->summary); */
+		camel_store_summary_save ((CamelStoreSummary *)((CamelMapiStore *)folder->parent_store)->summary);
 	} else {
 		/* We probably could not get the messages the first time. (get_folder) failed???!
 		 * so do a get_folder again. And hope that it works
@@ -276,7 +275,6 @@
 		item->header.flags |= CAMEL_MESSAGE_SEEN;
 	if ((*flags & MSGFLAG_HASATTACH) != 0)
 		item->header.flags |= CAMEL_MESSAGE_ATTACHMENTS;
-
 /* 	printf("%s(%d):%s:subject : %s \n from : %s\nto : %s\n cc : %s\n", __FILE__, */
 /* 	       __LINE__, __PRETTY_FUNCTION__, item->header.subject, */
 /* 	       item->header.from, item->header.to, item->header.cc); */
@@ -800,6 +798,7 @@
 	item->mid = mid;
 
 	/* FixME : which on of this will fetch the subject. */
+	item->header.subject = g_strdup (find_mapi_SPropValue_data (array, PR_NORMALIZED_SUBJECT));
 	item->header.to = g_strdup (find_mapi_SPropValue_data (array, PR_DISPLAY_TO));
 	item->header.cc = g_strdup (find_mapi_SPropValue_data (array, PR_DISPLAY_CC));
 	item->header.bcc = g_strdup (find_mapi_SPropValue_data (array, PR_DISPLAY_BCC));
@@ -822,6 +821,10 @@
 	if ((*flags & MSGFLAG_HASATTACH) != 0)
 		item->header.flags |= CAMEL_MESSAGE_ATTACHMENTS;
 
+	//Fetch Attachments here.
+	printf("%s(%d):%s:Number of Attachments : %d \n", __FILE__, __LINE__, __PRETTY_FUNCTION__, g_slist_length (attachments));
+	item->attachments = attachments;
+
 	return item;
 }
 
@@ -939,12 +942,15 @@
 	MapiItemType type;
 	CamelMultipart *multipart = NULL;
 
+	GSList *attach_list = NULL;
 	int errno;
 	char *body = NULL;
 	int body_len = 0;
 	const char *uid = NULL;
 	CamelStream *temp_stream;
 
+	attach_list = item->attachments;
+
 	msg = camel_mime_message_new ();
 
 	multipart = camel_multipart_new ();
@@ -957,6 +963,35 @@
 	mapi_msg_set_recipient_list (msg, item);
 	mapi_populate_details_from_item (msg, item);
 
+	if (attach_list) {
+		GSList *al = attach_list;
+		for (al = attach_list; al != NULL; al = al->next) {
+			ExchangeMAPIAttachment *attach = (ExchangeMAPIAttachment *)al->data;
+			CamelMimePart *part;
+
+			printf("%s(%d):%s:Attachment --\n\tFileName : %s \n\tMIME Tag : %s\n\tLength : %d\n",
+			       __FILE__, __LINE__, __PRETTY_FUNCTION__, 
+				 attach->filename, attach->mime_type, attach->value->len );
+
+			if (attach->value->len <= 0) {
+				continue;
+			}
+			part = camel_mime_part_new ();
+
+			camel_mime_part_set_filename(part, g_strdup(attach->filename));
+			//Auto generate content-id
+			camel_mime_part_set_content_id (part, NULL);
+			camel_mime_part_set_content(part, attach->value->data, attach->value->len, attach->mime_type);
+			camel_content_type_set_param (((CamelDataWrapper *) part)->mime_type, "name", attach->filename);
+
+			camel_multipart_set_boundary(multipart, NULL);
+			camel_multipart_add_part (multipart, part);
+			camel_object_unref (part);
+			
+		}
+		exchange_mapi_util_free_attachment_list (&attach_list);
+	}
+
 	camel_medium_set_content_object(CAMEL_MEDIUM (msg), CAMEL_DATA_WRAPPER(multipart));
 	camel_object_unref (multipart);
 

Modified: branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-folder.h
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-folder.h	(original)
+++ branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-folder.h	Tue Feb  5 07:26:51 2008
@@ -28,6 +28,7 @@
 #include <camel/camel-offline-folder.h>
 #include <camel/camel-offline-journal.h>
 #include <libmapi/libmapi.h>
+#include <exchange-mapi-connection.h>
 
 #define PATH_FOLDER ".evolution/mail/mapi"
 
@@ -77,6 +78,8 @@
 
 	MapiItemHeader header;
 	MapiItemMessage msg;
+
+	GSList *attachments;
 }MapiItem;
 
 

Modified: branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-connection.c
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-connection.c	(original)
+++ branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-connection.c	Tue Feb  5 07:26:51 2008
@@ -577,13 +577,14 @@
 	mem_ctx = talloc_init ("ExchangeMAPI_GetAttachments");
 
 	/* do we need MIME tag, MIME sequence etc ? */
-	proptags = set_SPropTagArray(mem_ctx, 0x7, 
+	proptags = set_SPropTagArray(mem_ctx, 0x8, 
 				     PR_ATTACH_NUM, 
 				     PR_INSTANCE_KEY, 
 				     PR_RECORD_KEY, 
 				     PR_RENDERING_POSITION,
 				     PR_ATTACH_FILENAME, 
 				     PR_ATTACH_LONG_FILENAME,  
+				     PR_ATTACH_MIME_TAG,
 				     PR_ATTACH_SIZE);
 
 	mapi_object_init(&obj_tb_attach);
@@ -645,6 +646,7 @@
 		/* Alloc buffer */
 		sz_data = (const uint32_t *) get_SPropValue_SRow_data(&rows_attach.aRow[i_row_attach], PR_ATTACH_SIZE);
 		buf_data = talloc_size(mem_ctx, *sz_data);
+
 		if (buf_data == 0)
 			goto loop_cleanup;
 
@@ -674,6 +676,8 @@
 			if (!(attachment->filename && *attachment->filename))
 				attachment->filename = (const char *) get_SPropValue_SRow_data(&rows_attach.aRow[i_row_attach], PR_ATTACH_FILENAME);
 
+			attachment->mime_type = (const char *) find_SPropValue_data (&rows_attach.aRow[i_row_attach], PR_ATTACH_MIME_TAG);
+
 			*attach_list = g_slist_append (*attach_list, attachment);
 		}
 		talloc_free (buf_data);
@@ -902,8 +906,10 @@
 			goto loop_cleanup;
 		}
 
-		if (has_attach && *has_attach)
+		if (has_attach && *has_attach) {
+			printf("%s(%d):%s:Fetching Attachments \n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
 			exchange_mapi_util_get_attachments (&obj_message, &attach_list);
+		}
 
 		exchange_mapi_util_get_recipients (&obj_message, &recip_list);
 
@@ -948,9 +954,9 @@
 	loop_cleanup:
 		mapi_object_release(&obj_message);
 
-		/* should I ?? */
-		if (attach_list)
-			exchange_mapi_util_free_attachment_list (&attach_list);
+		/* FIXME : Should be freed by the caller */
+/* 		if (attach_list) */
+/* 			exchange_mapi_util_free_attachment_list (&attach_list); */
 
 		if (recip_list) 
 			exchange_mapi_util_free_recipient_list (&recip_list);
@@ -1104,8 +1110,8 @@
 //		talloc_free (properties_array.lpProps);
 
 	/* should I ?? */
-	if (attach_list)
-		exchange_mapi_util_free_attachment_list (&attach_list);
+/* 	if (attach_list) */
+/* 		exchange_mapi_util_free_attachment_list (&attach_list); */
 
 	if (recip_list) 
 		exchange_mapi_util_free_recipient_list (&recip_list);

Modified: branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-connection.h
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-connection.h	(original)
+++ branches/EXCHANGE_MAPI_BRANCH/servers/mapi/exchange-mapi-connection.h	Tue Feb  5 07:26:51 2008
@@ -35,7 +35,8 @@
 /* FIXME: need to accomodate rendering position */
 typedef struct {
 	GByteArray *value;
-	const char *filename;
+	const gchar *filename;
+	const gchar *mime_type;
 } ExchangeMAPIAttachment;
 
 typedef struct {



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