evolution-data-server r8853 - in branches/EXCHANGE_MAPI_BRANCH: camel/providers/mapi servers/mapi
- From: jjohnny svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution-data-server r8853 - in branches/EXCHANGE_MAPI_BRANCH: camel/providers/mapi servers/mapi
- Date: Mon, 26 May 2008 06:48:52 +0000 (UTC)
Author: jjohnny
Date: Mon May 26 06:48:51 2008
New Revision: 8853
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8853&view=rev
Log:
Initial code for handling HTML mails.
Modified:
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/camel/providers/mapi/camel-mapi-transport.c
branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-transport.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 Mon May 26 06:48:51 2008
@@ -593,7 +593,7 @@
item->header.from = g_strdup (find_mapi_SPropValue_data (array, PR_SENT_REPRESENTING_NAME));
item->header.size = *(glong *)(find_mapi_SPropValue_data (array, PR_MESSAGE_SIZE));
- item->msg.body = g_strdup (find_mapi_SPropValue_data (array, PR_BODY));
+ item->msg.body_plain_text = g_strdup (find_mapi_SPropValue_data (array, PR_BODY));
delivery_date = (struct FILETIME *)find_mapi_SPropValue_data(array, PR_MESSAGE_DELIVERY_TIME);
if (delivery_date) {
@@ -735,7 +735,7 @@
multipart = camel_multipart_new ();
camel_mime_message_set_message_id (msg, uid);
- body = item->msg.body;
+ body = item->msg.body_plain_text;
mapi_populate_msg_body_from_item (multipart, item, body);
/*Set recipient details*/
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 Mon May 26 06:48:51 2008
@@ -51,6 +51,10 @@
MAPI_ITEM_TYPE_TASK
} MapiItemType;
+typedef enum {
+ PART_TYPE_PLAIN_TEXT=1,
+ PART_TYPE_TEXT_HTML
+} MapiItemPartType;
typedef struct {
gchar *subject;
@@ -66,9 +70,9 @@
} MapiItemHeader;
typedef struct {
- gchar *body;
- //Temp. Find a proper place for this
- CamelStream *body_stream;
+ //Temp : PLAIN
+ gchar *body_plain_text;
+ GSList *body_parts;
} MapiItemMessage;
typedef struct {
@@ -85,6 +89,7 @@
MapiItemMessage msg;
GSList *attachments;
+ GSList *generic_streams;
}MapiItem;
Modified: branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-transport.c
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-transport.c (original)
+++ branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-transport.c Mon May 26 06:48:51 2008
@@ -23,6 +23,10 @@
#endif
#include <string.h>
+
+#include <libmapi/libmapi.h>
+#include <gen_ndr/exchange.h>
+
#include <camel/camel-data-wrapper.h>
#include <camel/camel-exception.h>
#include <camel/camel-mime-filter-crlf.h>
@@ -79,11 +83,10 @@
printf("-----------------\n\n");
printf("%s(%d):%s: \n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
printf("item->header.from : %s\n",item->header.from);
- printf("item->header.to : %s\n",item->header.to);
- printf("item->header.cc : %s\n",item->header.cc);
- printf("item->header.bcc : %s\n",item->header.bcc);
+ //Use Recipient List
printf("item->header.subject : %s\n",item->header.subject);
- printf("item->msg.body_stream : %s\n",item->msg.body_stream);
+ //printf("item->msg.body_stream : %s\n",item->msg.body_stream);
+ printf("item->msg.body_plain_text : %s\n",item->msg.body_plain_text);
printf("-----------------\n\n");
}
@@ -105,26 +108,40 @@
item->header.subject = strdup(subject);
}
+#define MAX_READ_SIZE 0x1000
+
static void
-mapi_item_set_body_stream (MapiItem *item, CamelStream *body)
+mapi_item_set_body_stream (MapiItem *item, CamelStream *body, MapiItemPartType part_type)
{
guint8 *buf = g_new0 (guint8 , STREAM_SIZE);
- guint32 read_size;
-
- item->msg.body_stream = NULL;
+ guint32 read_size = 0;
+ ExchangeMAPIStream *stream = g_new0 (ExchangeMAPIStream, 1);
camel_seekable_stream_seek((CamelSeekableStream *)body, 0, CAMEL_STREAM_SET);
+
+ stream->value = g_byte_array_new ();
+
while((read_size = camel_stream_read(body, (char *)buf, STREAM_SIZE))){
- if (read_size == -1) {
- item->msg.body_stream = NULL;
+ if (read_size == -1)
return;
- }
- if (item->msg.body_stream) {
- item->msg.body_stream = g_strconcat (item->msg.body_stream, (char *) buf, NULL);
- } else
- item->msg.body_stream = g_strdup ((char *) buf);
+ stream->value = g_byte_array_append (stream->value, (char *) buf, read_size);
}
+
+ switch (part_type) {
+ case PART_TYPE_TEXT_HTML :
+ stream->proptag = PR_HTML;
+ break;
+ case PART_TYPE_PLAIN_TEXT:
+ stream->proptag = PR_BODY;
+ break;
+ }
+
+ if (stream->value->len < MAX_READ_SIZE)
+ item->msg.body_parts = g_slist_append (item->msg.body_parts, stream);
+ else
+ item->generic_streams = g_slist_append (item->generic_streams, stream);
+
}
static gboolean
@@ -191,7 +208,9 @@
type = camel_mime_part_get_content_type(part);
if (i_part == 0 && camel_content_type_is (type, "text", "plain")) {
- mapi_item_set_body_stream (item, content_stream);
+ mapi_item_set_body_stream (item, content_stream, PART_TYPE_PLAIN_TEXT);
+ } else if (camel_content_type_is (type, "text", "html")) {
+ mapi_item_set_body_stream (item, content_stream, PART_TYPE_TEXT_HTML);
} else {
mapi_item_add_attach(item, filename, description,
content_stream, content_size);
@@ -247,7 +266,6 @@
if (camel_mime_message_get_subject(message)) {
mapi_item_set_subject(item, camel_mime_message_get_subject(message));
}
- mapi_item_debug_dump (item);
/* contents body */
multipart = (CamelMultipart *)camel_medium_get_content_object (CAMEL_MEDIUM (message));
@@ -261,10 +279,11 @@
type = camel_mime_part_get_content_type((CamelMimePart *)message);
content_type = camel_content_type_simple (type);
content_size = camel_data_wrapper_write_to_stream(dw, (CamelStream *)content_stream);
- mapi_item_set_body_stream (item, content_stream);
+ mapi_item_set_body_stream (item, content_stream, PART_TYPE_PLAIN_TEXT);
}
-
+ mapi_item_debug_dump (item);
+
/* send */
st = mapi_message_item_send(item, attach_list, recipient_list);
@@ -334,21 +353,35 @@
MapiItem *item = (MapiItem *) data;
struct SPropValue *props;
- uint32_t msgflag;
- uint32_t editor = 1;
+ GSList *l;
+
+ uint32_t *msgflag = g_new0 (uint32_t, 1);
+ uint32_t *editor = g_new0 (uint32_t, 1);
int i=0;
- props = g_new0 (struct SPropValue, 5);
+ props = g_new0 (struct SPropValue, 6);
set_SPropValue_proptag(&props[i++], PR_CONVERSATION_TOPIC, g_strdup (item->header.subject));
set_SPropValue_proptag(&props[i++], PR_NORMALIZED_SUBJECT, g_strdup (item->header.subject));
- set_SPropValue_proptag(&props[i++], PR_MSG_EDITOR_FORMAT, (const void *)&editor);
- //Fixme :
- set_SPropValue_proptag(&props[i++], PR_BODY, g_strdup (item->msg.body_stream));
+ *msgflag = MSGFLAG_UNSENT;
+ set_SPropValue_proptag(&props[i++], PR_MESSAGE_FLAGS, (void *)msgflag);
- msgflag = MSGFLAG_UNSENT;
- set_SPropValue_proptag(&props[i++], PR_MESSAGE_FLAGS, (void *)&msgflag);
+ for (l = item->msg.body_parts; l; l = l->next) {
+ ExchangeMAPIStream *stream = (ExchangeMAPIStream *) (l->data);
+ struct SBinary_short *bin = g_new0 (struct SBinary_short, 1);
+
+ bin->cb = stream->value->len;
+ bin->lpb = (uint8_t *)stream->value->data;
+ if (stream->proptag == PR_HTML)
+ set_SPropValue_proptag(&props[i++], stream->proptag, (void *)bin);
+ else if (stream->proptag == PR_BODY)
+ set_SPropValue_proptag(&props[i++], stream->proptag, (void *)stream->value->data);
+ }
+
+ /* FIXME : */
+ /* editor = EDITOR_FORMAT_PLAINTEXT; */
+ /* set_SPropValue_proptag(&props[i++], PR_MSG_EDITOR_FORMAT, (const void *)editor); */
*value = props;
return i;
@@ -373,7 +406,7 @@
{
guint64 fid = 0;
- exchange_mapi_create_item (olFolderOutbox, fid, NULL, NULL, mail_build_props, item, recipients, item->attachments);
+ exchange_mapi_create_item (olFolderOutbox, fid, NULL, NULL, mail_build_props, item, recipients, item->attachments, item->generic_streams);
return 0;
}
Modified: branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-transport.h
==============================================================================
--- branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-transport.h (original)
+++ branches/EXCHANGE_MAPI_BRANCH/camel/providers/mapi/camel-mapi-transport.h Mon May 26 06:48:51 2008
@@ -21,6 +21,7 @@
#ifndef CAMEL_MAPI_TRANSPORT_H
#define CAMEL_MAPI_TRANSPORT_H 1
+#include <libmapi/libmapi.h>
#include <camel/camel-transport.h>
#include <exchange-mapi-connection.h>
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 Mon May 26 06:48:51 2008
@@ -373,6 +373,76 @@
return (retval == MAPI_E_SUCCESS);
}
+/* Returns TRUE if all attachments were written succcesfully, else returns FALSE */
+#define MAX_READ_SIZE 0x1000
+
+static gboolean
+exchange_mapi_util_set_generic_streams (mapi_object_t *obj_message, GSList *stream_list)
+{
+
+ TALLOC_CTX *mem_ctx;
+ GSList *l;
+ enum MAPISTATUS retval;
+ gboolean status = TRUE;
+
+ mem_ctx = talloc_init ("ExchangeMAPI_Set_GenericStreams");
+
+ for (l = stream_list; l; l = l->next) {
+ ExchangeMAPIStream *generic_stream = (ExchangeMAPIStream *) (l->data);
+
+ enum MAPISTATUS retval;
+ DATA_BLOB stream;
+ uint32_t size;
+ uint32_t offset;
+ uint16_t read_size;
+ mapi_object_t obj_stream;
+
+ uint32_t mapitag = generic_stream->proptag;
+ uint32_t access_flags = 2; //TODO : Figure out what this is ?
+
+ mapi_object_init(&obj_stream);
+ retval = OpenStream(obj_message, mapitag, access_flags, &obj_stream);
+ if (retval != MAPI_E_SUCCESS)
+ return false;
+
+ size = MAX_READ_SIZE;
+ offset = 0;
+ while (offset <= generic_stream->value->len) {
+ stream.length = size;
+ stream.data = talloc_size(mem_ctx, size);
+ memcpy(stream.data, generic_stream->value->data + offset, size);
+ retval = WriteStream(&obj_stream, &stream, &read_size);
+ talloc_free(stream.data);
+ if (retval != MAPI_E_SUCCESS) {
+ status = FALSE;
+ goto cleanup;
+ }
+ printf(".");
+ fflush(0);
+
+ /* Exit when there is nothing left to write */
+ if (!read_size)
+ break;
+
+ offset += read_size;
+
+ if ((offset + size) > generic_stream->value->len) {
+ size = generic_stream->value->len - offset;
+ }
+ }
+
+ cleanup:
+ if (retval != MAPI_E_SUCCESS)
+ status = FALSE;
+
+ //mapi_object_release(&obj_stream);
+ }
+
+ talloc_free (mem_ctx);
+
+ return status;
+}
+
static gboolean
exchange_mapi_util_delete_attachments (mapi_object_t *obj_message)
{
@@ -1333,7 +1403,7 @@
exchange_mapi_create_item (uint32_t olFolder, mapi_id_t fid,
BuildNameID build_name_id, gpointer ni_data,
BuildProps build_props, gpointer p_data,
- GSList *recipients, GSList *attachments)
+ GSList *recipients, GSList *attachments, GSList *generic_streams)
{
enum MAPISTATUS retval;
TALLOC_CTX *mem_ctx;
@@ -1408,10 +1478,11 @@
if (build_props) {
propslen = build_props (&props, SPropTagArray, p_data);
if (propslen < 1) {
- g_warning ("%s(%d): (%s): Could not build props \n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
+ g_warning ("%s(%d): (%s): build_props failed! propslen = %d \n", __FILE__, __LINE__, __PRETTY_FUNCTION__, propslen);
goto cleanup;
}
}
+ LOGALL();
/* set properties for the item */
retval = SetProps(&obj_message, props, propslen);
@@ -1419,6 +1490,11 @@
mapi_errstr("SetProps", GetLastError());
goto cleanup;
}
+ LOGNONE();
+
+ if (generic_streams) {
+ exchange_mapi_util_set_generic_streams (&obj_message, generic_streams);
+ }
/* Set attachments if any */
if (attachments) {
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 Mon May 26 06:48:51 2008
@@ -113,7 +113,8 @@
exchange_mapi_create_item (uint32_t olFolder, mapi_id_t fid,
BuildNameID build_name_id, gpointer ni_data,
BuildProps build_props, gpointer p_data,
- GSList *recipients, GSList *attachments);
+ GSList *recipients, GSList *attachments,
+ GSList *generic_streams);
gboolean
exchange_mapi_modify_item (uint32_t olFolder, mapi_id_t fid, mapi_id_t mid,
BuildNameID build_name_id, gpointer ni_data,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]